mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 16:57:26 +00:00
Compare commits
3 Commits
normalize-
...
android-ta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b5bfebf3c | ||
|
|
01885dbbc1 | ||
|
|
556a98cb32 |
36
.babelrc
36
.babelrc
@@ -1,38 +1,12 @@
|
|||||||
{
|
{
|
||||||
"presets": [
|
|
||||||
[
|
|
||||||
"@babel/preset-typescript",
|
|
||||||
{
|
|
||||||
"jsxPragma": "h"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@parcel/babel-preset-env",
|
|
||||||
{
|
|
||||||
"loose": true,
|
|
||||||
"bugfixes": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"transform-class-properties",
|
||||||
|
"transform-react-constant-elements",
|
||||||
|
"transform-react-remove-prop-types",
|
||||||
[
|
[
|
||||||
"@babel/plugin-transform-react-jsx",
|
"transform-react-jsx",
|
||||||
{
|
{
|
||||||
"loose": true,
|
"pragma": "h"
|
||||||
"pragma": "h",
|
|
||||||
"pragmaFrag": "Fragment"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@babel/plugin-proposal-decorators",
|
|
||||||
{
|
|
||||||
"legacy": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@babel/plugin-proposal-class-properties",
|
|
||||||
{
|
|
||||||
"loose": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
BasedOnStyle: Chromium
|
|
||||||
ColumnLimit: 100
|
|
||||||
36
.github/ISSUE_TEMPLATE/bug_report.md
vendored
36
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Something is not working as expected
|
|
||||||
labels:
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Before you start**
|
|
||||||
Please take a look at the [FAQ](https://github.com/GoogleChromeLabs/squoosh/wiki/FAQ) as well as the already opened issues! If nothing fits your problem, go ahead and fill out the following template:
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Version:**
|
|
||||||
- OS w/ version: [e.g. iOS 12]
|
|
||||||
- Browser w/ version [e.g. Chrome 70]
|
|
||||||
- Node version: [e.g. 10.11.0]
|
|
||||||
- npm version: [e.g. 6.4.1]
|
|
||||||
|
|
||||||
**Is your issue related to the quality of image compression?**
|
|
||||||
Please attach original and output images (you can drag & drop to attach).
|
|
||||||
- Original image
|
|
||||||
- Output image from Squoosh
|
|
||||||
|
|
||||||
**Additional context, screenshots, screencasts**
|
|
||||||
Add any other context about the problem here.
|
|
||||||
18
.github/ISSUE_TEMPLATE/feature_request.md
vendored
18
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,18 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
labels:
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Does other service/app have this feature?**
|
|
||||||
Add any service you know/use that has this feature (We want to know for research)
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,6 +4,3 @@ node_modules
|
|||||||
*.scss.d.ts
|
*.scss.d.ts
|
||||||
*.css.d.ts
|
*.css.d.ts
|
||||||
*.o
|
*.o
|
||||||
.parcel-cache
|
|
||||||
.cache
|
|
||||||
/public
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "@parcel/config-default",
|
|
||||||
"transformers": {
|
|
||||||
"*.wasm": ["@parcel/transformer-raw"]
|
|
||||||
},
|
|
||||||
"packagers": {
|
|
||||||
"*.wasm": "@parcel/packager-raw"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
.proxyrc.js
15
.proxyrc.js
@@ -1,15 +0,0 @@
|
|||||||
module.exports = function(app) {
|
|
||||||
// `app` is an Express instance
|
|
||||||
app.use(function(req, res, next) {
|
|
||||||
const sh = res.setHeader;
|
|
||||||
res.setHeader = function(key, value) {
|
|
||||||
// remove pointless/incorrect charset from binary responses:
|
|
||||||
if (/^content-type$/i.test(key)) {
|
|
||||||
const m = value && value.match(/^(image\/|application\/wasm); charset=.+$/);
|
|
||||||
if (m) value = m[1];
|
|
||||||
}
|
|
||||||
return sh.call(this, key, value);
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- node
|
||||||
cache: npm
|
cache: npm
|
||||||
script: npm run build
|
script: npm run build || npm run build # scss ts definitions need to be generated before an actual build
|
||||||
after_success: npm run sizereport
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- windows
|
|
||||||
|
|||||||
33
README.md
33
README.md
@@ -1,32 +1,5 @@
|
|||||||
# [Squoosh]!
|
# Squoosh!
|
||||||
|
|
||||||
[Squoosh] is an image compression web app that allows you to dive into the advanced options provided
|
Squoosh will be an image compression web app that allows you to dive into the
|
||||||
by various image compressors.
|
advanced options provided by various image compressors.
|
||||||
|
|
||||||
# Privacy
|
|
||||||
|
|
||||||
Google Analytics is used to record the following:
|
|
||||||
|
|
||||||
* [Basic visit data](https://support.google.com/analytics/answer/6004245?ref_topic=2919631).
|
|
||||||
* Before and after image size once an image is downloaded. These values are rounded to the nearest
|
|
||||||
kilobyte.
|
|
||||||
* If install is available, when Squoosh is installed, and what method was used to install Squoosh.
|
|
||||||
|
|
||||||
Image compression is handled locally; no additional data is sent to the server.
|
|
||||||
|
|
||||||
# Building locally
|
|
||||||
|
|
||||||
Clone the repo, and:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
You can run the development server with:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm start
|
|
||||||
```
|
|
||||||
|
|
||||||
[Squoosh]: https://squoosh.app
|
|
||||||
|
|||||||
18
_headers.ejs
18
_headers.ejs
@@ -1,18 +0,0 @@
|
|||||||
# Long-term cache by default.
|
|
||||||
/*
|
|
||||||
Cache-Control: max-age=31536000
|
|
||||||
|
|
||||||
# And here are the exceptions:
|
|
||||||
/
|
|
||||||
Cache-Control: no-cache
|
|
||||||
|
|
||||||
/serviceworker.js
|
|
||||||
Cache-Control: no-cache
|
|
||||||
|
|
||||||
/manifest.json
|
|
||||||
Cache-Control: must-revalidate, max-age=3600
|
|
||||||
|
|
||||||
# URLs in /assets do not include a hash and are mutable.
|
|
||||||
# But it isn't a big deal if the user gets an old version.
|
|
||||||
/assets/*
|
|
||||||
Cache-Control: must-revalidate, max-age=3600
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
/index.html / 301
|
|
||||||
/* /index.html 301
|
|
||||||
@@ -11,6 +11,6 @@ $ npm install
|
|||||||
$ npm run build
|
$ npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
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 successfully 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).
|
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 will document its API in its README.
|
Each codec will document its API in its README.
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh -e
|
|
||||||
docker build -t squoosh-cpp - < ../cpp.Dockerfile
|
|
||||||
docker run --rm -v $PWD:/src squoosh-cpp
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
set -e
|
|
||||||
|
|
||||||
docker build -t squoosh-rust - < ../rust.Dockerfile
|
|
||||||
docker run --rm -v $PWD:/src squoosh-rust "$@"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
FROM emscripten/emsdk:1.39.19
|
|
||||||
RUN apt-get update && apt-get install -qqy autoconf libtool pkg-config
|
|
||||||
ENV CFLAGS "-Os -flto"
|
|
||||||
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
|
|
||||||
WORKDIR /src
|
|
||||||
CMD ["sh", "-c", "emmake make -j`nproc`"]
|
|
||||||
1
codecs/hqx/.gitignore
vendored
1
codecs/hqx/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/target
|
|
||||||
289
codecs/hqx/Cargo.lock
generated
289
codecs/hqx/Cargo.lock
generated
@@ -1,289 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
[[package]]
|
|
||||||
name = "bumpalo"
|
|
||||||
version = "3.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console_error_panic_hook"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures"
|
|
||||||
version = "0.1.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hqx"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2#5f19cda24191ccc7c0c4920b6b246b4e242f377c"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "js-sys"
|
|
||||||
version = "0.3.42"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.73"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memory_units"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "0.4.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "0.6.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scoped-tls"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "squooshhqx"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"hqx 0.1.0 (git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2)",
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wee_alloc 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.35"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen"
|
|
||||||
version = "0.2.65"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-macro 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-backend"
|
|
||||||
version = "0.2.65"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-futures"
|
|
||||||
version = "0.3.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"web-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro"
|
|
||||||
version = "0.2.65"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-macro-support 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro-support"
|
|
||||||
version = "0.2.65"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-backend 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-shared"
|
|
||||||
version = "0.2.65"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-test"
|
|
||||||
version = "0.2.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-test-macro"
|
|
||||||
version = "0.2.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "web-sys"
|
|
||||||
version = "0.3.42"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wee_alloc"
|
|
||||||
version = "0.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[metadata]
|
|
||||||
"checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
|
|
||||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
|
||||||
"checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
|
|
||||||
"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
|
|
||||||
"checksum hqx 0.1.0 (git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2)" = "<none>"
|
|
||||||
"checksum js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
|
|
||||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
"checksum libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)" = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
|
|
||||||
"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
|
|
||||||
"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
|
|
||||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
|
||||||
"checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
|
||||||
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
|
||||||
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
|
||||||
"checksum scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
|
|
||||||
"checksum syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0"
|
|
||||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
|
||||||
"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
|
||||||
"checksum wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
|
|
||||||
"checksum wasm-bindgen-backend 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
|
|
||||||
"checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
|
|
||||||
"checksum wasm-bindgen-macro 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
|
|
||||||
"checksum wasm-bindgen-macro-support 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
|
|
||||||
"checksum wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
|
|
||||||
"checksum wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
|
|
||||||
"checksum wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
|
|
||||||
"checksum web-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
|
|
||||||
"checksum wee_alloc 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
|
|
||||||
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "squooshhqx"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Surma <surma@surma.link>"]
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["console_error_panic_hook", "wee_alloc"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
cfg-if = "0.1.2"
|
|
||||||
wasm-bindgen = "0.2.38"
|
|
||||||
# lazy_static = "1.0.0"
|
|
||||||
hqx = {git = "https://github.com/CryZe/wasmboy-rs", tag="v0.1.2"}
|
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
|
||||||
# logging them with `console.error`. This is great for development, but requires
|
|
||||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
|
||||||
# code size when deploying.
|
|
||||||
console_error_panic_hook = { version = "0.1.1", optional = true }
|
|
||||||
|
|
||||||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
|
|
||||||
# compared to the default allocator's ~10K. It is slower than the default
|
|
||||||
# allocator, however.
|
|
||||||
#
|
|
||||||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
|
||||||
wee_alloc = { version = "0.4.2", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
wasm-bindgen-test = "0.2"
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
# Tell `rustc` to optimize for small code size.
|
|
||||||
opt-level = "s"
|
|
||||||
lto = true
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# This is intentionally an old version of Rust. Newer versions
|
|
||||||
# generate _significantly_ bigger Wasm binaries.
|
|
||||||
FROM rust:1.37
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
|
||||||
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
||||||
|
|
||||||
RUN mkdir /opt/binaryen && \
|
|
||||||
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.38.32/binaryen-1.38.32-x86-linux.tar.gz | tar -xzf - -C /opt/binaryen --strip 1
|
|
||||||
|
|
||||||
ENV PATH="/opt/binaryen:${PATH}"
|
|
||||||
WORKDIR /src
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm"
|
|
||||||
echo "============================================="
|
|
||||||
(
|
|
||||||
wasm-pack build -- --verbose --locked
|
|
||||||
rm pkg/.gitignore
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
echo "Did you update your docker image?"
|
|
||||||
echo "Run \`docker pull ubuntu\`"
|
|
||||||
echo "Run \`docker pull rust\`"
|
|
||||||
echo "Run \`docker build -t squoosh-hqx .\`"
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
4
codecs/hqx/package-lock.json
generated
4
codecs/hqx/package-lock.json
generated
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "hqx",
|
|
||||||
"lockfileVersion": 1
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "hqx",
|
|
||||||
"scripts": {
|
|
||||||
"build:image": "docker build -t squoosh-hqx - < Dockerfile",
|
|
||||||
"build": "docker run --rm -v $(pwd):/src squoosh-hqx ./build.sh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "squooshhqx",
|
|
||||||
"collaborators": [
|
|
||||||
"Surma <surma@surma.link>"
|
|
||||||
],
|
|
||||||
"version": "0.1.0",
|
|
||||||
"files": [
|
|
||||||
"squooshhqx_bg.wasm",
|
|
||||||
"squooshhqx.js",
|
|
||||||
"squooshhqx.d.ts"
|
|
||||||
],
|
|
||||||
"module": "squooshhqx.js",
|
|
||||||
"types": "squooshhqx.d.ts",
|
|
||||||
"sideEffects": false
|
|
||||||
}
|
|
||||||
10
codecs/hqx/pkg/squooshhqx.d.ts
vendored
10
codecs/hqx/pkg/squooshhqx.d.ts
vendored
@@ -1,10 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* @param {Uint32Array} input_image
|
|
||||||
* @param {number} input_width
|
|
||||||
* @param {number} input_height
|
|
||||||
* @param {number} factor
|
|
||||||
* @returns {Uint32Array}
|
|
||||||
*/
|
|
||||||
export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import * as wasm from "./squooshhqx_bg.wasm";
|
|
||||||
export * from "./squooshhqx_bg.js";
|
|
||||||
6
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
6
codecs/hqx/pkg/squooshhqx_bg.d.ts
vendored
@@ -1,6 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
export const memory: WebAssembly.Memory;
|
|
||||||
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import * as wasm from './squooshhqx_bg.wasm';
|
|
||||||
|
|
||||||
let cachegetUint32Memory0 = null;
|
|
||||||
function getUint32Memory0() {
|
|
||||||
if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetUint32Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
|
||||||
|
|
||||||
function passArray32ToWasm0(arg, malloc) {
|
|
||||||
const ptr = malloc(arg.length * 4);
|
|
||||||
getUint32Memory0().set(arg, ptr / 4);
|
|
||||||
WASM_VECTOR_LEN = arg.length;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachegetInt32Memory0 = null;
|
|
||||||
function getInt32Memory0() {
|
|
||||||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetInt32Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getArrayU32FromWasm0(ptr, len) {
|
|
||||||
return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param {Uint32Array} input_image
|
|
||||||
* @param {number} input_width
|
|
||||||
* @param {number} input_height
|
|
||||||
* @param {number} factor
|
|
||||||
* @returns {Uint32Array}
|
|
||||||
*/
|
|
||||||
export function resize(input_image, input_width, input_height, factor) {
|
|
||||||
var ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
|
|
||||||
var len0 = WASM_VECTOR_LEN;
|
|
||||||
wasm.resize(8, ptr0, len0, input_width, input_height, factor);
|
|
||||||
var r0 = getInt32Memory0()[8 / 4 + 0];
|
|
||||||
var r1 = getInt32Memory0()[8 / 4 + 1];
|
|
||||||
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
||||||
wasm.__wbindgen_free(r0, r1 * 4);
|
|
||||||
return v1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,55 +0,0 @@
|
|||||||
extern crate cfg_if;
|
|
||||||
extern crate hqx;
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
|
||||||
// allocator.
|
|
||||||
if #[cfg(feature = "wee_alloc")] {
|
|
||||||
extern crate wee_alloc;
|
|
||||||
#[global_allocator]
|
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn resize(
|
|
||||||
input_image: Vec<u32>,
|
|
||||||
input_width: usize,
|
|
||||||
input_height: usize,
|
|
||||||
factor: usize,
|
|
||||||
) -> Vec<u32> {
|
|
||||||
let num_output_pixels = input_width * input_height * factor * factor;
|
|
||||||
let mut output_image = Vec::<u32>::with_capacity(num_output_pixels * 4);
|
|
||||||
output_image.resize(num_output_pixels, 0);
|
|
||||||
|
|
||||||
match factor {
|
|
||||||
2 => hqx::hq2x(
|
|
||||||
input_image.as_slice(),
|
|
||||||
output_image.as_mut_slice(),
|
|
||||||
input_width,
|
|
||||||
input_height,
|
|
||||||
),
|
|
||||||
3 => hqx::hq3x(
|
|
||||||
input_image.as_slice(),
|
|
||||||
output_image.as_mut_slice(),
|
|
||||||
input_width,
|
|
||||||
input_height,
|
|
||||||
),
|
|
||||||
4 => hqx::hq4x(
|
|
||||||
input_image.as_slice(),
|
|
||||||
output_image.as_mut_slice(),
|
|
||||||
input_width,
|
|
||||||
input_height,
|
|
||||||
),
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return output_image;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
use cfg_if::cfg_if;
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
// When the `console_error_panic_hook` feature is enabled, we can call the
|
|
||||||
// `set_panic_hook` function at least once during initialization, and then
|
|
||||||
// we will get better error messages if our code ever panics.
|
|
||||||
//
|
|
||||||
// For more details see
|
|
||||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
|
||||||
if #[cfg(feature = "console_error_panic_hook")] {
|
|
||||||
extern crate console_error_panic_hook;
|
|
||||||
pub use self::console_error_panic_hook::set_once as set_panic_hook;
|
|
||||||
} else {
|
|
||||||
#[inline]
|
|
||||||
pub fn set_panic_hook() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
CODEC_URL := https://github.com/ImageOptim/libimagequant/archive/2.12.1.tar.gz
|
|
||||||
CODEC_DIR := node_modules/libimagequant
|
|
||||||
CODEC_OUT_RELATIVE := libimagequant.a
|
|
||||||
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
|
|
||||||
OUT_JS := imagequant.js
|
|
||||||
OUT_WASM := $(OUT_JS:.js=.wasm)
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
all: $(OUT_JS)
|
|
||||||
|
|
||||||
%.js: %.cpp $(CODEC_OUT)
|
|
||||||
$(CXX) \
|
|
||||||
-I $(CODEC_DIR) \
|
|
||||||
${CXXFLAGS} \
|
|
||||||
${LDFLAGS} \
|
|
||||||
--bind \
|
|
||||||
--closure 1 \
|
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-s MODULARIZE=1 \
|
|
||||||
-s 'EXPORT_NAME="$(basename $(@F))"' \
|
|
||||||
-o $@ \
|
|
||||||
$+
|
|
||||||
|
|
||||||
$(CODEC_OUT): $(CODEC_DIR)/config.mk
|
|
||||||
$(MAKE) -C $(CODEC_DIR) $(CODEC_OUT_RELATIVE)
|
|
||||||
|
|
||||||
$(CODEC_DIR)/config.mk: $(CODEC_DIR)/configure
|
|
||||||
cd $(CODEC_DIR) && ./configure \
|
|
||||||
--disable-sse
|
|
||||||
|
|
||||||
$(CODEC_DIR)/configure: $(CODEC_DIR)
|
|
||||||
|
|
||||||
$(CODEC_DIR):
|
|
||||||
mkdir -p $@
|
|
||||||
curl -sL $(CODEC_URL) | tar xz --strip 1 -C $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(OUT_JS) $(OUT_WASM)
|
|
||||||
$(MAKE) -C $(CODEC_DIR) clean
|
|
||||||
@@ -24,3 +24,7 @@ Quantizes the given images, using at most `numColors`, a value between 2 and 256
|
|||||||
### `RawImage zx_quantize(std::string buffer, int image_width, int image_height, float dithering)`
|
### `RawImage zx_quantize(std::string buffer, int image_width, int image_height, float dithering)`
|
||||||
|
|
||||||
???
|
???
|
||||||
|
|
||||||
|
### `void free_result()`
|
||||||
|
|
||||||
|
Frees the result created by `quantize()`.
|
||||||
|
|||||||
48
codecs/imagequant/build.sh
Executable file
48
codecs/imagequant/build.sh
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export OPTIMIZE="-Os"
|
||||||
|
export LDFLAGS="${OPTIMIZE}"
|
||||||
|
export CFLAGS="${OPTIMIZE}"
|
||||||
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libimagequant"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
emcc \
|
||||||
|
--bind \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
|
-s MODULARIZE=1 \
|
||||||
|
-s 'EXPORT_NAME="imagequant"' \
|
||||||
|
-I node_modules/libimagequant \
|
||||||
|
--std=c99 \
|
||||||
|
-c \
|
||||||
|
node_modules/libimagequant/{libimagequant,pam,mediancut,blur,mempool,kmeans,nearest}.c
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling wasm module"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
emcc \
|
||||||
|
--bind \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
|
-s MODULARIZE=1 \
|
||||||
|
-s 'EXPORT_NAME="imagequant"' \
|
||||||
|
-I node_modules/libimagequant \
|
||||||
|
-o ./imagequant.js \
|
||||||
|
--std=c++11 *.o \
|
||||||
|
-x c++ \
|
||||||
|
imagequant.cpp
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling wasm module done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
echo "Did you update your docker image?"
|
||||||
|
echo "Run \`docker pull trzeci/emscripten\`"
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
// const rawImage = Module.quantize(image.data, image.width, image.height, 256, 1.0);
|
// const rawImage = Module.quantize(image.data, image.width, image.height, 256, 1.0);
|
||||||
const rawImage = Module.zx_quantize(image.data, image.width, image.height, 1.0);
|
const rawImage = Module.zx_quantize(image.data, image.width, image.height, 1.0);
|
||||||
console.log('done');
|
console.log('done');
|
||||||
|
Module.free_result();
|
||||||
|
|
||||||
const imageData = new ImageData(new Uint8ClampedArray(rawImage.buffer), rawImage.width, rawImage.height);
|
const imageData = new ImageData(new Uint8ClampedArray(rawImage.buffer), rawImage.width, rawImage.height);
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
|||||||
@@ -1,87 +1,95 @@
|
|||||||
#include <emscripten/bind.h>
|
#include "emscripten/bind.h"
|
||||||
#include <emscripten/val.h>
|
#include "emscripten/val.h"
|
||||||
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "libimagequant.h"
|
#include "libimagequant.h"
|
||||||
|
|
||||||
using namespace emscripten;
|
using namespace emscripten;
|
||||||
|
|
||||||
int version() {
|
int version() {
|
||||||
return (((LIQ_VERSION / 10000) % 100) << 16) | (((LIQ_VERSION / 100) % 100) << 8) |
|
return (((LIQ_VERSION/10000) % 100) << 16) |
|
||||||
(((LIQ_VERSION / 1) % 100) << 0);
|
(((LIQ_VERSION/100 ) % 100) << 8) |
|
||||||
|
(((LIQ_VERSION/1 ) % 100) << 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local const val Uint8ClampedArray = val::global("Uint8ClampedArray");
|
class RawImage {
|
||||||
|
public:
|
||||||
|
val buffer;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
#define liq_ptr(T) std::unique_ptr<T, std::integral_constant<decltype(&T##_destroy), T##_destroy>>
|
RawImage(val b, int w, int h)
|
||||||
|
: buffer(b), width(w), height(h) {}
|
||||||
|
};
|
||||||
|
|
||||||
using liq_attr_ptr = liq_ptr(liq_attr);
|
|
||||||
using liq_image_ptr = liq_ptr(liq_image);
|
|
||||||
using liq_result_ptr = liq_ptr(liq_result);
|
|
||||||
|
|
||||||
liq_result_ptr liq_image_quantize(liq_image* image, liq_attr* attr) {
|
liq_attr *attr;
|
||||||
liq_result* res = nullptr;
|
liq_image *image;
|
||||||
liq_image_quantize(image, attr, &res);
|
liq_result *res;
|
||||||
return liq_result_ptr(res);
|
uint8_t* result;
|
||||||
}
|
RawImage quantize(std::string rawimage, int image_width, int image_height, int num_colors, float dithering) {
|
||||||
|
const uint8_t* image_buffer = (uint8_t*)rawimage.c_str();
|
||||||
val quantize(std::string rawimage,
|
|
||||||
int image_width,
|
|
||||||
int image_height,
|
|
||||||
int num_colors,
|
|
||||||
float dithering) {
|
|
||||||
auto image_buffer = (const liq_color*)rawimage.c_str();
|
|
||||||
int size = image_width * image_height;
|
int size = image_width * image_height;
|
||||||
liq_attr_ptr attr(liq_attr_create());
|
attr = liq_attr_create();
|
||||||
liq_image_ptr image(
|
image = liq_image_create_rgba(attr, image_buffer, image_width, image_height, 0);
|
||||||
liq_image_create_rgba(attr.get(), image_buffer, image_width, image_height, 0));
|
liq_set_max_colors(attr, num_colors);
|
||||||
liq_set_max_colors(attr.get(), num_colors);
|
liq_image_quantize(image, attr, &res);
|
||||||
auto res = liq_image_quantize(image.get(), attr.get());
|
liq_set_dithering_level(res, dithering);
|
||||||
liq_set_dithering_level(res.get(), dithering);
|
uint8_t* image8bit = (uint8_t*) malloc(size);
|
||||||
std::vector<uint8_t> image8bit(size);
|
result = (uint8_t*) malloc(size * 4);
|
||||||
std::vector<liq_color> result(size);
|
liq_write_remapped_image(res, image, image8bit, size);
|
||||||
liq_write_remapped_image(res.get(), image.get(), image8bit.data(), image8bit.size());
|
const liq_palette *pal = liq_get_palette(res);
|
||||||
auto pal = liq_get_palette(res.get());
|
|
||||||
// Turn palletted image back into an RGBA image
|
// Turn palletted image back into an RGBA image
|
||||||
for (int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
result[i] = pal->entries[image8bit[i]];
|
result[i * 4 + 0] = pal->entries[image8bit[i]].r;
|
||||||
|
result[i * 4 + 1] = pal->entries[image8bit[i]].g;
|
||||||
|
result[i * 4 + 2] = pal->entries[image8bit[i]].b;
|
||||||
|
result[i * 4 + 3] = pal->entries[image8bit[i]].a;
|
||||||
}
|
}
|
||||||
return Uint8ClampedArray.new_(
|
free(image8bit);
|
||||||
typed_memory_view(result.size() * sizeof(liq_color), (const uint8_t*)result.data()));
|
liq_result_destroy(res);
|
||||||
|
liq_image_destroy(image);
|
||||||
|
liq_attr_destroy(attr);
|
||||||
|
return {
|
||||||
|
val(typed_memory_view(image_width*image_height*4, result)),
|
||||||
|
image_width,
|
||||||
|
image_height
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const liq_color zx_colors[] = {
|
const liq_color zx_colors[] = {
|
||||||
{.r = 0, .g = 0, .b = 0, .a = 255}, // regular black
|
{.a = 255, .r = 0, .g = 0, .b = 0}, // regular black
|
||||||
{.r = 0, .g = 0, .b = 215, .a = 255}, // regular blue
|
{.a = 255, .r = 0, .g = 0, .b = 215}, // regular blue
|
||||||
{.r = 215, .g = 0, .b = 0, .a = 255}, // regular red
|
{.a = 255, .r = 215, .g = 0, .b = 0}, // regular red
|
||||||
{.r = 215, .g = 0, .b = 215, .a = 255}, // regular magenta
|
{.a = 255, .r = 215, .g = 0, .b = 215}, // regular magenta
|
||||||
{.r = 0, .g = 215, .b = 0, .a = 255}, // regular green
|
{.a = 255, .r = 0, .g = 215, .b = 0}, // regular green
|
||||||
{.r = 0, .g = 215, .b = 215, .a = 255}, // regular cyan
|
{.a = 255, .r = 0, .g = 215, .b = 215}, // regular cyan
|
||||||
{.r = 215, .g = 215, .b = 0, .a = 255}, // regular yellow
|
{.a = 255, .r = 215, .g = 215, .b = 0}, // regular yellow
|
||||||
{.r = 215, .g = 215, .b = 215, .a = 255}, // regular white
|
{.a = 255, .r = 215, .g = 215, .b = 215}, // regular white
|
||||||
{.r = 0, .g = 0, .b = 255, .a = 255}, // bright blue
|
{.a = 255, .r = 0, .g = 0, .b = 255}, // bright blue
|
||||||
{.r = 255, .g = 0, .b = 0, .a = 255}, // bright red
|
{.a = 255, .r = 255, .g = 0, .b = 0}, // bright red
|
||||||
{.r = 255, .g = 0, .b = 255, .a = 255}, // bright magenta
|
{.a = 255, .r = 255, .g = 0, .b = 255}, // bright magenta
|
||||||
{.r = 0, .g = 255, .b = 0, .a = 255}, // bright green
|
{.a = 255, .r = 0, .g = 255, .b = 0}, // bright green
|
||||||
{.r = 0, .g = 255, .b = 255, .a = 255}, // bright cyan
|
{.a = 255, .r = 0, .g = 255, .b = 255}, // bright cyan
|
||||||
{.r = 255, .g = 255, .b = 0, .a = 255}, // bright yellow
|
{.a = 255, .r = 255, .g = 255, .b = 0}, // bright yellow
|
||||||
{.r = 255, .g = 255, .b = 255, .a = 255} // bright white
|
{.a = 255, .r = 255, .g = 255, .b = 255} // bright white
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t block[8 * 8 * 4];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ZX has one bit per pixel, but can assign two colours to an 8x8 block. The
|
* The ZX has one bit per pixel, but can assign two colours to an 8x8 block. The two colours must
|
||||||
* two colours must both be 'regular' or 'bright'. Black exists as both regular
|
* both be 'regular' or 'bright'. Black exists as both regular and bright.
|
||||||
* and bright.
|
|
||||||
*/
|
*/
|
||||||
val zx_quantize(std::string rawimage, int image_width, int image_height, float dithering) {
|
RawImage zx_quantize(std::string rawimage, int image_width, int image_height, float dithering) {
|
||||||
auto image_buffer = (const liq_color*)rawimage.c_str();
|
const uint8_t* image_buffer = (uint8_t*) rawimage.c_str();
|
||||||
int size = image_width * image_height;
|
int size = image_width * image_height;
|
||||||
liq_color block[8 * 8];
|
int bytes_per_pixel = 4;
|
||||||
uint8_t image8bit[8 * 8];
|
result = (uint8_t*) malloc(size * bytes_per_pixel);
|
||||||
std::vector<liq_color> result(size);
|
uint8_t* image8bit = (uint8_t*) malloc(8 * 8);
|
||||||
|
|
||||||
// For each 8x8 grid
|
// For each 8x8 grid
|
||||||
for (int block_start_y = 0; block_start_y < image_height; block_start_y += 8) {
|
for (int block_start_y = 0; block_start_y < image_height; block_start_y += 8) {
|
||||||
@@ -91,8 +99,7 @@ val zx_quantize(std::string rawimage, int image_width, int image_height, float d
|
|||||||
int block_width = 8;
|
int block_width = 8;
|
||||||
int block_height = 8;
|
int block_height = 8;
|
||||||
|
|
||||||
// If the block hangs off the right/bottom of the image dimensions, make
|
// If the block hangs off the right/bottom of the image dimensions, make it smaller to fit.
|
||||||
// it smaller to fit.
|
|
||||||
if (block_start_y + block_height > image_height) {
|
if (block_start_y + block_height > image_height) {
|
||||||
block_height = image_height - block_start_y;
|
block_height = image_height - block_start_y;
|
||||||
}
|
}
|
||||||
@@ -104,22 +111,26 @@ val zx_quantize(std::string rawimage, int image_width, int image_height, float d
|
|||||||
// For each pixel in that block:
|
// For each pixel in that block:
|
||||||
for (int y = block_start_y; y < block_start_y + block_height; y++) {
|
for (int y = block_start_y; y < block_start_y + block_height; y++) {
|
||||||
for (int x = block_start_x; x < block_start_x + block_width; x++) {
|
for (int x = block_start_x; x < block_start_x + block_width; x++) {
|
||||||
int pixel_start = (y * image_width) + x;
|
int pixel_start = (y * image_width * bytes_per_pixel) + (x * bytes_per_pixel);
|
||||||
int smallest_distance = INT_MAX;
|
int smallest_distance = INT_MAX;
|
||||||
int winning_index = -1;
|
int winning_index = -1;
|
||||||
|
|
||||||
// Copy pixel data for quantizing later
|
// Copy pixel data for quantizing later
|
||||||
block[block_index++] = image_buffer[pixel_start];
|
block[block_index++] = image_buffer[pixel_start];
|
||||||
|
block[block_index++] = image_buffer[pixel_start + 1];
|
||||||
|
block[block_index++] = image_buffer[pixel_start + 2];
|
||||||
|
block[block_index++] = image_buffer[pixel_start + 3];
|
||||||
|
|
||||||
// Which zx color is this pixel closest to?
|
// Which zx color is this pixel closest to?
|
||||||
for (int color_index = 0; color_index < 15; color_index++) {
|
for (int color_index = 0; color_index < 15; color_index++) {
|
||||||
liq_color color = zx_colors[color_index];
|
liq_color color = zx_colors[color_index];
|
||||||
liq_color pixel = image_buffer[pixel_start];
|
|
||||||
|
|
||||||
// Using Euclidean distance. LibQuant has better methods, but it
|
// Using Euclidean distance. LibQuant has better methods, but it requires conversion to
|
||||||
// requires conversion to LAB, so I don't think it's worth it.
|
// LAB, so I don't think it's worth it.
|
||||||
int distance =
|
int distance =
|
||||||
pow(color.r - pixel.r, 2) + pow(color.g - pixel.g, 2) + pow(color.b - pixel.b, 2);
|
pow(color.r - image_buffer[pixel_start + 0], 2) +
|
||||||
|
pow(color.g - image_buffer[pixel_start + 1], 2) +
|
||||||
|
pow(color.b - image_buffer[pixel_start + 2], 2);
|
||||||
|
|
||||||
if (distance < smallest_distance) {
|
if (distance < smallest_distance) {
|
||||||
winning_index = color_index;
|
winning_index = color_index;
|
||||||
@@ -140,8 +151,7 @@ val zx_quantize(std::string rawimage, int image_width, int image_height, float d
|
|||||||
|
|
||||||
for (int color_index = 0; color_index < 15; color_index++) {
|
for (int color_index = 0; color_index < 15; color_index++) {
|
||||||
if (color_popularity[color_index] > highest_popularity) {
|
if (color_popularity[color_index] > highest_popularity) {
|
||||||
// Store this as the most popular pixel, and demote the current
|
// Store this as the most popular pixel, and demote the current values:
|
||||||
// values:
|
|
||||||
third_color_index = second_color_index;
|
third_color_index = second_color_index;
|
||||||
third_highest_popularity = second_highest_popularity;
|
third_highest_popularity = second_highest_popularity;
|
||||||
second_color_index = first_color_index;
|
second_color_index = first_color_index;
|
||||||
@@ -159,8 +169,8 @@ val zx_quantize(std::string rawimage, int image_width, int image_height, float d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZX images can't mix bright and regular colours, except black which
|
// ZX images can't mix bright and regular colours, except black which appears in both.
|
||||||
// appears in both. Resolve any conflict:
|
// Resolve any conflict:
|
||||||
while (1) {
|
while (1) {
|
||||||
// If either colour is black, there's no conflict to resolve.
|
// If either colour is black, there's no conflict to resolve.
|
||||||
if (first_color_index != 0 && second_color_index != 0) {
|
if (first_color_index != 0 && second_color_index != 0) {
|
||||||
@@ -173,44 +183,63 @@ val zx_quantize(std::string rawimage, int image_width, int image_height, float d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If, during conflict resolving, we now have two of the same colour
|
// If, during conflict resolving, we now have two of the same colour (because we initially
|
||||||
// (because we initially selected the bright & regular version of the
|
// selected the bright & regular version of the same colour), retry again with the third
|
||||||
// same colour), retry again with the third most popular colour.
|
// most popular colour.
|
||||||
if (first_color_index == second_color_index) {
|
if (first_color_index == second_color_index) {
|
||||||
second_color_index = third_color_index;
|
second_color_index = third_color_index;
|
||||||
} else
|
} else break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantize
|
// Quantize
|
||||||
liq_attr_ptr attr(liq_attr_create());
|
attr = liq_attr_create();
|
||||||
liq_image_ptr image(liq_image_create_rgba(attr.get(), block, block_width, block_height, 0));
|
image = liq_image_create_rgba(attr, block, block_width, block_height, 0);
|
||||||
liq_set_max_colors(attr.get(), 2);
|
liq_set_max_colors(attr, 2);
|
||||||
liq_image_add_fixed_color(image.get(), zx_colors[first_color_index]);
|
liq_image_add_fixed_color(image, zx_colors[first_color_index]);
|
||||||
liq_image_add_fixed_color(image.get(), zx_colors[second_color_index]);
|
liq_image_add_fixed_color(image, zx_colors[second_color_index]);
|
||||||
auto res = liq_image_quantize(image.get(), attr.get());
|
liq_image_quantize(image, attr, &res);
|
||||||
liq_set_dithering_level(res.get(), dithering);
|
liq_set_dithering_level(res, dithering);
|
||||||
liq_write_remapped_image(res.get(), image.get(), image8bit, size);
|
liq_write_remapped_image(res, image, image8bit, size);
|
||||||
auto pal = liq_get_palette(res.get());
|
const liq_palette *pal = liq_get_palette(res);
|
||||||
|
|
||||||
// Turn palletted image back into an RGBA image, and write it into the
|
// Turn palletted image back into an RGBA image, and write it into the full size result image.
|
||||||
// full size result image.
|
for(int y = 0; y < block_height; y++) {
|
||||||
for (int y = 0; y < block_height; y++) {
|
for(int x = 0; x < block_width; x++) {
|
||||||
for (int x = 0; x < block_width; x++) {
|
|
||||||
int image8BitPos = y * block_width + x;
|
int image8BitPos = y * block_width + x;
|
||||||
int resultStartPos = ((block_start_y + y) * image_width) + (block_start_x + x);
|
int resultStartPos = ((block_start_y + y) * bytes_per_pixel * image_width) + ((block_start_x + x) * bytes_per_pixel);
|
||||||
result[resultStartPos] = pal->entries[image8bit[image8BitPos]];
|
result[resultStartPos + 0] = pal->entries[image8bit[image8BitPos]].r;
|
||||||
|
result[resultStartPos + 1] = pal->entries[image8bit[image8BitPos]].g;
|
||||||
|
result[resultStartPos + 2] = pal->entries[image8bit[image8BitPos]].b;
|
||||||
|
result[resultStartPos + 3] = pal->entries[image8bit[image8BitPos]].a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
liq_result_destroy(res);
|
||||||
|
liq_image_destroy(image);
|
||||||
|
liq_attr_destroy(attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Uint8ClampedArray.new_(
|
free(image8bit);
|
||||||
typed_memory_view(result.size() * sizeof(liq_color), (const uint8_t*)result.data()));
|
return {
|
||||||
|
val(typed_memory_view(image_width*image_height*4, result)),
|
||||||
|
image_width,
|
||||||
|
image_height
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_result() {
|
||||||
|
free(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_BINDINGS(my_module) {
|
EMSCRIPTEN_BINDINGS(my_module) {
|
||||||
|
class_<RawImage>("RawImage")
|
||||||
|
.property("buffer", &RawImage::buffer)
|
||||||
|
.property("width", &RawImage::width)
|
||||||
|
.property("height", &RawImage::height);
|
||||||
|
|
||||||
function("quantize", &quantize);
|
function("quantize", &quantize);
|
||||||
function("zx_quantize", &zx_quantize);
|
function("zx_quantize", &zx_quantize);
|
||||||
function("version", &version);
|
function("version", &version);
|
||||||
|
function("free_result", &free_result);
|
||||||
}
|
}
|
||||||
|
|||||||
13
codecs/imagequant/imagequant.d.ts
vendored
13
codecs/imagequant/imagequant.d.ts
vendored
@@ -1,6 +1,15 @@
|
|||||||
|
interface RawImage {
|
||||||
|
buffer: Uint8Array;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface QuantizerModule extends EmscriptenWasm.Module {
|
interface QuantizerModule extends EmscriptenWasm.Module {
|
||||||
quantize(data: BufferSource, width: number, height: number, numColors: number, dither: number): Uint8ClampedArray;
|
quantize(data: BufferSource, width: number, height: number, numColors: number, dither: number): RawImage;
|
||||||
zx_quantize(data: BufferSource, width: number, height: number, dither: number): Uint8ClampedArray;
|
zx_quantize(data: BufferSource, width: number, height: number, dither: number): RawImage;
|
||||||
|
free_result(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(opts: EmscriptenWasm.ModuleOpts): QuantizerModule;
|
export default function(opts: EmscriptenWasm.ModuleOpts): QuantizerModule;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
1145
codecs/imagequant/package-lock.json
generated
1145
codecs/imagequant/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "imagequant",
|
"name": "imagequant",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../build-cpp.sh"
|
"install": "napa",
|
||||||
|
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||||
|
},
|
||||||
|
"napa": {
|
||||||
|
"libimagequant": "ImageOptim/libimagequant#2.12.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"napa": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
CODEC_URL := https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz
|
|
||||||
CODEC_DIR := node_modules/mozjpeg
|
|
||||||
CODEC_OUT_RELATIVE := .libs/libjpeg.a rdswitch.o
|
|
||||||
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
|
|
||||||
OUT_JS := mozjpeg_enc.js
|
|
||||||
OUT_WASM := $(OUT_JS:.js=.wasm)
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
all: $(OUT_JS)
|
|
||||||
|
|
||||||
%.js: %.cpp $(CODEC_OUT)
|
|
||||||
$(CXX) \
|
|
||||||
-I $(CODEC_DIR) \
|
|
||||||
${CXXFLAGS} \
|
|
||||||
${LDFLAGS} \
|
|
||||||
--bind \
|
|
||||||
--closure 1 \
|
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-s MODULARIZE=1 \
|
|
||||||
-s 'EXPORT_NAME="$(basename $(@F))"' \
|
|
||||||
-o $@ \
|
|
||||||
$+
|
|
||||||
|
|
||||||
# This one is a bit special: there is no rule for .libs/libjpeg.a
|
|
||||||
# so we use libjpeg.la which implicitly builds that one instead.
|
|
||||||
$(CODEC_DIR)/.libs/libjpeg.a: $(CODEC_DIR)/Makefile
|
|
||||||
$(MAKE) -C $(CODEC_DIR) libjpeg.la
|
|
||||||
|
|
||||||
$(CODEC_DIR)/rdswitch.o: $(CODEC_DIR)/Makefile
|
|
||||||
$(MAKE) -C $(CODEC_DIR) rdswitch.o
|
|
||||||
|
|
||||||
$(CODEC_DIR)/Makefile: $(CODEC_DIR)/configure
|
|
||||||
cd $(CODEC_DIR) && ./configure \
|
|
||||||
--disable-shared \
|
|
||||||
--without-turbojpeg \
|
|
||||||
--without-simd \
|
|
||||||
--without-arith-enc \
|
|
||||||
--without-arith-dec
|
|
||||||
|
|
||||||
$(CODEC_DIR)/configure: $(CODEC_DIR)/configure.ac
|
|
||||||
cd $(CODEC_DIR) && autoreconf -iv
|
|
||||||
|
|
||||||
$(CODEC_DIR)/configure.ac: $(CODEC_DIR)
|
|
||||||
|
|
||||||
$(CODEC_DIR):
|
|
||||||
mkdir -p $@
|
|
||||||
curl -sL $(CODEC_URL) | tar xz --strip 1 -C $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(OUT_JS) $(OUT_WASM)
|
|
||||||
$(MAKE) -C $(CODEC_DIR) clean
|
|
||||||
@@ -17,6 +17,10 @@ See `example.html`
|
|||||||
|
|
||||||
Returns the version of MozJPEG as a number. va.b.c is encoded as 0x0a0b0c
|
Returns the version of MozJPEG as a number. va.b.c is encoded as 0x0a0b0c
|
||||||
|
|
||||||
|
### `void free_result()`
|
||||||
|
|
||||||
|
Frees the result created by `encode()`.
|
||||||
|
|
||||||
### `Uint8Array encode(std::string image_in, int image_width, int image_height, MozJpegOptions opts)`
|
### `Uint8Array encode(std::string image_in, int image_width, int image_height, MozJpegOptions opts)`
|
||||||
|
|
||||||
Encodes the given image with given dimension to JPEG. Options looks like this:
|
Encodes the given image with given dimension to JPEG. Options looks like this:
|
||||||
|
|||||||
53
codecs/mozjpeg_enc/build.sh
Executable file
53
codecs/mozjpeg_enc/build.sh
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export OPTIMIZE="-Os"
|
||||||
|
export LDFLAGS="${OPTIMIZE}"
|
||||||
|
export CFLAGS="${OPTIMIZE}"
|
||||||
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool libpng-dev pkg-config
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling mozjpeg"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
cd node_modules/mozjpeg
|
||||||
|
autoreconf -fiv
|
||||||
|
emconfigure ./configure --without-simd
|
||||||
|
emmake make libjpeg.la
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling mozjpeg done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling wasm bindings"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
emcc \
|
||||||
|
--bind \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-s WASM=1 \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
|
-s MODULARIZE=1 \
|
||||||
|
-s 'EXPORT_NAME="mozjpeg_enc"' \
|
||||||
|
-I node_modules/mozjpeg \
|
||||||
|
-o ./mozjpeg_enc.js \
|
||||||
|
-Wno-deprecated-register \
|
||||||
|
-Wno-writable-strings \
|
||||||
|
node_modules/mozjpeg/rdswitch.c \
|
||||||
|
-x c++ -std=c++11 \
|
||||||
|
mozjpeg_enc.cpp \
|
||||||
|
node_modules/mozjpeg/.libs/libjpeg.a
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling wasm bindings done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
echo "Did you update your docker image?"
|
||||||
|
echo "Run \`docker pull trzeci/emscripten\`"
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
@@ -1,22 +1,18 @@
|
|||||||
#include <emscripten/bind.h>
|
#include <emscripten/bind.h>
|
||||||
#include <emscripten/val.h>
|
#include <emscripten/val.h>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <setjmp.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "jpeglib.h"
|
#include "jpeglib.h"
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "cdjpeg.h"
|
#include "cdjpeg.h"
|
||||||
}
|
|
||||||
|
|
||||||
using namespace emscripten;
|
using namespace emscripten;
|
||||||
|
|
||||||
// MozJPEG doesn’t expose a numeric version, so I have to do some fun C macro
|
// MozJPEG doesn’t expose a numeric version, so I have to do some fun C macro hackery to turn it
|
||||||
// hackery to turn it into a string. More details here:
|
// into a string. More details here: https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
||||||
// https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
|
||||||
#define xstr(s) str(s)
|
#define xstr(s) str(s)
|
||||||
#define str(s) #s
|
#define str(s) #s
|
||||||
|
|
||||||
@@ -43,8 +39,8 @@ int version() {
|
|||||||
char buffer[] = xstr(MOZJPEG_VERSION);
|
char buffer[] = xstr(MOZJPEG_VERSION);
|
||||||
int version = 0;
|
int version = 0;
|
||||||
int last_index = 0;
|
int last_index = 0;
|
||||||
for (int i = 0; i < strlen(buffer); i++) {
|
for(int i = 0; i < strlen(buffer); i++) {
|
||||||
if (buffer[i] == '.') {
|
if(buffer[i] == '.') {
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
version = version << 8 | atoi(&buffer[last_index]);
|
version = version << 8 | atoi(&buffer[last_index]);
|
||||||
buffer[i] = '.';
|
buffer[i] = '.';
|
||||||
@@ -55,16 +51,16 @@ int version() {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local const val Uint8Array = val::global("Uint8Array");
|
uint8_t* last_result;
|
||||||
|
struct jpeg_compress_struct cinfo;
|
||||||
|
|
||||||
val encode(std::string image_in, int image_width, int image_height, MozJpegOptions opts) {
|
val encode(std::string image_in, int image_width, int image_height, MozJpegOptions opts) {
|
||||||
uint8_t* image_buffer = (uint8_t*)image_in.c_str();
|
uint8_t* image_buffer = (uint8_t*) image_in.c_str();
|
||||||
|
|
||||||
// The code below is basically the `write_JPEG_file` function from
|
// The code below is basically the `write_JPEG_file` function from
|
||||||
// https://github.com/mozilla/mozjpeg/blob/master/example.c
|
// https://github.com/mozilla/mozjpeg/blob/master/example.c
|
||||||
// I just write to memory instead of a file.
|
// I just write to memory instead of a file.
|
||||||
|
|
||||||
/* Step 1: allocate and initialize JPEG compression object */
|
|
||||||
|
|
||||||
/* This struct contains the JPEG compression parameters and pointers to
|
/* This struct contains the JPEG compression parameters and pointers to
|
||||||
* working space (which is allocated as needed by the JPEG library).
|
* working space (which is allocated as needed by the JPEG library).
|
||||||
@@ -72,7 +68,6 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
* compression/decompression processes, in existence at once. We refer
|
* compression/decompression processes, in existence at once. We refer
|
||||||
* to any one struct (and its associated working data) as a "JPEG object".
|
* to any one struct (and its associated working data) as a "JPEG object".
|
||||||
*/
|
*/
|
||||||
jpeg_compress_struct cinfo;
|
|
||||||
/* This struct represents a JPEG error handler. It is declared separately
|
/* This struct represents a JPEG error handler. It is declared separately
|
||||||
* because applications often want to supply a specialized error handler
|
* because applications often want to supply a specialized error handler
|
||||||
* (see the second half of this file for an example). But here we just
|
* (see the second half of this file for an example). But here we just
|
||||||
@@ -81,7 +76,15 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
* Note that this struct must live as long as the main JPEG parameter
|
* Note that this struct must live as long as the main JPEG parameter
|
||||||
* struct, to avoid dangling-pointer problems.
|
* struct, to avoid dangling-pointer problems.
|
||||||
*/
|
*/
|
||||||
jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
|
/* More stuff */
|
||||||
|
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
||||||
|
int row_stride; /* physical row width in image buffer */
|
||||||
|
uint8_t* output;
|
||||||
|
unsigned long size;
|
||||||
|
|
||||||
|
/* Step 1: allocate and initialize JPEG compression object */
|
||||||
|
|
||||||
/* We have to set up the error handler first, in case the initialization
|
/* We have to set up the error handler first, in case the initialization
|
||||||
* step fails. (Unlikely, but it could happen if you are out of memory.)
|
* step fails. (Unlikely, but it could happen if you are out of memory.)
|
||||||
* This routine fills in the contents of struct jerr, and returns jerr's
|
* This routine fills in the contents of struct jerr, and returns jerr's
|
||||||
@@ -103,8 +106,6 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
// fprintf(stderr, "can't open %s\n", filename);
|
// fprintf(stderr, "can't open %s\n", filename);
|
||||||
// exit(1);
|
// exit(1);
|
||||||
// }
|
// }
|
||||||
uint8_t* output = nullptr;
|
|
||||||
unsigned long size = 0;
|
|
||||||
jpeg_mem_dest(&cinfo, &output, &size);
|
jpeg_mem_dest(&cinfo, &output, &size);
|
||||||
|
|
||||||
/* Step 3: set parameters for compression */
|
/* Step 3: set parameters for compression */
|
||||||
@@ -112,17 +113,17 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
/* First we supply a description of the input image.
|
/* First we supply a description of the input image.
|
||||||
* Four fields of the cinfo struct must be filled in:
|
* Four fields of the cinfo struct must be filled in:
|
||||||
*/
|
*/
|
||||||
cinfo.image_width = image_width; /* image width and height, in pixels */
|
cinfo.image_width = image_width; /* image width and height, in pixels */
|
||||||
cinfo.image_height = image_height;
|
cinfo.image_height = image_height;
|
||||||
cinfo.input_components = 4; /* # of color components per pixel */
|
cinfo.input_components = 4; /* # of color components per pixel */
|
||||||
cinfo.in_color_space = JCS_EXT_RGBA; /* colorspace of input image */
|
cinfo.in_color_space = JCS_EXT_RGBA; /* colorspace of input image */
|
||||||
/* Now use the library's routine to set default compression parameters.
|
/* Now use the library's routine to set default compression parameters.
|
||||||
* (You must set at least cinfo.in_color_space before calling this,
|
* (You must set at least cinfo.in_color_space before calling this,
|
||||||
* since the defaults depend on the source color space.)
|
* since the defaults depend on the source color space.)
|
||||||
*/
|
*/
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_defaults(&cinfo);
|
||||||
|
|
||||||
jpeg_set_colorspace(&cinfo, (J_COLOR_SPACE)opts.color_space);
|
jpeg_set_colorspace(&cinfo, (J_COLOR_SPACE) opts.color_space);
|
||||||
|
|
||||||
if (opts.quant_table != -1) {
|
if (opts.quant_table != -1) {
|
||||||
jpeg_c_set_int_param(&cinfo, JINT_BASE_QUANT_TBL_IDX, opts.quant_table);
|
jpeg_c_set_int_param(&cinfo, JINT_BASE_QUANT_TBL_IDX, opts.quant_table);
|
||||||
@@ -142,17 +143,17 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_Q_OPT, opts.trellis_opt_table);
|
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_Q_OPT, opts.trellis_opt_table);
|
||||||
jpeg_c_set_int_param(&cinfo, JINT_TRELLIS_NUM_LOOPS, opts.trellis_loops);
|
jpeg_c_set_int_param(&cinfo, JINT_TRELLIS_NUM_LOOPS, opts.trellis_loops);
|
||||||
|
|
||||||
// A little hacky to build a string for this, but it means we can use
|
// A little hacky to build a string for this, but it means we can use set_quality_ratings which
|
||||||
// set_quality_ratings which does some useful heuristic stuff.
|
// does some useful heuristic stuff.
|
||||||
std::string quality_str = std::to_string(opts.quality);
|
std::string quality_str = std::to_string(opts.quality);
|
||||||
|
|
||||||
if (opts.separate_chroma_quality && opts.color_space == JCS_YCbCr) {
|
if (opts.separate_chroma_quality && opts.color_space == JCS_YCbCr) {
|
||||||
quality_str += "," + std::to_string(opts.chroma_quality);
|
quality_str += "," + std::to_string(opts.chroma_quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* pqual = quality_str.c_str();
|
char const *pqual = quality_str.c_str();
|
||||||
|
|
||||||
set_quality_ratings(&cinfo, (char*)pqual, opts.baseline);
|
set_quality_ratings(&cinfo, (char*) pqual, opts.baseline);
|
||||||
|
|
||||||
if (!opts.auto_subsample && opts.color_space == JCS_YCbCr) {
|
if (!opts.auto_subsample && opts.color_space == JCS_YCbCr) {
|
||||||
cinfo.comp_info[0].h_samp_factor = opts.chroma_subsample;
|
cinfo.comp_info[0].h_samp_factor = opts.chroma_subsample;
|
||||||
@@ -180,54 +181,54 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
|
|||||||
* To keep things simple, we pass one scanline per call; you can pass
|
* To keep things simple, we pass one scanline per call; you can pass
|
||||||
* more if you wish, though.
|
* more if you wish, though.
|
||||||
*/
|
*/
|
||||||
int row_stride = image_width * 4; /* JSAMPLEs per row in image_buffer */
|
row_stride = image_width * 4; /* JSAMPLEs per row in image_buffer */
|
||||||
|
|
||||||
while (cinfo.next_scanline < cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height) {
|
||||||
/* jpeg_write_scanlines expects an array of pointers to scanlines.
|
/* jpeg_write_scanlines expects an array of pointers to scanlines.
|
||||||
* Here the array is only one element long, but you could pass
|
* Here the array is only one element long, but you could pass
|
||||||
* more than one scanline at a time if that's more convenient.
|
* more than one scanline at a time if that's more convenient.
|
||||||
*/
|
*/
|
||||||
|
row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
|
||||||
JSAMPROW row_pointer =
|
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||||
&image_buffer[cinfo.next_scanline * row_stride]; /* pointer to JSAMPLE row[s] */
|
|
||||||
(void)jpeg_write_scanlines(&cinfo, &row_pointer, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 6: Finish compression */
|
/* Step 6: Finish compression */
|
||||||
|
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
|
|
||||||
/* Step 7: release JPEG compression object */
|
/* Step 7: release JPEG compression object */
|
||||||
|
|
||||||
auto js_result = Uint8Array.new_(typed_memory_view(size, output));
|
last_result = output;
|
||||||
|
|
||||||
/* This is an important step since it will release a good deal of memory. */
|
|
||||||
jpeg_destroy_compress(&cinfo);
|
|
||||||
free(output);
|
|
||||||
|
|
||||||
/* And we're done! */
|
/* And we're done! */
|
||||||
return js_result;
|
return val(typed_memory_view(size, output));
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_result() {
|
||||||
|
/* This is an important step since it will release a good deal of memory. */
|
||||||
|
jpeg_destroy_compress(&cinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_BINDINGS(my_module) {
|
EMSCRIPTEN_BINDINGS(my_module) {
|
||||||
value_object<MozJpegOptions>("MozJpegOptions")
|
value_object<MozJpegOptions>("MozJpegOptions")
|
||||||
.field("quality", &MozJpegOptions::quality)
|
.field("quality", &MozJpegOptions::quality)
|
||||||
.field("baseline", &MozJpegOptions::baseline)
|
.field("baseline", &MozJpegOptions::baseline)
|
||||||
.field("arithmetic", &MozJpegOptions::arithmetic)
|
.field("arithmetic", &MozJpegOptions::arithmetic)
|
||||||
.field("progressive", &MozJpegOptions::progressive)
|
.field("progressive", &MozJpegOptions::progressive)
|
||||||
.field("optimize_coding", &MozJpegOptions::optimize_coding)
|
.field("optimize_coding", &MozJpegOptions::optimize_coding)
|
||||||
.field("smoothing", &MozJpegOptions::smoothing)
|
.field("smoothing", &MozJpegOptions::smoothing)
|
||||||
.field("color_space", &MozJpegOptions::color_space)
|
.field("color_space", &MozJpegOptions::color_space)
|
||||||
.field("quant_table", &MozJpegOptions::quant_table)
|
.field("quant_table", &MozJpegOptions::quant_table)
|
||||||
.field("trellis_multipass", &MozJpegOptions::trellis_multipass)
|
.field("trellis_multipass", &MozJpegOptions::trellis_multipass)
|
||||||
.field("trellis_opt_zero", &MozJpegOptions::trellis_opt_zero)
|
.field("trellis_opt_zero", &MozJpegOptions::trellis_opt_zero)
|
||||||
.field("trellis_opt_table", &MozJpegOptions::trellis_opt_table)
|
.field("trellis_opt_table", &MozJpegOptions::trellis_opt_table)
|
||||||
.field("trellis_loops", &MozJpegOptions::trellis_loops)
|
.field("trellis_loops", &MozJpegOptions::trellis_loops)
|
||||||
.field("chroma_subsample", &MozJpegOptions::chroma_subsample)
|
.field("chroma_subsample", &MozJpegOptions::chroma_subsample)
|
||||||
.field("auto_subsample", &MozJpegOptions::auto_subsample)
|
.field("auto_subsample", &MozJpegOptions::auto_subsample)
|
||||||
.field("separate_chroma_quality", &MozJpegOptions::separate_chroma_quality)
|
.field("separate_chroma_quality", &MozJpegOptions::separate_chroma_quality)
|
||||||
.field("chroma_quality", &MozJpegOptions::chroma_quality);
|
.field("chroma_quality", &MozJpegOptions::chroma_quality)
|
||||||
|
;
|
||||||
|
|
||||||
function("version", &version);
|
function("version", &version);
|
||||||
function("encode", &encode);
|
function("encode", &encode);
|
||||||
|
function("free_result", &free_result);
|
||||||
}
|
}
|
||||||
|
|||||||
1
codecs/mozjpeg_enc/mozjpeg_enc.d.ts
vendored
1
codecs/mozjpeg_enc/mozjpeg_enc.d.ts
vendored
@@ -2,6 +2,7 @@ import { EncodeOptions } from '../../src/codecs/mozjpeg/encoder-meta';
|
|||||||
|
|
||||||
interface MozJPEGModule extends EmscriptenWasm.Module {
|
interface MozJPEGModule extends EmscriptenWasm.Module {
|
||||||
encode(data: BufferSource, width: number, height: number, options: EncodeOptions): Uint8Array;
|
encode(data: BufferSource, width: number, height: number, options: EncodeOptions): Uint8Array;
|
||||||
|
free_result(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(opts: EmscriptenWasm.ModuleOpts): MozJPEGModule;
|
export default function(opts: EmscriptenWasm.ModuleOpts): MozJPEGModule;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
1145
codecs/mozjpeg_enc/package-lock.json
generated
1145
codecs/mozjpeg_enc/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "mozjpeg_enc",
|
"name": "mozjpeg_enc",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../build-cpp.sh"
|
"install": "napa",
|
||||||
|
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||||
|
},
|
||||||
|
"napa": {
|
||||||
|
"mozjpeg": "mozilla/mozjpeg#v3.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"napa": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
codecs/optipng/.gitignore
vendored
Normal file
2
codecs/optipng/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
build/
|
||||||
|
*.o
|
||||||
26
codecs/optipng/README.md
Normal file
26
codecs/optipng/README.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# OptiPNG
|
||||||
|
|
||||||
|
- Source: <https://sourceforge.net/project/optipng>
|
||||||
|
- Version: v0.7.7
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
See `example.html`
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### `int version()`
|
||||||
|
|
||||||
|
Returns the version of optipng as a number. va.b.c is encoded as 0x0a0b0c
|
||||||
|
|
||||||
|
### `ArrayBuffer compress(std::string buffer, {level})`;
|
||||||
|
|
||||||
|
`compress` will re-compress the given PNG image via `buffer`. `level` is a number between 0 and 7.
|
||||||
|
|
||||||
|
### `void free_result()`
|
||||||
|
|
||||||
|
Frees the result created by `compress()`.
|
||||||
87
codecs/optipng/build.sh
Executable file
87
codecs/optipng/build.sh
Executable file
@@ -0,0 +1,87 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export OPTIMIZE="-Os"
|
||||||
|
export PREFIX="/src/build"
|
||||||
|
export CFLAGS="${OPTIMIZE} -I${PREFIX}/include/"
|
||||||
|
export CPPFLAGS="${OPTIMIZE} -I${PREFIX}/include/"
|
||||||
|
export LDFLAGS="${OPTIMIZE} -L${PREFIX}/lib/"
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling zlib"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_ZLIB" || (
|
||||||
|
cd node_modules/zlib
|
||||||
|
emconfigure ./configure --prefix=${PREFIX}/
|
||||||
|
emmake make
|
||||||
|
emmake make install
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling zlib done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libpng"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_LIBPNG" || (
|
||||||
|
cd node_modules/libpng
|
||||||
|
autoreconf -i
|
||||||
|
emconfigure ./configure --with-zlib-prefix=${PREFIX}/ --prefix=${PREFIX}/
|
||||||
|
emmake make
|
||||||
|
emmake make install
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libpng done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling optipng"
|
||||||
|
echo "============================================="
|
||||||
|
(
|
||||||
|
emcc \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-Wno-implicit-function-declaration \
|
||||||
|
-I ${PREFIX}/include \
|
||||||
|
-I node_modules/optipng/src/opngreduc \
|
||||||
|
-I node_modules/optipng/src/pngxtern \
|
||||||
|
-I node_modules/optipng/src/cexcept \
|
||||||
|
-I node_modules/optipng/src/gifread \
|
||||||
|
-I node_modules/optipng/src/pnmio \
|
||||||
|
-I node_modules/optipng/src/minitiff \
|
||||||
|
--std=c99 -c \
|
||||||
|
node_modules/optipng/src/opngreduc/*.c \
|
||||||
|
node_modules/optipng/src/pngxtern/*.c \
|
||||||
|
node_modules/optipng/src/gifread/*.c \
|
||||||
|
node_modules/optipng/src/minitiff/*.c \
|
||||||
|
node_modules/optipng/src/pnmio/*.c \
|
||||||
|
node_modules/optipng/src/optipng/*.c
|
||||||
|
|
||||||
|
emcc \
|
||||||
|
--bind \
|
||||||
|
${OPTIMIZE} \
|
||||||
|
-s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s 'EXPORT_NAME="optipng"' \
|
||||||
|
-I ${PREFIX}/include \
|
||||||
|
-I node_modules/optipng/src/opngreduc \
|
||||||
|
-I node_modules/optipng/src/pngxtern \
|
||||||
|
-I node_modules/optipng/src/cexcept \
|
||||||
|
-I node_modules/optipng/src/gifread \
|
||||||
|
-I node_modules/optipng/src/pnmio \
|
||||||
|
-I node_modules/optipng/src/minitiff \
|
||||||
|
-o "optipng.js" \
|
||||||
|
--std=c++11 \
|
||||||
|
optipng.cpp \
|
||||||
|
*.o \
|
||||||
|
${PREFIX}/lib/libz.so ${PREFIX}/lib/libpng.a
|
||||||
|
)
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling optipng done"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
echo "Did you update your docker image?"
|
||||||
|
echo "Run \`docker pull trzeci/emscripten\`"
|
||||||
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
19
codecs/optipng/example.html
Normal file
19
codecs/optipng/example.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<script src='optipng.js'></script>
|
||||||
|
<script>
|
||||||
|
const Module = optipng();
|
||||||
|
|
||||||
|
Module.onRuntimeInitialized = async _ => {
|
||||||
|
console.log('Version:', Module.version().toString(16));
|
||||||
|
const image = await fetch('../example_palette.png').then(r => r.arrayBuffer());
|
||||||
|
const newImage = Module.compress(image, {level: 3});
|
||||||
|
console.log('done');
|
||||||
|
Module.free_result();
|
||||||
|
|
||||||
|
console.log(`Old size: ${image.byteLength}, new size: ${newImage.byteLength} (${newImage.byteLength/image.byteLength*100}%)`);
|
||||||
|
const blobURL = URL.createObjectURL(new Blob([newImage], {type: 'image/png'}));
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.src = blobURL;
|
||||||
|
document.body.appendChild(img);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
53
codecs/optipng/optipng.cpp
Normal file
53
codecs/optipng/optipng.cpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include "emscripten/bind.h"
|
||||||
|
#include "emscripten/val.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
using namespace emscripten;
|
||||||
|
|
||||||
|
extern "C" int main(int argc, char *argv[]);
|
||||||
|
|
||||||
|
int version() {
|
||||||
|
// FIXME (@surma): Haven’t found a version in optipng :(
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct OptiPngOpts {
|
||||||
|
int level;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t* result;
|
||||||
|
val compress(std::string png, OptiPngOpts opts) {
|
||||||
|
remove("input.png");
|
||||||
|
remove("output.png");
|
||||||
|
FILE* infile = fopen("input.png", "wb");
|
||||||
|
fwrite(png.c_str(), png.length(), 1, infile);
|
||||||
|
fflush(infile);
|
||||||
|
fclose(infile);
|
||||||
|
|
||||||
|
char optlevel[8];
|
||||||
|
sprintf(&optlevel[0], "-o%d", opts.level);
|
||||||
|
char* args[] = {"optipng", optlevel, "-out", "output.png", "input.png"};
|
||||||
|
main(5, args);
|
||||||
|
|
||||||
|
FILE *outfile = fopen("output.png", "rb");
|
||||||
|
fseek(outfile, 0, SEEK_END);
|
||||||
|
int fsize = ftell(outfile);
|
||||||
|
result = (uint8_t*) malloc(fsize);
|
||||||
|
fseek(outfile, 0, SEEK_SET);
|
||||||
|
fread(result, fsize, 1, outfile);
|
||||||
|
return val(typed_memory_view(fsize, result));
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_result() {
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_BINDINGS(my_module) {
|
||||||
|
value_object<OptiPngOpts>("OptiPngOpts")
|
||||||
|
.field("level", &OptiPngOpts::level);
|
||||||
|
|
||||||
|
function("version", &version);
|
||||||
|
function("compress", &compress);
|
||||||
|
function("free_result", &free_result);
|
||||||
|
}
|
||||||
10
codecs/optipng/optipng.d.ts
vendored
Normal file
10
codecs/optipng/optipng.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import {EncodeOptions} from "src/codecs/optipng/encoder";
|
||||||
|
|
||||||
|
export interface OptiPngModule extends EmscriptenWasm.Module {
|
||||||
|
compress(data: BufferSource, opts: EncodeOptions): Uint8Array;
|
||||||
|
free_result(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function(opts: EmscriptenWasm.ModuleOpts): OptiPngModule;
|
||||||
|
|
||||||
|
|
||||||
24
codecs/optipng/optipng.js
Normal file
24
codecs/optipng/optipng.js
Normal file
File diff suppressed because one or more lines are too long
BIN
codecs/optipng/optipng.wasm
Normal file
BIN
codecs/optipng/optipng.wasm
Normal file
Binary file not shown.
1457
codecs/optipng/package-lock.json
generated
Normal file
1457
codecs/optipng/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
codecs/optipng/package.json
Normal file
22
codecs/optipng/package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "optipng",
|
||||||
|
"scripts": {
|
||||||
|
"install": "tar-dependency install && napa",
|
||||||
|
"build": "npm run build:wasm",
|
||||||
|
"build:wasm": "docker run --rm -v $(pwd):/src -e SKIP_ZLIB=\"${SKIP_ZLIB}\" -e SKIP_LIBPNG=\"${SKIP_LIBPNG}\" trzeci/emscripten ./build.sh"
|
||||||
|
},
|
||||||
|
"tarDependencies": {
|
||||||
|
"node_modules/optipng": {
|
||||||
|
"url": "https://netcologne.dl.sourceforge.net/project/optipng/OptiPNG/optipng-0.7.7/optipng-0.7.7.tar.gz",
|
||||||
|
"strip": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"napa": {
|
||||||
|
"libpng": "emscripten-ports/libpng",
|
||||||
|
"zlib": "emscripten-ports/zlib"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"napa": "^3.0.0",
|
||||||
|
"tar-dependency": "0.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
codecs/oxipng/.gitignore
vendored
1
codecs/oxipng/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/target
|
|
||||||
496
codecs/oxipng/Cargo.lock
generated
496
codecs/oxipng/Cargo.lock
generated
@@ -1,496 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
[[package]]
|
|
||||||
name = "adler32"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bit-vec"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "build_const"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bumpalo"
|
|
||||||
version = "3.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bytemuck"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "37fa13df2292ecb479ec23aa06f4507928bef07839be9ef15281411076629431"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder"
|
|
||||||
version = "1.3.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.0.58"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cloudflare-zlib"
|
|
||||||
version = "0.2.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f5ed63a019d55bacd15cadcbcb96bf41b16281417fff393bdb55fa84255fe4b9"
|
|
||||||
dependencies = [
|
|
||||||
"cloudflare-zlib-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cloudflare-zlib-sys"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7e195cb274a0d6ee87e718838a09baecd7cbc9f6075dac256a84cb5842739c06"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc"
|
|
||||||
version = "1.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb"
|
|
||||||
dependencies = [
|
|
||||||
"build_const",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc32fast"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-deque"
|
|
||||||
version = "0.7.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-epoch",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"maybe-uninit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-epoch"
|
|
||||||
version = "0.8.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"cfg-if",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"lazy_static",
|
|
||||||
"maybe-uninit",
|
|
||||||
"memoffset",
|
|
||||||
"scopeguard",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-queue"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"maybe-uninit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-utils"
|
|
||||||
version = "0.7.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"cfg-if",
|
|
||||||
"lazy_static",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "deflate"
|
|
||||||
version = "0.8.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
|
|
||||||
dependencies = [
|
|
||||||
"adler32",
|
|
||||||
"byteorder",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.1.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "image"
|
|
||||||
version = "0.23.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2397fc43bd5648b7117aabb3c5e62d0e62c194826ec77b0b4d0c41e62744635"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
"byteorder",
|
|
||||||
"num-iter",
|
|
||||||
"num-rational",
|
|
||||||
"num-traits",
|
|
||||||
"png",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indexmap"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"rayon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.72"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libdeflater"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "66dca08b13369865b2f6dca1dd05f833985cbe6c12a676b04d55f78b85e80246"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "maybe-uninit"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memoffset"
|
|
||||||
version = "0.5.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miniz_oxide"
|
|
||||||
version = "0.3.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
|
|
||||||
dependencies = [
|
|
||||||
"adler32",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-integer"
|
|
||||||
version = "0.1.43"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-iter"
|
|
||||||
version = "0.1.41"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-integer",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-rational"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-integer",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_cpus"
|
|
||||||
version = "1.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "oxipng"
|
|
||||||
version = "3.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d5fd695858078338d73862ff3755f820eff0bf4f3304e4b52f22aba53463183a"
|
|
||||||
dependencies = [
|
|
||||||
"bit-vec",
|
|
||||||
"byteorder",
|
|
||||||
"cloudflare-zlib",
|
|
||||||
"crc",
|
|
||||||
"image",
|
|
||||||
"indexmap",
|
|
||||||
"itertools",
|
|
||||||
"libdeflater",
|
|
||||||
"log",
|
|
||||||
"miniz_oxide",
|
|
||||||
"rgb",
|
|
||||||
"zopfli",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "png"
|
|
||||||
version = "0.16.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c150bf7479fafe3dd8740dbe48cc33b2a3efb7b0fe3483aced8bbc39f6d0238d"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"crc32fast",
|
|
||||||
"deflate",
|
|
||||||
"miniz_oxide",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon"
|
|
||||||
version = "1.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"crossbeam-deque",
|
|
||||||
"either",
|
|
||||||
"rayon-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon-core"
|
|
||||||
version = "1.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-deque",
|
|
||||||
"crossbeam-queue",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"lazy_static",
|
|
||||||
"num_cpus",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rgb"
|
|
||||||
version = "0.8.20"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "90ef54b45ae131327a88597e2463fee4098ad6c88ba7b6af4b3987db8aad4098"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scopeguard"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "squoosh-oxipng"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
"oxipng",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-xid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typed-arena"
|
|
||||||
version = "1.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"wasm-bindgen-macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-backend"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df"
|
|
||||||
dependencies = [
|
|
||||||
"bumpalo",
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"wasm-bindgen-shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8"
|
|
||||||
dependencies = [
|
|
||||||
"quote",
|
|
||||||
"wasm-bindgen-macro-support",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro-support"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"wasm-bindgen-backend",
|
|
||||||
"wasm-bindgen-shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-shared"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zopfli"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4079b79464426ade2a1b0177fb0ce8396ba6b4084267407e333573c666073964"
|
|
||||||
dependencies = [
|
|
||||||
"adler32",
|
|
||||||
"byteorder",
|
|
||||||
"crc",
|
|
||||||
"typed-arena",
|
|
||||||
]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "squoosh-oxipng"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Ingvar Stepanyan <me@rreverser.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
oxipng = { version = "3.0.0", default-features = false }
|
|
||||||
wasm-bindgen = "0.2.64"
|
|
||||||
log = { version = "0.4", features = ["release_max_level_off"] }
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
opt-level = "s"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
FROM rust
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
|
||||||
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
||||||
|
|
||||||
RUN mkdir /opt/wabt && \
|
|
||||||
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.17/wabt-1.0.17-ubuntu.tar.gz | tar -xzf - -C /opt/wabt --strip 1
|
|
||||||
|
|
||||||
RUN mkdir /opt/wasi-sdk && \
|
|
||||||
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-11/wasi-sdk-11.0-linux.tar.gz | tar -xzf - -C /opt/wasi-sdk --strip 1
|
|
||||||
|
|
||||||
ENV PATH="/opt/wabt/bin:/opt/wasi-sdk/bin:${PATH}"
|
|
||||||
WORKDIR /src
|
|
||||||
4
codecs/oxipng/package-lock.json
generated
4
codecs/oxipng/package-lock.json
generated
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "oxipng",
|
|
||||||
"lockfileVersion": 1
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "oxipng",
|
|
||||||
"scripts": {
|
|
||||||
"build": "../build-rust.sh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "squoosh-oxipng",
|
|
||||||
"collaborators": [
|
|
||||||
"Ingvar Stepanyan <me@rreverser.com>"
|
|
||||||
],
|
|
||||||
"version": "0.1.0",
|
|
||||||
"files": [
|
|
||||||
"squoosh_oxipng_bg.wasm",
|
|
||||||
"squoosh_oxipng.js",
|
|
||||||
"squoosh_oxipng.d.ts"
|
|
||||||
],
|
|
||||||
"module": "squoosh_oxipng.js",
|
|
||||||
"types": "squoosh_oxipng.d.ts",
|
|
||||||
"sideEffects": false
|
|
||||||
}
|
|
||||||
8
codecs/oxipng/pkg/squoosh_oxipng.d.ts
vendored
8
codecs/oxipng/pkg/squoosh_oxipng.d.ts
vendored
@@ -1,8 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* @param {Uint8Array} data
|
|
||||||
* @param {number} level
|
|
||||||
* @returns {Uint8Array}
|
|
||||||
*/
|
|
||||||
export function optimise(data: Uint8Array, level: number): Uint8Array;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import * as wasm from "./squoosh_oxipng_bg.wasm";
|
|
||||||
export * from "./squoosh_oxipng_bg.js";
|
|
||||||
8
codecs/oxipng/pkg/squoosh_oxipng_bg.d.ts
vendored
8
codecs/oxipng/pkg/squoosh_oxipng_bg.d.ts
vendored
@@ -1,8 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
export const memory: WebAssembly.Memory;
|
|
||||||
export function optimise(a: number, b: number, c: number, d: number): void;
|
|
||||||
export function malloc(a: number): number;
|
|
||||||
export function free(a: number): void;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import * as wasm from './squoosh_oxipng_bg.wasm';
|
|
||||||
|
|
||||||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
||||||
|
|
||||||
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
||||||
|
|
||||||
cachedTextDecoder.decode();
|
|
||||||
|
|
||||||
let cachegetUint8Memory0 = null;
|
|
||||||
function getUint8Memory0() {
|
|
||||||
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetUint8Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStringFromWasm0(ptr, len) {
|
|
||||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
||||||
}
|
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
|
||||||
|
|
||||||
function passArray8ToWasm0(arg, malloc) {
|
|
||||||
const ptr = malloc(arg.length * 1);
|
|
||||||
getUint8Memory0().set(arg, ptr / 1);
|
|
||||||
WASM_VECTOR_LEN = arg.length;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachegetInt32Memory0 = null;
|
|
||||||
function getInt32Memory0() {
|
|
||||||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetInt32Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getArrayU8FromWasm0(ptr, len) {
|
|
||||||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param {Uint8Array} data
|
|
||||||
* @param {number} level
|
|
||||||
* @returns {Uint8Array}
|
|
||||||
*/
|
|
||||||
export function optimise(data, level) {
|
|
||||||
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
||||||
var len0 = WASM_VECTOR_LEN;
|
|
||||||
wasm.optimise(8, ptr0, len0, level);
|
|
||||||
var r0 = getInt32Memory0()[8 / 4 + 0];
|
|
||||||
var r1 = getInt32Memory0()[8 / 4 + 1];
|
|
||||||
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
||||||
wasm.__wbindgen_free(r0, r1 * 1);
|
|
||||||
return v1;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const __wbindgen_throw = function(arg0, arg1) {
|
|
||||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
||||||
};
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,18 +0,0 @@
|
|||||||
mod malloc_shim;
|
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use oxipng::AlphaOptim;
|
|
||||||
|
|
||||||
#[wasm_bindgen(catch)]
|
|
||||||
pub fn optimise(data: &[u8], level: u8) -> Vec<u8> {
|
|
||||||
let mut options = oxipng::Options::from_preset(level);
|
|
||||||
options.alphas.insert(AlphaOptim::Black);
|
|
||||||
options.alphas.insert(AlphaOptim::White);
|
|
||||||
options.alphas.insert(AlphaOptim::Up);
|
|
||||||
options.alphas.insert(AlphaOptim::Down);
|
|
||||||
options.alphas.insert(AlphaOptim::Left);
|
|
||||||
options.alphas.insert(AlphaOptim::Right);
|
|
||||||
|
|
||||||
options.deflate = oxipng::Deflaters::Libdeflater;
|
|
||||||
oxipng::optimize_from_memory(data, &options).unwrap_throw()
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
//! This is a module that provides `malloc` and `free` for `libdeflate`.
|
|
||||||
//! These implementations are compatible with the standard signatures
|
|
||||||
//! but use Rust allocator instead of including libc one as well.
|
|
||||||
//!
|
|
||||||
//! Rust allocator APIs requires passing size and alignment to the
|
|
||||||
//! `dealloc` function. This is different from C API, which only
|
|
||||||
//! expects a pointer in `free` and expects allocators to take care of
|
|
||||||
//! storing any necessary information elsewhere.
|
|
||||||
//!
|
|
||||||
//! In order to simulate C API, we allocate a `size_and_data_ptr`
|
|
||||||
//! of size `sizeof(usize) + size` where `size` is the requested number
|
|
||||||
//! of bytes. Then, we store `size` at the beginning of the allocated
|
|
||||||
//! chunk (within those `sizeof(usize)` bytes) and return
|
|
||||||
//! `data_ptr = size_and_data_ptr + sizeof(usize)` to the calleer:
|
|
||||||
//!
|
|
||||||
//! [`size`][...actual data]
|
|
||||||
//! -^------------------ `size_and_data_ptr`
|
|
||||||
//! ---------^---------- `data_ptr`
|
|
||||||
//!
|
|
||||||
//! Then, in `free`, the caller gives us `data_ptr`. We can subtract
|
|
||||||
//! `sizeof(usize)` back and get the original `size_and_data_ptr`.
|
|
||||||
//! At this point we can read `size` back and call the Rust `dealloc`
|
|
||||||
//! for the whole allocated chunk.
|
|
||||||
//!
|
|
||||||
//! I've raised an upstream issue to hopefully make this easier in
|
|
||||||
//! future: https://github.com/ebiggers/libdeflate/issues/62
|
|
||||||
|
|
||||||
use std::alloc::*;
|
|
||||||
use std::mem::{align_of, size_of};
|
|
||||||
|
|
||||||
unsafe fn layout_for(size: usize) -> Layout {
|
|
||||||
Layout::from_size_align_unchecked(size_of::<usize>() + size, align_of::<usize>())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
|
|
||||||
let size_and_data_ptr = alloc(layout_for(size));
|
|
||||||
*(size_and_data_ptr as *mut usize) = size;
|
|
||||||
size_and_data_ptr.add(size_of::<usize>())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn free(data_ptr: *mut u8) {
|
|
||||||
let size_and_data_ptr = data_ptr.sub(size_of::<usize>());
|
|
||||||
let size = *(size_and_data_ptr as *const usize);
|
|
||||||
dealloc(size_and_data_ptr, layout_for(size))
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "codecs",
|
|
||||||
"version": "0.0.0"
|
|
||||||
}
|
|
||||||
5
codecs/resize/.gitignore
vendored
5
codecs/resize/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
**/*.rs.bk
|
|
||||||
target
|
|
||||||
bin/
|
|
||||||
pkg/README.md
|
|
||||||
lut.inc
|
|
||||||
284
codecs/resize/Cargo.lock
generated
284
codecs/resize/Cargo.lock
generated
@@ -1,284 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
[[package]]
|
|
||||||
name = "bumpalo"
|
|
||||||
version = "3.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console_error_panic_hook"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures"
|
|
||||||
version = "0.1.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "js-sys"
|
|
||||||
version = "0.3.41"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916"
|
|
||||||
dependencies = [
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.72"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memory_units"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "0.4.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid 0.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid 0.2.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "0.6.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.18",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "resize"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b9e653e390eafbfebb2b3c5fcfbc90d801bc410d0de1f44f266ffbf2151d28aa"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scoped-tls"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "squoosh-resize"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"console_error_panic_hook",
|
|
||||||
"resize",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"wasm-bindgen-test",
|
|
||||||
"wee_alloc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.18",
|
|
||||||
"quote 1.0.7",
|
|
||||||
"unicode-xid 0.2.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"wasm-bindgen-macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-backend"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df"
|
|
||||||
dependencies = [
|
|
||||||
"bumpalo",
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"proc-macro2 1.0.18",
|
|
||||||
"quote 1.0.7",
|
|
||||||
"syn",
|
|
||||||
"wasm-bindgen-shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-futures"
|
|
||||||
version = "0.3.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"futures",
|
|
||||||
"js-sys",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"web-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8"
|
|
||||||
dependencies = [
|
|
||||||
"quote 1.0.7",
|
|
||||||
"wasm-bindgen-macro-support",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-macro-support"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 1.0.18",
|
|
||||||
"quote 1.0.7",
|
|
||||||
"syn",
|
|
||||||
"wasm-bindgen-backend",
|
|
||||||
"wasm-bindgen-shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-shared"
|
|
||||||
version = "0.2.64"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-test"
|
|
||||||
version = "0.2.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
|
|
||||||
dependencies = [
|
|
||||||
"console_error_panic_hook",
|
|
||||||
"futures",
|
|
||||||
"js-sys",
|
|
||||||
"scoped-tls",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"wasm-bindgen-futures",
|
|
||||||
"wasm-bindgen-test-macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-bindgen-test-macro"
|
|
||||||
version = "0.2.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2 0.4.30",
|
|
||||||
"quote 0.6.13",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "web-sys"
|
|
||||||
version = "0.3.41"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d"
|
|
||||||
dependencies = [
|
|
||||||
"js-sys",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wee_alloc"
|
|
||||||
version = "0.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"memory_units",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu",
|
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "squoosh-resize"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Surma <surma@surma.link>"]
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
#crate-type = ["cdylib", "rlib"]
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["console_error_panic_hook", "wee_alloc"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
cfg-if = "0.1.2"
|
|
||||||
wasm-bindgen = "0.2.38"
|
|
||||||
resize = "0.3.0"
|
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
|
||||||
# logging them with `console.error`. This is great for development, but requires
|
|
||||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
|
||||||
# code size when deploying.
|
|
||||||
console_error_panic_hook = { version = "0.1.1", optional = true }
|
|
||||||
|
|
||||||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
|
|
||||||
# compared to the default allocator's ~10K. It is slower than the default
|
|
||||||
# allocator, however.
|
|
||||||
#
|
|
||||||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
|
||||||
wee_alloc = { version = "0.4.2", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
wasm-bindgen-test = "0.2"
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
# Tell `rustc` to optimize for small code size.
|
|
||||||
opt-level = "s"
|
|
||||||
lto = true
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
include!("./src/srgb.rs");
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
|
||||||
let mut srgb_to_linear_lut = String::from("static SRGB_TO_LINEAR_LUT: [f32; 256] = [");
|
|
||||||
let mut linear_to_srgb_lut = String::from("static LINEAR_TO_SRGB_LUT: [f32; 256] = [");
|
|
||||||
for i in 0..256 {
|
|
||||||
srgb_to_linear_lut.push_str(&format!("{0:.7}", srgb_to_linear((i as f32) / 255.0)));
|
|
||||||
srgb_to_linear_lut.push_str(",");
|
|
||||||
linear_to_srgb_lut.push_str(&format!("{0:.7}", linear_to_srgb((i as f32) / 255.0)));
|
|
||||||
linear_to_srgb_lut.push_str(",");
|
|
||||||
}
|
|
||||||
srgb_to_linear_lut.pop().unwrap();
|
|
||||||
linear_to_srgb_lut.pop().unwrap();
|
|
||||||
srgb_to_linear_lut.push_str("];");
|
|
||||||
linear_to_srgb_lut.push_str("];");
|
|
||||||
|
|
||||||
let mut file = std::fs::File::create("src/lut.inc")?;
|
|
||||||
file.write_all(srgb_to_linear_lut.as_bytes())?;
|
|
||||||
file.write_all(linear_to_srgb_lut.as_bytes())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
4
codecs/resize/package-lock.json
generated
4
codecs/resize/package-lock.json
generated
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "resize",
|
|
||||||
"lockfileVersion": 1
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "resize",
|
|
||||||
"scripts": {
|
|
||||||
"build": "../build-rust.sh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "squoosh-resize",
|
|
||||||
"collaborators": [
|
|
||||||
"Surma <surma@surma.link>"
|
|
||||||
],
|
|
||||||
"version": "0.1.0",
|
|
||||||
"files": [
|
|
||||||
"squoosh_resize_bg.wasm",
|
|
||||||
"squoosh_resize.js",
|
|
||||||
"squoosh_resize.d.ts"
|
|
||||||
],
|
|
||||||
"module": "squoosh_resize.js",
|
|
||||||
"types": "squoosh_resize.d.ts",
|
|
||||||
"sideEffects": false
|
|
||||||
}
|
|
||||||
14
codecs/resize/pkg/squoosh_resize.d.ts
vendored
14
codecs/resize/pkg/squoosh_resize.d.ts
vendored
@@ -1,14 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
/**
|
|
||||||
* @param {Uint8Array} input_image
|
|
||||||
* @param {number} input_width
|
|
||||||
* @param {number} input_height
|
|
||||||
* @param {number} output_width
|
|
||||||
* @param {number} output_height
|
|
||||||
* @param {number} typ_idx
|
|
||||||
* @param {boolean} premultiply
|
|
||||||
* @param {boolean} color_space_conversion
|
|
||||||
* @returns {Uint8Array}
|
|
||||||
*/
|
|
||||||
export function resize(input_image: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, typ_idx: number, premultiply: boolean, color_space_conversion: boolean): Uint8Array;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
import * as wasm from "./squoosh_resize_bg.wasm";
|
|
||||||
export * from "./squoosh_resize_bg.js";
|
|
||||||
6
codecs/resize/pkg/squoosh_resize_bg.d.ts
vendored
6
codecs/resize/pkg/squoosh_resize_bg.d.ts
vendored
@@ -1,6 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
/* eslint-disable */
|
|
||||||
export const memory: WebAssembly.Memory;
|
|
||||||
export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
|
|
||||||
export function __wbindgen_malloc(a: number): number;
|
|
||||||
export function __wbindgen_free(a: number, b: number): void;
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import * as wasm from './squoosh_resize_bg.wasm';
|
|
||||||
|
|
||||||
let cachegetUint8Memory0 = null;
|
|
||||||
function getUint8Memory0() {
|
|
||||||
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetUint8Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let WASM_VECTOR_LEN = 0;
|
|
||||||
|
|
||||||
function passArray8ToWasm0(arg, malloc) {
|
|
||||||
const ptr = malloc(arg.length * 1);
|
|
||||||
getUint8Memory0().set(arg, ptr / 1);
|
|
||||||
WASM_VECTOR_LEN = arg.length;
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cachegetInt32Memory0 = null;
|
|
||||||
function getInt32Memory0() {
|
|
||||||
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
||||||
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
||||||
}
|
|
||||||
return cachegetInt32Memory0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getArrayU8FromWasm0(ptr, len) {
|
|
||||||
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param {Uint8Array} input_image
|
|
||||||
* @param {number} input_width
|
|
||||||
* @param {number} input_height
|
|
||||||
* @param {number} output_width
|
|
||||||
* @param {number} output_height
|
|
||||||
* @param {number} typ_idx
|
|
||||||
* @param {boolean} premultiply
|
|
||||||
* @param {boolean} color_space_conversion
|
|
||||||
* @returns {Uint8Array}
|
|
||||||
*/
|
|
||||||
export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
|
|
||||||
var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
|
|
||||||
var len0 = WASM_VECTOR_LEN;
|
|
||||||
wasm.resize(8, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
|
|
||||||
var r0 = getInt32Memory0()[8 / 4 + 0];
|
|
||||||
var r1 = getInt32Memory0()[8 / 4 + 1];
|
|
||||||
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
||||||
wasm.__wbindgen_free(r0, r1 * 1);
|
|
||||||
return v1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,121 +0,0 @@
|
|||||||
extern crate cfg_if;
|
|
||||||
extern crate resize;
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use resize::Pixel::RGBA;
|
|
||||||
use resize::Type;
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
mod srgb;
|
|
||||||
use srgb::Clamp;
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
|
||||||
// allocator.
|
|
||||||
if #[cfg(feature = "wee_alloc")] {
|
|
||||||
extern crate wee_alloc;
|
|
||||||
#[global_allocator]
|
|
||||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
include!("./lut.inc");
|
|
||||||
|
|
||||||
// If `with_space_conversion` is true, this function returns 2 functions that
|
|
||||||
// convert from sRGB to linear RGB and vice versa. If `with_space_conversion` is
|
|
||||||
// false, the 2 functions returned do nothing.
|
|
||||||
fn converter_funcs(with_space_conversion: bool) -> ((fn(u8) -> f32), (fn(f32) -> u8)) {
|
|
||||||
if with_space_conversion {
|
|
||||||
(
|
|
||||||
|v| SRGB_TO_LINEAR_LUT[v as usize] * 255.0,
|
|
||||||
|v| (LINEAR_TO_SRGB_LUT[v as usize] * 255.0) as u8,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(|v| v as f32, |v| v as u8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If `with_alpha_premultiplication` is true, this function returns a function
|
|
||||||
// that premultiply the alpha channel with the given channel value and another
|
|
||||||
// function that reverses that process. If `with_alpha_premultiplication` is
|
|
||||||
// false, the functions just return the channel value.
|
|
||||||
fn alpha_multiplier_funcs(
|
|
||||||
with_alpha_premultiplication: bool,
|
|
||||||
) -> ((fn(f32, u8) -> u8), (fn(u8, u8) -> f32)) {
|
|
||||||
if with_alpha_premultiplication {
|
|
||||||
(
|
|
||||||
|v, a| (v * (a as f32) / 255.0) as u8,
|
|
||||||
|v, a| ((v as f32) * 255.0 / (a as f32)).clamp(0.0, 255.0),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(|v, _a| v as u8, |v, _a| v as f32)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn resize(
|
|
||||||
mut input_image: Vec<u8>,
|
|
||||||
input_width: usize,
|
|
||||||
input_height: usize,
|
|
||||||
output_width: usize,
|
|
||||||
output_height: usize,
|
|
||||||
typ_idx: usize,
|
|
||||||
premultiply: bool,
|
|
||||||
color_space_conversion: bool,
|
|
||||||
) -> Vec<u8> {
|
|
||||||
let typ = match typ_idx {
|
|
||||||
0 => Type::Triangle,
|
|
||||||
1 => Type::Catrom,
|
|
||||||
2 => Type::Mitchell,
|
|
||||||
3 => Type::Lanczos3,
|
|
||||||
_ => panic!("Nope"),
|
|
||||||
};
|
|
||||||
let num_input_pixels = input_width * input_height;
|
|
||||||
let num_output_pixels = output_width * output_height;
|
|
||||||
|
|
||||||
let (to_linear, to_color_space) = converter_funcs(color_space_conversion);
|
|
||||||
let (premultiplier, demultiplier) = alpha_multiplier_funcs(premultiply);
|
|
||||||
|
|
||||||
// If both options are false, there is no preprocessing on the pixel valus
|
|
||||||
// and we can skip the loop.
|
|
||||||
if premultiply || color_space_conversion {
|
|
||||||
for i in 0..num_input_pixels {
|
|
||||||
for j in 0..3 {
|
|
||||||
input_image[4 * i + j] =
|
|
||||||
premultiplier(to_linear(input_image[4 * i + j]), input_image[4 * i + 3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut resizer = resize::new(
|
|
||||||
input_width,
|
|
||||||
input_height,
|
|
||||||
output_width,
|
|
||||||
output_height,
|
|
||||||
RGBA,
|
|
||||||
typ,
|
|
||||||
);
|
|
||||||
let mut output_image = Vec::<u8>::with_capacity(num_output_pixels * 4);
|
|
||||||
output_image.resize(num_output_pixels * 4, 0);
|
|
||||||
resizer.resize(input_image.as_slice(), output_image.as_mut_slice());
|
|
||||||
|
|
||||||
if premultiply || color_space_conversion {
|
|
||||||
for i in 0..num_output_pixels {
|
|
||||||
for j in 0..3 {
|
|
||||||
// We don’t need to worry about division by zero, as division by zero
|
|
||||||
// is well-defined on floats to return ±Inf. ±Inf is converted to 0
|
|
||||||
// when casting to integers.
|
|
||||||
output_image[4 * i + j] = to_color_space(demultiplier(
|
|
||||||
output_image[4 * i + j],
|
|
||||||
output_image[4 * i + 3],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output_image;
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
pub trait Clamp: std::cmp::PartialOrd + Sized {
|
|
||||||
fn clamp(self, min: Self, max: Self) -> Self {
|
|
||||||
if self.lt(&min) {
|
|
||||||
min
|
|
||||||
} else if self.gt(&max) {
|
|
||||||
max
|
|
||||||
} else {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clamp for f32 {}
|
|
||||||
|
|
||||||
pub fn srgb_to_linear(v: f32) -> f32 {
|
|
||||||
if v < 0.04045 {
|
|
||||||
v / 12.92
|
|
||||||
} else {
|
|
||||||
((v + 0.055) / 1.055).powf(2.4).clamp(0.0, 1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn linear_to_srgb(v: f32) -> f32 {
|
|
||||||
if v < 0.0031308 {
|
|
||||||
v * 12.92
|
|
||||||
} else {
|
|
||||||
(1.055 * v.powf(1.0 / 2.4) - 0.055).clamp(0.0, 1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
use cfg_if::cfg_if;
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
// When the `console_error_panic_hook` feature is enabled, we can call the
|
|
||||||
// `set_panic_hook` function at least once during initialization, and then
|
|
||||||
// we will get better error messages if our code ever panics.
|
|
||||||
//
|
|
||||||
// For more details see
|
|
||||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
|
||||||
if #[cfg(feature = "console_error_panic_hook")] {
|
|
||||||
extern crate console_error_panic_hook;
|
|
||||||
pub use self::console_error_panic_hook::set_once as set_panic_hook;
|
|
||||||
} else {
|
|
||||||
#[inline]
|
|
||||||
pub fn set_panic_hook() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
codecs/rotate/.gitignore
vendored
1
codecs/rotate/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
target
|
|
||||||
6
codecs/rotate/Cargo.lock
generated
6
codecs/rotate/Cargo.lock
generated
@@ -1,6 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
[[package]]
|
|
||||||
name = "squoosh-rotate"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "squoosh-rotate"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Surma <surma@google.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "rotate"
|
|
||||||
path = "rotate.rs"
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
opt-level = "s"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
FROM rust
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
|
||||||
|
|
||||||
RUN mkdir /opt/wabt && \
|
|
||||||
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.11/wabt-1.0.11-linux.tar.gz | tar -xzf - -C /opt/wabt --strip 1
|
|
||||||
|
|
||||||
ENV PATH="/opt/wabt:${PATH}"
|
|
||||||
WORKDIR /src
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// THIS IS NOT A NODE SCRIPT
|
|
||||||
// This is a d8 script. Please install jsvu[1] and install v8.
|
|
||||||
// Then run `npm run --silent benchmark`.
|
|
||||||
// [1]: https://github.com/GoogleChromeLabs/jsvu
|
|
||||||
async function init() {
|
|
||||||
// Adjustable constants.
|
|
||||||
const imageDimensions = 4096;
|
|
||||||
const iterations = new Array(100);
|
|
||||||
|
|
||||||
// Constants. Don’t change.
|
|
||||||
const imageByteSize = imageDimensions * imageDimensions * 4;
|
|
||||||
const wasmPageSize = 64 * 1024;
|
|
||||||
|
|
||||||
const buffer = readbuffer("rotate.wasm");
|
|
||||||
const { instance } = await WebAssembly.instantiate(buffer);
|
|
||||||
|
|
||||||
const pagesAvailable = Math.floor(
|
|
||||||
instance.exports.memory.buffer.byteLength / wasmPageSize
|
|
||||||
);
|
|
||||||
const pagesNeeded = Math.floor((imageByteSize * 2 + 4) / wasmPageSize) + 1;
|
|
||||||
const additionalPagesNeeded = pagesNeeded - pagesAvailable;
|
|
||||||
if (additionalPagesNeeded > 0) {
|
|
||||||
instance.exports.memory.grow(additionalPagesNeeded);
|
|
||||||
}
|
|
||||||
|
|
||||||
[0, 90, 180, 270].forEach(rotation => {
|
|
||||||
print(`\n${rotation} degrees`);
|
|
||||||
print(`==============================`);
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
const start = Date.now();
|
|
||||||
instance.exports.rotate(imageDimensions, imageDimensions, rotation);
|
|
||||||
iterations[i] = Date.now() - start;
|
|
||||||
}
|
|
||||||
const average = iterations.reduce((sum, c) => sum + c) / iterations.length;
|
|
||||||
const stddev = Math.sqrt(
|
|
||||||
iterations
|
|
||||||
.map(i => Math.pow(i - average, 2))
|
|
||||||
.reduce((sum, c) => sum + c) / iterations.length
|
|
||||||
);
|
|
||||||
print(`n = ${iterations.length}`);
|
|
||||||
print(`Average: ${average}`);
|
|
||||||
print(`StdDev: ${stddev}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
init().catch(e => console.error(e.stack));
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cargo build \
|
|
||||||
--target wasm32-unknown-unknown \
|
|
||||||
--release
|
|
||||||
wasm-opt -Os --strip target/wasm32-unknown-unknown/release/rotate.wasm -o rotate.wasm
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "rotate",
|
|
||||||
"scripts": {
|
|
||||||
"build": "../build-rust.sh ./build.sh",
|
|
||||||
"benchmark": "echo File size after gzip && npm run benchmark:filesize && echo Optimizing && npm run -s benchmark:optimizing",
|
|
||||||
"benchmark:baseline": "v8 --liftoff --no-wasm-tier-up --no-opt ./benchmark.js",
|
|
||||||
"benchmark:optimizing": "v8 --no-liftoff --no-wasm-tier-up ./benchmark.js",
|
|
||||||
"benchmark:filesize": "cat rotate.wasm | gzip -c9n | wc -c"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
use std::slice::{from_raw_parts, from_raw_parts_mut};
|
|
||||||
|
|
||||||
// This function is taken from Zachary Dremann
|
|
||||||
// https://github.com/GoogleChromeLabs/squoosh/pull/462
|
|
||||||
trait HardUnwrap<T> {
|
|
||||||
fn unwrap_hard(self) -> T;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> HardUnwrap<T> for Option<T> {
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
#[inline]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
match self {
|
|
||||||
Some(t) => t,
|
|
||||||
None => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
self.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TILE_SIZE: usize = 16;
|
|
||||||
|
|
||||||
fn get_buffers<'a>(width: usize, height: usize) -> (&'a [u32], &'a mut [u32]) {
|
|
||||||
let num_pixels = width * height;
|
|
||||||
let in_b: &[u32];
|
|
||||||
let out_b: &mut [u32];
|
|
||||||
unsafe {
|
|
||||||
in_b = from_raw_parts::<u32>(8 as *const u32, num_pixels);
|
|
||||||
out_b = from_raw_parts_mut::<u32>((num_pixels * 4 + 8) as *mut u32, num_pixels);
|
|
||||||
}
|
|
||||||
return (in_b, out_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_0(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_90(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let _new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = (new_width - 1) - y;
|
|
||||||
let new_y = x + x_start;
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_180(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut().rev()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_270(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = y;
|
|
||||||
let new_y = new_height - 1 - (x_start + x);
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
fn rotate(width: usize, height: usize, rotate: usize) {
|
|
||||||
match rotate {
|
|
||||||
0 => rotate_0(width, height),
|
|
||||||
90 => rotate_90(width, height),
|
|
||||||
180 => rotate_180(width, height),
|
|
||||||
270 => rotate_270(width, height),
|
|
||||||
_ => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,15 +0,0 @@
|
|||||||
FROM emscripten/emsdk:1.39.19 AS wasm-tools
|
|
||||||
WORKDIR /opt/wasm-tools
|
|
||||||
RUN wget -qO- https://github.com/rustwasm/wasm-pack/releases/download/v0.9.1/wasm-pack-v0.9.1-x86_64-unknown-linux-musl.tar.gz | tar -xzf - --strip 1
|
|
||||||
|
|
||||||
FROM rust:1.44-stretch AS rust
|
|
||||||
RUN rustup target add wasm32-unknown-unknown
|
|
||||||
COPY --from=wasm-tools /emsdk/upstream/bin/wasm-opt /emsdk/upstream/bin/clang /usr/local/bin/
|
|
||||||
COPY --from=wasm-tools /emsdk/upstream/lib/ /usr/local/lib/
|
|
||||||
COPY --from=wasm-tools /emsdk/upstream/emscripten/system/include/libc/ /wasm32/include/
|
|
||||||
COPY --from=wasm-tools /emsdk/upstream/emscripten/system/lib/libc/musl/arch/emscripten/bits/ /wasm32/include/bits/
|
|
||||||
COPY --from=wasm-tools /opt/wasm-tools/wasm-pack /usr/local/cargo/bin/
|
|
||||||
|
|
||||||
ENV CPATH="/wasm32/include"
|
|
||||||
WORKDIR /src
|
|
||||||
CMD ["sh", "-c", "rm -rf pkg && wasm-pack build -- --verbose --locked && rm pkg/.gitignore"]
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user