Compile JXL decoder
This commit is contained in:
18
codecs/jxl_dec/README.md
Normal file
18
codecs/jxl_dec/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# 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()`.
|
69
codecs/jxl_dec/build.sh
Executable file
69
codecs/jxl_dec/build.sh
Executable file
@ -0,0 +1,69 @@
|
||||
#!/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 brunslidec-static brunslicommon-static brunslienc-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 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
24
codecs/jxl_dec/example.html
Normal file
24
codecs/jxl_dec/example.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<script src='avif_dec.js'></script>
|
||||
<script>
|
||||
const Module = avif_dec();
|
||||
|
||||
async function loadFile(src) {
|
||||
const resp = await fetch(src);
|
||||
return await resp.arrayBuffer();
|
||||
}
|
||||
|
||||
Module.onRuntimeInitialized = async _ => {
|
||||
const image = await loadFile('../example.avif');
|
||||
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>
|
BIN
codecs/jxl_dec/example.jxl
Normal file
BIN
codecs/jxl_dec/example.jxl
Normal file
Binary file not shown.
38
codecs/jxl_dec/jxl_dec.cpp
Normal file
38
codecs/jxl_dec/jxl_dec.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <emscripten/bind.h>
|
||||
#include <emscripten/val.h>
|
||||
|
||||
#include "jxl/dec_file.h"
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
class RawImage {
|
||||
public:
|
||||
val buffer;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
RawImage(val b, int w, int h) : buffer(b), width(w), height(h) {}
|
||||
};
|
||||
|
||||
val decode(std::string data) {
|
||||
jxl::Span<const uint8_t> compressed((uint8_t *)data.c_str(), data.length());
|
||||
jxl::DecompressParams dparams;
|
||||
// jxl::ThreadPool pool;
|
||||
jxl::CodecInOut io;
|
||||
jxl::AuxOut aux_out;
|
||||
|
||||
if (!DecodeFile(dparams, compressed, &io, &aux_out, NULL)) {
|
||||
printf("FAIL\n");
|
||||
}
|
||||
printf("YAY\n");
|
||||
return val(1);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(my_module) {
|
||||
class_<RawImage>("RawImage")
|
||||
.property("buffer", &RawImage::buffer)
|
||||
.property("width", &RawImage::width)
|
||||
.property("height", &RawImage::height);
|
||||
|
||||
function("decode", &decode);
|
||||
}
|
13
codecs/jxl_dec/jxl_dec.d.ts
vendored
Normal file
13
codecs/jxl_dec/jxl_dec.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
interface RawImage {
|
||||
buffer: Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface AVIFModule extends EmscriptenWasm.Module {
|
||||
decode(data: BufferSource): RawImage;
|
||||
free_result(): void;
|
||||
}
|
||||
|
||||
export default function(opts: EmscriptenWasm.ModuleOpts): AVIFModule;
|
||||
|
22
codecs/jxl_dec/jxl_dec.js
Normal file
22
codecs/jxl_dec/jxl_dec.js
Normal file
File diff suppressed because one or more lines are too long
BIN
codecs/jxl_dec/jxl_dec.wasm
Normal file
BIN
codecs/jxl_dec/jxl_dec.wasm
Normal file
Binary file not shown.
1211
codecs/jxl_dec/package-lock.json
generated
Normal file
1211
codecs/jxl_dec/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
codecs/jxl_dec/package.json
Normal file
12
codecs/jxl_dec/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "jxl_dec",
|
||||
"scripts": {
|
||||
"install": "napa",
|
||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||
},
|
||||
"napa": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"napa": "3.0.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user