mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Add Node 14 for SIMD tests
This commit is contained in:
@@ -5,5 +5,7 @@ ENV CXXFLAGS "${CFLAGS} -std=c++17"
|
||||
ENV LDFLAGS "${CFLAGS}"
|
||||
# Build and cache standard libraries with these flags
|
||||
RUN emcc ${CXXFLAGS} --bind -xc++ /dev/null -o /dev/null
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
|
||||
RUN /bin/bash -ic 'nvm install 14.7.0'
|
||||
WORKDIR /src
|
||||
CMD ["sh", "-c", "emmake make -j`nproc`"]
|
||||
|
||||
13
codecs/mozjpeg_enc/.emscripten
Normal file
13
codecs/mozjpeg_enc/.emscripten
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
emsdk_path = "/emsdk/"
|
||||
#NODE_JS = emsdk_path + '/node/12.18.1_64bit/bin/node'
|
||||
# We need a newer version of Node that supports the most recent iteration of Wasm SIMD
|
||||
# and need to enable that experimental support via flag so that autoconf can successfully
|
||||
# detect SIMD support.
|
||||
NODE_JS=["/root/.nvm/versions/node/v14.7.0/bin/node", "--experimental-wasm-simd"]
|
||||
LLVM_ROOT = emsdk_path + '/upstream/bin'
|
||||
BINARYEN_ROOT = emsdk_path + '/upstream'
|
||||
EMSCRIPTEN_ROOT = emsdk_path + '/upstream/emscripten'
|
||||
TEMP_DIR = emsdk_path + '/tmp'
|
||||
COMPILER_ENGINE = NODE_JS
|
||||
JS_ENGINES = [NODE_JS]
|
||||
@@ -5,11 +5,21 @@ CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
|
||||
OUT_JS := mozjpeg_enc.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"
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUT_JS)
|
||||
|
||||
%.js: %.cpp $(CODEC_OUT)
|
||||
# We just to disable the overridden NODE_JS binary because
|
||||
# `--closure 1` can’t handle arrays in `.emscripten` it seems.
|
||||
# https://github.com/emscripten-core/emsdk/issues/583
|
||||
export EM_NODE_JS='/root/.nvm/versions/node/v14.7.0/bin/node' && \
|
||||
$(CXX) \
|
||||
-I $(CODEC_DIR) \
|
||||
${CXXFLAGS} \
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
<!doctype html>
|
||||
<script src='mozjpeg_enc.js'></script>
|
||||
<script>
|
||||
const module = mozjpeg_enc();
|
||||
|
||||
async function loadImage(src) {
|
||||
// Load image
|
||||
const img = document.createElement('img');
|
||||
img.src = src;
|
||||
await new Promise(resolve => img.onload = resolve);
|
||||
// Make canvas same size as image
|
||||
const canvas = document.createElement('canvas');
|
||||
[canvas.width, canvas.height] = [img.width, img.height];
|
||||
// Draw image onto canvas
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
return ctx.getImageData(0, 0, img.width, img.height);
|
||||
}
|
||||
|
||||
module.onRuntimeInitialized = async _ => {
|
||||
console.log('Version:', module.version().toString(16));
|
||||
const module = mozjpeg_enc({
|
||||
loadFile() {
|
||||
return "./mozjpeg_enc.wasm";
|
||||
},
|
||||
async onRuntimeInitialized() {
|
||||
//console.log('Version:', module.version().toString(16));
|
||||
const image = await loadImage('../example.png');
|
||||
const result = module.encode(image.data, image.width, image.height, {
|
||||
const result = this.encode(image.data, image.width, image.height, {
|
||||
quality: 75,
|
||||
baseline: false,
|
||||
arithmetic: false,
|
||||
@@ -44,5 +32,21 @@
|
||||
const img = document.createElement('img');
|
||||
img.src = blobURL;
|
||||
document.body.appendChild(img);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
async function loadImage(src) {
|
||||
// Load image
|
||||
const img = document.createElement('img');
|
||||
img.src = src;
|
||||
await new Promise(resolve => img.onload = resolve);
|
||||
// Make canvas same size as image
|
||||
const canvas = document.createElement('canvas');
|
||||
[canvas.width, canvas.height] = [img.width, img.height];
|
||||
// Draw image onto canvas
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
return ctx.getImageData(0, 0, img.width, img.height);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <emscripten/bind.h>
|
||||
#include <emscripten/val.h>
|
||||
#include <wasm_simd128.h>
|
||||
#include <xmmintrin.h>
|
||||
#include <inttypes.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user