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.