@joycostudio/chopper 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/THIRD_PARTY_NOTICES.md +44 -9
- package/codecs/manifest.json +9 -2
- package/codecs/zstd.wasm +0 -0
- package/dist/browser/{chunk-TNQ7E4HG.js → chunk-6PIXH7DA.js} +11 -4
- package/dist/browser/chunk-6PIXH7DA.js.map +1 -0
- package/dist/browser/{in-process-3KN2LY3L.js → in-process-FAMTTLSK.js} +251 -14
- package/dist/browser/in-process-FAMTTLSK.js.map +1 -0
- package/dist/browser/index.d.ts +32 -5
- package/dist/browser/index.js +2 -2
- package/dist/browser/worker.js +274 -14
- package/dist/browser/worker.js.map +1 -1
- package/dist/cli/index.js +259 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +24 -3
- package/dist/config/index.js +20 -2
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +43 -9
- package/dist/index.js +38 -4
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +32 -5
- package/dist/node/index.js +257 -13
- package/dist/node/index.js.map +1 -1
- package/package.json +5 -2
- package/dist/browser/chunk-TNQ7E4HG.js.map +0 -1
- package/dist/browser/in-process-3KN2LY3L.js.map +0 -1
package/README.md
CHANGED
|
@@ -31,6 +31,60 @@ chopper codecs sync public/chopper-codecs
|
|
|
31
31
|
The browser defaults to a module worker and verifies the codec manifest and
|
|
32
32
|
each downloaded artifact. Node resolves the same artifacts from this package.
|
|
33
33
|
|
|
34
|
+
## Lossless raw KTX2
|
|
35
|
+
|
|
36
|
+
Use raw RGBA8 for numeric textures such as MSDF font atlases that must retain
|
|
37
|
+
every decoded pixel:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { defineRecipe } from '@joycostudio/chopper'
|
|
41
|
+
|
|
42
|
+
const atlasRecipe = defineRecipe({
|
|
43
|
+
kind: 'image',
|
|
44
|
+
encode: {
|
|
45
|
+
codec: 'ktx2',
|
|
46
|
+
mode: 'raw',
|
|
47
|
+
colorSpace: 'linear',
|
|
48
|
+
mipmaps: false,
|
|
49
|
+
zstd: true,
|
|
50
|
+
zstdLevel: 19,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
All fields after `mode` above show their defaults. Zstandard effort accepts
|
|
56
|
+
integers 1–19 and never changes fidelity. Set `zstd: false` to store the same
|
|
57
|
+
texels uncompressed; omit `zstdLevel` in that case. Browser workers and Node
|
|
58
|
+
use the same pinned Zstd artifact, loaded only when needed. Raw mode never
|
|
59
|
+
initializes Basis.
|
|
60
|
+
|
|
61
|
+
PNG/JPEG sources retain their decoded RGBA8 bytes, original dimensions and row
|
|
62
|
+
order, including RGB beneath transparent alpha. Palette and grayscale PNGs
|
|
63
|
+
expand to RGBA8. JPEG retains the decoder's output, including the source's
|
|
64
|
+
existing compression loss. No gamma/ICC conversion, premultiplication,
|
|
65
|
+
resizing, flipping, or block padding is applied. `linear` labels numeric data
|
|
66
|
+
with unspecified primaries; `srgb` labels the unchanged samples with sRGB
|
|
67
|
+
transfer and BT.709 primaries. Alpha is always linear.
|
|
68
|
+
|
|
69
|
+
Raw output has one base level, top-left orientation, the `.ktx2` extension and
|
|
70
|
+
`image/ktx2` MIME type. It is kept even when larger than the source. Zstd reduces
|
|
71
|
+
transfer/storage size; GPU storage remains **width × height × 4 bytes**.
|
|
72
|
+
Faster startup is not guaranteed and needs profiling on target devices.
|
|
73
|
+
|
|
74
|
+
Only standalone image recipes support raw mode. GLB embedded-texture recipes
|
|
75
|
+
reject it because `KHR_texture_basisu` cannot represent raw RGBA8. Raw mode
|
|
76
|
+
also rejects 16-bit PNG, HDR/float sources, `mipmaps: true`, `maxSize`, and Basis
|
|
77
|
+
options such as `level`, `quality`, `compression`, `rdo`, and `normalMap`.
|
|
78
|
+
|
|
79
|
+
Three.js `KTX2Loader` loads these files as native-size RGBA8 `DataTexture`s
|
|
80
|
+
without compressed-texture GPU support. For MSDF/data textures, use the linear
|
|
81
|
+
recipe and retain `NoColorSpace`, `flipY = false`, no generated mipmaps, and
|
|
82
|
+
linear minification/magnification filters. Original atlas metrics and UVs need
|
|
83
|
+
no block-padding adjustments. The loader may inflate Zstd synchronously;
|
|
84
|
+
measure loading and upload latency separately from encoded file size.
|
|
85
|
+
|
|
86
|
+
## Batch and routing
|
|
87
|
+
|
|
34
88
|
Batch results expose the same complete optimization provenance as the core API:
|
|
35
89
|
|
|
36
90
|
```ts
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -4,16 +4,51 @@ Chopper distributes or builds against the following third-party software. The
|
|
|
4
4
|
package versions are pinned in `package.json`; codec artifact versions and
|
|
5
5
|
SHA-256 digests are recorded in `codecs/manifest.json`.
|
|
6
6
|
|
|
7
|
-
| Software | License
|
|
8
|
-
| --------------------------------------------------------------------------- |
|
|
9
|
-
| @gltf-transform/core, @gltf-transform/extensions, @gltf-transform/functions | MIT
|
|
10
|
-
| @jsquash/avif, @jsquash/jpeg, @jsquash/png, @jsquash/resize, @jsquash/webp | Apache-2.0
|
|
11
|
-
| Draco (`draco3dgltf`) | Apache-2.0
|
|
12
|
-
| ktx2-encoder | MIT
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
7
|
+
| Software | License |
|
|
8
|
+
| --------------------------------------------------------------------------- | ------------ |
|
|
9
|
+
| @gltf-transform/core, @gltf-transform/extensions, @gltf-transform/functions | MIT |
|
|
10
|
+
| @jsquash/avif, @jsquash/jpeg, @jsquash/png, @jsquash/resize, @jsquash/webp | Apache-2.0 |
|
|
11
|
+
| Draco (`draco3dgltf`) | Apache-2.0 |
|
|
12
|
+
| ktx2-encoder | MIT |
|
|
13
|
+
| @bokuweb/zstd-wasm | MIT |
|
|
14
|
+
| Zstandard (inside zstd.wasm) | BSD-3-Clause |
|
|
15
|
+
| meshoptimizer | MIT |
|
|
16
|
+
| tinyglobby | MIT |
|
|
17
|
+
| jiti | MIT |
|
|
16
18
|
|
|
17
19
|
Copyright and license terms remain with their respective authors. Source and
|
|
18
20
|
license texts are available from each dependency's published package and
|
|
19
21
|
upstream repository.
|
|
22
|
+
|
|
23
|
+
## Zstandard
|
|
24
|
+
|
|
25
|
+
The pinned `@bokuweb/zstd-wasm` artifact is built from
|
|
26
|
+
[Zstandard](https://github.com/facebook/zstd) by
|
|
27
|
+
[@bokuweb/zstd-wasm](https://github.com/bokuweb/zstd-wasm). The wrapper package
|
|
28
|
+
declares MIT licensing; Chopper distributes the compiled Zstandard WASM with
|
|
29
|
+
the following upstream BSD license.
|
|
30
|
+
|
|
31
|
+
Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
|
|
32
|
+
|
|
33
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
34
|
+
are permitted provided that the following conditions are met:
|
|
35
|
+
|
|
36
|
+
- Redistributions of source code must retain the above copyright notice, this
|
|
37
|
+
list of conditions and the following disclaimer.
|
|
38
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
|
39
|
+
this list of conditions and the following disclaimer in the documentation
|
|
40
|
+
and/or other materials provided with the distribution.
|
|
41
|
+
- Neither the name Facebook, nor Meta, nor the names of its contributors may
|
|
42
|
+
be used to endorse or promote products derived from this software without
|
|
43
|
+
specific prior written permission.
|
|
44
|
+
|
|
45
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
46
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
47
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
48
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
49
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
50
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
51
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
52
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
53
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
54
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/codecs/manifest.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"chopperVersion": "0.8.
|
|
3
|
-
"manifestHash": "
|
|
2
|
+
"chopperVersion": "0.8.1",
|
|
3
|
+
"manifestHash": "1a43d902a113a7dcfa7801bcbd90998e401898dbad555f913e1e7f4352d9c63c",
|
|
4
4
|
"gltfTransformVersion": "4.4.2",
|
|
5
5
|
"meshoptimizerVersion": "1.0.1",
|
|
6
6
|
"artifacts": {
|
|
7
|
+
"zstdEncoder": {
|
|
8
|
+
"packageName": "@bokuweb/zstd-wasm",
|
|
9
|
+
"packageVersion": "0.0.27",
|
|
10
|
+
"packagePath": "dist/common/zstd.wasm",
|
|
11
|
+
"publicFile": "zstd.wasm",
|
|
12
|
+
"sha256": "80260eee5795ee8072bb5821e203730c74dca3909938f5ac1128da67f96223df"
|
|
13
|
+
},
|
|
7
14
|
"avifEncoder": {
|
|
8
15
|
"packageName": "@jsquash/avif",
|
|
9
16
|
"packageVersion": "2.1.1",
|
package/codecs/zstd.wasm
ADDED
|
Binary file
|
|
@@ -7,11 +7,18 @@ var failure = (code, message, cause) => ({
|
|
|
7
7
|
|
|
8
8
|
// package.json
|
|
9
9
|
var package_default = {
|
|
10
|
-
version: "0.8.
|
|
10
|
+
version: "0.8.1"};
|
|
11
11
|
|
|
12
12
|
// src/codecs/manifest.ts
|
|
13
|
-
var CODEC_MANIFEST_HASH = "
|
|
13
|
+
var CODEC_MANIFEST_HASH = "1a43d902a113a7dcfa7801bcbd90998e401898dbad555f913e1e7f4352d9c63c";
|
|
14
14
|
var CODEC_ARTIFACTS = {
|
|
15
|
+
zstdEncoder: {
|
|
16
|
+
packageName: "@bokuweb/zstd-wasm",
|
|
17
|
+
packageVersion: "0.0.27",
|
|
18
|
+
packagePath: "dist/common/zstd.wasm",
|
|
19
|
+
publicFile: "zstd.wasm",
|
|
20
|
+
sha256: "80260eee5795ee8072bb5821e203730c74dca3909938f5ac1128da67f96223df"
|
|
21
|
+
},
|
|
15
22
|
avifEncoder: {
|
|
16
23
|
packageName: "@jsquash/avif",
|
|
17
24
|
packageVersion: "2.1.1",
|
|
@@ -100,5 +107,5 @@ var CODEC_MANIFEST = {
|
|
|
100
107
|
var ENGINE_ID = `chopper@${package_default.version}:${CODEC_MANIFEST_HASH}`;
|
|
101
108
|
|
|
102
109
|
export { CODEC_ARTIFACTS, CODEC_MANIFEST, CODEC_MANIFEST_HASH, ENGINE_ID, failure, success };
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
104
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-6PIXH7DA.js.map
|
|
111
|
+
//# sourceMappingURL=chunk-6PIXH7DA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/result.ts","../../package.json","../../src/codecs/manifest.ts"],"names":[],"mappings":"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","file":"chunk-6PIXH7DA.js","sourcesContent":["export type ChopperErrorCode =\n | 'unsupported_asset'\n | 'invalid_recipe'\n | 'codec_load_failed'\n | 'decode_failed'\n | 'encode_failed'\n | 'validation_failed'\n | 'aborted'\n | 'io_failed'\n\nexport interface ChopperFailure {\n ok: false\n error: {\n code: ChopperErrorCode\n message: string\n cause?: unknown\n }\n}\n\nexport interface ChopperSuccess<T> {\n ok: true\n data: T\n}\n\nexport type ChopperResult<T> = ChopperSuccess<T> | ChopperFailure\n\nexport const success = <T>(data: T): ChopperSuccess<T> => ({ ok: true, data })\n\nexport const failure = (code: ChopperErrorCode, message: string, cause?: unknown): ChopperFailure => ({\n ok: false,\n error: cause === undefined ? { code, message } : { code, message, cause },\n})\n","{\n \"name\": \"@joycostudio/chopper\",\n \"version\": \"0.8.1\",\n \"description\": \"Isomorphic asset optimization pipeline\",\n \"type\": \"module\",\n \"license\": \"ISC\",\n \"author\": \"joyco.studio\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/joyco-studio/chopper.git\",\n \"directory\": \"packages/chopper\"\n },\n \"homepage\": \"https://github.com/joyco-studio/chopper#readme\",\n \"bugs\": \"https://github.com/joyco-studio/chopper/issues\",\n \"publishConfig\": {\n \"registry\": \"https://registry.npmjs.org\",\n \"access\": \"public\"\n },\n \"files\": [\n \"dist\",\n \"codecs\",\n \"README.md\",\n \"THIRD_PARTY_NOTICES.md\"\n ],\n \"bin\": {\n \"chopper\": \"dist/cli/index.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\"\n },\n \"./browser\": {\n \"types\": \"./dist/browser/index.d.ts\",\n \"import\": \"./dist/browser/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/node/index.d.ts\",\n \"import\": \"./dist/node/index.js\",\n \"default\": \"./dist/node/index.js\"\n },\n \"./config\": {\n \"types\": \"./dist/config/index.d.ts\",\n \"import\": \"./dist/config/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"build\": \"pnpm codecs:sync && tsup\",\n \"codecs:sync\": \"tsx ../../scripts/sync-codecs.ts\",\n \"dev\": \"tsup --watch\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@bokuweb/zstd-wasm\": \"0.0.27\",\n \"@gltf-transform/core\": \"4.4.2\",\n \"@gltf-transform/extensions\": \"4.4.2\",\n \"@gltf-transform/functions\": \"4.4.2\",\n \"@jsquash/avif\": \"2.1.1\",\n \"@jsquash/jpeg\": \"1.6.0\",\n \"@jsquash/png\": \"3.1.1\",\n \"@jsquash/resize\": \"2.1.1\",\n \"@jsquash/webp\": \"1.5.0\",\n \"draco3dgltf\": \"1.5.7\",\n \"jiti\": \"2.7.0\",\n \"ktx2-encoder\": \"0.6.0\",\n \"meshoptimizer\": \"1.0.1\",\n \"picomatch\": \"4.0.4\",\n \"tinyglobby\": \"0.2.17\"\n },\n \"devDependencies\": {\n \"@types/draco3dgltf\": \"1.4.3\",\n \"@types/picomatch\": \"4.0.3\",\n \"fzstd\": \"0.1.1\",\n \"ktx-parse\": \"1.0.1\"\n }\n}\n","import packageMetadata from '../../package.json'\n\nexport const CODEC_MANIFEST_HASH = '1a43d902a113a7dcfa7801bcbd90998e401898dbad555f913e1e7f4352d9c63c'\n\nexport const CODEC_ARTIFACTS = {\n zstdEncoder: {\n packageName: '@bokuweb/zstd-wasm',\n packageVersion: '0.0.27',\n packagePath: 'dist/common/zstd.wasm',\n publicFile: 'zstd.wasm',\n sha256: '80260eee5795ee8072bb5821e203730c74dca3909938f5ac1128da67f96223df',\n },\n avifEncoder: {\n packageName: '@jsquash/avif',\n packageVersion: '2.1.1',\n packagePath: 'codec/enc/avif_enc.wasm',\n publicFile: 'avif_enc.wasm',\n sha256: 'd9f2a95164362af48558d176e619becfd49dd97b50b86c679b47100860522b3d',\n },\n jpegDecoder: {\n packageName: '@jsquash/jpeg',\n packageVersion: '1.6.0',\n packagePath: 'codec/dec/mozjpeg_dec.wasm',\n publicFile: 'mozjpeg_dec.wasm',\n sha256: 'a7c4b12169817e779ff4af137981393ae924944e167ad1bd95747c9199162d3e',\n },\n jpegEncoder: {\n packageName: '@jsquash/jpeg',\n packageVersion: '1.6.0',\n packagePath: 'codec/enc/mozjpeg_enc.wasm',\n publicFile: 'mozjpeg_enc.wasm',\n sha256: '24d4177f1c4963e2058b107189249651c61fdef125570e79b1dfb63c8bb49326',\n },\n ktx2Encoder: {\n packageName: 'ktx2-encoder',\n packageVersion: '0.6.0',\n packagePath: 'dist/basis/basis_encoder.wasm',\n publicFile: 'basis_encoder.wasm',\n sha256: '9807719e87cf3d979b0d69ae7112eb88aec6a0e0206c0b2d00dc0bed0d581b80',\n },\n png: {\n packageName: '@jsquash/png',\n packageVersion: '3.1.1',\n packagePath: 'codec/pkg/squoosh_png_bg.wasm',\n publicFile: 'squoosh_png_bg.wasm',\n sha256: '263d6e658808a74b72a1a99c5cc1d619237e70c150db6e41d5d84d3d117ab9be',\n },\n resize: {\n packageName: '@jsquash/resize',\n packageVersion: '2.1.1',\n packagePath: 'lib/resize/pkg/squoosh_resize_bg.wasm',\n publicFile: 'squoosh_resize_bg.wasm',\n sha256: '5b1f702d502c4d0a70b99f78691bd554d566ba95859e4c57af5435955a1d74a5',\n },\n webpEncoder: {\n packageName: '@jsquash/webp',\n packageVersion: '1.5.0',\n packagePath: 'codec/enc/webp_enc.wasm',\n publicFile: 'webp_enc.wasm',\n sha256: 'b6085bb6702f144e9dc6016d58d230b34a84976bf0d080b7390b4b4b137d6ab7',\n },\n dracoDecoderScript: {\n packageName: 'draco3dgltf',\n packageVersion: '1.5.7',\n packagePath: 'draco_decoder_gltf_nodejs.js',\n publicFile: 'draco_decoder_gltf.js',\n sha256: '8bb2952d2ba7d67e1414f8df819410cb0434a666be53f671fff75f68843d76f6',\n },\n dracoDecoderWasm: {\n packageName: 'draco3dgltf',\n packageVersion: '1.5.7',\n packagePath: 'draco_decoder_gltf.wasm',\n publicFile: 'draco_decoder_gltf.wasm',\n sha256: '712db3449ae2041d6e8a224c395bda6cedb49e51322fae38b7db9beb8b381889',\n },\n dracoEncoderScript: {\n packageName: 'draco3dgltf',\n packageVersion: '1.5.7',\n packagePath: 'draco_encoder_gltf_nodejs.js',\n publicFile: 'draco_encoder_gltf.js',\n sha256: '8434adecd1446459601763e499be3697546056bca90b286a538ae0483a00845a',\n },\n dracoEncoderWasm: {\n packageName: 'draco3dgltf',\n packageVersion: '1.5.7',\n packagePath: 'draco_encoder.wasm',\n publicFile: 'draco_encoder.wasm',\n sha256: 'd2a3ac80c91980d5d321c116454834ff36264825c6d1794cc84e42288f158958',\n },\n} as const\n\nexport type CodecArtifactName = keyof typeof CODEC_ARTIFACTS\nexport type ImageWasmModuleName = Extract<\n CodecArtifactName,\n 'avifEncoder' | 'jpegDecoder' | 'jpegEncoder' | 'png' | 'resize' | 'webpEncoder' | 'zstdEncoder'\n>\n\nexport const CODEC_MANIFEST = {\n chopperVersion: packageMetadata.version,\n manifestHash: CODEC_MANIFEST_HASH,\n gltfTransformVersion: '4.4.2',\n meshoptimizerVersion: '1.0.1',\n artifacts: CODEC_ARTIFACTS,\n} as const\n\nexport const ENGINE_ID = `chopper@${packageMetadata.version}:${CODEC_MANIFEST_HASH}` as const\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CODEC_MANIFEST_HASH, CODEC_MANIFEST, ENGINE_ID, failure, success, CODEC_ARTIFACTS } from './chunk-
|
|
1
|
+
import { CODEC_MANIFEST_HASH, CODEC_MANIFEST, ENGINE_ID, failure, success, CODEC_ARTIFACTS } from './chunk-6PIXH7DA.js';
|
|
2
2
|
import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
3
3
|
|
|
4
4
|
// ../../node_modules/.pnpm/iota-array@1.0.0/node_modules/iota-array/iota.js
|
|
@@ -1398,6 +1398,123 @@ function latin1(bytes) {
|
|
|
1398
1398
|
return value;
|
|
1399
1399
|
}
|
|
1400
1400
|
|
|
1401
|
+
// src/codecs/raw-ktx2.ts
|
|
1402
|
+
var IDENTIFIER = new Uint8Array([171, 75, 84, 88, 32, 50, 48, 187, 13, 10, 26, 10]);
|
|
1403
|
+
var HEADER_SIZE = 104;
|
|
1404
|
+
var DFD_SIZE = 92;
|
|
1405
|
+
function rawSourceIssue(source) {
|
|
1406
|
+
if (source.mimeType !== "image/png" && source.mimeType !== "image/jpeg") {
|
|
1407
|
+
return failure(
|
|
1408
|
+
"unsupported_asset",
|
|
1409
|
+
"Raw KTX2 requires an 8-bit PNG or JPEG source; HDR/float sources are unsupported"
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
if (source.mimeType === "image/png" && source.bytes.length > 24 && source.bytes[24] === 16) {
|
|
1413
|
+
return failure("unsupported_asset", "Raw KTX2 does not support 16-bit PNG; author an RGBA8 source");
|
|
1414
|
+
}
|
|
1415
|
+
return void 0;
|
|
1416
|
+
}
|
|
1417
|
+
function rgbaDescriptor(srgb) {
|
|
1418
|
+
const bytes = new Uint8Array(DFD_SIZE);
|
|
1419
|
+
const view = new DataView(bytes.buffer);
|
|
1420
|
+
view.setUint32(0, DFD_SIZE, true);
|
|
1421
|
+
view.setUint16(8, 2, true);
|
|
1422
|
+
view.setUint16(10, DFD_SIZE - 4, true);
|
|
1423
|
+
bytes[12] = 1;
|
|
1424
|
+
bytes[13] = srgb ? 1 : 0;
|
|
1425
|
+
bytes[14] = srgb ? 2 : 1;
|
|
1426
|
+
bytes[20] = 4;
|
|
1427
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
1428
|
+
const offset = 28 + channel * 16;
|
|
1429
|
+
view.setUint16(offset, channel * 8, true);
|
|
1430
|
+
bytes[offset + 2] = 7;
|
|
1431
|
+
bytes[offset + 3] = channel === 3 ? 15 | (srgb ? 16 : 0) : channel;
|
|
1432
|
+
view.setUint32(offset + 12, 255, true);
|
|
1433
|
+
}
|
|
1434
|
+
return bytes;
|
|
1435
|
+
}
|
|
1436
|
+
function writeRawKtx2(width, height, payload, encoding) {
|
|
1437
|
+
const srgb = encoding.colorSpace === "srgb";
|
|
1438
|
+
const descriptor = rgbaDescriptor(srgb);
|
|
1439
|
+
const orientation = new TextEncoder().encode("KTXorientation\0rd\0");
|
|
1440
|
+
const kvdOffset = HEADER_SIZE + descriptor.length;
|
|
1441
|
+
const kvdLength = 4 + Math.ceil(orientation.length / 4) * 4;
|
|
1442
|
+
const levelOffset = kvdOffset + kvdLength;
|
|
1443
|
+
const bytes = new Uint8Array(levelOffset + payload.length);
|
|
1444
|
+
const view = new DataView(bytes.buffer);
|
|
1445
|
+
bytes.set(IDENTIFIER);
|
|
1446
|
+
[
|
|
1447
|
+
srgb ? 43 : 37,
|
|
1448
|
+
1,
|
|
1449
|
+
width,
|
|
1450
|
+
height,
|
|
1451
|
+
0,
|
|
1452
|
+
0,
|
|
1453
|
+
1,
|
|
1454
|
+
1,
|
|
1455
|
+
encoding.zstd === false ? 0 : 2,
|
|
1456
|
+
HEADER_SIZE,
|
|
1457
|
+
descriptor.length,
|
|
1458
|
+
kvdOffset,
|
|
1459
|
+
kvdLength
|
|
1460
|
+
].forEach((value, index) => {
|
|
1461
|
+
view.setUint32(12 + index * 4, value, true);
|
|
1462
|
+
});
|
|
1463
|
+
view.setBigUint64(80, BigInt(levelOffset), true);
|
|
1464
|
+
view.setBigUint64(88, BigInt(payload.length), true);
|
|
1465
|
+
view.setBigUint64(96, BigInt(width * height * 4), true);
|
|
1466
|
+
bytes.set(descriptor, HEADER_SIZE);
|
|
1467
|
+
view.setUint32(kvdOffset, orientation.length, true);
|
|
1468
|
+
bytes.set(orientation, kvdOffset + 4);
|
|
1469
|
+
bytes.set(payload, levelOffset);
|
|
1470
|
+
return bytes;
|
|
1471
|
+
}
|
|
1472
|
+
function validateRawKtx2(bytes, width, height, encoding) {
|
|
1473
|
+
if (bytes.length < HEADER_SIZE || !IDENTIFIER.every((byte, i) => bytes[i] === byte)) return false;
|
|
1474
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1475
|
+
const u32 = (offset) => view.getUint32(offset, true);
|
|
1476
|
+
const u64 = (offset) => Number(view.getBigUint64(offset, true));
|
|
1477
|
+
const expected = [
|
|
1478
|
+
encoding.colorSpace === "srgb" ? 43 : 37,
|
|
1479
|
+
1,
|
|
1480
|
+
width,
|
|
1481
|
+
height,
|
|
1482
|
+
0,
|
|
1483
|
+
0,
|
|
1484
|
+
1,
|
|
1485
|
+
1,
|
|
1486
|
+
encoding.zstd === false ? 0 : 2
|
|
1487
|
+
];
|
|
1488
|
+
if (!expected.every((value, i) => u32(12 + i * 4) === value)) return false;
|
|
1489
|
+
if (width < 1 || height < 1 || !Number.isSafeInteger(width * height * 4)) return false;
|
|
1490
|
+
if (u64(64) !== 0 || u64(72) !== 0 || u64(96) !== width * height * 4) return false;
|
|
1491
|
+
const dfdOffset = u32(48);
|
|
1492
|
+
const dfdLength = u32(52);
|
|
1493
|
+
const kvdOffset = u32(56);
|
|
1494
|
+
const kvdLength = u32(60);
|
|
1495
|
+
const levelOffset = u64(80);
|
|
1496
|
+
const levelLength = u64(88);
|
|
1497
|
+
if (dfdOffset < HEADER_SIZE || dfdOffset % 4 !== 0 || dfdLength !== DFD_SIZE || kvdOffset < dfdOffset + dfdLength || kvdOffset % 4 !== 0 || kvdLength % 4 !== 0 || levelOffset < kvdOffset + kvdLength || !Number.isSafeInteger(levelOffset) || !Number.isSafeInteger(levelLength) || levelLength < 1 || levelOffset + levelLength !== bytes.length)
|
|
1498
|
+
return false;
|
|
1499
|
+
if (encoding.zstd === false && (levelOffset % 4 !== 0 || levelLength !== width * height * 4)) return false;
|
|
1500
|
+
if (!rgbaDescriptor(encoding.colorSpace === "srgb").every((byte, i) => bytes[dfdOffset + i] === byte)) return false;
|
|
1501
|
+
let orientation;
|
|
1502
|
+
for (let offset = kvdOffset; offset < kvdOffset + kvdLength; ) {
|
|
1503
|
+
const length3 = u32(offset);
|
|
1504
|
+
const end = offset + 4 + length3;
|
|
1505
|
+
if (length3 < 2 || end > kvdOffset + kvdLength) return false;
|
|
1506
|
+
const entry = bytes.subarray(offset + 4, end);
|
|
1507
|
+
const separator = entry.indexOf(0);
|
|
1508
|
+
if (separator < 1) return false;
|
|
1509
|
+
if (new TextDecoder().decode(entry.subarray(0, separator)) === "KTXorientation") {
|
|
1510
|
+
if (orientation !== void 0) return false;
|
|
1511
|
+
orientation = new TextDecoder().decode(entry.subarray(separator + 1));
|
|
1512
|
+
}
|
|
1513
|
+
offset += 4 + Math.ceil(length3 / 4) * 4;
|
|
1514
|
+
}
|
|
1515
|
+
return orientation === "rd\0";
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1401
1518
|
// src/core/recipes.ts
|
|
1402
1519
|
function outputExtension(encoding) {
|
|
1403
1520
|
if (encoding.codec === "ktx2") return ".ktx2";
|
|
@@ -1495,6 +1612,9 @@ function recipeShapeIssue(recipe) {
|
|
|
1495
1612
|
if (!Array.isArray(selector[valueField])) return "Texture recipe selectors are malformed";
|
|
1496
1613
|
const encodingIssue2 = encodingShapeIssue(entry.encode);
|
|
1497
1614
|
if (encodingIssue2) return encodingIssue2;
|
|
1615
|
+
if (entry.encode.codec === "ktx2" && entry.encode.mode === "raw") {
|
|
1616
|
+
return `Texture recipe "${entry.label}" uses raw RGBA8, which KHR_texture_basisu does not cover; raw mode is only supported for standalone image recipes`;
|
|
1617
|
+
}
|
|
1498
1618
|
}
|
|
1499
1619
|
if (candidate.geometry !== void 0 && candidate.geometry !== false && (!candidate.geometry || typeof candidate.geometry !== "object" || !["draco", "meshopt"].includes(String(candidate.geometry.codec)))) {
|
|
1500
1620
|
return "GLB geometry must be false, Draco, or Meshopt";
|
|
@@ -1515,15 +1635,18 @@ function encodingShapeIssue(encoding) {
|
|
|
1515
1635
|
if (!["webp", "avif", "jpeg", "png", "ktx2"].includes(String(candidate.codec))) {
|
|
1516
1636
|
return `Unsupported image codec: ${String(candidate.codec)}`;
|
|
1517
1637
|
}
|
|
1518
|
-
if (candidate.codec === "ktx2" && candidate.mode !== "uastc" && candidate.mode !== "etc1s" && candidate.mode !== "uastc-hdr") {
|
|
1638
|
+
if (candidate.codec === "ktx2" && candidate.mode !== "uastc" && candidate.mode !== "etc1s" && candidate.mode !== "raw" && candidate.mode !== "uastc-hdr") {
|
|
1519
1639
|
return `Unsupported KTX2 mode: ${String(candidate.mode)}`;
|
|
1520
1640
|
}
|
|
1521
1641
|
if (candidate.codec === "ktx2" && candidate.mode === "uastc-hdr" && candidate.maxSize !== void 0) {
|
|
1522
1642
|
return "UASTC HDR does not support maxSize; resizing requires a decoded 8-bit image. Author the source at its target resolution.";
|
|
1523
1643
|
}
|
|
1524
|
-
const allowedFields = candidate.codec === "webp" ? ["codec", "maxSize", "quality", "effort", "lossless", "nearLossless"] : candidate.codec === "avif" ? ["codec", "maxSize", "quality", "effort", "lossless", "chromaSubsampling"] : candidate.codec === "jpeg" ? ["codec", "maxSize", "quality", "chromaSubsampling"] : candidate.codec === "png" ? ["codec", "maxSize"] : candidate.mode === "uastc" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "level", "mipmaps", "zstd", "rdo"] : candidate.mode === "etc1s" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "quality", "compression", "mipmaps"] : ["codec", "mode", "level", "mipmaps", "zstd"];
|
|
1644
|
+
const allowedFields = candidate.codec === "webp" ? ["codec", "maxSize", "quality", "effort", "lossless", "nearLossless"] : candidate.codec === "avif" ? ["codec", "maxSize", "quality", "effort", "lossless", "chromaSubsampling"] : candidate.codec === "jpeg" ? ["codec", "maxSize", "quality", "chromaSubsampling"] : candidate.codec === "png" ? ["codec", "maxSize"] : candidate.mode === "uastc" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "level", "mipmaps", "zstd", "rdo"] : candidate.mode === "etc1s" ? ["codec", "mode", "maxSize", "colorSpace", "normalMap", "quality", "compression", "mipmaps"] : candidate.mode === "raw" ? ["codec", "mode", "colorSpace", "mipmaps", "zstd", "zstdLevel"] : ["codec", "mode", "level", "mipmaps", "zstd"];
|
|
1525
1645
|
const unknownField = unknownFieldIssue(candidate, allowedFields, "image encoding");
|
|
1526
1646
|
if (unknownField) return unknownField;
|
|
1647
|
+
if (candidate.codec === "ktx2" && candidate.mode === "raw" && candidate.zstd === false && candidate.zstdLevel !== void 0) {
|
|
1648
|
+
return "Raw KTX2 zstdLevel requires Zstandard supercompression";
|
|
1649
|
+
}
|
|
1527
1650
|
if (candidate.codec === "ktx2" && candidate.mode === "uastc" && candidate.rdo !== void 0) {
|
|
1528
1651
|
if (!candidate.rdo || typeof candidate.rdo !== "object" || Array.isArray(candidate.rdo)) {
|
|
1529
1652
|
return "UASTC RDO must be an object";
|
|
@@ -1579,6 +1702,18 @@ function selectorValues(selector) {
|
|
|
1579
1702
|
return success(selector.indices);
|
|
1580
1703
|
}
|
|
1581
1704
|
function encodingIssue(encoding) {
|
|
1705
|
+
if (encoding.codec === "ktx2" && encoding.mode === "raw") {
|
|
1706
|
+
if (encoding.colorSpace !== void 0 && encoding.colorSpace !== "linear" && encoding.colorSpace !== "srgb") {
|
|
1707
|
+
return "Raw KTX2 colorSpace must be linear or srgb";
|
|
1708
|
+
}
|
|
1709
|
+
if (encoding.mipmaps !== void 0 && encoding.mipmaps !== false) return "Raw KTX2 mipmaps must be false";
|
|
1710
|
+
if (encoding.zstd !== void 0 && typeof encoding.zstd !== "boolean") return "Raw KTX2 zstd must be a boolean";
|
|
1711
|
+
if (encoding.zstdLevel !== void 0) {
|
|
1712
|
+
if (!Number.isInteger(encoding.zstdLevel) || encoding.zstdLevel < 1 || encoding.zstdLevel > 19) {
|
|
1713
|
+
return "Raw KTX2 zstdLevel must be an integer between 1 and 19";
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1582
1717
|
if ("maxSize" in encoding && encoding.maxSize) {
|
|
1583
1718
|
const [width, height] = encoding.maxSize;
|
|
1584
1719
|
if (!Number.isInteger(width) || width < 1 || !Number.isInteger(height) || height < 1) {
|
|
@@ -1643,6 +1778,15 @@ function normalizeEncoding(encoding) {
|
|
|
1643
1778
|
case "png":
|
|
1644
1779
|
return { ...encoding };
|
|
1645
1780
|
case "ktx2":
|
|
1781
|
+
if (encoding.mode === "raw") {
|
|
1782
|
+
return {
|
|
1783
|
+
codec: "ktx2",
|
|
1784
|
+
mode: "raw",
|
|
1785
|
+
colorSpace: encoding.colorSpace ?? "linear",
|
|
1786
|
+
mipmaps: false,
|
|
1787
|
+
...encoding.zstd === false ? { zstd: false } : { zstd: true, zstdLevel: encoding.zstdLevel ?? 19 }
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1646
1790
|
if (encoding.mode === "uastc-hdr") {
|
|
1647
1791
|
return {
|
|
1648
1792
|
...encoding,
|
|
@@ -1731,6 +1875,11 @@ function createChopper(runtime) {
|
|
|
1731
1875
|
if (kind.data !== "image" || recipe.kind !== "image") {
|
|
1732
1876
|
return failure("invalid_recipe", "Recipe and input type do not match");
|
|
1733
1877
|
}
|
|
1878
|
+
const rawEncoding = recipe.encode.codec === "ktx2" && recipe.encode.mode === "raw" ? recipe.encode : void 0;
|
|
1879
|
+
if (rawEncoding) {
|
|
1880
|
+
const issue = rawSourceIssue({ bytes: input.bytes, mimeType: imageMimeType(input) });
|
|
1881
|
+
if (issue) return issue;
|
|
1882
|
+
}
|
|
1734
1883
|
const inspection = await inspectImage(input, imageMimeType(input), runtime.image);
|
|
1735
1884
|
if (!inspection.ok) return inspection;
|
|
1736
1885
|
const encoded = await runtime.image.encode(
|
|
@@ -1743,6 +1892,12 @@ function createChopper(runtime) {
|
|
|
1743
1892
|
if (!hasExpectedSignature(encoded.data.bytes, encoded.data.mimeType)) {
|
|
1744
1893
|
return failure("validation_failed", `Encoded bytes do not match ${encoded.data.mimeType}`);
|
|
1745
1894
|
}
|
|
1895
|
+
if (rawEncoding && (encoded.data.mimeType !== "image/ktx2" || !validateRawKtx2(encoded.data.bytes, inspection.data.width, inspection.data.height, rawEncoding))) {
|
|
1896
|
+
return failure(
|
|
1897
|
+
"validation_failed",
|
|
1898
|
+
"Raw KTX2 output does not match the source dimensions or RGBA8 container contract"
|
|
1899
|
+
);
|
|
1900
|
+
}
|
|
1746
1901
|
const report = createReport({
|
|
1747
1902
|
recipe: normalized.data,
|
|
1748
1903
|
beforeBytes: input.bytes.byteLength,
|
|
@@ -26613,6 +26768,55 @@ function encodeToKTX2(imageBuffer, options = {}) {
|
|
|
26613
26768
|
return browserEncoder.encode(imageBuffer, options);
|
|
26614
26769
|
}
|
|
26615
26770
|
|
|
26771
|
+
// src/codecs/zstd.ts
|
|
26772
|
+
async function createZstdEncoder(module) {
|
|
26773
|
+
let memory;
|
|
26774
|
+
const abort = () => {
|
|
26775
|
+
throw new Error("Zstandard WASM aborted");
|
|
26776
|
+
};
|
|
26777
|
+
const instance = await WebAssembly.instantiate(module, {
|
|
26778
|
+
a: {
|
|
26779
|
+
a: abort,
|
|
26780
|
+
// proc_exit
|
|
26781
|
+
b: () => {
|
|
26782
|
+
},
|
|
26783
|
+
// emscripten_runtime_keepalive_clear
|
|
26784
|
+
c: abort,
|
|
26785
|
+
// abort_js
|
|
26786
|
+
d: abort,
|
|
26787
|
+
// setitimer_js (unused by the synchronous compressor)
|
|
26788
|
+
e: (requestedSize) => {
|
|
26789
|
+
try {
|
|
26790
|
+
memory.grow(Math.ceil((requestedSize - memory.buffer.byteLength) / 65536));
|
|
26791
|
+
return 1;
|
|
26792
|
+
} catch {
|
|
26793
|
+
return 0;
|
|
26794
|
+
}
|
|
26795
|
+
}
|
|
26796
|
+
}
|
|
26797
|
+
});
|
|
26798
|
+
const api = instance.exports;
|
|
26799
|
+
memory = api.f;
|
|
26800
|
+
api.g();
|
|
26801
|
+
return (data, level) => {
|
|
26802
|
+
let source = 0;
|
|
26803
|
+
let destination = 0;
|
|
26804
|
+
try {
|
|
26805
|
+
const capacity = api.i(data.length);
|
|
26806
|
+
source = api.s(data.length);
|
|
26807
|
+
destination = api.s(capacity);
|
|
26808
|
+
if (!source || !destination) throw new Error("Could not allocate Zstandard buffers");
|
|
26809
|
+
new Uint8Array(memory.buffer, source, data.length).set(data);
|
|
26810
|
+
const size = api.m(destination, capacity, source, data.length, level);
|
|
26811
|
+
if (api.h(size)) throw new Error(`Zstandard compression failed: ${size}`);
|
|
26812
|
+
return new Uint8Array(memory.buffer, destination, size).slice();
|
|
26813
|
+
} finally {
|
|
26814
|
+
if (source) api.t(source);
|
|
26815
|
+
if (destination) api.t(destination);
|
|
26816
|
+
}
|
|
26817
|
+
};
|
|
26818
|
+
}
|
|
26819
|
+
|
|
26616
26820
|
// src/codecs/image-engine.ts
|
|
26617
26821
|
var CodecLoadError = class extends Error {
|
|
26618
26822
|
};
|
|
@@ -26628,12 +26832,11 @@ function createWasmImageEngine(loader) {
|
|
|
26628
26832
|
id: ENGINE_ID,
|
|
26629
26833
|
manifestHash: CODEC_MANIFEST_HASH,
|
|
26630
26834
|
async inspect(source) {
|
|
26631
|
-
if (isHdrSourceMimeType(source.mimeType)) {
|
|
26632
|
-
const header = readHdrSource(source.bytes);
|
|
26633
|
-
if ("error" in header) return failure("decode_failed", header.error);
|
|
26634
|
-
return success({ width: header.width, height: header.height });
|
|
26635
|
-
}
|
|
26636
26835
|
try {
|
|
26836
|
+
if (isHdrSourceMimeType(source.mimeType)) {
|
|
26837
|
+
const header = readSupportedHdrSource(source.bytes);
|
|
26838
|
+
return success({ width: header.width, height: header.height });
|
|
26839
|
+
}
|
|
26637
26840
|
const image = await decodeSource(source, adapters);
|
|
26638
26841
|
return success({ width: image.width, height: image.height });
|
|
26639
26842
|
} catch (cause) {
|
|
@@ -26643,6 +26846,10 @@ function createWasmImageEngine(loader) {
|
|
|
26643
26846
|
async encode(source, encoding, signal) {
|
|
26644
26847
|
const valid = validateRecipe({ kind: "image", encode: encoding });
|
|
26645
26848
|
if (!valid.ok) return valid;
|
|
26849
|
+
if (encoding.codec === "ktx2" && encoding.mode === "raw") {
|
|
26850
|
+
const issue = rawSourceIssue(source);
|
|
26851
|
+
if (issue) return issue;
|
|
26852
|
+
}
|
|
26646
26853
|
const mismatch = sourcePairingIssue(source, encoding);
|
|
26647
26854
|
if (mismatch) return mismatch;
|
|
26648
26855
|
try {
|
|
@@ -26652,8 +26859,30 @@ function createWasmImageEngine(loader) {
|
|
|
26652
26859
|
assertNotAborted2(signal);
|
|
26653
26860
|
return success(encoded2);
|
|
26654
26861
|
}
|
|
26655
|
-
let image
|
|
26862
|
+
let image;
|
|
26863
|
+
try {
|
|
26864
|
+
image = await decodeSource(source, adapters);
|
|
26865
|
+
} catch (cause) {
|
|
26866
|
+
if (encoding.codec === "ktx2" && encoding.mode === "raw") {
|
|
26867
|
+
return operationFailure("decode_failed", "Could not decode image", cause);
|
|
26868
|
+
}
|
|
26869
|
+
throw cause;
|
|
26870
|
+
}
|
|
26656
26871
|
assertNotAborted2(signal);
|
|
26872
|
+
if (encoding.codec === "ktx2" && encoding.mode === "raw") {
|
|
26873
|
+
const rgba = new Uint8Array(image.data.buffer, image.data.byteOffset, image.data.byteLength);
|
|
26874
|
+
if (rgba.length !== image.width * image.height * 4) throw new Error("Decoder did not return RGBA8 pixels");
|
|
26875
|
+
const compress = encoding.zstd === false ? void 0 : await adapters.zstd();
|
|
26876
|
+
assertNotAborted2(signal);
|
|
26877
|
+
const payload = compress ? compress(rgba, encoding.zstdLevel ?? 19) : rgba;
|
|
26878
|
+
assertNotAborted2(signal);
|
|
26879
|
+
return success({
|
|
26880
|
+
bytes: writeRawKtx2(image.width, image.height, payload, encoding),
|
|
26881
|
+
mimeType: outputMimeType(encoding),
|
|
26882
|
+
width: image.width,
|
|
26883
|
+
height: image.height
|
|
26884
|
+
});
|
|
26885
|
+
}
|
|
26657
26886
|
if (encoding.maxSize) {
|
|
26658
26887
|
image = await resizeWithin(image, encoding.maxSize, adapters);
|
|
26659
26888
|
}
|
|
@@ -26681,6 +26910,7 @@ function createAdapterCache(loader) {
|
|
|
26681
26910
|
let png;
|
|
26682
26911
|
let resizeModule;
|
|
26683
26912
|
let webp;
|
|
26913
|
+
let zstd;
|
|
26684
26914
|
const load2 = async (name) => {
|
|
26685
26915
|
try {
|
|
26686
26916
|
return await loader.load(name);
|
|
@@ -26689,6 +26919,9 @@ function createAdapterCache(loader) {
|
|
|
26689
26919
|
}
|
|
26690
26920
|
};
|
|
26691
26921
|
return {
|
|
26922
|
+
zstd: () => zstd ??= load2("zstdEncoder").then(createZstdEncoder).catch((cause) => {
|
|
26923
|
+
throw new CodecLoadError("Could not initialize zstdEncoder", { cause });
|
|
26924
|
+
}),
|
|
26692
26925
|
avif: () => avif ??= load2("avifEncoder").then(
|
|
26693
26926
|
(module) => initEmscriptenModule(avif_enc_default, module)
|
|
26694
26927
|
),
|
|
@@ -26823,16 +27056,20 @@ function sourcePairingIssue(source, encoding) {
|
|
|
26823
27056
|
}
|
|
26824
27057
|
return void 0;
|
|
26825
27058
|
}
|
|
26826
|
-
|
|
26827
|
-
const header = readHdrSource(
|
|
27059
|
+
function readSupportedHdrSource(bytes) {
|
|
27060
|
+
const header = readHdrSource(bytes);
|
|
26828
27061
|
if ("error" in header) throw new SourceError("decode_failed", header.error);
|
|
26829
27062
|
const texels = header.width * header.height;
|
|
26830
27063
|
if (texels > MAX_HDR_SOURCE_TEXELS) {
|
|
26831
27064
|
throw new SourceError(
|
|
26832
27065
|
"unsupported_asset",
|
|
26833
|
-
`Source is ${header.width}x${header.height} (${megapixels(texels)} Mpix), over the ${megapixels(MAX_HDR_SOURCE_TEXELS)} Mpix HDR
|
|
27066
|
+
`Source is ${header.width}x${header.height} (${megapixels(texels)} Mpix), over the ${megapixels(MAX_HDR_SOURCE_TEXELS)} Mpix HDR source limit. Reduce the total pixel count (3072x3072 and 4096x3072 both fit) or split the source into tiles.`
|
|
26834
27067
|
);
|
|
26835
27068
|
}
|
|
27069
|
+
return header;
|
|
27070
|
+
}
|
|
27071
|
+
async function encodeKtx2Hdr(source, encoding, wasmUrl) {
|
|
27072
|
+
const header = readSupportedHdrSource(source.bytes);
|
|
26836
27073
|
const bytes = await encodeToKTX2(source.bytes, {
|
|
26837
27074
|
isHDR: true,
|
|
26838
27075
|
imageType: header.container,
|
|
@@ -26982,5 +27219,5 @@ is-buffer/index.js:
|
|
|
26982
27219
|
*/
|
|
26983
27220
|
|
|
26984
27221
|
export { createInProcessChopper };
|
|
26985
|
-
//# sourceMappingURL=in-process-
|
|
26986
|
-
//# sourceMappingURL=in-process-
|
|
27222
|
+
//# sourceMappingURL=in-process-FAMTTLSK.js.map
|
|
27223
|
+
//# sourceMappingURL=in-process-FAMTTLSK.js.map
|