Compare commits

..

31 Commits

Author SHA1 Message Date
Jason Miller
ce3d94297d Close Options flyout when clicking an item 2020-12-10 23:44:48 -05:00
Jason Miller
76ef6294f3 Fix merge issue 2020-12-10 23:37:55 -05:00
Jason Miller
50bc8e4106 Merge branch 'preprocessor-transformations-rebased' into cli-invoc-2 2020-12-10 23:34:10 -05:00
Jason Miller
1b8f051438 Merge branch 'dev' of github.com:GoogleChromeLabs/squoosh into preprocessor-transformations-rebased 2020-12-10 23:32:15 -05:00
Jason Miller
cf894b7d19 fix 2020-12-10 12:34:50 -05:00
Jason Miller
d1d181fccd Merge upstream 2020-12-10 10:24:56 -05:00
Jason Miller
a65bbdf811 Hoist flyouts to <body> 2020-12-09 23:47:43 -05:00
Jason Miller
7de8fa9da3 Initial Options Flyout 2020-12-09 18:11:44 -05:00
Jason Miller
646747b039 Merge branch 'preprocessor-transformations-rebased' into cli-invoc-2 2020-12-09 12:21:24 -05:00
Jason Miller
a2fb7a38cd Fix mobile fly-out 2020-12-09 12:20:55 -05:00
Jason Miller
81890e972b Remove development image load 2020-12-09 12:14:11 -05:00
Jason Miller
c2aa35aa02 Hide options on mobile 2020-12-09 12:12:32 -05:00
Jason Miller
c6d936cd49 Fix cropbox UI in Firefox 2020-12-09 11:58:27 -05:00
Jason Miller
60b79da936 Keep resize enabled when cropping 2020-12-09 11:58:10 -05:00
Jason Miller
dbd80f15eb Fix cropbox background when zoomed 2020-12-09 11:49:03 -05:00
Jason Miller
ed3c79894d Remove "Retina" zoom preset 2020-12-09 11:48:28 -05:00
Jason Miller
213028cfdd Changing crop updates and disables resize processor 2020-12-09 11:48:10 -05:00
Jason Miller
952aea049d Merge branch 'cli-invoc' of github.com:GoogleChromeLabs/squoosh into cli-invoc-2 2020-12-09 11:28:24 -05:00
Jason Miller
e3b053db12 Fix crop preprocessor 2020-12-09 11:22:43 -05:00
Jason Miller
b8574b228a fix ordering of preprocessors 2020-12-09 11:22:33 -05:00
Jason Miller
ee8ea539e7 fix crop aspect and presets 2020-12-09 11:22:22 -05:00
Jake Archibald
a7a991ae45 Removing redundant imports, restoring auto-load 2020-12-09 12:38:32 +00:00
Jason Miller
32232c7f0b Add yet another gray 2020-12-09 12:33:59 +00:00
Jason Miller
bb78632cf5 Preact TS tweak 2020-12-09 12:33:59 +00:00
Jason Miller
68cd15bd14 crop and flip preprocessor 2020-12-09 12:33:59 +00:00
Jason Miller
bde3a93b6e Add Transform modal 2020-12-09 12:33:57 +00:00
Jason Miller
7aeef5ff37 Add Flyout, hoist altBackground to Compress 2020-12-09 12:29:59 +00:00
Jason Miller
0ee234f03b Preact 10.5.7 2020-12-09 12:29:06 +00:00
Surma
8105633ca6 Update src/client/lazy-app/util/cli-invocation-generator.ts 2020-12-07 11:17:38 +00:00
Surma
46764f3375 Show snack on error 2020-12-01 13:14:35 +00:00
Surma
0371cfd292 Add CLI button 2020-12-01 13:12:28 +00:00
121 changed files with 10151 additions and 19344 deletions

View File

@@ -30,7 +30,7 @@ npm run build
You can run the development server with:
```sh
npm run dev
npm start
```
[squoosh]: https://squoosh.app

View File

@@ -33,7 +33,6 @@ Options:
--resize [config] Resize the image before compressing
--quant [config] Reduce the number of colors used (aka. paletting)
--rotate [config] Rotate image
--mozjpeg [config] Use MozJPEG to generate a .jpg file with the given configuration
--webp [config] Use WebP to generate a .webp file with the given configuration
--avif [config] Use AVIF to generate a .avif file with the given configuration
--jxl [config] Use JPEG-XL to generate a .jxl file with the given configuration

View File

