Make images smaller using best-in-class codecs, right in the browser.
JavaScript
Don't copy dem pixels
Surmac6015e2e8d10
diff --git a/codecs/avif/enc/avif_enc.cpp b/codecs/avif/enc/avif_enc.cppindex ac949b96..0b096774 100644--- a/codecs/avif/enc/avif_enc.cpp+++ b/codecs/avif/enc/avif_enc.cpp@@ -48,8 +48,8 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {avifRGBImage srcRGB;avifRGBImageSetDefaults(&srcRGB, image);- avifRGBImageAllocatePixels(&srcRGB);- memcpy(srcRGB.pixels, rgba, width * height * 4);+ srcRGB.pixels = rgba;+ srcRGB.rowBytes = width * 4;avifImageRGBToYUV(image, &srcRGB);avifEncoder* encoder = avifEncoderCreate();@@ -65,7 +65,6 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {}auto js_result = Uint8Array.new_(typed_memory_view(output.size, output.data));- avifRGBImageFreePixels(&srcRGB);avifImageDestroy(image);avifEncoderDestroy(encoder);return js_result;diff --git a/codecs/avif/enc/avif_enc.wasm b/codecs/avif/enc/avif_enc.wasmindex 0ea1d4b3..8d62898b 100644Binary files a/codecs/avif/enc/avif_enc.wasm and b/codecs/avif/enc/avif_enc.wasm differ