Make images smaller using best-in-class codecs, right in the browser.
JavaScript
Fix Lossless+Progressive JXL.
Luca Versaria699a5c4dc44
diff --git a/codecs/jxl/dec/jxl_dec.cpp b/codecs/jxl/dec/jxl_dec.cppindex 556d49b4..219388cb 100644--- a/codecs/jxl/dec/jxl_dec.cpp+++ b/codecs/jxl/dec/jxl_dec.cpp@@ -14,12 +14,33 @@ thread_local const val ImageData = val::global("ImageData");// R, G, B, A#define COMPONENTS_PER_PIXEL 4+#ifndef JXL_DEBUG_ON_ALL_ERROR+#define JXL_DEBUG_ON_ALL_ERROR 0+#endif++#if JXL_DEBUG_ON_ALL_ERROR+#define EXPECT_TRUE(a) \+ if (!(a)) { \+ fprintf(stderr, "Assertion failure (%d): %s\n", __LINE__, #a); \+ return val::null(); \+ }+#define EXPECT_EQ(a, b) \+ { \+ int a_ = a; \+ int b_ = b; \+ if (a_ != b_) { \+ fprintf(stderr, "Assertion failure (%d): %s (%d) != %s (%d)\n", __LINE__, #a, a_, #b, b_); \+ return val::null(); \+ } \+ }+#else#define EXPECT_TRUE(a) \if (!(a)) { \return val::null(); \}#define EXPECT_EQ(a, b) EXPECT_TRUE((a) == (b));+#endifval decode(std::string data) {std::unique_ptr<JxlDecoder,diff --git a/codecs/jxl/dec/jxl_dec.wasm b/codecs/jxl/dec/jxl_dec.wasmindex 6ca170e9..c873d23d 100755Binary files a/codecs/jxl/dec/jxl_dec.wasm and b/codecs/jxl/dec/jxl_dec.wasm differdiff --git a/codecs/jxl/enc/jxl_enc.cpp b/codecs/jxl/enc/jxl_enc.cppindex 41314c2b..8f3413cf 100644--- a/codecs/jxl/enc/jxl_enc.cpp+++ b/codecs/jxl/enc/jxl_enc.cpp@@ -38,7 +38,14 @@ val encode(std::string image, int width, int height, JXLOptions options) {// Reduce memory usage of tree learning for lossless data.// TODO(veluca93): this is a mitigation for excessive memory usage in the JXL encoder.- cparams.options.nb_repeats = 0.1;+ float megapixels = width * height * 0.000001;+ if (megapixels > 8) {+ cparams.options.nb_repeats = 0.1;+ } else if (megapixels > 4) {+ cparams.options.nb_repeats = 0.3;+ } else {+ // default is OK.+ }float quality = options.quality;@@ -59,8 +66,10 @@ val encode(std::string image, int width, int height, JXLOptions options) {if (options.progressive) {cparams.qprogressive_mode = true;- cparams.progressive_dc = 1;cparams.responsive = 1;+ if (!cparams.modular_mode) {+ cparams.progressive_dc = 1;+ }}if (cparams.modular_mode) {diff --git a/codecs/jxl/enc/jxl_enc.wasm b/codecs/jxl/enc/jxl_enc.wasmindex 393c086b..b23074ae 100755Binary files a/codecs/jxl/enc/jxl_enc.wasm and b/codecs/jxl/enc/jxl_enc.wasm differ