@@ -183,36 +183,31 @@ function progressTracker(results) {
return tracker;
}
async function getInputFiles(paths) {
async function checkInputFilesValid(files) {
const validFiles = [];
for (const path of paths) {
const files = (await fsp.lstat(path)).isDirectory()
? (await fsp.readdir(path)).map(file => join(path, file))
: [path];
for (const file of files) {
try {
await fsp.stat(file);
} catch (err) {
if (err.code === 'ENOENT') {
console.warn(
`Warning: Input file does not exist: ${resolvePath(file)}`,
);
continue;
} else {
throw err;
}
for (const file of files) {
try {
await fsp.stat(file);
} catch (err) {
if (err.code === 'ENOENT') {
console.warn(
`Warning: Input file does not exist: ${resolvePath(file)}`,
);
continue;
} else {
throw err;
}
validFiles.push(file);
}
validFiles.push(file);
}
return validFiles;
}
async function processFiles(files) {
files = await getInputFiles(files);
files = await checkInputFilesValid(files);
const parallelism = cpus().length;

View File

@@ -24,7 +24,7 @@ function jobPromise(worker, msg) {
export default class WorkerPool {
constructor(numWorkers, workerFile) {
this.numWorkers = numWorkers;
this.closing = false;
this.jobQueue = new TransformStream();
this.workerQueue = new TransformStream();
@@ -42,6 +42,7 @@ export default class WorkerPool {
while (true) {
const { value, done } = await reader.read();
if (done) {
this.workerQueue.writable.close();
await this._terminateAll();
return;
}
@@ -49,6 +50,12 @@ export default class WorkerPool {
const worker = await this._nextWorker();
jobPromise(worker, msg).then((result) => {
resolve(result);
// If we are in the process of closing, `workerQueue` is
// already closed and we cant requeue the worker.
if (this.closing) {
worker.terminate();
return;
}
const writer = this.workerQueue.writable.getWriter();
writer.write(worker);
writer.releaseLock();
@@ -64,15 +71,18 @@ export default class WorkerPool {
}
async _terminateAll() {
for (let n = 0; n < this.numWorkers; n++) {
while (true) {
const worker = await this._nextWorker();
if (!worker) {
return;
}
worker.terminate();
}
this.workerQueue.writable.close();
}
async join() {
this.jobQueue.writable.getWriter().close();
this.closing = true;
this.jobQueue.writable.close();
await this.done;
}

View File

@@ -1,7 +1,7 @@
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/v0.9.0.tar.gz
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/31d7c6d1e32cf467ac24fb8c7a76c4902a4c00db.tar.gz
CODEC_PACKAGE = node_modules/libavif.tar.gz
LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v2.0.2.tar.gz
LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v2.0.0.tar.gz
LIBAOM_PACKAGE = node_modules/libaom.tar.gz
export CODEC_DIR = node_modules/libavif
@@ -21,15 +21,11 @@ ENVIRONMENT = worker
HELPER_MAKEFLAGS := -f helper.Makefile
export CFLAGS+=-g
export CXXFLAGS+=-g
export LDFLAGS+=-g
.PHONY: all clean
all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS) $(OUT_NODE_ENC_JS) $(OUT_NODE_DEC_JS)
$(OUT_NODE_ENC_JS): ENVIRONMENT=node
$(OUT_NODE_ENC_JS): ENVIRONMENT=node
$(OUT_NODE_ENC_JS) $(OUT_ENC_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \

File diff suppressed because it is too large Load Diff

BIN
codecs/avif/dec/avif_dec.wasm Executable file → Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
codecs/avif/enc/avif_enc.wasm Executable file → Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
codecs/avif/enc/avif_enc_mt.wasm Executable file → Normal file

Binary file not shown.

View File

@@ -1,169 +1,103 @@
/**
* @license
* Copyright 2015 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
// Pthread Web Worker startup routine:
// This is the entry point file that is loaded first by each Web Worker
// that executes pthreads on the Emscripten application.
// Thread-local:
var threadInfoStruct = 0; // Info area for this thread in Emscripten HEAP (shared). If zero, this worker is not currently hosting an executing pthread.
var selfThreadId = 0; // The ID of this thread. 0 if not hosting a pthread.
var parentThreadId = 0; // The ID of the parent pthread that launched this thread.
var initializedJS = false; // Guard variable for one-time init of the JS state (currently only embind types registration)
var threadInfoStruct = 0;
var selfThreadId = 0;
var parentThreadId = 0;
var initializedJS = false;
var Module = {};
function assert(condition, text) {
if (!condition) abort('Assertion failed: ' + text);
}
function threadPrintErr() {
var text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
}
function threadAlert() {
var text = Array.prototype.slice.call(arguments).join(' ');
postMessage({cmd: 'alert', text: text, threadId: selfThreadId});
}
// We don't need out() for now, but may need to add it if we want to use it
// here. Or, if this code all moves into the main JS, that problem will go
// away. (For now, adding it here increases code size for no benefit.)
var out = function() {
throw 'out() is not defined in worker.js.';
postMessage({ cmd: 'alert', text: text, threadId: selfThreadId });
}
var err = threadPrintErr;
this.alert = threadAlert;
Module['instantiateWasm'] = function(info, receiveInstance) {
// Instantiate from the module posted from the main thread.
// We can just use sync instantiation in the worker.
Module['instantiateWasm'] = function (info, receiveInstance) {
var instance = new WebAssembly.Instance(Module['wasmModule'], info);
// We don't need the module anymore; new threads will be spawned from the main thread.
Module['wasmModule'] = null;
receiveInstance(instance); // The second 'module' parameter is intentionally null here, we don't need to keep a ref to the Module object from here.
receiveInstance(instance);
return instance.exports;
};
this.onmessage = function(e) {
this.onmessage = function (e) {
try {
if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
// Module and memory were sent from main thread
if (e.data.cmd === 'load') {
Module['wasmModule'] = e.data.wasmModule;
Module['wasmMemory'] = e.data.wasmMemory;
Module['buffer'] = Module['wasmMemory'].buffer;
Module['ENVIRONMENT_IS_PTHREAD'] = true;
import(e.data.urlOrBlob).then(function(avif_enc_mt) {
return avif_enc_mt.default(Module);
}).then(function(instance) {
Module = instance;
postMessage({ 'cmd': 'loaded' });
});
import(e.data.urlOrBlob)
.then(function (avif_enc_mt) {
return avif_enc_mt.default(Module);
})
.then(function (instance) {
Module = instance;
postMessage({ cmd: 'loaded' });
});
} else if (e.data.cmd === 'objectTransfer') {
Module['PThread'].receiveObjectTransfer(e.data);
} else if (e.data.cmd === 'run') {
// This worker was idle, and now should start executing its pthread entry
// point.
// performance.now() is specced to return a wallclock time in msecs since
// that Web Worker/main thread launched. However for pthreads this can
// cause subtle problems in emscripten_get_now() as this essentially
// would measure time from pthread_create(), meaning that the clocks
// between each threads would be wildly out of sync. Therefore sync all
// pthreads to the clock on the main browser thread, so that different
// threads see a somewhat coherent clock across each of them
// (+/- 0.1msecs in testing).
Module['__performance_now_clock_drift'] = performance.now() - e.data.time;
threadInfoStruct = e.data.threadInfoStruct;
// Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
Module['registerPthreadPtr'](threadInfoStruct, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0);
Module['registerPthreadPtr'](
threadInfoStruct,
/*isMainBrowserThread=*/ 0,
/*isMainRuntimeThread=*/ 0,
);
selfThreadId = e.data.selfThreadId;
parentThreadId = e.data.parentThreadId;
// Establish the stack frame for this thread in global scope
// The stack grows downwards
var max = e.data.stackBase;
var top = e.data.stackBase + e.data.stackSize;
assert(threadInfoStruct);
assert(selfThreadId);
assert(parentThreadId);
assert(top != 0);
assert(max != 0);
assert(top > max);
// Also call inside JS module to set up the stack frame for this pthread in JS module scope
Module['establishStackSpace'](top, max);
Module['_emscripten_tls_init']();
Module['writeStackCookie']();
Module['PThread'].receiveObjectTransfer(e.data);
Module['PThread'].setThreadStatus(Module['_pthread_self'](), 1/*EM_THREAD_STATUS_RUNNING*/);
// Embind must initialize itself on all threads, as it generates support JS.
// We only do this once per worker since they get reused
Module['PThread'].setThreadStatus(Module['_pthread_self'](), 1);
if (!initializedJS) {
Module['___embind_register_native_and_builtin_types']();
initializedJS = true;
}
try {
// pthread entry points are always of signature 'void *ThreadMain(void *arg)'
// Native codebases sometimes spawn threads with other thread entry point signatures,
// such as void ThreadMain(void *arg), void *ThreadMain(), or void ThreadMain().
// That is not acceptable per C/C++ specification, but x86 compiler ABI extensions
// enable that to work. If you find the following line to crash, either change the signature
// to "proper" void *ThreadMain(void *arg) form, or try linking with the Emscripten linker
// flag -s EMULATE_FUNCTION_POINTER_CASTS=1 to add in emulation for this x86 ABI extension.
var result = Module['dynCall']('ii', e.data.start_routine, [e.data.arg]);
Module['checkStackCookie']();
// The thread might have finished without calling pthread_exit(). If so, then perform the exit operation ourselves.
// (This is a no-op if explicit pthread_exit() had been called prior.)
if (!Module['getNoExitRuntime']())
Module['PThread'].threadExit(result);
} catch(ex) {
var result = Module['dynCall']('ii', e.data.start_routine, [
e.data.arg,
]);
if (!Module['getNoExitRuntime']()) Module['PThread'].threadExit(result);
} catch (ex) {
if (ex === 'Canceled!') {
Module['PThread'].threadCancel();
} else if (ex != 'unwind') {
Atomics.store(Module['HEAPU32'], (threadInfoStruct + 4 /*C_STRUCTS.pthread.threadExitCode*/ ) >> 2, (ex instanceof Module['ExitStatus']) ? ex.status : -2 /*A custom entry specific to Emscripten denoting that the thread crashed.*/);
Atomics.store(Module['HEAPU32'], (threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/ ) >> 2, 1); // Mark the thread as no longer running.
if (typeof(Module['_emscripten_futex_wake']) !== "function") {
err("Thread Initialisation failed.");
throw ex;
}
Module['_emscripten_futex_wake'](threadInfoStruct + 0 /*C_STRUCTS.pthread.threadStatus*/, 0x7FFFFFFF/*INT_MAX*/); // Wake all threads waiting on this thread to finish.
Atomics.store(
Module['HEAPU32'],
(threadInfoStruct + 4) >> /*C_STRUCTS.pthread.threadExitCode*/ 2,
ex instanceof Module['ExitStatus'] ? ex.status : -2,
);
/*A custom entry specific to Emscripten denoting that the thread crashed.*/ Atomics.store(
Module['HEAPU32'],
(threadInfoStruct + 0) >> /*C_STRUCTS.pthread.threadStatus*/ 2,
1,
);
Module['_emscripten_futex_wake'](
threadInfoStruct + 0,
/*C_STRUCTS.pthread.threadStatus*/ 2147483647,
);
if (!(ex instanceof Module['ExitStatus'])) throw ex;
} else {
// else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
err('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
}
}
} else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
} else if (e.data.cmd === 'cancel') {
if (threadInfoStruct) {
Module['PThread'].threadCancel();
}
} else if (e.data.target === 'setimmediate') {
// no-op
} else if (e.data.cmd === 'processThreadQueue') {
if (threadInfoStruct) { // If this thread is actually running?
if (threadInfoStruct) {
Module['_emscripten_current_thread_process_queued_calls']();
}
} else {
err('worker.js received unknown command ' + e.data.cmd);
err(e.data);
}
} catch(ex) {
} catch (ex) {
err('worker.js onmessage() captured an uncaught exception: ' + ex);
if (ex && ex.stack) err(ex.stack);
throw ex;
}
};

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -32,6 +32,7 @@ $(OUT_JS): $(OUT_CPP) $(LIBAOM_OUT) $(CODEC_OUT)
$(LDFLAGS) \
$(OUT_FLAGS) \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s TEXTDECODER=2 \
@@ -43,7 +44,7 @@ $(OUT_JS): $(OUT_CPP) $(LIBAOM_OUT) $(CODEC_OUT)
$(CODEC_OUT): $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_OUT)
emcmake cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=0 \
-DAVIF_CODEC_AOM=1 \
-DAOM_LIBRARY=$(LIBAOM_OUT) \
@@ -55,7 +56,7 @@ $(CODEC_OUT): $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_OUT)
$(LIBAOM_OUT): $(LIBAOM_DIR)/CMakeLists.txt
emcmake cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_CCACHE=0 \
-DAOM_TARGET_CPU=generic \
-DENABLE_DOCS=0 \

View File

@@ -1,6 +1,6 @@
FROM emscripten/emsdk:2.0.8
RUN apt-get update && apt-get install -qqy autoconf libtool pkg-config
ENV CFLAGS "-O3 -flto -s FILESYSTEM=0"
ENV CFLAGS "-O3 -flto"
ENV CXXFLAGS "${CFLAGS} -std=c++17"
ENV LDFLAGS "${CFLAGS} -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency"
# Build and cache standard libraries with these flags

177
codecs/hqx/Cargo.lock generated
View File

@@ -4,283 +4,286 @@
name = "bumpalo"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "console_error_panic_hook"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
dependencies = [
"cfg-if",
"wasm-bindgen",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "futures"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
[[package]]
name = "hqx"
version = "0.1.0"
source = "git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.3#d7cbae67906796928c8e451b186f3c653924beb8"
source = "git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2#5f19cda24191ccc7c0c4920b6b246b4e242f377c"
dependencies = [
"lazy_static",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "js-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memory_units"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
dependencies = [
"unicode-xid 0.2.1",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2 1.0.19",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]]
name = "squooshhqx"
version = "0.1.0"
dependencies = [
"cfg-if",
"console_error_panic_hook",
"hqx",
"wasm-bindgen",
"wasm-bindgen-test",
"wee_alloc",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hqx 0.1.0 (git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2)",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
"wee_alloc 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0"
dependencies = [
"proc-macro2 1.0.19",
"quote 1.0.7",
"unicode-xid 0.2.1",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasm-bindgen"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2 1.0.19",
"quote 1.0.7",
"syn",
"wasm-bindgen-shared",
"bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
dependencies = [
"cfg-if",
"futures",
"js-sys",
"wasm-bindgen",
"web-sys",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"web-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
dependencies = [
"quote 1.0.7",
"wasm-bindgen-macro-support",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
dependencies = [
"proc-macro2 1.0.19",
"quote 1.0.7",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
"proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
[[package]]
name = "wasm-bindgen-test"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
dependencies = [
"console_error_panic_hook",
"futures",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
"console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "web-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
dependencies = [
"js-sys",
"wasm-bindgen",
"js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wee_alloc"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"cfg-if",
"libc",
"memory_units",
"winapi",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)",
"memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[metadata]
"checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
"checksum hqx 0.1.0 (git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.2)" = "<none>"
"checksum js-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.73 (registry+https://github.com/rust-lang/crates.io-index)" = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9"
"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum proc-macro2 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
"checksum scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
"checksum syn 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
"checksum wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d"
"checksum wasm-bindgen-backend 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d"
"checksum wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
"checksum wasm-bindgen-macro 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e"
"checksum wasm-bindgen-macro-support 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6"
"checksum wasm-bindgen-shared 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87"
"checksum wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
"checksum wasm-bindgen-test-macro 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
"checksum web-sys 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
"checksum wee_alloc 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -13,7 +13,7 @@ default = ["console_error_panic_hook", "wee_alloc"]
cfg-if = "0.1.2"
wasm-bindgen = "0.2.38"
# lazy_static = "1.0.0"
hqx = {git = "https://github.com/CryZe/wasmboy-rs", tag="v0.1.3"}
hqx = {git = "https://github.com/CryZe/wasmboy-rs", tag="v0.1.2"}
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires

View File

@@ -1,6 +1,6 @@
{
"name": "hqx",
"scripts": {
"build": "../build-rust.sh"
"build": "RUST_IMG=rust:1.40 ../build-rust.sh"
}
}

54
codecs/hqx/pkg/squooshhqx.d.ts generated vendored
View File

@@ -1,30 +1,48 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Uint32Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} factor
* @returns {Uint32Array}
*/
export function resize(input_image: Uint32Array, input_width: number, input_height: number, factor: number): Uint32Array;
* @param {Uint32Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} factor
* @returns {Uint32Array}
*/
export function resize(
input_image: Uint32Array,
input_width: number,
input_height: number,
factor: number,
): Uint32Array;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export type InitInput =
| RequestInfo
| URL
| Response
| BufferSource
| WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly resize: (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
) => void;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
}
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init(
module_or_path?: InitInput | Promise<InitInput>,
): Promise<InitOutput>;

View File

@@ -1,108 +1,107 @@
let wasm;
let cachegetUint32Memory0 = null;
function getUint32Memory0() {
if (cachegetUint32Memory0 === null || cachegetUint32Memory0.buffer !== wasm.memory.buffer) {
cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory0;
if (
cachegetUint32Memory0 === null ||
cachegetUint32Memory0.buffer !== wasm.memory.buffer
) {
cachegetUint32Memory0 = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory0;
}
let WASM_VECTOR_LEN = 0;
function passArray32ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 4);
getUint32Memory0().set(arg, ptr / 4);
WASM_VECTOR_LEN = arg.length;
return ptr;
const ptr = malloc(arg.length * 4);
getUint32Memory0().set(arg, ptr / 4);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
if (
cachegetInt32Memory0 === null ||
cachegetInt32Memory0.buffer !== wasm.memory.buffer
) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
function getArrayU32FromWasm0(ptr, len) {
return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
}
/**
* @param {Uint32Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} factor
* @returns {Uint32Array}
*/
* @param {Uint32Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} factor
* @returns {Uint32Array}
*/
export function resize(input_image, input_width, input_height, factor) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
var ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.resize(retptr, ptr0, len0, input_width, input_height, factor);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v1 = getArrayU32FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 4);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
var ptr0 = passArray32ToWasm0(input_image, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.resize(8, ptr0, len0, input_width, input_height, factor);
var r0 = getInt32Memory0()[8 / 4 + 0];
var r1 = getInt32Memory0()[8 / 4 + 1];
var v1 = getArrayU32FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 4);
return v1;
}
async function load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (module.headers.get('Content-Type') != 'application/wasm') {
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
} else {
throw e;
}
}
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (module.headers.get('Content-Type') != 'application/wasm') {
console.warn(
'`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n',
e,
);
} else {
return instance;
throw e;
}
}
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
} else {
return instance;
}
}
}
async function init(input) {
if (typeof input === 'undefined') {
input = new URL('squooshhqx_bg.wasm', import.meta.url);
}
const imports = {};
if (typeof input === 'undefined') {
input = import.meta.url.replace(/\.js$/, '_bg.wasm');
}
const imports = {};
if (
typeof input === 'string' ||
(typeof Request === 'function' && input instanceof Request) ||
(typeof URL === 'function' && input instanceof URL)
) {
input = fetch(input);
}
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
return wasm;
}
export default init;

6
codecs/hqx/pkg/squooshhqx_bg.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function resize(a: number, b: number, c: number, d: number, e: number, f: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_free(a: number, b: number): void;

Binary file not shown.

View File

@@ -8,7 +8,7 @@ ENVIRONMENT = worker
.PHONY: all clean
all: $(OUT_JS)
all: $(OUT_JS) $(OUT_NODE_JS)
imagequant_node.js: ENVIRONMENT=node
$(OUT_JS): $(CODEC_OUT)
@@ -27,6 +27,21 @@ $(OUT_JS): $(CODEC_OUT)
$+ \
imagequant.cpp
$(CXX) \
-I $(CODEC_DIR) \
${CXXFLAGS} \
${LDFLAGS} \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s TEXTDECODER=2 \
-s ENVIRONMENT='node' \
-s EXPORT_ES6=1 \
-o $@ \
$+ \
imagequant.cpp
$(CODEC_OUT): $(CODEC_DIR)/config.mk
$(MAKE) -C $(CODEC_DIR) $(CODEC_OUT_RELATIVE)

Binary file not shown.

View File

@@ -1,5 +1,5 @@
CODEC_URL = https://gitlab.com/wg1/jpeg-xl.git
CODEC_VERSION = 5175d11717f3c48cf506a2c0e0afb070392ae296
CODEC_VERSION = 739e6cd1305fdec5acfa47ad414189b3d3ecb6a4
CODEC_DIR = node_modules/jxl
CODEC_BUILD_ROOT := $(CODEC_DIR)/build
CODEC_MT_BUILD_DIR := $(CODEC_BUILD_ROOT)/mt
@@ -41,6 +41,8 @@ $(OUT_JS):
-I $(CODEC_BUILD_DIR)/lib/include \
-I $(CODEC_DIR)/third_party/highway \
-I $(CODEC_DIR)/third_party/skcms \
-I $(CODEC_DIR)/third_party/brunsli \
-I $(CODEC_DIR)/third_party/brunsli/c/include \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
@@ -51,6 +53,9 @@ $(OUT_JS):
-s EXPORT_NAME="$(basename $(@F))" \
-o $@ \
$+ \
$(CODEC_BUILD_DIR)/artifacts/libbrunslienc-static.bc \
$(CODEC_BUILD_DIR)/artifacts/libbrunslicommon-static.bc \
$(CODEC_BUILD_DIR)/artifacts/libbrunslidec-static.bc \
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlidec-static.a \
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlienc-static.a \
$(CODEC_BUILD_DIR)/third_party/brotli/libbrotlicommon-static.a \

View File

@@ -52,14 +52,13 @@ val decode(std::string data) {
auto next_in = (const uint8_t*)data.c_str();
auto avail_in = data.size();
JxlDecoderSetInput(dec.get(), next_in, avail_in);
EXPECT_EQ(JXL_DEC_BASIC_INFO, JxlDecoderProcessInput(dec.get()));
EXPECT_EQ(JXL_DEC_BASIC_INFO, JxlDecoderProcessInput(dec.get(), &next_in, &avail_in));
JxlBasicInfo info;
EXPECT_EQ(JXL_DEC_SUCCESS, JxlDecoderGetBasicInfo(dec.get(), &info));
size_t pixel_count = info.xsize * info.ysize;
size_t component_count = pixel_count * COMPONENTS_PER_PIXEL;
EXPECT_EQ(JXL_DEC_COLOR_ENCODING, JxlDecoderProcessInput(dec.get()));
EXPECT_EQ(JXL_DEC_COLOR_ENCODING, JxlDecoderProcessInput(dec.get(), &next_in, &avail_in));
static const JxlPixelFormat format = {COMPONENTS_PER_PIXEL, JXL_TYPE_FLOAT, JXL_LITTLE_ENDIAN, 0};
size_t icc_size;
EXPECT_EQ(JXL_DEC_SUCCESS, JxlDecoderGetICCProfileSize(dec.get(), &format,
@@ -69,15 +68,10 @@ val decode(std::string data) {
JxlDecoderGetColorAsICCProfile(dec.get(), &format, JXL_COLOR_PROFILE_TARGET_DATA,
icc_profile.data(), icc_profile.size()));
EXPECT_EQ(JXL_DEC_NEED_IMAGE_OUT_BUFFER, JxlDecoderProcessInput(dec.get()));
size_t buffer_size;
EXPECT_EQ(JXL_DEC_SUCCESS, JxlDecoderImageOutBufferSize(dec.get(), &format, &buffer_size));
EXPECT_EQ(buffer_size, component_count * sizeof(float));
auto float_pixels = std::make_unique<float[]>(component_count);
EXPECT_EQ(JXL_DEC_SUCCESS, JxlDecoderSetImageOutBuffer(dec.get(), &format, float_pixels.get(),
component_count * sizeof(float)));
EXPECT_EQ(JXL_DEC_FULL_IMAGE, JxlDecoderProcessInput(dec.get()));
EXPECT_EQ(JXL_DEC_FULL_IMAGE, JxlDecoderProcessInput(dec.get(), &next_in, &avail_in));
auto byte_pixels = std::make_unique<uint8_t[]>(component_count);
// Convert to sRGB.

Binary file not shown.

Binary file not shown.

View File

@@ -42,6 +42,17 @@ val encode(std::string image, int width, int height, JXLOptions options) {
cparams.options.predictor = jxl::Predictor::Zero;
}
// Reduce memory usage of tree learning for lossless data.
// TODO(veluca93): this is a mitigation for excessive memory usage in the JXL encoder.
float megapixels = width * height * 0.000001;
if (megapixels > 8) {
cparams.options.nb_repeats = 0.1;
} else if (megapixels > 4) {
cparams.options.nb_repeats = 0.3;
} else {
// default is OK.
}
float quality = options.quality;
// Quality settings roughly match libjpeg qualities.
@@ -91,8 +102,8 @@ val encode(std::string image, int width, int height, JXLOptions options) {
auto result = jxl::ConvertImage(
jxl::Span<const uint8_t>(reinterpret_cast<const uint8_t*>(image.data()), image.size()), width,
height, jxl::ColorEncoding::SRGB(/*is_gray=*/false), /*has_alpha=*/true,
/*alpha_is_premultiplied=*/false, /*bits_per_sample=*/8, /*endiannes=*/JXL_LITTLE_ENDIAN,
/*flipped_y=*/false, pool_ptr, main);
/*alpha_is_premultiplied=*/false, /*bits_per_alpha=*/8, /*bits_per_sample=*/8,
/*big_endian=*/false, /*flipped_y=*/false, pool_ptr, main);
if (!result) {
return val::null();

Binary file not shown.

View File

@@ -17,7 +17,7 @@ function Da(a){return 2*a.length}function Ea(a,b){for(var c=0,d="";!(c>=b/4);){v
function Ga(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}function Ha(a,b){e().set(a,b)}var n,aa,ba,ca,fa,ha,ia,ka,ma;function u(a){n=a;D.HEAP8=aa=new Int8Array(a);D.HEAP16=ca=new Int16Array(a);D.HEAP32=ha=new Int32Array(a);D.HEAPU8=ba=new Uint8Array(a);D.HEAPU16=fa=new Uint16Array(a);D.HEAPU32=ia=new Uint32Array(a);D.HEAPF32=ka=new Float32Array(a);D.HEAPF64=ma=new Float64Array(a)}var Ia=D.INITIAL_MEMORY||16777216;
if(G)m=D.wasmMemory,n=D.buffer;else if(D.wasmMemory)m=D.wasmMemory;else if(m=new WebAssembly.Memory({initial:Ia/65536,maximum:32768,shared:!0}),!(m.buffer instanceof SharedArrayBuffer))throw J("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");m&&(n=m.buffer);Ia=n.byteLength;u(n);var M,Ja=[],Ka=[],La=[],Ma=[];
function Na(){var a=D.preRun.shift();Ja.unshift(a)}var N=0,Oa=null,Pa=null;D.preloadedImages={};D.preloadedAudios={};function K(a){if(D.onAbort)D.onAbort(a);G&&console.error("Pthread aborting at "+Error().stack);J(a);va=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");oa(a);throw a;}function Qa(){var a=O;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var O="jxl_enc_mt.wasm";
Qa()||(O=qa(O));function Ra(){try{if(ta)return new Uint8Array(ta);if(ra)return ra(O);throw"both async and sync fetching of the wasm failed";}catch(a){K(a)}}function Sa(){return ta||"function"!==typeof fetch?Promise.resolve().then(Ra):fetch(O,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+O+"'";return a.arrayBuffer()}).catch(function(){return Ra()})}var Ua={60805:function(a,b){setTimeout(function(){Ta(a,b)},0)},60883:function(){throw"Canceled!";}};
Qa()||(O=qa(O));function Ra(){try{if(ta)return new Uint8Array(ta);if(ra)return ra(O);throw"both async and sync fetching of the wasm failed";}catch(a){K(a)}}function Sa(){return ta||"function"!==typeof fetch?Promise.resolve().then(Ra):fetch(O,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+O+"'";return a.arrayBuffer()}).catch(function(){return Ra()})}var Ua={60341:function(a,b){setTimeout(function(){Ta(a,b)},0)},60419:function(){throw"Canceled!";}};
function Va(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(D);else{var c=b.Bb;"number"===typeof c?void 0===b.Va?M.get(c)():M.get(c)(b.Va):c(void 0===b.Va?null:b.Va)}}}function Wa(a,b,c){var d;-1!=a.indexOf("j")?d=c&&c.length?D["dynCall_"+a].apply(null,[b].concat(c)):D["dynCall_"+a].call(null,b):d=M.get(b).apply(null,c);return d}D.dynCall=Wa;var P=0,Xa=0,Ya=0;function Za(a,b,c){P=a|0;Ya=b|0;Xa=c|0}D.registerPthreadPtr=Za;
function $a(a,b){if(0>=a||a>e().length||a&1||0>b)return-28;if(0==b)return 0;2147483647<=b&&(b=Infinity);var c=Atomics.load(A(),Q.rb>>2),d=0;if(c==a&&Atomics.compareExchange(A(),Q.rb>>2,c,0)==c&&(--b,d=1,0>=b))return 1;a=Atomics.notify(A(),a>>2,b);if(0<=a)return a+d;throw"Atomics.notify returned an unexpected value "+a;}D._emscripten_futex_wake=$a;
function ab(a){if(G)throw"Internal Error! cleanupThread() can only ever be called from main application thread!";if(!a)throw"Internal Error! Null pthread_ptr in cleanupThread!";A()[a+12>>2]=0;(a=Q.Oa[a])&&Q.bb(a.worker)}
@@ -98,7 +98,7 @@ D._emscripten_sync_run_in_main_thread_1=function(){return(D._emscripten_sync_run
D._emscripten_sync_run_in_main_thread_3=function(){return(D._emscripten_sync_run_in_main_thread_3=D.asm.va).apply(null,arguments)};var Ec=D._emscripten_sync_run_in_main_thread_4=function(){return(Ec=D._emscripten_sync_run_in_main_thread_4=D.asm.wa).apply(null,arguments)};D._emscripten_sync_run_in_main_thread_5=function(){return(D._emscripten_sync_run_in_main_thread_5=D.asm.xa).apply(null,arguments)};
D._emscripten_sync_run_in_main_thread_6=function(){return(D._emscripten_sync_run_in_main_thread_6=D.asm.ya).apply(null,arguments)};D._emscripten_sync_run_in_main_thread_7=function(){return(D._emscripten_sync_run_in_main_thread_7=D.asm.za).apply(null,arguments)};
var Ub=D._emscripten_run_in_main_runtime_thread_js=function(){return(Ub=D._emscripten_run_in_main_runtime_thread_js=D.asm.Aa).apply(null,arguments)},$b=D.__emscripten_call_on_thread=function(){return($b=D.__emscripten_call_on_thread=D.asm.Ba).apply(null,arguments)};D._emscripten_tls_init=function(){return(D._emscripten_tls_init=D.asm.Ca).apply(null,arguments)};D.dynCall_viijii=function(){return(D.dynCall_viijii=D.asm.Da).apply(null,arguments)};
D.dynCall_iiji=function(){return(D.dynCall_iiji=D.asm.Ea).apply(null,arguments)};D.dynCall_jiji=function(){return(D.dynCall_jiji=D.asm.Fa).apply(null,arguments)};D.dynCall_iiiiiijj=function(){return(D.dynCall_iiiiiijj=D.asm.Ga).apply(null,arguments)};D.dynCall_iiiiij=function(){return(D.dynCall_iiiiij=D.asm.Ha).apply(null,arguments)};D.dynCall_iiiiijj=function(){return(D.dynCall_iiiiijj=D.asm.Ia).apply(null,arguments)};var cb=D._main_thread_futex=4639544;D.PThread=Q;D.PThread=Q;D._pthread_self=pc;
D.dynCall_iiji=function(){return(D.dynCall_iiji=D.asm.Ea).apply(null,arguments)};D.dynCall_jiji=function(){return(D.dynCall_jiji=D.asm.Fa).apply(null,arguments)};D.dynCall_iiiiiijj=function(){return(D.dynCall_iiiiiijj=D.asm.Ga).apply(null,arguments)};D.dynCall_iiiiij=function(){return(D.dynCall_iiiiij=D.asm.Ha).apply(null,arguments)};D.dynCall_iiiiijj=function(){return(D.dynCall_iiiiijj=D.asm.Ia).apply(null,arguments)};var cb=D._main_thread_futex=3060056;D.PThread=Q;D.PThread=Q;D._pthread_self=pc;
D.wasmMemory=m;D.ExitStatus=Hc;var Ic;function Hc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}Pa=function Jc(){Ic||Kc();Ic||(Pa=Jc)};
function Kc(){function a(){if(!Ic&&(Ic=!0,D.calledRun=!0,!va)){Va(Ka);G||Va(La);na(D);if(D.onRuntimeInitialized)D.onRuntimeInitialized();if(!G){if(D.postRun)for("function"==typeof D.postRun&&(D.postRun=[D.postRun]);D.postRun.length;){var b=D.postRun.shift();Ma.unshift(b)}Va(Ma)}}}if(!(0<N)){if(!G){if(D.preRun)for("function"==typeof D.preRun&&(D.preRun=[D.preRun]);D.preRun.length;)Na();Va(Ja)}0<N||(D.setStatus?(D.setStatus("Running..."),setTimeout(function(){setTimeout(function(){D.setStatus("")},
1);a()},1)):a())}}D.run=Kc;if(D.preInit)for("function"==typeof D.preInit&&(D.preInit=[D.preInit]);0<D.preInit.length;)D.preInit.pop()();G||(noExitRuntime=!0);G?Q.Lb():Kc();

Binary file not shown.

View File

@@ -17,7 +17,7 @@ function Da(a){return 2*a.length}function Ea(a,b){for(var c=0,d="";!(c>=b/4);){v
function Ga(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}function Ha(a,b){e().set(a,b)}var n,aa,ba,ca,fa,ha,ia,ka,ma;function u(a){n=a;D.HEAP8=aa=new Int8Array(a);D.HEAP16=ca=new Int16Array(a);D.HEAP32=ha=new Int32Array(a);D.HEAPU8=ba=new Uint8Array(a);D.HEAPU16=fa=new Uint16Array(a);D.HEAPU32=ia=new Uint32Array(a);D.HEAPF32=ka=new Float32Array(a);D.HEAPF64=ma=new Float64Array(a)}var Ia=D.INITIAL_MEMORY||16777216;
if(G)m=D.wasmMemory,n=D.buffer;else if(D.wasmMemory)m=D.wasmMemory;else if(m=new WebAssembly.Memory({initial:Ia/65536,maximum:32768,shared:!0}),!(m.buffer instanceof SharedArrayBuffer))throw J("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");m&&(n=m.buffer);Ia=n.byteLength;u(n);var M,Ja=[],Ka=[],La=[],Ma=[];
function Na(){var a=D.preRun.shift();Ja.unshift(a)}var N=0,Oa=null,Pa=null;D.preloadedImages={};D.preloadedAudios={};function K(a){if(D.onAbort)D.onAbort(a);G&&console.error("Pthread aborting at "+Error().stack);J(a);va=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");oa(a);throw a;}function Qa(){var a=O;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var O="jxl_enc_mt_simd.wasm";
Qa()||(O=qa(O));function Ra(){try{if(ta)return new Uint8Array(ta);if(ra)return ra(O);throw"both async and sync fetching of the wasm failed";}catch(a){K(a)}}function Sa(){return ta||"function"!==typeof fetch?Promise.resolve().then(Ra):fetch(O,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+O+"'";return a.arrayBuffer()}).catch(function(){return Ra()})}var Ua={60933:function(a,b){setTimeout(function(){Ta(a,b)},0)},61011:function(){throw"Canceled!";}};
Qa()||(O=qa(O));function Ra(){try{if(ta)return new Uint8Array(ta);if(ra)return ra(O);throw"both async and sync fetching of the wasm failed";}catch(a){K(a)}}function Sa(){return ta||"function"!==typeof fetch?Promise.resolve().then(Ra):fetch(O,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+O+"'";return a.arrayBuffer()}).catch(function(){return Ra()})}var Ua={60389:function(a,b){setTimeout(function(){Ta(a,b)},0)},60467:function(){throw"Canceled!";}};
function Va(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(D);else{var c=b.Bb;"number"===typeof c?void 0===b.Va?M.get(c)():M.get(c)(b.Va):c(void 0===b.Va?null:b.Va)}}}function Wa(a,b,c){var d;-1!=a.indexOf("j")?d=c&&c.length?D["dynCall_"+a].apply(null,[b].concat(c)):D["dynCall_"+a].call(null,b):d=M.get(b).apply(null,c);return d}D.dynCall=Wa;var P=0,Xa=0,Ya=0;function Za(a,b,c){P=a|0;Ya=b|0;Xa=c|0}D.registerPthreadPtr=Za;
function $a(a,b){if(0>=a||a>e().length||a&1||0>b)return-28;if(0==b)return 0;2147483647<=b&&(b=Infinity);var c=Atomics.load(A(),Q.rb>>2),d=0;if(c==a&&Atomics.compareExchange(A(),Q.rb>>2,c,0)==c&&(--b,d=1,0>=b))return 1;a=Atomics.notify(A(),a>>2,b);if(0<=a)return a+d;throw"Atomics.notify returned an unexpected value "+a;}D._emscripten_futex_wake=$a;
function ab(a){if(G)throw"Internal Error! cleanupThread() can only ever be called from main application thread!";if(!a)throw"Internal Error! Null pthread_ptr in cleanupThread!";A()[a+12>>2]=0;(a=Q.Oa[a])&&Q.bb(a.worker)}
@@ -99,7 +99,7 @@ D._emscripten_sync_run_in_main_thread_1=function(){return(D._emscripten_sync_run
D._emscripten_sync_run_in_main_thread_3=function(){return(D._emscripten_sync_run_in_main_thread_3=D.asm.va).apply(null,arguments)};var Ec=D._emscripten_sync_run_in_main_thread_4=function(){return(Ec=D._emscripten_sync_run_in_main_thread_4=D.asm.wa).apply(null,arguments)};D._emscripten_sync_run_in_main_thread_5=function(){return(D._emscripten_sync_run_in_main_thread_5=D.asm.xa).apply(null,arguments)};
D._emscripten_sync_run_in_main_thread_6=function(){return(D._emscripten_sync_run_in_main_thread_6=D.asm.ya).apply(null,arguments)};D._emscripten_sync_run_in_main_thread_7=function(){return(D._emscripten_sync_run_in_main_thread_7=D.asm.za).apply(null,arguments)};
var Ub=D._emscripten_run_in_main_runtime_thread_js=function(){return(Ub=D._emscripten_run_in_main_runtime_thread_js=D.asm.Aa).apply(null,arguments)},$b=D.__emscripten_call_on_thread=function(){return($b=D.__emscripten_call_on_thread=D.asm.Ba).apply(null,arguments)};D._emscripten_tls_init=function(){return(D._emscripten_tls_init=D.asm.Ca).apply(null,arguments)};D.dynCall_viijii=function(){return(D.dynCall_viijii=D.asm.Da).apply(null,arguments)};
D.dynCall_iiji=function(){return(D.dynCall_iiji=D.asm.Ea).apply(null,arguments)};D.dynCall_jiji=function(){return(D.dynCall_jiji=D.asm.Fa).apply(null,arguments)};D.dynCall_iiiiiijj=function(){return(D.dynCall_iiiiiijj=D.asm.Ga).apply(null,arguments)};D.dynCall_iiiiij=function(){return(D.dynCall_iiiiij=D.asm.Ha).apply(null,arguments)};D.dynCall_iiiiijj=function(){return(D.dynCall_iiiiijj=D.asm.Ia).apply(null,arguments)};var cb=D._main_thread_futex=4639672;D.PThread=Q;D.PThread=Q;D._pthread_self=pc;
D.dynCall_iiji=function(){return(D.dynCall_iiji=D.asm.Ea).apply(null,arguments)};D.dynCall_jiji=function(){return(D.dynCall_jiji=D.asm.Fa).apply(null,arguments)};D.dynCall_iiiiiijj=function(){return(D.dynCall_iiiiiijj=D.asm.Ga).apply(null,arguments)};D.dynCall_iiiiij=function(){return(D.dynCall_iiiiij=D.asm.Ha).apply(null,arguments)};D.dynCall_iiiiijj=function(){return(D.dynCall_iiiiijj=D.asm.Ia).apply(null,arguments)};var cb=D._main_thread_futex=3060104;D.PThread=Q;D.PThread=Q;D._pthread_self=pc;
D.wasmMemory=m;D.ExitStatus=Hc;var Ic;function Hc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}Pa=function Jc(){Ic||Kc();Ic||(Pa=Jc)};
function Kc(){function a(){if(!Ic&&(Ic=!0,D.calledRun=!0,!va)){Va(Ka);G||Va(La);na(D);if(D.onRuntimeInitialized)D.onRuntimeInitialized();if(!G){if(D.postRun)for("function"==typeof D.postRun&&(D.postRun=[D.postRun]);D.postRun.length;){var b=D.postRun.shift();Ma.unshift(b)}Va(Ma)}}}if(!(0<N)){if(!G){if(D.preRun)for("function"==typeof D.preRun&&(D.preRun=[D.preRun]);D.preRun.length;)Na();Va(Ja)}0<N||(D.setStatus?(D.setStatus("Running..."),setTimeout(function(){setTimeout(function(){D.setStatus("")},
1);a()},1)):a())}}D.run=Kc;if(D.preInit)for("function"==typeof D.preInit&&(D.preInit=[D.preInit]);0<D.preInit.length;)D.preInit.pop()();G||(noExitRuntime=!0);G?Q.Lb():Kc();

Binary file not shown.

Binary file not shown.

View File

@@ -46,10 +46,7 @@ $(CODEC_DIR)/Makefile: $(CODEC_DIR)/configure
--without-turbojpeg \
--without-simd \
--without-arith-enc \
--without-arith-dec \
--with-build-date=squoosh
# ^ If not provided with a dummy value, MozJPEG includes a build date in the
# binary as part of the version string, making binaries different each time.
--without-arith-dec
$(CODEC_DIR)/configure: $(CODEC_DIR)/configure.ac
cd $(CODEC_DIR) && autoreconf -iv

Binary file not shown.

View File

@@ -20,9 +20,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bit-vec"
version = "0.6.3"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3"
[[package]]
name = "bitflags"
@@ -56,9 +56,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cc"
version = "1.0.66"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40"
[[package]]
name = "cfg-if"
@@ -98,9 +98,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "const_fn"
version = "0.4.5"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab"
[[package]]
name = "crc"
@@ -143,9 +143,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f"
dependencies = [
"cfg-if 1.0.0",
"const_fn",
@@ -157,12 +157,13 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.1"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"const_fn",
"lazy_static",
]
@@ -199,9 +200,9 @@ dependencies = [
[[package]]
name = "image"
version = "0.23.12"
version = "0.23.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ce04077ead78e39ae8610ad26216aed811996b043d47beed5090db674f9e9b5"
checksum = "b4f0a8345b33b082aedec2f4d7d4a926b845cee184cbe78b703413066564431b"
dependencies = [
"bytemuck",
"byteorder",
@@ -214,9 +215,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "1.6.1"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b"
checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
dependencies = [
"autocfg",
"hashbrown",
@@ -225,9 +226,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.10.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
@@ -240,24 +241,24 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
[[package]]
name = "libdeflate-sys"
version = "0.7.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a95fa4be7085dd06a8296dcc3f399f12ab8b0309c157dcaa90669130b175b97"
checksum = "2f5b1582a0ebf8c55a46166c04d7c66f6bb17add3a6cbf69a082ac2219f31671"
dependencies = [
"cc",
]
[[package]]
name = "libdeflater"
version = "0.7.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccc147465654929bf7b56518cc46d11701ba290f4ff94398ae3f89f1663cf60f"
checksum = "93edd93a53970951da84ef733a8b6e30189a8f8a9e19610f69e4cc5bb1f4d654"
dependencies = [
"libdeflate-sys",
]
@@ -273,9 +274,9 @@ dependencies = [
[[package]]
name = "memoffset"
version = "0.6.1"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
dependencies = [
"autocfg",
]
@@ -358,9 +359,9 @@ checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
[[package]]
name = "oxipng"
version = "4.0.3"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d0b53912a666fe2970f8ab254e283531c816aed16551ab66c52485eadb44e6"
checksum = "9fefb26bde273c3db896a313151301a69e698a7495ee577fe2168ed7065c29c4"
dependencies = [
"bit-vec",
"byteorder",
@@ -389,9 +390,9 @@ dependencies = [
[[package]]
name = "png"
version = "0.16.8"
version = "0.16.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970"
dependencies = [
"bitflags",
"crc32fast",
@@ -410,9 +411,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.8"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
@@ -477,9 +478,9 @@ dependencies = [
[[package]]
name = "semver-parser"
version = "0.10.2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
dependencies = [
"pest",
]
@@ -489,7 +490,6 @@ name = "squoosh-oxipng"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"libdeflater",
"log",
"once_cell",
"oxipng",
@@ -499,9 +499,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.58"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
dependencies = [
"proc-macro2",
"quote",
@@ -522,19 +522,19 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasm-bindgen"
version = "0.2.69"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
dependencies = [
"cfg-if 1.0.0",
"cfg-if 0.1.10",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.69"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
dependencies = [
"bumpalo",
"lazy_static",
@@ -547,9 +547,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.69"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -557,9 +557,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.69"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
dependencies = [
"proc-macro2",
"quote",
@@ -570,6 +570,6 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.69"
version = "0.2.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"

View File

@@ -12,8 +12,7 @@ wasm-opt = ["-O", "--no-validation"]
crate-type = ["cdylib"]
[dependencies]
oxipng = { version = "4.0.1", default-features = false, features = ["libdeflater"] }
libdeflater = { version = "0.7.1", features = ["freestanding"] }
oxipng = { version = "4.0.0", default-features = false, features = ["libdeflater"] }
wasm-bindgen = "0.2.68"
log = { version = "0.4.11", features = ["release_max_level_off"] }
rayon = { version = "1.5.0", optional = true }

1
codecs/oxipng/build.sh Executable file → Normal file
View File

@@ -3,7 +3,6 @@
set -e
rm -rf pkg,{-parallel}
export CFLAGS="${CFLAGS} -DUNALIGNED_ACCESS_IS_FAST=1"
wasm-pack build -t web
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' wasm-pack build -t web -d pkg-parallel -- -Z build-std=panic_abort,std --features=parallel
# Workaround https://github.com/rustwasm/wasm-bindgen/issues/2133:

View File

@@ -22,6 +22,8 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
export interface InitOutput {
readonly optimise: (a: number, b: number, c: number, d: number) => void;
readonly malloc: (a: number) => number;
readonly free: (a: number) => void;
readonly worker_initializer: (a: number) => number;
readonly start_main_thread: () => void;
readonly start_worker_thread: () => void;

View File

@@ -1,6 +1,8 @@
/* tslint:disable */
/* eslint-disable */
export function optimise(a: number, b: number, c: number, d: number): void;
export function malloc(a: number): number;
export function free(a: number): void;
export function worker_initializer(a: number): number;
export function start_main_thread(): void;
export function start_worker_thread(): void;

View File

@@ -12,6 +12,8 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly optimise: (a: number, b: number, c: number, d: number) => void;
readonly malloc: (a: number) => number;
readonly free: (a: number) => void;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
}

View File

@@ -2,5 +2,7 @@
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function optimise(a: number, b: number, c: number, d: number): void;
export function malloc(a: number): number;
export function free(a: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_free(a: number, b: number): void;

View File

@@ -1,6 +1,8 @@
use oxipng::AlphaOptim;
use wasm_bindgen::prelude::*;
mod malloc_shim;
#[cfg(feature = "parallel")]
pub mod parallel;

View File

@@ -0,0 +1,47 @@
//! This is a module that provides `malloc` and `free` for `libdeflate`.
//! These implementations are compatible with the standard signatures
//! but use Rust allocator instead of including libc one as well.
//!
//! Rust allocator APIs requires passing size and alignment to the
//! `dealloc` function. This is different from C API, which only
//! expects a pointer in `free` and expects allocators to take care of
//! storing any necessary information elsewhere.
//!
//! In order to simulate C API, we allocate a `size_and_data_ptr`
//! of size `sizeof(usize) + size` where `size` is the requested number
//! of bytes. Then, we store `size` at the beginning of the allocated
//! chunk (within those `sizeof(usize)` bytes) and return
//! `data_ptr = size_and_data_ptr + sizeof(usize)` to the calleer:
//!
//! [`size`][...actual data]
//! -^------------------ `size_and_data_ptr`
//! ---------^---------- `data_ptr`
//!
//! Then, in `free`, the caller gives us `data_ptr`. We can subtract
//! `sizeof(usize)` back and get the original `size_and_data_ptr`.
//! At this point we can read `size` back and call the Rust `dealloc`
//! for the whole allocated chunk.
//!
//! I've raised an upstream issue to hopefully make this easier in
//! future: https://github.com/ebiggers/libdeflate/issues/62
use std::alloc::*;
use std::mem::{align_of, size_of};
unsafe fn layout_for(size: usize) -> Layout {
Layout::from_size_align_unchecked(size_of::<usize>() + size, align_of::<usize>())
}
#[no_mangle]
pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
let size_and_data_ptr = alloc(layout_for(size));
*(size_and_data_ptr as *mut usize) = size;
size_and_data_ptr.add(size_of::<usize>())
}
#[no_mangle]
pub unsafe extern "C" fn free(data_ptr: *mut u8) {
let size_and_data_ptr = data_ptr.sub(size_of::<usize>());
let size = *(size_and_data_ptr as *const usize);
dealloc(size_and_data_ptr, layout_for(size))
}

2
codecs/png/pkg/squoosh_png.d.ts generated vendored
View File

@@ -20,7 +20,6 @@ export interface InitOutput {
readonly encode: (a: number, b: number, c: number, d: number, e: number) => void;
readonly decode: (a: number, b: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
}
@@ -33,3 +32,4 @@ export interface InitOutput {
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;

View File

@@ -64,7 +64,8 @@ function getArrayU8FromWasm0(ptr, len) {
*/
export function encode(data, width, height) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const retptr = wasm.__wbindgen_export_1.value - 16;
wasm.__wbindgen_export_1.value = retptr;
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.encode(retptr, ptr0, len0, width, height);
@@ -74,7 +75,7 @@ export function encode(data, width, height) {
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export_1.value += 16;
}
}
@@ -137,7 +138,7 @@ async function load(module, imports) {
async function init(input) {
if (typeof input === 'undefined') {
input = new URL('squoosh_png_bg.wasm', import.meta.url);
input = import.meta.url.replace(/\.js$/, '_bg.wasm');
}
const imports = {};
imports.wbg = {};

Binary file not shown.

View File

@@ -4,5 +4,4 @@ export const memory: WebAssembly.Memory;
export function encode(a: number, b: number, c: number, d: number, e: number): void;
export function decode(a: number, b: number): number;
export function __wbindgen_free(a: number, b: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_malloc(a: number): number;

View File

@@ -6,12 +6,6 @@ version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
[[package]]
name = "bytemuck"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac"
[[package]]
name = "cfg-if"
version = "0.1.10"
@@ -108,21 +102,9 @@ dependencies = [
[[package]]
name = "resize"
version = "0.5.5"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a08c42ea86684dc00256494c4eb8b54707890ddac50c05060a717f29669029"
dependencies = [
"rgb",
]
[[package]]
name = "rgb"
version = "0.8.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "287f3c3f8236abb92d8b7e36797f19159df4b58f0a658cc3fb6dd3004b1f3bd3"
dependencies = [
"bytemuck",
]
checksum = "b9e653e390eafbfebb2b3c5fcfbc90d801bc410d0de1f44f266ffbf2151d28aa"
[[package]]
name = "scoped-tls"

View File

@@ -14,7 +14,7 @@ default = ["console_error_panic_hook", "wee_alloc"]
[dependencies]
cfg-if = "0.1.2"
wasm-bindgen = "0.2.38"
resize = "0.5.5"
resize = "0.3.0"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires

View File

@@ -4,14 +4,20 @@ use std::io::Write;
fn main() -> std::io::Result<()> {
let mut srgb_to_linear_lut = String::from("static SRGB_TO_LINEAR_LUT: [f32; 256] = [");
let mut linear_to_srgb_lut = String::from("static LINEAR_TO_SRGB_LUT: [f32; 256] = [");
for i in 0..256 {
srgb_to_linear_lut.push_str(&format!("{0:.7}", srgb_to_linear((i as f32) / 255.0)));
srgb_to_linear_lut.push_str(",");
linear_to_srgb_lut.push_str(&format!("{0:.7}", linear_to_srgb((i as f32) / 255.0)));
linear_to_srgb_lut.push_str(",");
}
srgb_to_linear_lut.pop().unwrap();
linear_to_srgb_lut.pop().unwrap();
srgb_to_linear_lut.push_str("];");
linear_to_srgb_lut.push_str("];");
let mut file = std::fs::File::create("src/lut.inc")?;
file.write_all(srgb_to_linear_lut.as_bytes())?;
file.write_all(linear_to_srgb_lut.as_bytes())?;
Ok(())
}

View File

@@ -1,34 +1,60 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8Array}
*/
export function resize(input_image: Uint8Array, input_width: number, input_height: number, output_width: number, output_height: number, typ_idx: number, premultiply: boolean, color_space_conversion: boolean): Uint8Array;
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8Array}
*/
export function resize(
input_image: Uint8Array,
input_width: number,
input_height: number,
output_width: number,
output_height: number,
typ_idx: number,
premultiply: boolean,
color_space_conversion: boolean,
): Uint8Array;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export type InitInput =
| RequestInfo
| URL
| Response
| BufferSource
| WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly resize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly resize: (
a: number,
b: number,
c: number,
d: number,
e: number,
f: number,
g: number,
h: number,
i: number,
j: number,
) => void;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
}
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init(
module_or_path?: InitInput | Promise<InitInput>,
): Promise<InitOutput>;

View File

@@ -1,112 +1,131 @@
let wasm;
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
if (
cachegetUint8Memory0 === null ||
cachegetUint8Memory0.buffer !== wasm.memory.buffer
) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
if (
cachegetInt32Memory0 === null ||
cachegetInt32Memory0.buffer !== wasm.memory.buffer
) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8Array}
*/
export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v1 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8Array}
*/
export function resize(
input_image,
input_width,
input_height,
output_width,
output_height,
typ_idx,
premultiply,
color_space_conversion,
) {
var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.resize(
8,
ptr0,
len0,
input_width,
input_height,
output_width,
output_height,
typ_idx,
premultiply,
color_space_conversion,
);
var r0 = getInt32Memory0()[8 / 4 + 0];
var r1 = getInt32Memory0()[8 / 4 + 1];
var v1 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
}
async function load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (module.headers.get('Content-Type') != 'application/wasm') {
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
} else {
throw e;
}
}
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (module.headers.get('Content-Type') != 'application/wasm') {
console.warn(
'`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n',
e,
);
} else {
return instance;
throw e;
}
}
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
} else {
return instance;
}
}
}
async function init(input) {
if (typeof input === 'undefined') {
input = new URL('squoosh_resize_bg.wasm', import.meta.url);
}
const imports = {};
if (typeof input === 'undefined') {
input = import.meta.url.replace(/\.js$/, '_bg.wasm');
}
const imports = {};
if (
typeof input === 'string' ||
(typeof Request === 'function' && input instanceof Request) ||
(typeof URL === 'function' && input instanceof URL)
) {
input = fetch(input);
}
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
return wasm;
}
export default init;

6
codecs/resize/pkg/squoosh_resize_bg.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function resize(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_free(a: number, b: number): void;

View File

@@ -5,12 +5,12 @@ extern crate wasm_bindgen;
mod utils;
use cfg_if::cfg_if;
use resize::Pixel;
use resize::Pixel::RGBA;
use resize::Type;
use wasm_bindgen::prelude::*;
mod srgb;
use srgb::{linear_to_srgb, Clamp};
use srgb::Clamp;
cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
@@ -27,17 +27,14 @@ include!("./lut.inc");
// If `with_space_conversion` is true, this function returns 2 functions that
// convert from sRGB to linear RGB and vice versa. If `with_space_conversion` is
// false, the 2 functions returned do nothing.
fn srgb_converter_funcs(with_space_conversion: bool) -> (fn(u8) -> f32, fn(f32) -> u8) {
fn converter_funcs(with_space_conversion: bool) -> ((fn(u8) -> f32), (fn(f32) -> u8)) {
if with_space_conversion {
(
|v| SRGB_TO_LINEAR_LUT[v as usize],
|v| (linear_to_srgb(v) * 255.0).clamp(0.0, 255.0) as u8,
|v| SRGB_TO_LINEAR_LUT[v as usize] * 255.0,
|v| (LINEAR_TO_SRGB_LUT[v as usize] * 255.0) as u8,
)
} else {
(
|v| (v as f32) / 255.0,
|v| (v * 255.0).clamp(0.0, 255.0) as u8,
)
(|v| v as f32, |v| v as u8)
}
}
@@ -47,18 +44,21 @@ fn srgb_converter_funcs(with_space_conversion: bool) -> (fn(u8) -> f32, fn(f32)
// false, the functions just return the channel value.
fn alpha_multiplier_funcs(
with_alpha_premultiplication: bool,
) -> (fn(f32, f32) -> f32, fn(f32, f32) -> f32) {
) -> ((fn(f32, u8) -> u8), (fn(u8, u8) -> f32)) {
if with_alpha_premultiplication {
(|v, a| v * a, |v, a| v / a)
(
|v, a| (v * (a as f32) / 255.0) as u8,
|v, a| ((v as f32) * 255.0 / (a as f32)).clamp(0.0, 255.0),
)
} else {
(|v, _a| v, |v, _a| v)
(|v, _a| v as u8, |v, _a| v as f32)
}
}
#[wasm_bindgen]
#[no_mangle]
pub fn resize(
input_image: Vec<u8>,
mut input_image: Vec<u8>,
input_width: usize,
input_height: usize,
output_width: usize,
@@ -77,64 +77,44 @@ pub fn resize(
let num_input_pixels = input_width * input_height;
let num_output_pixels = output_width * output_height;
let mut output_image = vec![0u8; num_output_pixels * 4];
// If both options are false, there is no preprocessing on the pixel values
// and we can skip the loop.
if !premultiply && !color_space_conversion {
let mut resizer = resize::new(
input_width,
input_height,
output_width,
output_height,
Pixel::RGBA,
typ,
);
resizer.resize(input_image.as_slice(), output_image.as_mut_slice());
return output_image;
}
// Otherwise, we convert to f32 images to keep the
// conversions as lossless and high-fidelity as possible.
let (to_linear, to_srgb) = srgb_converter_funcs(color_space_conversion);
let (to_linear, to_color_space) = converter_funcs(color_space_conversion);
let (premultiplier, demultiplier) = alpha_multiplier_funcs(premultiply);
let mut preprocessed_input_image: Vec<f32> = Vec::with_capacity(input_image.len());
preprocessed_input_image.resize(input_image.len(), 0.0f32);
for i in 0..num_input_pixels {
for j in 0..3 {
preprocessed_input_image[4 * i + j] = premultiplier(
to_linear(input_image[4 * i + j]),
(input_image[4 * i + 3] as f32) / 255.0,
);
// If both options are false, there is no preprocessing on the pixel valus
// and we can skip the loop.
if premultiply || color_space_conversion {
for i in 0..num_input_pixels {
for j in 0..3 {
input_image[4 * i + j] =
premultiplier(to_linear(input_image[4 * i + j]), input_image[4 * i + 3]);
}
}
preprocessed_input_image[4 * i + 3] = (input_image[4 * i + 3] as f32) / 255.0;
}
let mut unprocessed_output_image = vec![0.0f32; num_output_pixels * 4];
let mut resizer = resize::new(
input_width,
input_height,
output_width,
output_height,
Pixel::RGBAF32,
RGBA,
typ,
);
resizer.resize(
preprocessed_input_image.as_slice(),
unprocessed_output_image.as_mut_slice(),
);
let mut output_image = Vec::<u8>::with_capacity(num_output_pixels * 4);
output_image.resize(num_output_pixels * 4, 0);
resizer.resize(input_image.as_slice(), output_image.as_mut_slice());
for i in 0..num_output_pixels {
for j in 0..3 {
output_image[4 * i + j] = to_srgb(demultiplier(
unprocessed_output_image[4 * i + j],
unprocessed_output_image[4 * i + 3],
));
if premultiply || color_space_conversion {
for i in 0..num_output_pixels {
for j in 0..3 {
// We dont need to worry about division by zero, as division by zero
// is well-defined on floats to return ±Inf. ±Inf is converted to 0
// when casting to integers.
output_image[4 * i + j] = to_color_space(demultiplier(
output_image[4 * i + j],
output_image[4 * i + 3],
));
}
}
output_image[4 * i + 3] =
(unprocessed_output_image[4 * i + 3] * 255.0).clamp(0.0, 255.0) as u8;
}
return output_image;

View File

@@ -7,7 +7,7 @@ using namespace butteraugli;
// Turns an interleaved RGBA buffer into 4 planes for each color channel
void planarize(std::vector<ImageF>& img,
const uint8_t* rgba,
const char* rgba,
int width,
int height,
float gamma = 2.2) {
@@ -22,10 +22,10 @@ void planarize(std::vector<ImageF>& img,
float* const row_b = img[2].Row(y);
float* const row_a = img[3].Row(y);
for (int x = 0; x < width; x++) {
row_r[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 0] / 255.0, gamma);
row_g[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 1] / 255.0, gamma);
row_b[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 2] / 255.0, gamma);
row_a[x] = 255.0 * pow(rgba[(y * width + x) * 4 + 3] / 255.0, gamma);
row_r[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 0] / 255.0, gamma);
row_g[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 1] / 255.0, gamma);
row_b[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 2] / 255.0, gamma);
row_a[x] = 255.0 * pow(rgba[y * width * 4 + x * 4 + 3] / 255.0, gamma);
}
}
}
@@ -37,14 +37,14 @@ class VisDiff {
public:
VisDiff(std::string ref_img, int width, int height) {
planarize(this->ref_img, (uint8_t*)ref_img.c_str(), width, height);
planarize(this->ref_img, ref_img.c_str(), width, height);
this->width = width;
this->height = height;
}
double distance(std::string other_img) {
std::vector<ImageF> img;
planarize(img, (uint8_t*)other_img.c_str(), width, height);
planarize(img, other_img.c_str(), width, height);
ImageF diffmap;
double diffvalue;

128
codecs/visdif/visdif.js generated
View File

@@ -1,74 +1,80 @@
var visdif = (function() {
var _scriptDir = import.meta.url;
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
return (
function(visdif) {
visdif = visdif || {};
var f;f||(f=typeof visdif !== 'undefined' ? visdif : {});var ba,ca;f.ready=new Promise(function(a,b){ba=a;ca=b});var da={},q;for(q in f)f.hasOwnProperty(q)&&(da[q]=f[q]);var ea=!1,v=!1,fa=!1,ha=!1;ea="object"===typeof window;v="function"===typeof importScripts;fa="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;ha=!ea&&!fa&&!v;var y="",ia,ja,ka,la;
if(fa)y=v?require("path").dirname(y)+"/":__dirname+"/",ia=function(a,b){ka||(ka=require("fs"));la||(la=require("path"));a=la.normalize(a);return ka.readFileSync(a,b?null:"utf8")},ja=function(a){a=ia(a,!0);a.buffer||(a=new Uint8Array(a));assert(a.buffer);return a},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(a){throw a;}),process.on("unhandledRejection",A),f.inspect=function(){return"[Emscripten Module object]"};else if(ha)"undefined"!=
typeof read&&(ia=function(a){return read(a)}),ja=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");assert("object"===typeof a);return a},"undefined"!==typeof print&&("undefined"===typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!==typeof printErr?printErr:print);else if(ea||v)v?y=self.location.href:"undefined"!==typeof document&&document.currentScript&&(y=document.currentScript.src),_scriptDir&&(y=_scriptDir),
0!==y.indexOf("blob:")?y=y.substr(0,y.lastIndexOf("/")+1):y="",ia=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},v&&(ja=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});var ma=f.print||console.log.bind(console),B=f.printErr||console.warn.bind(console);for(q in da)da.hasOwnProperty(q)&&(f[q]=da[q]);da=null;var na;f.wasmBinary&&(na=f.wasmBinary);var noExitRuntime;
f.noExitRuntime&&(noExitRuntime=f.noExitRuntime);"object"!==typeof WebAssembly&&A("no native wasm support detected");var C,oa=!1;function assert(a,b){a||A("Assertion failed: "+b)}var pa="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
function qa(a,b,c){var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.subarray&&pa)return pa.decode(a.subarray(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var g=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|g);else{var k=a[b++]&63;e=224==(e&240)?(e&15)<<12|g<<6|k:(e&7)<<18|g<<12|k<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|e&1023))}}else d+=String.fromCharCode(e)}return d}
function ra(a,b,c){var d=D;if(0<c){c=b+c-1;for(var e=0;e<a.length;++e){var g=a.charCodeAt(e);if(55296<=g&&57343>=g){var k=a.charCodeAt(++e);g=65536+((g&1023)<<10)|k&1023}if(127>=g){if(b>=c)break;d[b++]=g}else{if(2047>=g){if(b+1>=c)break;d[b++]=192|g>>6}else{if(65535>=g){if(b+2>=c)break;d[b++]=224|g>>12}else{if(b+3>=c)break;d[b++]=240|g>>18;d[b++]=128|g>>12&63}d[b++]=128|g>>6&63}d[b++]=128|g&63}}d[b]=0}}var sa="undefined"!==typeof TextDecoder?new TextDecoder("utf-16le"):void 0;
function ta(a,b){var c=a>>1;for(var d=c+b/2;!(c>=d)&&ua[c];)++c;c<<=1;if(32<c-a&&sa)return sa.decode(D.subarray(a,c));c=0;for(d="";;){var e=E[a+2*c>>1];if(0==e||c==b/2)return d;++c;d+=String.fromCharCode(e)}}function va(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var e=0;e<c;++e)E[b>>1]=a.charCodeAt(e),b+=2;E[b>>1]=0;return b-d}function wa(a){return 2*a.length}
function xa(a,b){for(var c=0,d="";!(c>=b/4);){var e=F[a+4*c>>2];if(0==e)break;++c;65536<=e?(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|e&1023)):d+=String.fromCharCode(e)}return d}function ya(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var d=b;c=d+c-4;for(var e=0;e<a.length;++e){var g=a.charCodeAt(e);if(55296<=g&&57343>=g){var k=a.charCodeAt(++e);g=65536+((g&1023)<<10)|k&1023}F[b>>2]=g;b+=4;if(b+4>c)break}F[b>>2]=0;return b-d}
function za(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}var G,Aa,D,E,ua,F,I,Ba,Ca;function Da(a){G=a;f.HEAP8=Aa=new Int8Array(a);f.HEAP16=E=new Int16Array(a);f.HEAP32=F=new Int32Array(a);f.HEAPU8=D=new Uint8Array(a);f.HEAPU16=ua=new Uint16Array(a);f.HEAPU32=I=new Uint32Array(a);f.HEAPF32=Ba=new Float32Array(a);f.HEAPF64=Ca=new Float64Array(a)}var Ea=f.INITIAL_MEMORY||16777216;
f.wasmMemory?C=f.wasmMemory:C=new WebAssembly.Memory({initial:Ea/65536,maximum:32768});C&&(G=C.buffer);Ea=G.byteLength;Da(G);var Fa,Ga=[],Ha=[],Ia=[],Ja=[];function Ka(){var a=f.preRun.shift();Ga.unshift(a)}var J=0,La=null,Ma=null;f.preloadedImages={};f.preloadedAudios={};function A(a){if(f.onAbort)f.onAbort(a);B(a);oa=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");ca(a);throw a;}
function Na(a){var b=K;return String.prototype.startsWith?b.startsWith(a):0===b.indexOf(a)}function Oa(){return Na("data:application/octet-stream;base64,")}var K="visdif.wasm";if(!Oa()){var Pa=K;K=f.locateFile?f.locateFile(Pa,y):y+Pa}function Qa(){try{if(na)return new Uint8Array(na);if(ja)return ja(K);throw"both async and sync fetching of the wasm failed";}catch(a){A(a)}}
function Ra(){return na||!ea&&!v||"function"!==typeof fetch||Na("file://")?Promise.resolve().then(Qa):fetch(K,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+K+"'";return a.arrayBuffer()}).catch(function(){return Qa()})}function Sa(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(f);else{var c=b.ba;"number"===typeof c?void 0===b.V?Fa.get(c)():Fa.get(c)(b.V):c(void 0===b.V?null:b.V)}}}
function Ta(a){this.C=a-16;this.qa=function(b){F[this.C+8>>2]=b};this.na=function(b){F[this.C+0>>2]=b};this.oa=function(){F[this.C+4>>2]=0};this.ma=function(){Aa[this.C+12>>0]=0};this.pa=function(){Aa[this.C+13>>0]=0};this.ga=function(b,c){this.qa(b);this.na(c);this.oa();this.ma();this.pa()}}function Ua(){return 0<Ua.Z}function Va(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}var Wa=void 0;
function L(a){for(var b="";D[a];)b+=Wa[D[a++]];return b}var M={},N={},Xa={};function Ya(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}function Za(a,b){a=Ya(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)}
function $a(a){var b=Error,c=Za(a,function(d){this.name=a;this.message=d;d=Error(d).stack;void 0!==d&&(this.stack=this.toString()+"\n"+d.replace(/^Error(:[^\n]*)?\n/,""))});c.prototype=Object.create(b.prototype);c.prototype.constructor=c;c.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message};return c}var O=void 0;function R(a){throw new O(a);}var ab=void 0;function bb(a){throw new ab(a);}
function cb(a,b,c){function d(h){h=c(h);h.length!==a.length&&bb("Mismatched type converter count");for(var m=0;m<a.length;++m)S(a[m],h[m])}a.forEach(function(h){Xa[h]=b});var e=Array(b.length),g=[],k=0;b.forEach(function(h,m){N.hasOwnProperty(h)?e[m]=N[h]:(g.push(h),M.hasOwnProperty(h)||(M[h]=[]),M[h].push(function(){e[m]=N[h];++k;k===g.length&&d(e)}))});0===g.length&&d(e)}
function S(a,b,c){c=c||{};if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var d=b.name;a||R('type "'+d+'" must have a positive integer typeid pointer');if(N.hasOwnProperty(a)){if(c.fa)return;R("Cannot register type '"+d+"' twice")}N[a]=b;delete Xa[a];M.hasOwnProperty(a)&&(b=M[a],delete M[a],b.forEach(function(e){e()}))}function db(a){return{count:a.count,N:a.N,P:a.P,C:a.C,F:a.F,G:a.G,H:a.H}}
function eb(a){R(a.B.F.D.name+" instance already deleted")}var fb=!1;function gb(){}function hb(a){--a.count.value;0===a.count.value&&(a.G?a.H.M(a.G):a.F.D.M(a.C))}function ib(a){if("undefined"===typeof FinalizationGroup)return ib=function(b){return b},a;fb=new FinalizationGroup(function(b){for(var c=b.next();!c.done;c=b.next())c=c.value,c.C?hb(c):console.warn("object already deleted: "+c.C)});ib=function(b){fb.register(b,b.B,b.B);return b};gb=function(b){fb.unregister(b.B)};return ib(a)}
var jb=void 0,kb=[];function lb(){for(;kb.length;){var a=kb.pop();a.B.N=!1;a["delete"]()}}function T(){}var mb={};function nb(a,b,c){if(void 0===a[b].J){var d=a[b];a[b]=function(){a[b].J.hasOwnProperty(arguments.length)||R("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].J+")!");return a[b].J[arguments.length].apply(this,arguments)};a[b].J=[];a[b].J[d.S]=d}}
function ob(a,b){f.hasOwnProperty(a)?(R("Cannot register public name '"+a+"' twice"),nb(f,a,a),f.hasOwnProperty(void 0)&&R("Cannot register multiple overloads of a function with the same number of arguments (undefined)!"),f[a].J[void 0]=b):f[a]=b}function pb(a,b,c,d,e,g,k,h){this.name=a;this.constructor=b;this.O=c;this.M=d;this.I=e;this.da=g;this.R=k;this.aa=h;this.ia=[]}
function qb(a,b,c){for(;b!==c;)b.R||R("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.R(a),b=b.I;return a}function rb(a,b){if(null===b)return this.W&&R("null is not a valid "+this.name),0;b.B||R('Cannot pass "'+U(b)+'" as a '+this.name);b.B.C||R("Cannot pass deleted object as a pointer of type "+this.name);return qb(b.B.C,b.B.F.D,this.D)}
function sb(a,b){if(null===b){this.W&&R("null is not a valid "+this.name);if(this.U){var c=this.ja();null!==a&&a.push(this.M,c);return c}return 0}b.B||R('Cannot pass "'+U(b)+'" as a '+this.name);b.B.C||R("Cannot pass deleted object as a pointer of type "+this.name);!this.T&&b.B.F.T&&R("Cannot convert argument of type "+(b.B.H?b.B.H.name:b.B.F.name)+" to parameter type "+this.name);c=qb(b.B.C,b.B.F.D,this.D);if(this.U)switch(void 0===b.B.G&&R("Passing raw pointer to smart pointer is illegal"),this.ra){case 0:b.B.H===
this?c=b.B.G:R("Cannot convert argument of type "+(b.B.H?b.B.H.name:b.B.F.name)+" to parameter type "+this.name);break;case 1:c=b.B.G;break;case 2:if(b.B.H===this)c=b.B.G;else{var d=b.clone();c=this.ka(c,vb(function(){d["delete"]()}));null!==a&&a.push(this.M,c)}break;default:R("Unsupporting sharing policy")}return c}
function wb(a,b){if(null===b)return this.W&&R("null is not a valid "+this.name),0;b.B||R('Cannot pass "'+U(b)+'" as a '+this.name);b.B.C||R("Cannot pass deleted object as a pointer of type "+this.name);b.B.F.T&&R("Cannot convert argument of type "+b.B.F.name+" to parameter type "+this.name);return qb(b.B.C,b.B.F.D,this.D)}function xb(a){return this.fromWireType(I[a>>2])}function yb(a,b,c){if(b===c)return a;if(void 0===c.I)return null;a=yb(a,b,c.I);return null===a?null:c.aa(a)}var zb={};
function Ab(a,b){for(void 0===b&&R("ptr should not be undefined");a.I;)b=a.R(b),a=a.I;return zb[b]}function Bb(a,b){b.F&&b.C||bb("makeClassHandle requires ptr and ptrType");!!b.H!==!!b.G&&bb("Both smartPtrType and smartPtr must be specified");b.count={value:1};return ib(Object.create(a,{B:{value:b}}))}function V(a,b,c,d){this.name=a;this.D=b;this.W=c;this.T=d;this.U=!1;this.M=this.ka=this.ja=this.Y=this.ra=this.ha=void 0;void 0!==b.I?this.toWireType=sb:(this.toWireType=d?rb:wb,this.K=null)}
function Cb(a,b){f.hasOwnProperty(a)||bb("Replacing nonexistant public symbol");f[a]=b;f[a].S=void 0}function Db(a,b){assert(0<=a.indexOf("j"),"getDynCaller should only be called with i64 sigs");var c=[];return function(){c.length=arguments.length;for(var d=0;d<arguments.length;d++)c[d]=arguments[d];var e;-1!=a.indexOf("j")?e=c&&c.length?f["dynCall_"+a].apply(null,[b].concat(c)):f["dynCall_"+a].call(null,b):e=Fa.get(b).apply(null,c);return e}}
function W(a,b){a=L(a);var c=-1!=a.indexOf("j")?Db(a,b):Fa.get(b);"function"!==typeof c&&R("unknown function pointer with signature "+a+": "+b);return c}var Eb=void 0;function Fb(a){a=Gb(a);var b=L(a);X(a);return b}function Hb(a,b){function c(g){e[g]||N[g]||(Xa[g]?Xa[g].forEach(c):(d.push(g),e[g]=!0))}var d=[],e={};b.forEach(c);throw new Eb(a+": "+d.map(Fb).join([", "]));}function Ib(a,b){for(var c=[],d=0;d<a;d++)c.push(F[(b>>2)+d]);return c}
function Jb(a){for(;a.length;){var b=a.pop();a.pop()(b)}}function Kb(a){var b=Function;if(!(b instanceof Function))throw new TypeError("new_ called with constructor type "+typeof b+" which is not a function");var c=Za(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}var Lb=[],Y=[{},{value:void 0},{value:null},{value:!0},{value:!1}];
function vb(a){switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=Lb.length?Lb.pop():Y.length;Y[b]={la:1,value:a};return b}}function U(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a}function Mb(a,b){switch(b){case 2:return function(c){return this.fromWireType(Ba[c>>2])};case 3:return function(c){return this.fromWireType(Ca[c>>3])};default:throw new TypeError("Unknown float type: "+a);}}
function Nb(a,b,c){switch(b){case 0:return c?function(d){return Aa[d]}:function(d){return D[d]};case 1:return c?function(d){return E[d>>1]}:function(d){return ua[d>>1]};case 2:return c?function(d){return F[d>>2]}:function(d){return I[d>>2]};default:throw new TypeError("Unknown integer type: "+a);}}for(var Ob=[null,[],[]],Pb=Array(256),Qb=0;256>Qb;++Qb)Pb[Qb]=String.fromCharCode(Qb);Wa=Pb;O=f.BindingError=$a("BindingError");ab=f.InternalError=$a("InternalError");
T.prototype.isAliasOf=function(a){if(!(this instanceof T&&a instanceof T))return!1;var b=this.B.F.D,c=this.B.C,d=a.B.F.D;for(a=a.B.C;b.I;)c=b.R(c),b=b.I;for(;d.I;)a=d.R(a),d=d.I;return b===d&&c===a};T.prototype.clone=function(){this.B.C||eb(this);if(this.B.P)return this.B.count.value+=1,this;var a=ib(Object.create(Object.getPrototypeOf(this),{B:{value:db(this.B)}}));a.B.count.value+=1;a.B.N=!1;return a};
T.prototype["delete"]=function(){this.B.C||eb(this);this.B.N&&!this.B.P&&R("Object already scheduled for deletion");gb(this);hb(this.B);this.B.P||(this.B.G=void 0,this.B.C=void 0)};T.prototype.isDeleted=function(){return!this.B.C};T.prototype.deleteLater=function(){this.B.C||eb(this);this.B.N&&!this.B.P&&R("Object already scheduled for deletion");kb.push(this);1===kb.length&&jb&&jb(lb);this.B.N=!0;return this};V.prototype.ea=function(a){this.Y&&(a=this.Y(a));return a};
V.prototype.X=function(a){this.M&&this.M(a)};V.prototype.argPackAdvance=8;V.prototype.readValueFromPointer=xb;V.prototype.deleteObject=function(a){if(null!==a)a["delete"]()};
V.prototype.fromWireType=function(a){function b(){return this.U?Bb(this.D.O,{F:this.ha,C:c,H:this,G:a}):Bb(this.D.O,{F:this,C:a})}var c=this.ea(a);if(!c)return this.X(a),null;var d=Ab(this.D,c);if(void 0!==d){if(0===d.B.count.value)return d.B.C=c,d.B.G=a,d.clone();d=d.clone();this.X(a);return d}d=this.D.da(c);d=mb[d];if(!d)return b.call(this);d=this.T?d.$:d.pointerType;var e=yb(c,this.D,d.D);return null===e?b.call(this):this.U?Bb(d.D.O,{F:d,C:e,H:this,G:a}):Bb(d.D.O,{F:d,C:e})};
f.getInheritedInstanceCount=function(){return Object.keys(zb).length};f.getLiveInheritedInstances=function(){var a=[],b;for(b in zb)zb.hasOwnProperty(b)&&a.push(zb[b]);return a};f.flushPendingDeletes=lb;f.setDelayFunction=function(a){jb=a;kb.length&&jb&&jb(lb)};Eb=f.UnboundTypeError=$a("UnboundTypeError");f.count_emval_handles=function(){for(var a=0,b=5;b<Y.length;++b)void 0!==Y[b]&&++a;return a};f.get_first_emval=function(){for(var a=5;a<Y.length;++a)if(void 0!==Y[a])return Y[a];return null};Ha.push({ba:function(){Rb()}});
var Tb={c:function(a,b,c,d){A("Assertion failed: "+(a?qa(D,a,void 0):"")+", at: "+[b?b?qa(D,b,void 0):"":"unknown filename",c,d?d?qa(D,d,void 0):"":"unknown function"])},t:function(a){return Sb(a+16)+16},p:function(a,b,c){(new Ta(a)).ga(b,c);"uncaught_exception"in Ua?Ua.Z++:Ua.Z=1;throw a;},k:function(a,b,c,d,e){var g=Va(c);b=L(b);S(a,{name:b,fromWireType:function(k){return!!k},toWireType:function(k,h){return h?d:e},argPackAdvance:8,readValueFromPointer:function(k){if(1===c)var h=Aa;else if(2===c)h=
E;else if(4===c)h=F;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(h[k>>g])},K:null})},o:function(a,b,c,d,e,g,k,h,m,l,n,t,u){n=L(n);g=W(e,g);h&&(h=W(k,h));l&&(l=W(m,l));u=W(t,u);var z=Ya(n);ob(z,function(){Hb("Cannot construct "+n+" due to unbound types",[d])});cb([a,b,c],d?[d]:[],function(r){r=r[0];if(d){var w=r.D;var p=w.O}else p=T.prototype;r=Za(z,function(){if(Object.getPrototypeOf(this)!==H)throw new O("Use 'new' to construct "+n);if(void 0===x.L)throw new O(n+
" has no accessible constructor");var P=x.L[arguments.length];if(void 0===P)throw new O("Tried to invoke ctor of "+n+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(x.L).toString()+") parameters instead!");return P.apply(this,arguments)});var H=Object.create(p,{constructor:{value:r}});r.prototype=H;var x=new pb(n,r,H,u,w,g,h,l);w=new V(n,x,!0,!1);p=new V(n+"*",x,!1,!1);var Z=new V(n+" const*",x,!1,!0);mb[a]={pointerType:p,$:Z};Cb(z,r);return[w,p,Z]})},n:function(a,
b,c,d,e,g){assert(0<b);var k=Ib(b,c);e=W(d,e);var h=[g],m=[];cb([],[a],function(l){l=l[0];var n="constructor "+l.name;void 0===l.D.L&&(l.D.L=[]);if(void 0!==l.D.L[b-1])throw new O("Cannot register multiple constructors with identical number of parameters ("+(b-1)+") for class '"+l.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");l.D.L[b-1]=function(){Hb("Cannot construct "+l.name+" due to unbound types",k)};cb([],k,function(t){l.D.L[b-1]=
function(){arguments.length!==b-1&&R(n+" called with "+arguments.length+" arguments, expected "+(b-1));m.length=0;h.length=b;for(var u=1;u<b;++u)h[u]=t[u].toWireType(m,arguments[u-1]);u=e.apply(null,h);Jb(m);return t[0].fromWireType(u)};return[]});return[]})},m:function(a,b,c,d,e,g,k,h){var m=Ib(c,d);b=L(b);g=W(e,g);cb([],[a],function(l){function n(){Hb("Cannot call "+t+" due to unbound types",m)}l=l[0];var t=l.name+"."+b;h&&l.D.ia.push(b);var u=l.D.O,z=u[b];void 0===z||void 0===z.J&&z.className!==
l.name&&z.S===c-2?(n.S=c-2,n.className=l.name,u[b]=n):(nb(u,b,t),u[b].J[c-2]=n);cb([],m,function(r){var w=t,p=l,H=g,x=r.length;2>x&&R("argTypes array size mismatch! Must at least get return value and 'this' types!");var Z=null!==r[1]&&null!==p,P=!1;for(p=1;p<r.length;++p)if(null!==r[p]&&void 0===r[p].K){P=!0;break}var tb="void"!==r[0].name,Q="",aa="";for(p=0;p<x-2;++p)Q+=(0!==p?", ":"")+"arg"+p,aa+=(0!==p?", ":"")+"arg"+p+"Wired";w="return function "+Ya(w)+"("+Q+") {\nif (arguments.length !== "+(x-
2)+") {\nthrowBindingError('function "+w+" called with ' + arguments.length + ' arguments, expected "+(x-2)+" args!');\n}\n";P&&(w+="var destructors = [];\n");var ub=P?"destructors":"null";Q="throwBindingError invoker fn runDestructors retType classParam".split(" ");H=[R,H,k,Jb,r[0],r[1]];Z&&(w+="var thisWired = classParam.toWireType("+ub+", this);\n");for(p=0;p<x-2;++p)w+="var arg"+p+"Wired = argType"+p+".toWireType("+ub+", arg"+p+"); // "+r[p+2].name+"\n",Q.push("argType"+p),H.push(r[p+2]);Z&&(aa=
"thisWired"+(0<aa.length?", ":"")+aa);w+=(tb?"var rv = ":"")+"invoker(fn"+(0<aa.length?", ":"")+aa+");\n";if(P)w+="runDestructors(destructors);\n";else for(p=Z?1:2;p<r.length;++p)x=1===p?"thisWired":"arg"+(p-2)+"Wired",null!==r[p].K&&(w+=x+"_dtor("+x+"); // "+r[p].name+"\n",Q.push(x+"_dtor"),H.push(r[p].K));tb&&(w+="var ret = retType.fromWireType(rv);\nreturn ret;\n");Q.push(w+"}\n");r=Kb(Q).apply(null,H);void 0===u[b].J?(r.S=c-2,u[b]=r):u[b].J[c-2]=r;return[]});return[]})},s:function(a,b){b=L(b);
S(a,{name:b,fromWireType:function(c){var d=Y[c].value;4<c&&0===--Y[c].la&&(Y[c]=void 0,Lb.push(c));return d},toWireType:function(c,d){return vb(d)},argPackAdvance:8,readValueFromPointer:xb,K:null})},j:function(a,b,c){c=Va(c);b=L(b);S(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,e){if("number"!==typeof e&&"boolean"!==typeof e)throw new TypeError('Cannot convert "'+U(e)+'" to '+this.name);return e},argPackAdvance:8,readValueFromPointer:Mb(b,c),K:null})},e:function(a,b,c,d,e){function g(l){return l}
b=L(b);-1===e&&(e=4294967295);var k=Va(c);if(0===d){var h=32-8*c;g=function(l){return l<<h>>>h}}var m=-1!=b.indexOf("unsigned");S(a,{name:b,fromWireType:g,toWireType:function(l,n){if("number"!==typeof n&&"boolean"!==typeof n)throw new TypeError('Cannot convert "'+U(n)+'" to '+this.name);if(n<d||n>e)throw new TypeError('Passing a number "'+U(n)+'" from JS side to C/C++ side to an argument of type "'+b+'", which is outside the valid range ['+d+", "+e+"]!");return m?n>>>0:n|0},argPackAdvance:8,readValueFromPointer:Nb(b,
k,0!==d),K:null})},d:function(a,b,c){function d(g){g>>=2;var k=I;return new e(G,k[g+1],k[g])}var e=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=L(c);S(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{fa:!0})},h:function(a,b){b=L(b);var c="std::string"===b;S(a,{name:b,fromWireType:function(d){var e=I[d>>2];if(c)for(var g=d+4,k=0;k<=e;++k){var h=d+4+k;if(k==e||0==D[h]){g=g?qa(D,g,h-g):"";if(void 0===m)var m=g;else m+=String.fromCharCode(0),
m+=g;g=h+1}}else{m=Array(e);for(k=0;k<e;++k)m[k]=String.fromCharCode(D[d+4+k]);m=m.join("")}X(d);return m},toWireType:function(d,e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));var g="string"===typeof e;g||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||R("Cannot pass non-string to std::string");var k=(c&&g?function(){for(var l=0,n=0;n<e.length;++n){var t=e.charCodeAt(n);55296<=t&&57343>=t&&(t=65536+((t&1023)<<10)|e.charCodeAt(++n)&1023);127>=t?++l:l=2047>=t?l+
2:65535>=t?l+3:l+4}return l}:function(){return e.length})(),h=Sb(4+k+1);I[h>>2]=k;if(c&&g)ra(e,h+4,k+1);else if(g)for(g=0;g<k;++g){var m=e.charCodeAt(g);255<m&&(X(h),R("String has UTF-16 code units that do not fit in 8 bits"));D[h+4+g]=m}else for(g=0;g<k;++g)D[h+4+g]=e[g];null!==d&&d.push(X,h);return h},argPackAdvance:8,readValueFromPointer:xb,K:function(d){X(d)}})},g:function(a,b,c){c=L(c);if(2===b){var d=ta;var e=va;var g=wa;var k=function(){return ua};var h=1}else 4===b&&(d=xa,e=ya,g=za,k=function(){return I},
h=2);S(a,{name:c,fromWireType:function(m){for(var l=I[m>>2],n=k(),t,u=m+4,z=0;z<=l;++z){var r=m+4+z*b;if(z==l||0==n[r>>h])u=d(u,r-u),void 0===t?t=u:(t+=String.fromCharCode(0),t+=u),u=r+b}X(m);return t},toWireType:function(m,l){"string"!==typeof l&&R("Cannot pass non-string to C++ string type "+c);var n=g(l),t=Sb(4+n+b);I[t>>2]=n>>h;e(l,t+4,n+b);null!==m&&m.push(X,t);return t},argPackAdvance:8,readValueFromPointer:xb,K:function(m){X(m)}})},l:function(a,b){b=L(b);S(a,{sa:!0,name:b,argPackAdvance:0,
fromWireType:function(){},toWireType:function(){}})},b:function(){A()},r:function(a,b,c){D.copyWithin(a,b,b+c)},f:function(a){a>>>=0;var b=D.length;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);d=Math.max(16777216,a,d);0<d%65536&&(d+=65536-d%65536);a:{try{C.grow(Math.min(2147483648,d)-G.byteLength+65535>>>16);Da(C.buffer);var e=1;break a}catch(g){}e=void 0}if(e)return!0}return!1},i:function(a,b,c,d){for(var e=0,g=0;g<c;g++){for(var k=F[b+8*g>>2],h=F[b+
(8*g+4)>>2],m=0;m<h;m++){var l=D[k+m],n=Ob[a];0===l||10===l?((1===a?ma:B)(qa(n,0)),n.length=0):n.push(l)}e+=h}F[d>>2]=e;return 0},a:C,q:function(){}};
(function(){function a(e){f.asm=e.exports;Fa=f.asm.u;J--;f.monitorRunDependencies&&f.monitorRunDependencies(J);0==J&&(null!==La&&(clearInterval(La),La=null),Ma&&(e=Ma,Ma=null,e()))}function b(e){a(e.instance)}function c(e){return Ra().then(function(g){return WebAssembly.instantiate(g,d)}).then(e,function(g){B("failed to asynchronously prepare wasm: "+g);A(g)})}var d={a:Tb};J++;f.monitorRunDependencies&&f.monitorRunDependencies(J);if(f.instantiateWasm)try{return f.instantiateWasm(d,a)}catch(e){return B("Module.instantiateWasm callback failed with error: "+
e),!1}(function(){return na||"function"!==typeof WebAssembly.instantiateStreaming||Oa()||Na("file://")||"function"!==typeof fetch?c(b):fetch(K,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(b,function(g){B("wasm streaming compile failed: "+g);B("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ca);return{}})();
var Rb=f.___wasm_call_ctors=function(){return(Rb=f.___wasm_call_ctors=f.asm.v).apply(null,arguments)},Sb=f._malloc=function(){return(Sb=f._malloc=f.asm.w).apply(null,arguments)},X=f._free=function(){return(X=f._free=f.asm.x).apply(null,arguments)},Gb=f.___getTypeName=function(){return(Gb=f.___getTypeName=f.asm.y).apply(null,arguments)};f.___embind_register_native_and_builtin_types=function(){return(f.___embind_register_native_and_builtin_types=f.asm.z).apply(null,arguments)};
f.dynCall_jiji=function(){return(f.dynCall_jiji=f.asm.A).apply(null,arguments)};var Ub;Ma=function Vb(){Ub||Wb();Ub||(Ma=Vb)};
function Wb(){function a(){if(!Ub&&(Ub=!0,f.calledRun=!0,!oa)){Sa(Ha);Sa(Ia);ba(f);if(f.onRuntimeInitialized)f.onRuntimeInitialized();if(f.postRun)for("function"==typeof f.postRun&&(f.postRun=[f.postRun]);f.postRun.length;){var b=f.postRun.shift();Ja.unshift(b)}Sa(Ja)}}if(!(0<J)){if(f.preRun)for("function"==typeof f.preRun&&(f.preRun=[f.preRun]);f.preRun.length;)Ka();Sa(Ga);0<J||(f.setStatus?(f.setStatus("Running..."),setTimeout(function(){setTimeout(function(){f.setStatus("")},1);a()},1)):a())}}
f.run=Wb;if(f.preInit)for("function"==typeof f.preInit&&(f.preInit=[f.preInit]);0<f.preInit.length;)f.preInit.pop()();noExitRuntime=!0;Wb();
var e;e||(e=typeof visdif !== 'undefined' ? visdif : {});var ba,ca;e.ready=new Promise(function(a,b){ba=a;ca=b});var da={},q;for(q in e)e.hasOwnProperty(q)&&(da[q]=e[q]);var ea=!1,v=!1,fa=!1,ha=!1;ea="object"===typeof window;v="function"===typeof importScripts;fa="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;ha=!ea&&!fa&&!v;var z="",ia,ja,ka,la;
if(fa)z=v?require("path").dirname(z)+"/":__dirname+"/",ia=function(a,b){ka||(ka=require("fs"));la||(la=require("path"));a=la.normalize(a);return ka.readFileSync(a,b?null:"utf8")},ja=function(a){a=ia(a,!0);a.buffer||(a=new Uint8Array(a));assert(a.buffer);return a},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(a){throw a;}),process.on("unhandledRejection",A),e.inspect=function(){return"[Emscripten Module object]"};else if(ha)"undefined"!=
typeof read&&(ia=function(a){return read(a)}),ja=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");assert("object"===typeof a);return a},"undefined"!==typeof print&&("undefined"===typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!==typeof printErr?printErr:print);else if(ea||v)v?z=self.location.href:document.currentScript&&(z=document.currentScript.src),_scriptDir&&(z=_scriptDir),0!==z.indexOf("blob:")?z=z.substr(0,
z.lastIndexOf("/")+1):z="",ia=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},v&&(ja=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});var ma=e.print||console.log.bind(console),B=e.printErr||console.warn.bind(console);for(q in da)da.hasOwnProperty(q)&&(e[q]=da[q]);da=null;var na;e.wasmBinary&&(na=e.wasmBinary);var noExitRuntime;e.noExitRuntime&&(noExitRuntime=e.noExitRuntime);
"object"!==typeof WebAssembly&&A("no native wasm support detected");var C,oa=new WebAssembly.Table({initial:39,maximum:39,element:"anyfunc"}),pa=!1;function assert(a,b){a||A("Assertion failed: "+b)}var qa="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
function ra(a,b,c){var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.subarray&&qa)return qa.decode(a.subarray(b,c));for(d="";b<c;){var f=a[b++];if(f&128){var g=a[b++]&63;if(192==(f&224))d+=String.fromCharCode((f&31)<<6|g);else{var k=a[b++]&63;f=224==(f&240)?(f&15)<<12|g<<6|k:(f&7)<<18|g<<12|k<<6|a[b++]&63;65536>f?d+=String.fromCharCode(f):(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else d+=String.fromCharCode(f)}return d}
function sa(a,b,c){var d=D;if(0<c){c=b+c-1;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var k=a.charCodeAt(++f);g=65536+((g&1023)<<10)|k&1023}if(127>=g){if(b>=c)break;d[b++]=g}else{if(2047>=g){if(b+1>=c)break;d[b++]=192|g>>6}else{if(65535>=g){if(b+2>=c)break;d[b++]=224|g>>12}else{if(b+3>=c)break;d[b++]=240|g>>18;d[b++]=128|g>>12&63}d[b++]=128|g>>6&63}d[b++]=128|g&63}}d[b]=0}}var ta="undefined"!==typeof TextDecoder?new TextDecoder("utf-16le"):void 0;
function ua(a,b){var c=a>>1;for(var d=c+b/2;!(c>=d)&&va[c];)++c;c<<=1;if(32<c-a&&ta)return ta.decode(D.subarray(a,c));c=0;for(d="";;){var f=E[a+2*c>>1];if(0==f||c==b/2)return d;++c;d+=String.fromCharCode(f)}}function wa(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var f=0;f<c;++f)E[b>>1]=a.charCodeAt(f),b+=2;E[b>>1]=0;return b-d}function xa(a){return 2*a.length}
function ya(a,b){for(var c=0,d="";!(c>=b/4);){var f=F[a+4*c>>2];if(0==f)break;++c;65536<=f?(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023)):d+=String.fromCharCode(f)}return d}function za(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var d=b;c=d+c-4;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var k=a.charCodeAt(++f);g=65536+((g&1023)<<10)|k&1023}F[b>>2]=g;b+=4;if(b+4>c)break}F[b>>2]=0;return b-d}
function Aa(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}var G,Ba,D,E,va,F,I,Ca,Da;function Ea(a){G=a;e.HEAP8=Ba=new Int8Array(a);e.HEAP16=E=new Int16Array(a);e.HEAP32=F=new Int32Array(a);e.HEAPU8=D=new Uint8Array(a);e.HEAPU16=va=new Uint16Array(a);e.HEAPU32=I=new Uint32Array(a);e.HEAPF32=Ca=new Float32Array(a);e.HEAPF64=Da=new Float64Array(a)}var Fa=e.INITIAL_MEMORY||16777216;
e.wasmMemory?C=e.wasmMemory:C=new WebAssembly.Memory({initial:Fa/65536,maximum:32768});C&&(G=C.buffer);Fa=G.byteLength;Ea(G);F[5836]=5266384;function Ga(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(e);else{var c=b.ia;"number"===typeof c?void 0===b.aa?e.dynCall_v(c):e.dynCall_vi(c,b.aa):c(void 0===b.aa?null:b.aa)}}}var Ha=[],Ia=[],Ja=[],Ka=[];function La(){var a=e.preRun.shift();Ha.unshift(a)}var J=0,Ma=null,Na=null;e.preloadedImages={};e.preloadedAudios={};
function A(a){if(e.onAbort)e.onAbort(a);B(a);pa=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");ca(a);throw a;}function Oa(a){var b=K;return String.prototype.startsWith?b.startsWith(a):0===b.indexOf(a)}function Pa(){return Oa("data:application/octet-stream;base64,")}var K="visdif.wasm";if(!Pa()){var Qa=K;K=e.locateFile?e.locateFile(Qa,z):z+Qa}
function Ra(){try{if(na)return new Uint8Array(na);if(ja)return ja(K);throw"both async and sync fetching of the wasm failed";}catch(a){A(a)}}function Sa(){return na||!ea&&!v||"function"!==typeof fetch||Oa("file://")?new Promise(function(a){a(Ra())}):fetch(K,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+K+"'";return a.arrayBuffer()}).catch(function(){return Ra()})}Ia.push({ia:function(){Ta()}});function Ua(){return 0<Ua.da}
function Va(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}var Wa=void 0;function L(a){for(var b="";D[a];)b+=Wa[D[a++]];return b}var M={},N={},Xa={};function Ya(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}
function Za(a,b){a=Ya(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)}function $a(a){var b=Error,c=Za(a,function(d){this.name=a;this.message=d;d=Error(d).stack;void 0!==d&&(this.stack=this.toString()+"\n"+d.replace(/^Error(:[^\n]*)?\n/,""))});c.prototype=Object.create(b.prototype);c.prototype.constructor=c;c.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message};return c}
var O=void 0;function R(a){throw new O(a);}var ab=void 0;function bb(a){throw new ab(a);}function cb(a,b,c){function d(h){h=c(h);h.length!==a.length&&bb("Mismatched type converter count");for(var m=0;m<a.length;++m)S(a[m],h[m])}a.forEach(function(h){Xa[h]=b});var f=Array(b.length),g=[],k=0;b.forEach(function(h,m){N.hasOwnProperty(h)?f[m]=N[h]:(g.push(h),M.hasOwnProperty(h)||(M[h]=[]),M[h].push(function(){f[m]=N[h];++k;k===g.length&&d(f)}))});0===g.length&&d(f)}
function S(a,b,c){c=c||{};if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var d=b.name;a||R('type "'+d+'" must have a positive integer typeid pointer');if(N.hasOwnProperty(a)){if(c.la)return;R("Cannot register type '"+d+"' twice")}N[a]=b;delete Xa[a];M.hasOwnProperty(a)&&(b=M[a],delete M[a],b.forEach(function(f){f()}))}function db(a){return{count:a.count,U:a.U,W:a.W,K:a.K,L:a.L,M:a.M,N:a.N}}
function eb(a){R(a.I.L.J.name+" instance already deleted")}var fb=!1;function gb(){}function hb(a){--a.count.value;0===a.count.value&&(a.M?a.N.T(a.M):a.L.J.T(a.K))}function ib(a){if("undefined"===typeof FinalizationGroup)return ib=function(b){return b},a;fb=new FinalizationGroup(function(b){for(var c=b.next();!c.done;c=b.next())c=c.value,c.K?hb(c):console.warn("object already deleted: "+c.K)});ib=function(b){fb.register(b,b.I,b.I);return b};gb=function(b){fb.unregister(b.I)};return ib(a)}
var jb=void 0,kb=[];function lb(){for(;kb.length;){var a=kb.pop();a.I.U=!1;a["delete"]()}}function T(){}var mb={};function nb(a,b,c){if(void 0===a[b].P){var d=a[b];a[b]=function(){a[b].P.hasOwnProperty(arguments.length)||R("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].P+")!");return a[b].P[arguments.length].apply(this,arguments)};a[b].P=[];a[b].P[d.Y]=d}}
function ob(a,b){e.hasOwnProperty(a)?(R("Cannot register public name '"+a+"' twice"),nb(e,a,a),e.hasOwnProperty(void 0)&&R("Cannot register multiple overloads of a function with the same number of arguments (undefined)!"),e[a].P[void 0]=b):e[a]=b}function pb(a,b,c,d,f,g,k,h){this.name=a;this.constructor=b;this.V=c;this.T=d;this.O=f;this.ja=g;this.X=k;this.ha=h;this.na=[]}
function qb(a,b,c){for(;b!==c;)b.X||R("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.X(a),b=b.O;return a}function rb(a,b){if(null===b)return this.ba&&R("null is not a valid "+this.name),0;b.I||R('Cannot pass "'+U(b)+'" as a '+this.name);b.I.K||R("Cannot pass deleted object as a pointer of type "+this.name);return qb(b.I.K,b.I.L.J,this.J)}
function ub(a,b){if(null===b){this.ba&&R("null is not a valid "+this.name);if(this.$){var c=this.oa();null!==a&&a.push(this.T,c);return c}return 0}b.I||R('Cannot pass "'+U(b)+'" as a '+this.name);b.I.K||R("Cannot pass deleted object as a pointer of type "+this.name);!this.Z&&b.I.L.Z&&R("Cannot convert argument of type "+(b.I.N?b.I.N.name:b.I.L.name)+" to parameter type "+this.name);c=qb(b.I.K,b.I.L.J,this.J);if(this.$)switch(void 0===b.I.M&&R("Passing raw pointer to smart pointer is illegal"),this.ra){case 0:b.I.N===
this?c=b.I.M:R("Cannot convert argument of type "+(b.I.N?b.I.N.name:b.I.L.name)+" to parameter type "+this.name);break;case 1:c=b.I.M;break;case 2:if(b.I.N===this)c=b.I.M;else{var d=b.clone();c=this.pa(c,vb(function(){d["delete"]()}));null!==a&&a.push(this.T,c)}break;default:R("Unsupporting sharing policy")}return c}
function wb(a,b){if(null===b)return this.ba&&R("null is not a valid "+this.name),0;b.I||R('Cannot pass "'+U(b)+'" as a '+this.name);b.I.K||R("Cannot pass deleted object as a pointer of type "+this.name);b.I.L.Z&&R("Cannot convert argument of type "+b.I.L.name+" to parameter type "+this.name);return qb(b.I.K,b.I.L.J,this.J)}function xb(a){return this.fromWireType(I[a>>2])}function yb(a,b,c){if(b===c)return a;if(void 0===c.O)return null;a=yb(a,b,c.O);return null===a?null:c.ha(a)}var zb={};
function Ab(a,b){for(void 0===b&&R("ptr should not be undefined");a.O;)b=a.X(b),a=a.O;return zb[b]}function Bb(a,b){b.L&&b.K||bb("makeClassHandle requires ptr and ptrType");!!b.N!==!!b.M&&bb("Both smartPtrType and smartPtr must be specified");b.count={value:1};return ib(Object.create(a,{I:{value:b}}))}function V(a,b,c,d){this.name=a;this.J=b;this.ba=c;this.Z=d;this.$=!1;this.T=this.pa=this.oa=this.fa=this.ra=this.ma=void 0;void 0!==b.O?this.toWireType=ub:(this.toWireType=d?rb:wb,this.R=null)}
function Cb(a,b){e.hasOwnProperty(a)||bb("Replacing nonexistant public symbol");e[a]=b;e[a].Y=void 0}function W(a,b){a=L(a);var c=e["dynCall_"+a];for(var d=[],f=1;f<a.length;++f)d.push("a"+f);f="return function dynCall_"+(a+"_"+b)+"("+d.join(", ")+") {\n";f+=" return dynCall(rawFunction"+(d.length?", ":"")+d.join(", ")+");\n";c=(new Function("dynCall","rawFunction",f+"};\n"))(c,b);"function"!==typeof c&&R("unknown function pointer with signature "+a+": "+b);return c}var Db=void 0;
function Eb(a){a=Fb(a);var b=L(a);X(a);return b}function Gb(a,b){function c(g){f[g]||N[g]||(Xa[g]?Xa[g].forEach(c):(d.push(g),f[g]=!0))}var d=[],f={};b.forEach(c);throw new Db(a+": "+d.map(Eb).join([", "]));}function Hb(a,b){for(var c=[],d=0;d<a;d++)c.push(F[(b>>2)+d]);return c}function Ib(a){for(;a.length;){var b=a.pop();a.pop()(b)}}
function Jb(a){var b=Function;if(!(b instanceof Function))throw new TypeError("new_ called with constructor type "+typeof b+" which is not a function");var c=Za(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}var Kb=[],Y=[{},{value:void 0},{value:null},{value:!0},{value:!1}];
function vb(a){switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=Kb.length?Kb.pop():Y.length;Y[b]={qa:1,value:a};return b}}function U(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a}function Lb(a,b){switch(b){case 2:return function(c){return this.fromWireType(Ca[c>>2])};case 3:return function(c){return this.fromWireType(Da[c>>3])};default:throw new TypeError("Unknown float type: "+a);}}
function Mb(a,b,c){switch(b){case 0:return c?function(d){return Ba[d]}:function(d){return D[d]};case 1:return c?function(d){return E[d>>1]}:function(d){return va[d>>1]};case 2:return c?function(d){return F[d>>2]}:function(d){return I[d>>2]};default:throw new TypeError("Unknown integer type: "+a);}}for(var Nb=[null,[],[]],Ob=Array(256),Pb=0;256>Pb;++Pb)Ob[Pb]=String.fromCharCode(Pb);Wa=Ob;O=e.BindingError=$a("BindingError");ab=e.InternalError=$a("InternalError");
T.prototype.isAliasOf=function(a){if(!(this instanceof T&&a instanceof T))return!1;var b=this.I.L.J,c=this.I.K,d=a.I.L.J;for(a=a.I.K;b.O;)c=b.X(c),b=b.O;for(;d.O;)a=d.X(a),d=d.O;return b===d&&c===a};T.prototype.clone=function(){this.I.K||eb(this);if(this.I.W)return this.I.count.value+=1,this;var a=ib(Object.create(Object.getPrototypeOf(this),{I:{value:db(this.I)}}));a.I.count.value+=1;a.I.U=!1;return a};
T.prototype["delete"]=function(){this.I.K||eb(this);this.I.U&&!this.I.W&&R("Object already scheduled for deletion");gb(this);hb(this.I);this.I.W||(this.I.M=void 0,this.I.K=void 0)};T.prototype.isDeleted=function(){return!this.I.K};T.prototype.deleteLater=function(){this.I.K||eb(this);this.I.U&&!this.I.W&&R("Object already scheduled for deletion");kb.push(this);1===kb.length&&jb&&jb(lb);this.I.U=!0;return this};V.prototype.ka=function(a){this.fa&&(a=this.fa(a));return a};
V.prototype.ea=function(a){this.T&&this.T(a)};V.prototype.argPackAdvance=8;V.prototype.readValueFromPointer=xb;V.prototype.deleteObject=function(a){if(null!==a)a["delete"]()};
V.prototype.fromWireType=function(a){function b(){return this.$?Bb(this.J.V,{L:this.ma,K:c,N:this,M:a}):Bb(this.J.V,{L:this,K:a})}var c=this.ka(a);if(!c)return this.ea(a),null;var d=Ab(this.J,c);if(void 0!==d){if(0===d.I.count.value)return d.I.K=c,d.I.M=a,d.clone();d=d.clone();this.ea(a);return d}d=this.J.ja(c);d=mb[d];if(!d)return b.call(this);d=this.Z?d.ga:d.pointerType;var f=yb(c,this.J,d.J);return null===f?b.call(this):this.$?Bb(d.J.V,{L:d,K:f,N:this,M:a}):Bb(d.J.V,{L:d,K:f})};
e.getInheritedInstanceCount=function(){return Object.keys(zb).length};e.getLiveInheritedInstances=function(){var a=[],b;for(b in zb)zb.hasOwnProperty(b)&&a.push(zb[b]);return a};e.flushPendingDeletes=lb;e.setDelayFunction=function(a){jb=a;kb.length&&jb&&jb(lb)};Db=e.UnboundTypeError=$a("UnboundTypeError");e.count_emval_handles=function(){for(var a=0,b=5;b<Y.length;++b)void 0!==Y[b]&&++a;return a};e.get_first_emval=function(){for(var a=5;a<Y.length;++a)if(void 0!==Y[a])return Y[a];return null};
var Rb={d:function(a,b,c,d){A("Assertion failed: "+(a?ra(D,a,void 0):"")+", at: "+[b?b?ra(D,b,void 0):"":"unknown filename",c,d?d?ra(D,d,void 0):"":"unknown function"])},s:function(a){return Qb(a)},o:function(a){"uncaught_exception"in Ua?Ua.da++:Ua.da=1;throw a;},j:function(a,b,c,d,f){var g=Va(c);b=L(b);S(a,{name:b,fromWireType:function(k){return!!k},toWireType:function(k,h){return h?d:f},argPackAdvance:8,readValueFromPointer:function(k){if(1===c)var h=Ba;else if(2===c)h=E;else if(4===c)h=F;else throw new TypeError("Unknown boolean type size: "+
b);return this.fromWireType(h[k>>g])},R:null})},n:function(a,b,c,d,f,g,k,h,m,l,n,t,u){n=L(n);g=W(f,g);h&&(h=W(k,h));l&&(l=W(m,l));u=W(t,u);var y=Ya(n);ob(y,function(){Gb("Cannot construct "+n+" due to unbound types",[d])});cb([a,b,c],d?[d]:[],function(r){r=r[0];if(d){var w=r.J;var p=w.V}else p=T.prototype;r=Za(y,function(){if(Object.getPrototypeOf(this)!==H)throw new O("Use 'new' to construct "+n);if(void 0===x.S)throw new O(n+" has no accessible constructor");var P=x.S[arguments.length];if(void 0===
P)throw new O("Tried to invoke ctor of "+n+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(x.S).toString()+") parameters instead!");return P.apply(this,arguments)});var H=Object.create(p,{constructor:{value:r}});r.prototype=H;var x=new pb(n,r,H,u,w,g,h,l);w=new V(n,x,!0,!1);p=new V(n+"*",x,!1,!1);var Z=new V(n+" const*",x,!1,!0);mb[a]={pointerType:p,ga:Z};Cb(y,r);return[w,p,Z]})},m:function(a,b,c,d,f,g){assert(0<b);var k=Hb(b,c);f=W(d,f);var h=[g],m=[];cb([],[a],
function(l){l=l[0];var n="constructor "+l.name;void 0===l.J.S&&(l.J.S=[]);if(void 0!==l.J.S[b-1])throw new O("Cannot register multiple constructors with identical number of parameters ("+(b-1)+") for class '"+l.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");l.J.S[b-1]=function(){Gb("Cannot construct "+l.name+" due to unbound types",k)};cb([],k,function(t){l.J.S[b-1]=function(){arguments.length!==b-1&&R(n+" called with "+arguments.length+
" arguments, expected "+(b-1));m.length=0;h.length=b;for(var u=1;u<b;++u)h[u]=t[u].toWireType(m,arguments[u-1]);u=f.apply(null,h);Ib(m);return t[0].fromWireType(u)};return[]});return[]})},l:function(a,b,c,d,f,g,k,h){var m=Hb(c,d);b=L(b);g=W(f,g);cb([],[a],function(l){function n(){Gb("Cannot call "+t+" due to unbound types",m)}l=l[0];var t=l.name+"."+b;h&&l.J.na.push(b);var u=l.J.V,y=u[b];void 0===y||void 0===y.P&&y.className!==l.name&&y.Y===c-2?(n.Y=c-2,n.className=l.name,u[b]=n):(nb(u,b,t),u[b].P[c-
2]=n);cb([],m,function(r){var w=t,p=l,H=g,x=r.length;2>x&&R("argTypes array size mismatch! Must at least get return value and 'this' types!");var Z=null!==r[1]&&null!==p,P=!1;for(p=1;p<r.length;++p)if(null!==r[p]&&void 0===r[p].R){P=!0;break}var sb="void"!==r[0].name,Q="",aa="";for(p=0;p<x-2;++p)Q+=(0!==p?", ":"")+"arg"+p,aa+=(0!==p?", ":"")+"arg"+p+"Wired";w="return function "+Ya(w)+"("+Q+") {\nif (arguments.length !== "+(x-2)+") {\nthrowBindingError('function "+w+" called with ' + arguments.length + ' arguments, expected "+
(x-2)+" args!');\n}\n";P&&(w+="var destructors = [];\n");var tb=P?"destructors":"null";Q="throwBindingError invoker fn runDestructors retType classParam".split(" ");H=[R,H,k,Ib,r[0],r[1]];Z&&(w+="var thisWired = classParam.toWireType("+tb+", this);\n");for(p=0;p<x-2;++p)w+="var arg"+p+"Wired = argType"+p+".toWireType("+tb+", arg"+p+"); // "+r[p+2].name+"\n",Q.push("argType"+p),H.push(r[p+2]);Z&&(aa="thisWired"+(0<aa.length?", ":"")+aa);w+=(sb?"var rv = ":"")+"invoker(fn"+(0<aa.length?", ":"")+aa+
");\n";if(P)w+="runDestructors(destructors);\n";else for(p=Z?1:2;p<r.length;++p)x=1===p?"thisWired":"arg"+(p-2)+"Wired",null!==r[p].R&&(w+=x+"_dtor("+x+"); // "+r[p].name+"\n",Q.push(x+"_dtor"),H.push(r[p].R));sb&&(w+="var ret = retType.fromWireType(rv);\nreturn ret;\n");Q.push(w+"}\n");r=Jb(Q).apply(null,H);void 0===u[b].P?(r.Y=c-2,u[b]=r):u[b].P[c-2]=r;return[]});return[]})},r:function(a,b){b=L(b);S(a,{name:b,fromWireType:function(c){var d=Y[c].value;4<c&&0===--Y[c].qa&&(Y[c]=void 0,Kb.push(c));
return d},toWireType:function(c,d){return vb(d)},argPackAdvance:8,readValueFromPointer:xb,R:null})},i:function(a,b,c){c=Va(c);b=L(b);S(a,{name:b,fromWireType:function(d){return d},toWireType:function(d,f){if("number"!==typeof f&&"boolean"!==typeof f)throw new TypeError('Cannot convert "'+U(f)+'" to '+this.name);return f},argPackAdvance:8,readValueFromPointer:Lb(b,c),R:null})},b:function(a,b,c,d,f){function g(l){return l}b=L(b);-1===f&&(f=4294967295);var k=Va(c);if(0===d){var h=32-8*c;g=function(l){return l<<
h>>>h}}var m=-1!=b.indexOf("unsigned");S(a,{name:b,fromWireType:g,toWireType:function(l,n){if("number"!==typeof n&&"boolean"!==typeof n)throw new TypeError('Cannot convert "'+U(n)+'" to '+this.name);if(n<d||n>f)throw new TypeError('Passing a number "'+U(n)+'" from JS side to C/C++ side to an argument of type "'+b+'", which is outside the valid range ['+d+", "+f+"]!");return m?n>>>0:n|0},argPackAdvance:8,readValueFromPointer:Mb(b,k,0!==d),R:null})},a:function(a,b,c){function d(g){g>>=2;var k=I;return new f(G,
k[g+1],k[g])}var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=L(c);S(a,{name:c,fromWireType:d,argPackAdvance:8,readValueFromPointer:d},{la:!0})},g:function(a,b){b=L(b);var c="std::string"===b;S(a,{name:b,fromWireType:function(d){var f=I[d>>2];if(c)for(var g=d+4,k=0;k<=f;++k){var h=d+4+k;if(k==f||0==D[h]){g=g?ra(D,g,h-g):"";if(void 0===m)var m=g;else m+=String.fromCharCode(0),m+=g;g=h+1}}else{m=Array(f);for(k=0;k<f;++k)m[k]=String.fromCharCode(D[d+
4+k]);m=m.join("")}X(d);return m},toWireType:function(d,f){f instanceof ArrayBuffer&&(f=new Uint8Array(f));var g="string"===typeof f;g||f instanceof Uint8Array||f instanceof Uint8ClampedArray||f instanceof Int8Array||R("Cannot pass non-string to std::string");var k=(c&&g?function(){for(var l=0,n=0;n<f.length;++n){var t=f.charCodeAt(n);55296<=t&&57343>=t&&(t=65536+((t&1023)<<10)|f.charCodeAt(++n)&1023);127>=t?++l:l=2047>=t?l+2:65535>=t?l+3:l+4}return l}:function(){return f.length})(),h=Qb(4+k+1);I[h>>
2]=k;if(c&&g)sa(f,h+4,k+1);else if(g)for(g=0;g<k;++g){var m=f.charCodeAt(g);255<m&&(X(h),R("String has UTF-16 code units that do not fit in 8 bits"));D[h+4+g]=m}else for(g=0;g<k;++g)D[h+4+g]=f[g];null!==d&&d.push(X,h);return h},argPackAdvance:8,readValueFromPointer:xb,R:function(d){X(d)}})},f:function(a,b,c){c=L(c);if(2===b){var d=ua;var f=wa;var g=xa;var k=function(){return va};var h=1}else 4===b&&(d=ya,f=za,g=Aa,k=function(){return I},h=2);S(a,{name:c,fromWireType:function(m){for(var l=I[m>>2],
n=k(),t,u=m+4,y=0;y<=l;++y){var r=m+4+y*b;if(y==l||0==n[r>>h])u=d(u,r-u),void 0===t?t=u:(t+=String.fromCharCode(0),t+=u),u=r+b}X(m);return t},toWireType:function(m,l){"string"!==typeof l&&R("Cannot pass non-string to C++ string type "+c);var n=g(l),t=Qb(4+n+b);I[t>>2]=n>>h;f(l,t+4,n+b);null!==m&&m.push(X,t);return t},argPackAdvance:8,readValueFromPointer:xb,R:function(m){X(m)}})},k:function(a,b){b=L(b);S(a,{sa:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},e:function(){A()},
q:function(a,b,c){D.copyWithin(a,b,b+c)},c:function(a){a>>>=0;var b=D.length;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);d=Math.max(16777216,a,d);0<d%65536&&(d+=65536-d%65536);a:{try{C.grow(Math.min(2147483648,d)-G.byteLength+65535>>>16);Ea(C.buffer);var f=1;break a}catch(g){}f=void 0}if(f)return!0}return!1},h:function(a,b,c,d){for(var f=0,g=0;g<c;g++){for(var k=F[b+8*g>>2],h=F[b+(8*g+4)>>2],m=0;m<h;m++){var l=D[k+m],n=Nb[a];0===l||10===l?((1===a?ma:
B)(ra(n,0)),n.length=0):n.push(l)}f+=h}F[d>>2]=f;return 0},memory:C,p:function(){},table:oa};
(function(){function a(f){e.asm=f.exports;J--;e.monitorRunDependencies&&e.monitorRunDependencies(J);0==J&&(null!==Ma&&(clearInterval(Ma),Ma=null),Na&&(f=Na,Na=null,f()))}function b(f){a(f.instance)}function c(f){return Sa().then(function(g){return WebAssembly.instantiate(g,d)}).then(f,function(g){B("failed to asynchronously prepare wasm: "+g);A(g)})}var d={a:Rb};J++;e.monitorRunDependencies&&e.monitorRunDependencies(J);if(e.instantiateWasm)try{return e.instantiateWasm(d,a)}catch(f){return B("Module.instantiateWasm callback failed with error: "+
f),!1}(function(){if(na||"function"!==typeof WebAssembly.instantiateStreaming||Pa()||Oa("file://")||"function"!==typeof fetch)return c(b);fetch(K,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,d).then(b,function(g){B("wasm streaming compile failed: "+g);B("falling back to ArrayBuffer instantiation");return c(b)})})})();return{}})();
var Ta=e.___wasm_call_ctors=function(){return(Ta=e.___wasm_call_ctors=e.asm.t).apply(null,arguments)},Qb=e._malloc=function(){return(Qb=e._malloc=e.asm.u).apply(null,arguments)},X=e._free=function(){return(X=e._free=e.asm.v).apply(null,arguments)},Fb=e.___getTypeName=function(){return(Fb=e.___getTypeName=e.asm.w).apply(null,arguments)};e.___embind_register_native_and_builtin_types=function(){return(e.___embind_register_native_and_builtin_types=e.asm.x).apply(null,arguments)};
e.dynCall_ii=function(){return(e.dynCall_ii=e.asm.y).apply(null,arguments)};e.dynCall_vi=function(){return(e.dynCall_vi=e.asm.z).apply(null,arguments)};e.dynCall_dii=function(){return(e.dynCall_dii=e.asm.A).apply(null,arguments)};e.dynCall_iiiii=function(){return(e.dynCall_iiiii=e.asm.B).apply(null,arguments)};e.dynCall_iiii=function(){return(e.dynCall_iiii=e.asm.C).apply(null,arguments)};e.dynCall_diii=function(){return(e.dynCall_diii=e.asm.D).apply(null,arguments)};
e.dynCall_viiiiii=function(){return(e.dynCall_viiiiii=e.asm.E).apply(null,arguments)};e.dynCall_viiiii=function(){return(e.dynCall_viiiii=e.asm.F).apply(null,arguments)};e.dynCall_viiii=function(){return(e.dynCall_viiii=e.asm.G).apply(null,arguments)};e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.H).apply(null,arguments)};var Sb;Na=function Tb(){Sb||Ub();Sb||(Na=Tb)};
function Ub(){function a(){if(!Sb&&(Sb=!0,e.calledRun=!0,!pa)){Ga(Ia);Ga(Ja);ba(e);if(e.onRuntimeInitialized)e.onRuntimeInitialized();if(e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();Ka.unshift(b)}Ga(Ka)}}if(!(0<J)){if(e.preRun)for("function"==typeof e.preRun&&(e.preRun=[e.preRun]);e.preRun.length;)La();Ga(Ha);0<J||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1);a()},1)):a())}}
e.run=Ub;if(e.preInit)for("function"==typeof e.preInit&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();noExitRuntime=!0;Ub();
return visdif.ready
}
);
})();
export default visdif;
if (typeof exports === 'object' && typeof module === 'object')
module.exports = visdif;
else if (typeof define === 'function' && define['amd'])
define([], function() { return visdif; });
else if (typeof exports === 'object')
exports["visdif"] = visdif;

BIN
codecs/visdif/visdif.wasm Executable file → Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
CODEC_URL = https://chromium.googlesource.com/codecs/libwebp2/+archive/413df7caeca5013fa9a51401660f7efd8572e0ae.tar.gz
CODEC_URL = https://chromium.googlesource.com/codecs/libwebp2/+archive/7c0dceb507efdec47f9d219e0b8be91092db8b48.tar.gz
CODEC_DIR = node_modules/wp2
CODEC_BUILD_ROOT := $(CODEC_DIR)/build
CODEC_BASELINE_BUILD_DIR := $(CODEC_BUILD_ROOT)/baseline
@@ -60,7 +60,6 @@ $(CODEC_MT_SIMD_BUILD_DIR)/Makefile: CMAKE_FLAGS+=-DWP2_ENABLE_SIMD=1
-DWP2_BUILD_TESTS=0 \
-DWP2_BUILD_EXAMPLES=0 \
-DWP2_BUILD_EXTRAS=0 \
-DWP2_REDUCED=1 \
-B $(@D) \
$(<D)

View File

@@ -44,7 +44,7 @@ b,c){A.copyWithin(a,b,b+c)},d:function(a){a>>>=0;var b=A.length;if(2147483648<a)
k);)++k;k=fa.decode(m.subarray?m.subarray(0,k):new Uint8Array(m.slice(0,k)));(1===a?da:v)(k);m.length=0}else m.push(k)}f+=h}E[d>>2]=f;return 0},a:z,t:function(){}};
(function(){function a(f){e.asm=f.exports;J=e.asm.w;K--;e.monitorRunDependencies&&e.monitorRunDependencies(K);0==K&&(null!==ya&&(clearInterval(ya),ya=null),L&&(f=L,L=null,f()))}function b(f){a(f.instance)}function c(f){return Ca().then(function(g){return WebAssembly.instantiate(g,d)}).then(f,function(g){v("failed to asynchronously prepare wasm: "+g);y(g)})}var d={a:mb};K++;e.monitorRunDependencies&&e.monitorRunDependencies(K);if(e.instantiateWasm)try{return e.instantiateWasm(d,a)}catch(f){return v("Module.instantiateWasm callback failed with error: "+
f),!1}(function(){return w||"function"!==typeof WebAssembly.instantiateStreaming||za()||"function"!==typeof fetch?c(b):fetch(N,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,d).then(b,function(g){v("wasm streaming compile failed: "+g);v("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})();
var kb=e.___wasm_call_ctors=function(){return(kb=e.___wasm_call_ctors=e.asm.x).apply(null,arguments)},Y=e._free=function(){return(Y=e._free=e.asm.y).apply(null,arguments)},lb=e._malloc=function(){return(lb=e._malloc=e.asm.z).apply(null,arguments)},bb=e.___getTypeName=function(){return(bb=e.___getTypeName=e.asm.A).apply(null,arguments)};e.___embind_register_native_and_builtin_types=function(){return(e.___embind_register_native_and_builtin_types=e.asm.B).apply(null,arguments)};
var kb=e.___wasm_call_ctors=function(){return(kb=e.___wasm_call_ctors=e.asm.x).apply(null,arguments)},lb=e._malloc=function(){return(lb=e._malloc=e.asm.y).apply(null,arguments)},Y=e._free=function(){return(Y=e._free=e.asm.z).apply(null,arguments)},bb=e.___getTypeName=function(){return(bb=e.___getTypeName=e.asm.A).apply(null,arguments)};e.___embind_register_native_and_builtin_types=function(){return(e.___embind_register_native_and_builtin_types=e.asm.B).apply(null,arguments)};
e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.C).apply(null,arguments)};var nb;L=function ob(){nb||pb();nb||(L=ob)};
function pb(){function a(){if(!nb&&(nb=!0,e.calledRun=!0,!ea)){O(ua);O(va);aa(e);if(e.onRuntimeInitialized)e.onRuntimeInitialized();if(e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();wa.unshift(b)}O(wa)}}if(!(0<K)){if(e.preRun)for("function"==typeof e.preRun&&(e.preRun=[e.preRun]);e.preRun.length;)xa();O(ta);0<K||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1);a()},1)):a())}}
e.run=pb;if(e.preInit)for("function"==typeof e.preInit&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();noExitRuntime=!0;pb();

BIN
codecs/wp2/dec/wp2_dec.wasm Executable file → Normal file

Binary file not shown.

View File

@@ -44,7 +44,7 @@ b,c){z.copyWithin(a,b,b+c)},d:function(a){a>>>=0;var b=z.length;if(2147483648<a)
0;n[p]&&!(NaN<=p);)++p;p=ka.decode(n.subarray?n.subarray(0,p):new Uint8Array(n.slice(0,p)));m(p);n.length=0}else n.push(m)}f+=h}D[d>>2]=f;return 0},a:y,t:function(){}};
(function(){function a(f){e.asm=f.exports;I=e.asm.w;J--;e.monitorRunDependencies&&e.monitorRunDependencies(J);0==J&&(null!==Ca&&(clearInterval(Ca),Ca=null),K&&(f=K,K=null,f()))}function b(f){a(f.instance)}function c(f){return Promise.resolve().then(Fa).then(function(g){return WebAssembly.instantiate(g,d)}).then(f,function(g){v("failed to asynchronously prepare wasm: "+g);u(g)})}var d={a:ob};J++;e.monitorRunDependencies&&e.monitorRunDependencies(J);if(e.instantiateWasm)try{return e.instantiateWasm(d,
a)}catch(f){return v("Module.instantiateWasm callback failed with error: "+f),!1}(function(){return w||"function"!==typeof WebAssembly.instantiateStreaming||Da()||"function"!==typeof fetch?c(b):fetch(M,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,d).then(b,function(g){v("wasm streaming compile failed: "+g);v("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})();
var nb=e.___wasm_call_ctors=function(){return(nb=e.___wasm_call_ctors=e.asm.x).apply(null,arguments)},X=e._free=function(){return(X=e._free=e.asm.y).apply(null,arguments)},Z=e._malloc=function(){return(Z=e._malloc=e.asm.z).apply(null,arguments)},eb=e.___getTypeName=function(){return(eb=e.___getTypeName=e.asm.A).apply(null,arguments)};e.___embind_register_native_and_builtin_types=function(){return(e.___embind_register_native_and_builtin_types=e.asm.B).apply(null,arguments)};
var nb=e.___wasm_call_ctors=function(){return(nb=e.___wasm_call_ctors=e.asm.x).apply(null,arguments)},Z=e._malloc=function(){return(Z=e._malloc=e.asm.y).apply(null,arguments)},X=e._free=function(){return(X=e._free=e.asm.z).apply(null,arguments)},eb=e.___getTypeName=function(){return(eb=e.___getTypeName=e.asm.A).apply(null,arguments)};e.___embind_register_native_and_builtin_types=function(){return(e.___embind_register_native_and_builtin_types=e.asm.B).apply(null,arguments)};
e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.C).apply(null,arguments)};var pb;K=function qb(){pb||rb();pb||(K=qb)};
function rb(){function a(){if(!pb&&(pb=!0,e.calledRun=!0,!ja)){N(ya);N(za);aa(e);if(e.onRuntimeInitialized)e.onRuntimeInitialized();if(e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();Aa.unshift(b)}N(Aa)}}if(!(0<J)){if(e.preRun)for("function"==typeof e.preRun&&(e.preRun=[e.preRun]);e.preRun.length;)Ba();N(xa);0<J||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1);a()},1)):a())}}
e.run=rb;if(e.preInit)for("function"==typeof e.preInit&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();noExitRuntime=!0;rb();

Binary file not shown.

View File

@@ -47,7 +47,7 @@ a,d);0<d%65536&&(d+=65536-d%65536);a:{try{B.grow(Math.min(2147483648,d)-I.byteLe
a:B,s:function(){}};
(function(){function a(e){f.asm=e.exports;L=f.asm.C;M--;f.monitorRunDependencies&&f.monitorRunDependencies(M);0==M&&(null!==za&&(clearInterval(za),za=null),N&&(e=N,N=null,e()))}function b(e){a(e.instance)}function c(e){return Da().then(function(g){return WebAssembly.instantiate(g,d)}).then(e,function(g){v("failed to asynchronously prepare wasm: "+g);A(g)})}var d={a:ob};M++;f.monitorRunDependencies&&f.monitorRunDependencies(M);if(f.instantiateWasm)try{return f.instantiateWasm(d,a)}catch(e){return v("Module.instantiateWasm callback failed with error: "+
e),!1}(function(){return w||"function"!==typeof WebAssembly.instantiateStreaming||Aa()||"function"!==typeof fetch?c(b):fetch(O,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(b,function(g){v("wasm streaming compile failed: "+g);v("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})();
var mb=f.___wasm_call_ctors=function(){return(mb=f.___wasm_call_ctors=f.asm.D).apply(null,arguments)},Z=f._free=function(){return(Z=f._free=f.asm.E).apply(null,arguments)},nb=f._malloc=function(){return(nb=f._malloc=f.asm.F).apply(null,arguments)},cb=f.___getTypeName=function(){return(cb=f.___getTypeName=f.asm.G).apply(null,arguments)};f.___embind_register_native_and_builtin_types=function(){return(f.___embind_register_native_and_builtin_types=f.asm.H).apply(null,arguments)};
var mb=f.___wasm_call_ctors=function(){return(mb=f.___wasm_call_ctors=f.asm.D).apply(null,arguments)},nb=f._malloc=function(){return(nb=f._malloc=f.asm.E).apply(null,arguments)},Z=f._free=function(){return(Z=f._free=f.asm.F).apply(null,arguments)},cb=f.___getTypeName=function(){return(cb=f.___getTypeName=f.asm.G).apply(null,arguments)};f.___embind_register_native_and_builtin_types=function(){return(f.___embind_register_native_and_builtin_types=f.asm.H).apply(null,arguments)};
f.dynCall_jiji=function(){return(f.dynCall_jiji=f.asm.I).apply(null,arguments)};var pb;N=function qb(){pb||rb();pb||(N=qb)};
function rb(){function a(){if(!pb&&(pb=!0,f.calledRun=!0,!ea)){P(va);P(wa);aa(f);if(f.onRuntimeInitialized)f.onRuntimeInitialized();if(f.postRun)for("function"==typeof f.postRun&&(f.postRun=[f.postRun]);f.postRun.length;){var b=f.postRun.shift();xa.unshift(b)}P(xa)}}if(!(0<M)){if(f.preRun)for("function"==typeof f.preRun&&(f.preRun=[f.preRun]);f.preRun.length;)ya();P(ua);0<M||(f.setStatus?(f.setStatus("Running..."),setTimeout(function(){setTimeout(function(){f.setStatus("")},1);a()},1)):a())}}
f.run=rb;if(f.preInit)for("function"==typeof f.preInit&&(f.preInit=[f.preInit]);0<f.preInit.length;)f.preInit.pop()();noExitRuntime=!0;rb();

BIN
codecs/wp2/enc/wp2_enc.wasm Executable file → Normal file

Binary file not shown.

View File

@@ -17,7 +17,7 @@ function Ba(a){return 2*a.length}function Ca(a,b){for(var c=0,d="";!(c>=b/4);){v
function Ea(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}var m,aa,ca,da,fa,ha,ia,ka,ma;function p(a){m=a;A.HEAP8=aa=new Int8Array(a);A.HEAP16=da=new Int16Array(a);A.HEAP32=ha=new Int32Array(a);A.HEAPU8=ca=new Uint8Array(a);A.HEAPU16=fa=new Uint16Array(a);A.HEAPU32=ia=new Uint32Array(a);A.HEAPF32=ka=new Float32Array(a);A.HEAPF64=ma=new Float64Array(a)}var Fa=A.INITIAL_MEMORY||16777216;
if(D)k=A.wasmMemory,m=A.buffer;else if(A.wasmMemory)k=A.wasmMemory;else if(k=new WebAssembly.Memory({initial:Fa/65536,maximum:32768,shared:!0}),!(k.buffer instanceof SharedArrayBuffer))throw H("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");k&&(m=k.buffer);Fa=m.byteLength;p(m);var L,Ga=[],Ha=[],Ia=[],Ja=[];
function Ka(){var a=A.preRun.shift();Ga.unshift(a)}var N=0,La=null,O=null;A.preloadedImages={};A.preloadedAudios={};function J(a){if(A.onAbort)A.onAbort(a);D&&console.error("Pthread aborting at "+Error().stack);H(a);ua=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");oa(a);throw a;}function Ma(){var a=P;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var P="wp2_enc_mt.wasm";
Ma()||(P=qa(P));function Na(){try{if(I)return new Uint8Array(I);if(ra)return ra(P);throw"both async and sync fetching of the wasm failed";}catch(a){J(a)}}function Oa(){return I||"function"!==typeof fetch?Promise.resolve().then(Na):fetch(P,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+P+"'";return a.arrayBuffer()}).catch(function(){return Na()})}var Qa={109389:function(a,b){setTimeout(function(){Pa(a,b)},0)},109467:function(){throw"Canceled!";}};
Ma()||(P=qa(P));function Na(){try{if(I)return new Uint8Array(I);if(ra)return ra(P);throw"both async and sync fetching of the wasm failed";}catch(a){J(a)}}function Oa(){return I||"function"!==typeof fetch?Promise.resolve().then(Na):fetch(P,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+P+"'";return a.arrayBuffer()}).catch(function(){return Na()})}var Qa={124965:function(a,b){setTimeout(function(){Pa(a,b)},0)},125043:function(){throw"Canceled!";}};
function Ra(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(A);else{var c=b.mb;"number"===typeof c?void 0===b.Ka?L.get(c)():L.get(c)(b.Ka):c(void 0===b.Ka?null:b.Ka)}}}function Sa(a,b,c){var d;-1!=a.indexOf("j")?d=c&&c.length?A["dynCall_"+a].apply(null,[b].concat(c)):A["dynCall_"+a].call(null,b):d=L.get(b).apply(null,c);return d}A.dynCall=Sa;var Q=0,Ta=0,Ua=0;function Va(a,b,c){Q=a|0;Ua=b|0;Ta=c|0}A.registerPthreadPtr=Va;
function Wa(a,b){if(0>=a||a>e().length||a&1||0>b)return-28;if(0==b)return 0;2147483647<=b&&(b=Infinity);var c=Atomics.load(y(),R.bb>>2),d=0;if(c==a&&Atomics.compareExchange(y(),R.bb>>2,c,0)==c&&(--b,d=1,0>=b))return 1;a=Atomics.notify(y(),a>>2,b);if(0<=a)return a+d;throw"Atomics.notify returned an unexpected value "+a;}A._emscripten_futex_wake=Wa;
function Xa(a){if(D)throw"Internal Error! cleanupThread() can only ever be called from main application thread!";if(!a)throw"Internal Error! Null pthread_ptr in cleanupThread!";y()[a+12>>2]=0;(a=R.Ea[a])&&R.Qa(a.worker)}
@@ -75,7 +75,7 @@ x+108+24>>2);h&&(y()[h>>2]=E);n&&(y()[n>>2]=x)}else H("pthread_getschedparam cal
B:function(){}};
(function(){function a(f,g){A.asm=f.exports;L=A.asm.V;ta=g;if(!D){var l=R.Ca.length;R.Ca.forEach(function(h){R.ab(h,function(){if(!--l&&(N--,A.monitorRunDependencies&&A.monitorRunDependencies(N),0==N&&(null!==La&&(clearInterval(La),La=null),O))){var n=O;O=null;n()}})})}}function b(f){a(f.instance,f.module)}function c(f){return Oa().then(function(g){return WebAssembly.instantiate(g,d)}).then(f,function(g){H("failed to asynchronously prepare wasm: "+g);J(g)})}var d={a:rc};D||(va(!D,"addRunDependency cannot be used in a pthread worker"),
N++,A.monitorRunDependencies&&A.monitorRunDependencies(N));if(A.instantiateWasm)try{return A.instantiateWasm(d,a)}catch(f){return H("Module.instantiateWasm callback failed with error: "+f),!1}(function(){return I||"function"!==typeof WebAssembly.instantiateStreaming||Ma()||"function"!==typeof fetch?c(b):fetch(P,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,d).then(b,function(g){H("wasm streaming compile failed: "+g);H("falling back to ArrayBuffer instantiation");
return c(b)})})})().catch(oa);return{}})();var oc=A.___wasm_call_ctors=function(){return(oc=A.___wasm_call_ctors=A.asm.W).apply(null,arguments)},T=A._free=function(){return(T=A._free=A.asm.X).apply(null,arguments)},S=A._malloc=function(){return(S=A._malloc=A.asm.Y).apply(null,arguments)},Gb=A.___getTypeName=function(){return(Gb=A.___getTypeName=A.asm.Z).apply(null,arguments)};
return c(b)})})})().catch(oa);return{}})();var oc=A.___wasm_call_ctors=function(){return(oc=A.___wasm_call_ctors=A.asm.W).apply(null,arguments)},S=A._malloc=function(){return(S=A._malloc=A.asm.X).apply(null,arguments)},T=A._free=function(){return(T=A._free=A.asm.Y).apply(null,arguments)},Gb=A.___getTypeName=function(){return(Gb=A.___getTypeName=A.asm.Z).apply(null,arguments)};
A.___embind_register_native_and_builtin_types=function(){return(A.___embind_register_native_and_builtin_types=A.asm._).apply(null,arguments)};var ic=A._emscripten_get_global_libc=function(){return(ic=A._emscripten_get_global_libc=A.asm.$).apply(null,arguments)};A.___em_js__initPthreadsJS=function(){return(A.___em_js__initPthreadsJS=A.asm.aa).apply(null,arguments)};
var Pb=A.stackSave=function(){return(Pb=A.stackSave=A.asm.ba).apply(null,arguments)},cb=A.stackRestore=function(){return(cb=A.stackRestore=A.asm.ca).apply(null,arguments)},Qb=A.stackAlloc=function(){return(Qb=A.stackAlloc=A.asm.da).apply(null,arguments)},qc=A._memalign=function(){return(qc=A._memalign=A.asm.ea).apply(null,arguments)};A._emscripten_main_browser_thread_id=function(){return(A._emscripten_main_browser_thread_id=A.asm.fa).apply(null,arguments)};
var $a=A.___pthread_tsd_run_dtors=function(){return($a=A.___pthread_tsd_run_dtors=A.asm.ga).apply(null,arguments)},ab=A._emscripten_main_thread_process_queued_calls=function(){return(ab=A._emscripten_main_thread_process_queued_calls=A.asm.ha).apply(null,arguments)};A._emscripten_current_thread_process_queued_calls=function(){return(A._emscripten_current_thread_process_queued_calls=A.asm.ia).apply(null,arguments)};
@@ -84,7 +84,7 @@ A._emscripten_sync_run_in_main_thread=function(){return(A._emscripten_sync_run_i
A._emscripten_sync_run_in_main_thread_2=function(){return(A._emscripten_sync_run_in_main_thread_2=A.asm.pa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_xprintf_varargs=function(){return(A._emscripten_sync_run_in_main_thread_xprintf_varargs=A.asm.qa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_3=function(){return(A._emscripten_sync_run_in_main_thread_3=A.asm.ra).apply(null,arguments)};
var pc=A._emscripten_sync_run_in_main_thread_4=function(){return(pc=A._emscripten_sync_run_in_main_thread_4=A.asm.sa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_5=function(){return(A._emscripten_sync_run_in_main_thread_5=A.asm.ta).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_6=function(){return(A._emscripten_sync_run_in_main_thread_6=A.asm.ua).apply(null,arguments)};
A._emscripten_sync_run_in_main_thread_7=function(){return(A._emscripten_sync_run_in_main_thread_7=A.asm.va).apply(null,arguments)};var Rb=A._emscripten_run_in_main_runtime_thread_js=function(){return(Rb=A._emscripten_run_in_main_runtime_thread_js=A.asm.wa).apply(null,arguments)},Xb=A.__emscripten_call_on_thread=function(){return(Xb=A.__emscripten_call_on_thread=A.asm.xa).apply(null,arguments)};A._emscripten_tls_init=function(){return(A._emscripten_tls_init=A.asm.ya).apply(null,arguments)};
A.dynCall_jiji=function(){return(A.dynCall_jiji=A.asm.za).apply(null,arguments)};var Za=A._main_thread_futex=124012;A.PThread=R;A.PThread=R;A._pthread_self=jc;A.wasmMemory=k;A.ExitStatus=sc;var tc;function sc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}O=function uc(){tc||vc();tc||(O=uc)};
A.dynCall_jiji=function(){return(A.dynCall_jiji=A.asm.za).apply(null,arguments)};var Za=A._main_thread_futex=139708;A.PThread=R;A.PThread=R;A._pthread_self=jc;A.wasmMemory=k;A.ExitStatus=sc;var tc;function sc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}O=function uc(){tc||vc();tc||(O=uc)};
function vc(){function a(){if(!tc&&(tc=!0,A.calledRun=!0,!ua)){Ra(Ha);D||Ra(Ia);na(A);if(A.onRuntimeInitialized)A.onRuntimeInitialized();if(!D){if(A.postRun)for("function"==typeof A.postRun&&(A.postRun=[A.postRun]);A.postRun.length;){var b=A.postRun.shift();Ja.unshift(b)}Ra(Ja)}}}if(!(0<N)){if(!D){if(A.preRun)for("function"==typeof A.preRun&&(A.preRun=[A.preRun]);A.preRun.length;)Ka();Ra(Ga)}0<N||(A.setStatus?(A.setStatus("Running..."),setTimeout(function(){setTimeout(function(){A.setStatus("")},
1);a()},1)):a())}}A.run=vc;if(A.preInit)for("function"==typeof A.preInit&&(A.preInit=[A.preInit]);0<A.preInit.length;)A.preInit.pop()();D||(noExitRuntime=!0);D?R.wb():vc();

BIN
codecs/wp2/enc/wp2_enc_mt.wasm Executable file → Normal file

Binary file not shown.

View File

@@ -17,7 +17,7 @@ function Ba(a){return 2*a.length}function Ca(a,b){for(var c=0,d="";!(c>=b/4);){v
function Ea(a){for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=d&&++c;b+=4}return b}var m,aa,ca,da,fa,ha,ia,ka,ma;function p(a){m=a;A.HEAP8=aa=new Int8Array(a);A.HEAP16=da=new Int16Array(a);A.HEAP32=ha=new Int32Array(a);A.HEAPU8=ca=new Uint8Array(a);A.HEAPU16=fa=new Uint16Array(a);A.HEAPU32=ia=new Uint32Array(a);A.HEAPF32=ka=new Float32Array(a);A.HEAPF64=ma=new Float64Array(a)}var Fa=A.INITIAL_MEMORY||16777216;
if(D)k=A.wasmMemory,m=A.buffer;else if(A.wasmMemory)k=A.wasmMemory;else if(k=new WebAssembly.Memory({initial:Fa/65536,maximum:32768,shared:!0}),!(k.buffer instanceof SharedArrayBuffer))throw H("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");k&&(m=k.buffer);Fa=m.byteLength;p(m);var L,Ga=[],Ha=[],Ia=[],Ja=[];
function Ka(){var a=A.preRun.shift();Ga.unshift(a)}var N=0,La=null,O=null;A.preloadedImages={};A.preloadedAudios={};function J(a){if(A.onAbort)A.onAbort(a);D&&console.error("Pthread aborting at "+Error().stack);H(a);ua=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");oa(a);throw a;}function Ma(){var a=P;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var P="wp2_enc_mt_simd.wasm";
Ma()||(P=qa(P));function Na(){try{if(I)return new Uint8Array(I);if(ra)return ra(P);throw"both async and sync fetching of the wasm failed";}catch(a){J(a)}}function Oa(){return I||"function"!==typeof fetch?Promise.resolve().then(Na):fetch(P,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+P+"'";return a.arrayBuffer()}).catch(function(){return Na()})}var Qa={109469:function(a,b){setTimeout(function(){Pa(a,b)},0)},109547:function(){throw"Canceled!";}};
Ma()||(P=qa(P));function Na(){try{if(I)return new Uint8Array(I);if(ra)return ra(P);throw"both async and sync fetching of the wasm failed";}catch(a){J(a)}}function Oa(){return I||"function"!==typeof fetch?Promise.resolve().then(Na):fetch(P,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+P+"'";return a.arrayBuffer()}).catch(function(){return Na()})}var Qa={125045:function(a,b){setTimeout(function(){Pa(a,b)},0)},125123:function(){throw"Canceled!";}};
function Ra(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(A);else{var c=b.ob;"number"===typeof c?void 0===b.Ma?L.get(c)():L.get(c)(b.Ma):c(void 0===b.Ma?null:b.Ma)}}}function Sa(a,b,c){var d;-1!=a.indexOf("j")?d=c&&c.length?A["dynCall_"+a].apply(null,[b].concat(c)):A["dynCall_"+a].call(null,b):d=L.get(b).apply(null,c);return d}A.dynCall=Sa;var Q=0,Ta=0,Ua=0;function Va(a,b,c){Q=a|0;Ua=b|0;Ta=c|0}A.registerPthreadPtr=Va;
function Wa(a,b){if(0>=a||a>e().length||a&1||0>b)return-28;if(0==b)return 0;2147483647<=b&&(b=Infinity);var c=Atomics.load(y(),R.eb>>2),d=0;if(c==a&&Atomics.compareExchange(y(),R.eb>>2,c,0)==c&&(--b,d=1,0>=b))return 1;a=Atomics.notify(y(),a>>2,b);if(0<=a)return a+d;throw"Atomics.notify returned an unexpected value "+a;}A._emscripten_futex_wake=Wa;
function Xa(a){if(D)throw"Internal Error! cleanupThread() can only ever be called from main application thread!";if(!a)throw"Internal Error! Null pthread_ptr in cleanupThread!";y()[a+12>>2]=0;(a=R.Ga[a])&&R.Sa(a.worker)}
@@ -76,7 +76,7 @@ x+108+24>>2);h&&(y()[h>>2]=E);n&&(y()[n>>2]=x)}else H("pthread_getschedparam cal
o:function(){}};
(function(){function a(f,g){A.asm=f.exports;L=A.asm.V;ta=g;if(!D){var l=R.Ea.length;R.Ea.forEach(function(h){R.cb(h,function(){if(!--l&&(N--,A.monitorRunDependencies&&A.monitorRunDependencies(N),0==N&&(null!==La&&(clearInterval(La),La=null),O))){var n=O;O=null;n()}})})}}function b(f){a(f.instance,f.module)}function c(f){return Oa().then(function(g){return WebAssembly.instantiate(g,d)}).then(f,function(g){H("failed to asynchronously prepare wasm: "+g);J(g)})}var d={a:rc};D||(va(!D,"addRunDependency cannot be used in a pthread worker"),
N++,A.monitorRunDependencies&&A.monitorRunDependencies(N));if(A.instantiateWasm)try{return A.instantiateWasm(d,a)}catch(f){return H("Module.instantiateWasm callback failed with error: "+f),!1}(function(){return I||"function"!==typeof WebAssembly.instantiateStreaming||Ma()||"function"!==typeof fetch?c(b):fetch(P,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,d).then(b,function(g){H("wasm streaming compile failed: "+g);H("falling back to ArrayBuffer instantiation");
return c(b)})})})().catch(oa);return{}})();var oc=A.___wasm_call_ctors=function(){return(oc=A.___wasm_call_ctors=A.asm.W).apply(null,arguments)},T=A._free=function(){return(T=A._free=A.asm.X).apply(null,arguments)},S=A._malloc=function(){return(S=A._malloc=A.asm.Y).apply(null,arguments)},Gb=A.___getTypeName=function(){return(Gb=A.___getTypeName=A.asm.Z).apply(null,arguments)};
return c(b)})})})().catch(oa);return{}})();var oc=A.___wasm_call_ctors=function(){return(oc=A.___wasm_call_ctors=A.asm.W).apply(null,arguments)},S=A._malloc=function(){return(S=A._malloc=A.asm.X).apply(null,arguments)},T=A._free=function(){return(T=A._free=A.asm.Y).apply(null,arguments)},Gb=A.___getTypeName=function(){return(Gb=A.___getTypeName=A.asm.Z).apply(null,arguments)};
A.___embind_register_native_and_builtin_types=function(){return(A.___embind_register_native_and_builtin_types=A.asm._).apply(null,arguments)};var ic=A._emscripten_get_global_libc=function(){return(ic=A._emscripten_get_global_libc=A.asm.$).apply(null,arguments)};A.___em_js__initPthreadsJS=function(){return(A.___em_js__initPthreadsJS=A.asm.aa).apply(null,arguments)};
var Pb=A.stackSave=function(){return(Pb=A.stackSave=A.asm.ba).apply(null,arguments)},cb=A.stackRestore=function(){return(cb=A.stackRestore=A.asm.ca).apply(null,arguments)},Qb=A.stackAlloc=function(){return(Qb=A.stackAlloc=A.asm.da).apply(null,arguments)},qc=A._memalign=function(){return(qc=A._memalign=A.asm.ea).apply(null,arguments)};A._emscripten_main_browser_thread_id=function(){return(A._emscripten_main_browser_thread_id=A.asm.fa).apply(null,arguments)};
var $a=A.___pthread_tsd_run_dtors=function(){return($a=A.___pthread_tsd_run_dtors=A.asm.ga).apply(null,arguments)},ab=A._emscripten_main_thread_process_queued_calls=function(){return(ab=A._emscripten_main_thread_process_queued_calls=A.asm.ha).apply(null,arguments)};A._emscripten_current_thread_process_queued_calls=function(){return(A._emscripten_current_thread_process_queued_calls=A.asm.ia).apply(null,arguments)};
@@ -85,7 +85,7 @@ A._emscripten_sync_run_in_main_thread=function(){return(A._emscripten_sync_run_i
A._emscripten_sync_run_in_main_thread_2=function(){return(A._emscripten_sync_run_in_main_thread_2=A.asm.pa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_xprintf_varargs=function(){return(A._emscripten_sync_run_in_main_thread_xprintf_varargs=A.asm.qa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_3=function(){return(A._emscripten_sync_run_in_main_thread_3=A.asm.ra).apply(null,arguments)};
var pc=A._emscripten_sync_run_in_main_thread_4=function(){return(pc=A._emscripten_sync_run_in_main_thread_4=A.asm.sa).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_5=function(){return(A._emscripten_sync_run_in_main_thread_5=A.asm.ta).apply(null,arguments)};A._emscripten_sync_run_in_main_thread_6=function(){return(A._emscripten_sync_run_in_main_thread_6=A.asm.ua).apply(null,arguments)};
A._emscripten_sync_run_in_main_thread_7=function(){return(A._emscripten_sync_run_in_main_thread_7=A.asm.va).apply(null,arguments)};var Rb=A._emscripten_run_in_main_runtime_thread_js=function(){return(Rb=A._emscripten_run_in_main_runtime_thread_js=A.asm.wa).apply(null,arguments)},Xb=A.__emscripten_call_on_thread=function(){return(Xb=A.__emscripten_call_on_thread=A.asm.xa).apply(null,arguments)};A._emscripten_tls_init=function(){return(A._emscripten_tls_init=A.asm.ya).apply(null,arguments)};
A.dynCall_jiii=function(){return(A.dynCall_jiii=A.asm.za).apply(null,arguments)};A.dynCall_jiiiiii=function(){return(A.dynCall_jiiiiii=A.asm.Aa).apply(null,arguments)};A.dynCall_jiji=function(){return(A.dynCall_jiji=A.asm.Ba).apply(null,arguments)};var Za=A._main_thread_futex=124172;A.PThread=R;A.PThread=R;A._pthread_self=jc;A.wasmMemory=k;A.ExitStatus=sc;var tc;function sc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}O=function uc(){tc||vc();tc||(O=uc)};
A.dynCall_jiii=function(){return(A.dynCall_jiii=A.asm.za).apply(null,arguments)};A.dynCall_jiiiiii=function(){return(A.dynCall_jiiiiii=A.asm.Aa).apply(null,arguments)};A.dynCall_jiji=function(){return(A.dynCall_jiji=A.asm.Ba).apply(null,arguments)};var Za=A._main_thread_futex=139852;A.PThread=R;A.PThread=R;A._pthread_self=jc;A.wasmMemory=k;A.ExitStatus=sc;var tc;function sc(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}O=function uc(){tc||vc();tc||(O=uc)};
function vc(){function a(){if(!tc&&(tc=!0,A.calledRun=!0,!ua)){Ra(Ha);D||Ra(Ia);na(A);if(A.onRuntimeInitialized)A.onRuntimeInitialized();if(!D){if(A.postRun)for("function"==typeof A.postRun&&(A.postRun=[A.postRun]);A.postRun.length;){var b=A.postRun.shift();Ja.unshift(b)}Ra(Ja)}}}if(!(0<N)){if(!D){if(A.preRun)for("function"==typeof A.preRun&&(A.preRun=[A.preRun]);A.preRun.length;)Ka();Ra(Ga)}0<N||(A.setStatus?(A.setStatus("Running..."),setTimeout(function(){setTimeout(function(){A.setStatus("")},
1);a()},1)):a())}}A.run=vc;if(A.preInit)for("function"==typeof A.preInit&&(A.preInit=[A.preInit]);0<A.preInit.length;)A.preInit.pop()();D||(noExitRuntime=!0);D?R.yb():vc();

BIN
codecs/wp2/enc/wp2_enc_mt_simd.wasm Executable file → Normal file

Binary file not shown.

View File

@@ -48,7 +48,7 @@ a,d);0<d%65536&&(d+=65536-d%65536);a:{try{A.grow(Math.min(2147483648,d)-H.byteLe
2]=e;return 0},a:A,s:function(){}};
(function(){function a(e){f.asm=e.exports;K=f.asm.C;L--;f.monitorRunDependencies&&f.monitorRunDependencies(L);0==L&&(null!==Da&&(clearInterval(Da),Da=null),M&&(e=M,M=null,e()))}function b(e){a(e.instance)}function c(e){return Promise.resolve().then(Ga).then(function(g){return WebAssembly.instantiate(g,d)}).then(e,function(g){v("failed to asynchronously prepare wasm: "+g);u(g)})}var d={a:qb};L++;f.monitorRunDependencies&&f.monitorRunDependencies(L);if(f.instantiateWasm)try{return f.instantiateWasm(d,a)}catch(e){return v("Module.instantiateWasm callback failed with error: "+
e),!1}(function(){return w||"function"!==typeof WebAssembly.instantiateStreaming||Ea()||"function"!==typeof fetch?c(b):fetch(N,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,d).then(b,function(g){v("wasm streaming compile failed: "+g);v("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ba);return{}})();
var ob=f.___wasm_call_ctors=function(){return(ob=f.___wasm_call_ctors=f.asm.D).apply(null,arguments)},Z=f._free=function(){return(Z=f._free=f.asm.E).apply(null,arguments)},pb=f._malloc=function(){return(pb=f._malloc=f.asm.F).apply(null,arguments)},eb=f.___getTypeName=function(){return(eb=f.___getTypeName=f.asm.G).apply(null,arguments)};f.___embind_register_native_and_builtin_types=function(){return(f.___embind_register_native_and_builtin_types=f.asm.H).apply(null,arguments)};
var ob=f.___wasm_call_ctors=function(){return(ob=f.___wasm_call_ctors=f.asm.D).apply(null,arguments)},pb=f._malloc=function(){return(pb=f._malloc=f.asm.E).apply(null,arguments)},Z=f._free=function(){return(Z=f._free=f.asm.F).apply(null,arguments)},eb=f.___getTypeName=function(){return(eb=f.___getTypeName=f.asm.G).apply(null,arguments)};f.___embind_register_native_and_builtin_types=function(){return(f.___embind_register_native_and_builtin_types=f.asm.H).apply(null,arguments)};
f.dynCall_jiji=function(){return(f.dynCall_jiji=f.asm.I).apply(null,arguments)};var rb;M=function sb(){rb||tb();rb||(M=sb)};
function tb(){function a(){if(!rb&&(rb=!0,f.calledRun=!0,!ka)){O(za);O(Aa);aa(f);if(f.onRuntimeInitialized)f.onRuntimeInitialized();if(f.postRun)for("function"==typeof f.postRun&&(f.postRun=[f.postRun]);f.postRun.length;){var b=f.postRun.shift();Ba.unshift(b)}O(Ba)}}if(!(0<L)){if(f.preRun)for("function"==typeof f.preRun&&(f.preRun=[f.preRun]);f.preRun.length;)Ca();O(ya);0<L||(f.setStatus?(f.setStatus("Running..."),setTimeout(function(){setTimeout(function(){f.setStatus("")},1);a()},1)):a())}}
f.run=tb;if(f.preInit)for("function"==typeof f.preInit&&(f.preInit=[f.preInit]);0<f.preInit.length;)f.preInit.pop()();noExitRuntime=!0;tb();

Binary file not shown.

View File

@@ -12,11 +12,9 @@
*/
import { promises as fs } from 'fs';
import { basename } from 'path';
import { imageSize } from 'image-size';
const defaultOpts = {
prefix: 'url',
imagePrefix: 'img-url',
};
export default function urlPlugin(opts) {
@@ -26,7 +24,6 @@ export default function urlPlugin(opts) {
let assetIdToSourceBuffer;
const prefix = opts.prefix + ':';
const imagePrefix = opts.imagePrefix + ':';
return {
name: 'url-plugin',
buildStart() {
@@ -51,49 +48,28 @@ export default function urlPlugin(opts) {
return combinedBuffer;
},
async resolveId(id, importer) {
const idPrefix = [prefix, imagePrefix].find((prefix) =>
id.startsWith(prefix),
);
if (!idPrefix) return;
const realId = id.slice(idPrefix.length);
if (!id.startsWith(prefix)) return;
const realId = id.slice(prefix.length);
const resolveResult = await this.resolve(realId, importer);
if (!resolveResult) {
throw Error(`Cannot find ${realId}`);
}
// Add an additional .js to the end so it ends up with .js at the end in the _virtual folder.
return idPrefix + resolveResult.id + '.js';
return prefix + resolveResult.id + '.js';
},
async load(id) {
const idPrefix = [prefix, imagePrefix].find((prefix) =>
id.startsWith(prefix),
);
if (!idPrefix) return;
const realId = id.slice(idPrefix.length, -'.js'.length);
if (!id.startsWith(prefix)) return;
const realId = id.slice(prefix.length, -'.js'.length);
const source = await fs.readFile(realId);
assetIdToSourceBuffer.set(id, source);
this.addWatchFile(realId);
let imgSizeExport = '';
if (idPrefix === imagePrefix) {
const imgInfo = imageSize(source);
imgSizeExport = [
`export const width = ${JSON.stringify(imgInfo.width)};`,
`export const height = ${JSON.stringify(imgInfo.height)};`,
].join('\n');
}
return [
`export default import.meta.ROLLUP_FILE_URL_${this.emitFile({
type: 'asset',
source,
name: basename(realId),
})};`,
imgSizeExport,
].join('\n');
return `export default import.meta.ROLLUP_FILE_URL_${this.emitFile({
type: 'asset',
source,
name: basename(realId),
})}`;
},
};
}

7
missing-types.d.ts vendored
View File

@@ -22,13 +22,6 @@ declare module 'url:*' {
export default value;
}
declare module 'img-url:*' {
const value: string;
export default value;
export const width: number;
export const height: number;
}
declare module 'omt:*' {
const value: string;
export default value;

105
package-lock.json generated
View File

@@ -109,9 +109,9 @@
}
},
"@rollup/plugin-commonjs": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-17.0.0.tgz",
"integrity": "sha512-/omBIJG1nHQc+bgkYDuLpb/V08QyutP9amOrJRUSlYJZP+b/68gM//D8sxJe3Yry2QnYIr3QjR3x4AlxJEN3GA==",
"version": "15.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-15.1.0.tgz",
"integrity": "sha512-xCQqz4z/o0h2syQ7d9LskIMvBSH4PX5PjYdpSSvgS+pQik3WahkQVNWg3D8XJeYjZoVWnIUQYDghuEMRGrmQYQ==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^3.1.0",
@@ -124,17 +124,17 @@
},
"dependencies": {
"estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.1.tgz",
"integrity": "sha512-tF0hv+Yi2Ot1cwj9eYHtxC0jB9bmjacjQs6ZBTj82H8JwUywFuc+7E83NWfNMwHXZc11mjfFcVXPe9gEP4B8dg==",
"dev": true
}
}
},
"@rollup/plugin-node-resolve": {
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.1.0.tgz",
"integrity": "sha512-ouBBppRdWJKCllDXGzJ7ZIkYbaq+5TmyP0smt1vdJCFfoZhLi31vhpmjLhyo8lreHf4RoeSNllaWrvSqHpHRog==",
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-9.0.0.tgz",
"integrity": "sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^3.1.0",
@@ -142,19 +142,7 @@
"builtin-modules": "^3.1.0",
"deepmerge": "^4.2.2",
"is-module": "^1.0.0",
"resolve": "^1.19.0"
},
"dependencies": {
"resolve": {
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz",
"integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==",
"dev": true,
"requires": {
"is-core-module": "^2.1.0",
"path-parse": "^1.0.6"
}
}
"resolve": "^1.17.0"
}
},
"@rollup/plugin-replace": {
@@ -216,12 +204,6 @@
"@types/node": "*"
}
},
"@types/mime-types": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz",
"integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=",
"dev": true
},
"@types/minimatch": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
@@ -559,9 +541,9 @@
"dev": true
},
"builtin-modules": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz",
"integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz",
"integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==",
"dev": true
},
"bytes": {
@@ -2089,15 +2071,6 @@
"integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==",
"dev": true
},
"image-size": {
"version": "0.9.3",
"resolved": "https://registry.npmjs.org/image-size/-/image-size-0.9.3.tgz",
"integrity": "sha512-5SakFa79uhUVSjKeQE30GVzzLJ0QNzB53+I+/VD1vIesD6GP6uatWIlgU0uisFNLt1u0d6kBydp7yfk+lLJhLQ==",
"dev": true,
"requires": {
"queue": "6.0.1"
}
},
"import-fresh": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz",
@@ -2174,15 +2147,6 @@
"rgba-regex": "^1.0.0"
}
},
"is-core-module": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.2.0.tgz",
"integrity": "sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==",
"dev": true,
"requires": {
"has": "^1.0.3"
}
},
"is-date-object": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz",
@@ -2587,20 +2551,12 @@
"dev": true
},
"mime-types": {
"version": "2.1.28",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz",
"integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==",
"version": "2.1.27",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
"dev": true,
"requires": {
"mime-db": "1.45.0"
},
"dependencies": {
"mime-db": {
"version": "1.45.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz",
"integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==",
"dev": true
}
"mime-db": "1.44.0"
}
},
"mimic-fn": {
@@ -6080,9 +6036,9 @@
"dev": true
},
"preact": {
"version": "10.5.5",
"resolved": "https://registry.npmjs.org/preact/-/preact-10.5.5.tgz",
"integrity": "sha512-5ONLNH1SXMzzbQoExZX4TELemNt+TEDb622xXFNfZngjjM9qtrzseJt+EfiUu4TZ6EJ95X5sE1ES4yqHFSIdhg==",
"version": "10.5.7",
"resolved": "https://registry.npmjs.org/preact/-/preact-10.5.7.tgz",
"integrity": "sha512-4oEpz75t/0UNcwmcsjk+BIcDdk68oao+7kxcpc1hQPNs2Oo3ZL9xFz8UBf350mxk/VEdD41L5b4l2dE3Ug3RYg==",
"dev": true
},
"preact-render-to-string": {
@@ -6134,15 +6090,6 @@
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
"dev": true
},
"queue": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/queue/-/queue-6.0.1.tgz",
"integrity": "sha512-AJBQabRCCNr9ANq8v77RJEv73DPbn55cdTb+Giq4X0AVnNVZvMHlYp7XlQiN+1npCZj1DuSmaA2hYVUUDgxFDg==",
"dev": true,
"requires": {
"inherits": "~2.0.3"
}
},
"randombytes": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz",
@@ -6264,9 +6211,9 @@
}
},
"rollup": {
"version": "2.38.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.38.0.tgz",
"integrity": "sha512-ay9zDiNitZK/LNE/EM2+v5CZ7drkB2xyDljvb1fQJCGnq43ZWRkhxN145oV8GmoW1YNi4sA/1Jdkr2LfawJoXw==",
"version": "2.33.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.33.1.tgz",
"integrity": "sha512-uY4O/IoL9oNW8MMcbA5hcOaz6tZTMIh7qJHx/tzIJm+n1wLoY38BLn6fuy7DhR57oNFLMbDQtDeJoFURt5933w==",
"dev": true,
"requires": {
"fsevents": "~2.1.2"
@@ -6983,9 +6930,9 @@
"dev": true
},
"typescript": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz",
"integrity": "sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==",
"dev": true
},
"uniq": {

View File

@@ -11,12 +11,11 @@
"serve": "serve --config ../../../serve.json .tmp/build/static"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.1.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.4",
"@surma/rollup-plugin-off-main-thread": "^1.4.2",
"@types/dedent": "^0.7.0",
"@types/mime-types": "^2.1.0",
"@types/node": "^14.14.7",
"comlink": "^4.3.0",
"cssnano": "^4.1.10",
@@ -25,11 +24,10 @@
"file-drop-element": "^1.0.1",
"husky": "^4.3.0",
"idb-keyval": "^3.2.0",
"image-size": "^0.9.3",
"linkstate": "^2.0.0",
"lint-staged": "^10.5.1",
"lodash.camelcase": "^4.3.0",
"mime-types": "^2.1.28",
"mime-types": "^2.1.27",
"npm-run-all": "^4.1.5",
"pointer-tracker": "^2.4.0",
"postcss": "^7.0.35",
@@ -37,13 +35,13 @@
"postcss-nested": "^4.2.3",
"postcss-simple-vars": "^5.0.2",
"postcss-url": "^8.0.0",
"preact": "^10.5.5",
"preact": "^10.5.7",
"preact-render-to-string": "^5.1.11",
"prettier": "^2.1.2",
"rollup": "^2.38.0",
"rollup": "^2.33.1",
"rollup-plugin-terser": "^7.0.2",
"serve": "^11.3.2",
"typescript": "^4.1.3",
"typescript": "^4.0.5",
"which": "^2.0.2"
},
"husky": {

View File

@@ -0,0 +1,37 @@
import { h, Component, createRef } from 'preact';
import { drawDataToCanvas } from '../util';
export interface CanvasImageProps
extends h.JSX.HTMLAttributes<HTMLCanvasElement> {
image?: ImageData;
}
export default class CanvasImage extends Component<CanvasImageProps> {
canvas = createRef<HTMLCanvasElement>();
componentDidUpdate(prevProps: CanvasImageProps) {
if (this.props.image !== prevProps.image) {
this.draw(this.props.image);
}
}
componentDidMount() {
if (this.props.image) {
this.draw(this.props.image);
}
}
draw(image?: ImageData) {
const canvas = this.canvas.current;
if (!canvas) return;
if (!image) canvas.getContext('2d');
else drawDataToCanvas(canvas, image);
}
render({ image, ...props }: CanvasImageProps) {
return (
<canvas
ref={this.canvas}
width={image?.width}
height={image?.height}
{...props}
/>
);
}
}

View File

@@ -0,0 +1,54 @@
import {
Component,
cloneElement,
createRef,
toChildArray,
ComponentChildren,
RefObject,
} from 'preact';
interface Props {
children: ComponentChildren;
onClick?(e: MouseEvent | KeyboardEvent): void;
}
export class ClickOutsideDetector extends Component<Props> {
private _roots: RefObject<Element>[] = [];
private handleClick = (e: MouseEvent) => {
let target = e.target as Node;
// check if the click came from within any of our child elements:
for (const { current: root } of this._roots) {
if (root && (root === target || root.contains(target))) return;
}
const { onClick } = this.props;
if (onClick) onClick(e);
};
private handleKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
const { onClick } = this.props;
if (onClick) onClick(e);
}
};
componentDidMount() {
addEventListener('click', this.handleClick, { passive: true });
addEventListener('keydown', this.handleKey, { passive: true });
}
componentWillUnmount() {
removeEventListener('click', this.handleClick);
removeEventListener('keydown', this.handleKey);
}
render({ children }: Props) {
this._roots = [];
return toChildArray(children).map((child) => {
if (typeof child !== 'object') return child;
const ref = createRef();
this._roots.push(ref);
return cloneElement(child, { ref });
});
}
}

