mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Compare commits
122 Commits
v1.2.2
...
oxipng-old
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6f69c57cf | ||
|
|
9e19c36b42 | ||
|
|
cf45520be3 | ||
|
|
8faf8a5b48 | ||
|
|
cb16fb5437 | ||
|
|
36f5fa2c47 | ||
|
|
51ad22e72c | ||
|
|
1a355c0c16 | ||
|
|
fe5ba08963 | ||
|
|
7fc994d4af | ||
|
|
a0a8285e02 | ||
|
|
da2e35f613 | ||
|
|
09bdc25352 | ||
|
|
ad263a9c36 | ||
|
|
c8d8d4e43d | ||
|
|
94249b8a93 | ||
|
|
edd2c51eb6 | ||
|
|
1d24e9399f | ||
|
|
3a0062276d | ||
|
|
1993cf3f6c | ||
|
|
c97aac31c6 | ||
|
|
507921cbe8 | ||
|
|
887db675c8 | ||
|
|
3917618e4e | ||
|
|
3c42d2e6a4 | ||
|
|
db8777b7f7 | ||
|
|
18c2cddee2 | ||
|
|
3ff9d3a1fa | ||
|
|
6503667c78 | ||
|
|
0fa95f84d4 | ||
|
|
cf91a90270 | ||
|
|
690052f989 | ||
|
|
b3e935f7e4 | ||
|
|
17314ebd29 | ||
|
|
adc437cd51 | ||
|
|
0e97b74510 | ||
|
|
9ffb475cac | ||
|
|
faa2b030c5 | ||
|
|
e3b3b10e2a | ||
|
|
b569cf268c | ||
|
|
b154b77556 | ||
|
|
84c0f30a7c | ||
|
|
16463ff76d | ||
|
|
8314e9e24b | ||
|
|
a33c557818 | ||
|
|
6fbdc65ad0 | ||
|
|
9c9b6c4711 | ||
|
|
46278d04c3 | ||
|
|
c1c16508b5 | ||
|
|
ed1b983711 | ||
|
|
ec23e28eda | ||
|
|
d48b49e8e4 | ||
|
|
14308970c6 | ||
|
|
38e86e1012 | ||
|
|
e9a33af831 | ||
|
|
6a63e5dbb2 | ||
|
|
1e1892a3d5 | ||
|
|
8bff9a2973 | ||
|
|
cbe753dd29 | ||
|
|
b047845b43 | ||
|
|
1bebc75381 | ||
|
|
93c46bfc8d | ||
|
|
a3d0f5963e | ||
|
|
006b82bf05 | ||
|
|
c36e37ac6b | ||
|
|
3cf6d7385a | ||
|
|
9045b2fa97 | ||
|
|
be6f3b9c6d | ||
|
|
5a699b7ce9 | ||
|
|
f366a78e87 | ||
|
|
c63c7ead51 | ||
|
|
ecfa5902cd | ||
|
|
444027b496 | ||
|
|
9c5dcb93c7 | ||
|
|
9594221271 | ||
|
|
01823d3b75 | ||
|
|
db07a90139 | ||
|
|
962d0928d3 | ||
|
|
e67d50c8e6 | ||
|
|
f9b2f17852 | ||
|
|
9746a9f5ed | ||
|
|
be0877ecb0 | ||
|
|
d2fcdfae43 | ||
|
|
2c9eb46941 | ||
|
|
d30a85fd48 | ||
|
|
9260bed1b1 | ||
|
|
f6d12985a9 | ||
|
|
10c9b1db7c | ||
|
|
4fb17be8de | ||
|
|
b592b1a088 | ||
|
|
0544a6507e | ||
|
|
1e20ff15ed | ||
|
|
04a0ec0645 | ||
|
|
f355292fe3 | ||
|
|
32e4d813de | ||
|
|
f960f5ea87 | ||
|
|
aa6f83e2fa | ||
|
|
c09e1f1895 | ||
|
|
7c311928dd | ||
|
|
5f1c8bcb6b | ||
|
|
93bc20f014 | ||
|
|
d29d9571c6 | ||
|
|
3d47dfc820 | ||
|
|
d7846c9add | ||
|
|
4d6fe9d641 | ||
|
|
205feba75d | ||
|
|
ca7663b94a | ||
|
|
83e45f054b | ||
|
|
783e893a67 | ||
|
|
0a941866a9 | ||
|
|
04edfe0085 | ||
|
|
6cae634eca | ||
|
|
8c7bf278dc | ||
|
|
f6106650b5 | ||
|
|
166e606034 | ||
|
|
c997e6a3e4 | ||
|
|
2a1b6dc9da | ||
|
|
129c33fa12 | ||
|
|
3245987113 | ||
|
|
593ad62cbb | ||
|
|
a625a76e9e | ||
|
|
c2a305304b |
2
_redirects.ejs
Normal file
2
_redirects.ejs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/index.html / 301
|
||||||
|
/* /index.html 301
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
"libimagequant": "ImageOptim/libimagequant#2.12.1"
|
"libimagequant": "ImageOptim/libimagequant#2.12.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "^3.0.0"
|
"napa": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
"mozjpeg": "mozilla/mozjpeg#v3.3.1"
|
"mozjpeg": "mozilla/mozjpeg#v3.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "^3.0.0"
|
"napa": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# OptiPNG
|
# OptiPNG
|
||||||
|
|
||||||
- Source: <https://sourceforge.net/project/optipng>
|
- Source: <http://optipng.sourceforge.net/>
|
||||||
- Version: v0.7.7
|
- Version: v0.7.7
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"zlib": "emscripten-ports/zlib"
|
"zlib": "emscripten-ports/zlib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"napa": "^3.0.0",
|
"napa": "3.0.0",
|
||||||
"tar-dependency": "0.0.3"
|
"tar-dependency": "0.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
codecs/oxipng/.cargo-ok
Normal file
0
codecs/oxipng/.cargo-ok
Normal file
5
codecs/oxipng/.gitignore
vendored
Normal file
5
codecs/oxipng/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
|
bin/
|
||||||
|
wasm-pack.log
|
||||||
36
codecs/oxipng/Cargo.toml
Normal file
36
codecs/oxipng/Cargo.toml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
[package]
|
||||||
|
name = "test"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Surma <surma@surma.link>"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "lib.rs"
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cfg-if = "0.1.2"
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
|
oxipng = "2.2.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"
|
||||||
52
codecs/oxipng/README.md
Normal file
52
codecs/oxipng/README.md
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# 🦀🕸️ `wasm-pack-template`
|
||||||
|
|
||||||
|
A template for kick starting a Rust and WebAssembly project using
|
||||||
|
[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
|
||||||
|
|
||||||
|
This template is designed for compiling Rust libraries into WebAssembly and
|
||||||
|
publishing the resulting package to NPM.
|
||||||
|
|
||||||
|
* Want to use the published NPM package in a Website? [Check out
|
||||||
|
`create-wasm-app`.](https://github.com/rustwasm/create-wasm-app)
|
||||||
|
* Want to make a monorepo-style Website without publishing to NPM? Check out
|
||||||
|
[`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
|
||||||
|
and/or
|
||||||
|
[`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
|
||||||
|
|
||||||
|
## 🔋 Batteries Included
|
||||||
|
|
||||||
|
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
|
||||||
|
between WebAssembly and JavaScript.
|
||||||
|
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
|
||||||
|
for logging panic messages to the developer console.
|
||||||
|
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
|
||||||
|
for small code size.
|
||||||
|
|
||||||
|
## 🚴 Usage
|
||||||
|
|
||||||
|
### 🐑 Use `cargo generate` to Clone this Template
|
||||||
|
|
||||||
|
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
|
||||||
|
cd my-project
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🛠️ Build with `wasm-pack build`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack build
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔬 Test in Headless Browsers with `wasm-pack test`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack test --headless --firefox
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🎁 Publish to NPM with `wasm-pack publish`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack publish
|
||||||
|
```
|
||||||
5
codecs/oxipng/Xargo.toml
Normal file
5
codecs/oxipng/Xargo.toml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[target.wasm32-unknown-unknown.dependencies]
|
||||||
|
time = {}
|
||||||
|
|
||||||
|
[target.wasm32-unknown-unknown.dependencies.std]
|
||||||
|
features = ["wasm_syscall"]
|
||||||
52
codecs/oxipng/pkg/README.md
Normal file
52
codecs/oxipng/pkg/README.md
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# 🦀🕸️ `wasm-pack-template`
|
||||||
|
|
||||||
|
A template for kick starting a Rust and WebAssembly project using
|
||||||
|
[`wasm-pack`](https://github.com/rustwasm/wasm-pack).
|
||||||
|
|
||||||
|
This template is designed for compiling Rust libraries into WebAssembly and
|
||||||
|
publishing the resulting package to NPM.
|
||||||
|
|
||||||
|
* Want to use the published NPM package in a Website? [Check out
|
||||||
|
`create-wasm-app`.](https://github.com/rustwasm/create-wasm-app)
|
||||||
|
* Want to make a monorepo-style Website without publishing to NPM? Check out
|
||||||
|
[`rust-webpack-template`](https://github.com/rustwasm/rust-webpack-template)
|
||||||
|
and/or
|
||||||
|
[`rust-parcel-template`](https://github.com/rustwasm/rust-parcel-template).
|
||||||
|
|
||||||
|
## 🔋 Batteries Included
|
||||||
|
|
||||||
|
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
|
||||||
|
between WebAssembly and JavaScript.
|
||||||
|
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
|
||||||
|
for logging panic messages to the developer console.
|
||||||
|
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized
|
||||||
|
for small code size.
|
||||||
|
|
||||||
|
## 🚴 Usage
|
||||||
|
|
||||||
|
### 🐑 Use `cargo generate` to Clone this Template
|
||||||
|
|
||||||
|
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
|
||||||
|
cd my-project
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🛠️ Build with `wasm-pack build`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack build
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔬 Test in Headless Browsers with `wasm-pack test`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack test --headless --firefox
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🎁 Publish to NPM with `wasm-pack publish`
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm-pack publish
|
||||||
|
```
|
||||||
BIN
codecs/oxipng/pkg/img.png
Normal file
BIN
codecs/oxipng/pkg/img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
14
codecs/oxipng/pkg/lol.js
Normal file
14
codecs/oxipng/pkg/lol.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const oxipng = require("./oxipng_wasm");
|
||||||
|
const repl = require("repl");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
// const img = fs.readFileSync("img.png")
|
||||||
|
// const output = oxipng.compress(img, 0);
|
||||||
|
// fs.writeFileSync("output.png", output);
|
||||||
|
console.log(">>>", oxipng.doit());
|
||||||
|
const r = repl.start("node> ");
|
||||||
|
r.context.i = oxipng;
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
3
codecs/oxipng/pkg/oxipng.d.ts
vendored
Normal file
3
codecs/oxipng/pkg/oxipng.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
export function compress(arg0: Uint8Array, arg1: number): Uint8Array;
|
||||||
|
|
||||||
73
codecs/oxipng/pkg/oxipng.js
Normal file
73
codecs/oxipng/pkg/oxipng.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
var wasm;
|
||||||
|
|
||||||
|
const TextDecoder = require('util').TextDecoder;
|
||||||
|
|
||||||
|
let cachedTextDecoder = new TextDecoder('utf-8');
|
||||||
|
|
||||||
|
let cachegetUint8Memory = null;
|
||||||
|
function getUint8Memory() {
|
||||||
|
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetUint8Memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStringFromWasm(ptr, len) {
|
||||||
|
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.__wbg_log_64e6f53d8e6d5db5 = function(arg0, arg1) {
|
||||||
|
let varg0 = getStringFromWasm(arg0, arg1);
|
||||||
|
console.log(varg0);
|
||||||
|
};
|
||||||
|
|
||||||
|
let WASM_VECTOR_LEN = 0;
|
||||||
|
|
||||||
|
function passArray8ToWasm(arg) {
|
||||||
|
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
||||||
|
getUint8Memory().set(arg, ptr / 1);
|
||||||
|
WASM_VECTOR_LEN = arg.length;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayU8FromWasm(ptr, len) {
|
||||||
|
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachedGlobalArgumentPtr = null;
|
||||||
|
function globalArgumentPtr() {
|
||||||
|
if (cachedGlobalArgumentPtr === null) {
|
||||||
|
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
||||||
|
}
|
||||||
|
return cachedGlobalArgumentPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachegetUint32Memory = null;
|
||||||
|
function getUint32Memory() {
|
||||||
|
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetUint32Memory;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param {Uint8Array} arg0
|
||||||
|
* @param {number} arg1
|
||||||
|
* @returns {Uint8Array}
|
||||||
|
*/
|
||||||
|
module.exports.compress = function(arg0, arg1) {
|
||||||
|
const ptr0 = passArray8ToWasm(arg0);
|
||||||
|
const len0 = WASM_VECTOR_LEN;
|
||||||
|
const retptr = globalArgumentPtr();
|
||||||
|
wasm.compress(retptr, ptr0, len0, arg1);
|
||||||
|
const mem = getUint32Memory();
|
||||||
|
const rustptr = mem[retptr / 4];
|
||||||
|
const rustlen = mem[retptr / 4 + 1];
|
||||||
|
|
||||||
|
const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
|
||||||
|
wasm.__wbindgen_free(rustptr, rustlen * 1);
|
||||||
|
return realRet;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
wasm = require('./oxipng_bg');
|
||||||
6
codecs/oxipng/pkg/oxipng_bg.d.ts
vendored
Normal file
6
codecs/oxipng/pkg/oxipng_bg.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
export const memory: WebAssembly.Memory;
|
||||||
|
export function __wbindgen_global_argument_ptr(): number;
|
||||||
|
export function compress(a: number, b: number, c: number, d: number): void;
|
||||||
|
export function __wbindgen_malloc(a: number): number;
|
||||||
|
export function __wbindgen_free(a: number, b: number): void;
|
||||||
9
codecs/oxipng/pkg/oxipng_bg.js
Normal file
9
codecs/oxipng/pkg/oxipng_bg.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
const path = require('path').join(__dirname, 'oxipng_bg.wasm');
|
||||||
|
const bytes = require('fs').readFileSync(path);
|
||||||
|
let imports = {};
|
||||||
|
imports['./oxipng'] = require('./oxipng');
|
||||||
|
|
||||||
|
const wasmModule = new WebAssembly.Module(bytes);
|
||||||
|
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
||||||
|
module.exports = wasmInstance.exports;
|
||||||
BIN
codecs/oxipng/pkg/oxipng_bg.wasm
Normal file
BIN
codecs/oxipng/pkg/oxipng_bg.wasm
Normal file
Binary file not shown.
3
codecs/oxipng/pkg/oxipng_manual.d.ts
vendored
Normal file
3
codecs/oxipng/pkg/oxipng_manual.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
export function compress(arg0: Uint8Array, arg1: number): Promise<Uint8Array>;
|
||||||
|
|
||||||
77
codecs/oxipng/pkg/oxipng_manual.js
Normal file
77
codecs/oxipng/pkg/oxipng_manual.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
import wasmUrl from './oxipng_bg.wasm';
|
||||||
|
|
||||||
|
let wasm;
|
||||||
|
const instancePromise = WebAssembly.instantiateStreaming(fetch(wasmUrl), {
|
||||||
|
"./oxipng": {__wbg_log_64e6f53d8e6d5db5}
|
||||||
|
});
|
||||||
|
|
||||||
|
let cachedTextDecoder = new TextDecoder('utf-8');
|
||||||
|
|
||||||
|
let cachegetUint8Memory = null;
|
||||||
|
function getUint8Memory() {
|
||||||
|
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetUint8Memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStringFromWasm(ptr, len) {
|
||||||
|
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function __wbg_log_64e6f53d8e6d5db5(arg0, arg1) {
|
||||||
|
let varg0 = getStringFromWasm(arg0, arg1);
|
||||||
|
console.log(varg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let WASM_VECTOR_LEN = 0;
|
||||||
|
|
||||||
|
function passArray8ToWasm(arg) {
|
||||||
|
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
|
||||||
|
getUint8Memory().set(arg, ptr / 1);
|
||||||
|
WASM_VECTOR_LEN = arg.length;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayU8FromWasm(ptr, len) {
|
||||||
|
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachedGlobalArgumentPtr = null;
|
||||||
|
function globalArgumentPtr() {
|
||||||
|
if (cachedGlobalArgumentPtr === null) {
|
||||||
|
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
||||||
|
}
|
||||||
|
return cachedGlobalArgumentPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cachegetUint32Memory = null;
|
||||||
|
function getUint32Memory() {
|
||||||
|
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
|
||||||
|
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
|
||||||
|
}
|
||||||
|
return cachegetUint32Memory;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param {Uint8Array} arg0
|
||||||
|
* @param {number} arg1
|
||||||
|
* @returns {Uint8Array}
|
||||||
|
*/
|
||||||
|
export async function compress(arg0, arg1) {
|
||||||
|
wasm = (await instancePromise).instance.exports;
|
||||||
|
debugger;
|
||||||
|
const ptr0 = passArray8ToWasm(arg0);
|
||||||
|
const len0 = WASM_VECTOR_LEN;
|
||||||
|
const retptr = globalArgumentPtr();
|
||||||
|
wasm.compress(retptr, ptr0, len0, arg1);
|
||||||
|
const mem = getUint32Memory();
|
||||||
|
const rustptr = mem[retptr / 4];
|
||||||
|
const rustlen = mem[retptr / 4 + 1];
|
||||||
|
|
||||||
|
const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
|
||||||
|
wasm.__wbindgen_free(rustptr, rustlen * 1);
|
||||||
|
return realRet;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
3
codecs/oxipng/pkg/oxipng_wasm.d.ts
vendored
Normal file
3
codecs/oxipng/pkg/oxipng_wasm.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
export function doit(): number;
|
||||||
|
|
||||||
11
codecs/oxipng/pkg/oxipng_wasm.js
Normal file
11
codecs/oxipng/pkg/oxipng_wasm.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
var wasm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
module.exports.doit = function() {
|
||||||
|
return wasm.doit();
|
||||||
|
};
|
||||||
|
|
||||||
|
wasm = require('./oxipng_wasm_bg');
|
||||||
3
codecs/oxipng/pkg/oxipng_wasm_bg.d.ts
vendored
Normal file
3
codecs/oxipng/pkg/oxipng_wasm_bg.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/* tslint:disable */
|
||||||
|
export const memory: WebAssembly.Memory;
|
||||||
|
export function doit(): number;
|
||||||
8
codecs/oxipng/pkg/oxipng_wasm_bg.js
Normal file
8
codecs/oxipng/pkg/oxipng_wasm_bg.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
const path = require('path').join(__dirname, 'oxipng_wasm_bg.wasm');
|
||||||
|
const bytes = require('fs').readFileSync(path);
|
||||||
|
let imports = {};
|
||||||
|
|
||||||
|
const wasmModule = new WebAssembly.Module(bytes);
|
||||||
|
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
||||||
|
module.exports = wasmInstance.exports;
|
||||||
BIN
codecs/oxipng/pkg/oxipng_wasm_bg.wasm
Normal file
BIN
codecs/oxipng/pkg/oxipng_wasm_bg.wasm
Normal file
Binary file not shown.
15
codecs/oxipng/pkg/package.json
Normal file
15
codecs/oxipng/pkg/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "oxipng-wasm",
|
||||||
|
"collaborators": [
|
||||||
|
"Surma <surma@surma.link>"
|
||||||
|
],
|
||||||
|
"version": "0.1.0",
|
||||||
|
"files": [
|
||||||
|
"oxipng_wasm_bg.wasm",
|
||||||
|
"oxipng_wasm.js",
|
||||||
|
"oxipng_wasm_bg.js",
|
||||||
|
"oxipng_wasm.d.ts"
|
||||||
|
],
|
||||||
|
"main": "oxipng_wasm.js",
|
||||||
|
"types": "oxipng_wasm.d.ts"
|
||||||
|
}
|
||||||
0
codecs/oxipng/pkg/test/lol.rs
Normal file
0
codecs/oxipng/pkg/test/lol.rs
Normal file
42
codecs/oxipng/src/lib.rs
Normal file
42
codecs/oxipng/src/lib.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
extern crate cfg_if;
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
// extern crate oxipng;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use std::time::{Instant};
|
||||||
|
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]
|
||||||
|
// extern {
|
||||||
|
// #[wasm_bindgen(js_namespace = console)]
|
||||||
|
// fn log(s: &str);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// #[wasm_bindgen]
|
||||||
|
// pub fn compress(img: Vec<u8>, level: u8) -> Vec<u8> {
|
||||||
|
// log(&format!("len: {}, level: {}", img.len(), level));
|
||||||
|
// let mut options = oxipng::Options::from_preset(level);
|
||||||
|
// options.threads = 0;
|
||||||
|
// let result = oxipng::optimize_from_memory(img.as_slice(), &options);
|
||||||
|
// match result {
|
||||||
|
// Ok(v) => v,
|
||||||
|
// Err(e) => e.to_string().as_bytes().to_vec()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn doit() -> u32 {
|
||||||
|
let start = Instant::now();
|
||||||
|
start.elapsed().as_secs() as u32
|
||||||
|
}
|
||||||
17
codecs/oxipng/src/utils.rs
Normal file
17
codecs/oxipng/src/utils.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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/oxipng/tmp/.gitignore
vendored
Normal file
1
codecs/oxipng/tmp/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target
|
||||||
27
codecs/oxipng/tmp/Cargo.toml
Normal file
27
codecs/oxipng/tmp/Cargo.toml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
[package]
|
||||||
|
name = "loltest"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Surma <surma@surma.link>"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "lib.rs"
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wasm-bindgen = "0.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 }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
wasm-bindgen-test = "0.2"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
# Tell `rustc` to optimize for small code size.
|
||||||
|
opt-level = "s"
|
||||||
2
codecs/oxipng/tmp/Xargo.toml
Normal file
2
codecs/oxipng/tmp/Xargo.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[dependencies.std]
|
||||||
|
features = ["wasm_syscall"]
|
||||||
20
codecs/oxipng/tmp/_README.md
Normal file
20
codecs/oxipng/tmp/_README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
I’m trying to activate [the `wasm_syscall` feature][1] in Rust’s stdlib for WebAssembly.
|
||||||
|
|
||||||
|
Here is my `Cargo.toml` and my `Xargo.toml`. But even with this setup the generated wasm file is still hard-coded to panic.
|
||||||
|
|
||||||
|
**HELP?**
|
||||||
|
|
||||||
|
My current command to compile is:
|
||||||
|
|
||||||
|
```
|
||||||
|
xargo build --target wasm32-unknown-unknown --release
|
||||||
|
```
|
||||||
|
|
||||||
|
If you have [`wasm2wat`][2] installed, you can verify the generate code via
|
||||||
|
|
||||||
|
```
|
||||||
|
wasm2wat target/wasm32-unknown-unknown/release/loltest.wasm | grep -A5 perform::
|
||||||
|
```
|
||||||
|
|
||||||
|
[1]: https://github.com/rust-lang/rust/blob/b139669f374eb5024a50eb13f116ff763b1c5935/src/libstd/sys/wasm/mod.rs#L309
|
||||||
|
[2]: https://github.com/WebAssembly/wabt
|
||||||
14
codecs/oxipng/tmp/lib.rs
Normal file
14
codecs/oxipng/tmp/lib.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use std::thread::spawn;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn doit() {
|
||||||
|
// let child = spawn(move || -> u32 {
|
||||||
|
// 5
|
||||||
|
// });
|
||||||
|
// let result = child.join().unwrap();
|
||||||
|
let result = spawn();
|
||||||
|
println!("Result: {}", result);
|
||||||
|
}
|
||||||
47
codecs/oxipng/tmp/lol.js
Normal file
47
codecs/oxipng/tmp/lol.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// const oxipng = require("./oxipng_wasm");
|
||||||
|
const repl = require("repl");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const dec = new TextDecoder();
|
||||||
|
let buffer = '';
|
||||||
|
async function init() {
|
||||||
|
const { instance } = await WebAssembly.instantiate(
|
||||||
|
fs.readFileSync("./target/wasm32-unknown-unknown/release/loltest.wasm"),
|
||||||
|
{
|
||||||
|
__wbindgen_placeholder__: {
|
||||||
|
__wbindgen_describe(v) {
|
||||||
|
console.log(`__wbindgen_desribe(${v})`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
env: {
|
||||||
|
// See https://github.com/rust-lang/rust/blob/master/src/libstd/sys/wasm/mod.rs
|
||||||
|
rust_wasm_syscall(syscall, ptr) {
|
||||||
|
switch(syscall) {
|
||||||
|
case 1: // Write
|
||||||
|
const [fd, dataPtr, len] = new Uint32Array(instance.exports.memory.buffer, ptr, 3 * 4);
|
||||||
|
const fragment = new Uint8Array(instance.exports.memory.buffer, dataPtr, len);
|
||||||
|
buffer += dec.decode(fragment);
|
||||||
|
const idx = buffer.indexOf('\n');
|
||||||
|
if(idx !== -1) {
|
||||||
|
console.log(buffer.slice(0, idx));
|
||||||
|
buffer = buffer.slice(idx);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
case 6: // Time
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return 0; // False, unimplemented
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
instance.exports.doit();
|
||||||
|
} catch{}
|
||||||
|
const r = repl.start("node> ");
|
||||||
|
r.context.i = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
1737
codecs/oxipng/tmp/thread_mod.rs
Normal file
1737
codecs/oxipng/tmp/thread_mod.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
# WebP decoder
|
# WebP decoder
|
||||||
|
|
||||||
- Source: <https://github.com/webmproject/libwebp>
|
- Source: <https://github.com/webmproject/libwebp>
|
||||||
- Version: v0.6.1
|
- Version: v1.0.2
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,33 @@ export OPTIMIZE="-Os"
|
|||||||
export LDFLAGS="${OPTIMIZE}"
|
export LDFLAGS="${OPTIMIZE}"
|
||||||
export CFLAGS="${OPTIMIZE}"
|
export CFLAGS="${OPTIMIZE}"
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool libpng-dev pkg-config
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libwebp"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_LIBWEBP" || (
|
||||||
|
cd node_modules/libwebp
|
||||||
|
autoreconf -fiv
|
||||||
|
rm -rf build || true
|
||||||
|
mkdir -p build && cd build
|
||||||
|
emconfigure ../configure \
|
||||||
|
--disable-libwebpdemux \
|
||||||
|
--disable-wic \
|
||||||
|
--disable-gif \
|
||||||
|
--disable-tiff \
|
||||||
|
--disable-jpeg \
|
||||||
|
--disable-png \
|
||||||
|
--disable-sdl \
|
||||||
|
--disable-gl \
|
||||||
|
--disable-threading \
|
||||||
|
--disable-neon-rtcd \
|
||||||
|
--disable-neon \
|
||||||
|
--disable-sse2 \
|
||||||
|
--disable-sse4.1
|
||||||
|
emmake make
|
||||||
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings"
|
echo "Compiling wasm bindings"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
@@ -20,9 +46,9 @@ echo "============================================="
|
|||||||
--std=c++11 \
|
--std=c++11 \
|
||||||
-I node_modules/libwebp \
|
-I node_modules/libwebp \
|
||||||
-o ./webp_dec.js \
|
-o ./webp_dec.js \
|
||||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
|
||||||
-x c++ \
|
-x c++ \
|
||||||
webp_dec.cpp
|
webp_dec.cpp \
|
||||||
|
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings done"
|
echo "Compiling wasm bindings done"
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||||
},
|
},
|
||||||
"napa": {
|
"napa": {
|
||||||
"libwebp": "webmproject/libwebp#v1.0.0"
|
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "^3.0.0"
|
"napa": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
# WebP encoder
|
# WebP encoder
|
||||||
|
|
||||||
- Source: <https://github.com/webmproject/libwebp>
|
- Source: <https://github.com/webmproject/libwebp>
|
||||||
- Version: v0.6.1
|
- Version: v1.0.2
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,33 @@ export LDFLAGS="${OPTIMIZE}"
|
|||||||
export CFLAGS="${OPTIMIZE}"
|
export CFLAGS="${OPTIMIZE}"
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool libpng-dev pkg-config
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libwebp"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_LIBWEBP" || (
|
||||||
|
cd node_modules/libwebp
|
||||||
|
autoreconf -fiv
|
||||||
|
rm -rf build || true
|
||||||
|
mkdir -p build && cd build
|
||||||
|
emconfigure ../configure \
|
||||||
|
--disable-libwebpdemux \
|
||||||
|
--disable-wic \
|
||||||
|
--disable-gif \
|
||||||
|
--disable-tiff \
|
||||||
|
--disable-jpeg \
|
||||||
|
--disable-png \
|
||||||
|
--disable-sdl \
|
||||||
|
--disable-gl \
|
||||||
|
--disable-threading \
|
||||||
|
--disable-neon-rtcd \
|
||||||
|
--disable-neon \
|
||||||
|
--disable-sse2 \
|
||||||
|
--disable-sse4.1
|
||||||
|
emmake make
|
||||||
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings"
|
echo "Compiling wasm bindings"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
@@ -20,9 +47,9 @@ echo "============================================="
|
|||||||
--std=c++11 \
|
--std=c++11 \
|
||||||
-I node_modules/libwebp \
|
-I node_modules/libwebp \
|
||||||
-o ./webp_enc.js \
|
-o ./webp_enc.js \
|
||||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
|
||||||
-x c++ \
|
-x c++ \
|
||||||
webp_enc.cpp
|
webp_enc.cpp \
|
||||||
|
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings done"
|
echo "Compiling wasm bindings done"
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||||
},
|
},
|
||||||
"napa": {
|
"napa": {
|
||||||
"libwebp": "webmproject/libwebp#v1.0.0"
|
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "^3.0.0"
|
"napa": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ val encode(std::string img, int width, int height, WebPConfig config) {
|
|||||||
throw std::runtime_error("Unexpected error");
|
throw std::runtime_error("Unexpected error");
|
||||||
}
|
}
|
||||||
|
|
||||||
pic.use_argb = !!config.lossless;
|
// Only use use_argb if we really need it, as it's slower.
|
||||||
|
pic.use_argb = config.lossless || config.use_sharp_yuv || config.preprocessing > 0;
|
||||||
pic.width = width;
|
pic.width = width;
|
||||||
pic.height = height;
|
pic.height = height;
|
||||||
pic.writer = WebPMemoryWrite;
|
pic.writer = WebPMemoryWrite;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
1202
package-lock.json
generated
1202
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
102
package.json
102
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.2.2",
|
"version": "1.3.1",
|
||||||
"license": "apache-2.0",
|
"license": "apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
||||||
@@ -15,55 +15,55 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^10.12.6",
|
"@types/node": "10.12.21",
|
||||||
"@types/pretty-bytes": "^5.1.0",
|
"@types/pretty-bytes": "5.1.0",
|
||||||
"@types/webassembly-js-api": "0.0.1",
|
"@types/webassembly-js-api": "0.0.2",
|
||||||
"@webcomponents/custom-elements": "^1.2.1",
|
"@webcomponents/custom-elements": "1.2.1",
|
||||||
"@webpack-cli/serve": "^0.1.2",
|
"@webpack-cli/serve": "0.1.3",
|
||||||
"assets-webpack-plugin": "^3.9.7",
|
"assets-webpack-plugin": "3.9.7",
|
||||||
"chokidar": "^2.0.4",
|
"chokidar": "2.0.4",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "2.2.6",
|
||||||
"clean-webpack-plugin": "^1.0.0",
|
"clean-webpack-plugin": "1.0.1",
|
||||||
"comlink": "^3.0.3",
|
"comlink": "3.1.1",
|
||||||
"copy-webpack-plugin": "^4.6.0",
|
"copy-webpack-plugin": "4.6.0",
|
||||||
"critters-webpack-plugin": "^2.0.1",
|
"critters-webpack-plugin": "2.2.0",
|
||||||
"css-loader": "^1.0.1",
|
"css-loader": "1.0.1",
|
||||||
"ejs": "^2.6.1",
|
"ejs": "2.6.1",
|
||||||
"exports-loader": "^0.7.0",
|
"exports-loader": "0.7.0",
|
||||||
"file-drop-element": "^0.0.9",
|
"file-drop-element": "0.0.9",
|
||||||
"file-loader": "^2.0.0",
|
"file-loader": "3.0.1",
|
||||||
"html-webpack-plugin": "^3.2.0",
|
"html-webpack-plugin": "3.2.0",
|
||||||
"husky": "^1.1.4",
|
"husky": "1.3.1",
|
||||||
"idb-keyval": "^3.1.0",
|
"idb-keyval": "3.1.0",
|
||||||
"linkstate": "^1.1.1",
|
"linkstate": "1.1.1",
|
||||||
"loader-utils": "^1.1.0",
|
"loader-utils": "1.2.0",
|
||||||
"mini-css-extract-plugin": "^0.4.4",
|
"mini-css-extract-plugin": "0.5.0",
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "3.0.4",
|
||||||
"node-sass": "^4.11.0",
|
"node-sass": "4.11.0",
|
||||||
"optimize-css-assets-webpack-plugin": "^5.0.1",
|
"optimize-css-assets-webpack-plugin": "5.0.1",
|
||||||
"pointer-tracker": "^2.0.3",
|
"pointer-tracker": "2.0.3",
|
||||||
"preact": "^8.3.1",
|
"preact": "8.4.2",
|
||||||
"prerender-loader": "^1.2.0",
|
"prerender-loader": "1.2.0",
|
||||||
"pretty-bytes": "^5.1.0",
|
"pretty-bytes": "5.1.0",
|
||||||
"progress-bar-webpack-plugin": "^1.11.0",
|
"progress-bar-webpack-plugin": "1.12.1",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "1.0.0",
|
||||||
"sass-loader": "^7.1.0",
|
"sass-loader": "7.1.0",
|
||||||
"script-ext-html-webpack-plugin": "^2.1.3",
|
"script-ext-html-webpack-plugin": "2.1.3",
|
||||||
"source-map-loader": "^0.2.4",
|
"source-map-loader": "0.2.4",
|
||||||
"style-loader": "^0.23.1",
|
"style-loader": "0.23.1",
|
||||||
"terser-webpack-plugin": "^1.1.0",
|
"terser-webpack-plugin": "1.2.2",
|
||||||
"ts-loader": "^5.3.0",
|
"ts-loader": "5.3.3",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "5.12.1",
|
||||||
"tslint-config-airbnb": "^5.11.0",
|
"tslint-config-airbnb": "5.11.1",
|
||||||
"tslint-config-semistandard": "^7.0.0",
|
"tslint-config-semistandard": "7.0.0",
|
||||||
"tslint-react": "^3.6.0",
|
"tslint-react": "3.6.0",
|
||||||
"typed-css-modules": "^0.3.7",
|
"typed-css-modules": "0.3.7",
|
||||||
"typescript": "^3.1.6",
|
"typescript": "3.2.4",
|
||||||
"url-loader": "^1.1.2",
|
"url-loader": "1.1.2",
|
||||||
"webpack": "^4.25.1",
|
"webpack": "4.28.0",
|
||||||
"webpack-bundle-analyzer": "^3.0.3",
|
"webpack-bundle-analyzer": "3.0.3",
|
||||||
"webpack-cli": "^3.1.2",
|
"webpack-cli": "3.2.3",
|
||||||
"webpack-dev-server": "^3.1.10",
|
"webpack-dev-server": "3.1.14",
|
||||||
"worker-plugin": "^1.1.1"
|
"worker-plugin": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
renovate.json
Normal file
5
renovate.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"config:base"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as identity from './identity/encoder-meta';
|
import * as identity from './identity/encoder-meta';
|
||||||
import * as optiPNG from './optipng/encoder-meta';
|
import * as optiPNG from './optipng/encoder-meta';
|
||||||
|
import * as oxiPNG from './oxipng/encoder-meta';
|
||||||
import * as mozJPEG from './mozjpeg/encoder-meta';
|
import * as mozJPEG from './mozjpeg/encoder-meta';
|
||||||
import * as webP from './webp/encoder-meta';
|
import * as webP from './webp/encoder-meta';
|
||||||
import * as browserPNG from './browser-png/encoder-meta';
|
import * as browserPNG from './browser-png/encoder-meta';
|
||||||
@@ -18,6 +19,7 @@ export interface EncoderSupportMap {
|
|||||||
export type EncoderState =
|
export type EncoderState =
|
||||||
identity.EncoderState |
|
identity.EncoderState |
|
||||||
optiPNG.EncoderState |
|
optiPNG.EncoderState |
|
||||||
|
oxiPNG.EncoderState |
|
||||||
mozJPEG.EncoderState |
|
mozJPEG.EncoderState |
|
||||||
webP.EncoderState |
|
webP.EncoderState |
|
||||||
browserPNG.EncoderState |
|
browserPNG.EncoderState |
|
||||||
@@ -32,6 +34,7 @@ export type EncoderState =
|
|||||||
export type EncoderOptions =
|
export type EncoderOptions =
|
||||||
identity.EncodeOptions |
|
identity.EncodeOptions |
|
||||||
optiPNG.EncodeOptions |
|
optiPNG.EncodeOptions |
|
||||||
|
oxiPNG.EncodeOptions |
|
||||||
mozJPEG.EncodeOptions |
|
mozJPEG.EncodeOptions |
|
||||||
webP.EncodeOptions |
|
webP.EncodeOptions |
|
||||||
browserPNG.EncodeOptions |
|
browserPNG.EncodeOptions |
|
||||||
@@ -48,6 +51,7 @@ export type EncoderType = keyof typeof encoderMap;
|
|||||||
export const encoderMap = {
|
export const encoderMap = {
|
||||||
[identity.type]: identity,
|
[identity.type]: identity,
|
||||||
[optiPNG.type]: optiPNG,
|
[optiPNG.type]: optiPNG,
|
||||||
|
[oxiPNG.type]: oxiPNG,
|
||||||
[mozJPEG.type]: mozJPEG,
|
[mozJPEG.type]: mozJPEG,
|
||||||
[webP.type]: webP,
|
[webP.type]: webP,
|
||||||
[browserPNG.type]: browserPNG,
|
[browserPNG.type]: browserPNG,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ export interface EncodeOptions {
|
|||||||
}
|
}
|
||||||
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
||||||
|
|
||||||
export const type = 'png';
|
export const type = 'optipng';
|
||||||
export const label = 'OptiPNG';
|
export const label = 'OptiPNG';
|
||||||
export const mimeType = 'image/png';
|
export const mimeType = 'image/png';
|
||||||
export const extension = 'png';
|
export const extension = 'png';
|
||||||
|
|||||||
13
src/codecs/oxipng/encoder-meta.ts
Normal file
13
src/codecs/oxipng/encoder-meta.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export interface EncodeOptions {
|
||||||
|
level: number;
|
||||||
|
}
|
||||||
|
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
||||||
|
|
||||||
|
export const type = 'oxipng';
|
||||||
|
export const label = 'OxiPNG';
|
||||||
|
export const mimeType = 'image/png';
|
||||||
|
export const extension = 'png';
|
||||||
|
|
||||||
|
export const defaultOptions: EncodeOptions = {
|
||||||
|
level: 6,
|
||||||
|
};
|
||||||
18
src/codecs/oxipng/encoder.ts
Normal file
18
src/codecs/oxipng/encoder.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import * as oxipng from '../../../codecs/oxipng/pkg/oxipng_manual';
|
||||||
|
import { EncodeOptions } from './encoder-meta';
|
||||||
|
|
||||||
|
export async function compress(data: BufferSource, { level }: EncodeOptions): Promise<ArrayBuffer> {
|
||||||
|
let buffer: ArrayBuffer;
|
||||||
|
|
||||||
|
if (ArrayBuffer.isView(data)) {
|
||||||
|
buffer = data.buffer;
|
||||||
|
} else {
|
||||||
|
buffer = data;
|
||||||
|
}
|
||||||
|
debugger;
|
||||||
|
const resultView = await oxipng.compress(new Uint8Array(buffer), level);
|
||||||
|
const result = new Uint8Array(resultView);
|
||||||
|
|
||||||
|
// wasm can’t run on SharedArrayBuffers, so we hard-cast to ArrayBuffer.
|
||||||
|
return result.buffer as ArrayBuffer;
|
||||||
|
}
|
||||||
42
src/codecs/oxipng/options.tsx
Normal file
42
src/codecs/oxipng/options.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { h, Component } from 'preact';
|
||||||
|
import { bind } from '../../lib/initial-util';
|
||||||
|
import { inputFieldValueAsNumber, preventDefault } from '../../lib/util';
|
||||||
|
import { EncodeOptions } from './encoder-meta';
|
||||||
|
import Range from '../../components/range';
|
||||||
|
import * as style from '../../components/Options/style.scss';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
options: EncodeOptions;
|
||||||
|
onChange(newOptions: EncodeOptions): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class OxiPNGEncoderOptions extends Component<Props, {}> {
|
||||||
|
@bind
|
||||||
|
onChange(event: Event) {
|
||||||
|
const form = (event.currentTarget as HTMLInputElement).closest('form') as HTMLFormElement;
|
||||||
|
|
||||||
|
const options: EncodeOptions = {
|
||||||
|
level: inputFieldValueAsNumber(form.level),
|
||||||
|
};
|
||||||
|
this.props.onChange(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
render({ options }: Props) {
|
||||||
|
return (
|
||||||
|
<form class={style.optionsSection} onSubmit={preventDefault}>
|
||||||
|
<div class={style.optionOneCell}>
|
||||||
|
<Range
|
||||||
|
name="level"
|
||||||
|
min="0"
|
||||||
|
max="9"
|
||||||
|
step="1"
|
||||||
|
value={options.level}
|
||||||
|
onInput={this.onChange}
|
||||||
|
>
|
||||||
|
Effort:
|
||||||
|
</Range>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,6 +41,16 @@ async function optiPngEncode(
|
|||||||
return compress(data, options);
|
return compress(data, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function oxiPngEncode(
|
||||||
|
data: BufferSource, options: import('../oxipng/encoder-meta').EncodeOptions,
|
||||||
|
): Promise<ArrayBuffer> {
|
||||||
|
const { compress } = await import(
|
||||||
|
/* webpackChunkName: "process-optipng" */
|
||||||
|
'../oxipng/encoder',
|
||||||
|
);
|
||||||
|
return compress(data, options);
|
||||||
|
}
|
||||||
|
|
||||||
async function webpEncode(
|
async function webpEncode(
|
||||||
data: ImageData, options: import('../webp/encoder-meta').EncodeOptions,
|
data: ImageData, options: import('../webp/encoder-meta').EncodeOptions,
|
||||||
): Promise<ArrayBuffer> {
|
): Promise<ArrayBuffer> {
|
||||||
@@ -59,7 +69,15 @@ async function webpDecode(data: ArrayBuffer): Promise<ImageData> {
|
|||||||
return decode(data);
|
return decode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exports = { mozjpegEncode, quantize, rotate, optiPngEncode, webpEncode, webpDecode };
|
const exports = {
|
||||||
|
mozjpegEncode,
|
||||||
|
quantize,
|
||||||
|
rotate,
|
||||||
|
optiPngEncode,
|
||||||
|
oxiPngEncode,
|
||||||
|
webpEncode,
|
||||||
|
webpDecode,
|
||||||
|
};
|
||||||
export type ProcessorWorkerApi = typeof exports;
|
export type ProcessorWorkerApi = typeof exports;
|
||||||
|
|
||||||
expose(exports, self);
|
expose(exports, self);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { QuantizeOptions } from './imagequant/processor-meta';
|
|||||||
import { canvasEncode, blobToArrayBuffer } from '../lib/util';
|
import { canvasEncode, blobToArrayBuffer } from '../lib/util';
|
||||||
import { EncodeOptions as MozJPEGEncoderOptions } from './mozjpeg/encoder-meta';
|
import { EncodeOptions as MozJPEGEncoderOptions } from './mozjpeg/encoder-meta';
|
||||||
import { EncodeOptions as OptiPNGEncoderOptions } from './optipng/encoder-meta';
|
import { EncodeOptions as OptiPNGEncoderOptions } from './optipng/encoder-meta';
|
||||||
|
import { EncodeOptions as OxiPNGEncoderOptions } from './oxipng/encoder-meta';
|
||||||
import { EncodeOptions as WebPEncoderOptions } from './webp/encoder-meta';
|
import { EncodeOptions as WebPEncoderOptions } from './webp/encoder-meta';
|
||||||
import { EncodeOptions as BrowserJPEGOptions } from './browser-jpeg/encoder-meta';
|
import { EncodeOptions as BrowserJPEGOptions } from './browser-jpeg/encoder-meta';
|
||||||
import { EncodeOptions as BrowserWebpEncodeOptions } from './browser-webp/encoder-meta';
|
import { EncodeOptions as BrowserWebpEncodeOptions } from './browser-webp/encoder-meta';
|
||||||
@@ -20,7 +21,7 @@ import * as browserPDF from './browser-pdf/encoder';
|
|||||||
type ProcessorWorkerApi = import('./processor-worker').ProcessorWorkerApi;
|
type ProcessorWorkerApi = import('./processor-worker').ProcessorWorkerApi;
|
||||||
|
|
||||||
/** How long the worker should be idle before terminating. */
|
/** How long the worker should be idle before terminating. */
|
||||||
const workerTimeout = 1000;
|
const workerTimeout = 10000;
|
||||||
|
|
||||||
interface ProcessingJobOptions {
|
interface ProcessingJobOptions {
|
||||||
needsWorker?: boolean;
|
needsWorker?: boolean;
|
||||||
@@ -147,6 +148,16 @@ export default class Processor {
|
|||||||
return this._workerApi!.optiPngEncode(pngBuffer, opts);
|
return this._workerApi!.optiPngEncode(pngBuffer, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Processor._processingJob({ needsWorker: true })
|
||||||
|
async oxiPngEncode(
|
||||||
|
data: ImageData, opts: OxiPNGEncoderOptions,
|
||||||
|
): Promise<ArrayBuffer> {
|
||||||
|
// OptiPNG expects PNG input.
|
||||||
|
const pngBlob = await canvasEncode(data, 'image/png');
|
||||||
|
const pngBuffer = await blobToArrayBuffer(pngBlob);
|
||||||
|
return this._workerApi!.oxiPngEncode(pngBuffer, opts);
|
||||||
|
}
|
||||||
|
|
||||||
@Processor._processingJob({ needsWorker: true })
|
@Processor._processingJob({ needsWorker: true })
|
||||||
webpEncode(data: ImageData, opts: WebPEncoderOptions): Promise<ArrayBuffer> {
|
webpEncode(data: ImageData, opts: WebPEncoderOptions): Promise<ArrayBuffer> {
|
||||||
return this._workerApi!.webpEncode(data, opts);
|
return this._workerApi!.webpEncode(data, opts);
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import { RotateOptions } from './processor-meta';
|
import { RotateOptions } from './processor-meta';
|
||||||
|
|
||||||
const bpp = 4;
|
|
||||||
|
|
||||||
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
||||||
const { rotate } = opts;
|
const { rotate } = opts;
|
||||||
|
|
||||||
// Early exit if there's no transform.
|
|
||||||
if (rotate === 0) return data;
|
|
||||||
|
|
||||||
const flipDimensions = rotate % 180 !== 0;
|
const flipDimensions = rotate % 180 !== 0;
|
||||||
const { width: inputWidth, height: inputHeight } = data;
|
const { width: inputWidth, height: inputHeight } = data;
|
||||||
const outputWidth = flipDimensions ? inputHeight : inputWidth;
|
const outputWidth = flipDimensions ? inputHeight : inputWidth;
|
||||||
@@ -65,14 +59,13 @@ export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
|||||||
d2Multiplier = 1;
|
d2Multiplier = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inB = new Uint32Array(data.data.buffer);
|
||||||
|
const outB = new Uint32Array(out.data.buffer);
|
||||||
for (let d2 = d2Start; d2 >= 0 && d2 < d2Limit; d2 += d2Advance) {
|
for (let d2 = d2Start; d2 >= 0 && d2 < d2Limit; d2 += d2Advance) {
|
||||||
for (let d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
|
for (let d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
|
||||||
// Iterate over channels:
|
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier));
|
||||||
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier)) * bpp;
|
outB[i] = inB[start];
|
||||||
for (let j = 0; j < bpp; j += 1) {
|
i += 1;
|
||||||
out.data[i] = data.data[start + j];
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import '../../lib/SnackBar';
|
|||||||
import Intro from '../intro';
|
import Intro from '../intro';
|
||||||
import '../custom-els/LoadingSpinner';
|
import '../custom-els/LoadingSpinner';
|
||||||
|
|
||||||
|
const ROUTE_EDITOR = '/editor';
|
||||||
|
|
||||||
const compressPromise = import(
|
const compressPromise = import(
|
||||||
/* webpackChunkName: "main-app" */
|
/* webpackChunkName: "main-app" */
|
||||||
'../compress',
|
'../compress',
|
||||||
@@ -18,15 +20,21 @@ const offlinerPromise = import(
|
|||||||
'../../lib/offliner',
|
'../../lib/offliner',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function back() {
|
||||||
|
window.history.back();
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
file?: File | Fileish;
|
file?: File | Fileish;
|
||||||
|
isEditorOpen: Boolean;
|
||||||
Compress?: typeof import('../compress').default;
|
Compress?: typeof import('../compress').default;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class App extends Component<Props, State> {
|
export default class App extends Component<Props, State> {
|
||||||
state: State = {
|
state: State = {
|
||||||
|
isEditorOpen: false,
|
||||||
file: undefined,
|
file: undefined,
|
||||||
Compress: undefined,
|
Compress: undefined,
|
||||||
};
|
};
|
||||||
@@ -48,22 +56,33 @@ export default class App extends Component<Props, State> {
|
|||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
this.setState(window.STATE);
|
this.setState(window.STATE);
|
||||||
const oldCDU = this.componentDidUpdate;
|
const oldCDU = this.componentDidUpdate;
|
||||||
this.componentDidUpdate = (props, state) => {
|
this.componentDidUpdate = (props, state, prev) => {
|
||||||
if (oldCDU) oldCDU.call(this, props, state);
|
if (oldCDU) oldCDU.call(this, props, state, prev);
|
||||||
window.STATE = this.state;
|
window.STATE = this.state;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Since iOS 10, Apple tries to prevent disabling pinch-zoom. This is great in theory, but
|
||||||
|
// really breaks things on Squoosh, as you can easily end up zooming the UI when you mean to
|
||||||
|
// zoom the image. Once you've done this, it's really difficult to undo. Anyway, this seems to
|
||||||
|
// prevent it.
|
||||||
|
document.body.addEventListener('gesturestart', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('popstate', this.onPopState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
private onFileDrop(event: FileDropEvent) {
|
private onFileDrop({ file }: FileDropEvent) {
|
||||||
const { file } = event;
|
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
this.openEditor();
|
||||||
this.setState({ file });
|
this.setState({ file });
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
private onIntroPickFile(file: File | Fileish) {
|
private onIntroPickFile(file: File | Fileish) {
|
||||||
|
this.openEditor();
|
||||||
this.setState({ file });
|
this.setState({ file });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,18 +93,25 @@ export default class App extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
private onBack() {
|
private onPopState() {
|
||||||
this.setState({ file: undefined });
|
this.setState({ isEditorOpen: location.pathname === ROUTE_EDITOR });
|
||||||
}
|
}
|
||||||
|
|
||||||
render({}: Props, { file, Compress }: State) {
|
@bind
|
||||||
|
private openEditor() {
|
||||||
|
if (this.state.isEditorOpen) return;
|
||||||
|
history.pushState(null, '', ROUTE_EDITOR);
|
||||||
|
this.setState({ isEditorOpen: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
render({}: Props, { file, isEditorOpen, Compress }: State) {
|
||||||
return (
|
return (
|
||||||
<div id="app" class={style.app}>
|
<div id="app" class={style.app}>
|
||||||
<file-drop accept="image/*" onfiledrop={this.onFileDrop} class={style.drop}>
|
<file-drop accept="image/*" onfiledrop={this.onFileDrop} class={style.drop}>
|
||||||
{(!file)
|
{!isEditorOpen
|
||||||
? <Intro onFile={this.onIntroPickFile} showSnack={this.showSnack} />
|
? <Intro onFile={this.onIntroPickFile} showSnack={this.showSnack} />
|
||||||
: (Compress)
|
: (Compress)
|
||||||
? <Compress file={file} showSnack={this.showSnack} onBack={this.onBack} />
|
? <Compress file={file!} showSnack={this.showSnack} onBack={back} />
|
||||||
: <loading-spinner class={style.appLoader}/>
|
: <loading-spinner class={style.appLoader}/>
|
||||||
}
|
}
|
||||||
<snack-bar ref={linkRef(this, 'snackbar')} />
|
<snack-bar ref={linkRef(this, 'snackbar')} />
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ import Checkbox from '../checkbox';
|
|||||||
import Expander from '../expander';
|
import Expander from '../expander';
|
||||||
import Select from '../select';
|
import Select from '../select';
|
||||||
|
|
||||||
const encoderOptionsComponentMap = {
|
const encoderOptionsComponentMap: {
|
||||||
|
[x: string]: (new (...args: any[]) => Component<any, any>) | undefined;
|
||||||
|
} = {
|
||||||
[identity.type]: undefined,
|
[identity.type]: undefined,
|
||||||
[optiPNG.type]: OptiPNGEncoderOptions,
|
[optiPNG.type]: OptiPNGEncoderOptions,
|
||||||
[mozJPEG.type]: MozJpegEncoderOptions,
|
[mozJPEG.type]: MozJpegEncoderOptions,
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ $horizontalPadding: 15px;
|
|||||||
|
|
||||||
.text-field {
|
.text-field {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
|
color: #000;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 2px 0 2px 10px;
|
padding: 2px 0 2px 10px;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import Options from '../Options';
|
|||||||
import ResultCache from './result-cache';
|
import ResultCache from './result-cache';
|
||||||
import * as identity from '../../codecs/identity/encoder-meta';
|
import * as identity from '../../codecs/identity/encoder-meta';
|
||||||
import * as optiPNG from '../../codecs/optipng/encoder-meta';
|
import * as optiPNG from '../../codecs/optipng/encoder-meta';
|
||||||
|
import * as oxiPNG from '../../codecs/oxipng/encoder-meta';
|
||||||
import * as mozJPEG from '../../codecs/mozjpeg/encoder-meta';
|
import * as mozJPEG from '../../codecs/mozjpeg/encoder-meta';
|
||||||
import * as webP from '../../codecs/webp/encoder-meta';
|
import * as webP from '../../codecs/webp/encoder-meta';
|
||||||
import * as browserPNG from '../../codecs/browser-png/encoder-meta';
|
import * as browserPNG from '../../codecs/browser-png/encoder-meta';
|
||||||
@@ -85,12 +86,18 @@ interface UpdateImageOptions {
|
|||||||
skipPreprocessing?: boolean;
|
skipPreprocessing?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processInput(
|
async function processInput(
|
||||||
data: ImageData,
|
data: ImageData,
|
||||||
inputProcessData: InputProcessorState,
|
inputProcessData: InputProcessorState,
|
||||||
processor: Processor,
|
processor: Processor,
|
||||||
) {
|
) {
|
||||||
return processor.rotate(data, inputProcessData.rotate);
|
let processedData = data;
|
||||||
|
|
||||||
|
if (inputProcessData.rotate.rotate !== 0) {
|
||||||
|
processedData = await processor.rotate(processedData, inputProcessData.rotate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return processedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function preprocessImage(
|
async function preprocessImage(
|
||||||
@@ -125,6 +132,7 @@ async function compressImage(
|
|||||||
const compressedData = await (() => {
|
const compressedData = await (() => {
|
||||||
switch (encodeData.type) {
|
switch (encodeData.type) {
|
||||||
case optiPNG.type: return processor.optiPngEncode(image, encodeData.options);
|
case optiPNG.type: return processor.optiPngEncode(image, encodeData.options);
|
||||||
|
case oxiPNG.type: return processor.oxiPngEncode(image, encodeData.options);
|
||||||
case mozJPEG.type: return processor.mozjpegEncode(image, encodeData.options);
|
case mozJPEG.type: return processor.mozjpegEncode(image, encodeData.options);
|
||||||
case webP.type: return processor.webpEncode(image, encodeData.options);
|
case webP.type: return processor.webpEncode(image, encodeData.options);
|
||||||
case browserPNG.type: return processor.browserPngEncode(image);
|
case browserPNG.type: return processor.browserPngEncode(image);
|
||||||
@@ -154,7 +162,7 @@ function stateForNewSourceData(state: State, newSource: SourceImage): State {
|
|||||||
for (const i of [0, 1]) {
|
for (const i of [0, 1]) {
|
||||||
// Ditch previous encodings
|
// Ditch previous encodings
|
||||||
const downloadUrl = state.sides[i].downloadUrl;
|
const downloadUrl = state.sides[i].downloadUrl;
|
||||||
if (downloadUrl) URL.revokeObjectURL(downloadUrl!);
|
if (downloadUrl) URL.revokeObjectURL(downloadUrl);
|
||||||
|
|
||||||
newState = cleanMerge(state, `sides.${i}`, {
|
newState = cleanMerge(state, `sides.${i}`, {
|
||||||
preprocessed: undefined,
|
preprocessed: undefined,
|
||||||
@@ -234,6 +242,8 @@ export default class Compress extends Component<Props, State> {
|
|||||||
private readonly encodeCache = new ResultCache();
|
private readonly encodeCache = new ResultCache();
|
||||||
private readonly leftProcessor = new Processor();
|
private readonly leftProcessor = new Processor();
|
||||||
private readonly rightProcessor = new Processor();
|
private readonly rightProcessor = new Processor();
|
||||||
|
// For debouncing calls to updateImage for each side.
|
||||||
|
private readonly updateImageTimeoutIds: [number?, number?] = [undefined, undefined];
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -301,10 +311,8 @@ export default class Compress extends Component<Props, State> {
|
|||||||
// The image only needs updated if the encoder/preprocessor settings have changed, or the
|
// The image only needs updated if the encoder/preprocessor settings have changed, or the
|
||||||
// source has changed.
|
// source has changed.
|
||||||
if (sourceDataChanged || encoderChanged || preprocessorChanged) {
|
if (sourceDataChanged || encoderChanged || preprocessorChanged) {
|
||||||
this.updateImage(i, {
|
this.queueUpdateImage(i, {
|
||||||
skipPreprocessing: !sourceDataChanged && !preprocessorChanged,
|
skipPreprocessing: !sourceDataChanged && !preprocessorChanged,
|
||||||
}).catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,9 +321,14 @@ export default class Compress extends Component<Props, State> {
|
|||||||
private async onCopyToOtherClick(index: 0 | 1) {
|
private async onCopyToOtherClick(index: 0 | 1) {
|
||||||
const otherIndex = (index + 1) % 2;
|
const otherIndex = (index + 1) % 2;
|
||||||
const oldSettings = this.state.sides[otherIndex];
|
const oldSettings = this.state.sides[otherIndex];
|
||||||
|
const newSettings = { ...this.state.sides[index] };
|
||||||
|
|
||||||
|
// Create a new object URL for the new settings. This avoids both sides sharing a URL, which
|
||||||
|
// means it can be safely revoked without impacting the other side.
|
||||||
|
if (newSettings.file) newSettings.downloadUrl = URL.createObjectURL(newSettings.file);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
sides: cleanSet(this.state.sides, otherIndex, this.state.sides[index]),
|
sides: cleanSet(this.state.sides, otherIndex, newSettings),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await this.props.showSnack('Settings copied across', {
|
const result = await this.props.showSnack('Settings copied across', {
|
||||||
@@ -446,6 +459,27 @@ export default class Compress extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debounce the heavy lifting of updateImage.
|
||||||
|
* Otherwise, the thrashing causes jank, and sometimes crashes iOS Safari.
|
||||||
|
*/
|
||||||
|
private queueUpdateImage(index: number, options: UpdateImageOptions = {}): void {
|
||||||
|
// Call updateImage after this delay, unless queueUpdateImage is called again, in which case the
|
||||||
|
// timeout is reset.
|
||||||
|
const delay = 100;
|
||||||
|
|
||||||
|
clearTimeout(this.updateImageTimeoutIds[index]);
|
||||||
|
|
||||||
|
this.updateImageTimeoutIds[index] = self.setTimeout(
|
||||||
|
() => {
|
||||||
|
this.updateImage(index, options).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
delay,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async updateImage(index: number, options: UpdateImageOptions = {}): Promise<void> {
|
private async updateImage(index: number, options: UpdateImageOptions = {}): Promise<void> {
|
||||||
const {
|
const {
|
||||||
skipPreprocessing = false,
|
skipPreprocessing = false,
|
||||||
@@ -544,9 +578,9 @@ export default class Compress extends Component<Props, State> {
|
|||||||
mobileView={mobileView}
|
mobileView={mobileView}
|
||||||
preprocessorState={side.latestSettings.preprocessorState}
|
preprocessorState={side.latestSettings.preprocessorState}
|
||||||
encoderState={side.latestSettings.encoderState}
|
encoderState={side.latestSettings.encoderState}
|
||||||
onEncoderTypeChange={this.onEncoderTypeChange.bind(this, index)}
|
onEncoderTypeChange={this.onEncoderTypeChange.bind(this, index as 0|1)}
|
||||||
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index)}
|
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index as 0|1)}
|
||||||
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index)}
|
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index as 0|1)}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -560,7 +594,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
source={source}
|
source={source}
|
||||||
loading={loading || side.loading}
|
loading={loading || side.loading}
|
||||||
copyDirection={copyDirections[index]}
|
copyDirection={copyDirections[index]}
|
||||||
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index)}
|
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index as 0|1)}
|
||||||
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
|
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
|
||||||
>
|
>
|
||||||
{!mobileView ? null : [
|
{!mobileView ? null : [
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
// Reorder so headings appear after content:
|
// Reorder so headings appear after content:
|
||||||
& > :nth-child(1) {
|
& > :nth-child(1) {
|
||||||
|
|||||||
@@ -251,6 +251,11 @@ module.exports = async function (_, env) {
|
|||||||
filename: '_headers',
|
filename: '_headers',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
isProd && new AssetTemplatePlugin({
|
||||||
|
template: path.join(__dirname, '_redirects.ejs'),
|
||||||
|
filename: '_redirects',
|
||||||
|
}),
|
||||||
|
|
||||||
new ScriptExtHtmlPlugin({
|
new ScriptExtHtmlPlugin({
|
||||||
inline: ['first']
|
inline: ['first']
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user