mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Compare commits
75 Commits
v1.3.1
...
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 |
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
|
||||
|
||||
- Source: <https://github.com/webmproject/libwebp>
|
||||
- Version: v0.6.1
|
||||
- Version: v1.0.2
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
@@ -6,7 +6,33 @@ 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 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 "Compiling wasm bindings"
|
||||
echo "============================================="
|
||||
@@ -20,9 +46,9 @@ echo "============================================="
|
||||
--std=c++11 \
|
||||
-I node_modules/libwebp \
|
||||
-o ./webp_dec.js \
|
||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
||||
-x c++ \
|
||||
webp_dec.cpp
|
||||
webp_dec.cpp \
|
||||
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||
)
|
||||
echo "============================================="
|
||||
echo "Compiling wasm bindings done"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||
},
|
||||
"napa": {
|
||||
"libwebp": "webmproject/libwebp#v1.0.0"
|
||||
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"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
|
||||
|
||||
- Source: <https://github.com/webmproject/libwebp>
|
||||
- Version: v0.6.1
|
||||
- Version: v1.0.2
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
@@ -7,6 +7,33 @@ 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 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 "Compiling wasm bindings"
|
||||
echo "============================================="
|
||||
@@ -20,9 +47,9 @@ echo "============================================="
|
||||
--std=c++11 \
|
||||
-I node_modules/libwebp \
|
||||
-o ./webp_enc.js \
|
||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
||||
-x c++ \
|
||||
webp_enc.cpp
|
||||
webp_enc.cpp \
|
||||
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||
)
|
||||
echo "============================================="
|
||||
echo "Compiling wasm bindings done"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"build": "docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh"
|
||||
},
|
||||
"napa": {
|
||||
"libwebp": "webmproject/libwebp#v1.0.0"
|
||||
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"napa": "3.0.0"
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
875
package-lock.json
generated
875
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -15,28 +15,28 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "10.12.15",
|
||||
"@types/node": "10.12.21",
|
||||
"@types/pretty-bytes": "5.1.0",
|
||||
"@types/webassembly-js-api": "0.0.2",
|
||||
"@webcomponents/custom-elements": "1.2.1",
|
||||
"@webpack-cli/serve": "0.1.2",
|
||||
"@webpack-cli/serve": "0.1.3",
|
||||
"assets-webpack-plugin": "3.9.7",
|
||||
"chokidar": "2.0.4",
|
||||
"classnames": "2.2.6",
|
||||
"clean-webpack-plugin": "1.0.0",
|
||||
"clean-webpack-plugin": "1.0.1",
|
||||
"comlink": "3.1.1",
|
||||
"copy-webpack-plugin": "4.6.0",
|
||||
"critters-webpack-plugin": "2.1.1",
|
||||
"critters-webpack-plugin": "2.2.0",
|
||||
"css-loader": "1.0.1",
|
||||
"ejs": "2.6.1",
|
||||
"exports-loader": "0.7.0",
|
||||
"file-drop-element": "0.0.9",
|
||||
"file-loader": "2.0.0",
|
||||
"file-loader": "3.0.1",
|
||||
"html-webpack-plugin": "3.2.0",
|
||||
"husky": "1.2.1",
|
||||
"husky": "1.3.1",
|
||||
"idb-keyval": "3.1.0",
|
||||
"linkstate": "1.1.1",
|
||||
"loader-utils": "1.1.0",
|
||||
"loader-utils": "1.2.0",
|
||||
"mini-css-extract-plugin": "0.5.0",
|
||||
"minimatch": "3.0.4",
|
||||
"node-sass": "4.11.0",
|
||||
@@ -45,25 +45,25 @@
|
||||
"preact": "8.4.2",
|
||||
"prerender-loader": "1.2.0",
|
||||
"pretty-bytes": "5.1.0",
|
||||
"progress-bar-webpack-plugin": "1.11.0",
|
||||
"progress-bar-webpack-plugin": "1.12.1",
|
||||
"raw-loader": "1.0.0",
|
||||
"sass-loader": "7.1.0",
|
||||
"script-ext-html-webpack-plugin": "2.1.3",
|
||||
"source-map-loader": "0.2.4",
|
||||
"style-loader": "0.23.1",
|
||||
"terser-webpack-plugin": "1.1.0",
|
||||
"ts-loader": "5.3.1",
|
||||
"tslint": "5.11.0",
|
||||
"terser-webpack-plugin": "1.2.2",
|
||||
"ts-loader": "5.3.3",
|
||||
"tslint": "5.12.1",
|
||||
"tslint-config-airbnb": "5.11.1",
|
||||
"tslint-config-semistandard": "7.0.0",
|
||||
"tslint-react": "3.6.0",
|
||||
"typed-css-modules": "0.3.7",
|
||||
"typescript": "3.2.2",
|
||||
"typescript": "3.2.4",
|
||||
"url-loader": "1.1.2",
|
||||
"webpack": "4.27.1",
|
||||
"webpack": "4.28.0",
|
||||
"webpack-bundle-analyzer": "3.0.3",
|
||||
"webpack-cli": "3.1.2",
|
||||
"webpack-dev-server": "3.1.10",
|
||||
"webpack-cli": "3.2.3",
|
||||
"webpack-dev-server": "3.1.14",
|
||||
"worker-plugin": "3.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as identity from './identity/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 webP from './webp/encoder-meta';
|
||||
import * as browserPNG from './browser-png/encoder-meta';
|
||||
@@ -18,6 +19,7 @@ export interface EncoderSupportMap {
|
||||
export type EncoderState =
|
||||
identity.EncoderState |
|
||||
optiPNG.EncoderState |
|
||||
oxiPNG.EncoderState |
|
||||
mozJPEG.EncoderState |
|
||||
webP.EncoderState |
|
||||
browserPNG.EncoderState |
|
||||
@@ -32,6 +34,7 @@ export type EncoderState =
|
||||
export type EncoderOptions =
|
||||
identity.EncodeOptions |
|
||||
optiPNG.EncodeOptions |
|
||||
oxiPNG.EncodeOptions |
|
||||
mozJPEG.EncodeOptions |
|
||||
webP.EncodeOptions |
|
||||
browserPNG.EncodeOptions |
|
||||
@@ -48,6 +51,7 @@ export type EncoderType = keyof typeof encoderMap;
|
||||
export const encoderMap = {
|
||||
[identity.type]: identity,
|
||||
[optiPNG.type]: optiPNG,
|
||||
[oxiPNG.type]: oxiPNG,
|
||||
[mozJPEG.type]: mozJPEG,
|
||||
[webP.type]: webP,
|
||||
[browserPNG.type]: browserPNG,
|
||||
|
||||
@@ -3,7 +3,7 @@ export interface EncodeOptions {
|
||||
}
|
||||
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
||||
|
||||
export const type = 'png';
|
||||
export const type = 'optipng';
|
||||
export const label = 'OptiPNG';
|
||||
export const mimeType = 'image/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);
|
||||
}
|
||||
|
||||
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(
|
||||
data: ImageData, options: import('../webp/encoder-meta').EncodeOptions,
|
||||
): Promise<ArrayBuffer> {
|
||||
@@ -59,7 +69,15 @@ async function webpDecode(data: ArrayBuffer): Promise<ImageData> {
|
||||
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;
|
||||
|
||||
expose(exports, self);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { QuantizeOptions } from './imagequant/processor-meta';
|
||||
import { canvasEncode, blobToArrayBuffer } from '../lib/util';
|
||||
import { EncodeOptions as MozJPEGEncoderOptions } from './mozjpeg/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 BrowserJPEGOptions } from './browser-jpeg/encoder-meta';
|
||||
import { EncodeOptions as BrowserWebpEncodeOptions } from './browser-webp/encoder-meta';
|
||||
@@ -147,6 +148,16 @@ export default class Processor {
|
||||
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 })
|
||||
webpEncode(data: ImageData, opts: WebPEncoderOptions): Promise<ArrayBuffer> {
|
||||
return this._workerApi!.webpEncode(data, opts);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { RotateOptions } from './processor-meta';
|
||||
|
||||
const bpp = 4;
|
||||
|
||||
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
||||
const { rotate } = opts;
|
||||
const flipDimensions = rotate % 180 !== 0;
|
||||
@@ -61,14 +59,13 @@ export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
||||
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 d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
|
||||
// Iterate over channels:
|
||||
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier)) * bpp;
|
||||
for (let j = 0; j < bpp; j += 1) {
|
||||
out.data[i] = data.data[start + j];
|
||||
i += 1;
|
||||
}
|
||||
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier));
|
||||
outB[i] = inB[start];
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import Options from '../Options';
|
||||
import ResultCache from './result-cache';
|
||||
import * as identity from '../../codecs/identity/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 webP from '../../codecs/webp/encoder-meta';
|
||||
import * as browserPNG from '../../codecs/browser-png/encoder-meta';
|
||||
@@ -131,6 +132,7 @@ async function compressImage(
|
||||
const compressedData = await (() => {
|
||||
switch (encodeData.type) {
|
||||
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 webP.type: return processor.webpEncode(image, encodeData.options);
|
||||
case browserPNG.type: return processor.browserPngEncode(image);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
overflow: hidden;
|
||||
|
||||
// Reorder so headings appear after content:
|
||||
& > :nth-child(1) {
|
||||
|
||||
Reference in New Issue
Block a user