View File

@@ -0,0 +1,210 @@
import {
h,
cloneElement,
Component,
VNode,
createRef,
ComponentChildren,
ComponentProps,
Fragment,
render,
} from 'preact';
import * as style from './style.css';
import 'add-css:./style.css';
type Anchor = 'left' | 'right' | 'top' | 'bottom';
type Direction = 'left' | 'right' | 'up' | 'down';
const has = (haystack: string | string[] | undefined, needle: string) =>
Array.isArray(haystack) ? haystack.includes(needle) : haystack === needle;
interface Props extends Omit<ComponentProps<'aside'>, 'ref'> {
showing?: boolean;
direction?: Direction | Direction[];
anchor?: Anchor;
toggle?: VNode;
children?: ComponentChildren;
}
interface State {
showing: boolean;
hasShown: boolean;
}
export default class Flyout extends Component<Props, State> {
state = {
showing: this.props.showing === true,
hasShown: this.props.showing === true,
};
private wrap = createRef<HTMLElement>();
private menu = createRef<HTMLElement>();
private resizeObserver?: ResizeObserver;
private shown?: number;
private dismiss = (event: Event) => {
if (this.menu.current && this.menu.current.contains(event.target as Node))
return;
// prevent toggle buttons from immediately dismissing:
if (this.shown && Date.now() - this.shown < 10) return;
this.setShowing(false);
};
hide = () => {
this.setShowing(false);
};
show = () => {
this.setShowing(true);
};
toggle = () => {
this.setShowing(!this.state.showing);
};
private setShowing = (showing?: boolean) => {
this.shown = Date.now();
if (showing) this.setState({ showing: true, hasShown: true });
else this.setState({ showing: false });
};
private reposition = () => {
const menu = this.menu.current;
const wrap = this.wrap.current;
if (!menu || !wrap || !this.state.showing) return;
const bbox = wrap.getBoundingClientRect();
const { direction = 'down', anchor = 'right' } = this.props;
const { innerWidth, innerHeight } = window;
const anchorX = has(anchor, 'left') ? bbox.left : bbox.right;
menu.style.left = menu.style.right = menu.style.top = menu.style.bottom =
'';
if (has(direction, 'left')) {
menu.style.right = innerWidth - anchorX + 'px';
} else {
menu.style.left = anchorX + 'px';
}
if (has(direction, 'up')) {
const anchorY = has(anchor, 'bottom') ? bbox.bottom : bbox.top;
menu.style.bottom = innerHeight - anchorY + 'px';
} else {
const anchorY = has(anchor, 'top') ? bbox.top : bbox.bottom;
menu.style.top = anchorY + 'px';
}
};
componentWillReceiveProps({ showing }: Props) {
if (showing !== this.props.showing) {
this.setShowing(showing);
}
}
componentDidMount() {
addEventListener('click', this.dismiss, { passive: true });
addEventListener('resize', this.reposition, { passive: true });
if (typeof ResizeObserver === 'function' && this.wrap.current) {
this.resizeObserver = new ResizeObserver(this.reposition);
this.resizeObserver.observe(this.wrap.current);
}
if (this.props.showing) this.setShowing(true);
}
componentWillUnmount() {
removeEventListener('click', this.dismiss);
removeEventListener('resize', this.reposition);
if (this.resizeObserver) this.resizeObserver.disconnect();
}
componentDidUpdate(prevProps: Props, prevState: State) {
if (this.state.showing && !prevState.showing) {
const menu = this.menu.current;
if (menu) {
this.reposition();
let toFocus = menu.firstElementChild;
for (let child of menu.children) {
if (child.hasAttribute('autofocus')) {
toFocus = child;
break;
}
}
// @ts-ignore-next
if (toFocus) toFocus.focus();
}
}
}
render(
{ direction, anchor, toggle, children, ...props }: Props,
{ showing }: State,
) {
const toggleProps = {
flyoutOpen: showing,
onClick: this.toggle,
};
const directionText = Array.isArray(direction)
? direction.join(' ')
: direction;
const anchorText = Array.isArray(anchor) ? anchor.join(' ') : anchor;
return (
<span
class={style.wrap}
ref={this.wrap}
data-flyout-open={showing ? '' : undefined}
>
{toggle && cloneElement(toggle, toggleProps)}
{showing &&
createPortal(
<aside
{...props}
class={`${style.flyout} ${props.class || props.className || ''}`}
ref={this.menu}
data-anchor={anchorText}
data-direction={directionText}
>
{children}
</aside>,
document.body,
)}
</span>
);
}
}
// not worth pulling in compat
function createPortal(children: ComponentChildren, parent: Element) {
return <Portal parent={parent}>{children}</Portal>;
}
// this is probably overly careful, since it works directly rendering into parent
function createPersistentFragment(parent: Element) {
const frag = {
nodeType: 11,
childNodes: [],
appendChild: parent.appendChild.bind(parent),
insertBefore: parent.insertBefore.bind(parent),
removeChild: parent.removeChild.bind(parent),
};
return (frag as unknown) as Element;
}
class Portal extends Component<{
children: ComponentChildren;
parent: Element;
}> {
root = createPersistentFragment(this.props.parent);
componentWillUnmount() {
render(null, this.root);
}
render() {
render(<Fragment>{this.props.children}</Fragment>, this.root);
return null;
}
}

