mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 08:47:31 +00:00
Compare commits
2 Commits
tiling-rus
...
rotation-o
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd98d67b3e | ||
|
|
db1db8506e |
@@ -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
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
/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: <http://optipng.sourceforge.net/>
|
- Source: <https://sourceforge.net/project/optipng>
|
||||||
- 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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "rotate",
|
|
||||||
"scripts": {
|
|
||||||
"build:image": "docker build -t squoosh-rotate .",
|
|
||||||
"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",
|
|
||||||
"benchmark:baseline": "v8 --liftoff --no-wasm-tier-up --no-opt ./benchmark.js",
|
|
||||||
"benchmark:optimizing": "v8 --no-liftoff --no-wasm-tier-up ./benchmark.js",
|
|
||||||
"benchmark:filesize": "cat rotate.wasm | gzip -c9n | wc -c"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
use std::slice::{from_raw_parts, from_raw_parts_mut};
|
|
||||||
|
|
||||||
// This function is taken from Zachary Dremann
|
|
||||||
// https://github.com/GoogleChromeLabs/squoosh/pull/462
|
|
||||||
trait HardUnwrap<T> {
|
|
||||||
fn unwrap_hard(self) -> T;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> HardUnwrap<T> for Option<T> {
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
#[inline]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
match self {
|
|
||||||
Some(t) => t,
|
|
||||||
None => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
fn unwrap_hard(self) -> T {
|
|
||||||
self.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TILE_SIZE: usize = 16;
|
|
||||||
|
|
||||||
fn get_buffers<'a>(width: usize, height: usize) -> (&'a [u32], &'a mut [u32]) {
|
|
||||||
let num_pixels = width * height;
|
|
||||||
let in_b: &[u32];
|
|
||||||
let out_b: &mut [u32];
|
|
||||||
unsafe {
|
|
||||||
in_b = from_raw_parts::<u32>(8 as *const u32, num_pixels);
|
|
||||||
out_b = from_raw_parts_mut::<u32>((num_pixels * 4 + 8) as *mut u32, num_pixels);
|
|
||||||
}
|
|
||||||
return (in_b, out_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_0(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_90(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let _new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = (new_width - 1) - y;
|
|
||||||
let new_y = x + x_start;
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_180(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
for (in_p, out_p) in in_b.iter().zip(out_b.iter_mut().rev()) {
|
|
||||||
*out_p = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn rotate_270(width: usize, height: usize) {
|
|
||||||
let (in_b, out_b) = get_buffers(width, height);
|
|
||||||
let new_width = height;
|
|
||||||
let new_height = width;
|
|
||||||
for y_start in (0..height).step_by(TILE_SIZE) {
|
|
||||||
for x_start in (0..width).step_by(TILE_SIZE) {
|
|
||||||
for y in y_start..(y_start + TILE_SIZE).min(height) {
|
|
||||||
let in_offset = y * width;
|
|
||||||
let in_bounds = if x_start + TILE_SIZE < width {
|
|
||||||
(in_offset + x_start)..(in_offset + x_start + TILE_SIZE)
|
|
||||||
} else {
|
|
||||||
(in_offset + x_start)..(in_offset + width)
|
|
||||||
};
|
|
||||||
let in_chunk = in_b.get(in_bounds).unwrap_hard();
|
|
||||||
for (x, in_p) in in_chunk.iter().enumerate() {
|
|
||||||
let new_x = y;
|
|
||||||
let new_y = new_height - 1 - (x_start + x);
|
|
||||||
*out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = *in_p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
fn rotate(width: usize, height: usize, rotate: usize) {
|
|
||||||
match rotate {
|
|
||||||
0 => rotate_0(width, height),
|
|
||||||
90 => rotate_90(width, height),
|
|
||||||
180 => rotate_180(width, height),
|
|
||||||
270 => rotate_270(width, height),
|
|
||||||
_ => std::process::abort(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,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,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.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,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.2"
|
"libwebp": "webmproject/libwebp#v1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "3.0.0"
|
"napa": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ val encode(std::string img, int width, int height, WebPConfig config) {
|
|||||||
throw std::runtime_error("Unexpected error");
|
throw std::runtime_error("Unexpected error");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only use use_argb if we really need it, as it's slower.
|
pic.use_argb = !!config.lossless;
|
||||||
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.
@@ -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();
|
|
||||||
3097
package-lock.json
generated
3097
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
110
package.json
110
package.json
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.3.3",
|
"version": "1.2.2",
|
||||||
"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,60 +15,55 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "10.12.26",
|
"@types/node": "^10.12.6",
|
||||||
"@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.1",
|
||||||
"@webcomponents/custom-elements": "1.2.1",
|
"@webcomponents/custom-elements": "^1.2.1",
|
||||||
"@webpack-cli/serve": "0.1.3",
|
"@webpack-cli/serve": "^0.1.2",
|
||||||
"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.0",
|
||||||
"clean-webpack-plugin": "1.0.1",
|
"comlink": "^3.0.3",
|
||||||
"comlink": "3.1.1",
|
"copy-webpack-plugin": "^4.6.0",
|
||||||
"copy-webpack-plugin": "5.0.0",
|
"critters-webpack-plugin": "^2.0.1",
|
||||||
"critters-webpack-plugin": "2.3.0",
|
"css-loader": "^1.0.1",
|
||||||
"css-loader": "1.0.1",
|
"ejs": "^2.6.1",
|
||||||
"ejs": "2.6.1",
|
"exports-loader": "^0.7.0",
|
||||||
"escape-string-regexp": "1.0.5",
|
"file-drop-element": "^0.0.9",
|
||||||
"exports-loader": "0.7.0",
|
"file-loader": "^2.0.0",
|
||||||
"file-drop-element": "0.0.9",
|
"html-webpack-plugin": "^3.2.0",
|
||||||
"file-loader": "3.0.1",
|
"husky": "^1.1.4",
|
||||||
"gzip-size": "5.0.0",
|
"idb-keyval": "^3.1.0",
|
||||||
"html-webpack-plugin": "3.2.0",
|
"linkstate": "^1.1.1",
|
||||||
"husky": "1.3.1",
|
"loader-utils": "^1.1.0",
|
||||||
"idb-keyval": "3.1.0",
|
"mini-css-extract-plugin": "^0.4.4",
|
||||||
"linkstate": "1.1.1",
|
"minimatch": "^3.0.4",
|
||||||
"loader-utils": "1.2.3",
|
"node-sass": "^4.11.0",
|
||||||
"mini-css-extract-plugin": "0.5.0",
|
"optimize-css-assets-webpack-plugin": "^5.0.1",
|
||||||
"minimatch": "3.0.4",
|
"pointer-tracker": "^2.0.3",
|
||||||
"node-fetch": "2.3.0",
|
"preact": "^8.3.1",
|
||||||
"node-sass": "4.11.0",
|
"prerender-loader": "^1.2.0",
|
||||||
"optimize-css-assets-webpack-plugin": "5.0.1",
|
"pretty-bytes": "^5.1.0",
|
||||||
"pointer-tracker": "2.0.3",
|
"progress-bar-webpack-plugin": "^1.11.0",
|
||||||
"preact": "8.4.2",
|
"raw-loader": "^0.5.1",
|
||||||
"prerender-loader": "1.2.0",
|
"sass-loader": "^7.1.0",
|
||||||
"pretty-bytes": "5.1.0",
|
"script-ext-html-webpack-plugin": "^2.1.3",
|
||||||
"progress-bar-webpack-plugin": "1.12.1",
|
"source-map-loader": "^0.2.4",
|
||||||
"raw-loader": "1.0.0",
|
"style-loader": "^0.23.1",
|
||||||
"readdirp": "2.2.1",
|
"terser-webpack-plugin": "^1.1.0",
|
||||||
"sass-loader": "7.1.0",
|
"ts-loader": "^5.3.0",
|
||||||
"script-ext-html-webpack-plugin": "2.1.3",
|
"tslint": "^5.11.0",
|
||||||
"source-map-loader": "0.2.4",
|
"tslint-config-airbnb": "^5.11.0",
|
||||||
"style-loader": "0.23.1",
|
"tslint-config-semistandard": "^7.0.0",
|
||||||
"terser-webpack-plugin": "1.2.2",
|
"tslint-react": "^3.6.0",
|
||||||
"ts-loader": "5.3.3",
|
"typed-css-modules": "^0.3.7",
|
||||||
"tslint": "5.12.1",
|
"typescript": "^3.1.6",
|
||||||
"tslint-config-airbnb": "5.11.1",
|
"url-loader": "^1.1.2",
|
||||||
"tslint-config-semistandard": "7.0.0",
|
"webpack": "^4.25.1",
|
||||||
"tslint-react": "3.6.0",
|
"webpack-bundle-analyzer": "^3.0.3",
|
||||||
"typed-css-modules": "0.3.7",
|
"webpack-cli": "^3.1.2",
|
||||||
"typescript": "3.2.4",
|
"webpack-dev-server": "^3.1.10",
|
||||||
"url-loader": "1.1.2",
|
"worker-plugin": "^1.1.1"
|
||||||
"webpack": "4.28.0",
|
|
||||||
"webpack-bundle-analyzer": "3.0.4",
|
|
||||||
"webpack-cli": "3.2.3",
|
|
||||||
"webpack-dev-server": "3.2.0",
|
|
||||||
"worker-plugin": "3.1.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"config:base"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,3 @@ export interface RotateOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOptions: RotateOptions = { rotate: 0 };
|
export const defaultOptions: RotateOptions = { rotate: 0 };
|
||||||
|
|
||||||
export interface RotateModuleInstance {
|
|
||||||
exports: {
|
|
||||||
memory: WebAssembly.Memory;
|
|
||||||
rotate(width: number, height: number, rotate: 0 | 90 | 180 | 270): void;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,33 +1,76 @@
|
|||||||
import wasmUrl from '../../../codecs/rotate/rotate.wasm';
|
import { RotateOptions } from './processor-meta';
|
||||||
import { RotateOptions, RotateModuleInstance } from './processor-meta';
|
|
||||||
|
|
||||||
const instancePromise = (WebAssembly as any).instantiateStreaming(fetch(wasmUrl));
|
const bpp = 4;
|
||||||
|
|
||||||
export async function rotate(
|
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
||||||
data: ImageData,
|
const { rotate } = opts;
|
||||||
opts: RotateOptions,
|
const flipDimensions = rotate % 180 !== 0;
|
||||||
): Promise<ImageData> {
|
const { width: inputWidth, height: inputHeight } = data;
|
||||||
const { instance } = (await instancePromise) as {instance: RotateModuleInstance};
|
const outputWidth = flipDimensions ? inputHeight : inputWidth;
|
||||||
|
const outputHeight = flipDimensions ? inputWidth : inputHeight;
|
||||||
|
const out = new ImageData(outputWidth, outputHeight);
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
// In the straight-copy case, d1 is x, d2 is y.
|
||||||
const bytesPerImage = data.width * data.height * 4;
|
// x starts at 0 and increases.
|
||||||
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 8) / (64 * 1024));
|
// y starts at 0 and increases.
|
||||||
// Only count full pages, just to be safe.
|
let d1Start = 0;
|
||||||
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
|
let d1Limit = inputWidth;
|
||||||
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
|
let d1Advance = 1;
|
||||||
|
let d1Multiplier = 1;
|
||||||
|
let d2Start = 0;
|
||||||
|
let d2Limit = inputHeight;
|
||||||
|
let d2Advance = 1;
|
||||||
|
let d2Multiplier = inputWidth;
|
||||||
|
|
||||||
if (additionalPagesToAllocate > 0) {
|
if (rotate === 90) {
|
||||||
instance.exports.memory.grow(additionalPagesToAllocate);
|
// 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;
|
||||||
}
|
}
|
||||||
const view = new Uint8ClampedArray(instance.exports.memory.buffer);
|
|
||||||
view.set(data.data, 8);
|
|
||||||
|
|
||||||
instance.exports.rotate(data.width, data.height, opts.rotate);
|
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 flipDimensions = opts.rotate % 180 !== 0;
|
return out;
|
||||||
return new ImageData(
|
|
||||||
view.slice(bytesPerImage + 8, bytesPerImage * 2 + 8),
|
|
||||||
flipDimensions ? data.height : data.width,
|
|
||||||
flipDimensions ? data.width : data.height,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ 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',
|
||||||
@@ -20,21 +18,15 @@ 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,
|
||||||
};
|
};
|
||||||
@@ -56,33 +48,22 @@ 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, prev) => {
|
this.componentDidUpdate = (props, state) => {
|
||||||
if (oldCDU) oldCDU.call(this, props, state, prev);
|
if (oldCDU) oldCDU.call(this, props, state);
|
||||||
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({ file }: FileDropEvent) {
|
private onFileDrop(event: 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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,25 +74,18 @@ export default class App extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
private onPopState() {
|
private onBack() {
|
||||||
this.setState({ isEditorOpen: location.pathname === ROUTE_EDITOR });
|
this.setState({ file: undefined });
|
||||||
}
|
}
|
||||||
|
|
||||||
@bind
|
render({}: Props, { file, Compress }: State) {
|
||||||
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}>
|
||||||
{!isEditorOpen
|
{(!file)
|
||||||
? <Intro onFile={this.onIntroPickFile} showSnack={this.showSnack} />
|
? <Intro onFile={this.onIntroPickFile} showSnack={this.showSnack} />
|
||||||
: (Compress)
|
: (Compress)
|
||||||
? <Compress file={file!} showSnack={this.showSnack} onBack={back} />
|
? <Compress file={file} showSnack={this.showSnack} onBack={this.onBack} />
|
||||||
: <loading-spinner class={style.appLoader}/>
|
: <loading-spinner class={style.appLoader}/>
|
||||||
}
|
}
|
||||||
<snack-bar ref={linkRef(this, 'snackbar')} />
|
<snack-bar ref={linkRef(this, 'snackbar')} />
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ 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,7 +43,6 @@ $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;
|
||||||
|
|||||||
@@ -160,7 +160,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,
|
||||||
@@ -240,8 +240,6 @@ 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);
|
||||||
@@ -309,8 +307,10 @@ 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.queueUpdateImage(i, {
|
this.updateImage(i, {
|
||||||
skipPreprocessing: !sourceDataChanged && !preprocessorChanged,
|
skipPreprocessing: !sourceDataChanged && !preprocessorChanged,
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,14 +319,9 @@ 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, newSettings),
|
sides: cleanSet(this.state.sides, otherIndex, this.state.sides[index]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await this.props.showSnack('Settings copied across', {
|
const result = await this.props.showSnack('Settings copied across', {
|
||||||
@@ -457,27 +452,6 @@ 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,
|
||||||
@@ -576,9 +550,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 as 0|1)}
|
onEncoderTypeChange={this.onEncoderTypeChange.bind(this, index)}
|
||||||
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index as 0|1)}
|
onEncoderOptionsChange={this.onEncoderOptionsChange.bind(this, index)}
|
||||||
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index as 0|1)}
|
onPreprocessorOptionsChange={this.onPreprocessorOptionsChange.bind(this, index)}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -592,7 +566,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 as 0|1)}
|
onCopyToOtherClick={this.onCopyToOtherClick.bind(this, index)}
|
||||||
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
|
buttonPosition={mobileView ? 'stack-right' : buttonPositions[index]}
|
||||||
>
|
>
|
||||||
{!mobileView ? null : [
|
{!mobileView ? null : [
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -251,11 +251,6 @@ 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