forked from external-repos/squoosh
Compare commits
45 Commits
assemblysc
...
windows-bu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ace858bfe | ||
|
|
0388bde540 | ||
|
|
26fb713560 | ||
|
|
e801170496 | ||
|
|
91e7c9c5ad | ||
|
|
ca5162ed32 | ||
|
|
0bf87d0c87 | ||
|
|
ce91eb5bae | ||
|
|
8d68056bca | ||
|
|
d0de8e444a | ||
|
|
dfef1f21cc | ||
|
|
2440ac4e87 | ||
|
|
e90db78697 | ||
|
|
5ae15d429c | ||
|
|
89d6b46f3e | ||
|
|
e086f64779 | ||
|
|
9ed3b4f11e | ||
|
|
ece3fa12b4 | ||
|
|
9a35224535 | ||
|
|
ef3faa58bc | ||
|
|
b6a8f7eeba | ||
|
|
d1203d9c42 | ||
|
|
a834b6ae38 | ||
|
|
e7982a73ad | ||
|
|
717342c80c | ||
|
|
075f0e62fd | ||
|
|
bcca31fbed | ||
|
|
007891fc11 | ||
|
|
f8e41952d1 | ||
|
|
e4d64f8a79 | ||
|
|
1654f69ec1 | ||
|
|
cb16fb5437 | ||
|
|
36f5fa2c47 | ||
|
|
51ad22e72c | ||
|
|
1a355c0c16 | ||
|
|
fe5ba08963 | ||
|
|
7fc994d4af | ||
|
|
a0a8285e02 | ||
|
|
da2e35f613 | ||
|
|
09bdc25352 | ||
|
|
ad263a9c36 | ||
|
|
c8d8d4e43d | ||
|
|
94249b8a93 | ||
|
|
edd2c51eb6 | ||
|
|
1d24e9399f |
@@ -1,7 +1,4 @@
|
|||||||
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
Normal file
2
codecs/rotate/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
target
|
||||||
|
Cargo.lock
|
||||||
14
codecs/rotate/Cargo.toml
Normal file
14
codecs/rotate/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[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"
|
||||||
17
codecs/rotate/Dockerfile
Normal file
17
codecs/rotate/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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
|
||||||
25
codecs/rotate/build.sh
Executable file
25
codecs/rotate/build.sh
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/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 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
7
codecs/rotate/package.json
Normal file
7
codecs/rotate/package.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "rotate",
|
||||||
|
"scripts": {
|
||||||
|
"build:image": "docker build -t squoosh-rotate .",
|
||||||
|
"build": "docker run --rm -v $(pwd):/src squoosh-rotate ./build.sh"
|
||||||
|
}
|
||||||
|
}
|
||||||
90
codecs/rotate/rotate.rs
Normal file
90
codecs/rotate/rotate.rs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
use std::slice::from_raw_parts_mut;
|
||||||
|
|
||||||
|
// This function is taken from
|
||||||
|
// https://rustwasm.github.io/book/reference/code-size.html
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
#[inline]
|
||||||
|
pub fn unwrap_abort<T>(o: Option<T>) -> T {
|
||||||
|
use std::process;
|
||||||
|
match o {
|
||||||
|
Some(t) => t,
|
||||||
|
None => process::abort(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normal panic-y behavior for debug builds
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
unsafe fn unchecked_unwrap<T>(o: Option<T>) -> T {
|
||||||
|
o.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn rotate(input_width: isize, input_height: isize, rotate: isize) {
|
||||||
|
let mut i = 0isize;
|
||||||
|
|
||||||
|
// In the straight-copy case, d1 is x, d2 is y.
|
||||||
|
// x starts at 0 and increases.
|
||||||
|
// y starts at 0 and increases.
|
||||||
|
let mut d1_start: isize = 0;
|
||||||
|
let mut d1_limit: isize = input_width;
|
||||||
|
let mut d1_advance: isize = 1;
|
||||||
|
let mut d1_multiplier: isize = 1;
|
||||||
|
let mut d2_start: isize = 0;
|
||||||
|
let mut d2_limit: isize = input_height;
|
||||||
|
let mut d2_advance: isize = 1;
|
||||||
|
let mut d2_multiplier: isize = input_width;
|
||||||
|
|
||||||
|
if rotate == 90 {
|
||||||
|
// d1 is y, d2 is x.
|
||||||
|
// y starts at its max value and decreases.
|
||||||
|
// x starts at 0 and increases.
|
||||||
|
d1_start = input_height - 1;
|
||||||
|
d1_limit = input_height;
|
||||||
|
d1_advance = -1;
|
||||||
|
d1_multiplier = input_width;
|
||||||
|
d2_start = 0;
|
||||||
|
d2_limit = input_width;
|
||||||
|
d2_advance = 1;
|
||||||
|
d2_multiplier = 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.
|
||||||
|
d1_start = input_width - 1;
|
||||||
|
d1_limit = input_width;
|
||||||
|
d1_advance = -1;
|
||||||
|
d1_multiplier = 1;
|
||||||
|
d2_start = input_height - 1;
|
||||||
|
d2_limit = input_height;
|
||||||
|
d2_advance = -1;
|
||||||
|
d2_multiplier = input_width;
|
||||||
|
} else if rotate == 270 {
|
||||||
|
// d1 is y, d2 is x.
|
||||||
|
// y starts at 0 and increases.
|
||||||
|
// x starts at its max and decreases.
|
||||||
|
d1_start = 0;
|
||||||
|
d1_limit = input_height;
|
||||||
|
d1_advance = 1;
|
||||||
|
d1_multiplier = input_width;
|
||||||
|
d2_start = input_width - 1;
|
||||||
|
d2_limit = input_width;
|
||||||
|
d2_advance = -1;
|
||||||
|
d2_multiplier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let num_pixels = (input_width * input_height) as usize;
|
||||||
|
let in_b: &mut [u32];
|
||||||
|
let out_b: &mut [u32];
|
||||||
|
unsafe {
|
||||||
|
in_b = from_raw_parts_mut::<u32>(4 as *mut u32, num_pixels);
|
||||||
|
out_b = from_raw_parts_mut::<u32>((input_width * input_height * 4 + 4) as *mut u32, num_pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
for d2 in 0..d2_limit {
|
||||||
|
for d1 in 0..d1_limit {
|
||||||
|
let in_idx = (d1_start + d1 * d1_advance) * d1_multiplier + (d2_start + d2 * d2_advance) * d2_multiplier;
|
||||||
|
*unwrap_abort(out_b.get_mut(i as usize)) = *unwrap_abort(in_b.get(in_idx as usize));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
codecs/rotate/rotate.wasm
Executable file
BIN
codecs/rotate/rotate.wasm
Executable file
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: v0.6.1
|
- Version: v1.0.2
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,33 @@ export OPTIMIZE="-Os"
|
|||||||
export LDFLAGS="${OPTIMIZE}"
|
export LDFLAGS="${OPTIMIZE}"
|
||||||
export CFLAGS="${OPTIMIZE}"
|
export CFLAGS="${OPTIMIZE}"
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool libpng-dev pkg-config
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libwebp"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_LIBWEBP" || (
|
||||||
|
cd node_modules/libwebp
|
||||||
|
autoreconf -fiv
|
||||||
|
rm -rf build || true
|
||||||
|
mkdir -p build && cd build
|
||||||
|
emconfigure ../configure \
|
||||||
|
--disable-libwebpdemux \
|
||||||
|
--disable-wic \
|
||||||
|
--disable-gif \
|
||||||
|
--disable-tiff \
|
||||||
|
--disable-jpeg \
|
||||||
|
--disable-png \
|
||||||
|
--disable-sdl \
|
||||||
|
--disable-gl \
|
||||||
|
--disable-threading \
|
||||||
|
--disable-neon-rtcd \
|
||||||
|
--disable-neon \
|
||||||
|
--disable-sse2 \
|
||||||
|
--disable-sse4.1
|
||||||
|
emmake make
|
||||||
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings"
|
echo "Compiling wasm bindings"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
@@ -20,9 +46,9 @@ echo "============================================="
|
|||||||
--std=c++11 \
|
--std=c++11 \
|
||||||
-I node_modules/libwebp \
|
-I node_modules/libwebp \
|
||||||
-o ./webp_dec.js \
|
-o ./webp_dec.js \
|
||||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
|
||||||
-x c++ \
|
-x c++ \
|
||||||
webp_dec.cpp
|
webp_dec.cpp \
|
||||||
|
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings done"
|
echo "Compiling wasm bindings done"
|
||||||
|
|||||||
@@ -5,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.0"
|
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "3.0.0"
|
"napa": "3.0.0"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
# WebP encoder
|
# WebP encoder
|
||||||
|
|
||||||
- Source: <https://github.com/webmproject/libwebp>
|
- Source: <https://github.com/webmproject/libwebp>
|
||||||
- Version: v0.6.1
|
- Version: v1.0.2
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,33 @@ export LDFLAGS="${OPTIMIZE}"
|
|||||||
export CFLAGS="${OPTIMIZE}"
|
export CFLAGS="${OPTIMIZE}"
|
||||||
export CPPFLAGS="${OPTIMIZE}"
|
export CPPFLAGS="${OPTIMIZE}"
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -qqy autoconf libtool libpng-dev pkg-config
|
||||||
|
|
||||||
|
echo "============================================="
|
||||||
|
echo "Compiling libwebp"
|
||||||
|
echo "============================================="
|
||||||
|
test -n "$SKIP_LIBWEBP" || (
|
||||||
|
cd node_modules/libwebp
|
||||||
|
autoreconf -fiv
|
||||||
|
rm -rf build || true
|
||||||
|
mkdir -p build && cd build
|
||||||
|
emconfigure ../configure \
|
||||||
|
--disable-libwebpdemux \
|
||||||
|
--disable-wic \
|
||||||
|
--disable-gif \
|
||||||
|
--disable-tiff \
|
||||||
|
--disable-jpeg \
|
||||||
|
--disable-png \
|
||||||
|
--disable-sdl \
|
||||||
|
--disable-gl \
|
||||||
|
--disable-threading \
|
||||||
|
--disable-neon-rtcd \
|
||||||
|
--disable-neon \
|
||||||
|
--disable-sse2 \
|
||||||
|
--disable-sse4.1
|
||||||
|
emmake make
|
||||||
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings"
|
echo "Compiling wasm bindings"
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
@@ -20,9 +47,9 @@ echo "============================================="
|
|||||||
--std=c++11 \
|
--std=c++11 \
|
||||||
-I node_modules/libwebp \
|
-I node_modules/libwebp \
|
||||||
-o ./webp_enc.js \
|
-o ./webp_enc.js \
|
||||||
node_modules/libwebp/src/{dec,dsp,demux,enc,mux,utils}/*.c \
|
|
||||||
-x c++ \
|
-x c++ \
|
||||||
webp_enc.cpp
|
webp_enc.cpp \
|
||||||
|
node_modules/libwebp/build/src/.libs/libwebp.a
|
||||||
)
|
)
|
||||||
echo "============================================="
|
echo "============================================="
|
||||||
echo "Compiling wasm bindings done"
|
echo "Compiling wasm bindings done"
|
||||||
|
|||||||
@@ -5,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.0"
|
"libwebp": "webmproject/libwebp#v1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"napa": "3.0.0"
|
"napa": "3.0.0"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
204
config/size-report.js
Normal file
204
config/size-report.js
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
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();
|
||||||
1224
package-lock.json
generated
1224
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.3.1",
|
"version": "1.3.3",
|
||||||
"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": {
|
||||||
@@ -15,13 +16,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "10.12.18",
|
"@types/node": "10.12.26",
|
||||||
"@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.0.4",
|
"chokidar": "2.1.1",
|
||||||
|
"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",
|
||||||
@@ -29,29 +31,33 @@
|
|||||||
"critters-webpack-plugin": "2.2.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.0",
|
"loader-utils": "1.2.3",
|
||||||
"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.0",
|
"progress-bar-webpack-plugin": "1.12.1",
|
||||||
"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.1",
|
"terser-webpack-plugin": "1.2.2",
|
||||||
"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",
|
||||||
@@ -61,8 +67,8 @@
|
|||||||
"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.3",
|
"webpack-bundle-analyzer": "3.0.4",
|
||||||
"webpack-cli": "3.2.1",
|
"webpack-cli": "3.2.3",
|
||||||
"webpack-dev-server": "3.1.14",
|
"webpack-dev-server": "3.1.14",
|
||||||
"worker-plugin": "3.0.0"
|
"worker-plugin": "3.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,10 @@ 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,73 +1,33 @@
|
|||||||
import { RotateOptions } from './processor-meta';
|
import wasmUrl from '../../../codecs/rotate/rotate.wasm';
|
||||||
|
import { RotateOptions, RotateModuleInstance } from './processor-meta';
|
||||||
|
|
||||||
export function rotate(data: ImageData, opts: RotateOptions): ImageData {
|
const instancePromise = (WebAssembly as any).instantiateStreaming(fetch(wasmUrl));
|
||||||
const { rotate } = opts;
|
|
||||||
const flipDimensions = rotate % 180 !== 0;
|
|
||||||
const { width: inputWidth, height: inputHeight } = data;
|
|
||||||
const outputWidth = flipDimensions ? inputHeight : inputWidth;
|
|
||||||
const outputHeight = flipDimensions ? inputWidth : inputHeight;
|
|
||||||
const out = new ImageData(outputWidth, outputHeight);
|
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
// In the straight-copy case, d1 is x, d2 is y.
|
export async function rotate(
|
||||||
// x starts at 0 and increases.
|
data: ImageData,
|
||||||
// y starts at 0 and increases.
|
opts: RotateOptions,
|
||||||
let d1Start = 0;
|
): Promise<ImageData> {
|
||||||
let d1Limit = inputWidth;
|
const { instance } = (await instancePromise) as {instance: RotateModuleInstance};
|
||||||
let d1Advance = 1;
|
|
||||||
let d1Multiplier = 1;
|
|
||||||
let d2Start = 0;
|
|
||||||
let d2Limit = inputHeight;
|
|
||||||
let d2Advance = 1;
|
|
||||||
let d2Multiplier = inputWidth;
|
|
||||||
|
|
||||||
if (rotate === 90) {
|
// Number of wasm memory pages (á 64KiB) needed to store the image twice.
|
||||||
// d1 is y, d2 is x.
|
const bytesPerImage = data.width * data.height * 4;
|
||||||
// y starts at its max value and decreases.
|
const numPagesNeeded = Math.ceil((bytesPerImage * 2 + 4) / (64 * 1024));
|
||||||
// x starts at 0 and increases.
|
// Only count full pages, just to be safe.
|
||||||
d1Start = inputHeight - 1;
|
const numPagesAvailable = Math.floor(instance.exports.memory.buffer.byteLength / (64 * 1024));
|
||||||
d1Limit = inputHeight;
|
const additionalPagesToAllocate = numPagesNeeded - numPagesAvailable;
|
||||||
d1Advance = -1;
|
|
||||||
d1Multiplier = inputWidth;
|
if (additionalPagesToAllocate > 0) {
|
||||||
d2Start = 0;
|
instance.exports.memory.grow(additionalPagesToAllocate);
|
||||||
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, 4);
|
||||||
|
|
||||||
const inB = new Uint32Array(data.data.buffer);
|
instance.exports.rotate(data.width, data.height, opts.rotate);
|
||||||
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) {
|
|
||||||
const start = ((d1 * d1Multiplier) + (d2 * d2Multiplier));
|
|
||||||
outB[i] = inB[start];
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
const flipDimensions = opts.rotate % 180 !== 0;
|
||||||
|
return new ImageData(
|
||||||
|
view.slice(bytesPerImage + 4, bytesPerImage * 2 + 4),
|
||||||
|
flipDimensions ? data.height : data.width,
|
||||||
|
flipDimensions ? data.width : data.height,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
// Reorder so headings appear after content:
|
// Reorder so headings appear after content:
|
||||||
& > :nth-child(1) {
|
& > :nth-child(1) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ const CrittersPlugin = require('critters-webpack-plugin');
|
|||||||
const AssetTemplatePlugin = require('./config/asset-template-plugin');
|
const AssetTemplatePlugin = require('./config/asset-template-plugin');
|
||||||
const addCssTypes = require('./config/add-css-types');
|
const addCssTypes = require('./config/add-css-types');
|
||||||
|
|
||||||
|
const regexpPathSep = path.sep === '\\' ? '\\\\' : '/';
|
||||||
|
|
||||||
function readJson (filename) {
|
function readJson (filename) {
|
||||||
return JSON.parse(fs.readFileSync(filename));
|
return JSON.parse(fs.readFileSync(filename));
|
||||||
}
|
}
|
||||||
@@ -38,7 +40,7 @@ module.exports = async function (_, env) {
|
|||||||
return {
|
return {
|
||||||
mode: isProd ? 'production' : 'development',
|
mode: isProd ? 'production' : 'development',
|
||||||
entry: {
|
entry: {
|
||||||
'first-interaction': './src/index'
|
'first-interaction': path.join('.', 'src', 'index'),
|
||||||
},
|
},
|
||||||
devtool: isProd ? 'source-map' : 'inline-source-map',
|
devtool: isProd ? 'source-map' : 'inline-source-map',
|
||||||
stats: 'minimal',
|
stats: 'minimal',
|
||||||
@@ -52,13 +54,13 @@ module.exports = async function (_, env) {
|
|||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.tsx', '.mjs', '.js', '.scss', '.css'],
|
extensions: ['.ts', '.tsx', '.mjs', '.js', '.scss', '.css'],
|
||||||
alias: {
|
alias: {
|
||||||
style: path.join(__dirname, 'src/style')
|
style: path.join(__dirname, 'src', 'style')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolveLoader: {
|
resolveLoader: {
|
||||||
alias: {
|
alias: {
|
||||||
// async-component-loader returns a wrapper component that waits for the import to load before rendering:
|
// async-component-loader returns a wrapper component that waits for the import to load before rendering:
|
||||||
async: path.join(__dirname, 'config/async-component-loader')
|
async: path.join(__dirname, 'config', 'async-component-loader')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
@@ -147,11 +149,11 @@ module.exports = async function (_, env) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`.
|
// All the codec files define a global with the same name as their file name. `exports-loader` attaches those to `module.exports`.
|
||||||
test: /\/codecs\/.*\.js$/,
|
test: new RegExp(`${regexpPathSep}codecs${regexpPathSep}.*\.js`),
|
||||||
loader: 'exports-loader'
|
loader: 'exports-loader'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\/codecs\/.*\.wasm$/,
|
test: new RegExp(`${regexpPathSep}codecs${regexpPathSep}.*\.wasm`),
|
||||||
// This is needed to make webpack NOT process wasm files.
|
// This is needed to make webpack NOT process wasm files.
|
||||||
// See https://github.com/webpack/webpack/issues/6725
|
// See https://github.com/webpack/webpack/issues/6725
|
||||||
type: 'javascript/auto',
|
type: 'javascript/auto',
|
||||||
@@ -172,7 +174,7 @@ module.exports = async function (_, env) {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new webpack.IgnorePlugin(
|
new webpack.IgnorePlugin(
|
||||||
/(fs|crypto|path)/,
|
/(fs|crypto|path)/,
|
||||||
new RegExp(`${path.sep}codecs${path.sep}`)
|
new RegExp(`${regexpPathSep}codecs${regexpPathSep}`)
|
||||||
),
|
),
|
||||||
|
|
||||||
// Pretty progressbar showing build progress:
|
// Pretty progressbar showing build progress:
|
||||||
|
|||||||
Reference in New Issue
Block a user