View File

@@ -0,0 +1,41 @@
.wrap {
position: relative;
display: flex;
align-items: center;
justify-items: center;
}
.flyout {
display: inline-block;
position: fixed;
z-index: 100;
display: flex;
flex-wrap: nowrap;
flex-direction: column;
align-items: flex-start;
overflow: visible;
outline: none;
will-change: transform, opacity;
animation: menuOpen 350ms ease forwards 1;
--flyout-offset-y: -20px;
&[hidden] {
display: none;
}
&[data-direction*='left'] {
align-items: flex-end;
}
&[data-direction*='up'] {
--flyout-offset-y: 20px;
flex-direction: column-reverse;
}
}
@keyframes menuOpen {
0% {
transform: translateY(var(--flyout-offset-y, 0));
opacity: 0;
}
}

View File

@@ -1,4 +1,4 @@
import { h, Component } from 'preact';
import { h, Component, createRef } from 'preact';
import * as style from './style.css';
import 'add-css:./style.css';
@@ -15,9 +15,10 @@ import {
import Expander from './Expander';
import Toggle from './Toggle';
import Select from './Select';
import Flyout from '../Flyout';
import { Options as QuantOptionsComponent } from 'features/processors/quantize/client';
import { Options as ResizeOptionsComponent } from 'features/processors/resize/client';
import { CLIIcon, SwapIcon } from 'client/lazy-app/icons';
import { CLIIcon, MoreIcon, SwapIcon } from 'client/lazy-app/icons';
interface Props {
index: 0 | 1;
@@ -64,6 +65,8 @@ export default class Options extends Component<Props, State> {
supportedEncoderMap: undefined,
};
menu = createRef<Flyout>();
constructor() {
super();
supportedEncoderMapP.then((supportedEncoderMap) =>
@@ -110,10 +113,12 @@ export default class Options extends Component<Props, State> {
private onCopyCliClick = () => {
this.props.onCopyCliClick(this.props.index);
if (this.menu.current) this.menu.current.hide();
};
private onCopyToOtherSideClick = () => {
this.props.onCopyToOtherSideClick(this.props.index);
if (this.menu.current) this.menu.current.hide();
};
render(
@@ -136,23 +141,33 @@ export default class Options extends Component<Props, State> {
{!encoderState ? null : (
<div>
<h3 class={style.optionsTitle}>
<div class={style.titleAndButtons}>
Edit
Edit
<Flyout
ref={this.menu}
class={style.menu}
direction={['up', 'left']}
anchor="right"
toggle={
<button class={style.titleButton}>
<MoreIcon />
</button>
}
>
<button
class={style.cliButton}
title="Copy npx command"
class={style.menuButton}
onClick={this.onCopyCliClick}
>
<CLIIcon />
Copy npx command
</button>
<button
class={style.copyOverButton}
title="Copy settings to other side"
class={style.menuButton}
onClick={this.onCopyToOtherSideClick}
>
<SwapIcon />
Copy settings to other side
</button>
</div>
</Flyout>
</h3>
<label class={style.sectionEnabler}>
Resize

View File

@@ -14,13 +14,21 @@
background-color: var(--main-theme-color);
color: var(--header-text-color);
margin: 0;
padding: 10px var(--horizontal-padding);
height: 38px;
padding: 0 var(--horizontal-padding);
font-weight: bold;
font-size: 1.4rem;
border-bottom: 1px solid var(--off-black);
transition: all 300ms ease-in-out;
transition-property: background-color, color;
display: grid;
align-items: center;
grid-template-columns: 1fr;
grid-auto-columns: max-content;
grid-auto-flow: column;
gap: 0.8rem 0;
position: sticky;
top: 0;
z-index: 1;
@@ -82,36 +90,63 @@
border-radius: 4px;
}
.title-and-buttons {
grid-template-columns: 1fr;
grid-auto-columns: max-content;
grid-auto-flow: column;
display: grid;
gap: 0.8rem;
.menu {
transform: translateY(-10px);
}
.title-button {
position: relative;
left: 10px;
composes: unbutton from global;
border-radius: 50%;
background: rgba(255, 255, 255, 0);
&:hover,
&:active {
background: rgba(255, 255, 255, 0.3);
}
svg {
--size: 20px;
--size: 24px;
fill: var(--header-text-color);
display: block;
width: var(--size);
height: var(--size);
padding: 5px;
}
}
.cli-button {
composes: title-button;
.menu-button {
display: flex;
align-items: center;
box-sizing: border-box;
margin: 8px 0;
background-color: rgba(29, 29, 29, 0.92);
border: 1px solid rgba(0, 0, 0, 0.67);
border-radius: 2rem;
line-height: 1.1;
white-space: nowrap;
height: 39px;
padding: 0 16px;
font-size: 1.2rem;
cursor: pointer;
color: #fff;
svg {
stroke: var(--header-text-color);
}
}
.copy-over-button {
composes: title-button;
svg {
fill: var(--header-text-color);
&:hover {
background: rgba(50, 50, 50, 0.92);
}
&:focus {
box-shadow: 0 0 0 2px #fff;
outline: none;
z-index: 1;
}
& > svg {
position: relative;
width: 18px;
height: 18px;
margin-right: 12px;
color: var(--main-theme-color);
}
}

View File

@@ -68,8 +68,6 @@ export default class TwoUp extends HTMLElement {
);
},
});
window.addEventListener('keydown', event => this._onKeyDown(event));
}
connectedCallback() {
@@ -96,29 +94,6 @@ export default class TwoUp extends HTMLElement {
}
}
// KeyDown event handler
private _onKeyDown(event: KeyboardEvent) {
if (event.code === 'Digit1' || event.code === 'Numpad1') {
this._position = 0;
this._relativePosition = 0;
this._setPosition();
} else if (event.code === 'Digit2' || event.code === 'Numpad2') {
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
const bounds = this.getBoundingClientRect();
this._position = bounds[dimensionAxis] / 2;
this._relativePosition = (this._position / bounds[dimensionAxis]) / 2;
this._setPosition();
} else if (event.code === 'Digit3' || event.code === 'Numpad3') {
const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width';
const bounds = this.getBoundingClientRect();
this._position = bounds[dimensionAxis];
this._relativePosition = this._position / bounds[dimensionAxis];
this._setPosition();
}
}
private _resetPosition() {
// Set the initial position of the handle.
requestAnimationFrame(() => {

View File

@@ -1,4 +1,4 @@
import { h, Component, Fragment } from 'preact';
import { h, createRef, Component, Fragment } from 'preact';
import type PinchZoom from './custom-els/PinchZoom';
import type { ScaleToOpts } from './custom-els/PinchZoom';
import './custom-els/PinchZoom';
@@ -10,30 +10,37 @@ import {
ToggleBackgroundIcon,
AddIcon,
RemoveIcon,
ToggleBackgroundActiveIcon,
RotateIcon,
MoreIcon,
} from '../../icons';
import { twoUpHandle } from './custom-els/TwoUp/styles.css';
import type { PreprocessorState } from '../../feature-meta';
import { cleanSet } from '../../util/clean-modify';
import type { SourceImage } from '../../Compress';
import { linkRef } from 'shared/prerendered-app/util';
import Flyout from '../Flyout';
interface Props {
source?: SourceImage;
preprocessorState?: PreprocessorState;
hidden?: boolean;
mobileView: boolean;
leftCompressed?: ImageData;
rightCompressed?: ImageData;
leftImgContain: boolean;
rightImgContain: boolean;
onPreprocessorChange: (newState: PreprocessorState) => void;
onPreprocessorChange?: (newState: PreprocessorState) => void;
onShowPreprocessorTransforms?: () => void;
onToggleBackground?: () => void;
}
interface State {
scale: number;
editingScale: boolean;
altBackground: boolean;
transform: boolean;
menuOpen: boolean;
smallControls: boolean;
}
const scaleToOpts: ScaleToOpts = {
@@ -48,12 +55,18 @@ export default class Output extends Component<Props, State> {
scale: 1,
editingScale: false,
altBackground: false,
transform: false,
menuOpen: false,
smallControls:
typeof matchMedia === 'function' &&
matchMedia('(max-width: 859px)').matches,
};
canvasLeft?: HTMLCanvasElement;
canvasRight?: HTMLCanvasElement;
pinchZoomLeft?: PinchZoom;
pinchZoomRight?: PinchZoom;
scaleInput?: HTMLInputElement;
flyout = createRef<Flyout>();
retargetedEvents = new WeakSet<Event>();
componentDidMount() {
@@ -75,6 +88,12 @@ export default class Output extends Component<Props, State> {
if (this.canvasRight && rightDraw) {
drawDataToCanvas(this.canvasRight, rightDraw);
}
if (typeof matchMedia === 'function') {
matchMedia('(max-width: 859px)').addEventListener('change', (e) =>
this.setState({ smallControls: e.matches }),
);
}
}
componentDidUpdate(prevProps: Props, prevState: State) {
@@ -144,12 +163,6 @@ export default class Output extends Component<Props, State> {
return props.rightCompressed || (props.source && props.source.preprocessed);
}
private toggleBackground = () => {
this.setState({
altBackground: !this.state.altBackground,
});
};
private zoomIn = () => {
if (!this.pinchZoomLeft) throw Error('Missing pinch-zoom element');
this.pinchZoomLeft.scaleTo(this.state.scale * 1.25, scaleToOpts);
@@ -160,17 +173,30 @@ export default class Output extends Component<Props, State> {
this.pinchZoomLeft.scaleTo(this.state.scale / 1.25, scaleToOpts);
};
private onRotateClick = () => {
const { preprocessorState: inputProcessorState } = this.props;
if (!inputProcessorState) return;
const newState = cleanSet(
inputProcessorState,
'rotate.rotate',
(inputProcessorState.rotate.rotate + 90) % 360,
private fitToViewport = () => {
if (!this.pinchZoomLeft) throw Error('Missing pinch-zoom element');
const img = this.props.source?.preprocessed;
if (!img) return;
const scale = Number(
Math.min(
(window.innerWidth - 20) / img.width,
(window.innerHeight - 20) / img.height,
).toFixed(2),
);
this.pinchZoomLeft.scaleTo(Number(scale.toFixed(2)), scaleToOpts);
this.recenter();
// this.hideMenu();
};
this.props.onPreprocessorChange(newState);
private recenter = () => {
const img = this.props.source?.preprocessed;
if (!img || !this.pinchZoomLeft) return;
let scale = this.pinchZoomLeft.scale;
this.pinchZoomLeft.setTransform({
x: (img.width - img.width * scale) / 2,
y: (img.height - img.height * scale) / 2,
allowChangeEvent: true,
});
};
private onScaleValueFocus = () => {
@@ -253,8 +279,16 @@ export default class Output extends Component<Props, State> {
};
render(
{ mobileView, leftImgContain, rightImgContain, source }: Props,
{ scale, editingScale, altBackground }: State,
{
source,
mobileView,
hidden,
leftImgContain,
rightImgContain,
onShowPreprocessorTransforms,
onToggleBackground,
}: Props,
{ scale, editingScale, smallControls }: State,
) {
const leftDraw = this.leftDrawable();
const rightDraw = this.rightDrawable();
@@ -263,9 +297,7 @@ export default class Output extends Component<Props, State> {
return (
<Fragment>
<div
class={`${style.output} ${altBackground ? style.altBackground : ''}`}
>
<div class={style.output} hidden={hidden}>
<two-up
legacy-clip-compat
class={style.twoUp}
@@ -291,7 +323,7 @@ export default class Output extends Component<Props, State> {
style={{
width: originalImage ? originalImage.width : '',
height: originalImage ? originalImage.height : '',
objectFit: leftImgContain ? 'contain' : '',
objectFit: leftImgContain ? 'contain' : undefined,
}}
/>
</pinch-zoom>
@@ -307,15 +339,16 @@ export default class Output extends Component<Props, State> {
style={{
width: originalImage ? originalImage.width : '',
height: originalImage ? originalImage.height : '',
objectFit: rightImgContain ? 'contain' : '',
objectFit: rightImgContain ? 'contain' : undefined,
}}
/>
</pinch-zoom>
</two-up>
</div>
<div class={style.controls}>
<div class={style.controls} hidden={hidden}>
<div class={style.buttonGroup}>
<button class={style.firstButton} onClick={this.zoomOut}>
<button class={style.button} onClick={this.zoomOut}>
<RemoveIcon />
</button>
{editingScale ? (
@@ -342,18 +375,34 @@ export default class Output extends Component<Props, State> {
<button class={style.lastButton} onClick={this.zoomIn}>
<AddIcon />
</button>
</div>
<div class={style.buttonGroup}>
<button class={style.firstButton} onClick={this.onRotateClick}>
<RotateIcon />
</button>
<button class={style.lastButton} onClick={this.toggleBackground}>
{altBackground ? (
<ToggleBackgroundActiveIcon />
) : (
<ToggleBackgroundIcon />
)}
</button>
<Flyout
class={style.menu}
showing={hidden ? false : undefined}
anchor="right"
direction={smallControls ? ['down', 'left'] : 'up'}
toggle={
<button class={`${style.button} ${style.moreButton}`}>
<MoreIcon />
</button>
}
>
<button
class={style.button}
onClick={onShowPreprocessorTransforms}
>
<RotateIcon /> Rotate & Transform
</button>
<button class={style.button} onClick={this.fitToViewport}>
Fit to viewport
</button>
<button class={style.button} onClick={this.recenter}>
Re-center
</button>
<button class={style.button} onClick={onToggleBackground}>
<ToggleBackgroundIcon /> Change canvas color
</button>
</Flyout>
</div>
</div>
</Fragment>

View File

@@ -1,20 +1,8 @@
.output {
display: contents;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #000;
opacity: 0.8;
transition: opacity 500ms ease;
}
&.alt-background::before {
opacity: 0;
&[hidden] {
display: none;
}
}
@@ -42,16 +30,21 @@
.controls {
display: flex;
justify-content: center;
overflow: hidden;
flex-wrap: wrap;
contain: content;
grid-area: header;
align-self: center;
padding: 9px 66px;
position: relative;
/* Had to disable containment because of the overflow menu. */
/*
contain: content;
overflow: hidden;
*/
transition: transform 500ms ease;
/* Allow clicks to fall through to the pinch zoom area */
pointer-events: none;
& > * {
pointer-events: auto;
}
@@ -62,13 +55,34 @@
grid-area: viewportOpts;
align-self: end;
}
&[hidden] {
visibility: visible;
transform: translateY(-200%);
@media (min-width: 860px) {
transform: translateY(200%);
}
}
}
.button-group {
display: flex;
position: relative;
z-index: 100;
margin: 0 3px;
& > :not(:first-child) {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
margin-left: 0;
}
& > :not(:nth-last-child(2)) {
margin-right: 0;
border-right-width: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}
.button,
@@ -76,9 +90,10 @@
display: flex;
align-items: center;
box-sizing: border-box;
margin: 4px;
background-color: rgba(29, 29, 29, 0.92);
border: 1px solid rgba(0, 0, 0, 0.67);
border-width: 1px 0 1px 1px;
border-radius: 6px;
line-height: 1.1;
white-space: nowrap;
height: 39px;
@@ -161,3 +176,64 @@ input.zoom {
pointer-events: auto;
}
}
/** Three-dot menu */
.moreButton {
padding: 0 4px;
& > svg {
transform-origin: center;
transition: transform 200ms ease;
}
}
.controls [data-flyout-open] {
.moreButton {
background: rgba(82, 82, 82, 0.92);
& > svg {
transform: rotate(180deg);
}
}
&:before {
content: '';
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(50, 50, 50, 0.4);
backdrop-filter: blur(2px) contrast(70%);
animation: menuShimFadeIn 350ms ease forwards 1;
will-change: opacity;
z-index: -1;
}
}
@keyframes menuShimFadeIn {
0% {
opacity: 0;
}
}
.menu {
button {
margin: 8px 0;
border-radius: 2rem;
padding: 0 16px;
& > svg {
position: relative;
left: -6px;
}
}
h5 {
text-transform: uppercase;
font-size: 0.8rem;
color: #fff;
margin: 8px 4px;
padding: 10px 0 0;
}
}

View File

@@ -0,0 +1,330 @@
import { h, Component, ComponentChildren } from 'preact';
import * as style from './style.css';
import 'add-css:./style.css';
import { shallowEqual } from 'client/lazy-app/util';
export interface CropBox {
left: number;
top: number;
right: number;
bottom: number;
}
// Minimum CropBox size
const MIN_SIZE = 2;
export interface Props {
size: { width: number; height: number };
scale?: number;
lockAspect?: boolean;
crop: CropBox;
onChange?(crop: CropBox): void;
}
type Edge = keyof CropBox;
interface PointerTrack {
x: number;
y: number;
edges: { edge: Edge; value: number }[];
aspect: number | undefined;
}
interface State {
crop: CropBox;
pan: boolean;
}
export default class Cropper extends Component<Props, State> {
private pointers = new Map<number, PointerTrack>();
state = {
crop: this.normalizeCrop({ ...this.props.crop }),
pan: false,
};
shouldComponentUpdate(nextProps: Props, nextState: State) {
if (!shallowEqual(nextState, this.state)) return true;
const { size, scale, lockAspect, crop } = this.props;
return (
size.width !== nextProps.size.width ||
size.height !== nextProps.size.height ||
scale !== nextProps.scale ||
lockAspect !== nextProps.lockAspect ||
!shallowEqual(crop, nextProps.crop)
);
}
componentWillReceiveProps({ crop }: Props, nextState: State) {
const current = nextState.crop || this.state.crop;
if (crop !== this.props.crop && !shallowEqual(crop, current)) {
// this.setState({ crop: nextProps.crop });
this.setCrop(crop);
}
}
private normalizeCrop(crop: CropBox) {
crop.left = Math.round(Math.max(0, crop.left));
crop.top = Math.round(Math.max(0, crop.top));
crop.right = Math.round(Math.max(0, crop.right));
crop.bottom = Math.round(Math.max(0, crop.bottom));
return crop;
}
private setCrop(cropUpdate: Partial<CropBox>) {
const crop = this.normalizeCrop({ ...this.state.crop, ...cropUpdate });
// ignore crop updates that normalize to the same values
const old = this.state.crop;
if (
crop.left === old.left &&
crop.right === old.right &&
crop.top === old.top &&
crop.bottom === old.bottom
) {
return;
}
this.setState({ crop });
if (this.props.onChange) {
this.props.onChange(crop);
}
}
private onPointerDown = (event: PointerEvent) => {
if (event.button !== 0 || this.state.pan) return;
const target = event.target as SVGElement;
const edgeAttr = target.getAttribute('data-edge');
if (edgeAttr) {
event.stopPropagation();
event.preventDefault();
let aspect;
const edges = edgeAttr.split(/ *, */) as Edge[];
if (this.props.lockAspect) {
if (edges.length === 1) return;
const { size } = this.props;
const oldCrop = this.state.crop;
aspect =
(size.width - oldCrop.left - oldCrop.right) /
(size.height - oldCrop.top - oldCrop.bottom);
}
this.pointers.set(event.pointerId, {
x: event.x,
y: event.y,
edges: edges.map((edge) => ({ edge, value: this.state.crop[edge] })),
aspect,
});
target.setPointerCapture(event.pointerId);
}
};
private onPointerMove = (event: PointerEvent) => {
const target = event.target as SVGElement;
const down = this.pointers.get(event.pointerId);
if (down && target.hasPointerCapture(event.pointerId)) {
const { size } = this.props;
const oldCrop = this.state.crop;
const scale = this.props.scale || 1;
let dx = (event.x - down.x) / scale;
let dy = (event.y - down.y) / scale;
if (down.aspect && down.edges.length === 2) {
const dir = (dx + dy) / 2;
dx = dir * down.aspect;
dy = dir / down.aspect;
}
const crop: Partial<CropBox> = {};
for (const { edge, value } of down.edges) {
let edgeValue = value;
switch (edge) {
case 'left':
edgeValue += dx;
break;
case 'right':
edgeValue -= dx;
break;
case 'top':
edgeValue += dy;
break;
case 'bottom':
edgeValue -= dy;
break;
}
crop[edge] = edgeValue;
}
// Prevent MOVE from resizing the cropbox:
if (crop.left && crop.right) {
if (crop.left < 0) crop.right += crop.left;
if (crop.right < 0) crop.left += crop.right;
} else {
// enforce minimum 1px cropbox width
if (crop.left) {
if (down.aspect) crop.left = Math.max(0, crop.left);
else
crop.left = Math.min(
crop.left,
size.width - oldCrop.right - MIN_SIZE,
);
}
if (crop.right) {
if (down.aspect) crop.right = Math.max(0, crop.right);
crop.right = Math.min(
crop.right,
size.width - oldCrop.left - MIN_SIZE,
);
}
if (
down.aspect &&
(crop.left ?? oldCrop.left) + (crop.right ?? oldCrop.right) >
size.width
)
return;
}
if (crop.top && crop.bottom) {
if (crop.top < 0) crop.bottom += crop.top;
if (crop.bottom < 0) crop.top += crop.bottom;
} else {
// enforce minimum 1px cropbox height
if (crop.top) {
if (down.aspect) crop.top = Math.max(0, crop.top);
crop.top = Math.min(
crop.top,
size.height - oldCrop.bottom - MIN_SIZE,
);
}
if (crop.bottom) {
if (down.aspect) crop.bottom = Math.max(0, crop.bottom);
crop.bottom = Math.min(
crop.bottom,
size.height - oldCrop.top - MIN_SIZE,
);
}
if (
down.aspect &&
(crop.top ?? oldCrop.top) + (crop.bottom ?? oldCrop.bottom) >
size.height
)
return;
}
this.setCrop(crop);
event.stopPropagation();
event.preventDefault();
}
};
private onPointerUp = (event: PointerEvent) => {
const target = event.target as SVGElement;
const down = this.pointers.get(event.pointerId);
if (down && target.hasPointerCapture(event.pointerId)) {
this.onPointerMove(event);
target.releasePointerCapture(event.pointerId);
event.stopPropagation();
event.preventDefault();
this.pointers.delete(event.pointerId);
}
};
private onKeyDown = (event: KeyboardEvent) => {
if (event.key === ' ') {
if (!this.state.pan) {
this.setState({ pan: true });
}
event.preventDefault();
}
};
private onKeyUp = (event: KeyboardEvent) => {
if (event.key === ' ') this.setState({ pan: false });
};
componentDidMount() {
addEventListener('keydown', this.onKeyDown);
addEventListener('keyup', this.onKeyUp);
}
componentWillUnmount() {
addEventListener('keydown', this.onKeyDown);
addEventListener('keyup', this.onKeyUp);
}
render({ size, scale }: Props, { crop, pan }: State) {
const x = crop.left;
const y = crop.top;
const width = size.width - crop.left - crop.right;
const height = size.height - crop.top - crop.bottom;
const s = (x: number) => x / (scale || 1);
const clip = `polygon(0 0, 0 100%, 100% 100%, 100% 0, 0 0, ${s(x)}px ${s(
y,
)}px, ${s(x + width)}px ${s(y)}px, ${s(x + width)}px ${s(
y + height,
)}px, ${s(x)}px ${s(y + height)}px, ${s(x)}px ${s(y)}px)`;
return (
<svg
class={`${style.cropper} ${pan ? style.pan : ''}`}
width={size.width + 20}
height={size.height + 20}
viewBox={`-10 -10 ${size.width + 20} ${size.height + 20}`}
style={{
// this is hack to force style invalidation in Chrome
zoom: (scale || 1).toFixed(3),
}}
onPointerDown={this.onPointerDown}
onPointerMove={this.onPointerMove}
onPointerUp={this.onPointerUp}
>
<rect
class={style.background}
width={size.width}
height={size.height}
clip-path={clip}
/>
<svg x={x} y={y} width={width} height={height}>
<Freezer>
<rect
id="box"
class={style.cropbox}
data-edge="left,right,top,bottom"
width="100%"
height="100%"
/>
<rect class={style.edge} data-edge="top" width="100%" />
<rect class={style.edge} data-edge="bottom" width="100%" y="100%" />
<rect class={style.edge} data-edge="left" height="100%" />
<rect class={style.edge} data-edge="right" height="100%" x="100%" />
<circle class={style.corner} data-edge="left,top" />
<circle class={style.corner} data-edge="right,top" cx="100%" />
<circle
class={style.corner}
data-edge="right,bottom"
cx="100%"
cy="100%"
/>
<circle class={style.corner} data-edge="left,bottom" cy="100%" />
</Freezer>
</svg>
</svg>
);
}
}
interface FreezerProps {
children: ComponentChildren;
}
class Freezer extends Component<FreezerProps> {
shouldComponentUpdate() {
return false;
}
render({ children }: FreezerProps) {
return children;
}
}

View File

@@ -0,0 +1,119 @@
.cropper {
position: absolute;
left: calc(-10px / var(--scale, 1));
top: calc(-10px / var(--scale, 1));
right: calc(-10px / var(--scale, 1));
bottom: calc(-10px / var(--scale, 1));
shape-rendering: crispedges;
overflow: hidden;
contain: strict;
transform-origin: 0 0;
transform: scale(calc(1 / var(--scale))) !important;
zoom: var(--scale, 1);
&.pan {
cursor: grabbing;
& * {
pointer-events: none;
}
}
& > svg {
margin: -10px;
padding: 10px;
overflow: visible;
contain: strict;
/* overflow: visible; */
}
}
.background {
pointer-events: none;
fill: rgba(0, 0, 0, 0.25);
}
.cropbox {
fill: none;
stroke: white;
stroke-width: calc(1.5px / var(--scale, 1));
stroke-dasharray: calc(5px / var(--scale, 1)), calc(5px / var(--scale, 1));
stroke-dashoffset: 50%;
/* Accept pointer input even though this is unpainted transparent */
pointer-events: all;
cursor: move;
/* animation: ants 1s linear forwards infinite; */
}
/*
@keyframes ants {
0% { stroke-dashoffset: 0; }
100% { stroke-dashoffset: -12; }
}
*/
.edge {
fill: #aaa;
opacity: 0;
transition: opacity 250ms ease;
z-index: 2;
pointer-events: all;
--edge-width: calc(10px / var(--scale, 1));
@media (max-width: 779px) {
--edge-width: calc(20px / var(--scale, 1));
fill: rgba(0, 0, 0, 0.01);
}
&[data-edge='left'],
&[data-edge='right'] {
cursor: ew-resize;
transform: translate(calc(var(--edge-width, 10px) / -2), 0);
width: var(--edge-width, 10px);
}
&[data-edge='top'],
&[data-edge='bottom'] {
cursor: ns-resize;
transform: translate(0, calc(var(--edge-width, 10px) / -2));
height: var(--edge-width, 10px);
}
&:hover,
&:active {
opacity: 0.1;
transition: none;
}
}
.corner {
r: calc(4px / var(--scale, 1));
stroke-width: calc(4px / var(--scale, 1));
stroke: rgba(225, 225, 225, 0.01);
fill: white;
shape-rendering: geometricprecision;
pointer-events: all;
transition: fill 250ms ease, stroke 250ms ease;
&:hover,
&:active {
stroke: rgba(225, 225, 225, 0.5);
transition: none;
}
@media (max-width: 779px) {
r: calc(10 / var(--scale, 1));
stroke-width: calc(2 / var(--scale, 1));
}
&[data-edge='left,top'] {
cursor: nw-resize;
}
&[data-edge='right,top'] {
cursor: ne-resize;
}
&[data-edge='right,bottom'] {
cursor: se-resize;
}
&[data-edge='left,bottom'] {
cursor: sw-resize;
}
}

View File

@@ -0,0 +1,587 @@
import {
h,
Component,
Fragment,
createRef,
FunctionComponent,
ComponentChildren,
} from 'preact';
import type {
default as PinchZoom,
ScaleToOpts,
} from '../Output/custom-els/PinchZoom';
import '../Output/custom-els/PinchZoom';
import * as style from './style.css';
import 'add-css:./style.css';
import {
AddIcon,
CheckmarkIcon,
CompareIcon,
FlipHorizontallyIcon,
FlipVerticallyIcon,
RemoveIcon,
RotateClockwiseIcon,
RotateCounterClockwiseIcon,
SwapIcon,
} from '../../icons';
import { cleanSet } from '../../util/clean-modify';
import type { SourceImage } from '../../Compress';
import { PreprocessorState } from 'client/lazy-app/feature-meta';
import Cropper, { CropBox } from './Cropper';
import CanvasImage from '../CanvasImage';
import Expander from '../Options/Expander';
import Select from '../Options/Select';
import Checkbox from '../Options/Checkbox';
const ROTATE_ORIENTATIONS = [0, 90, 180, 270] as const;
const cropPresets = {
square: {
name: 'Square',
ratio: 1,
},
'4:3': {
name: '4:3',
ratio: 4 / 3,
},
'16:9': {
name: '16:9',
ratio: 16 / 9,
},
'16:10': {
name: '16:10',
ratio: 16 / 10,
},
};
type CropPresetId = keyof typeof cropPresets;
interface Props {
source: SourceImage;
preprocessorState: PreprocessorState;
mobileView: boolean;
onCancel?(): void;
onSave?(e: { preprocessorState: PreprocessorState }): void;
}
interface State {
scale: number;
editingScale: boolean;
rotate: typeof ROTATE_ORIENTATIONS[number];
// crop: false | CropBox;
crop: CropBox;
cropPreset: keyof typeof cropPresets | undefined;
lockAspect: boolean;
flip: PreprocessorState['flip'];
}
const scaleToOpts: ScaleToOpts = {
originX: '50%',
originY: '50%',
relativeTo: 'container',
allowChangeEvent: true,
};
export default class Transform extends Component<Props, State> {
state: State = {
scale: 1,
editingScale: false,
cropPreset: undefined,
lockAspect: false,
...this.fromPreprocessorState(this.props.preprocessorState),
};
pinchZoom = createRef<PinchZoom>();
scaleInput = createRef<HTMLInputElement>();
// static getDerivedStateFromProps({ source, preprocessorState }: Props) {
// return {
// rotate: preprocessorState.rotate.rotate || 0,
// crop: preprocessorState.crop || false,
// flip: preprocessorState.flip || { horizontal: false, vertical: false },
// };
// }
componentWillReceiveProps(
{ source, preprocessorState }: Props,
{ crop, cropPreset }: State,
) {
if (preprocessorState !== this.props.preprocessorState) {
this.setState(this.fromPreprocessorState(preprocessorState));
}
const { width, height } = source.decoded;
const cropWidth = width - crop.left - crop.right;
const cropHeight = height - crop.top - crop.bottom;
for (const [id, preset] of Object.entries(cropPresets)) {
if (cropHeight * preset.ratio === cropWidth) {
if (cropPreset !== id) {
this.setState({ cropPreset: id as CropPresetId });
}
break;
}
}
}
private fromPreprocessorState(preprocessorState?: PreprocessorState) {
const state: Pick<State, 'rotate' | 'crop' | 'flip'> = {
rotate: preprocessorState ? preprocessorState.rotate.rotate : 0,
crop: Object.assign(
{
left: 0,
right: 0,
top: 0,
bottom: 0,
},
(preprocessorState && preprocessorState.crop) || {},
),
flip: Object.assign(
{
horizontal: false,
vertical: false,
},
(preprocessorState && preprocessorState.flip) || {},
),
};
return state;
}
private save = () => {
const { preprocessorState, onSave } = this.props;
const { rotate, crop, flip } = this.state;
let newState = cleanSet(preprocessorState, 'rotate.rotate', rotate);
newState = cleanSet(newState, 'crop', crop);
newState = cleanSet(newState, 'flip', flip);
if (onSave) onSave({ preprocessorState: newState });
};
private cancel = () => {
const { onCancel, onSave } = this.props;
if (onCancel) onCancel();
else if (onSave)
onSave({ preprocessorState: this.props.preprocessorState });
};
private zoomIn = () => {
if (!this.pinchZoom.current) throw Error('Missing pinch-zoom element');
this.pinchZoom.current.scaleTo(this.state.scale * 1.25, scaleToOpts);
};
private zoomOut = () => {
if (!this.pinchZoom.current) throw Error('Missing pinch-zoom element');
this.pinchZoom.current.scaleTo(this.state.scale / 1.25, scaleToOpts);
};
private onScaleValueFocus = () => {
this.setState({ editingScale: true }, () => {
if (this.scaleInput.current) {
// Firefox unfocuses the input straight away unless I force a style
// calculation here. I have no idea why, but it's late and I'm quite
// tired.
getComputedStyle(this.scaleInput.current).transform;
this.scaleInput.current.focus();
}
});
};
private onScaleInputBlur = () => {
this.setState({ editingScale: false });
};
private onScaleInputChanged = (event: Event) => {
const target = event.target as HTMLInputElement;
const percent = parseFloat(target.value);
if (isNaN(percent)) return;
if (!this.pinchZoom.current) throw Error('Missing pinch-zoom element');
this.pinchZoom.current.scaleTo(percent / 100, scaleToOpts);
};
private onPinchZoomChange = () => {
if (!this.pinchZoom.current) throw Error('Missing pinch-zoom element');
this.setState({
scale: this.pinchZoom.current.scale,
});
};
private onCropChange = (crop: CropBox) => {
this.setState({ crop });
};
private onCropPresetChange = (event: Event) => {
const { value } = event.target as HTMLSelectElement;
const cropPreset = value ? (value as keyof typeof cropPresets) : undefined;
const crop = { ...this.state.crop };
if (cropPreset) {
const preset = cropPresets[cropPreset];
const { width, height } = this.props.source.decoded;
const w = width - crop.left - crop.right;
const h = w / preset.ratio;
crop.bottom = height - crop.top - h;
if (crop.bottom < 0) {
crop.top += crop.bottom;
crop.bottom = 0;
}
}
this.setState({
crop,
cropPreset,
lockAspect: !!cropPreset,
});
};
private swapCropDimensions = () => {
const { width, height } = this.props.source.decoded;
let { left, right, top, bottom } = this.state.crop;
const cropWidth = width - left - right;
const cropHeight = height - top - bottom;
const centerX = left - right;
const centerY = top - bottom;
const crop = {
top: (width - cropWidth) / 2 + centerY / 2,
bottom: (width - cropWidth) / 2 - centerY / 2,
left: (height - cropHeight) / 2 + centerX / 2,
right: (height - cropHeight) / 2 - centerX / 2,
};
this.setCrop(crop);
};
private setCrop(crop: CropBox) {
if (crop.top < 0) {
crop.bottom += crop.top;
crop.top = 0;
}
if (crop.bottom < 0) {
crop.top += crop.bottom;
crop.bottom = 0;
}
if (crop.left < 0) {
crop.right += crop.left;
crop.left = 0;
}
if (crop.right < 0) {
crop.left += crop.right;
crop.right = 0;
}
this.setState({ crop });
}
// yeah these could just += 90
private rotateClockwise = () => {
let { rotate, crop } = this.state;
this.setState({
rotate: ((rotate + 90) % 360) as typeof ROTATE_ORIENTATIONS[number],
crop: {
top: crop.left,
left: crop.bottom,
bottom: crop.right,
right: crop.top,
},
});
};
private rotateCounterClockwise = () => {
let { rotate, crop } = this.state;
this.setState({
rotate: (rotate
? rotate - 90
: 270) as typeof ROTATE_ORIENTATIONS[number],
crop: {
top: crop.right,
right: crop.bottom,
bottom: crop.left,
left: crop.top,
},
});
};
private flipHorizontally = () => {
const { horizontal, vertical } = this.state.flip;
this.setState({ flip: { horizontal: !horizontal, vertical } });
};
private flipVertically = () => {
const { horizontal, vertical } = this.state.flip;
this.setState({ flip: { horizontal, vertical: !vertical } });
};
private toggleLockAspect = () => {
this.setState({ lockAspect: !this.state.lockAspect });
};
private setCropWidth = (
event: preact.JSX.TargetedEvent<HTMLInputElement, Event>,
) => {
const { width, height } = this.props.source.decoded;
const newWidth = Math.min(width, parseInt(event.currentTarget.value, 10));
let { top, right, bottom, left } = this.state.crop;
const aspect = (width - left - right) / (height - top - bottom);
right = width - newWidth - left;
if (this.state.lockAspect) {
const newHeight = newWidth / aspect;
if (newHeight > height) return;
bottom = height - newHeight - top;
}
this.setCrop({ top, right, bottom, left });
};
private setCropHeight = (
event: preact.JSX.TargetedEvent<HTMLInputElement, Event>,
) => {
const { width, height } = this.props.source.decoded;
const newHeight = Math.min(height, parseInt(event.currentTarget.value, 10));
let { top, right, bottom, left } = this.state.crop;
const aspect = (width - left - right) / (height - top - bottom);
bottom = height - newHeight - top;
if (this.state.lockAspect) {
const newWidth = newHeight * aspect;
if (newWidth > width) return;
right = width - newWidth - left;
}
this.setCrop({ top, right, bottom, left });
};
render(
{ mobileView, source }: Props,
{ scale, editingScale, rotate, flip, crop, cropPreset, lockAspect }: State,
) {
const image = source.decoded;
const width = source.decoded.width - crop.left - crop.right;
const height = source.decoded.height - crop.top - crop.bottom;
let transform =
`rotate(${rotate}deg) ` +
`scale(${flip.horizontal ? -1 : 1}, ${flip.vertical ? -1 : 1})`;
return (
<Fragment>
<CancelButton onClick={this.cancel} />
<SaveButton onClick={this.save} />
<div class={style.transform}>
<pinch-zoom
class={style.pinchZoom}
onChange={this.onPinchZoomChange}
ref={this.pinchZoom}
>
{/* <Backdrop width={image.width} height={image.height} /> */}
<div
class={style.wrap}
style={{
width: image.width,
height: image.height,
}}
>
<CanvasImage
class={style.pinchTarget}
image={image}
style={{ transform }}
/>
{crop && (
<Cropper
size={{ width: image.width, height: image.height }}
scale={scale}
lockAspect={lockAspect}
crop={crop}
onChange={this.onCropChange}
/>
)}
</div>
</pinch-zoom>
</div>
<div class={style.controls}>
<div class={style.zoomControls}>
<button class={style.button} onClick={this.zoomOut}>
<RemoveIcon />
</button>
{editingScale ? (
<input
type="number"
step="1"
min="1"
max="1000000"
ref={this.scaleInput}
class={style.zoom}
value={Math.round(scale * 100)}
onInput={this.onScaleInputChanged}
onBlur={this.onScaleInputBlur}
/>
) : (
<span
class={style.zoom}
tabIndex={0}
onFocus={this.onScaleValueFocus}
>
<span class={style.zoomValue}>{Math.round(scale * 100)}</span>%
</span>
)}
<button class={style.button} onClick={this.zoomIn}>
<AddIcon />
</button>
</div>
</div>
<div class={style.options}>
<h3 class={style.optionsTitle}>Modify Source</h3>
<div class={style.optionsSection}>
<h4 class={style.optionsSectionTitle}>Crop</h4>
<div class={style.optionOneCell}>
<Select
large
value={cropPreset}
onChange={this.onCropPresetChange}
>
<option value="">Custom</option>
{Object.entries(cropPresets).map(([type, preset]) => (
<option value={type}>{preset.name}</option>
))}
</Select>
</div>
<label class={style.optionCheckbox}>
<Checkbox checked={lockAspect} onClick={this.toggleLockAspect} />
Lock aspect-ratio
</label>
<div class={style.optionsDimensions}>
<input
type="number"
name="width"
value={width}
title="Crop width"
onInput={this.setCropWidth}
/>
<button
class={style.optionsButton}
title="swap"
onClick={this.swapCropDimensions}
>
<SwapIcon />
</button>
<input
type="number"
name="height"
value={height}
title="Crop height"
onInput={this.setCropHeight}
/>
</div>
<div class={style.optionButtonRow}>
Flip
<button
class={style.optionsButton}
data-active={flip.vertical}
title="Flip vertically"
onClick={this.flipVertically}
>
<FlipVerticallyIcon />
</button>
<button
class={style.optionsButton}
data-active={flip.horizontal}
title="Flip horizontally"
onClick={this.flipHorizontally}
>
<FlipHorizontallyIcon />
</button>
</div>
<div class={style.optionButtonRow}>
Rotate
<button
class={style.optionsButton}
title="Rotate clockwise"
onClick={this.rotateClockwise}
>
<RotateClockwiseIcon />
</button>
<button
class={style.optionsButton}
title="Rotate counter-clockwise"
onClick={this.rotateCounterClockwise}
>
<RotateCounterClockwiseIcon />
</button>
</div>
</div>
</div>
</Fragment>
);
}
}
const CancelButton = ({ onClick }: { onClick: () => void }) => (
<button class={style.cancel} onClick={onClick}>
<svg viewBox="0 0 80 80" width="80" height="80">
<path d="M8.06 40.98c-.53-7.1 4.05-14.52 9.98-19.1s13.32-6.35 22.13-6.43c8.84-.12 19.12 1.51 24.4 7.97s5.6 17.74 1.68 26.97c-3.89 9.26-11.97 16.45-20.46 18-8.43 1.55-17.28-2.62-24.5-8.08S8.54 48.08 8.07 40.98z" />
</svg>
<CompareIcon class={style.icon} />
<span>Cancel</span>
</button>
);
const SaveButton = ({ onClick }: { onClick: () => void }) => (
<button class={style.save} onClick={onClick}>
<svg viewBox="0 0 89 87" width="89" height="87">
<path
fill="#0c99ff"
opacity=".7"
d="M27.3 71.9c-8-4-15.6-12.3-16.9-21-1.2-8.7 4-17.8 10.5-26s14.4-15.6 24-16 21.2 6 28.6 16.5c7.4 10.5 10.8 25 6.6 34S64.1 71.7 54 73.5c-10.2 2-18.7 2.3-26.7-1.6z"
/>
<path
fill="#0c99ff"
opacity=".7"
d="M14.6 24.8c4.3-7.8 13-15 21.8-15.7 8.7-.8 17.5 4.8 25.4 11.8 7.8 6.9 14.8 15.2 14.8 24.9s-7.2 20.7-18 27.6c-10.9 6.8-25.6 9.5-34.3 4.8S13 61.6 11.6 51.4c-1.3-10.3-1.3-18.8 3-26.6z"
/>
</svg>
<CheckmarkIcon class={style.icon} />
</button>
);
interface BackdropProps {
width: number;
height: number;
}
/** @TODO this could at least use clip-path. It's too expensive this way. */
class Backdrop extends Component<BackdropProps> {
shouldComponentUpdate({ width, height }: BackdropProps) {
return width !== this.props.width || height !== this.props.height;
}
render({ width, height }: BackdropProps) {
const transform =
`transform-origin: 50% 50%; transform: translate(var(--x), var(--y)) ` +
`translate(-${width / 2}px, -${height / 2}px) ` +
`scale(calc(var(--scale, 1) * 0.99999));`;
return (
<svg
class={style.backdrop}
preserveAspectRatio="xMidYMid meet"
width="100%"
height="100%"
shape-rendering="optimizeSpeed"
>
<mask id="bgmask">
<rect width="100%" height="100%" fill="white" />
<rect
style={transform}
width={width}
height={height}
x="50%"
y="50%"
fill="black"
/>
</mask>
<rect
class={style.backdropArea}
width="100%"
height="100%"
mask="url(#bgmask)"
/>
</svg>
);
}
}

View File

@@ -0,0 +1,356 @@
.transform {
display: block;
}
.wrap {
overflow: visible;
/*
& > canvas {
transition: transform 150ms ease;
}
*/
}
.backdrop {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
transform: none !important;
will-change: initial !important;
contain: strict;
& * {
contain: strict;
}
/* background: rgba(255, 0, 0, 0.5); */
}
.backdropArea {
fill: rgba(0, 0, 0, 0.25);
}
.pinch-zoom {
composes: abs-fill from global;
outline: none;
display: flex;
justify-content: center;
align-items: center;
}
.pinch-target {
/* This fixes a severe painting bug in Chrome.
* We should try to remove this once the issue is fixed.
* https://bugs.chromium.org/p/chromium/issues/detail?id=870222#c10 */
will-change: auto;
/* Prevent the image becoming misshapen due to default flexbox layout. */
flex-shrink: 0;
}
.cancel,
.save {
composes: unbutton from global;
position: absolute;
padding: 0;
z-index: 2;
}
.save {
position: absolute;
right: 0;
bottom: 0;
display: grid;
align-items: center;
justify-items: center;
& > * {
grid-area: 1/1/1/1;
fill: #fff;
}
}
/* @TODO use grid */
.cancel {
fill: rgba(0, 0, 0, 0.7);
& > svg:not(.icon) {
display: block;
margin: -8px 0;
width: 80px;
height: 80px;
}
& > .icon {
position: absolute;
left: 28px;
top: 22px;
fill: #fff;
}
& > span {
display: inline-block;
padding: 4px 10px;
border-radius: 1rem;
background: rgba(0, 0, 0, 0.7);
font-size: 80%;
color: #fff;
}
&:hover,
&:focus {
fill: rgba(0, 0, 0, 0.9);
& > span {
background: rgba(0, 0, 0, 0.9);
}
}
}
.options {
position: fixed;
right: 0;
bottom: 78px;
color: #fff;
font-size: 1.2rem;
display: flex;
flex-flow: column;
max-width: 250px;
margin: 0;
width: calc(100% - 60px);
max-height: 100%;
overflow: hidden;
align-self: end;
border-radius: var(--options-radius) 0 0 var(--options-radius);
animation: slideInFromRight 500ms ease-out forwards 1;
--horizontal-padding: 15px;
--main-theme-color: var(--blue);
/* Hide on mobile (for now) */
@media (max-width: 599px) {
display: none;
}
}
@keyframes slideInFromRight {
0% {
transform: translateX(100%);
}
}
.options-title {
background-color: var(--main-theme-color);
color: var(--dark-text);
margin: 0;
padding: 10px var(--horizontal-padding);
font-weight: bold;
font-size: 1.4rem;
border-bottom: 1px solid var(--off-black);
}
.options-section {
padding: 5px 0;
background: var(--off-black);
}
.options-section-title {
font: inherit;
margin: 0;
padding: 5px var(--horizontal-padding);
}
.option-base {
display: grid;
gap: 0.7em;
align-items: center;
padding: 5px var(--horizontal-padding);
}
.options-button {
composes: unbutton from global;
width: 40px;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
border: 1px solid var(--dark-gray);
color: var(--white);
&:hover,
&:focus {
background-color: var(--off-black);
border-color: var(--med-gray);
}
&[data-active] {
background-color: var(--dark-gray);
border-color: var(--med-gray);
}
}
.options-dimensions {
composes: option-base;
grid-template-columns: 1fr 0fr 1fr;
input {
background: var(--white);
color: var(--black);
font: inherit;
border: none;
width: 100%;
padding: 4px;
box-sizing: border-box;
border-radius: 4px;
}
}
.option-one-cell {
composes: option-base;
grid-template-columns: 1fr;
}
.option-button-row {
composes: option-base;
grid-template-columns: 1fr auto auto;
}
.option-checkbox {
composes: option-base;
grid-template-columns: auto 1fr;
}
/** Zoom controls */
.controls {
position: absolute;
display: flex;
justify-content: center;
top: 0;
left: 0;
right: 0;
padding: 9px 84px;
flex-wrap: wrap;
/* Allow clicks to fall through to the pinch zoom area */
pointer-events: none;
& > * {
pointer-events: auto;
}
@media (min-width: 860px) {
padding: 9px;
top: auto;
left: 320px;
right: 320px;
bottom: 0;
flex-wrap: wrap-reverse;
}
}
.zoom-controls {
display: flex;
position: relative;
z-index: 100;
& > :not(:first-child) {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
margin-left: 0;
}
& > :not(:last-child) {
margin-right: 0;
border-right-width: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}
.button,
.zoom {
display: flex;
align-items: center;
box-sizing: border-box;
margin: 4px;
background-color: rgba(29, 29, 29, 0.92);
border: 1px solid rgba(0, 0, 0, 0.67);
border-radius: 6px;
line-height: 1.1;
white-space: nowrap;
height: 39px;
padding: 0 8px;
font-size: 1.2rem;
cursor: pointer;
/*
@media (min-width: 600px) {
height: 39px;
padding: 0 16px;
}
*/
&:focus {
/* box-shadow: 0 0 0 2px var(--hot-pink); */
box-shadow: 0 0 0 2px #fff;
outline: none;
z-index: 1;
}
}
.button {
color: #fff;
&:hover {
background: rgba(50, 50, 50, 0.92);
}
&.active {
background: rgba(72, 72, 72, 0.92);
color: #fff;
}
}
.zoom {
cursor: text;
width: 7rem;
font: inherit;
text-align: center;
justify-content: center;
&:focus {
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.2), 0 0 0 2px #fff;
}
}
span.zoom {
color: #939393;
font-size: 0.8rem;
line-height: 1.2;
font-weight: 100;
}
input.zoom {
font-size: 1.2rem;
letter-spacing: 0.05rem;
font-weight: 700;
text-indent: 3px;
color: #fff;
}
.zoom-value {
margin: 0 3px 0 0;
padding: 0 2px;
font-size: 1.2rem;
letter-spacing: 0.05rem;
font-weight: 700;
color: #fff;
border-bottom: 1px dashed #999;
}
.buttons-no-wrap {
display: flex;
pointer-events: none;
& > * {
pointer-events: auto;
}
}

Some files were not shown because too many files have changed in this diff Show More