mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 18:49:50 +00:00
Update JXL library and build system
This commit is contained in:
1
codecs/jxl/.gitignore
vendored
Normal file
1
codecs/jxl/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules
|
||||||
63
codecs/jxl/Makefile
Normal file
63
codecs/jxl/Makefile
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
CODEC_URL = https://gitlab.com/wg1/jpeg-xl.git
|
||||||
|
CODEC_VERSION = 7a2f362aba73f1f7b25347737304f80acf2490ed
|
||||||
|
CODEC_DIR = node_modules/jxl
|
||||||
|
CODEC_BUILD_DIR := $(CODEC_DIR)/build
|
||||||
|
CODEC_OUT := $(CODEC_BUILD_DIR)/libjpegxl-static.a
|
||||||
|
|
||||||
|
OUT_JS = enc/jxl_enc.js dec/jxl_dec.js
|
||||||
|
OUT_WASM = $(OUT_JS:.js=.wasm)
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all: $(OUT_JS)
|
||||||
|
|
||||||
|
%.js: %.cpp $(LIBAOM_OUT) $(CODEC_OUT)
|
||||||
|
$(CXX) \
|
||||||
|
-I $(CODEC_DIR) \
|
||||||
|
-I $(CODEC_DIR)/third_party/highway \
|
||||||
|
-I $(CODEC_DIR)/third_party/brunsli \
|
||||||
|
-I $(CODEC_DIR)/third_party/brunsli/c/include \
|
||||||
|
${CXXFLAGS} \
|
||||||
|
${LDFLAGS} \
|
||||||
|
--bind \
|
||||||
|
--closure 1 \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
|
-s MODULARIZE=1 \
|
||||||
|
-s 'EXPORT_NAME="$(basename $(@F))"' \
|
||||||
|
-o $@ \
|
||||||
|
$+ \
|
||||||
|
$(CODEC_BUILD_DIR)/artifacts/libbrunslienc-static.bc \
|
||||||
|
$(CODEC_BUILD_DIR)/artifacts/libbrunslicommon-static.bc \
|
||||||
|
$(CODEC_BUILD_DIR)/artifacts/libbrunslidec-static.bc \
|
||||||
|
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlidec-static.a \
|
||||||
|
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlienc-static.a \
|
||||||
|
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlicommon-static.a \
|
||||||
|
$(CODEC_BUILD_DIR)/third_party/liblcms2.a \
|
||||||
|
$(CODEC_BUILD_DIR)/third_party/highway/libhwy.a
|
||||||
|
|
||||||
|
$(CODEC_OUT): $(CODEC_DIR)/CMakeLists.txt
|
||||||
|
mkdir -p $(CODEC_BUILD_DIR)
|
||||||
|
cd $(CODEC_BUILD_DIR) && \
|
||||||
|
emcmake cmake ../ && \
|
||||||
|
$(MAKE) jpegxl-static
|
||||||
|
|
||||||
|
|
||||||
|
$(CODEC_DIR)/CMakeLists.txt: $(CODEC_DIR)
|
||||||
|
|
||||||
|
$(CODEC_DIR):
|
||||||
|
# The JXL repository doesn’t have version tags or anything yet,
|
||||||
|
# so we have to pin to a specific commit for now. This implies we
|
||||||
|
# can’t use --recursive, as we will change commit after checkout (it
|
||||||
|
# seems you can’t clone a specific commit directly), and it also means
|
||||||
|
# we can’t use --depth 1 because we want to change commits.
|
||||||
|
# The JXL code base also relies on submodules so we can’t just download
|
||||||
|
# a .tar.gz from GitLab.
|
||||||
|
mkdir -p $@
|
||||||
|
git clone $(CODEC_URL) $@
|
||||||
|
cd $@ && \
|
||||||
|
git checkout -b squoosh-build $(CODEC_VERSION) && \
|
||||||
|
git submodule update --init --recursive
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(OUT_JS) $(OUT_WASM)
|
||||||
|
$(MAKE) -C $(CODEC_BUILD_DIR) clean
|
||||||
7569
codecs/jxl/dec/jxl_dec.js
Normal file
7569
codecs/jxl/dec/jxl_dec.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
codecs/jxl/dec/jxl_dec.wasm
Normal file
BIN
codecs/jxl/dec/jxl_dec.wasm
Normal file
Binary file not shown.
7075
codecs/jxl/enc/jxl_enc.js
Normal file
7075
codecs/jxl/enc/jxl_enc.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
codecs/jxl/enc/jxl_enc.wasm
Normal file
BIN
codecs/jxl/enc/jxl_enc.wasm
Normal file
Binary file not shown.
6
codecs/jxl/package.json
Normal file
6
codecs/jxl/package.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "jxl",
|
||||||
|
"scripts": {
|
||||||
|
"build": "../build-cpp.sh"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# JPEG XL decoder
|
|
||||||
|
|
||||||
- Source: <https://gitlab.com/wg1/jpeg-xl>
|
|
||||||
- Version: ???
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
See `example.html`
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `RawImage decode(std::string buffer)`
|
|
||||||
|
|
||||||
Decodes the given avif buffer into raw RGBA. `RawImage` is a class with 3 fields: `buffer`, `width`, and `height`.
|
|
||||||
|
|
||||||
### `void free_result()`
|
|
||||||
|
|
||||||
Frees the result created by `decode()`.
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
export OPTIMIZE="-Os"
|
|
||||||
export LDFLAGS="${OPTIMIZE}"
|
|
||||||
export CFLAGS="${OPTIMIZE}"
|
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Downloading libjxl"
|
|
||||||
echo "============================================="
|
|
||||||
test -d node_modules/jxl || (
|
|
||||||
cd node_modules
|
|
||||||
git clone --recursive https://gitlab.com/wg1/jpeg-xl.git jxl
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Downloading libjxl done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libjxl"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
test -n "$SKIP_LIBJXL" || (
|
|
||||||
cd node_modules/jxl
|
|
||||||
git submodule update --init --recursive
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
emcmake cmake ../
|
|
||||||
emmake make jpegxl-static
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libjxl done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm bindings"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
emcc \
|
|
||||||
${OPTIMIZE} \
|
|
||||||
--bind \
|
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-s MODULARIZE=1 \
|
|
||||||
-s 'EXPORT_NAME="jxl_dec"' \
|
|
||||||
-I ./node_modules/jxl \
|
|
||||||
-I ./node_modules/jxl/include \
|
|
||||||
-I ./node_modules/jxl/third_party/highway \
|
|
||||||
-o ./jxl_dec.js \
|
|
||||||
-x c++ \
|
|
||||||
--std=c++11 \
|
|
||||||
jxl_dec.cpp \
|
|
||||||
./node_modules/jxl/build/libjpegxl-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brunsli/libbrunslidec-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brunsli/libbrunslicommon-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brotli/libbrotlidec-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brotli/libbrotlicommon-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/liblcms2.bc
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm bindings done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
echo "Did you update your docker image?"
|
|
||||||
echo "Run \`docker pull trzeci/emscripten\`"
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<script src='jxl_dec.js'></script>
|
|
||||||
<script>
|
|
||||||
const Module = jxl_dec();
|
|
||||||
|
|
||||||
async function loadFile(src) {
|
|
||||||
const resp = await fetch(src);
|
|
||||||
return await resp.arrayBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
Module.onRuntimeInitialized = async _ => {
|
|
||||||
const image = await loadFile('../example.jxl');
|
|
||||||
const result = Module.decode(image);
|
|
||||||
console.log(result.width, result.height, result.buffer);
|
|
||||||
const imageData = new ImageData(new Uint8ClampedArray(result.buffer), result.width, result.height);
|
|
||||||
Module.free_result();
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = result.width;
|
|
||||||
canvas.height = result.height;
|
|
||||||
document.body.appendChild(canvas);
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
ctx.putImageData(imageData, 0, 0);
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
1211
codecs/jxl_dec/package-lock.json
generated
1211
codecs/jxl_dec/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jxl_dec",
|
|
||||||
"scripts": {
|
|
||||||
"install": "napa",
|
|
||||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
|
||||||
},
|
|
||||||
"napa": {
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"napa": "3.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# JPEG XL decoder
|
|
||||||
|
|
||||||
- Source: <https://gitlab.com/wg1/jpeg-xl>
|
|
||||||
- Version: ???
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
See `example.html`
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
### `RawImage decode(std::string buffer)`
|
|
||||||
|
|
||||||
Decodes the given avif buffer into raw RGBA. `RawImage` is a class with 3 fields: `buffer`, `width`, and `height`.
|
|
||||||
|
|
||||||
### `void free_result()`
|
|
||||||
|
|
||||||
Frees the result created by `decode()`.
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
export OPTIMIZE="-Os"
|
|
||||||
export LDFLAGS="${OPTIMIZE}"
|
|
||||||
export CFLAGS="${OPTIMIZE}"
|
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Downloading libjxl"
|
|
||||||
echo "============================================="
|
|
||||||
test -d node_modules/jxl || (
|
|
||||||
cd node_modules
|
|
||||||
git clone --recursive https://gitlab.com/wg1/jpeg-xl.git jxl
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Downloading libjxl done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libjxl"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
test -n "$SKIP_LIBJXL" || (
|
|
||||||
cd node_modules/jxl
|
|
||||||
git submodule update --init --recursive
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
emcmake cmake ../
|
|
||||||
emmake make jpegxl-static
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling libjxl done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm bindings"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
emcc \
|
|
||||||
${OPTIMIZE} \
|
|
||||||
--bind \
|
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-s MODULARIZE=1 \
|
|
||||||
-s 'EXPORT_NAME="jxl_enc"' \
|
|
||||||
-I ./node_modules/jxl \
|
|
||||||
-I ./node_modules/jxl/include \
|
|
||||||
-I ./node_modules/jxl/third_party/brunsli \
|
|
||||||
-I ./node_modules/jxl/third_party/brunsli/c/include \
|
|
||||||
-I ./node_modules/jxl/third_party/highway \
|
|
||||||
-o ./jxl_enc.js \
|
|
||||||
-x c++ \
|
|
||||||
--std=c++11 \
|
|
||||||
jxl_enc.cpp \
|
|
||||||
./node_modules/jxl/build/libjpegxl-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brunsli/libbrunslienc-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brunsli/libbrunslidec-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brunsli/libbrunslicommon-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brotli/libbrotlienc-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brotli/libbrotlidec-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/brotli/libbrotlicommon-static.bc \
|
|
||||||
./node_modules/jxl/build/third_party/liblcms2.bc \
|
|
||||||
./node_modules/jxl/build/third_party/highway/libhwy.bc
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm bindings done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
echo "Did you update your docker image?"
|
|
||||||
echo "Run \`docker pull trzeci/emscripten\`"
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const avifEnc = require("./jxl_enc.js")(fs.readFileSync("./jxl_enc.wasm"));
|
|
||||||
|
|
||||||
avifEnc.onRuntimeInitialized = () => {
|
|
||||||
const jxl = avifEnc.encode(
|
|
||||||
new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255]),
|
|
||||||
3,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
console.log(jxl)
|
|
||||||
fs.writeFileSync("lol.jxl", jxl);
|
|
||||||
};
|
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
1211
codecs/jxl_enc/package-lock.json
generated
1211
codecs/jxl_enc/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jxl_enc",
|
|
||||||
"scripts": {
|
|
||||||
"install": "napa",
|
|
||||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
|
||||||
},
|
|
||||||
"napa": {
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"napa": "3.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import jxl_dec, { JXLModule } from '../../../codecs/jxl_dec/jxl_dec';
|
import jxl_dec, { JXLModule } from '../../../codecs/jxl/dec/jxl_dec';
|
||||||
import wasmUrl from '../../../codecs/jxl_dec/jxl_dec.wasm';
|
import wasmUrl from '../../../codecs/jxl/dec/jxl_dec.wasm';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from '../util';
|
||||||
|
|
||||||
let emscriptenModule: Promise<JXLModule>;
|
let emscriptenModule: Promise<JXLModule>;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import jxl_enc, { JXLModule } from '../../../codecs/jxl_enc/jxl_enc';
|
import jxl_enc, { JXLModule } from '../../../codecs/jxl/enc/jxl_enc';
|
||||||
import wasmUrl from '../../../codecs/jxl_enc/jxl_enc.wasm';
|
import wasmUrl from '../../../codecs/jxl/enc/jxl_enc.wasm';
|
||||||
import { EncodeOptions } from './encoder-meta';
|
import { EncodeOptions } from './encoder-meta';
|
||||||
import { initEmscriptenModule } from '../util';
|
import { initEmscriptenModule } from '../util';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user