diff --git a/codecs/mozjpeg_enc/Makefile b/codecs/mozjpeg_enc/Makefile index 542e0b78..bf62ffb4 100644 --- a/codecs/mozjpeg_enc/Makefile +++ b/codecs/mozjpeg_enc/Makefile @@ -2,14 +2,14 @@ CODEC_URL := https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz CODEC_DIR := node_modules/mozjpeg CODEC_OUT_RELATIVE := .libs/libjpeg.a rdswitch.o CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE)) -OUT_JS := mozjpeg_enc.js +OUT_JS := mozjpeg_enc_simd.js OUT_WASM := $(OUT_JS:.js=.wasm) CFLAGS += -msimd128 -msse --em-config /src/.emscripten CXXFLAGS += -msimd128 -msse --em-config /src/.emscripten -#override CFLAGS += "-msimd128 -msse" -#override CXXFLAGS += "-msimd128 -msse" +#CFLAGS += --em-config /src/.emscripten +#CXXFLAGS += --em-config /src/.emscripten .PHONY: all clean @@ -28,6 +28,7 @@ all: $(OUT_JS) --closure 1 \ -s ALLOW_MEMORY_GROWTH=1 \ -s MODULARIZE=1 \ + -s EXPORT_ES6=1 \ -s 'EXPORT_NAME="$(basename $(@F))"' \ -o $@ \ $+ diff --git a/codecs/mozjpeg_enc/bench.d8.js b/codecs/mozjpeg_enc/bench.d8.js new file mode 100644 index 00000000..e7d016b7 --- /dev/null +++ b/codecs/mozjpeg_enc/bench.d8.js @@ -0,0 +1,62 @@ +import mozjpeg from "./mozjpeg_enc.js"; +import mozjpegSimd from "./mozjpeg_enc_simd.js"; + +const width = 2048; +const height = 2048; +const size = width * height * 4; +const data = new Uint8ClampedArray(size); +for(let i = 0; i < size; i++) { + data[i] = Math.random() * 256; +} + +mozjpeg({ + onRuntimeInitialized() { + const start = performance.now(); + const result = this.encode(data, width, height, { + quality: 75, + baseline: false, + arithmetic: false, + progressive: true, + optimize_coding: true, + smoothing: 0, + color_space: 3, + quant_table: 3, + trellis_multipass: false, + trellis_opt_zero: false, + trellis_opt_table: false, + trellis_loops: 1, + auto_subsample: true, + chroma_subsample: 2, + separate_chroma_quality: false, + chroma_quality: 75, + }); + const end = performance.now(); + console.log("No SIMD", end - start); + } +}) + +mozjpegSimd({ + onRuntimeInitialized() { + const start = performance.now(); + const result = this.encode(data, width, height, { + quality: 75, + baseline: false, + arithmetic: false, + progressive: true, + optimize_coding: true, + smoothing: 0, + color_space: 3, + quant_table: 3, + trellis_multipass: false, + trellis_opt_zero: false, + trellis_opt_table: false, + trellis_loops: 1, + auto_subsample: true, + chroma_subsample: 2, + separate_chroma_quality: false, + chroma_quality: 75, + }); + const end = performance.now(); + console.log("SIMD", end - start); + } +}) diff --git a/codecs/mozjpeg_enc/mozjpeg_enc.cpp b/codecs/mozjpeg_enc/mozjpeg_enc.cpp index 3673db5c..27388587 100644 --- a/codecs/mozjpeg_enc/mozjpeg_enc.cpp +++ b/codecs/mozjpeg_enc/mozjpeg_enc.cpp @@ -1,7 +1,5 @@ #include #include -#include -#include #include #include #include diff --git a/codecs/mozjpeg_enc/mozjpeg_enc.js b/codecs/mozjpeg_enc/mozjpeg_enc.js index 7c6d20f6..6b69a491 100644 --- a/codecs/mozjpeg_enc/mozjpeg_enc.js +++ b/codecs/mozjpeg_enc/mozjpeg_enc.js @@ -1,7 +1,7 @@ var mozjpeg_enc = (function() { - var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; - if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; + var _scriptDir = import.meta.url; + return ( function(mozjpeg_enc) { mozjpeg_enc = mozjpeg_enc || {}; @@ -63,10 +63,4 @@ d.run=Cb;if(d.preInit)for("function"==typeof d.preInit&&(d.preInit=[d.preInit]); } ); })(); -if (typeof exports === 'object' && typeof module === 'object') - module.exports = mozjpeg_enc; - else if (typeof define === 'function' && define['amd']) - define([], function() { return mozjpeg_enc; }); - else if (typeof exports === 'object') - exports["mozjpeg_enc"] = mozjpeg_enc; - \ No newline at end of file +export default mozjpeg_enc; \ No newline at end of file diff --git a/codecs/mozjpeg_enc/mozjpeg_enc.wasm b/codecs/mozjpeg_enc/mozjpeg_enc.wasm index e6e508c2..d68572bf 100644 Binary files a/codecs/mozjpeg_enc/mozjpeg_enc.wasm and b/codecs/mozjpeg_enc/mozjpeg_enc.wasm differ