forked from external-repos/squoosh
Compare commits
6 Commits
tiling-rus
...
assemblysc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41f085438b | ||
|
|
fdbc0932e4 | ||
|
|
2412e925ba | ||
|
|
a676e1a2e9 | ||
|
|
a8265d5350 | ||
|
|
8f5c03e05b |
@@ -1,4 +1,7 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- node
|
||||||
|
- 10
|
||||||
|
- 8
|
||||||
cache: npm
|
cache: npm
|
||||||
script: npm run build
|
script: npm run build
|
||||||
after_success: npm run sizereport
|
|
||||||
|
|||||||
2
codecs/rotate/.gitignore
vendored
2
codecs/rotate/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
target
|
|
||||||
Cargo.lock
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "rotate"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Surma <surma@google.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "rotate"
|
|
||||||
path = "rotate.rs"
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
opt-level = "s"
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
FROM ubuntu
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -qqy git build-essential cmake python2.7
|
|
||||||
RUN git clone --recursive https://github.com/WebAssembly/wabt /usr/src/wabt
|
|
||||||
RUN mkdir -p /usr/src/wabt/build
|
|
||||||
WORKDIR /usr/src/wabt/build
|
|
||||||
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \
|
|
||||||
make && \
|
|
||||||
make install
|
|
||||||
|
|
||||||
FROM rust
|
|
||||||
RUN rustup install nightly && \
|
|
||||||
rustup target add --toolchain nightly wasm32-unknown-unknown
|
|
||||||
|
|
||||||
COPY --from=0 /opt/wabt /opt/wabt
|
|
||||||
ENV PATH="/opt/wabt/bin:${PATH}"
|
|
||||||
WORKDIR /src
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// THIS IS NOT A NODE SCRIPT
|
|
||||||
// This is a d8 script. Please install jsvu[1] and install v8.
|
|
||||||
// Then run `npm run --silent benchmark`.
|
|
||||||
// [1]: https://github.com/GoogleChromeLabs/jsvu
|
|
||||||
async function init() {
|
|
||||||
// Adjustable constants.
|
|
||||||
const imageDimensions = 4096;
|
|
||||||
const iterations = new Array(100);
|
|
||||||
|
|
||||||
// Constants. Don’t change.
|
|
||||||
const imageByteSize = imageDimensions * imageDimensions * 4;
|
|
||||||
const wasmPageSize = 64 * 1024;
|
|
||||||
|
|
||||||
const buffer = readbuffer("rotate.wasm");
|
|
||||||
const { instance } = await WebAssembly.instantiate(buffer);
|
|
||||||
|
|
||||||
const pagesAvailable = Math.floor(
|
|
||||||
instance.exports.memory.buffer.byteLength / wasmPageSize
|
|
||||||
);
|
|
||||||
const pagesNeeded = Math.floor((imageByteSize * 2 + 4) / wasmPageSize) + 1;
|
|
||||||
const additionalPagesNeeded = pagesNeeded - pagesAvailable;
|
|
||||||
if (additionalPagesNeeded > 0) {
|
|
||||||
instance.exports.memory.grow(additionalPagesNeeded);
|
|
||||||
}
|
|
||||||
|
|
||||||
[0, 90, 180, 270].forEach(rotation => {
|
|
||||||
print(`\n${rotation} degrees`);
|
|
||||||
print(`==============================`);
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
const start = Date.now();
|
|
||||||
instance.exports.rotate(imageDimensions, imageDimensions, rotation);
|
|
||||||
iterations[i] = Date.now() - start;
|
|
||||||
}
|
|
||||||
const average = iterations.reduce((sum, c) => sum + c) / iterations.length;
|
|
||||||
const stddev = Math.sqrt(
|
|
||||||
iterations
|
|
||||||
.map(i => Math.pow(i - average, 2))
|
|
||||||
.reduce((sum, c) => sum + c) / iterations.length
|
|
||||||
);
|
|
||||||
print(`n = ${iterations.length}`);
|
|
||||||
print(`Average: ${average}`);
|
|
||||||
print(`StdDev: ${stddev}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
init().catch(e => console.error(e.stack));
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm"
|
|
||||||
echo "============================================="
|
|
||||||
(
|
|
||||||
rustup run nightly \
|
|
||||||
cargo build \
|
|
||||||
--target wasm32-unknown-unknown \
|
|
||||||
--release
|
|
||||||
cp target/wasm32-unknown-unknown/release/rotate.wasm .
|
|
||||||
wasm-strip rotate.wasm
|
|
||||||
)
|
|
||||||
echo "============================================="
|
|
||||||
echo "Compiling wasm done"
|
|
||||||
echo "============================================="
|
|
||||||
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
echo "Did you update your docker image?"
|
|
||||||
echo "Run \`docker pull ubuntu\`"
|
|
||||||
echo "Run \`docker pull rust\`"
|
|
||||||
echo "Run \`docker build -t squoosh-rotate .\`"
|
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
124
codecs/rotate/package-lock.json
generated
Normal file
124
codecs/rotate/package-lock.json
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"name": "rotate",
|
||||||
|
"requires": true,
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"dependencies": {
|
||||||
|
"@protobufjs/utf8": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz",
|
||||||
|
"integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"assemblyscript": {
|
||||||
|
"version": "github:AssemblyScript/assemblyscript#54b02c287c4d42092e4b01cc5d11bce1a53e9fb2",
|
||||||
|
"from": "github:AssemblyScript/assemblyscript",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@protobufjs/utf8": "^1.1.0",
|
||||||
|
"binaryen": "63.0.0-nightly.20190107",
|
||||||
|
"glob": "^7.1.3",
|
||||||
|
"long": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"balanced-match": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"binaryen": {
|
||||||
|
"version": "63.0.0-nightly.20190107",
|
||||||
|
"resolved": "https://registry.npmjs.org/binaryen/-/binaryen-63.0.0-nightly.20190107.tgz",
|
||||||
|
"integrity": "sha512-vck6ZESU9q6DeEK9v/Fk2O8d2jBsSrNlia8jpmdLZv5eqmNWpkNli+QMRa9Ezfb4wi3c+NVMuxT3Ck0g9GYe8A==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"brace-expansion": {
|
||||||
|
"version": "1.1.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
|
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"balanced-match": "^1.0.0",
|
||||||
|
"concat-map": "0.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"concat-map": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"fs.realpath": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"glob": {
|
||||||
|
"version": "7.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
|
||||||
|
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"fs.realpath": "^1.0.0",
|
||||||
|
"inflight": "^1.0.4",
|
||||||
|
"inherits": "2",
|
||||||
|
"minimatch": "^3.0.4",
|
||||||
|
"once": "^1.3.0",
|
||||||
|
"path-is-absolute": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inflight": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
|
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"once": "^1.3.0",
|
||||||
|
"wrappy": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"inherits": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"long": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"minimatch": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"brace-expansion": "^1.1.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"once": {
|
||||||
|
"version": "1.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"wrappy": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"path-is-absolute": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"wrappy": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "rotate",
|
"name": "rotate",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:image": "docker build -t squoosh-rotate .",
|
"build": "mv rotate.{as,ts} && asc rotate.ts -b rotate.wasm --validate -O3 --importMemory && mv rotate.{ts,as}"
|
||||||
"build": "docker run --rm -v $(pwd):/src squoosh-rotate ./build.sh",
|
},
|
||||||
"benchmark": "echo File size after gzip && npm run benchmark:filesize && echo Optimizing && npm run -s benchmark:optimizing",
|
"devDependencies": {
|
||||||
"benchmark:baseline": "v8 --liftoff --no-wasm-tier-up --no-opt ./benchmark.js",
|
"assemblyscript": "github:AssemblyScript/assemblyscript"
|
||||||
"benchmark:optimizing": "v8 --no-liftoff --no-wasm-tier-up ./benchmark.js",
|
|
||||||
"benchmark:filesize": "cat rotate.wasm | gzip -c9n | wc -c"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
64
codecs/rotate/rotate.as
Normal file
64
codecs/rotate/rotate.as
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
export function rotate(inputWidth: i32, inputHeight: i32, rotate: i32): void {
|
||||||
|
const bpp = 4;
|
||||||
|
let offset = inputWidth * inputHeight * bpp;
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
// In the straight-copy case, d1 is x, d2 is y.
|
||||||
|
// x starts at 0 and increases.
|
||||||
|
// y starts at 0 and increases.
|
||||||
|
let d1Start = 0;
|
||||||
|
let d1Limit = inputWidth;
|
||||||
|
let d1Advance = 1;
|
||||||
|
let d1Multiplier = 1;
|
||||||
|
let d2Start = 0;
|
||||||
|
let d2Limit = inputHeight;
|
||||||
|
let d2Advance = 1;
|
||||||
|
let d2Multiplier = inputWidth;
|
||||||
|
|
||||||
|
if (rotate === 90) {
|
||||||
|
// d1 is y, d2 is x.
|
||||||
|
// y starts at its max value and decreases.
|
||||||
|
// x starts at 0 and increases.
|
||||||
|
d1Start = inputHeight - 1;
|
||||||
|
d1Limit = inputHeight;
|
||||||
|
d1Advance = -1;
|
||||||
|
d1Multiplier = inputWidth;
|
||||||
|
d2Start = 0;
|
||||||
|
d2Limit = inputWidth;
|
||||||
|
d2Advance = 1;
|
||||||
|
d2Multiplier = 1;
|
||||||
|
} else if (rotate === 180) {
|
||||||
|
// d1 is x, d2 is y.
|
||||||
|
// x starts at its max and decreases.
|
||||||
|
// y starts at its max and decreases.
|
||||||
|
d1Start = inputWidth - 1;
|
||||||
|
d1Limit = inputWidth;
|
||||||
|
d1Advance = -1;
|
||||||
|
d1Multiplier = 1;
|
||||||
|
d2Start = inputHeight - 1;
|
||||||
|
d2Limit = inputHeight;
|
||||||
|
d2Advance = -1;
|
||||||
|
d2Multiplier = inputWidth;
|
||||||
|
} else if (rotate === 270) {
|
||||||
|
// d1 is y, d2 is x.
|
||||||
|
// y starts at 0 and increases.
|
||||||
|
// x starts at its max and decreases.
|
||||||
|
d1Start = 0;
|
||||||
|
d1Limit = inputHeight;
|
||||||
|
d1Advance = 1;
|
||||||
|
d1Multiplier = inputWidth;
|
||||||
|
d2Start = inputWidth - 1;
|
||||||
|
d2Limit = inputWidth;
|
||||||
|
d2Advance = -1;
|
||||||
|
d2Multiplier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let d2 = d2Start; d2 >= 0 && d2 < d2Limit; d2 += d2Advance) {
|
||||||
|
let d2offset = d2 * d2Multiplier;
|
||||||
|
for (let d1 = d1Start; d1 >= 0 && d1 < d1Limit; d1 += d1Advance) {
|
||||||
|
let start = ((d1 * d1Multiplier) + d2offset);
|
||||||
|
store<u32>(offset + i * 4, load<u32>(start * 4));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
use std::slice::{from_raw_parts, from_raw_parts_mut};
|
|
||||||
|
|
||||||
// This function is taken from Zachary Dremann
|
|
||||||
// https://github.com/GoogleChromeLabs/squoosh/pull/462
|
|
||||||
trait HardUnwrap<T> {
|
|
||||||
fn unwrap_hard(self) -> T;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> HardUnwrap<T> for Option<T> {
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
#[inline]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
match self {
|
|
||||||
Some(t) => t,
|
|
||||||
None => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
self.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TILE_SIZE: usize = 16;
|
|
||||||
|
|
||||||
fn get_buffers<'a>(width: usize, height: usize) -> (&'a [u32], &'a mut [u32]) {
|
|
||||||
let num_pixels = width * height;
|
|
||||||
let in_b: &[u32];
|
|
||||||
let out_b: &mut [u32];
|
|
||||||
unsafe {
|
|
||||||
in_b = from_raw_parts::<u32>(8 as *const u32, num_pixels);
|
|
||||||
out_b = from_raw_parts_mut::<u32>((num_pixels * 4 + 8) as *mut u32, num_pixels);
|
|
||||||
}
|
|
||||||
return (in_b, out_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_0(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_90(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let _new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = (new_width - 1) - y;
|
|
||||||
let new_y = x + x_start;
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_180(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut().rev()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_270(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = y;
|
|
||||||
let new_y = new_height - 1 - (x_start + x);
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
fn rotate(width: usize, height: usize, rotate: usize) {
|
|
||||||
match rotate {
|
|
||||||
0 => rotate_0(width, height),
|
|
||||||
90 => rotate_90(width, height),
|
|
||||||
180 => rotate_180(width, height),
|
|
||||||
270 => rotate_270(width, height),
|
|
||||||
_ => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
codecs/rotate/rotate.wasm
Executable file → Normal file
BIN
codecs/rotate/rotate.wasm
Executable file → Normal file
Binary file not shown.
6
codecs/rotate/tsconfig.json
Normal file
6
codecs/rotate/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "./node_modules/assemblyscript/std/assembly.json",
|
||||||
|
"include": [
|
||||||
|
"./**/*.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# WebP decoder
|
# WebP decoder
|
||||||
|
|
||||||
- Source: <https://github.com/webmproject/libwebp>
|
- Source: <https://github.com/webmproject/libwebp>
|
||||||
- Version: v1.0.2
|
- Version: v0.6.1
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|||||||
@@ -6,33 +6,7 @@ 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 "============================================="
|
||||||
@@ -46,9 +20,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,7 +5,7 @@
|
|||||||
"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.2"
|
"libwebp": "webmproject/libwebp#v1.0.0"
|
||||||
},
|
},
|
||||||
"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: v1.0.2
|
- Version: v0.6.1
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
|||||||
@@ -7,33 +7,6 @@ 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 "============================================="
|
||||||
@@ -47,9 +20,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,7 +5,7 @@
|
|||||||
"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.2"
|
"libwebp": "webmproject/libwebp#v1.0.0"
|
||||||
},
|
},
|
||||||
"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,204 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
const { URL } = require('url');
|
|
||||||
|
|
||||||
const gzipSize = require('gzip-size');
|
|
||||||
const fetch = require('node-fetch');
|
|
||||||
const prettyBytes = require('pretty-bytes');
|
|
||||||
const escapeRE = require('escape-string-regexp');
|
|
||||||
const readdirp = require('readdirp');
|
|
||||||
const chalk = new require('chalk').constructor({ level: 4 });
|
|
||||||
|
|
||||||
function fetchTravis(path, options = {}) {
|
|
||||||
const url = new URL(path, 'https://api.travis-ci.org');
|
|
||||||
url.search = new URLSearchParams(options);
|
|
||||||
|
|
||||||
return fetch(url, {
|
|
||||||
headers: { 'Travis-API-Version': '3' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchTravisBuildInfo(user, repo, branch) {
|
|
||||||
return fetchTravis(`/repo/${encodeURIComponent(`${user}/${repo}`)}/builds`, {
|
|
||||||
'branch.name': branch,
|
|
||||||
state: 'passed',
|
|
||||||
limit: 1,
|
|
||||||
}).then(r => r.json());
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchTravisText(path) {
|
|
||||||
return fetchTravis(path).then(r => r.text());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively-read a directory and turn it into an array of { name, size, gzipSize }
|
|
||||||
*/
|
|
||||||
async function dirToInfoArray(startPath, {
|
|
||||||
namePrefix = '',
|
|
||||||
} = {}) {
|
|
||||||
const results = await new Promise((resolve, reject) => {
|
|
||||||
readdirp({ root: startPath }, (err, results) => {
|
|
||||||
if (err) reject(err); else resolve(results);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(
|
|
||||||
results.files.map(async (entry) => ({
|
|
||||||
name: entry.path,
|
|
||||||
gzipSize: await gzipSize.file(entry.fullPath),
|
|
||||||
size: entry.stat.size,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to treat two entries with different file name hashes as the same file.
|
|
||||||
*/
|
|
||||||
function findHashedMatch(name, buildInfo) {
|
|
||||||
const nameParts = /^(.+\.)[a-f0-9]+(\..+)$/.exec(name);
|
|
||||||
if (!nameParts) return;
|
|
||||||
|
|
||||||
const matchRe = new RegExp(`^${escapeRE(nameParts[1])}[a-f0-9]+${escapeRE(nameParts[2])}$`);
|
|
||||||
const matchingEntry = buildInfo.find(entry => matchRe.test(entry.name));
|
|
||||||
return matchingEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
const buildSizePrefix = '=== BUILD SIZES: ';
|
|
||||||
const buildSizePrefixRe = new RegExp(`^${escapeRE(buildSizePrefix)}(.+)$`, 'm');
|
|
||||||
|
|
||||||
async function getPreviousBuildInfo() {
|
|
||||||
const buildData = await fetchTravisBuildInfo('GoogleChromeLabs', 'squoosh', 'master');
|
|
||||||
const jobUrl = buildData.builds[0].jobs[0]['@href'];
|
|
||||||
const log = await fetchTravisText(jobUrl + '/log.txt');
|
|
||||||
const reResult = buildSizePrefixRe.exec(log);
|
|
||||||
|
|
||||||
if (!reResult) return;
|
|
||||||
return JSON.parse(reResult[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate an array that represents the difference between builds.
|
|
||||||
* Returns an array of { beforeName, afterName, beforeSize, afterSize }.
|
|
||||||
* Sizes are gzipped size.
|
|
||||||
* Before/after properties are missing if resource isn't in the previous/new build.
|
|
||||||
*/
|
|
||||||
function getChanges(previousBuildInfo, buildInfo) {
|
|
||||||
const buildChanges = [];
|
|
||||||
const alsoInPreviousBuild = new Set();
|
|
||||||
|
|
||||||
for (const oldEntry of previousBuildInfo) {
|
|
||||||
const newEntry = buildInfo.find(entry => entry.name === oldEntry.name) ||
|
|
||||||
findHashedMatch(oldEntry.name, buildInfo);
|
|
||||||
|
|
||||||
// Entry is in previous build, but not the new build.
|
|
||||||
if (!newEntry) {
|
|
||||||
buildChanges.push({
|
|
||||||
beforeName: oldEntry.name,
|
|
||||||
beforeSize: oldEntry.gzipSize,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark this entry so we know we've dealt with it.
|
|
||||||
alsoInPreviousBuild.add(newEntry);
|
|
||||||
|
|
||||||
// If they're the same, just ignore.
|
|
||||||
// Using size rather than gzip size. I've seen different platforms produce different zipped
|
|
||||||
// sizes.
|
|
||||||
if (
|
|
||||||
oldEntry.size === newEntry.size &&
|
|
||||||
oldEntry.name === newEntry.name
|
|
||||||
) continue;
|
|
||||||
|
|
||||||
// Entry is in both builds (maybe renamed).
|
|
||||||
buildChanges.push({
|
|
||||||
beforeName: oldEntry.name,
|
|
||||||
afterName: newEntry.name,
|
|
||||||
beforeSize: oldEntry.gzipSize,
|
|
||||||
afterSize: newEntry.gzipSize,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look for entries that are only in the new build.
|
|
||||||
for (const newEntry of buildInfo) {
|
|
||||||
if (alsoInPreviousBuild.has(newEntry)) continue;
|
|
||||||
|
|
||||||
buildChanges.push({
|
|
||||||
afterName: newEntry.name,
|
|
||||||
afterSize: newEntry.gzipSize,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
// Output the current build sizes for later retrieval.
|
|
||||||
const buildInfo = await dirToInfoArray(__dirname + '/../build');
|
|
||||||
console.log(buildSizePrefix + JSON.stringify(buildInfo));
|
|
||||||
console.log('\nBuild change report:');
|
|
||||||
|
|
||||||
let previousBuildInfo;
|
|
||||||
|
|
||||||
try {
|
|
||||||
previousBuildInfo = await getPreviousBuildInfo();
|
|
||||||
} catch (err) {
|
|
||||||
console.log(` Couldn't parse previous build info`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!previousBuildInfo) {
|
|
||||||
console.log(` Couldn't find previous build info`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const buildChanges = getChanges(previousBuildInfo, buildInfo);
|
|
||||||
|
|
||||||
if (buildChanges.length === 0) {
|
|
||||||
console.log(' No changes');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// One letter references, so it's easier to get the spacing right.
|
|
||||||
const y = chalk.yellow;
|
|
||||||
const g = chalk.green;
|
|
||||||
const r = chalk.red;
|
|
||||||
|
|
||||||
for (const change of buildChanges) {
|
|
||||||
// New file.
|
|
||||||
if (!change.beforeSize) {
|
|
||||||
console.log(` ${g('ADDED')} ${change.afterName} - ${prettyBytes(change.afterSize)}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removed file.
|
|
||||||
if (!change.afterSize) {
|
|
||||||
console.log(` ${r('REMOVED')} ${change.beforeName} - was ${prettyBytes(change.beforeSize)}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Changed file.
|
|
||||||
let size;
|
|
||||||
|
|
||||||
if (change.beforeSize === change.afterSize) {
|
|
||||||
// Just renamed.
|
|
||||||
size = `${prettyBytes(change.afterSize)} -> no change`;
|
|
||||||
} else {
|
|
||||||
const color = change.afterSize > change.beforeSize ? r : g;
|
|
||||||
const sizeDiff = prettyBytes(change.afterSize - change.beforeSize, { signed: true });
|
|
||||||
const relativeDiff = Math.round((change.afterSize / change.beforeSize) * 1000) / 1000;
|
|
||||||
|
|
||||||
size = `${prettyBytes(change.beforeSize)} -> ${prettyBytes(change.afterSize)}` +
|
|
||||||
' (' +
|
|
||||||
color(`${sizeDiff}, ${relativeDiff}x`) +
|
|
||||||
')';
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(` ${y('CHANGED')} ${change.afterName} - ${size}`);
|
|
||||||
|
|
||||||
if (change.beforeName !== change.afterName) {
|
|
||||||
console.log(` Renamed from: ${change.beforeName}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
||||||
2122
package-lock.json
generated
2122
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.3.3",
|
"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",
|
||||||
"build": "webpack -p",
|
"build": "webpack -p",
|
||||||
"lint": "tslint -c tslint.json -p tsconfig.json -t verbose 'src/**/*.{ts,tsx,js,jsx}'",
|
"lint": "tslint -c tslint.json -p tsconfig.json -t verbose 'src/**/*.{ts,tsx,js,jsx}'",
|
||||||
"lintfix": "tslint -c tslint.json -p tsconfig.json -t verbose --fix 'src/**/*.{ts,tsx,js,jsx}'",
|
"lintfix": "tslint -c tslint.json -p tsconfig.json -t verbose --fix 'src/**/*.{ts,tsx,js,jsx}'"
|
||||||
"sizereport": "node config/size-report.js"
|
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
@@ -16,48 +15,43 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "10.12.26",
|
"@types/node": "10.12.18",
|
||||||
"@types/pretty-bytes": "5.1.0",
|
"@types/pretty-bytes": "5.1.0",
|
||||||
"@types/webassembly-js-api": "0.0.2",
|
"@types/webassembly-js-api": "0.0.2",
|
||||||
"@webcomponents/custom-elements": "1.2.1",
|
"@webcomponents/custom-elements": "1.2.1",
|
||||||
"@webpack-cli/serve": "0.1.3",
|
"@webpack-cli/serve": "0.1.3",
|
||||||
"assets-webpack-plugin": "3.9.7",
|
"assets-webpack-plugin": "3.9.7",
|
||||||
"chokidar": "2.1.2",
|
"chokidar": "2.0.4",
|
||||||
"chalk": "2.4.2",
|
|
||||||
"classnames": "2.2.6",
|
"classnames": "2.2.6",
|
||||||
"clean-webpack-plugin": "1.0.1",
|
"clean-webpack-plugin": "1.0.1",
|
||||||
"comlink": "3.1.1",
|
"comlink": "3.1.1",
|
||||||
"copy-webpack-plugin": "5.0.0",
|
"copy-webpack-plugin": "4.6.0",
|
||||||
"critters-webpack-plugin": "2.3.0",
|
"critters-webpack-plugin": "2.2.0",
|
||||||
"css-loader": "1.0.1",
|
"css-loader": "1.0.1",
|
||||||
"ejs": "2.6.1",
|
"ejs": "2.6.1",
|
||||||
"escape-string-regexp": "1.0.5",
|
|
||||||
"exports-loader": "0.7.0",
|
"exports-loader": "0.7.0",
|
||||||
"file-drop-element": "0.0.9",
|
"file-drop-element": "0.0.9",
|
||||||
"file-loader": "3.0.1",
|
"file-loader": "3.0.1",
|
||||||
"gzip-size": "5.0.0",
|
|
||||||
"html-webpack-plugin": "3.2.0",
|
"html-webpack-plugin": "3.2.0",
|
||||||
"husky": "1.3.1",
|
"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.2.3",
|
"loader-utils": "1.2.0",
|
||||||
"mini-css-extract-plugin": "0.5.0",
|
"mini-css-extract-plugin": "0.5.0",
|
||||||
"minimatch": "3.0.4",
|
"minimatch": "3.0.4",
|
||||||
"node-fetch": "2.3.0",
|
|
||||||
"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.4.2",
|
"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.12.1",
|
"progress-bar-webpack-plugin": "1.12.0",
|
||||||
"raw-loader": "1.0.0",
|
"raw-loader": "1.0.0",
|
||||||
"readdirp": "2.2.1",
|
|
||||||
"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.2.2",
|
"terser-webpack-plugin": "1.2.1",
|
||||||
"ts-loader": "5.3.3",
|
"ts-loader": "5.3.3",
|
||||||
"tslint": "5.12.1",
|
"tslint": "5.12.1",
|
||||||
"tslint-config-airbnb": "5.11.1",
|
"tslint-config-airbnb": "5.11.1",
|
||||||
@@ -67,9 +61,9 @@
|
|||||||
"typescript": "3.2.4",
|
"typescript": "3.2.4",
|
||||||
"url-loader": "1.1.2",
|
"url-loader": "1.1.2",
|
||||||
"webpack": "4.28.0",
|
"webpack": "4.28.0",
|
||||||
"webpack-bundle-analyzer": "3.0.4",
|
"webpack-bundle-analyzer": "3.0.3",
|
||||||
"webpack-cli": "3.2.3",
|
"webpack-cli": "3.2.1",
|
||||||
"webpack-dev-server": "3.2.0",
|
"webpack-dev-server": "3.1.14",
|
||||||
"worker-plugin": "3.1.0"
|
"worker-plugin": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,29 @@
|
|||||||
import wasmUrl from '../../../codecs/rotate/rotate.wasm';
|
import wasmUrl from '../../../codecs/rotate/rotate.wasm';
|
||||||
import { RotateOptions, RotateModuleInstance } from './processor-meta';
|
import { RotateOptions, RotateModuleInstance } from './processor-meta';
|
||||||
|
|
||||||
const instancePromise = (WebAssembly as any).instantiateStreaming(fetch(wasmUrl));
|
|
||||||
|
|
||||||
export async function rotate(
|
export async function rotate(
|
||||||
data: ImageData,
|
data: ImageData,
|
||||||
opts: RotateOptions,
|
opts: RotateOptions,
|
||||||
): Promise<ImageData> {
|
): Promise<ImageData> {
|
||||||
const { instance } = (await instancePromise) as {instance: RotateModuleInstance};
|
const flipDimensions = opts.rotate % 180 !== 0;
|
||||||
|
|
||||||
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
||||||
const bytesPerImage = data.width * data.height * 4;
|
const bytesPerImage = data.width * data.height * 4;
|
||||||
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 8) / (64 * 1024));
|
const numPagesNeeded = Math.ceil(bytesPerImage * 2 / (64 * 1024));
|
||||||
// Only count full pages, just to be safe.
|
const { instance } = (await (WebAssembly as any).instantiateStreaming(
|
||||||
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
|
fetch(wasmUrl),
|
||||||
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
|
{
|
||||||
|
env: {
|
||||||
|
memory: new WebAssembly.Memory({ initial: numPagesNeeded }),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)) as { instance: RotateModuleInstance };
|
||||||
|
|
||||||
if (additionalPagesToAllocate > 0) {
|
|
||||||
instance.exports.memory.grow(additionalPagesToAllocate);
|
|
||||||
}
|
|
||||||
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
|
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
|
||||||
view.set(data.data, 8);
|
view.set(data.data);
|
||||||
|
|
||||||
instance.exports.rotate(data.width, data.height, opts.rotate);
|
instance.exports.rotate(data.width, data.height, opts.rotate);
|
||||||
|
|
||||||
const flipDimensions = opts.rotate % 180 !== 0;
|
|
||||||
return new ImageData(
|
return new ImageData(
|
||||||
view.slice(bytesPerImage + 8, bytesPerImage * 2 + 8),
|
view.slice(bytesPerImage, bytesPerImage * 2),
|
||||||
flipDimensions ? data.height : data.width,
|
flipDimensions ? data.height : data.width,
|
||||||
flipDimensions ? data.width : data.height,
|
flipDimensions ? data.width : data.height,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user