Properly split encoder and decoder

This commit is contained in:
Surma
2018-05-15 13:21:39 +01:00
parent 953a0c9124
commit ddf8409127
14 changed files with 2915 additions and 2959 deletions

View File

@@ -1,6 +1,6 @@
# Codecs
This folder contains a self-contained sub-project for each codec that squoosh supports.
This folder contains a self-contained sub-project for each encoder and decoder that squoosh supplies.
## Build
@@ -11,22 +11,6 @@ $ npm install
$ npm run build
```
This will build two files: `<codec name>_codec.js` and `<codec name>_codec.wasm`. Due to some current limitations in Emscripten, both of these files have to be served from the root folder. When the `.js` file is loaded, a global `<codec name>` is created with the same API as an [Emscripten `Module`](https://kripken.github.io/emscripten-site/docs/api_reference/module.html).
This will build two files: `<codec name>_<enc or dec>.js` and `<codec name>_<enc or dec>.wasm`. It will most likely be necessary to set [`Module["locateFile"]`](https://kripken.github.io/emscripten-site/docs/api_reference/module.html#affecting-execution) to sucessfully load the `.wasm` file. When the `.js` file is loaded, a global `<codec name>_<enc or dec>` is created with the same API as an [Emscripten `Module`](https://kripken.github.io/emscripten-site/docs/api_reference/module.html).
Each codec offers at least 2 functions:
- `void encode(uint8_t* img_in, int width, int height, float quality)`
- `void decode(???)`
Example:
```html
<!-- *_codec.{wasm,js} need to be in / -->
<script src="/mozjpeg_codec.js"></script>
<script>
mozjpeg.onRuntimeInitialized = _ => {
const encode = mozjpeg.cwrap('encode', '', ['number', 'number', 'number', 'number']);
/* ... */
};
</script>
```
Each codec will document its API in its README.

File diff suppressed because one or more lines are too long

Binary file not shown.

2
codecs/mozjpeg_enc/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/*.wasm
/*.js

View File

@@ -7,7 +7,7 @@
EMSCRIPTEN_KEEPALIVE
int version() {
return 0x030301; // Lol harcoded
return JPEG_LIB_VERSION;
}
EMSCRIPTEN_KEEPALIVE

View File

@@ -1,10 +1,10 @@
{
"name": "webp",
"name": "mozjpeg_enc",
"scripts": {
"install": "napa",
"build": "npm run build:library && npm run build:wasm",
"build:library": "cd node_modules/mozjpeg && autoreconf -fiv && docker run --rm -v $(pwd):/src trzeci/emscripten emconfigure ./configure --without-simd && docker run --rm -v $(pwd):/src trzeci/emscripten emmake make libjpeg.la",
"build:wasm": "docker run --rm -v $(pwd):/src trzeci/emscripten emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"mozjpeg\"' -I node_modules/mozjpeg -o ./mozjpeg_codec.js mozjpeg.c node_modules/mozjpeg/.libs/libjpeg.a"
"build:wasm": "docker run --rm -v $(pwd):/src trzeci/emscripten emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"mozjpeg_enc\"' -I node_modules/mozjpeg -o ./mozjpeg_enc.js mozjpeg_enc.c node_modules/mozjpeg/.libs/libjpeg.a"
},
"napa": {
"mozjpeg": "mozilla/mozjpeg#v3.3.1"

File diff suppressed because one or more lines are too long

Binary file not shown.

2
codecs/webp_enc/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/*.wasm
/*.js

View File

@@ -1,8 +1,8 @@
{
"name": "webp",
"name": "webp_enc",
"scripts": {
"install": "napa",
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"webp\"' -I node_modules/libwebp -o ./webp_codec.js webp.c node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c"
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]' -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"webp_enc\"' -I node_modules/libwebp -o ./webp_enc.js webp_enc.c node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c"
},
"napa": {
"libwebp": "webmproject/libwebp#v0.6.1"