Compare commits

...

449 Commits

Author SHA1 Message Date
87eae143ef Refactored to reflect the strict-csp API change to an options object 2022-01-10 16:36:36 +01:00
8aeea1dc04 Enabled unsafe eval 2021-12-23 09:29:04 +01:00
8a860f285c Added comments 2021-12-15 15:39:07 +01:00
dd2b2c361f Added comments 2021-12-15 15:38:28 +01:00
e673c9c772 Import strict-csp from npm 2021-12-15 15:29:43 +01:00
c484750779 Merge branch 'dev' into maudnals-csp 2021-12-15 11:09:19 +01:00
66ec763667 Merge pull request #1171 from TimvdLippe/fix-webassembly-instantiate 2021-10-20 15:42:50 +01:00
029eda7b37 Merge branch 'dev' into fix-webassembly-instantiate 2021-10-20 15:36:48 +01:00
e6810059ef Add warning for using multiple image pools
Instantiating and using multiple image pools is not intended and can
lead to memory problems. Instead, users should use a single pool and
reuse that pool across all image processing. Therefore, let's add
a warning in the README to specify call this out and avoid users
of running into issues.

Relates to #1065
2021-10-20 14:56:34 +01:00
4eba015009 Merge pull request #1165 from TimvdLippe/update-typescript 2021-10-20 13:25:54 +01:00
dd49a1f23d Merge branch 'dev' into update-typescript 2021-10-20 13:15:39 +01:00
5ecb99992c Merge pull request #1169 from TimvdLippe/update-prettier 2021-10-20 13:15:32 +01:00
d9c6ebe0a2 Merge branch 'dev' into update-prettier 2021-10-20 12:48:59 +01:00
fba67a7a18 Merge pull request #1170 from TimvdLippe/fix-husky 2021-10-20 12:47:01 +01:00
129b925098 Fix Husky pre-commit
By upgrading to version 7, we now ensure that NPM/Yarn will run
the `prepare` script and appropriately install Husky. This also
migrates us to the `pre-commit` hook as a separate file, rather
than as part of the `package.json` definition.
2021-10-20 12:44:12 +01:00
e23bc4d2e5 Update Prettier
Also manually run prettier on `src/` and `lib/` to ensure
consistent formatting.
2021-10-20 12:28:45 +01:00
f523a07f01 Update TypeScript and types packages
This pulls in TypeScript 4.4, which ships ResizeObserver in the DOM
types, as well as sets caught errors to `unknown`, requiring explicit
checks for `AbortError`.
2021-10-20 11:36:27 +01:00
e3f840c6da Added Apple touch Icon for PWA (#1160) 2021-10-15 11:52:13 +01:00
cad09160b6 Reducing browser spinner time (#1157) 2021-09-20 13:49:53 +01:00
9663c23489 Merge pull request #1151 from ergunsh/improve-encode-types
Improve `encode` API and its types
2021-09-17 13:50:29 +01:00
58d467fbba Added CSP generation code 2021-09-15 12:35:03 +02:00
b2465ebe48 Added lib-csp (temp until available as npm pckg) 2021-09-15 12:32:39 +02:00
8ea8d05706 Added needed dependency for CSP 2021-09-15 12:32:02 +02:00
95a1b35c91 Update encodedWith to contain resolved values
We already await the promises that we set on the `encodedWith` instead of setting already
resolved promises to `encodedWith` we can set the resolved values

So, the users can use like
`const { mozjpeg: { binary } } = await image.encode({ mozjpeg })` or
they can first run
`await image.encode({ mozjpeg })` and then
`image.encodedWith.mozjpeg.binary`
2021-09-10 15:18:14 +02:00
914cdea41d Return encode result from Image.encode calls
Before this, there were one way to use the API:
call `await image.encode({ mozjpeg: {} })`
then use `encodedWith` by asserting that `mozjpeg` property exists on it

After adding return value to encode, people
will be able to use it like
`const { mozjpeg } = await image.encode({ mozjpeg: {} });`
which provides better type safety
2021-09-10 14:45:20 +02:00
6bfce29af6 Improve typing of Image.encode
Instead of returning `any` we're now returning the whole object.

Still from typing perspective, the API is not that
great since we don't have any type relation
between `encode` calls and `encodedWith` property. Maybe we can think about
returning directly from `encode` call
with the returned object having properties
that is supplied in `encode` calls
2021-09-10 14:08:21 +02:00
64cad1cc23 Merge pull request #1123 from styfle/load-file-async
Reduce `@squoosh/lib` Node.js API usage (make it run on the web)
2021-09-08 22:30:53 +01:00
87f25d909b Merge branch 'dev' into load-file-async 2021-09-08 17:04:50 -04:00
bdfdaf53af Remove unused readme link per atjn
Co-authored-by: Anton <dev@atjn.dk>
2021-09-08 17:04:46 -04:00
1ab9e8b3ab Merge pull request #1141 from ergunsh/improve-exposed-types 2021-09-08 17:57:46 +01:00
2718077d3d Merge branch 'dev' into improve-exposed-types 2021-09-08 19:48:01 +03:00
255dfa434a Update pointer-tracker (#1147) 2021-09-07 14:43:19 +01:00
0bef05bcd4 Remove origin trial header 2021-09-06 15:00:48 +01:00
c4bc369c6b Fix typo in triangle 2021-09-03 15:03:28 +03:00
68ce8f420d Improve encode parameter typing 2021-09-03 14:54:08 +03:00
27f103fee5 Improve preprocess parameter type 2021-09-03 11:53:52 +03:00
c21d3714a8 Fix link in readme 2021-09-02 16:38:22 -04:00
3ea0d88c4f Apply suggestions from atjn
Co-authored-by: Anton <dev@atjn.dk>
2021-09-02 16:36:37 -04:00
00cfdafdf3 Merge pull request #1138 from jcao219/fix-windows-path
Use pathify to calculate absolute paths for cross-platform compatibility
2021-08-31 13:34:28 +01:00
92f52319da Use pathify to calculate absolute paths for cross-platform compatibility 2021-08-31 00:18:21 -07:00
023304803f JPEG-XL: Better 'effort' and adding noise synth (#1039) 2021-08-27 14:18:54 +01:00
6b08cd2355 Aliasing toggle button (#1132) 2021-08-26 16:44:20 +01:00
db1a5138e6 Fix pinch zoom on iOS (#1133) 2021-08-26 15:59:42 +01:00
a547491146 Maintain DC_SCAN_OPT_MODE if subsampling is > 2. Fixes #1129 (#1130) 2021-08-26 14:29:13 +01:00
6e427f9208 The observer is null if user prefers reduced motion
Turns out TypeScript is there for a reason and shouldn't be bypassed. Fixes #1135
2021-08-25 14:10:57 +01:00
0d35fbd349 Fix horizontal scroll on option elements on mobile (#1134) 2021-08-25 09:25:09 +01:00
4e901c714c [RFC] Add Three Homepage Sections (#1112) 2021-08-25 09:08:22 +01:00
b74788e036 Stable mousewheel scrolling, one wheel up + one wheel down = no change (#1131) 2021-08-24 14:52:25 +01:00
14c3d190e9 Max cap on scale #905 (#1128) 2021-08-23 13:27:17 +01:00
202d0bc088 Generalize file to ArrayLike<number> 2021-08-20 18:48:30 -04:00
bdb5b16372 Remove Buffer from decodeFile() 2021-08-20 18:36:23 -04:00
30140c2b7a Fix CLI bug 2021-08-20 18:35:29 -04:00
10996cdbca Add missing import 2021-08-20 16:08:01 -04:00
e5806507d4 Remove Node.js API surface in libsquoosh 2021-08-20 15:11:14 -04:00
1c5b44f9a1 Add loadFile parameter to ImagePool 2021-08-16 16:51:23 -04:00
eeaa19589e Merge pull request #1120 from veluca93/jxl_05
Bump JPEG XL to v0.5.
2021-08-14 09:23:04 +01:00
35b8c56f1a Bump JPEG XL to v0.5. 2021-08-13 23:27:44 +02:00
816d1f92fd Merge pull request #1110 from styfle/libsquoosh-ts-remaining 2021-08-10 12:38:11 +01:00
4091f2efec Remove unused export 2021-08-06 13:20:14 -04:00
821d14c6ab Merge branch 'dev' into libsquoosh-ts-remaining 2021-08-06 13:02:46 -04:00
a72ca46531 Move as to input param instead of return type 2021-08-06 12:49:17 -04:00
fafcf97f0c Update code for the review comments
* Make decode module return value `ImageData`
* Fix global definition of ImageData
* Use concrete Encoder types for encode functions
* Use ArrayBufferView in FileLike instead of using a similar type
* Throw error when the `encode` functions
return null
* Use generic types for WorkerPool
* Fix `encode` function typing
in `index.ts`
* Remove ts-ignore for web-streams-polyfill
and handle nulls for TransformStream
* Fix rollup entry point (now we need to have
`index.ts` instead of `index.js`)
2021-08-06 16:05:14 +03:00
d526877147 Merge pull request #1099 from mikedelgaudio/add-meta-info 2021-07-27 11:48:04 +01:00
0ed7ef842f Include site origin in build 2021-07-27 11:30:58 +01:00
de4eb9c8f7 Add encode() and decode() types 2021-07-26 23:22:28 -04:00
16a53caa48 Convert remaining JS to TS in libSquoosh 2021-07-26 22:37:00 -04:00
3d4c62fede Merge branch 'dev' into add-meta-info 2021-07-26 12:23:06 -04:00
ce7be359c0 remove keywords
Co-authored-by: Anton <dev@atjn.dk>
2021-07-26 12:23:00 -04:00
3f2dd66726 Merge pull request #1030 from veluca93/jxl_github 2021-07-23 13:49:46 +01:00
9198f748b8 Merge branch 'dev' into jxl_github 2021-07-23 13:37:37 +01:00
a726adf0e8 Merge pull request #1107 from styfle/patch-1
Fix typo uncluding => including
2021-07-23 13:15:21 +01:00
04580b0bcb Fix typo uncluding => including 2021-07-22 13:48:19 -04:00
a040c47047 Update JPEG XL to latest version.
Also update repositories.
2021-07-21 18:55:52 +02:00
2427763a14 Squoosh CLI v0.7.2 2021-07-21 17:19:19 +01:00
c582c54922 libsquoosh v0.4.0 2021-07-21 17:15:59 +01:00
9ae27c1887 Merge pull request #1106 from GoogleChromeLabs/issue-1102 2021-07-21 17:03:21 +01:00
bf95eb39c2 Fix handling of PNGs that are not 8 bit 2021-07-21 16:16:44 +01:00
011c0346c1 Merge pull request #1100 from MaxGraey/opt-visdif-codec 2021-07-20 19:17:23 +01:00
9b36c3f9af Merge remote-tracking branch 'origin/dev' into opt-visdif-codec 2021-07-20 19:14:54 +01:00
490fe2aace Add build instructions 2021-07-20 19:14:23 +01:00
48efb4ddeb remove twitter image 2021-07-20 10:55:47 -04:00
0977bd94d3 Merge pull request #1074 from GoogleChromeLabs/avif-node-mt 2021-07-20 12:01:47 +01:00
d5f12a8c61 Merge remote-tracking branch 'origin/dev' into avif-node-mt 2021-07-20 11:51:10 +01:00
fb867dcdaa Review by rreverser 2021-07-20 11:50:48 +01:00
f038c1bd7d Update src/static-build/pages/index/index.tsx 2021-07-20 11:26:19 +01:00
b37cc0784f typo fix for secure 2021-07-19 20:31:58 -04:00
ff40000473 adding secure 2021-07-19 20:28:23 -04:00
7232524f4d add twitter 2021-07-19 20:20:03 -04:00
bf683cdf59 Merge pull request #1093 from mikedelgaudio/update-readme
[DOCS] Update README, Remove Passive Voice
2021-07-19 17:27:54 +01:00
f848a9384e Merge branch 'dev' into update-readme 2021-07-19 11:48:13 -04:00
d4d0db6c49 update header statement 2021-07-19 11:47:52 -04:00
0719abff27 Merge pull request #1081 from atjn/unused-code
Remove unused variable
2021-07-19 12:42:01 +01:00
2c561687af Merge branch 'dev' into unused-code 2021-07-19 12:39:51 +01:00
cd20082e5d Build wasm 2021-07-19 12:36:43 +01:00
8262c79bb6 fix 2021-07-13 22:38:30 +03:00
ef176d7565 optimize more 2021-07-13 22:38:10 +03:00
3b0b7dbdb1 fix 2021-07-13 19:00:26 +03:00
cc9a887386 optimize srgb -> linear preparation by using lookup table 2021-07-13 18:33:15 +03:00
71ca1ab0ca Update src/static-build/pages/index/index.tsx
Co-authored-by: Joan León <joan.leon@gmail.com>
2021-07-12 14:40:37 -04:00
f5d9535fd2 adding meta tags for better SEO 2021-07-12 11:13:51 -04:00
cea6a61366 Modify meta data 2021-07-09 15:53:18 -04:00
192cfc62ee Update README.md 2021-07-07 09:57:44 -04:00
fe21322b2b [DOCS] Update list of develop steps 2021-07-06 14:34:04 -04:00
d953822d19 [DOCS] Remove passive voice, simplify README 2021-07-05 22:37:04 -04:00
021b082884 [DOCS] Remove passive voice, simplify README 2021-07-05 22:24:20 -04:00
ad5002c79c Merge pull request #1078 from ergunsh/auto-optimizer-to-ts
Typescriptify auto optimizer in libSquoosh
2021-07-01 15:53:06 +01:00
883bb92e48 Merge branch 'dev' into auto-optimizer-to-ts 2021-07-01 15:45:38 +01:00
79efd0d32e Merge pull request #1080 from pekeq/doc-resize-with-aspect
libsquoosh/README: Add code example to resize with aspect ratio preserved.
2021-07-01 15:45:32 +01:00
99741d665d Merge branch 'dev' into auto-optimizer-to-ts 2021-07-01 15:22:23 +01:00
b38765b4e6 Merge branch 'dev' into doc-resize-with-aspect 2021-07-01 15:22:13 +01:00
a11ac15008 fix: Don't overwrite value while typing (#1082)
Fixes #316
2021-07-01 11:11:00 +01:00
4f6d21199c Remove unused variable 2021-07-01 00:08:58 +02:00
fb7e00067f Update libsquoosh/README.md code example
Add code example to resize with aspect ratio preserved.
2021-06-30 22:43:20 +09:00
a2121ec47b Typescriptify auto optimizer in libSquoosh 2021-06-27 22:27:43 +02:00
d4056026fb Add AVIF thread support 2021-06-25 00:11:25 +01:00
d12b040bd3 Add threaded AVIF encoder for node 2021-06-24 17:07:57 +01:00
149ebf5a67 Merge pull request #1073 from atjn/patch-1
Fix codecs link
2021-06-24 16:35:31 +01:00
d8297aad10 Fix codecs link 2021-06-24 17:03:17 +02:00
0e84a5b5f7 Merge pull request #1071 from simon04/patch-1 2021-06-24 10:56:26 +01:00
187a5bed01 cli/README: linkfix src/codecs.ts 2021-06-24 09:34:09 +02:00
07a288398e Spotted another leak (#1069) 2021-06-23 10:39:27 +01:00
dbb31a1add Merge remote-tracking branch 'origin/dev' into dev 2021-06-21 12:58:41 +01:00
6e58e8edb0 Merge pull request #1061 from atjn/engines
Specify supported node versions
2021-06-21 12:58:28 +01:00
955079b18f Merge branch 'dev' into engines 2021-06-21 12:53:32 +01:00
f6f70c590e Add repo info in package.json so that people can backtrack from npm site (#1066) 2021-06-21 11:59:21 +01:00
55c4aa51ac Merge pull request #1063 from SimonGolms/patch-1
fix(cli): append suffix option at the end
2021-06-19 14:25:55 +01:00
aea316c604 fix(cli): append suffix option at the end
- close #1062
2021-06-19 11:40:52 +02:00
d604e94ad2 Specify supported node versions 2021-06-18 21:18:37 +02:00
61de471e52 Merge pull request #1058 from atjn/fix-detectors
Fix WebP sniffing some more
2021-06-18 15:58:03 +01:00
955b2ac1ba Fix WebP sniffing some more 2021-06-18 15:51:20 +02:00
3d225966c5 CLI v0.7.1 2021-06-16 17:13:59 +01:00
851da25302 Update CLI dependency 2021-06-16 17:13:37 +01:00
32e3528666 libsquoosh v0.3.1 2021-06-16 17:11:15 +01:00
1e52837931 Oooops. Old files 2021-06-16 17:02:54 +01:00
5bc80e66ec Merge remote-tracking branch 'origin/dev' into visdif-error 2021-06-16 13:54:49 +01:00
b1f50cd27c Fix AVIF auto optimizer options 2021-06-16 13:54:17 +01:00
3d136016e2 Provide optimizer default value 2021-06-16 13:44:24 +01:00
14a715e952 Add test files for now 2021-06-16 12:56:37 +01:00
324b04d398 Merge pull request #1044 from ergunsh/libsquoosh-codecs-to-ts
Typescriptify libsquoosh's codecs.js and emscripten-utils.js
2021-06-16 11:47:21 +01:00
eb76fbc4bc Merge branch 'dev' into libsquoosh-codecs-to-ts 2021-06-16 11:43:35 +01:00
1d292468b0 Everything supports ResizeObserver now 2021-06-16 10:13:46 +01:00
828f9a5eeb Fix memory leaks (#1054) 2021-06-15 10:45:53 +01:00
5595525c8a Merge pull request #1053 from alex-drocks/patch-1
Update README.md @libSquoosh code example
2021-06-11 16:25:23 +01:00
5e14444b13 Update README.md
To close typo in example code as reported in issue #1051
2021-06-11 09:36:30 -04:00
3d58c616af Merge branch 'dev' into libsquoosh-codecs-to-ts 2021-06-10 18:31:02 +02:00
d7090042a6 Fix alignment issue 2021-06-10 12:25:58 -04:00
be3249bf2f Add test case 2021-06-10 11:31:59 -04:00
1b59c3f47a Keep js extension while importing module & types 2021-06-09 18:11:30 +02:00
9a37cc7959 Merge pull request #1042 from GoogleChromeLabs/issue-1022 2021-06-09 12:17:00 +01:00
ffb9135a7a Merge remote-tracking branch 'origin/dev' into issue-1022 2021-06-09 06:35:00 -04:00
5707eeff41 Return Uint8ClampedArray in resize operation 2021-06-08 20:28:22 +02:00
a18ed360eb Address review comments
* Updated import to contain file extension `js`
* Separated WebAssembly definitions from missing-types
* Converted resizer.resize result to Uint8ClampedArray
* Moved ResizeInstantiateOptions to an interface
2021-06-08 20:09:37 +02:00
011d0c2099 Update AVIF 2021-06-08 16:51:08 +01:00
89105bbb22 Update wp2 2021-06-08 11:07:32 -04:00
5f7c619413 Update webp 2021-06-08 11:02:43 -04:00
3ec7d4db16 Update visdif 2021-06-08 10:59:47 -04:00
8ef8cef522 Update MozJPEG 2021-06-08 10:58:10 -04:00
f6431d8147 Update JXL 2021-06-08 10:54:16 -04:00
be037754ce Update imagequant 2021-06-08 10:43:33 -04:00
32107124e6 Update Emscripten version 2021-06-08 10:43:11 -04:00
1af5d1fa7b Typescriptify libsquoosh's codecs and emscripten-utils 2021-06-04 19:12:31 +02:00
08adfba8be Merge pull request #1037 from ergunsh/libsquoosh-ts-setup
Add initial ts setup for libsquoosh
2021-06-04 15:46:23 +01:00
5df04f6419 Update wp2 2021-06-04 09:51:10 -04:00
cf570a4d3f Update webp 2021-06-04 09:29:16 -04:00
2aa691339c Update visdif 2021-06-04 09:25:57 -04:00
9fcb4a4c55 Update mozjpeg 2021-06-04 09:23:23 -04:00
18e3d77aef Update jxl 2021-06-04 09:18:27 -04:00
6a4982bf4c Update imagequant 2021-06-04 08:52:46 -04:00
c7b998a877 Add flags 2021-06-04 08:33:57 -04:00
e5b2030666 Merge branch 'dev' into libsquoosh-ts-setup 2021-06-03 18:54:36 +02:00
0e09d0b33f Remove unnecessary missing-typed.d.ts for now
We don't need it for ImageData module
2021-06-03 18:50:44 +02:00
ed03a37fb8 Merge pull request #1041 from alexander-akait/issue-1034
fix: `main` filed
2021-06-03 11:18:41 +01:00
2bc4ab8fd6 fix: main filed 2021-06-03 12:36:49 +03:00
2037fe8964 Add an error for unsupported usage of new URL 2021-06-02 17:03:14 +01:00
d07c57ecaa Update lib/client-bundle-plugin.js 2021-06-02 17:03:14 +01:00
e7d55bf903 Update lib/entry-data-plugin.js
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
2021-06-02 17:03:14 +01:00
687cf5aae2 Bundle URL assets as dependencies
I've added support for `new URL(..., import.meta.url)` pattern accepted by many bundlers to wasm-bindgen and Emscripten, both for Wasm files as well as for side Workers autogenerated to support multithreading.

On the apps side like Squoosh this means we no longer have to manually specify URLs to be passed to wasm-bindgen or Emscripten init functions. In this PR I'm primarily doing just that - removing all the manual Wasm URL locators, as well as the associated logic.

One notable change on the build system side is that, in order for Wasm and multithreading-related Workers to be detected as dependencies, I'm now walking over `referencedFiles` in addition to `imports` when collecting list of dependencies in `getDependencies` function (client-bundle-plugin.js).

As a side effect, it also included other linked assets - images and CSS - which simplified quite a few caching lists in to-cache.ts as well. Instead of having to manually specify each asset that needs to be included, the logic is inverted and only few extra assets had to be excluded to keep the list of in items cached on the first load as low as it was before the change.

All in all, I think this simplification is worth it and even helped to accidentally uncover & fix one caching bug where WP2 regular JS was cached in addition to WP2 multithreaded JS simultaneously.
2021-06-02 17:03:14 +01:00
d63823d196 Add @web/rollup-plugin-import-meta-assets 2021-06-02 17:03:14 +01:00
7d111b6a43 Update wasm-bindgen 2021-06-02 17:03:14 +01:00
426f31e548 Upgrade Emscripten to 2.0.21
Few notes:
 - Lots of deprecated SIMD intrinsic warnings & errors in JPEG-XL -> Highway; had to suppress erorrs to make project build.
 - Moved couple of common link flags to cpp.Dockerfile (note: can't move `EXPORT_ES6` otherwise `configure` will fail).
 - MODULARIZE=1 is no longer necessary and implied by EXPORT_ES6.
 - EXPORT_NAME=... is no longer necessary in EXPORT_ES6.
 - Changed visdif to also use EXPORT_ES6 and ENVIRONMENT=node instead of generic JS.
2021-06-02 17:03:14 +01:00
dd0adba6b1 Revert "Remove SIMD for now (#1025)"
This reverts commit f779e13bc8.
2021-06-02 17:03:14 +01:00
30445927ea Add initial ts setup for libsquoosh
Convert `image_data` to typescript as an example
2021-05-31 21:45:28 +02:00
31b263fc27 Merge pull request #1035 from JustTestCode/patch-1
Update README.md
2021-05-30 10:06:01 +01:00
fc590918ed Update README.md
I check 2 hours, why can't run...
2021-05-30 12:16:58 +08:00
c4783b03df Merge pull request #1031 from GoogleChromeLabs/defensive-web-codec 2021-05-27 10:30:38 +01:00
8f9c0ff0e7 More defensive use of isTypeSupported 2021-05-27 09:14:13 +01:00
40c81ef782 Remove circular dependency 2021-05-27 09:13:17 +01:00
397193a5f5 <title> to indicate progress/error (#1023)
Fixes #644
2021-05-25 14:29:42 +01:00
f91c7a267d libsquoosh v0.2.3 2021-05-25 11:49:54 +01:00
99f2286a73 Better error handling for libSquoosh 2021-05-25 11:46:30 +01:00
f414092ea9 libsquoosh v0.2.2 2021-05-24 23:58:15 +01:00
c683dfaaed Merge branch 'libsquoosh-kinks' into dev 2021-05-24 23:57:33 +01:00
12fb647fde Fix JXL in libsquoosh 2021-05-24 23:57:24 +01:00
2ee1dfa867 Fix AVIF in libsquoosh 2021-05-24 23:54:26 +01:00
fa331586d7 Handle more input types gracefully 2021-05-24 17:56:53 +01:00
4192c607f1 Merge pull request #1018 from GoogleChromeLabs/web-codecs
Add a call-out to Web Codecs API during decoding
2021-05-24 17:08:54 +01:00
128096afd9 Make TS happy 2021-05-24 16:29:12 +01:00
58661078e2 Update src/client/lazy-app/util/index.ts
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
2021-05-24 16:26:20 +01:00
cbfa503fcb Update src/client/lazy-app/util/index.ts
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
2021-05-24 16:26:05 +01:00
96b6dc8e6e Merge branch 'dev' into web-codecs 2021-05-24 16:06:09 +01:00
4033d1c965 Move logic to builtinDecode 2021-05-24 15:39:38 +01:00
f779e13bc8 Remove SIMD for now (#1025)
This is by no means a proper fix, but Chrome 91 (stable tomorrow) brings some breaking changes to SIMD, and I'd rather disable SIMD for now to avoid breaking Squoosh altogether once it hits stable, and work on a proper fix in a separate branch.
2021-05-24 12:50:48 +01:00
2f00fe2b1b I’m an idiot 2021-05-21 15:14:22 +01:00
118885cd26 Fall through to built-in decoding 2021-05-21 15:13:00 +01:00
af80643809 Remove redundant code (#1024) 2021-05-21 11:16:47 +01:00
1aba7b51ee Merge pull request #1021 from atjn/documentation-fixes 2021-05-20 10:08:27 +01:00
b0a7b21b0b Merge branch 'dev' into documentation-fixes 2021-05-20 10:00:36 +01:00
8dfe35aa77 Merge pull request #1019 from atjn/readdir-fix-rebase 2021-05-20 09:59:08 +01:00
1a891072c0 Fix broken links after libsquoosh release 2021-05-20 09:36:37 +02:00
720cb98872 [CLI] Handle subdirectories without failing 2021-05-20 09:12:29 +02:00
4e1dcb819c Release v0.2.1 of libSquoosh 2021-05-19 12:30:05 +01:00
c36f4bebb8 Update libSquoosh README after rename 2021-05-19 12:28:35 +01:00
c04bb54f0d Merge branch 'API' into dev 2021-05-19 12:23:07 +01:00
4890c56abb Publish v0.2.0 of @squoosh/lib 2021-05-19 12:22:50 +01:00
392aced394 Introduce libSquoosh 2021-05-19 12:15:00 +01:00
8bcaeb2f78 Simplify types a bit 2021-05-18 20:04:35 +01:00
c417bd0a7a Its working now 2021-05-18 20:02:43 +01:00
eb8204d69b Add a call-out to Web Codecs API 2021-05-18 19:53:39 +01:00
25754b91b7 Change 'encodedAs' to 'encodedWith' 2021-05-13 19:34:50 +02:00
875c24525b Upgrade commander to v7 2021-05-13 19:07:42 +02:00
50ed5febd3 Stick to the term 'preprocessor' 2021-05-13 16:53:15 +02:00
10c5082499 Add back a loader customization for full URL (#1016)
Emscripten uses dynamic `import(fullUrlOfTheMainJS)` in generated Workers.

It appears that upstream rollup-plugin-off-main-thread never handled this correctly, but we had a customization in Squoosh loader template that allowed those anyway, which I removed together with most other customizations in #1007, thus breaking Emscripten codecs.

This adds a hotfix back, but we need to fix this properly upstream too (TBD separately).
2021-05-13 15:48:23 +01:00
f0fb891498 Updating oxi, adding interlace option (#1014) 2021-05-13 14:22:19 +01:00
b9b6e57581 wasm-bindgen-rayon and new OMT plugin (#1007)
* WIP: wasm-bindgen-rayon and new OMT plugin

* Bump package-lock

* Make OMT work again

* Update year

* Restore accidental change

* Prevent minification of `nextDefineUri`

* Delay loading external deps

This gives inline `define` calls a chance to define dependencies for earlier `define` calls on the same page.

* Add comment
2021-05-13 13:50:31 +01:00
ff9dea465f Updating AVIF, and 'auto' SSIM option (#1008) 2021-05-10 18:56:33 +01:00
912c1fac08 Better DC pass (#1006) 2021-05-06 15:02:04 +01:00
ad0d46de3e Fix typo in README 2021-05-04 15:40:44 +02:00
efc89efba5 JXL decoding speed tier (#1001) 2021-05-04 13:16:54 +01:00
8ed50d8f0c Fix install command in README 2021-05-04 14:13:34 +02:00
b50402e3b3 Separate CLI and API 2021-05-04 12:57:48 +02:00
df65f1a112 Update JPEG XL to latest. (#1000) 2021-05-04 11:47:19 +01:00
58c09ff740 Adding COOP+COEP headers to dev 2021-05-04 10:57:58 +01:00
33c0c3b034 Additional AVIF options (#987)
* Separate colour & alpha options for AVIF

* Adding broken noise synthesis

* Build files

* Updating build

* Changing speed default

* Remove old comment

* Better speed default
2021-04-29 11:19:24 +01:00
e900d33092 Fix alpha regression in resizer (#995) 2021-04-28 15:33:44 +01:00
650c662ffa Re-enable SIMD with new origin trial token (#985)
Not bothering with renewing for dev, since it's going to be in stable Chrome soon.
2021-04-06 14:13:30 +01:00
2bf0b904cd Don't listen for two-up keyboard shortcuts if in input (#979) 2021-03-23 13:04:15 +00:00
9d890a8fd6 Fix AVIF multithreading (#981) 2021-03-23 12:28:56 +00:00
914bff41c6 Merge pull request #972 from GoogleChromeLabs/png-decoder-colors
[cli] Handle all color types in png decoder
2021-03-11 16:10:45 +00:00
86c4271844 Merge branch 'dev' into png-decoder-colors 2021-03-11 16:04:51 +00:00
56beb6786a [cli] Handle all color types in png decoder
Add conversions for all color types in PNG decoder used in CLI. (While at it, also made few minor cleanups.)

Fixes #971.
2021-03-11 15:21:45 +00:00
ef77da9e96 Fix JXL mimetype (#970) 2021-03-10 14:56:59 +00:00
42cfbe11a1 Better AVIF options (#965)
* Better AVIF options

* Removing internal URL

* Remove AQ, add SSIM

* Better cast
2021-03-10 14:12:54 +00:00
0874a3ba52 Update JPEG XL and support container format in mime sniffing. (#969) 2021-03-10 13:24:52 +00:00
7f6ee3204f Remove mt AVIF encoder for now (#964) 2021-03-03 12:02:43 +00:00
37d778e4da Merge pull request #963 from veluca93/jxl_uprev
Update JPEG XL.
2021-02-24 16:44:22 +00:00
8f24c9b5ce Update JPEG XL.
This in particular fixes encoding with progressive enabled.
2021-02-24 16:38:22 +01:00
9d3401762e Merge pull request #962 from GoogleChromeLabs/butteraugli-fix 2021-02-22 18:07:33 +00:00
a783de618d Review 2021-02-22 18:05:26 +00:00
659d2b8277 Fix butteraugli for auto-optimizer 2021-02-22 17:58:15 +00:00
934ab9065a Merge pull request #957 from veluca93/jxl_v03
Bump jxl version and remove workaround for enc memory usage.
2021-02-11 14:50:44 +00:00
029c2ebb83 Bump jxl version and remove workaround for enc memory usage. 2021-02-10 12:55:18 +01:00
dc40f84a65 Update stuff and keep new Typescript happy 2021-01-25 15:35:52 +00:00
2c0dd363d4 Merge pull request #949 from GoogleChromeLabs/RReverser-patch-1
Remove no-op variable in imagequant Makefile
2021-01-22 19:25:41 +00:00
e6916575b7 Remove no-op variable in imagequant Makefile
One more follow-up...
2021-01-22 15:30:41 +00:00
1c7486056d Avoid cache when updating SW, for now 2021-01-22 13:58:16 +00:00
8e8b75684d Remove caching headers for now 2021-01-22 13:51:30 +00:00
92ade727aa Fix browser version of imagequant (#947)
Fix Makefile compiling same file twice and overriding the correct browser version (ENVIRONMENT=$(ENVIRONMENT)) with Node.js one (ENVIRONMENT=node).

Looks like this was introduced by accident in 33d60658cd.

Fixes #946.
2021-01-22 13:13:18 +00:00
6117c9dd26 Update HQX to latest (#943)
I've played a bit and added a non-invasive change to the HQX - https://github.com/CryZe/wasmboy-rs/pull/1 - to work around the code size regression (https://github.com/rust-lang/rust/issues/74947) introduced in the latest Rust.

As a side benefit of the change, the build time also went down significantly and now takes only 1 minute altogether - including spawning Docker, fetching Cargo, building Wasm and optimising it with wasm-opt - instead of 15-20 minutes it took before.

P.S. h/t @CryZe for a very quick review & publish.
2021-01-22 12:27:44 +00:00
a3be343959 Add manifest fields for PWA install bottom sheet (#933)
* Add manifest fields for PWA install bottom sheet

* Switch to webp

* Revert "Switch to webp"

This reverts commit c60d0d9629.

* Try JPEG

* Use mime-type library

* Automate image size

Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
2021-01-21 09:45:52 +00:00
39c6be41df Merge pull request #937 from akrisrn/patch-1
Update CLI README.md
2021-01-20 12:34:42 +00:00
5603f2d6e7 Merge branch 'dev' into patch-1 2021-01-20 12:31:46 +00:00
0d72f652c5 Merge pull request #940 from GoogleChromeLabs/reproducible-mozjpeg
Make MozJPEG builds reproducible
2021-01-19 16:56:53 +00:00
7ce0c8a4fc Make MozJPEG builds reproducible
I was wondering why MozJPEG produces different Wasm binaries even when nothing is changed.

After looking at the binary diffs, I think I have figured & fixed the reason.
2021-01-19 13:21:00 +00:00
30528c2330 Disable filesystem in C++ codecs (#938) 2021-01-18 12:59:40 +00:00
b4329c5bed Rebuild codecs (#935) 2021-01-18 12:29:38 +00:00
5845e566da Update README.md 2021-01-16 01:24:27 +08:00
5d0c856fa0 match manifest.json (#936)
removes the orange for the hotpink
2021-01-15 09:00:13 +00:00
ff25dd81f8 Merge pull request #931 from GoogleChromeLabs/unaligned_access_is_fast
Use UNALIGNED_ACCESS_IS_FAST for OxiPNG -> libdeflate
2021-01-13 13:16:45 +00:00
c7d156e8d7 Use UNALIGNED_ACCESS_IS_FAST for OxiPNG -> libdeflate
I only observed ~10-15% increase in perf on single-threaded bench, which isn't much, but no harm in adding flag anyway.

Fixes #833.
2021-01-13 13:07:01 +00:00
02532b5a31 Merge pull request #930 from GoogleChromeLabs/wp2-update
Update WP2
2021-01-07 20:57:29 +00:00
c5c95254f0 Update WP2 2021-01-07 17:46:54 +00:00
dfa7695a97 Switch to upstream freestanding support (#864)
Co-authored-by: Jake Archibald <jaffathecake@gmail.com>
2021-01-06 17:16:10 +00:00
7095ed2f7a Merge pull request #911 from aethelz/fix-permissions 2021-01-05 16:52:25 +00:00
61a66c4ed4 Merge branch 'dev' into fix-permissions 2021-01-05 16:40:57 +00:00
c6188c8846 Merge pull request #927 from veluca93/update_jxl_v02 2021-01-05 16:40:39 +00:00
ae583f7581 Merge branch 'dev' into update_jxl_v02 2021-01-05 16:37:42 +00:00
22a948267c Rebuild WebP codec 2021-01-05 16:23:46 +00:00
35f5ad6e2b Merge branch 'dev' into fix-permissions 2021-01-05 16:22:10 +00:00
34d3c13b5d Merge pull request #910 from GoogleChromeLabs/banding-fix 2021-01-05 15:32:14 +00:00
dba8f097d3 Merge remote-tracking branch 'origin/dev' into banding-fix 2021-01-05 15:30:07 +00:00
36293d756b Move variable assignment out of loop 2021-01-05 15:29:57 +00:00
ad07584730 Update codecs/resize/src/lib.rs
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2021-01-05 14:50:08 +00:00
e260994600 Update codecs/resize/src/lib.rs 2021-01-05 14:49:41 +00:00
f55e4cf9a8 Update codecs/resize/src/lib.rs
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2021-01-05 14:49:08 +00:00
a1ea6223ac Merge branch 'dev' into fix-permissions 2021-01-05 14:38:35 +00:00
e7e205c326 Simplify WorkerPool joining (closes #925) 2021-01-05 14:26:26 +00:00
990a43b733 Merge pull request #923 from DetachHead/dev 2021-01-05 12:51:59 +00:00
1a40c57876 Merge branch 'dev' into banding-fix 2021-01-05 12:34:29 +00:00
e8afe408f1 Update JPEG XL to v0.2 (format freeze). 2020-12-31 00:05:25 +01:00
9352569852 remove outdated comment 2020-12-27 16:01:02 +10:00
10d648c28d check if path is directory using lstat instead of requiring trailing slash 2020-12-27 15:59:56 +10:00
1e64e52298 fix reading directories 2020-12-26 23:26:27 +10:00
733b470f1f allow passing entire directories as input 2020-12-26 22:56:23 +10:00
e72dcd6c6e Merge pull request #917 from dtinth/patch-1
Fix wrong development script in README
2020-12-19 18:30:44 +00:00
62b4d39128 Fix wrong development script in README 2020-12-19 05:46:16 +07:00
d338e8a048 Merge pull request #813 from samal-rasmussen/keyboard-shortcuts 2020-12-15 12:04:17 +00:00
f2a947df9e Merge branch 'dev' into keyboard-shortcuts 2020-12-15 12:01:04 +00:00
3ec55b0a03 Merge pull request #913 from GoogleChromeLabs/default-resize-type
Make vector the default resize type for vector images
2020-12-15 11:53:05 +00:00
3338808f17 Make vector the default resize type for vector images 2020-12-15 10:42:18 +00:00
5bdba43b33 Fix oxipng build script permissions 2020-12-13 20:18:33 +03:00
c63120d4ce Minor cleanup 2020-12-13 16:36:00 +00:00
405dd1cdfa Fix banding from linear RGB color space conversion 2020-12-13 16:27:59 +00:00
b958d46086 Add keyboard shortcuts for moving the split view separator 2020-12-10 19:58:10 +00:00
c3d05e0e2d Merge pull request #892 from XhmikosR/gitignore 2020-12-10 14:00:56 +00:00
0c848a33ad Merge branch 'dev' into gitignore 2020-12-10 13:49:38 +00:00
57357f5c8d Merge pull request #894 from fernap3/validate-input-files
Validate that input files exist before attempting to process them
2020-12-10 13:22:11 +00:00
6bfd1f2c29 Merge branch 'dev' into validate-input-files 2020-12-10 13:18:41 +00:00
8b20aa5f14 Merge branch 'dev' into gitignore 2020-12-10 13:11:45 +00:00
81e171e684 Merge pull request #891 from kurtextrem/patch-1
Fix typo
2020-12-10 13:06:52 +00:00
7b4dbbfe2d Merge branch 'dev' into patch-1 2020-12-10 13:03:27 +00:00
a972dfdeed Update .gitignore 2020-12-10 14:29:53 +02:00
f190ca6069 Merge branch 'dev' into validate-input-files 2020-12-10 12:26:54 +00:00
adb2f7ed50 Use real font. Fixes #895 2020-12-10 10:45:43 +00:00
d6de741ddc Copying over old sw-bridge
This is from the webpack build, but the old build failed to make this file work offline. It's the file that handles the "update available" stuff, which is why users using the old version aren't seeing the UI update. We can remove this file once everyone's off the old version.
2020-12-10 10:33:56 +00:00
b5f708a1e6 Fix formatting 2020-12-09 17:17:31 -05:00
15248bf85a Validate that input files exist before attempting to process them 2020-12-09 17:14:43 -05:00
5d691af8a1 Simpler fallback 2020-12-09 22:03:34 +00:00
722f1c806c Correct service worker name 2020-12-09 21:54:08 +00:00
522449adc1 Add .DS_Store to .gitignore. 2020-12-09 22:35:41 +02:00
07b4e53718 Fix typo 2020-12-09 19:15:12 +01:00
c6e6042726 Merge branch 'plan-b' into dev 2020-12-09 17:33:54 +00:00
94b9d08719 Update SIMD token (#889) 2020-12-09 16:26:30 +00:00
064b152e2a CLI v0.6.0 2020-12-09 16:06:58 +00:00
9de95f74fe Copy setting button 2020-12-09 14:36:50 +00:00
21a8f62dcc Styled viewport controls & cli copy 2020-12-09 14:28:32 +00:00
9062a75541 Cache correct assets (#887)
* Cache correct assets

* Update lib/entry-data-plugin.js

Co-authored-by: Surma <surma@surma.dev>

* Actually commit the fix this time

Co-authored-by: Surma <surma@surma.dev>
2020-12-09 12:20:14 +00:00
fec826b106 (Almost the) rest of the redesign (#880)
* Load demo img

* two-up styles

* Back button

* Button size tweak

* Move back btn

* Move options and back button into a single grid

* Simpler max height

* Responsive grid

* Feed index into options

* Option heading themes

* More option styles

* Changing checkbox position

* Theme range input & use transforms

* Range input underline theme

* Checkbox color

* Add toggle

* Reorder

* Arrow revealer

* Round two-up thumb

* Don't bundle CSS urls starting #

* Results in progress

* Fix Safari bugs

* Download blobs

* Loading spinner

* Hook up download button

* Different style for original image

* Mobile design for results

* Remove demo auto-loader

* Remove redundant colors

* Sticky headings
2020-12-09 11:47:23 +00:00
12889d9d50 Add node version of MozJPEG encoder & decoder (#886)
* Add node version of MozJPEG

* Update paths for MozJPEG encoder
2020-12-09 11:44:46 +00:00
a19e97b2ed Merge pull request #875 from GoogleChromeLabs/visdf 2020-12-09 10:19:16 +00:00
5765ea5aa4 Update cli/src/image_data.js 2020-12-09 10:16:02 +00:00
c11e99c811 collaboration 2020-12-08 18:21:42 -05:00
76d8a636af de-throned 2020-12-08 18:21:20 -05:00
5758e5db9a Fix PNG decoder returning Rust-owned ImageData 2020-12-08 20:19:48 +00:00
4e4778397f Update cli/src/codecs.js 2020-12-08 19:12:14 +00:00
aff137218d Update codecs/jxl/Makefile
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2020-12-08 18:28:24 +00:00
fa5bd3d1c6 Update cli/src/image_data.js
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2020-12-08 18:24:26 +00:00
d1533d66a2 Update cli/src/codecs.js
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2020-12-08 18:24:16 +00:00
83b52cabc1 Update cli/src/codecs.js
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2020-12-08 18:23:30 +00:00
c832287fa6 Release build of png 2020-12-08 18:15:45 +00:00
ed55660c88 Merge remote-tracking branch 'origin/dev' into visdf 2020-12-08 17:56:26 +00:00
33d60658cd Makefile review 2020-12-08 17:55:49 +00:00
5af8810e0b CLI code review 2020-12-08 16:33:33 +00:00
33c3fd3278 Update cli/lib/asset-plugin.js
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2020-12-08 16:25:33 +00:00
f5be882b10 Update cli/README.md 2020-12-08 16:15:13 +00:00
2a8a2f2952 Merge pull request #878 from veluca93/makefile_sha
Make the JXL Makefile work with both tags and SHAs.
2020-12-08 15:03:49 +00:00
200e01132c Make the JXL Makefile work with both tags and SHAs. 2020-12-08 11:18:20 +01:00
fe6cc5c503 Merge pull request #877 from veluca93/update_jxl 2020-12-07 14:37:54 +00:00
d25d01c705 Update JPEG XL to v0.1.1. 2020-12-07 14:23:58 +01:00
7699f75b45 Allow non-0 quality in webp (#876) 2020-12-07 11:35:27 +00:00
4976ad8481 v0.5.0 2020-12-05 22:07:39 +00:00
60cef4cb3a README update 2020-12-05 22:05:23 +00:00
6b8d2e058c Add node version of WebP 2020-12-05 22:04:53 +00:00
004e18036b Add a CLI README 2020-12-05 21:50:41 +00:00
f051dcb07c Add node version of WP2 2020-12-05 21:36:31 +00:00
4e5bb64565 Reenable rotate 2020-12-05 20:50:20 +00:00
89508c9385 Reenable resize 2020-12-05 20:26:05 +00:00
951e0dc93a Reenable PNG 2020-12-05 20:23:48 +00:00
c35c285273 Add node version for JXL 2020-12-05 20:23:44 +00:00
45fe4d2917 Add node version for imagequant 2020-12-05 20:23:35 +00:00
ef31e5cbd1 Add node version to AVIF 2020-12-05 20:23:34 +00:00
d8bd12fc6a Merge remote-tracking branch 'origin/dev' into visdf 2020-12-05 17:26:02 +00:00
3abc770053 Site isolation headers & redirect fix (#866)
* Fix redirect behaviour

* Generate headers file

* Specific redirect

* Another try

* And again

* Use dedent
2020-12-05 11:23:32 +00:00
a3b341f813 New homepage (#861)
* Paste button

* Logo and animated blobs

* Predictable initial blob position

* Initial blob shape

* Update canvas on resize if not updating every frame

* lol

* Get styles from CSS

* Background blobs

* Fade into the center

* Get initial focus

* Pause time while page is hidden

* Footer

* Optimise amount of initial CSS

* More CSS optimisation

* Install button

* Home page with demo loading

* Tweak size

* Replace thumbnails

* Responsive demo section

* Responsive main section

* Remove debug stuff

* Fix prerender SVG size

* Changes from feedback

* Blob nudges (#872)

* more smaller blobs

* less blobs that are practically invisible

* more dynamic speed range and stronger gravity

* Reverting resize observer change

The content rect is different to getBoundingClientRect

Co-authored-by: Adam Argyle <atom@argyleink.com>
2020-12-05 11:21:33 +00:00
58a6abffbb Threads and threads+SIMD builds for JPEG-XL (#865) 2020-12-02 15:40:16 +00:00
869d3f7732 Update WebP & WebP2 to latest upstream
Includes renaming "speed" to "effort" in WebP2.
2020-12-01 14:36:30 +00:00
618a4d777b Update WebP2 binding code 2020-12-01 14:36:30 +00:00
7266c94f52 Rebuild WebP 2020-12-01 14:36:30 +00:00
d15dba7d20 Make Docker runs interactive
Otherwise they're impossible to cancel via Ctrl+C and this is driving me mad.
2020-12-01 14:36:30 +00:00
0ded493489 Switch to upstream libwebp2 2020-12-01 14:36:30 +00:00
990018f758 Switch to upstream libwebp
The patches were merged now.
2020-12-01 14:36:30 +00:00
4f4eaf01b7 Add comment to thread_level in wp2 2020-12-01 14:36:30 +00:00
19fab33d3c Update webpEncode.ts 2020-12-01 14:36:30 +00:00
6f19d027b4 Delete processor.ts 2020-12-01 14:36:30 +00:00
73499d4a27 Add SIMD origin trial for dev--squoosh.netlify.app 2020-12-01 14:36:30 +00:00
8581785869 Rebase fixes 2020-12-01 14:36:30 +00:00
198ad0fb1b Add SIMD support to libwebp 2020-12-01 14:36:30 +00:00
f0d341aefa Update Emscripten for SIMD 2020-12-01 14:36:30 +00:00
69e62339e6 Fixup 2020-12-01 14:36:30 +00:00
195762f64f Point to custom fork for SIMD builds 2020-12-01 14:36:30 +00:00
a951096aaa Support threads and threads+SIMD in WebP2 2020-12-01 14:36:30 +00:00
24d241564e Simplify how BUILD_DIR is passed 2020-12-01 14:36:30 +00:00
3d1ecc1215 Don't restrict drag & drop to images (so it works with wp2 & JXL) 2020-11-23 14:23:21 +00:00
25fb1a9c80 Fix dev server config & redirect /editor 2020-11-23 14:20:41 +00:00
3ae1cf86f5 Autoformat staged C++ and Rust 2020-11-21 03:56:30 +00:00
a699a5c4dc Fix Lossless+Progressive JXL.
Also limit the workaround for memory usage to large images.
2020-11-20 22:27:49 +00:00
613401c541 Add .gitattributes to fold generated files in PRs 2020-11-20 22:21:21 +00:00
f450373e3f Fix nightly Rust pinning; rebuild Oxi 2020-11-20 22:21:21 +00:00
750872aca6 Delete old oxipng files 2020-11-20 22:21:21 +00:00
beaabe47dc Merge pull request #858 from GoogleChromeLabs/gh-actions
Switch from Travis to Github Actions
2020-11-20 17:08:51 -05:00
8f7369068c Remove sizereport step
Apparently it doesn't exist anymore, even though it was referenced in Travis.
2020-11-20 21:41:57 +00:00
10bfd60e20 Try to fix multiple OS 2020-11-20 21:39:18 +00:00
7f08348509 Delete .travis.yml 2020-11-20 21:37:38 +00:00
f77ddac652 Add Github Action 2020-11-20 21:37:00 +00:00
13631f1cfc Extra Wp2 Options (#853)
* wip

* wip

* Add extra options

* Even more options!

* Update src/features/encoders/wp2/client/index.tsx

Co-authored-by: Surma <surma@surma.dev>

Co-authored-by: Surma <surma@surma.dev>
2020-11-20 16:12:38 +00:00
f11e692d58 Unset loading on error. Fixes #855 2020-11-20 16:11:57 +00:00
f0221b626d Prettier ignore file 2020-11-20 11:51:43 +00:00
10c5ed0495 Don't prettify codec code 2020-11-20 10:48:41 +00:00
d945c79796 Use run-p for cross-platform parallel runs (#850) 2020-11-20 08:53:44 +00:00
30b628c1b9 Fixing windows build (#849)
Co-authored-by: Ingvar Stepanyan <rreverser@google.com>
2020-11-19 15:03:51 +00:00
6ebf94d1b6 Auto edge filter 2020-11-19 11:35:12 +00:00
a229662bed Change JXL defaults 2020-11-19 11:27:03 +00:00
e995b445ef Updating node version and lockfile 2020-11-19 11:20:04 +00:00
6da590c7d0 Merge branch 'rollup-build' into dev
# Conflicts:
#	_headers.ejs
#	codecs/oxipng/pkg/squoosh_oxipng_bg.js
#	src/codecs/avif/encoder.ts
#	src/codecs/oxipng/encoder.ts
#	src/codecs/processor.ts
#	src/codecs/util.ts
#	src/components/intro/imgs/logo.svg
#	src/missing-types.d.ts
#	webpack.config.js
2020-11-19 11:12:29 +00:00
56e10b3aa2 Rollup build 2020-11-19 11:00:23 +00:00
67df305594 v0.4.0 2020-11-02 17:00:14 +00:00
106d733fec Add rotate support 2020-11-02 16:59:29 +00:00
67c64d4df3 Add ImageQuant support 2020-11-02 16:09:58 +00:00
75d571cb6c Add proper aspect ratio resizing support 2020-11-02 15:14:07 +00:00
af954bd9e0 Build preprocessor pipeline 2020-11-02 14:55:29 +00:00
612cee0011 not-fully-working autoOptimize for oxipng 2020-10-05 22:51:53 -04:00
911ca32c35 Fancy progress output 2020-10-05 22:51:23 -04:00
49cb8b268c Fix misnamed butteraugliDistanceGoal parameter 2020-10-05 22:50:49 -04:00
4946268ae2 Move image decoding into the worker pool 2020-10-05 22:50:06 -04:00
4487da9e9e Add Babel to fix Node <14 compat 2020-10-05 22:45:36 -04:00
09f65d0cd7 Fix worker_pool for node 2020-10-05 22:38:23 -04:00
261b3ad013 0.3.1 2020-09-21 23:58:39 +01:00
1b886aa4e2 v0.3.0 2020-09-21 18:21:00 +01:00
1d5fd98a3e Add support for no-value encoder flags 2020-09-21 18:20:02 +01:00
588d5ad44e Add OxiPNG 2020-09-21 18:14:42 +01:00
139b635eed Add PNG encoding support 2020-09-18 16:00:29 +01:00
516c0aa8e7 Update wasm-bindgen version 2020-09-17 14:49:58 +01:00
273b4211c9 Add support for PNG decoding (encoding still buggy) 2020-09-16 23:59:06 +01:00
ef920ac6ba Add suffix support 2020-09-16 14:58:04 +01:00
f445a5dcbe Parameterize auto optimizer 2020-09-16 13:32:09 +01:00
c8dc88f8a1 Add auto optimizer 2020-09-15 17:53:49 +01:00
1d7b6ab13e v0.2.0 2020-09-14 17:23:01 +01:00
1e700cd7c3 Add better output formatting 2020-09-14 17:20:49 +01:00
01c04d4a72 Add worker pool implementation 2020-09-14 17:05:02 +01:00
df45b996d1 v0.1.3 2020-09-09 23:44:01 +01:00
c9a271f57a Use __filename for worker instead 2020-09-09 23:43:30 +01:00
c37f798565 v0.1.2 2020-09-09 23:38:39 +01:00
e9b9993189 Add shebang to output 2020-09-09 23:38:26 +01:00
96b1ec2356 v0.1.1 2020-09-09 23:30:07 +01:00
e5d254ad80 Add package-level bin 2020-09-09 23:29:48 +01:00
b1b3c8c461 v0.1.0 2020-09-09 18:57:32 +01:00
1f2f5d1c61 Add .npmignore 2020-09-09 18:52:21 +01:00
12a719f05a Make it public 2020-09-09 18:33:47 +01:00
28c7b7aa94 Put right package name 2020-09-09 18:26:42 +01:00
6e3e6af70e Moar prettier 2020-09-09 18:25:32 +01:00
31118daa18 Add .gitignore 2020-09-09 18:23:51 +01:00
47fb7f9f71 Rollup for proper CLI 2020-09-09 18:22:50 +01:00
3b07862efb Use workers for parallelization 2020-09-09 15:48:56 +01:00
f0eb79f2f1 Use all the codecs 2020-09-09 15:22:39 +01:00
ebdb00f50d Keep planarized reference image around across runs 2020-09-09 12:50:02 +01:00
4b6334a212 Switch to Butteraugli and simpel CLI 2020-09-08 00:18:57 +01:00
483daa0493 Trying out more 2020-08-27 20:01:36 +01:00
0b4a673b13 It runs but not really 2020-08-25 13:03:10 +01:00
8c56d16aea Switch to dssim_core 2020-08-24 17:06:08 +01:00
773208d76e Trying dssim 2020-08-24 14:01:48 +01:00
494 changed files with 34054 additions and 21479 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
/codecs/**/*.js linguist-generated=true
/codecs/*/pkg*/*.d.ts linguist-generated=true

22
.github/workflows/node.js.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Node.js CI
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- id: nvmrc
uses: browniebroke/read-nvmrc-action@v1
- uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvmrc.outputs.node_version }}'
- run: npm ci
- run: npm run build

10
.gitignore vendored
View File

@ -1,6 +1,12 @@
.tmp
node_modules
/build
/*.log
*.scss.d.ts
*.css.d.ts
build
*.o
.DS_Store
# Auto-generated by lib/feature-plugin.js
src/features-worker/index.ts
src/client/lazy-app/worker-bridge/meta.ts
src/client/lazy-app/feature-meta/index.ts

1
.husky/pre-commit Executable file
View File

@ -0,0 +1 @@
npx lint-staged

2
.nvmrc
View File

@ -1 +1 @@
10.16.2
14.15.1

12
.prettierignore Normal file
View File

@ -0,0 +1,12 @@
codecs
.tmp
node_modules
*.scss.d.ts
*.css.d.ts
build
*.o
# Auto-generated by lib/feature-plugin.js
src/features-worker/index.ts
src/client/lazy-app/worker-bridge/meta.ts
src/client/lazy-app/feature-meta/index.ts

4
.prettierrc.json Normal file
View File

@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}

View File

@ -1,7 +0,0 @@
language: node_js
cache: npm
script: npm run build
after_success: npm run sizereport
os:
- linux
- windows

View File

@ -1,32 +1,42 @@
# [Squoosh]!
[Squoosh] is an image compression web app that allows you to dive into the advanced options provided
by various image compressors.
[Squoosh] is an image compression web app that reduces image sizes through numerous formats.
# API & CLI
Squoosh has [an API](https://github.com/GoogleChromeLabs/squoosh/tree/dev/libsquoosh) and [a CLI](https://github.com/GoogleChromeLabs/squoosh/tree/dev/cli) to compress many images at once.
# Privacy
Google Analytics is used to record the following:
Squoosh does not send your image to a server. All image compression processes locally.
* [Basic visit data](https://support.google.com/analytics/answer/6004245?ref_topic=2919631).
* Before and after image size once an image is downloaded. These values are rounded to the nearest
kilobyte.
* If install is available, when Squoosh is installed, and what method was used to install Squoosh.
However, Squoosh utilizes Google Analytics to collect the following:
Image compression is handled locally; no additional data is sent to the server.
- [Basic visitor data](https://support.google.com/analytics/answer/6004245?ref_topic=2919631).
- The before and after image size value.
- If Squoosh PWA, the type of Squoosh installation.
- If Squoosh PWA, the installation time and date.
# Building locally
# Developing
Clone the repo, and:
To develop for Squoosh:
```sh
npm install
npm run build
```
1. Clone the repository
1. To install node packages, run:
```sh
npm install
```
1. Then build the app by running:
```sh
npm run build
```
1. After building, start the development server by running:
```sh
npm run dev
```
You can run the development server with:
# Contributing
```sh
npm start
```
Squoosh is an open-source project that appreciates all community involvement. To contribute to the project, follow the [contribute guide](/CONTRIBUTING.md).
[Squoosh]: https://squoosh.app
[squoosh]: https://squoosh.app

View File

@ -1,23 +0,0 @@
# Long-term cache by default.
/*
Cache-Control: max-age=31536000
# And here are the exceptions:
/
Cache-Control: no-cache
/serviceworker.js
Cache-Control: no-cache
/manifest.json
Cache-Control: must-revalidate, max-age=3600
# URLs in /assets do not include a hash and are mutable.
# But it isn't a big deal if the user gets an old version.
/assets/*
Cache-Control: must-revalidate, max-age=3600
# COOP+COEP for WebAssembly threads.
/*
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

View File

@ -1,2 +0,0 @@
/index.html / 301
/* /index.html 301

3
cli/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
build
.DS_Store

1
cli/.npmignore Normal file
View File

@ -0,0 +1 @@
node_modules

0
cli/.npmrc Normal file
View File

59
cli/README.md Normal file
View File

@ -0,0 +1,59 @@
# Squoosh CLI
Squoosh CLI is an _experimental_ way to run all the codecs you know from the [Squoosh] web app on your command line using WebAssembly. The Squoosh CLI uses a worker pool to parallelize processing images. This way you can apply the same codec to many images at once.
Squoosh CLI is currently not the fastest image compression tool in town and doesnt aim to be. It is, however, fast enough to compress many images sufficiently quick at once.
## Installation
The Squoosh CLI can be used straight from the command line without installing using `npx`:
```
$ npx @squoosh/cli <options...>
```
Of course, you can also install the Squoosh CLI:
```
$ npm i -g @squoosh/cli
$ squoosh-cli <options...>
```
## Usage
```
Usage: squoosh-cli [options] <files...>
Options:
-V, --version output the version number
-d, --output-dir <dir> Output directory (default: ".")
-s, --suffix <suffix> Append suffix to output files (default: "")
--max-optimizer-rounds <rounds> Maximum number of compressions to use for auto optimizations (default: "6")
--optimizer-butteraugli-target <butteraugli distance> Target Butteraugli distance for auto optimizer (default: "1.4")
--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
--wp2 [config] Use WebP2 to generate a .wp2 file with the given configuration
--oxipng [config] Use OxiPNG to generate a .png file with the given configuration
-h, --help display help for command
```
The default values for each `config` option can be found in the [`codecs.ts`][codecs.ts] file under `defaultEncoderOptions`. Every unspecified value will use the default value specified here. _Better documentation is needed here._
## Auto optimizer
Squoosh CLI has an _experimental_ auto optimizer that compresses an image as much as possible, trying to hit a specific [Butteraugli] target value. The higher the Butteraugli target value, the more artifacts can be introduced.
You can make use of the auto optimizer by using “auto” as the config object.
```
$ npx @squoosh/cli --wp2 auto test.png
```
[squoosh]: https://squoosh.app
[codecs.ts]: https://github.com/GoogleChromeLabs/squoosh/blob/dev/libsquoosh/src/codecs.ts
[butteraugli]: https://github.com/google/butteraugli

613
cli/package-lock.json generated Normal file
View File

@ -0,0 +1,613 @@
{
"name": "@squoosh/cli",
"version": "0.7.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@squoosh/cli",
"version": "0.7.2",
"license": "Apache-2.0",
"dependencies": {
"@squoosh/lib": "^0.4.0",
"commander": "^7.2.0",
"json5": "^2.2.0",
"kleur": "^4.1.4",
"ora": "^5.4.0"
},
"bin": {
"cli": "src/index.js",
"squoosh-cli": "src/index.js"
},
"engines": {
"node": " ^12.20.2 || ^14.13.1 || ^16.0.0 "
}
},
"node_modules/@squoosh/lib": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@squoosh/lib/-/lib-0.4.0.tgz",
"integrity": "sha512-O1LyugWLZjMI4JZeZMA5vzfhfPjfMZXH5/HmVkRagP8B70wH3uoR7tjxfGNdSavey357MwL8YJDxbGwBBdHp7Q==",
"dependencies": {
"wasm-feature-detect": "^1.2.11",
"web-streams-polyfill": "^3.0.3"
},
"engines": {
"node": " ^12.5.0 || ^14.0.0 || ^16.0.0 "
}
},
"node_modules/ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
},
"node_modules/bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
"integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
"dependencies": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
}
},
"node_modules/buffer": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
}
},
"node_modules/chalk": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
"integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==",
"dependencies": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
"integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==",
"dependencies": {
"restore-cursor": "^3.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/cli-spinners": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.6.0.tgz",
"integrity": "sha512-t+4/y50K/+4xcCRosKkA7W4gTr1MySvLV0q+PxmG7FJ5g+66ChKurYjxBCjHggHH3HA5Hh9cy+lcUGWDqVH+4Q==",
"engines": {
"node": ">=6"
}
},
"node_modules/clone": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz",
"integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=",
"engines": {
"node": ">=0.8"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/commander": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
"engines": {
"node": ">= 10"
}
},
"node_modules/defaults": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
"integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=",
"dependencies": {
"clone": "^1.0.2"
}
},
"node_modules/has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/is-interactive": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz",
"integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==",
"engines": {
"node": ">=8"
}
},
"node_modules/is-unicode-supported": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz",
"integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==",
"engines": {
"node": ">=10"
}
},
"node_modules/json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"dependencies": {
"minimist": "^1.2.5"
},
"bin": {
"json5": "lib/cli.js"
},
"engines": {
"node": ">=6"
}
},
"node_modules/kleur": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.4.tgz",
"integrity": "sha512-8QADVssbrFjivHWQU7KkMgptGTl6WAcSdlbBPY4uNF+mWr6DGcKrvY2w4FQJoXch7+fKMjj0dRrL75vk3k23OA==",
"engines": {
"node": ">=6"
}
},
"node_modules/log-symbols": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
"integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==",
"dependencies": {
"chalk": "^4.1.0",
"is-unicode-supported": "^0.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
"engines": {
"node": ">=6"
}
},
"node_modules/minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"node_modules/onetime": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",
"integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",
"dependencies": {
"mimic-fn": "^2.1.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/ora": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/ora/-/ora-5.4.0.tgz",
"integrity": "sha512-1StwyXQGoU6gdjYkyVcqOLnVlbKj+6yPNNOxJVgpt9t4eksKjiriiHuxktLYkgllwk+D6MbC4ihH84L1udRXPg==",
"dependencies": {
"bl": "^4.1.0",
"chalk": "^4.1.0",
"cli-cursor": "^3.1.0",
"cli-spinners": "^2.5.0",
"is-interactive": "^1.0.0",
"is-unicode-supported": "^0.1.0",
"log-symbols": "^4.1.0",
"strip-ansi": "^6.0.0",
"wcwidth": "^1.0.1"
},
"engines": {
"node": ">=10"
}
},
"node_modules/readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/restore-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz",
"integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==",
"dependencies": {
"onetime": "^5.1.0",
"signal-exit": "^3.0.2"
},
"engines": {
"node": ">=8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"node_modules/signal-exit": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/strip-ansi": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"dependencies": {
"ansi-regex": "^5.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dependencies": {
"has-flag": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"node_modules/wasm-feature-detect": {
"version": "1.2.11",
"resolved": "https://registry.npmjs.org/wasm-feature-detect/-/wasm-feature-detect-1.2.11.tgz",
"integrity": "sha512-HUqwaodrQGaZgz1lZaNioIkog9tkeEJjrM3eq4aUL04whXOVDRc/o2EGb/8kV0QX411iAYWEqq7fMBmJ6dKS6w=="
},
"node_modules/wcwidth": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",
"integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=",
"dependencies": {
"defaults": "^1.0.3"
}
},
"node_modules/web-streams-polyfill": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.0.3.tgz",
"integrity": "sha512-d2H/t0eqRNM4w2WvmTdoeIvzAUSpK7JmATB8Nr2lb7nQ9BTIJVjbQ/TRFVEh2gUH1HwclPdoPtfMoFfetXaZnA==",
"engines": {
"node": ">= 8"
}
}
},
"dependencies": {
"@squoosh/lib": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@squoosh/lib/-/lib-0.4.0.tgz",
"integrity": "sha512-O1LyugWLZjMI4JZeZMA5vzfhfPjfMZXH5/HmVkRagP8B70wH3uoR7tjxfGNdSavey357MwL8YJDxbGwBBdHp7Q==",
"requires": {
"wasm-feature-detect": "^1.2.11",
"web-streams-polyfill": "^3.0.3"
}
},
"ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
},
"bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
"integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",
"requires": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
"readable-stream": "^3.4.0"
}
},
"buffer": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
"requires": {
"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
}
},
"chalk": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
"integrity": "sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
"integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==",
"requires": {
"restore-cursor": "^3.1.0"
}
},
"cli-spinners": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.6.0.tgz",
"integrity": "sha512-t+4/y50K/+4xcCRosKkA7W4gTr1MySvLV0q+PxmG7FJ5g+66ChKurYjxBCjHggHH3HA5Hh9cy+lcUGWDqVH+4Q=="
},
"clone": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz",
"integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4="
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"commander": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz",
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="
},
"defaults": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
"integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=",
"requires": {
"clone": "^1.0.2"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"is-interactive": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz",
"integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w=="
},
"is-unicode-supported": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz",
"integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw=="
},
"json5": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
"requires": {
"minimist": "^1.2.5"
}
},
"kleur": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.4.tgz",
"integrity": "sha512-8QADVssbrFjivHWQU7KkMgptGTl6WAcSdlbBPY4uNF+mWr6DGcKrvY2w4FQJoXch7+fKMjj0dRrL75vk3k23OA=="
},
"log-symbols": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
"integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==",
"requires": {
"chalk": "^4.1.0",
"is-unicode-supported": "^0.1.0"
}
},
"mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"onetime": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",
"integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==",
"requires": {
"mimic-fn": "^2.1.0"
}
},
"ora": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/ora/-/ora-5.4.0.tgz",
"integrity": "sha512-1StwyXQGoU6gdjYkyVcqOLnVlbKj+6yPNNOxJVgpt9t4eksKjiriiHuxktLYkgllwk+D6MbC4ihH84L1udRXPg==",
"requires": {
"bl": "^4.1.0",
"chalk": "^4.1.0",
"cli-cursor": "^3.1.0",
"cli-spinners": "^2.5.0",
"is-interactive": "^1.0.0",
"is-unicode-supported": "^0.1.0",
"log-symbols": "^4.1.0",
"strip-ansi": "^6.0.0",
"wcwidth": "^1.0.1"
}
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"restore-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz",
"integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==",
"requires": {
"onetime": "^5.1.0",
"signal-exit": "^3.0.2"
}
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"signal-exit": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
},
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"requires": {
"safe-buffer": "~5.2.0"
}
},
"strip-ansi": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"requires": {
"ansi-regex": "^5.0.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"requires": {
"has-flag": "^4.0.0"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"wasm-feature-detect": {
"version": "1.2.11",
"resolved": "https://registry.npmjs.org/wasm-feature-detect/-/wasm-feature-detect-1.2.11.tgz",
"integrity": "sha512-HUqwaodrQGaZgz1lZaNioIkog9tkeEJjrM3eq4aUL04whXOVDRc/o2EGb/8kV0QX411iAYWEqq7fMBmJ6dKS6w=="
},
"wcwidth": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",
"integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=",
"requires": {
"defaults": "^1.0.3"
}
},
"web-streams-polyfill": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.0.3.tgz",
"integrity": "sha512-d2H/t0eqRNM4w2WvmTdoeIvzAUSpK7JmATB8Nr2lb7nQ9BTIJVjbQ/TRFVEh2gUH1HwclPdoPtfMoFfetXaZnA=="
}
}
}

32
cli/package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "@squoosh/cli",
"version": "0.7.2",
"description": "A CLI for Squoosh",
"public": true,
"type": "module",
"homepage": "https://github.com/GoogleChromeLabs/squoosh",
"repository": {
"type": "git",
"url": "https://github.com/GoogleChromeLabs/squoosh.git"
},
"bin": {
"squoosh-cli": "src/index.js",
"@squoosh/cli": "src/index.js"
},
"files": [
"/src/index.js"
],
"keywords": [],
"author": "Google Chrome Developers <chromium-dev@google.com>",
"license": "Apache-2.0",
"engines": {
"node": " ^12.20.2 || ^14.13.1 || ^16.0.0 "
},
"dependencies": {
"@squoosh/lib": "^0.4.0",
"commander": "^7.2.0",
"json5": "^2.2.0",
"kleur": "^4.1.4",
"ora": "^5.4.0"
}
}

236
cli/src/index.js Executable file
View File

@ -0,0 +1,236 @@
#!/usr/bin/env node
import { program } from 'commander/esm.mjs';
import JSON5 from 'json5';
import path from 'path';
import { promises as fsp } from 'fs';
import { cpus } from 'os';
import ora from 'ora';
import kleur from 'kleur';
import { ImagePool, preprocessors, encoders } from '@squoosh/lib';
function clamp(v, min, max) {
if (v < min) return min;
if (v > max) return max;
return v;
}
const suffix = ['B', 'KB', 'MB'];
function prettyPrintSize(size) {
const base = Math.floor(Math.log2(size) / 10);
const index = clamp(base, 0, 2);
return (size / 2 ** (10 * index)).toFixed(2) + suffix[index];
}
function progressTracker(results) {
const spinner = ora();
const tracker = {};
tracker.spinner = spinner;
tracker.progressOffset = 0;
tracker.totalOffset = 0;
let status = '';
tracker.setStatus = (text) => {
status = text || '';
update();
};
let progress = '';
tracker.setProgress = (done, total) => {
spinner.prefixText = kleur.dim(`${done}/${total}`);
const completeness =
(tracker.progressOffset + done) / (tracker.totalOffset + total);
progress = kleur.cyan(
`${'▨'.repeat((completeness * 10) | 0).padEnd(10, '╌')}`,
);
update();
};
function update() {
spinner.text = progress + kleur.bold(status) + getResultsText();
}
tracker.finish = (text) => {
spinner.succeed(kleur.bold(text) + getResultsText());
};
function getResultsText() {
let out = '';
for (const result of results.values()) {
out += `\n ${kleur.cyan(result.file)}: ${prettyPrintSize(result.size)}`;
for (const { outputFile, size: outputSize, infoText } of result.outputs) {
out += `\n ${kleur.dim('└')} ${kleur.cyan(
outputFile.padEnd(5),
)}${prettyPrintSize(outputSize)}`;
const percent = ((outputSize / result.size) * 100).toPrecision(3);
out += ` (${kleur[outputSize > result.size ? 'red' : 'green'](
percent + '%',
)})`;
if (infoText) out += kleur.yellow(infoText);
}
}
return out || '\n';
}
spinner.start();
return tracker;
}
async function getInputFiles(paths) {
const validFiles = [];
for (const inputPath of paths) {
const files = (await fsp.lstat(inputPath)).isDirectory()
? (await fsp.readdir(inputPath, { withFileTypes: true }))
.filter((dirent) => dirent.isFile())
.map((dirent) => path.join(inputPath, dirent.name))
: [inputPath];
for (const file of files) {
try {
await fsp.stat(file);
} catch (err) {
if (err.code === 'ENOENT') {
console.warn(
`Warning: Input file does not exist: ${path.resolve(file)}`,
);
continue;
} else {
throw err;
}
}
validFiles.push(file);
}
}
return validFiles;
}
async function processFiles(files) {
files = await getInputFiles(files);
const imagePool = new ImagePool(cpus().length);
const results = new Map();
const progress = progressTracker(results);
progress.setStatus('Decoding...');
progress.totalOffset = files.length;
progress.setProgress(0, files.length);
// Create output directory
await fsp.mkdir(program.opts().outputDir, { recursive: true });
let decoded = 0;
let decodedFiles = await Promise.all(
files.map(async (file) => {
const buffer = await fsp.readFile(file);
const image = imagePool.ingestImage(buffer);
await image.decoded;
results.set(image, {
file,
size: (await image.decoded).size,
outputs: [],
});
progress.setProgress(++decoded, files.length);
return image;
}),
);
const preprocessOptions = {};
for (const preprocessorName of Object.keys(preprocessors)) {
if (!program.opts()[preprocessorName]) {
continue;
}
preprocessOptions[preprocessorName] = JSON5.parse(
program.opts()[preprocessorName],
);
}
for (const image of decodedFiles) {
image.preprocess(preprocessOptions);
}
await Promise.all(decodedFiles.map((image) => image.decoded));
progress.progressOffset = decoded;
progress.setStatus(
'Encoding ' + kleur.dim(`(${imagePool.workerPool.numWorkers} threads)`),
);
progress.setProgress(0, files.length);
const jobs = [];
let jobsStarted = 0;
let jobsFinished = 0;
for (const image of decodedFiles) {
const originalFile = results.get(image).file;
const encodeOptions = {
optimizerButteraugliTarget: Number(
program.opts().optimizerButteraugliTarget,
),
maxOptimizerRounds: Number(program.opts().maxOptimizerRounds),
};
for (const encName of Object.keys(encoders)) {
if (!program.opts()[encName]) {
continue;
}
const encParam = program.opts()[encName];
const encConfig =
encParam.toLowerCase() === 'auto' ? 'auto' : JSON5.parse(encParam);
encodeOptions[encName] = encConfig;
}
jobsStarted++;
const job = image.encode(encodeOptions).then(async () => {
jobsFinished++;
const outputPath = path.join(
program.opts().outputDir,
path.basename(originalFile, path.extname(originalFile)) +
program.opts().suffix,
);
for (const output of Object.values(image.encodedWith)) {
const outputFile = `${outputPath}.${(await output).extension}`;
await fsp.writeFile(outputFile, (await output).binary);
results
.get(image)
.outputs.push(Object.assign(await output, { outputFile }));
}
progress.setProgress(jobsFinished, jobsStarted);
});
jobs.push(job);
}
// update the progress to account for multi-format
progress.setProgress(jobsFinished, jobsStarted);
// Wait for all jobs to finish
await Promise.all(jobs);
await imagePool.close();
progress.finish('Squoosh results:');
}
program
.name('squoosh-cli')
.arguments('<files...>')
.option('-d, --output-dir <dir>', 'Output directory', '.')
.option('-s, --suffix <suffix>', 'Append suffix to output files', '')
.option(
'--max-optimizer-rounds <rounds>',
'Maximum number of compressions to use for auto optimizations',
'6',
)
.option(
'--optimizer-butteraugli-target <butteraugli distance>',
'Target Butteraugli distance for auto optimizer',
'1.4',
)
.action(processFiles);
// Create a CLI option for each supported preprocessor
for (const [key, value] of Object.entries(preprocessors)) {
program.option(`--${key} [config]`, value.description);
}
// Create a CLI option for each supported encoder
for (const [key, value] of Object.entries(encoders)) {
program.option(
`--${key} [config]`,
`Use ${value.name} to generate a .${value.extension} file with the given configuration`,
);
}
program.parse(process.argv);

19
client-tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"extends": "./generic-tsconfig.json",
"compilerOptions": {
"lib": ["esnext", "dom", "dom.iterable"],
"types": []
},
"include": [
"src/features/**/client/**/*",
"src/features/**/shared/**/*",
"src/features/client-utils/**/*",
"src/shared/**/*",
"src/client/**/*",
// Not really clean, but we need these to access the type of the functions
// for comlink
"src/features/**/worker/**/*",
"src/features-worker/**/*",
"src/features/worker-utils/**/*"
]
}

View File

@ -1,33 +1,39 @@
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/31d7c6d1e32cf467ac24fb8c7a76c4902a4c00db.tar.gz
# libavif and libaom versions are from
# https://docs.google.com/document/d/1wEEA5rRU7wT54k41u3qyZIZHDCJArIMzLuzsrLAwaK8/edit
CODEC_URL = https://github.com/AOMediaCodec/libavif/archive/1c39e772c2c0d687691dd4b589a12c323f5f767d.tar.gz
CODEC_PACKAGE = node_modules/libavif.tar.gz
LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v2.0.0.tar.gz
LIBAOM_URL = https://aomedia.googlesource.com/aom/+archive/v3.1.0.tar.gz
LIBAOM_PACKAGE = node_modules/libaom.tar.gz
export CODEC_DIR = node_modules/libavif
BUILD_DIR := node_modules/build
ENC_BUILD_DIR := $(BUILD_DIR)/enc
ENC_MT_BUILD_DIR := $(BUILD_DIR)/enc-mt
DEC_BUILD_DIR := $(BUILD_DIR)/dec
export BUILD_DIR = node_modules/build
export LIBAOM_DIR = node_modules/libaom
override CFLAGS += "-Wno-unused-macros"
export
OUT_ENC_JS = enc/avif_enc.js
OUT_NODE_ENC_JS = enc/avif_node_enc.js
OUT_ENC_MT_JS = enc/avif_enc_mt.js
OUT_NODE_ENC_MT_JS = enc/avif_node_enc_mt.js
OUT_DEC_JS = dec/avif_dec.js
OUT_NODE_DEC_JS = dec/avif_node_dec.js
OUT_ENC_CPP = enc/avif_enc.cpp
OUT_DEC_CPP = dec/avif_dec.cpp
ENVIRONMENT = worker
HELPER_MAKEFLAGS := -f helper.Makefile
.PHONY: all clean
all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS)
all: $(OUT_ENC_JS) $(OUT_DEC_JS) $(OUT_ENC_MT_JS) $(OUT_NODE_ENC_JS) $(OUT_NODE_ENC_MT_JS) $(OUT_NODE_DEC_JS)
$(OUT_ENC_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(OUT_NODE_ENC_JS) $(OUT_NODE_ENC_MT_JS): ENVIRONMENT=node
$(OUT_NODE_ENC_JS) $(OUT_ENC_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
BUILD_DIR=$(ENC_BUILD_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
@ -35,31 +41,33 @@ $(OUT_ENC_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLis
-DCONFIG_MULTITHREAD=0 \
-DCONFIG_AV1_HIGHBITDEPTH=0 \
" \
ENVIRONMENT=$(ENVIRONMENT) \
LIBAVIF_FLAGS="-DAVIF_CODEC_AOM_DECODE=0"
$(OUT_ENC_MT_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(OUT_ENC_MT_JS) $(OUT_NODE_ENC_MT_JS): $(OUT_ENC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
BUILD_DIR=$(ENC_MT_BUILD_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
-DCONFIG_AV1_DECODER=0 \
-DCONFIG_AV1_HIGHBITDEPTH=0 \
" \
ENVIRONMENT=$(ENVIRONMENT) \
LIBAVIF_FLAGS="-DAVIF_CODEC_AOM_DECODE=0" \
OUT_FLAGS="-pthread"
$(OUT_DEC_JS): $(OUT_DEC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(OUT_NODE_DEC_JS): ENVIRONMENT=node
$(OUT_NODE_DEC_JS) $(OUT_DEC_JS): $(OUT_DEC_CPP) $(CODEC_DIR)/CMakeLists.txt $(LIBAOM_DIR)/CMakeLists.txt
$(MAKE) \
$(HELPER_MAKEFLAGS) \
BUILD_DIR=$(DEC_BUILD_DIR) \
OUT_JS=$@ \
OUT_CPP=$< \
LIBAOM_FLAGS="\
-DCONFIG_AV1_ENCODER=0 \
-DCONFIG_MULTITHREAD=0 \
" \
ENVIRONMENT=$(ENVIRONMENT) \
LIBAVIF_FLAGS="-DAVIF_CODEC_AOM_ENCODE=0"
$(CODEC_PACKAGE):
@ -79,6 +87,9 @@ $(LIBAOM_DIR)/CMakeLists.txt: $(LIBAOM_PACKAGE)
tar xzm -C $(@D) -f $(LIBAOM_PACKAGE)
clean:
$(MAKE) $(HELPER_MAKEFLAGS) BUILD_DIR=$(ENC_BUILD_DIR) OUT_JS=$(OUT_ENC_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) BUILD_DIR=$(ENC_MT_BUILD_DIR) OUT_JS=$(OUT_ENC_MT_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) BUILD_DIR=$(DEC_BUILD_DIR) OUT_JS=$(OUT_DEC_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_ENC_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_ENC_MT_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_ENC_NODE_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_ENC_NODE_MT_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_DEC_JS) clean
$(MAKE) $(HELPER_MAKEFLAGS) OUT_JS=$(OUT_DEV_NODE_JS) clean

View File

@ -1,6 +1,7 @@
interface AVIFModule extends EmscriptenWasm.Module {
export interface AVIFModule extends EmscriptenWasm.Module {
decode(data: BufferSource): ImageData | null;
}
export default function(opts: EmscriptenWasm.ModuleOpts): Promise<AVIFModule>;
declare var moduleFactory: EmscriptenWasm.ModuleFactory<AVIFModule>;
export default moduleFactory;

File diff suppressed because one or more lines are too long

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

Binary file not shown.

16
codecs/avif/dec/avif_node_dec.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,6 +1,6 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <emscripten/threading.h>
#include <emscripten/val.h>
#include "avif/avif.h"
using namespace emscripten;
@ -9,10 +9,9 @@ struct AvifOptions {
// [0 - 63]
// 0 = lossless
// 63 = worst quality
int minQuantizer;
int maxQuantizer;
int minQuantizerAlpha;
int maxQuantizerAlpha;
int cqLevel;
// As above, but -1 means 'use cqLevel'
int cqAlphaLevel;
// [0 - 6]
// Creates 2^n tiles in that dimension
int tileRowsLog2;
@ -26,6 +25,16 @@ struct AvifOptions {
// 2 = 4:2:2
// 3 = 4:4:4
int subsample;
// Extra chroma compression
bool chromaDeltaQ;
// 0-7
int sharpness;
// 0 = auto
// 1 = PSNR
// 2 = SSIM
int tune;
// 0-50
int denoiseLevel;
};
thread_local const val Uint8Array = val::global("Uint8Array");
@ -49,21 +58,19 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
break;
}
bool lossless = options.cqLevel == AVIF_QUANTIZER_LOSSLESS &&
options.cqAlphaLevel <= AVIF_QUANTIZER_LOSSLESS &&
format == AVIF_PIXEL_FORMAT_YUV444;
avifImage* image = avifImageCreate(width, height, depth, format);
if (
options.maxQuantizer == AVIF_QUANTIZER_LOSSLESS &&
options.minQuantizer == AVIF_QUANTIZER_LOSSLESS &&
options.minQuantizerAlpha == AVIF_QUANTIZER_LOSSLESS &&
options.maxQuantizerAlpha == AVIF_QUANTIZER_LOSSLESS &&
format == AVIF_PIXEL_FORMAT_YUV444
) {
if (lossless) {
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_IDENTITY;
} else {
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT709;
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;
}
uint8_t* rgba = (uint8_t*)buffer.c_str();
uint8_t* rgba = reinterpret_cast<uint8_t*>(const_cast<char*>(buffer.data()));
avifRGBImage srcRGB;
avifRGBImageSetDefaults(&srcRGB, image);
@ -72,14 +79,44 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
avifImageRGBToYUV(image, &srcRGB);
avifEncoder* encoder = avifEncoderCreate();
if (lossless) {
encoder->minQuantizer = AVIF_QUANTIZER_LOSSLESS;
encoder->maxQuantizer = AVIF_QUANTIZER_LOSSLESS;
encoder->minQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
encoder->maxQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
} else {
encoder->minQuantizer = AVIF_QUANTIZER_BEST_QUALITY;
encoder->maxQuantizer = AVIF_QUANTIZER_WORST_QUALITY;
encoder->minQuantizerAlpha = AVIF_QUANTIZER_BEST_QUALITY;
encoder->maxQuantizerAlpha = AVIF_QUANTIZER_WORST_QUALITY;
avifEncoderSetCodecSpecificOption(encoder, "end-usage", "q");
avifEncoderSetCodecSpecificOption(encoder, "cq-level", std::to_string(options.cqLevel).c_str());
avifEncoderSetCodecSpecificOption(encoder, "sharpness",
std::to_string(options.sharpness).c_str());
if (options.cqAlphaLevel != -1) {
avifEncoderSetCodecSpecificOption(encoder, "alpha:cq-level",
std::to_string(options.cqAlphaLevel).c_str());
}
if (options.tune == 2 || (options.tune == 0 && options.cqLevel <= 32)) {
avifEncoderSetCodecSpecificOption(encoder, "tune", "ssim");
}
if (options.chromaDeltaQ) {
avifEncoderSetCodecSpecificOption(encoder, "enable-chroma-deltaq", "1");
}
avifEncoderSetCodecSpecificOption(encoder, "color:denoise-noise-level",
std::to_string(options.denoiseLevel).c_str());
}
encoder->maxThreads = emscripten_num_logical_cores();
encoder->minQuantizer = options.minQuantizer;
encoder->maxQuantizer = options.maxQuantizer;
encoder->minQuantizerAlpha = options.minQuantizerAlpha;
encoder->maxQuantizerAlpha = options.maxQuantizerAlpha;
encoder->tileRowsLog2 = options.tileRowsLog2;
encoder->tileColsLog2 = options.tileColsLog2;
encoder->speed = options.speed;
avifResult encodeResult = avifEncoderWrite(encoder, image, &output);
auto js_result = val::null();
if (encodeResult == AVIF_RESULT_OK) {
@ -94,13 +131,15 @@ val encode(std::string buffer, int width, int height, AvifOptions options) {
EMSCRIPTEN_BINDINGS(my_module) {
value_object<AvifOptions>("AvifOptions")
.field("minQuantizer", &AvifOptions::minQuantizer)
.field("maxQuantizer", &AvifOptions::maxQuantizer)
.field("minQuantizerAlpha", &AvifOptions::minQuantizerAlpha)
.field("maxQuantizerAlpha", &AvifOptions::maxQuantizerAlpha)
.field("cqLevel", &AvifOptions::cqLevel)
.field("cqAlphaLevel", &AvifOptions::cqAlphaLevel)
.field("tileRowsLog2", &AvifOptions::tileRowsLog2)
.field("tileColsLog2", &AvifOptions::tileColsLog2)
.field("speed", &AvifOptions::speed)
.field("chromaDeltaQ", &AvifOptions::chromaDeltaQ)
.field("sharpness", &AvifOptions::sharpness)
.field("tune", &AvifOptions::tune)
.field("denoiseLevel", &AvifOptions::denoiseLevel)
.field("subsample", &AvifOptions::subsample);
function("encode", &encode);

View File

@ -1,7 +1,31 @@
import { EncodeOptions } from '../../../src/codecs/avif/encoder-meta';
interface AVIFModule extends EmscriptenWasm.Module {
encode(data: BufferSource, width: number, height: number, options: EncodeOptions): Uint8Array | null;
export const enum AVIFTune {
auto,
psnr,
ssim,
}
export default function(opts: EmscriptenWasm.ModuleOpts): Promise<AVIFModule>;
export interface EncodeOptions {
cqLevel: number;
denoiseLevel: number;
cqAlphaLevel: number;
tileRowsLog2: number;
tileColsLog2: number;
speed: number;
subsample: number;
chromaDeltaQ: boolean;
sharpness: number;
tune: AVIFTune;
}
export interface AVIFModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions,
): Uint8Array | null;
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<AVIFModule>;
export default moduleFactory;

File diff suppressed because one or more lines are too long

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

Binary file not shown.

1
codecs/avif/enc/avif_enc_mt.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export { default } from './avif_enc';

File diff suppressed because one or more lines are too long

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

Binary file not shown.

View File

@ -1 +1 @@
var threadInfoStruct=0;var selfThreadId=0;var parentThreadId=0;var Module={};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})}var err=threadPrintErr;this.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);Module["wasmModule"]=null;receiveInstance(instance);return instance.exports};this.onmessage=function(e){try{if(e.data.cmd==="load"){Module["DYNAMIC_BASE"]=e.data.DYNAMIC_BASE;Module["DYNAMICTOP_PTR"]=e.data.DYNAMICTOP_PTR;Module["wasmModule"]=e.data.wasmModule;Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["ENVIRONMENT_IS_PTHREAD"]=true;if(typeof e.data.urlOrBlob==="string"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}avif_enc_mt(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"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;threadInfoStruct=e.data.threadInfoStruct;Module["registerPthreadPtr"](threadInfoStruct,/*isMainBrowserThread=*/0,/*isMainRuntimeThread=*/0);selfThreadId=e.data.selfThreadId;parentThreadId=e.data.parentThreadId;var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["_emscripten_tls_init"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].setThreadStatus(Module["_pthread_self"](),1);/*EM_THREAD_STATUS_RUNNING*/try{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);Module["_emscripten_futex_wake"](threadInfoStruct+0,/*C_STRUCTS.pthread.threadStatus*/2147483647);if(!(ex instanceof Module["ExitStatus"]))throw ex}}}else if(e.data.cmd==="cancel"){if(threadInfoStruct){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(threadInfoStruct){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex.stack)err(ex.stack);throw ex}};if(typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string"){self={location:{href:__filename}};var onmessage=this.onmessage;var nodeWorkerThreads=require("worker_threads");global.Worker=nodeWorkerThreads.Worker;var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",function(data){onmessage({data:data})});var nodeFS=require("fs");var nodeRead=function(filename){return nodeFS.readFileSync(filename,"utf8")};function globalEval(x){global.require=require;global.Module=Module;eval.call(null,x)}importScripts=function(f){globalEval(nodeRead(f))};postMessage=function(msg){parentPort.postMessage(msg)};if(typeof performance==="undefined"){performance={now:function(){return Date.now()}}}}
"use strict";var Module={};var initializedJS=false;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:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};function moduleLoaded(){}self.onmessage=function(e){try{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;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./avif_enc_mt.js")).then(function(exports){return exports.default(Module)}).then(function(instance){Module=instance;moduleLoaded()})}else if(e.data.cmd==="objectTransfer"){Module["PThread"].receiveObjectTransfer(e.data)}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.threadInfoStruct,0,0);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();if(!initializedJS){Module["___embind_register_native_and_builtin_types"]();initializedJS=true}try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["PThread"].threadExit(result)}}catch(ex){if(ex==="Canceled!"){Module["PThread"].threadCancel()}else if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){}else{Module["PThread"].threadExit(ex.status)}}else{Module["PThread"].threadExit(-2);throw ex}}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);throw ex}};

16
codecs/avif/enc/avif_node_enc.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

16
codecs/avif/enc/avif_node_enc_mt.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1 @@
"use strict";var Module={};if(typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string"){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",function(data){onmessage({data:data})});var nodeFS=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(nodeFS.readFileSync(f,"utf8"))},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;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:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};function moduleLoaded(){}self.onmessage=function(e){try{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;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./avif_node_enc_mt.js")).then(function(exports){return exports.default(Module)}).then(function(instance){Module=instance;moduleLoaded()})}else if(e.data.cmd==="objectTransfer"){Module["PThread"].receiveObjectTransfer(e.data)}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.threadInfoStruct,0,0);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();if(!initializedJS){Module["___embind_register_native_and_builtin_types"]();initializedJS=true}try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["PThread"].threadExit(result)}}catch(ex){if(ex==="Canceled!"){Module["PThread"].threadCancel()}else if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){}else{Module["PThread"].threadExit(ex.status)}}else{Module["PThread"].threadExit(-2);throw ex}}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);throw ex}};

View File

@ -8,11 +8,14 @@
# $(OUT_CPP)
# $(LIBAOM_FLAGS)
# $(LIBAVIF_FLAGS)
# $(ENVIRONMENT)
CODEC_BUILD_DIR := $(BUILD_DIR)/libavif
OUT_BUILD_DIR := $(BUILD_DIR)/$(basename $(OUT_JS))
CODEC_BUILD_DIR := $(OUT_BUILD_DIR)/libavif
CODEC_OUT := $(CODEC_BUILD_DIR)/libavif.a
LIBAOM_BUILD_DIR := $(BUILD_DIR)/libaom
LIBAOM_BUILD_DIR := $(OUT_BUILD_DIR)/libaom
LIBAOM_OUT := $(LIBAOM_BUILD_DIR)/libaom.a
OUT_WASM = $(OUT_JS:.js=.wasm)
@ -29,10 +32,8 @@ $(OUT_JS): $(OUT_CPP) $(LIBAOM_OUT) $(CODEC_OUT)
$(LDFLAGS) \
$(OUT_FLAGS) \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s 'EXPORT_NAME="$(basename $(@F))"' \
-s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \
-o $@ \
$+

View File

@ -1,3 +1,3 @@
#!/bin/sh -e
docker build -t squoosh-cpp - < ../cpp.Dockerfile
docker run --rm -v $PWD:/src squoosh-cpp
docker run -it --rm -v $PWD:/src squoosh-cpp "$@"

View File

@ -1,4 +0,0 @@
set -e
docker build -t squoosh-rust-nightly --build-arg RUST_IMG=rustlang/rust:nightly - < ../rust.Dockerfile
docker run --rm -v $PWD:/src squoosh-rust-nightly "$@"

View File

@ -1,4 +1,10 @@
set -e
docker build -t squoosh-rust - < ../rust.Dockerfile
docker run --rm -v $PWD:/src squoosh-rust "$@"
if [ ! -z "$RUST_IMG" ]
then
# Get part after ":" (https://stackoverflow.com/a/15149278/439965).
IMG_SUFFIX=-${RUST_IMG#*:}
fi
IMG_NAME=squoosh-rust$IMG_SUFFIX
docker build -t $IMG_NAME --build-arg RUST_IMG - < ../rust.Dockerfile
docker run -it --rm -v $PWD:/src $IMG_NAME "$@"

View File

@ -1,9 +1,17 @@
FROM emscripten/emsdk:1.40.0
FROM emscripten/emsdk:2.0.23
RUN apt-get update && apt-get install -qqy autoconf libtool pkg-config
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
RUN emcc ${CXXFLAGS} --bind -xc++ /dev/null -o /dev/null
ENV LDFLAGS "${CFLAGS} \
-s FILESYSTEM=0 \
-s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency \
-s ALLOW_MEMORY_GROWTH=1 \
-s TEXTDECODER=2 \
-s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 \
"
# Build and cache standard libraries with these flags + Embind.
RUN emcc ${CXXFLAGS} ${LDFLAGS} --bind -xc++ /dev/null -o /dev/null
# And another set for the pthread variant.
RUN emcc ${CXXFLAGS} ${LDFLAGS} --bind -pthread -xc++ /dev/null -o /dev/null
WORKDIR /src
CMD ["sh", "-c", "emmake make -j`nproc`"]

197
codecs/hqx/Cargo.lock generated
View File

@ -4,286 +4,289 @@
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 = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[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 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)",
"cfg-if 0.1.10",
"wasm-bindgen",
]
[[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.2#5f19cda24191ccc7c0c4920b6b246b4e242f377c"
source = "git+https://github.com/CryZe/wasmboy-rs?tag=v0.1.3#d7cbae67906796928c8e451b186f3c653924beb8"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static",
]
[[package]]
name = "js-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2"
dependencies = [
"wasm-bindgen 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen",
]
[[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 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10",
]
[[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 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.19"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
"unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.1",
]
[[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 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30",
]
[[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 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.27",
]
[[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 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)",
"cfg-if 0.1.10",
"console_error_panic_hook",
"hqx",
"wasm-bindgen",
"wasm-bindgen-test",
"wee_alloc",
]
[[package]]
name = "syn"
version = "1.0.35"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
"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)",
"proc-macro2 1.0.27",
"quote 1.0.7",
"unicode-xid 0.2.1",
]
[[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"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd"
dependencies = [
"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)",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.65"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900"
dependencies = [
"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)",
"bumpalo",
"lazy_static",
"log",
"proc-macro2 1.0.27",
"quote 1.0.7",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
dependencies = [
"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)",
"cfg-if 0.1.10",
"futures",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.65"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4"
dependencies = [
"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)",
"quote 1.0.7",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.65"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97"
dependencies = [
"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)",
"proc-macro2 1.0.27",
"quote 1.0.7",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.65"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f"
[[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 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)",
"console_error_panic_hook",
"futures",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
]
[[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 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.30",
"quote 0.6.13",
]
[[package]]
name = "web-sys"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2"
dependencies = [
"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)",
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "wee_alloc"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
dependencies = [
"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)",
"cfg-if 0.1.10",
"libc",
"memory_units",
"winapi",
]
[[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 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)",
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[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"
[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"
checksum = "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.2"}
hqx = {git = "https://github.com/CryZe/wasmboy-rs", tag="v0.1.3"}
# 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,11 +0,0 @@
# This is intentionally an old version of Rust. Newer versions
# generate _significantly_ bigger Wasm binaries.
FROM rust:1.37
RUN rustup target add wasm32-unknown-unknown
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
RUN mkdir /opt/binaryen && \
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.38.32/binaryen-1.38.32-x86-linux.tar.gz | tar -xzf - -C /opt/binaryen --strip 1
ENV PATH="/opt/binaryen:${PATH}"
WORKDIR /src

View File

@ -1,21 +0,0 @@
#!/bin/bash
set -e
echo "============================================="
echo "Compiling wasm"
echo "============================================="
(
wasm-pack build -- --verbose --locked
rm pkg/.gitignore
)
echo "============================================="
echo "Compiling wasm done"
echo "============================================="
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Did you update your docker image?"
echo "Run \`docker pull ubuntu\`"
echo "Run \`docker pull rust\`"
echo "Run \`docker build -t squoosh-hqx .\`"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"

View File

@ -1,7 +1,6 @@
{
"name": "hqx",
"scripts": {
"build:image": "docker build -t squoosh-hqx - < Dockerfile",
"build": "docker run --rm -v $(pwd):/src squoosh-hqx ./build.sh"
"build": "../build-rust.sh"
}
}

5
codecs/hqx/pkg/README.md Normal file
View File

@ -0,0 +1,5 @@
# HQX
- Source: <https://github.com/CryZe/wasmboy-rs>
- Version: v0.1.2
- License: Apache 2.0

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

@ -8,3 +8,23 @@
* @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 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 __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>;

View File

@ -1,2 +1,108 @@
import * as wasm from "./squooshhqx_bg.wasm";
export * from "./squooshhqx_bg.js";
let wasm;
let cachegetUint32Memory0 = null;
function getUint32Memory0() {
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;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
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);
}
/**
* @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);
}
}
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 };
} 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 === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
}
export default init;

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

@ -1,6 +0,0 @@
/* 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;

View File

@ -1,48 +0,0 @@
import * as wasm from './squooshhqx_bg.wasm';
let cachegetUint32Memory0 = null;
function getUint32Memory0() {
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;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
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);
}
/**
* @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) {
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;
}

Binary file not shown.

View File

@ -2,25 +2,26 @@ CODEC_URL := https://github.com/ImageOptim/libimagequant/archive/2.12.1.tar.gz
CODEC_DIR := node_modules/libimagequant
CODEC_OUT_RELATIVE := libimagequant.a
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
OUT_JS := imagequant.js
OUT_JS := imagequant.js imagequant_node.js
OUT_WASM := $(OUT_JS:.js=.wasm)
ENVIRONMENT = worker
.PHONY: all clean
all: $(OUT_JS)
%.js: %.cpp $(CODEC_OUT)
imagequant_node.js: ENVIRONMENT=node
$(OUT_JS): $(CODEC_OUT)
$(CXX) \
-I $(CODEC_DIR) \
${CXXFLAGS} \
${LDFLAGS} \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s 'EXPORT_NAME="$(basename $(@F))"' \
-s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \
-o $@ \
$+
$+ \
imagequant.cpp
$(CODEC_OUT): $(CODEC_DIR)/config.mk
$(MAKE) -C $(CODEC_DIR) $(CODEC_OUT_RELATIVE)

View File

@ -1,18 +1,17 @@
<!doctype html>
<!DOCTYPE html>
<style>
canvas {
image-rendering: pixelated;
}
</style>
<script src='imagequant.js'></script>
<script>
const Module = imagequant();
<script type="module">
import imagequant from './imagequant.js';
async function loadImage(src) {
// Load image
const img = document.createElement('img');
img.src = src;
await new Promise(resolve => img.onload = resolve);
await new Promise((resolve) => (img.onload = resolve));
// Make canvas same size as image
const canvas = document.createElement('canvas');
[canvas.width, canvas.height] = [img.width, img.height];
@ -22,19 +21,32 @@
return ctx.getImageData(0, 0, img.width, img.height);
}
Module.onRuntimeInitialized = async _ => {
console.log('Version:', Module.version().toString(16));
async function main() {
const module = await imagequant();
console.log('Version:', module.version().toString(16));
const image = await loadImage('../example.png');
// const rawImage = Module.quantize(image.data, image.width, image.height, 256, 1.0);
const rawImage = Module.zx_quantize(image.data, image.width, image.height, 1.0);
const rawImage = module.quantize(
image.data,
image.width,
image.height,
256,
1.0,
);
console.log('done');
const imageData = new ImageData(new Uint8ClampedArray(rawImage.buffer), image.width, image.height);
const imageData = new ImageData(
new Uint8ClampedArray(rawImage.buffer),
image.width,
image.height,
);
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
const ctx = canvas.getContext('2d');
ctx.putImageData(imageData, 0, 0);
document.body.appendChild(canvas);
};
}
main();
</script>

View File

@ -1,6 +1,19 @@
interface QuantizerModule extends EmscriptenWasm.Module {
quantize(data: BufferSource, width: number, height: number, numColors: number, dither: number): Uint8ClampedArray;
zx_quantize(data: BufferSource, width: number, height: number, dither: number): Uint8ClampedArray;
export interface QuantizerModule extends EmscriptenWasm.Module {
quantize(
data: BufferSource,
width: number,
height: number,
numColors: number,
dither: number,
): Uint8ClampedArray;
zx_quantize(
data: BufferSource,
width: number,
height: number,
dither: number,
): Uint8ClampedArray;
}
export default function(opts: EmscriptenWasm.ModuleOpts): Promise<QuantizerModule>;
declare var moduleFactory: EmscriptenWasm.ModuleFactory<QuantizerModule>;
export default moduleFactory;

File diff suppressed because one or more lines are too long

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

Binary file not shown.

16
codecs/imagequant/imagequant_node.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

90
codecs/jxl/Makefile Normal file
View File

@ -0,0 +1,90 @@
CODEC_URL = https://github.com/libjxl/libjxl.git
CODEC_VERSION = v0.5
CODEC_DIR = node_modules/jxl
CODEC_BUILD_ROOT := $(CODEC_DIR)/build
CODEC_MT_BUILD_DIR := $(CODEC_BUILD_ROOT)/mt
CODEC_MT_SIMD_BUILD_DIR := $(CODEC_BUILD_ROOT)/mt-simd
ENVIRONMENT = worker
OUT_JS = enc/jxl_enc.js enc/jxl_enc_mt.js enc/jxl_enc_mt_simd.js dec/jxl_dec.js enc/jxl_node_enc.js dec/jxl_node_dec.js
OUT_WASM = $(OUT_JS:.js=.wasm)
OUT_WORKER = $(OUT_JS:.js=.worker.js)
.PHONY: all clean
all: $(OUT_JS)
# Define dependencies for all variations of build artifacts.
$(filter enc/%,$(OUT_JS)): enc/jxl_enc.cpp
$(filter dec/%,$(OUT_JS)): dec/jxl_dec.cpp
enc/jxl_node_enc.js dec/jxl_node_dec.js: ENVIRONMENT = node
# For single-threaded build, we compile with threads enabled, but then just don't use them nor link them in.
enc/jxl_enc.js enc/jxl_node_enc.js enc/jxl_enc_mt.js dec/jxl_dec.js dec/jxl_node_dec.js: CODEC_BUILD_DIR:=$(CODEC_MT_BUILD_DIR)
enc/jxl_enc_mt_simd.js: CODEC_BUILD_DIR:=$(CODEC_MT_SIMD_BUILD_DIR)
enc/jxl_node_enc.js dec/jxl_node_dec.js enc/jxl_enc.js dec/jxl_dec.js: $(CODEC_MT_BUILD_DIR)/lib/libjxl.a
enc/jxl_enc_mt.js: $(CODEC_MT_BUILD_DIR)/lib/libjxl.a $(CODEC_MT_BUILD_DIR)/lib/libjxl_threads.a
enc/jxl_enc_mt_simd.js: $(CODEC_MT_SIMD_BUILD_DIR)/lib/libjxl.a $(CODEC_MT_SIMD_BUILD_DIR)/lib/libjxl_threads.a
# Disable errors on deprecated SIMD intrinsics.
# JPEG-XL & Highway need to catch up, once they do, we can remove this suppression.
export CXXFLAGS += -Wno-deprecated-declarations
# Compile multithreaded wrappers with -pthread.
enc/jxl_enc_mt.js enc/jxl_enc_mt_simd.js: CXXFLAGS+=-pthread
$(OUT_JS):
$(CXX) \
$(CXXFLAGS) \
$(LDFLAGS) \
-I $(CODEC_DIR) \
-I $(CODEC_DIR)/lib \
-I $(CODEC_DIR)/lib/include \
-I $(CODEC_BUILD_DIR)/lib/include \
-I $(CODEC_DIR)/third_party/highway \
-I $(CODEC_DIR)/third_party/skcms \
--bind \
-s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \
-o $@ \
$+ \
$(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 \
$(CODEC_BUILD_DIR)/third_party/libskcms.a \
$(CODEC_BUILD_DIR)/third_party/highway/libhwy.a
%/lib/libjxl.a: %/Makefile
$(MAKE) -C $(<D) jxl-static
%/lib/libjxl_threads.a: %/Makefile
$(MAKE) -C $(<D) jxl_threads-static
# Enable SIMD on a SIMD build.
$(CODEC_MT_SIMD_BUILD_DIR)/Makefile: CXXFLAGS+=-msimd128
%/Makefile: $(CODEC_DIR)/CMakeLists.txt
emcmake cmake \
$(CMAKE_FLAGS) \
-DBUILD_SHARED_LIBS=0 \
-DJPEGXL_ENABLE_BENCHMARK=0 \
-DJPEGXL_ENABLE_EXAMPLES=0 \
-DBUILD_TESTING=0 \
-DCMAKE_CROSSCOMPILING_EMULATOR=node \
-B $(@D) \
$(<D)
$(CODEC_DIR)/CMakeLists.txt:
$(RM) -r $(@D)
git init $(@D)
git -C $(@D) fetch $(CODEC_URL) $(CODEC_VERSION) --depth 1
git -C $(@D) checkout FETCH_HEAD
git -C $(@D) submodule update --init --depth 1 --recursive --jobs `nproc`
clean:
$(RM) $(OUT_JS) $(OUT_WASM) $(OUT_WORKER)
$(MAKE) -C $(CODEC_BUILD_DIR) clean
$(MAKE) -C $(CODEC_MT_BUILD_DIR) clean
$(MAKE) -C $(CODEC_MT_SIMD_BUILD_DIR) clean

View File

@ -0,0 +1,99 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <jxl/decode.h>
#include "lib/jxl/color_encoding_internal.h"
#include "skcms.h"
using namespace emscripten;
thread_local const val Uint8ClampedArray = val::global("Uint8ClampedArray");
thread_local const val ImageData = val::global("ImageData");
// R, G, B, A
#define COMPONENTS_PER_PIXEL 4
#ifndef JXL_DEBUG_ON_ALL_ERROR
#define JXL_DEBUG_ON_ALL_ERROR 0
#endif
#if JXL_DEBUG_ON_ALL_ERROR
#define EXPECT_TRUE(a) \
if (!(a)) { \
fprintf(stderr, "Assertion failure (%d): %s\n", __LINE__, #a); \
return val::null(); \
}
#define EXPECT_EQ(a, b) \
{ \
int a_ = a; \
int b_ = b; \
if (a_ != b_) { \
fprintf(stderr, "Assertion failure (%d): %s (%d) != %s (%d)\n", __LINE__, #a, a_, #b, b_); \
return val::null(); \
} \
}
#else
#define EXPECT_TRUE(a) \
if (!(a)) { \
return val::null(); \
}
#define EXPECT_EQ(a, b) EXPECT_TRUE((a) == (b));
#endif
val decode(std::string data) {
std::unique_ptr<JxlDecoder,
std::integral_constant<decltype(&JxlDecoderDestroy), JxlDecoderDestroy>>
dec(JxlDecoderCreate(nullptr));
EXPECT_EQ(JXL_DEC_SUCCESS,
JxlDecoderSubscribeEvents(
dec.get(), JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING | JXL_DEC_FULL_IMAGE));
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()));
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()));
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,
JXL_COLOR_PROFILE_TARGET_DATA, &icc_size));
std::vector<uint8_t> icc_profile(icc_size);
EXPECT_EQ(JXL_DEC_SUCCESS,
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()));
auto byte_pixels = std::make_unique<uint8_t[]>(component_count);
// Convert to sRGB.
skcms_ICCProfile jxl_profile;
EXPECT_TRUE(skcms_Parse(icc_profile.data(), icc_profile.size(), &jxl_profile));
EXPECT_TRUE(skcms_Transform(
float_pixels.get(), skcms_PixelFormat_RGBA_ffff,
info.alpha_premultiplied ? skcms_AlphaFormat_PremulAsEncoded : skcms_AlphaFormat_Unpremul,
&jxl_profile, byte_pixels.get(), skcms_PixelFormat_RGBA_8888, skcms_AlphaFormat_Unpremul,
skcms_sRGB_profile(), pixel_count));
return ImageData.new_(
Uint8ClampedArray.new_(typed_memory_view(component_count, byte_pixels.get())), info.xsize,
info.ysize);
}
EMSCRIPTEN_BINDINGS(my_module) {
function("decode", &decode);
}

7
codecs/jxl/dec/jxl_dec.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
export interface JXLModule extends EmscriptenWasm.Module {
decode(data: BufferSource): ImageData | null;
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<JXLModule>;
export default moduleFactory;

16
codecs/jxl/dec/jxl_dec.js generated Normal file

File diff suppressed because one or more lines are too long

BIN
codecs/jxl/dec/jxl_dec.wasm Executable file

Binary file not shown.

16
codecs/jxl/dec/jxl_node_dec.js generated Normal file

File diff suppressed because one or more lines are too long

BIN
codecs/jxl/dec/jxl_node_dec.wasm Executable file

Binary file not shown.

119
codecs/jxl/enc/jxl_enc.cpp Normal file
View File

@ -0,0 +1,119 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "lib/jxl/base/thread_pool_internal.h"
#include "lib/jxl/enc_external_image.h"
#include "lib/jxl/enc_file.h"
using namespace emscripten;
thread_local const val Uint8Array = val::global("Uint8Array");
struct JXLOptions {
int effort;
float quality;
bool progressive;
int epf;
bool lossyPalette;
size_t decodingSpeedTier;
float photonNoiseIso;
};
val encode(std::string image, int width, int height, JXLOptions options) {
jxl::CompressParams cparams;
jxl::PassesEncoderState passes_enc_state;
jxl::CodecInOut io;
jxl::PaddedBytes bytes;
jxl::ImageBundle* main = &io.Main();
jxl::ThreadPoolInternal* pool_ptr = nullptr;
#ifdef __EMSCRIPTEN_PTHREADS__
jxl::ThreadPoolInternal pool;
pool_ptr = &pool;
#endif
size_t st = 10 - options.effort;
cparams.speed_tier = jxl::SpeedTier(st);
cparams.epf = options.epf;
cparams.decoding_speed_tier = options.decodingSpeedTier;
cparams.photon_noise_iso = options.photonNoiseIso;
if (options.lossyPalette) {
cparams.lossy_palette = true;
cparams.palette_colors = 0;
cparams.options.predictor = jxl::Predictor::Zero;
// Near-lossless assumes -R 0
cparams.responsive = 0;
cparams.modular_mode = true;
}
float quality = options.quality;
// Quality settings roughly match libjpeg qualities.
if (quality < 7 || quality == 100) {
cparams.modular_mode = true;
// Internal modular quality to roughly match VarDCT size.
cparams.quality_pair.first = cparams.quality_pair.second =
std::min(35 + (quality - 7) * 3.0f, 100.0f);
} else {
cparams.modular_mode = false;
if (quality >= 30) {
cparams.butteraugli_distance = 0.1 + (100 - quality) * 0.09;
} else {
cparams.butteraugli_distance = 6.4 + pow(2.5, (30 - quality) / 5.0f) / 6.25f;
}
}
if (options.progressive) {
cparams.qprogressive_mode = true;
cparams.responsive = 1;
if (!cparams.modular_mode) {
cparams.progressive_dc = 1;
}
}
if (cparams.modular_mode) {
if (cparams.quality_pair.first != 100 || cparams.quality_pair.second != 100) {
cparams.color_transform = jxl::ColorTransform::kXYB;
} else {
cparams.color_transform = jxl::ColorTransform::kNone;
}
}
io.metadata.m.SetAlphaBits(8);
if (!io.metadata.size.Set(width, height)) {
return val::null();
}
uint8_t* inBuffer = (uint8_t*)image.c_str();
auto result = jxl::ConvertFromExternal(
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);
if (!result) {
return val::null();
}
auto js_result = val::null();
if (EncodeFile(cparams, &io, &passes_enc_state, &bytes, /*aux=*/nullptr, pool_ptr)) {
js_result = Uint8Array.new_(typed_memory_view(bytes.size(), bytes.data()));
}
return js_result;
}
EMSCRIPTEN_BINDINGS(my_module) {
value_object<JXLOptions>("JXLOptions")
.field("effort", &JXLOptions::effort)
.field("quality", &JXLOptions::quality)
.field("progressive", &JXLOptions::progressive)
.field("lossyPalette", &JXLOptions::lossyPalette)
.field("decodingSpeedTier", &JXLOptions::decodingSpeedTier)
.field("photonNoiseIso", &JXLOptions::photonNoiseIso)
.field("epf", &JXLOptions::epf);
function("encode", &encode);
}

22
codecs/jxl/enc/jxl_enc.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
export interface EncodeOptions {
effort: number;
quality: number;
progressive: boolean;
epf: number;
lossyPalette: boolean;
decodingSpeedTier: number;
photonNoiseIso: number;
}
export interface JXLModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions,
): Uint8Array | null;
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<JXLModule>;
export default moduleFactory;

16
codecs/jxl/enc/jxl_enc.js generated Normal file

File diff suppressed because one or more lines are too long

BIN
codecs/jxl/enc/jxl_enc.wasm Executable file

Binary file not shown.

1
codecs/jxl/enc/jxl_enc_mt.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export { default } from './jxl_enc';

16
codecs/jxl/enc/jxl_enc_mt.js generated Normal file

File diff suppressed because one or more lines are too long

BIN
codecs/jxl/enc/jxl_enc_mt.wasm Executable file

Binary file not shown.

1
codecs/jxl/enc/jxl_enc_mt.worker.js generated Normal file
View File

@ -0,0 +1 @@
"use strict";var Module={};var initializedJS=false;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:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};function moduleLoaded(){}self.onmessage=function(e){try{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;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./jxl_enc_mt.js")).then(function(exports){return exports.default(Module)}).then(function(instance){Module=instance;moduleLoaded()})}else if(e.data.cmd==="objectTransfer"){Module["PThread"].receiveObjectTransfer(e.data)}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.threadInfoStruct,0,0);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();if(!initializedJS){Module["___embind_register_native_and_builtin_types"]();initializedJS=true}try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["PThread"].threadExit(result)}}catch(ex){if(ex==="Canceled!"){Module["PThread"].threadCancel()}else if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){}else{Module["PThread"].threadExit(ex.status)}}else{Module["PThread"].threadExit(-2);throw ex}}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);throw ex}};

1
codecs/jxl/enc/jxl_enc_mt_simd.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export { default } from './jxl_enc';

16
codecs/jxl/enc/jxl_enc_mt_simd.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1 @@
"use strict";var Module={};var initializedJS=false;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:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};function moduleLoaded(){}self.onmessage=function(e){try{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;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./jxl_enc_mt_simd.js")).then(function(exports){return exports.default(Module)}).then(function(instance){Module=instance;moduleLoaded()})}else if(e.data.cmd==="objectTransfer"){Module["PThread"].receiveObjectTransfer(e.data)}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.threadInfoStruct,0,0);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();if(!initializedJS){Module["___embind_register_native_and_builtin_types"]();initializedJS=true}try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["PThread"].threadExit(result)}}catch(ex){if(ex==="Canceled!"){Module["PThread"].threadCancel()}else if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){}else{Module["PThread"].threadExit(ex.status)}}else{Module["PThread"].threadExit(-2);throw ex}}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);throw ex}};

16
codecs/jxl/enc/jxl_node_enc.js generated Normal file

File diff suppressed because one or more lines are too long

BIN
codecs/jxl/enc/jxl_node_enc.wasm Executable file

Binary file not shown.

View File

@ -1,5 +1,5 @@
{
"name": "mozjpeg_enc",
"name": "jxl",
"scripts": {
"build": "../build-cpp.sh"
}

View File

@ -2,23 +2,29 @@ CODEC_URL := https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz
CODEC_DIR := node_modules/mozjpeg
CODEC_OUT_RELATIVE := .libs/libjpeg.a rdswitch.o
CODEC_OUT := $(addprefix $(CODEC_DIR)/, $(CODEC_OUT_RELATIVE))
OUT_JS := mozjpeg_enc.js
ENVIRONMENT = worker
OUT_JS := enc/mozjpeg_enc.js enc/mozjpeg_node_enc.js dec/mozjpeg_node_dec.js
OUT_WASM := $(OUT_JS:.js=.wasm)
.PHONY: all clean
all: $(OUT_JS)
%.js: %.cpp $(CODEC_OUT)
# Define dependencies for all variations of build artifacts.
$(filter enc/%,$(OUT_JS)): enc/mozjpeg_enc.cpp
$(filter dec/%,$(OUT_JS)): dec/mozjpeg_dec.cpp
enc/mozjpeg_node_enc.js dec/mozjpeg_node_dec.js: ENVIRONMENT = node
%.js: $(CODEC_OUT)
$(CXX) \
-I $(CODEC_DIR) \
${CXXFLAGS} \
${LDFLAGS} \
--bind \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s 'EXPORT_NAME="$(basename $(@F))"' \
-s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \
-o $@ \
$+
@ -36,7 +42,10 @@ $(CODEC_DIR)/Makefile: $(CODEC_DIR)/configure
--without-turbojpeg \
--without-simd \
--without-arith-enc \
--without-arith-dec
--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.
$(CODEC_DIR)/configure: $(CODEC_DIR)/configure.ac
cd $(CODEC_DIR) && autoreconf -iv

View File

@ -0,0 +1,57 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "config.h"
#include "jpeglib.h"
extern "C" {
#include "cdjpeg.h"
}
using namespace emscripten;
thread_local const val Uint8ClampedArray = val::global("Uint8ClampedArray");
thread_local const val ImageData = val::global("ImageData");
val decode(std::string image_in) {
uint8_t* image_buffer = (uint8_t*)image_in.c_str();
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
// Initialize the JPEG decompression object with default error handling.
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, image_buffer, image_in.length());
// Read file header, set default decompression parameters
jpeg_read_header(&cinfo, TRUE);
// Force RGBA decoding, even for grayscale images
cinfo.out_color_space = JCS_EXT_RGBA;
jpeg_start_decompress(&cinfo);
// Prepare output buffer
size_t output_size = cinfo.output_width * cinfo.output_height * 4;
std::vector<uint8_t> output_buffer(output_size);
auto stride = cinfo.output_width * 4;
// Process data
while (cinfo.output_scanline < cinfo.output_height) {
uint8_t* ptr = &output_buffer[stride * cinfo.output_scanline];
jpeg_read_scanlines(&cinfo, &ptr, 1);
}
jpeg_finish_decompress(&cinfo);
// Step 7: release JPEG compression object
auto data = Uint8ClampedArray.new_(typed_memory_view(output_size, &output_buffer[0]));
auto js_result = ImageData.new_(data, cinfo.output_width, cinfo.output_height);
// This is an important step since it will release a good deal of memory.
jpeg_destroy_decompress(&cinfo);
// And we're done!
return js_result;
}
EMSCRIPTEN_BINDINGS(my_module) {
function("decode", &decode);
}

16
codecs/mozjpeg/dec/mozjpeg_node_dec.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -141,6 +141,7 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_EOB_OPT, opts.trellis_opt_zero);
jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_Q_OPT, opts.trellis_opt_table);
jpeg_c_set_int_param(&cinfo, JINT_TRELLIS_NUM_LOOPS, opts.trellis_loops);
jpeg_c_set_int_param(&cinfo, JINT_DC_SCAN_OPT_MODE, 0);
// A little hacky to build a string for this, but it means we can use
// set_quality_ratings which does some useful heuristic stuff.
@ -157,6 +158,11 @@ val encode(std::string image_in, int image_width, int image_height, MozJpegOptio
if (!opts.auto_subsample && opts.color_space == JCS_YCbCr) {
cinfo.comp_info[0].h_samp_factor = opts.chroma_subsample;
cinfo.comp_info[0].v_samp_factor = opts.chroma_subsample;
if (opts.chroma_subsample > 2) {
// Otherwise encoding fails.
jpeg_c_set_int_param(&cinfo, JINT_DC_SCAN_OPT_MODE, 1);
}
}
if (!opts.baseline && opts.progressive) {

37
codecs/mozjpeg/enc/mozjpeg_enc.d.ts vendored Normal file
View File

@ -0,0 +1,37 @@
export const enum MozJpegColorSpace {
GRAYSCALE = 1,
RGB,
YCbCr,
}
export interface EncodeOptions {
quality: number;
baseline: boolean;
arithmetic: boolean;
progressive: boolean;
optimize_coding: boolean;
smoothing: number;
color_space: MozJpegColorSpace;
quant_table: number;
trellis_multipass: boolean;
trellis_opt_zero: boolean;
trellis_opt_table: boolean;
trellis_loops: number;
auto_subsample: boolean;
chroma_subsample: number;
separate_chroma_quality: boolean;
chroma_quality: number;
}
export interface MozJPEGModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions,
): Uint8Array;
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<MozJPEGModule>;
export default moduleFactory;

16
codecs/mozjpeg/enc/mozjpeg_enc.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

16
codecs/mozjpeg/enc/mozjpeg_node_enc.js generated Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,5 @@
{
"scripts": {
"build": "../build-cpp.sh"
}
}

View File

@ -1,44 +0,0 @@
# MozJPEG encoder
- Source: <https://github.com/mozilla/mozjpeg>
- Version: v3.3.1
- License: BSD
## Dependencies
- Docker
## Example
See `example.html`
## API
### `int version()`
Returns the version of MozJPEG as a number. va.b.c is encoded as 0x0a0b0c
### `Uint8Array encode(std::string image_in, int image_width, int image_height, MozJpegOptions opts)`
Encodes the given image with given dimension to JPEG. Options looks like this:
```c++
struct MozJpegOptions {
int quality;
bool baseline;
bool arithmetic;
bool progressive;
bool optimize_coding;
int smoothing;
int color_space;
int quant_table;
bool trellis_multipass;
bool trellis_opt_zero;
bool trellis_opt_table;
int trellis_loops;
bool auto_subsample;
int chroma_subsample;
bool separate_chroma_quality;
int chroma_quality;
};
```

View File

@ -1,48 +0,0 @@
<!doctype html>
<script src='mozjpeg_enc.js'></script>
<script>
const module = mozjpeg_enc();
async function loadImage(src) {
// Load image
const img = document.createElement('img');
img.src = src;
await new Promise(resolve => img.onload = resolve);
// Make canvas same size as image
const canvas = document.createElement('canvas');
[canvas.width, canvas.height] = [img.width, img.height];
// Draw image onto canvas
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
return ctx.getImageData(0, 0, img.width, img.height);
}
module.onRuntimeInitialized = async _ => {
console.log('Version:', module.version().toString(16));
const image = await loadImage('../example.png');
const result = module.encode(image.data, image.width, image.height, {
quality: 75,
baseline: false,
arithmetic: false,
progressive: true,
optimize_coding: true,
smoothing: 0,
color_space: 3,
quant_table: 3,
trellis_multipass: false,
trellis_opt_zero: false,
trellis_opt_table: false,
trellis_loops: 1,
auto_subsample: true,
chroma_subsample: 2,
separate_chroma_quality: false,
chroma_quality: 75,
});
const blob = new Blob([result], {type: 'image/jpeg'});
const blobURL = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = blobURL;
document.body.appendChild(img);
};
</script>

View File

@ -1,7 +0,0 @@
import { EncodeOptions } from '../../src/codecs/mozjpeg/encoder-meta';
interface MozJPEGModule extends EmscriptenWasm.Module {
encode(data: BufferSource, width: number, height: number, options: EncodeOptions): Uint8Array;
}
export default function(opts: EmscriptenWasm.ModuleOpts): Promise<MozJPEGModule>;

View File

@ -1,72 +0,0 @@
var mozjpeg_enc = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
return (
function(mozjpeg_enc) {
mozjpeg_enc = mozjpeg_enc || {};
var d;d||(d=typeof mozjpeg_enc !== 'undefined' ? mozjpeg_enc : {});var aa,ba;d.ready=new Promise(function(a,b){aa=a;ba=b});var r={},t;for(t in d)d.hasOwnProperty(t)&&(r[t]=d[t]);var ca="./this.program";function u(a,b){throw b;}var v=!1,w=!1,da=!1,ea=!1;v="object"===typeof window;w="function"===typeof importScripts;da="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;ea=!v&&!da&&!w;var x="",B,C,fa,ha;
if(da)x=w?require("path").dirname(x)+"/":__dirname+"/",B=function(a,b){fa||(fa=require("fs"));ha||(ha=require("path"));a=ha.normalize(a);return fa.readFileSync(a,b?null:"utf8")},C=function(a){a=B(a,!0);a.buffer||(a=new Uint8Array(a));a.buffer||D("Assertion failed: undefined");return a},1<process.argv.length&&(ca=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2),process.on("uncaughtException",function(a){if(!(a instanceof ja))throw a;}),process.on("unhandledRejection",D),u=function(a){process.exit(a)},
d.inspect=function(){return"[Emscripten Module object]"};else if(ea)"undefined"!=typeof read&&(B=function(a){return read(a)}),C=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");"object"===typeof a||D("Assertion failed: undefined");return a},"function"===typeof quit&&(u=function(a){quit(a)}),"undefined"!==typeof print&&("undefined"===typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!==typeof printErr?printErr:
print);else if(v||w)w?x=self.location.href:document.currentScript&&(x=document.currentScript.src),_scriptDir&&(x=_scriptDir),0!==x.indexOf("blob:")?x=x.substr(0,x.lastIndexOf("/")+1):x="",B=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},w&&(C=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});var ka=d.print||console.log.bind(console),E=d.printErr||console.warn.bind(console);
for(t in r)r.hasOwnProperty(t)&&(d[t]=r[t]);r=null;d.thisProgram&&(ca=d.thisProgram);d.quit&&(u=d.quit);var G;d.wasmBinary&&(G=d.wasmBinary);var noExitRuntime;d.noExitRuntime&&(noExitRuntime=d.noExitRuntime);"object"!==typeof WebAssembly&&D("no native wasm support detected");var H,la=new WebAssembly.Table({initial:115,maximum:115,element:"anyfunc"}),ma=!1,na="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
function oa(a,b,c){var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16<c-b&&a.subarray&&na)return na.decode(a.subarray(b,c));for(e="";b<c;){var f=a[b++];if(f&128){var g=a[b++]&63;if(192==(f&224))e+=String.fromCharCode((f&31)<<6|g);else{var l=a[b++]&63;f=224==(f&240)?(f&15)<<12|g<<6|l:(f&7)<<18|g<<12|l<<6|a[b++]&63;65536>f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e}
function pa(a,b,c){var e=I;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 l=a.charCodeAt(++f);g=65536+((g&1023)<<10)|l&1023}if(127>=g){if(b>=c)break;e[b++]=g}else{if(2047>=g){if(b+1>=c)break;e[b++]=192|g>>6}else{if(65535>=g){if(b+2>=c)break;e[b++]=224|g>>12}else{if(b+3>=c)break;e[b++]=240|g>>18;e[b++]=128|g>>12&63}e[b++]=128|g>>6&63}e[b++]=128|g&63}}e[b]=0}}var qa="undefined"!==typeof TextDecoder?new TextDecoder("utf-16le"):void 0;
function ra(a,b){var c=a>>1;for(var e=c+b/2;!(c>=e)&&sa[c];)++c;c<<=1;if(32<c-a&&qa)return qa.decode(I.subarray(a,c));c=0;for(e="";;){var f=J[a+2*c>>1];if(0==f||c==b/2)return e;++c;e+=String.fromCharCode(f)}}function ta(a,b,c){void 0===c&&(c=2147483647);if(2>c)return 0;c-=2;var e=b;c=c<2*a.length?c/2:a.length;for(var f=0;f<c;++f)J[b>>1]=a.charCodeAt(f),b+=2;J[b>>1]=0;return b-e}function ua(a){return 2*a.length}
function va(a,b){for(var c=0,e="";!(c>=b/4);){var f=K[a+4*c>>2];if(0==f)break;++c;65536<=f?(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023)):e+=String.fromCharCode(f)}return e}function wa(a,b,c){void 0===c&&(c=2147483647);if(4>c)return 0;var e=b;c=e+c-4;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var l=a.charCodeAt(++f);g=65536+((g&1023)<<10)|l&1023}K[b>>2]=g;b+=4;if(b+4>c)break}K[b>>2]=0;return b-e}
function xa(a){for(var b=0,c=0;c<a.length;++c){var e=a.charCodeAt(c);55296<=e&&57343>=e&&++c;b+=4}return b}var L,M,I,J,sa,K,N,ya,za;function Aa(a){L=a;d.HEAP8=M=new Int8Array(a);d.HEAP16=J=new Int16Array(a);d.HEAP32=K=new Int32Array(a);d.HEAPU8=I=new Uint8Array(a);d.HEAPU16=sa=new Uint16Array(a);d.HEAPU32=N=new Uint32Array(a);d.HEAPF32=ya=new Float32Array(a);d.HEAPF64=za=new Float64Array(a)}var Ba=d.INITIAL_MEMORY||16777216;d.wasmMemory?H=d.wasmMemory:H=new WebAssembly.Memory({initial:Ba/65536,maximum:32768});
H&&(L=H.buffer);Ba=L.byteLength;Aa(L);K[21680]=5329760;function Ca(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b(d);else{var c=b.da;"number"===typeof c?void 0===b.Y?d.dynCall_v(c):d.dynCall_vi(c,b.Y):c(void 0===b.Y?null:b.Y)}}}var Da=[],Ea=[],Fa=[],Ga=[];function Ha(){var a=d.preRun.shift();Da.unshift(a)}var O=0,Ia=null,P=null;d.preloadedImages={};d.preloadedAudios={};
function D(a){if(d.onAbort)d.onAbort(a);E(a);ma=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");ba(a);throw a;}function Ja(a){var b=Q;return String.prototype.startsWith?b.startsWith(a):0===b.indexOf(a)}function Ka(){return Ja("data:application/octet-stream;base64,")}var Q="mozjpeg_enc.wasm";if(!Ka()){var La=Q;Q=d.locateFile?d.locateFile(La,x):x+La}
function Ma(){try{if(G)return new Uint8Array(G);if(C)return C(Q);throw"both async and sync fetching of the wasm failed";}catch(a){D(a)}}function Na(){return G||!v&&!w||"function"!==typeof fetch||Ja("file://")?new Promise(function(a){a(Ma())}):fetch(Q,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+Q+"'";return a.arrayBuffer()}).catch(function(){return Ma()})}Ea.push({da:function(){Oa()}});var Pa={};
function Qa(a){for(;a.length;){var b=a.pop();a.pop()(b)}}function Ra(a){return this.fromWireType(N[a>>2])}var R={},S={},Sa={};function Ta(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 Ua(a,b){a=Ta(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)}
function Va(a){var b=Error,c=Ua(a,function(e){this.name=a;this.message=e;e=Error(e).stack;void 0!==e&&(this.stack=this.toString()+"\n"+e.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 Wa=void 0;
function Xa(a,b,c){function e(k){k=c(k);if(k.length!==a.length)throw new Wa("Mismatched type converter count");for(var h=0;h<a.length;++h)T(a[h],k[h])}a.forEach(function(k){Sa[k]=b});var f=Array(b.length),g=[],l=0;b.forEach(function(k,h){S.hasOwnProperty(k)?f[h]=S[k]:(g.push(k),R.hasOwnProperty(k)||(R[k]=[]),R[k].push(function(){f[h]=S[k];++l;l===g.length&&e(f)}))});0===g.length&&e(f)}
function Ya(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 Za=void 0;function U(a){for(var b="";I[a];)b+=Za[I[a++]];return b}var $a=void 0;function V(a){throw new $a(a);}
function T(a,b,c){c=c||{};if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var e=b.name;a||V('type "'+e+'" must have a positive integer typeid pointer');if(S.hasOwnProperty(a)){if(c.ha)return;V("Cannot register type '"+e+"' twice")}S[a]=b;delete Sa[a];R.hasOwnProperty(a)&&(b=R[a],delete R[a],b.forEach(function(f){f()}))}var ab=[],X=[{},{value:void 0},{value:null},{value:!0},{value:!1}];
function bb(a){4<a&&0===--X[a].Z&&(X[a]=void 0,ab.push(a))}function cb(a){switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=ab.length?ab.pop():X.length;X[b]={Z:1,value:a};return b}}function db(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a}
function eb(a,b){switch(b){case 2:return function(c){return this.fromWireType(ya[c>>2])};case 3:return function(c){return this.fromWireType(za[c>>3])};default:throw new TypeError("Unknown float type: "+a);}}function fb(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=Ua(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}
function gb(a,b){var c=d;if(void 0===c[a].W){var e=c[a];c[a]=function(){c[a].W.hasOwnProperty(arguments.length)||V("Function '"+b+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+c[a].W+")!");return c[a].W[arguments.length].apply(this,arguments)};c[a].W=[];c[a].W[e.aa]=e}}
function hb(a,b,c){d.hasOwnProperty(a)?((void 0===c||void 0!==d[a].W&&void 0!==d[a].W[c])&&V("Cannot register public name '"+a+"' twice"),gb(a,a),d.hasOwnProperty(c)&&V("Cannot register multiple overloads of a function with the same number of arguments ("+c+")!"),d[a].W[c]=b):(d[a]=b,void 0!==c&&(d[a].oa=c))}function ib(a,b){for(var c=[],e=0;e<a;e++)c.push(K[(b>>2)+e]);return c}
function Y(a,b){a=U(a);var c=d["dynCall_"+a];for(var e=[],f=1;f<a.length;++f)e.push("a"+f);f="return function dynCall_"+(a+"_"+b)+"("+e.join(", ")+") {\n";f+=" return dynCall(rawFunction"+(e.length?", ":"")+e.join(", ")+");\n";c=(new Function("dynCall","rawFunction",f+"};\n"))(c,b);"function"!==typeof c&&V("unknown function pointer with signature "+a+": "+b);return c}var jb=void 0;function kb(a){a=lb(a);var b=U(a);Z(a);return b}
function mb(a,b){function c(g){f[g]||S[g]||(Sa[g]?Sa[g].forEach(c):(e.push(g),f[g]=!0))}var e=[],f={};b.forEach(c);throw new jb(a+": "+e.map(kb).join([", "]));}function nb(a,b,c){switch(b){case 0:return c?function(e){return M[e]}:function(e){return I[e]};case 1:return c?function(e){return J[e>>1]}:function(e){return sa[e>>1]};case 2:return c?function(e){return K[e>>2]}:function(e){return N[e>>2]};default:throw new TypeError("Unknown integer type: "+a);}}var ob={};
function pb(){return"object"===typeof globalThis?globalThis:Function("return this")()}function qb(a,b){var c=S[a];void 0===c&&V(b+" has unknown type "+kb(a));return c}var rb={},sb={};function tb(){if(!ub){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"===typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:ca||"./this.program"},b;for(b in sb)a[b]=sb[b];var c=[];for(b in a)c.push(b+"="+a[b]);ub=c}return ub}
var ub,vb=[null,[],[]];Wa=d.InternalError=Va("InternalError");for(var wb=Array(256),xb=0;256>xb;++xb)wb[xb]=String.fromCharCode(xb);Za=wb;$a=d.BindingError=Va("BindingError");d.count_emval_handles=function(){for(var a=0,b=5;b<X.length;++b)void 0!==X[b]&&++a;return a};d.get_first_emval=function(){for(var a=5;a<X.length;++a)if(void 0!==X[a])return X[a];return null};jb=d.UnboundTypeError=Va("UnboundTypeError");
var zb={A:function(){},n:function(a){var b=Pa[a];delete Pa[a];var c=b.ia,e=b.ja,f=b.$,g=f.map(function(l){return l.ga}).concat(f.map(function(l){return l.la}));Xa([a],g,function(l){var k={};f.forEach(function(h,m){var n=l[m],q=h.ea,y=h.fa,z=l[m+f.length],p=h.ka,ia=h.ma;k[h.ba]={read:function(A){return n.fromWireType(q(y,A))},write:function(A,F){var W=[];p(ia,A,z.toWireType(W,F));Qa(W)}}});return[{name:b.name,fromWireType:function(h){var m={},n;for(n in k)m[n]=k[n].read(h);e(h);return m},toWireType:function(h,
m){for(var n in k)if(!(n in m))throw new TypeError('Missing field: "'+n+'"');var q=c();for(n in k)k[n].write(q,m[n]);null!==h&&h.push(e,q);return q},argPackAdvance:8,readValueFromPointer:Ra,X:e}]})},x:function(a,b,c,e,f){var g=Ya(c);b=U(b);T(a,{name:b,fromWireType:function(l){return!!l},toWireType:function(l,k){return k?e:f},argPackAdvance:8,readValueFromPointer:function(l){if(1===c)var k=M;else if(2===c)k=J;else if(4===c)k=K;else throw new TypeError("Unknown boolean type size: "+b);return this.fromWireType(k[l>>
g])},X:null})},w:function(a,b){b=U(b);T(a,{name:b,fromWireType:function(c){var e=X[c].value;bb(c);return e},toWireType:function(c,e){return cb(e)},argPackAdvance:8,readValueFromPointer:Ra,X:null})},j:function(a,b,c){c=Ya(c);b=U(b);T(a,{name:b,fromWireType:function(e){return e},toWireType:function(e,f){if("number"!==typeof f&&"boolean"!==typeof f)throw new TypeError('Cannot convert "'+db(f)+'" to '+this.name);return f},argPackAdvance:8,readValueFromPointer:eb(b,c),X:null})},f:function(a,b,c,e,f,g){var l=
ib(b,c);a=U(a);f=Y(e,f);hb(a,function(){mb("Cannot call "+a+" due to unbound types",l)},b-1);Xa([],l,function(k){var h=[k[0],null].concat(k.slice(1)),m=k=a,n=f,q=h.length;2>q&&V("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var y=null!==h[1]&&!1,z=!1,p=1;p<h.length;++p)if(null!==h[p]&&void 0===h[p].X){z=!0;break}var ia="void"!==h[0].name,A="",F="";for(p=0;p<q-2;++p)A+=(0!==p?", ":"")+"arg"+p,F+=(0!==p?", ":"")+"arg"+p+"Wired";m="return function "+Ta(m)+"("+
A+") {\nif (arguments.length !== "+(q-2)+") {\nthrowBindingError('function "+m+" called with ' + arguments.length + ' arguments, expected "+(q-2)+" args!');\n}\n";z&&(m+="var destructors = [];\n");var W=z?"destructors":"null";A="throwBindingError invoker fn runDestructors retType classParam".split(" ");n=[V,n,g,Qa,h[0],h[1]];y&&(m+="var thisWired = classParam.toWireType("+W+", this);\n");for(p=0;p<q-2;++p)m+="var arg"+p+"Wired = argType"+p+".toWireType("+W+", arg"+p+"); // "+h[p+2].name+"\n",A.push("argType"+
p),n.push(h[p+2]);y&&(F="thisWired"+(0<F.length?", ":"")+F);m+=(ia?"var rv = ":"")+"invoker(fn"+(0<F.length?", ":"")+F+");\n";if(z)m+="runDestructors(destructors);\n";else for(p=y?1:2;p<h.length;++p)q=1===p?"thisWired":"arg"+(p-2)+"Wired",null!==h[p].X&&(m+=q+"_dtor("+q+"); // "+h[p].name+"\n",A.push(q+"_dtor"),n.push(h[p].X));ia&&(m+="var ret = retType.fromWireType(rv);\nreturn ret;\n");A.push(m+"}\n");h=fb(A).apply(null,n);p=b-1;if(!d.hasOwnProperty(k))throw new Wa("Replacing nonexistant public symbol");
void 0!==d[k].W&&void 0!==p?d[k].W[p]=h:(d[k]=h,d[k].aa=p);return[]})},c:function(a,b,c,e,f){function g(m){return m}b=U(b);-1===f&&(f=4294967295);var l=Ya(c);if(0===e){var k=32-8*c;g=function(m){return m<<k>>>k}}var h=-1!=b.indexOf("unsigned");T(a,{name:b,fromWireType:g,toWireType:function(m,n){if("number"!==typeof n&&"boolean"!==typeof n)throw new TypeError('Cannot convert "'+db(n)+'" to '+this.name);if(n<e||n>f)throw new TypeError('Passing a number "'+db(n)+'" from JS side to C/C++ side to an argument of type "'+
b+'", which is outside the valid range ['+e+", "+f+"]!");return h?n>>>0:n|0},argPackAdvance:8,readValueFromPointer:nb(b,l,0!==e),X:null})},b:function(a,b,c){function e(g){g>>=2;var l=N;return new f(L,l[g+1],l[g])}var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][b];c=U(c);T(a,{name:c,fromWireType:e,argPackAdvance:8,readValueFromPointer:e},{ha:!0})},k:function(a,b){b=U(b);var c="std::string"===b;T(a,{name:b,fromWireType:function(e){var f=N[e>>2];if(c)for(var g=
e+4,l=0;l<=f;++l){var k=e+4+l;if(l==f||0==I[k]){g=g?oa(I,g,k-g):"";if(void 0===h)var h=g;else h+=String.fromCharCode(0),h+=g;g=k+1}}else{h=Array(f);for(l=0;l<f;++l)h[l]=String.fromCharCode(I[e+4+l]);h=h.join("")}Z(e);return h},toWireType:function(e,f){f instanceof ArrayBuffer&&(f=new Uint8Array(f));var g="string"===typeof f;g||f instanceof Uint8Array||f instanceof Uint8ClampedArray||f instanceof Int8Array||V("Cannot pass non-string to std::string");var l=(c&&g?function(){for(var m=0,n=0;n<f.length;++n){var q=
f.charCodeAt(n);55296<=q&&57343>=q&&(q=65536+((q&1023)<<10)|f.charCodeAt(++n)&1023);127>=q?++m:m=2047>=q?m+2:65535>=q?m+3:m+4}return m}:function(){return f.length})(),k=yb(4+l+1);N[k>>2]=l;if(c&&g)pa(f,k+4,l+1);else if(g)for(g=0;g<l;++g){var h=f.charCodeAt(g);255<h&&(Z(k),V("String has UTF-16 code units that do not fit in 8 bits"));I[k+4+g]=h}else for(g=0;g<l;++g)I[k+4+g]=f[g];null!==e&&e.push(Z,k);return k},argPackAdvance:8,readValueFromPointer:Ra,X:function(e){Z(e)}})},e:function(a,b,c){c=U(c);
if(2===b){var e=ra;var f=ta;var g=ua;var l=function(){return sa};var k=1}else 4===b&&(e=va,f=wa,g=xa,l=function(){return N},k=2);T(a,{name:c,fromWireType:function(h){for(var m=N[h>>2],n=l(),q,y=h+4,z=0;z<=m;++z){var p=h+4+z*b;if(z==m||0==n[p>>k])y=e(y,p-y),void 0===q?q=y:(q+=String.fromCharCode(0),q+=y),y=p+b}Z(h);return q},toWireType:function(h,m){"string"!==typeof m&&V("Cannot pass non-string to C++ string type "+c);var n=g(m),q=yb(4+n+b);N[q>>2]=n>>k;f(m,q+4,n+b);null!==h&&h.push(Z,q);return q},
argPackAdvance:8,readValueFromPointer:Ra,X:function(h){Z(h)}})},o:function(a,b,c,e,f,g){Pa[a]={name:U(b),ia:Y(c,e),ja:Y(f,g),$:[]}},a:function(a,b,c,e,f,g,l,k,h,m){Pa[a].$.push({ba:U(b),ga:c,ea:Y(e,f),fa:g,la:l,ka:Y(k,h),ma:m})},y:function(a,b){b=U(b);T(a,{na:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},h:bb,z:function(a){if(0===a)return cb(pb());var b=ob[a];a=void 0===b?U(a):b;return cb(pb()[a])},m:function(a){4<a&&(X[a].Z+=1)},p:function(a,b,c,e){a||V("Cannot use deleted val. handle = "+
a);a=X[a].value;var f=rb[b];if(!f){f="";for(var g=0;g<b;++g)f+=(0!==g?", ":"")+"arg"+g;var l="return function emval_allocator_"+b+"(constructor, argTypes, args) {\n";for(g=0;g<b;++g)l+="var argType"+g+" = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + "+g+'], "parameter '+g+'");\nvar arg'+g+" = argType"+g+".readValueFromPointer(args);\nargs += argType"+g+"['argPackAdvance'];\n";f=(new Function("requireRegisteredType","Module","__emval_register",l+("var obj = new constructor("+f+");\nreturn __emval_register(obj);\n}\n")))(qb,
d,cb);rb[b]=f}return f(a,c,e)},g:function(){D()},s:function(a,b,c){I.copyWithin(a,b,b+c)},d:function(a){a>>>=0;var b=I.length;if(2147483648<a)return!1;for(var c=1;4>=c;c*=2){var e=b*(1+.2/c);e=Math.min(e,a+100663296);e=Math.max(16777216,a,e);0<e%65536&&(e+=65536-e%65536);a:{try{H.grow(Math.min(2147483648,e)-L.byteLength+65535>>>16);Aa(H.buffer);var f=1;break a}catch(g){}f=void 0}if(f)return!0}return!1},t:function(a,b){var c=0;tb().forEach(function(e,f){var g=b+c;f=K[a+4*f>>2]=g;for(g=0;g<e.length;++g)M[f++>>
0]=e.charCodeAt(g);M[f>>0]=0;c+=e.length+1});return 0},u:function(a,b){var c=tb();K[a>>2]=c.length;var e=0;c.forEach(function(f){e+=f.length+1});K[b>>2]=e;return 0},l:function(a){if(!noExitRuntime&&(ma=!0,d.onExit))d.onExit(a);u(a,new ja(a))},v:function(){return 0},q:function(){},i:function(a,b,c,e){for(var f=0,g=0;g<c;g++){for(var l=K[b+8*g>>2],k=K[b+(8*g+4)>>2],h=0;h<k;h++){var m=I[l+h],n=vb[a];0===m||10===m?((1===a?ka:E)(oa(n,0)),n.length=0):n.push(m)}f+=k}K[e>>2]=f;return 0},memory:H,r:function(){},
table:la};
(function(){function a(f){d.asm=f.exports;O--;d.monitorRunDependencies&&d.monitorRunDependencies(O);0==O&&(null!==Ia&&(clearInterval(Ia),Ia=null),P&&(f=P,P=null,f()))}function b(f){a(f.instance)}function c(f){return Na().then(function(g){return WebAssembly.instantiate(g,e)}).then(f,function(g){E("failed to asynchronously prepare wasm: "+g);D(g)})}var e={a:zb};O++;d.monitorRunDependencies&&d.monitorRunDependencies(O);if(d.instantiateWasm)try{return d.instantiateWasm(e,a)}catch(f){return E("Module.instantiateWasm callback failed with error: "+f),
!1}(function(){if(G||"function"!==typeof WebAssembly.instantiateStreaming||Ka()||Ja("file://")||"function"!==typeof fetch)return c(b);fetch(Q,{credentials:"same-origin"}).then(function(f){return WebAssembly.instantiateStreaming(f,e).then(b,function(g){E("wasm streaming compile failed: "+g);E("falling back to ArrayBuffer instantiation");return c(b)})})})();return{}})();
var Oa=d.___wasm_call_ctors=function(){return(Oa=d.___wasm_call_ctors=d.asm.B).apply(null,arguments)},Z=d._free=function(){return(Z=d._free=d.asm.C).apply(null,arguments)},yb=d._malloc=function(){return(yb=d._malloc=d.asm.D).apply(null,arguments)},lb=d.___getTypeName=function(){return(lb=d.___getTypeName=d.asm.E).apply(null,arguments)};d.___embind_register_native_and_builtin_types=function(){return(d.___embind_register_native_and_builtin_types=d.asm.F).apply(null,arguments)};
d.dynCall_i=function(){return(d.dynCall_i=d.asm.G).apply(null,arguments)};d.dynCall_vi=function(){return(d.dynCall_vi=d.asm.H).apply(null,arguments)};d.dynCall_iii=function(){return(d.dynCall_iii=d.asm.I).apply(null,arguments)};d.dynCall_viii=function(){return(d.dynCall_viii=d.asm.J).apply(null,arguments)};d.dynCall_ii=function(){return(d.dynCall_ii=d.asm.K).apply(null,arguments)};d.dynCall_iiiiii=function(){return(d.dynCall_iiiiii=d.asm.L).apply(null,arguments)};
d.dynCall_viiiii=function(){return(d.dynCall_viiiii=d.asm.M).apply(null,arguments)};d.dynCall_vii=function(){return(d.dynCall_vii=d.asm.N).apply(null,arguments)};d.dynCall_iiiiiii=function(){return(d.dynCall_iiiiiii=d.asm.O).apply(null,arguments)};d.dynCall_iiiii=function(){return(d.dynCall_iiiii=d.asm.P).apply(null,arguments)};d.dynCall_iiii=function(){return(d.dynCall_iiii=d.asm.Q).apply(null,arguments)};d.dynCall_viiii=function(){return(d.dynCall_viiii=d.asm.R).apply(null,arguments)};
d.dynCall_viiiiiiii=function(){return(d.dynCall_viiiiiiii=d.asm.S).apply(null,arguments)};d.dynCall_viiiiiii=function(){return(d.dynCall_viiiiiii=d.asm.T).apply(null,arguments)};d.dynCall_jiji=function(){return(d.dynCall_jiji=d.asm.U).apply(null,arguments)};d.dynCall_viiiiii=function(){return(d.dynCall_viiiiii=d.asm.V).apply(null,arguments)};var Ab;function ja(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}P=function Bb(){Ab||Cb();Ab||(P=Bb)};
function Cb(){function a(){if(!Ab&&(Ab=!0,d.calledRun=!0,!ma)){Ca(Ea);Ca(Fa);aa(d);if(d.onRuntimeInitialized)d.onRuntimeInitialized();if(d.postRun)for("function"==typeof d.postRun&&(d.postRun=[d.postRun]);d.postRun.length;){var b=d.postRun.shift();Ga.unshift(b)}Ca(Ga)}}if(!(0<O)){if(d.preRun)for("function"==typeof d.preRun&&(d.preRun=[d.preRun]);d.preRun.length;)Ha();Ca(Da);0<O||(d.setStatus?(d.setStatus("Running..."),setTimeout(function(){setTimeout(function(){d.setStatus("")},1);a()},1)):a())}}
d.run=Cb;if(d.preInit)for("function"==typeof d.preInit&&(d.preInit=[d.preInit]);0<d.preInit.length;)d.preInit.pop()();noExitRuntime=!0;Cb();
return mozjpeg_enc.ready
}
);
})();
if (typeof exports === 'object' && typeof module === 'object')
module.exports = mozjpeg_enc;
else if (typeof define === 'function' && define['amd'])
define([], function() { return mozjpeg_enc; });
else if (typeof exports === 'object')
exports["mozjpeg_enc"] = mozjpeg_enc;

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