@forgeax/engine-image 0.1.2
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/LICENSE +202 -0
- package/README.md +168 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/__tests__/compression-mode.unit.test.d.ts +2 -0
- package/dist/__tests__/compression-mode.unit.test.d.ts.map +1 -0
- package/dist/__tests__/encode-source-too-large.unit.test.d.ts +2 -0
- package/dist/__tests__/encode-source-too-large.unit.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test-d.d.ts +2 -0
- package/dist/__tests__/errors.test-d.d.ts.map +1 -0
- package/dist/__tests__/image-importer-conversion-failure.unit.test.d.ts +2 -0
- package/dist/__tests__/image-importer-conversion-failure.unit.test.d.ts.map +1 -0
- package/dist/__tests__/image-importer-hdr-equirect.test.d.ts +2 -0
- package/dist/__tests__/image-importer-hdr-equirect.test.d.ts.map +1 -0
- package/dist/__tests__/image-importer-topology.unit.test.d.ts +2 -0
- package/dist/__tests__/image-importer-topology.unit.test.d.ts.map +1 -0
- package/dist/__tests__/image-importer.test.d.ts +2 -0
- package/dist/__tests__/image-importer.test.d.ts.map +1 -0
- package/dist/__tests__/image-local-artifacts.test.d.ts +2 -0
- package/dist/__tests__/image-local-artifacts.test.d.ts.map +1 -0
- package/dist/__tests__/image.unit.test.d.ts +2 -0
- package/dist/__tests__/image.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-basis-importer.unit.test.d.ts +2 -0
- package/dist/__tests__/ktx2-basis-importer.unit.test.d.ts.map +1 -0
- package/dist/__tests__/ktx2-encode-mode-owner.test-d.d.ts +2 -0
- package/dist/__tests__/ktx2-encode-mode-owner.test-d.d.ts.map +1 -0
- package/dist/__tests__/make-fixture.d.ts +12 -0
- package/dist/__tests__/make-fixture.d.ts.map +1 -0
- package/dist/__tests__/parse-image-downscale.test.d.ts +2 -0
- package/dist/__tests__/parse-image-downscale.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-decode.unit.test.d.ts +2 -0
- package/dist/__tests__/runtime-decode.unit.test.d.ts.map +1 -0
- package/dist/__tests__/source-key.unit.test.d.ts +2 -0
- package/dist/__tests__/source-key.unit.test.d.ts.map +1 -0
- package/dist/__tests__/tga.unit.test.d.ts +2 -0
- package/dist/__tests__/tga.unit.test.d.ts.map +1 -0
- package/dist/decode-image-from-file.d.ts +40 -0
- package/dist/decode-image-from-file.d.ts.map +1 -0
- package/dist/decode-image-from-file.mjs +590 -0
- package/dist/decode-image-from-file.mjs.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/hdr-decoder.d.ts +28 -0
- package/dist/hdr-decoder.d.ts.map +1 -0
- package/dist/hdr-decoder.mjs +212 -0
- package/dist/hdr-decoder.mjs.map +1 -0
- package/dist/image-decoder-browser.d.ts +22 -0
- package/dist/image-decoder-browser.d.ts.map +1 -0
- package/dist/image-decoder-node.d.ts +50 -0
- package/dist/image-decoder-node.d.ts.map +1 -0
- package/dist/image-importer.d.ts +15 -0
- package/dist/image-importer.d.ts.map +1 -0
- package/dist/image-importer.mjs +1107 -0
- package/dist/image-importer.mjs.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +503 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ktx2-encode.d.ts +84 -0
- package/dist/ktx2-encode.d.ts.map +1 -0
- package/dist/ktx2-encode.mjs +100 -0
- package/dist/ktx2-encode.mjs.map +1 -0
- package/dist/parse-image.d.ts +48 -0
- package/dist/parse-image.d.ts.map +1 -0
- package/dist/parse-image.mjs +231 -0
- package/dist/parse-image.mjs.map +1 -0
- package/dist/reimport-reuse-meta.d.ts +81 -0
- package/dist/reimport-reuse-meta.d.ts.map +1 -0
- package/dist/resize-image.d.ts +7 -0
- package/dist/resize-image.d.ts.map +1 -0
- package/dist/result.d.ts +2 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/runtime/__tests__/asset-decoders.unit.test.d.ts +2 -0
- package/dist/runtime/__tests__/asset-decoders.unit.test.d.ts.map +1 -0
- package/dist/runtime/asset-decoders.d.ts +4 -0
- package/dist/runtime/asset-decoders.d.ts.map +1 -0
- package/dist/runtime/decode-image-bytes.d.ts +7 -0
- package/dist/runtime/decode-image-bytes.d.ts.map +1 -0
- package/dist/runtime/image-error.d.ts +3 -0
- package/dist/runtime/image-error.d.ts.map +1 -0
- package/dist/source-key.d.ts +21 -0
- package/dist/source-key.d.ts.map +1 -0
- package/dist/sub-asset-key.d.ts +50 -0
- package/dist/sub-asset-key.d.ts.map +1 -0
- package/dist/to-asset-pack.d.ts +61 -0
- package/dist/to-asset-pack.d.ts.map +1 -0
- package/package.json +105 -0
- package/src/__tests__/compression-mode.unit.test.ts +104 -0
- package/src/__tests__/encode-source-too-large.unit.test.ts +81 -0
- package/src/__tests__/errors.test-d.ts +148 -0
- package/src/__tests__/image-importer-conversion-failure.unit.test.ts +297 -0
- package/src/__tests__/image-importer-hdr-equirect.test.ts +218 -0
- package/src/__tests__/image-importer-topology.unit.test.ts +209 -0
- package/src/__tests__/image-importer.test.ts +12 -0
- package/src/__tests__/image-local-artifacts.test.ts +38 -0
- package/src/__tests__/image.unit.test.ts +1387 -0
- package/src/__tests__/ktx2-basis-importer.unit.test.ts +126 -0
- package/src/__tests__/ktx2-encode-mode-owner.test-d.ts +70 -0
- package/src/__tests__/make-fixture.ts +100 -0
- package/src/__tests__/parse-image-downscale.test.ts +26 -0
- package/src/__tests__/runtime-decode.unit.test.ts +22 -0
- package/src/__tests__/source-key.unit.test.ts +65 -0
- package/src/__tests__/tga.unit.test.ts +59 -0
- package/src/decode-image-from-file.ts +298 -0
- package/src/errors.ts +60 -0
- package/src/hdr-decoder.ts +255 -0
- package/src/image-decoder-browser.ts +88 -0
- package/src/image-decoder-node.ts +67 -0
- package/src/image-decoders.d.ts +23 -0
- package/src/image-importer.ts +780 -0
- package/src/index.ts +46 -0
- package/src/ktx2-encode.ts +221 -0
- package/src/parse-image.ts +276 -0
- package/src/reimport-reuse-meta.ts +160 -0
- package/src/resize-image.ts +39 -0
- package/src/result.ts +13 -0
- package/src/runtime/__tests__/asset-decoders.unit.test.ts +66 -0
- package/src/runtime/asset-decoders.ts +152 -0
- package/src/runtime/decode-image-bytes.ts +41 -0
- package/src/runtime/image-error.ts +8 -0
- package/src/source-key.ts +41 -0
- package/src/sub-asset-key.ts +67 -0
- package/src/to-asset-pack.ts +95 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, extname, join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { validateMeta } from '@forgeax/engine-pack';
|
|
5
|
+
import type { DecodedImage, ImageError, ImageMeta } from '@forgeax/engine-types';
|
|
6
|
+
import { imageError } from './errors.js';
|
|
7
|
+
import { decodeHdr, type HdrDecoded } from './hdr-decoder.js';
|
|
8
|
+
import { parseImage } from './parse-image.js';
|
|
9
|
+
import type { Result } from './result.js';
|
|
10
|
+
import { err, ok } from './result.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sidecar JSON shape consumed by decodeImageFromFile. The schema is the
|
|
14
|
+
* external-asset-package $defs from `packages/pack/schema/meta.schema.json`
|
|
15
|
+
* (research F-9). Only the fields required by the Node-side decoder are
|
|
16
|
+
* enumerated here; importSettings remains free-form per plan-strategy R5.
|
|
17
|
+
*/
|
|
18
|
+
interface SidecarMeta {
|
|
19
|
+
readonly schemaVersion: string;
|
|
20
|
+
readonly kind: 'external-asset-package';
|
|
21
|
+
readonly importer: 'image';
|
|
22
|
+
readonly source: string;
|
|
23
|
+
readonly importSettings: Partial<{
|
|
24
|
+
colorSpace: ImageMeta['colorSpace'];
|
|
25
|
+
mipmap: ImageMeta['mipmap'];
|
|
26
|
+
addressMode: ImageMeta['addressMode'];
|
|
27
|
+
filterMode: ImageMeta['filterMode'];
|
|
28
|
+
}>;
|
|
29
|
+
readonly subAssets: ReadonlyArray<{
|
|
30
|
+
readonly guid: string;
|
|
31
|
+
readonly sourceIndex: number;
|
|
32
|
+
readonly kind: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Result envelope returned by decodeImageFromFile for PNG/JPG sources.
|
|
38
|
+
* Carries both the raw DecodedImage POD (for direct uploadTexture consumption)
|
|
39
|
+
* and the parsed ImageMeta POD.
|
|
40
|
+
*/
|
|
41
|
+
export interface DecodedImageWithMeta {
|
|
42
|
+
readonly decoded: DecodedImage;
|
|
43
|
+
readonly meta: ImageMeta;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Result envelope returned by decodeImageFromFile for .hdr sources.
|
|
48
|
+
* Carries the HDR-decoded float data ready for cubemap upload.
|
|
49
|
+
*/
|
|
50
|
+
export interface DecodedHdrWithMeta {
|
|
51
|
+
readonly hdr: HdrDecoded;
|
|
52
|
+
readonly meta: ImageMeta;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const EXT_TO_MIME: Readonly<
|
|
56
|
+
Record<string, 'image/png' | 'image/jpeg' | 'image/x-tga' | 'image/vnd.radiance'>
|
|
57
|
+
> = {
|
|
58
|
+
'.png': 'image/png',
|
|
59
|
+
'.jpg': 'image/jpeg',
|
|
60
|
+
'.jpeg': 'image/jpeg',
|
|
61
|
+
'.tga': 'image/x-tga',
|
|
62
|
+
'.hdr': 'image/vnd.radiance',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function deriveSidecarPath(sourcePath: string): string {
|
|
66
|
+
const dir = dirname(sourcePath);
|
|
67
|
+
// sidecar lives next to source as <source-with-ext>.meta.json
|
|
68
|
+
// (feat-20260521 unify-sidecar-meta-dispatch-by-content; the importer field
|
|
69
|
+
// in the JSON drives importer dispatch instead of filename suffix).
|
|
70
|
+
const base = sourcePath.slice(dir.length + 1);
|
|
71
|
+
return join(dir, `${base}.meta.json`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function sidecarSchemaFailureReason(): string {
|
|
75
|
+
const firstError = validateMeta.errors?.[0];
|
|
76
|
+
if (firstError === undefined) return 'sidecar schema validation failed';
|
|
77
|
+
const location = firstError.instancePath === '' ? '/' : firstError.instancePath;
|
|
78
|
+
return `sidecar schema validation failed: ${firstError.keyword} at ${location}`.slice(0, 256);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function imageSidecarFailureReason(
|
|
82
|
+
sidecar: SidecarMeta,
|
|
83
|
+
mime: (typeof EXT_TO_MIME)[keyof typeof EXT_TO_MIME],
|
|
84
|
+
): string | undefined {
|
|
85
|
+
const subAsset = sidecar.subAssets[0];
|
|
86
|
+
const settings = sidecar.importSettings;
|
|
87
|
+
const expectedKind = mime === 'image/vnd.radiance' ? 'equirect' : 'texture';
|
|
88
|
+
if (sidecar.importer !== 'image') return 'image sidecar importer must be image';
|
|
89
|
+
if (sidecar.subAssets.length !== 1 || subAsset === undefined) {
|
|
90
|
+
return 'image sidecar must declare one sub-asset';
|
|
91
|
+
}
|
|
92
|
+
if (subAsset.kind !== expectedKind || subAsset.sourceIndex !== 0) {
|
|
93
|
+
return `image sidecar sub-asset must be ${expectedKind} at sourceIndex 0`;
|
|
94
|
+
}
|
|
95
|
+
if (settings.colorSpace !== undefined && !['srgb', 'linear'].includes(settings.colorSpace)) {
|
|
96
|
+
return 'image sidecar colorSpace must be srgb or linear';
|
|
97
|
+
}
|
|
98
|
+
if (settings.mipmap !== undefined && !['auto', 'none'].includes(settings.mipmap)) {
|
|
99
|
+
return 'image sidecar mipmap must be auto or none';
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
settings.addressMode !== undefined &&
|
|
103
|
+
!['repeat', 'clamp-to-edge', 'mirror-repeat'].includes(settings.addressMode)
|
|
104
|
+
) {
|
|
105
|
+
return 'image sidecar addressMode is unsupported';
|
|
106
|
+
}
|
|
107
|
+
if (settings.filterMode !== undefined && !['nearest', 'linear'].includes(settings.filterMode)) {
|
|
108
|
+
return 'image sidecar filterMode is unsupported';
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Async file-system entry to the image importer (plan-strategy section 3.2
|
|
115
|
+
* sequence A; AC-17 path (a) sidecar three-way fallback).
|
|
116
|
+
*
|
|
117
|
+
* Behaviour (left-to-right, fail-fast on first surfaced ImageError):
|
|
118
|
+
* 1. Sniff extension -- not in `.png / .jpg / .jpeg` -> image-format-unsupported
|
|
119
|
+
* 2. Stat source -- absent -> image-decode-failed with the source path
|
|
120
|
+
* 3. Stat sibling `<source>.meta.json` (importer: 'image') -- absent -> image-meta-missing
|
|
121
|
+
* 4. Read source bytes + parse sidecar JSON
|
|
122
|
+
* 5. Hand off to `parseImage(bytes, mime, opts)` -- surfaces image-decode-failed
|
|
123
|
+
* / image-format-unsupported / image-dimension-out-of-bounds
|
|
124
|
+
* 6. Compose DecodedImage POD + ImageMeta POD return envelope.
|
|
125
|
+
*
|
|
126
|
+
* AC-17 path (a) lock: when the sidecar is absent, the returned error
|
|
127
|
+
* carries `detail.sourcePath` + `detail.expectedSidecarPath` so AI users
|
|
128
|
+
* read .hint and run `forgeax-engine-remote-asset import <path>` to
|
|
129
|
+
* self-recover (charter P3 explicit failure + IDE jump-to-source).
|
|
130
|
+
*/
|
|
131
|
+
export async function decodeImageFromFile(
|
|
132
|
+
sourcePath: string,
|
|
133
|
+
): Promise<Result<DecodedImageWithMeta, ImageError>> {
|
|
134
|
+
const ext = extname(sourcePath).toLowerCase();
|
|
135
|
+
const mime = EXT_TO_MIME[ext];
|
|
136
|
+
if (mime === undefined) {
|
|
137
|
+
return err(
|
|
138
|
+
imageError({
|
|
139
|
+
code: 'image-format-unsupported',
|
|
140
|
+
actualMime: `extension '${ext || '<none>'}'`,
|
|
141
|
+
path: sourcePath,
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const sidecarPath = deriveSidecarPath(sourcePath);
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
await stat(sourcePath);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return err(
|
|
152
|
+
imageError({
|
|
153
|
+
code: 'image-decode-failed',
|
|
154
|
+
reason: `failed to read source: ${e instanceof Error ? e.message : String(e)}`,
|
|
155
|
+
path: sourcePath,
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await stat(sidecarPath);
|
|
162
|
+
} catch {
|
|
163
|
+
return err(
|
|
164
|
+
imageError({
|
|
165
|
+
code: 'image-meta-missing',
|
|
166
|
+
sourcePath,
|
|
167
|
+
expectedSidecarPath: sidecarPath,
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let sidecarText: string;
|
|
173
|
+
try {
|
|
174
|
+
sidecarText = (await readFile(sidecarPath)).toString('utf8');
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return err(
|
|
177
|
+
imageError({
|
|
178
|
+
code: 'image-decode-failed',
|
|
179
|
+
reason: `failed to read sidecar: ${e instanceof Error ? e.message : String(e)}`,
|
|
180
|
+
path: sidecarPath,
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let parsedSidecar: unknown;
|
|
186
|
+
try {
|
|
187
|
+
parsedSidecar = JSON.parse(sidecarText) as unknown;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return err(
|
|
190
|
+
imageError({
|
|
191
|
+
code: 'image-decode-failed',
|
|
192
|
+
reason: `sidecar JSON parse failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
193
|
+
path: sidecarPath,
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!validateMeta(parsedSidecar)) {
|
|
199
|
+
return err(
|
|
200
|
+
imageError({
|
|
201
|
+
code: 'image-decode-failed',
|
|
202
|
+
reason: sidecarSchemaFailureReason(),
|
|
203
|
+
path: sidecarPath,
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const sidecar = parsedSidecar as unknown as SidecarMeta;
|
|
209
|
+
const imageSidecarFailure = imageSidecarFailureReason(sidecar, mime);
|
|
210
|
+
if (imageSidecarFailure !== undefined) {
|
|
211
|
+
return err(
|
|
212
|
+
imageError({
|
|
213
|
+
code: 'image-decode-failed',
|
|
214
|
+
reason: imageSidecarFailure,
|
|
215
|
+
path: sidecarPath,
|
|
216
|
+
}),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const settings = sidecar.importSettings ?? {};
|
|
221
|
+
const colorSpace: ImageMeta['colorSpace'] = settings.colorSpace ?? 'srgb';
|
|
222
|
+
const mipmap: ImageMeta['mipmap'] = settings.mipmap ?? 'auto';
|
|
223
|
+
const addressMode: ImageMeta['addressMode'] = settings.addressMode ?? 'repeat';
|
|
224
|
+
const filterMode: ImageMeta['filterMode'] = settings.filterMode ?? 'linear';
|
|
225
|
+
const guid = sidecar.subAssets[0]?.guid ?? '';
|
|
226
|
+
|
|
227
|
+
const meta: ImageMeta = {
|
|
228
|
+
guid,
|
|
229
|
+
colorSpace,
|
|
230
|
+
mipmap,
|
|
231
|
+
addressMode,
|
|
232
|
+
filterMode,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
let bytes: Uint8Array;
|
|
236
|
+
try {
|
|
237
|
+
const buf = await readFile(sourcePath);
|
|
238
|
+
bytes = new Uint8Array(buf);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
return err(
|
|
241
|
+
imageError({
|
|
242
|
+
code: 'image-decode-failed',
|
|
243
|
+
reason: `failed to read source: ${e instanceof Error ? e.message : String(e)}`,
|
|
244
|
+
path: sourcePath,
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// .hdr path: delegate to HDR decoder, enforce linear color space
|
|
250
|
+
if (mime === 'image/vnd.radiance') {
|
|
251
|
+
if (colorSpace !== 'linear') {
|
|
252
|
+
return err(
|
|
253
|
+
imageError({
|
|
254
|
+
code: 'image-format-unsupported',
|
|
255
|
+
actualMime: `colorSpace conflict: HDR requires linear, got ${colorSpace}`,
|
|
256
|
+
path: sourcePath,
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
const hdrRes = decodeHdr(bytes);
|
|
261
|
+
if (!hdrRes.ok) return err(hdrRes.error);
|
|
262
|
+
// DecodedImageWithMeta expects DecodedImage; for HDR we return the HDR
|
|
263
|
+
// variant through a separate export path. Downstream consumers
|
|
264
|
+
// distinguish by file extension.
|
|
265
|
+
// For the DecodedImageWithMeta return type compatibility, we synthesise
|
|
266
|
+
// a minimal DecodedImage POD carrying the byte representation.
|
|
267
|
+
// This keeps the return type stable for existing PNG/JPG callers.
|
|
268
|
+
// The HDR data is available through the separate decodeHdr export.
|
|
269
|
+
const rgba8 = new Uint8Array(hdrRes.value.width * hdrRes.value.height * 4);
|
|
270
|
+
// convert float to quantised 8-bit for the POD shape (lossy; consumers
|
|
271
|
+
// should use decodeHdr directly for float precision)
|
|
272
|
+
for (let i = 0; i < hdrRes.value.data.length; i++) {
|
|
273
|
+
const v = hdrRes.value.data[i];
|
|
274
|
+
const clamped = v !== undefined ? Math.max(0, Math.min(1, v as number)) : 0;
|
|
275
|
+
rgba8[i] = Math.round(clamped * 255);
|
|
276
|
+
}
|
|
277
|
+
const decoded: DecodedImage = {
|
|
278
|
+
bytes: rgba8,
|
|
279
|
+
width: hdrRes.value.width,
|
|
280
|
+
height: hdrRes.value.height,
|
|
281
|
+
mime: 'image/jpeg',
|
|
282
|
+
colorSpace: 'linear',
|
|
283
|
+
mipmap: false,
|
|
284
|
+
};
|
|
285
|
+
return ok({ decoded, meta });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const r = parseImage(bytes, mime, {
|
|
289
|
+
colorSpace,
|
|
290
|
+
mipmap: mipmap === 'auto',
|
|
291
|
+
path: sourcePath,
|
|
292
|
+
});
|
|
293
|
+
if (!r.ok) {
|
|
294
|
+
return err(r.error);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return ok({ decoded: r.value, meta });
|
|
298
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ImageErrorCode, ImageErrorDetailFor, ImageErrorFor } from '@forgeax/engine-types';
|
|
2
|
+
import { IMAGE_ERROR_HINTS } from '@forgeax/engine-types';
|
|
3
|
+
|
|
4
|
+
// Per-code .expected string literals SSOT.
|
|
5
|
+
// Mirrors ASSET_ERROR_HINTS / IMAGE_ERROR_HINTS shape (charter P5 consistent
|
|
6
|
+
// abstraction). AI users surface .expected when a structured error needs to
|
|
7
|
+
// describe the precondition that was violated.
|
|
8
|
+
const IMAGE_ERROR_EXPECTED: Readonly<Record<ImageErrorCode, string>> = {
|
|
9
|
+
'image-decode-failed': 'PNG / JPG byte stream decodes successfully',
|
|
10
|
+
'image-format-unsupported':
|
|
11
|
+
"mime is one of ['image/png', 'image/jpeg', 'image/x-tga']; uploadTexture format <-> colorSpace family agrees",
|
|
12
|
+
'image-dimension-out-of-bounds':
|
|
13
|
+
'width and height fall under device caps maxTextureDimension2D (or 16384 hard cap)',
|
|
14
|
+
'image-meta-missing':
|
|
15
|
+
"<source>.meta.json sidecar (importer: 'image') exists in the same directory",
|
|
16
|
+
'image-hdr-decode-failed': 'Radiance RGBE header is valid and pixel data decodes successfully',
|
|
17
|
+
// feat-20260521-sprite-atlas-animation M1 T-03 — vite-plugin-image atlas
|
|
18
|
+
// hook .expected literals (plan-strategy section 2 D-2 + AC-10 a/b/c).
|
|
19
|
+
// ImageErrorImpl construction path is unchanged: the new atlas-* errors
|
|
20
|
+
// flow through `new ImageErrorImpl({ code: 'atlas-...', ...detail })` and
|
|
21
|
+
// pick the .expected string up from this Record at construction time
|
|
22
|
+
// (charter P3 explicit failure SSOT — AI users surface .expected next to
|
|
23
|
+
// .hint after switch (err.code) without parsing the message).
|
|
24
|
+
'atlas-empty-input': 'images.length >= 1',
|
|
25
|
+
'atlas-size-exceeded':
|
|
26
|
+
'image width x height <= maxAtlasSize^2 and each image fits in the atlas footprint',
|
|
27
|
+
'atlas-region-mismatch': 'sum(regions[i].w x regions[i].h) <= atlasWidth x atlasHeight',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Runtime implementation of the correlated `ImageErrorFor<C>` envelope. */
|
|
31
|
+
export class ImageErrorImpl<C extends ImageErrorCode = ImageErrorCode>
|
|
32
|
+
extends Error
|
|
33
|
+
implements ImageErrorFor<C>
|
|
34
|
+
{
|
|
35
|
+
readonly code: C;
|
|
36
|
+
readonly expected: string;
|
|
37
|
+
readonly hint: string;
|
|
38
|
+
readonly detail: ImageErrorDetailFor<C>;
|
|
39
|
+
|
|
40
|
+
constructor(detail: ImageErrorDetailFor<C>) {
|
|
41
|
+
const code = detail.code;
|
|
42
|
+
const expected = IMAGE_ERROR_EXPECTED[code];
|
|
43
|
+
const hint = IMAGE_ERROR_HINTS[code];
|
|
44
|
+
super(`[ImageError ${code}] expected: ${expected}; hint: ${hint}`);
|
|
45
|
+
this.name = 'ImageError';
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.expected = expected;
|
|
48
|
+
this.hint = hint;
|
|
49
|
+
this.detail = detail;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Construct a structured image error while preserving its code/detail pair. */
|
|
54
|
+
export function imageError<C extends ImageErrorCode>(
|
|
55
|
+
detail: ImageErrorDetailFor<C>,
|
|
56
|
+
): ImageErrorFor<C> {
|
|
57
|
+
return new ImageErrorImpl<C>(detail);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { IMAGE_ERROR_EXPECTED };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { ImageError } from '@forgeax/engine-types';
|
|
2
|
+
import { imageError } from './errors.js';
|
|
3
|
+
import type { Result } from './result.js';
|
|
4
|
+
import { err, ok } from './result.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Decoded HDR image POD.
|
|
8
|
+
*
|
|
9
|
+
* `data` is an interleaved RGBA Float32Array (4 floats per pixel, row-major).
|
|
10
|
+
* Color space is always linear (RGBE is radiance).
|
|
11
|
+
*/
|
|
12
|
+
export interface HdrDecoded {
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
readonly data: Float32Array;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// ASCII code points
|
|
19
|
+
const LF = 0x0a;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Decode a Radiance RGBE (.hdr) byte stream into linear RGBA float pixels.
|
|
23
|
+
*
|
|
24
|
+
* Steps per research F-6:
|
|
25
|
+
* 1. Parse ASCII header: magic (#?RADIANCE), FORMAT=32-bit_rle_rgbe,
|
|
26
|
+
* resolution line (-Y height +X width).
|
|
27
|
+
* 2. Decode per-scanline new-RLE pixel data: 4 independent channel runs.
|
|
28
|
+
* 3. Convert RGBE to float: if E==0 -> 0; else f=2^(E-136), R=(Rm+0.5)*f.
|
|
29
|
+
* 4. Output as interleaved RGBA Float32Array (alpha=1.0).
|
|
30
|
+
*
|
|
31
|
+
* Old-RLE scanlines (prefix not matching 0x02,0x02,hi,lo with correct width)
|
|
32
|
+
* return image-hdr-decode-failed.
|
|
33
|
+
*/
|
|
34
|
+
export function decodeHdr(bytes: Uint8Array): Result<HdrDecoded, ImageError> {
|
|
35
|
+
let pos = 0;
|
|
36
|
+
|
|
37
|
+
// Step 1a: magic -- must start with "#?RADIANCE" or "#?RGBE"
|
|
38
|
+
if (bytes.length < 11) {
|
|
39
|
+
return err(hdrDecodeError('file too short for Radiance HDR header'));
|
|
40
|
+
}
|
|
41
|
+
const magic = String.fromCharCode(...bytes.subarray(0, 11));
|
|
42
|
+
if (magic !== '#?RADIANCE\n' && magic !== '#?RGBE\n') {
|
|
43
|
+
return err(
|
|
44
|
+
hdrDecodeError('missing or invalid Radiance HDR magic; expected #?RADIANCE or #?RGBE'),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
pos = 11;
|
|
48
|
+
|
|
49
|
+
// Step 1b: key=value lines until empty line
|
|
50
|
+
let formatFound = false;
|
|
51
|
+
while (pos < bytes.length) {
|
|
52
|
+
const lineEnd = findByte(bytes, LF, pos);
|
|
53
|
+
if (lineEnd === -1) return err(hdrDecodeError('header truncated before empty line'));
|
|
54
|
+
const line = asciiSubstring(bytes, pos, lineEnd);
|
|
55
|
+
pos = lineEnd + 1;
|
|
56
|
+
if (line === '') break;
|
|
57
|
+
if (line.startsWith('FORMAT=')) {
|
|
58
|
+
const val = line.slice(7);
|
|
59
|
+
if (val === '32-bit_rle_rgbe') {
|
|
60
|
+
formatFound = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!formatFound) {
|
|
65
|
+
return err(hdrDecodeError('missing or unsupported FORMAT; expected FORMAT=32-bit_rle_rgbe'));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Step 1c: resolution line (-Y height +X width)
|
|
69
|
+
if (pos >= bytes.length) return err(hdrDecodeError('missing resolution line'));
|
|
70
|
+
const resLineEnd = findByte(bytes, LF, pos);
|
|
71
|
+
if (resLineEnd === -1) return err(hdrDecodeError('resolution line truncated'));
|
|
72
|
+
const resLine = asciiSubstring(bytes, pos, resLineEnd);
|
|
73
|
+
pos = resLineEnd + 1;
|
|
74
|
+
const resMatch = /^-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/.exec(resLine);
|
|
75
|
+
if (resMatch === null) {
|
|
76
|
+
return err(
|
|
77
|
+
hdrDecodeError(`unexpected resolution line format: "${resLine}"; expected "-Y H +X W"`),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const height = Number(resMatch[1]);
|
|
81
|
+
const width = Number(resMatch[2]);
|
|
82
|
+
if (height === undefined || width === undefined || height <= 0 || width <= 0) {
|
|
83
|
+
return err(hdrDecodeError(`invalid dimensions: ${width}x${height}`));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Step 2: decode per-scanline new-RLE pixel data
|
|
87
|
+
const pixelCount = width * height;
|
|
88
|
+
const rgbe = new Uint8Array(pixelCount * 4);
|
|
89
|
+
const scanlineBytes = width * 4;
|
|
90
|
+
|
|
91
|
+
for (let y = 0; y < height; y++) {
|
|
92
|
+
if (pos + 4 > bytes.length) {
|
|
93
|
+
return err(hdrDecodeError(`truncated at scanline ${y}: expected 4-byte prefix`));
|
|
94
|
+
}
|
|
95
|
+
const p0 = bytes[pos];
|
|
96
|
+
const p1 = bytes[pos + 1];
|
|
97
|
+
const pHi = bytes[pos + 2];
|
|
98
|
+
const pLo = bytes[pos + 3];
|
|
99
|
+
if (p0 === undefined || p1 === undefined || pHi === undefined || pLo === undefined) {
|
|
100
|
+
return err(hdrDecodeError(`truncated at scanline ${y}`));
|
|
101
|
+
}
|
|
102
|
+
// biome-ignore lint/style/noNonNullAssertion: checked above
|
|
103
|
+
const prefixWidth = (pHi! << 8) | pLo!;
|
|
104
|
+
|
|
105
|
+
if (p0 === 0x02 && p1 === 0x02 && prefixWidth === width && width >= 8 && width <= 32767) {
|
|
106
|
+
// New-RLE: 4 channels independently RLE-encoded, then interleaved
|
|
107
|
+
const decoded = decodeNewRleScanline(bytes, pos + 4, width);
|
|
108
|
+
if (decoded === null) {
|
|
109
|
+
return err(hdrDecodeError(`RLE decode failed at scanline ${y}`));
|
|
110
|
+
}
|
|
111
|
+
// Copy into rgbe interleaved buffer
|
|
112
|
+
const base = y * scanlineBytes;
|
|
113
|
+
const channels = [decoded[0], decoded[1], decoded[2], decoded[3]];
|
|
114
|
+
for (let x = 0; x < width; x++) {
|
|
115
|
+
for (let ch = 0; ch < 4; ch++) {
|
|
116
|
+
// biome-ignore lint/style/noNonNullAssertion: checked at allocation
|
|
117
|
+
rgbe[base + x * 4 + ch] = channels[ch]![x]!;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Advance pos past the 4-byte prefix + the total RLE bytes consumed
|
|
121
|
+
pos += 4 + decoded.totalBytes;
|
|
122
|
+
} else {
|
|
123
|
+
// Old-RLE: not supported
|
|
124
|
+
return err(
|
|
125
|
+
hdrDecodeError(
|
|
126
|
+
'old-RLE format is not supported; only new-RLE (32-bit_rle_rgbe) is accepted',
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Step 3: RGBE to float
|
|
133
|
+
const out = new Float32Array(pixelCount * 4);
|
|
134
|
+
for (let i = 0; i < pixelCount; i++) {
|
|
135
|
+
const base = i * 4;
|
|
136
|
+
// biome-ignore lint/style/noNonNullAssertion: checked at allocation
|
|
137
|
+
const r = rgbe[base]!;
|
|
138
|
+
// biome-ignore lint/style/noNonNullAssertion: checked at allocation
|
|
139
|
+
const g = rgbe[base + 1]!;
|
|
140
|
+
// biome-ignore lint/style/noNonNullAssertion: checked at allocation
|
|
141
|
+
const b = rgbe[base + 2]!;
|
|
142
|
+
// biome-ignore lint/style/noNonNullAssertion: checked at allocation
|
|
143
|
+
const e = rgbe[base + 3]!;
|
|
144
|
+
out[base + 3] = 1.0;
|
|
145
|
+
|
|
146
|
+
if (e === 0) {
|
|
147
|
+
out[base] = 0;
|
|
148
|
+
out[base + 1] = 0;
|
|
149
|
+
out[base + 2] = 0;
|
|
150
|
+
} else {
|
|
151
|
+
// f = 2^(E - 136) = ldexp(1.0, E - 128 - 8)
|
|
152
|
+
// Equivalent: ldexp(1.0 / 256.0, E - 128)
|
|
153
|
+
// But simpler: const f = (1.0 / 256.0) * Math.pow(2, e - 128);
|
|
154
|
+
// Using ldexp: Math.pow(2, e - 136)
|
|
155
|
+
const f = 2 ** (e - 136);
|
|
156
|
+
out[base] = (r + 0.5) * f;
|
|
157
|
+
out[base + 1] = (g + 0.5) * f;
|
|
158
|
+
out[base + 2] = (b + 0.5) * f;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return ok({ width, height, data: out });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface DecodedScanline {
|
|
166
|
+
/** 4 channels, each width bytes */
|
|
167
|
+
readonly 0: Uint8Array;
|
|
168
|
+
readonly 1: Uint8Array;
|
|
169
|
+
readonly 2: Uint8Array;
|
|
170
|
+
readonly 3: Uint8Array;
|
|
171
|
+
readonly totalBytes: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Decode one scanline of new-RLE data into 4 channel arrays.
|
|
176
|
+
* Returns null on failure (data underrun).
|
|
177
|
+
*/
|
|
178
|
+
function decodeNewRleScanline(
|
|
179
|
+
bytes: Uint8Array,
|
|
180
|
+
start: number,
|
|
181
|
+
width: number,
|
|
182
|
+
): DecodedScanline | null {
|
|
183
|
+
const channels: Uint8Array[] = [];
|
|
184
|
+
let cursor = start;
|
|
185
|
+
|
|
186
|
+
for (let ch = 0; ch < 4; ch++) {
|
|
187
|
+
const data = new Uint8Array(width);
|
|
188
|
+
let x = 0;
|
|
189
|
+
while (x < width) {
|
|
190
|
+
if (cursor >= bytes.length) return null;
|
|
191
|
+
// biome-ignore lint/style/noNonNullAssertion: checked above
|
|
192
|
+
const code = bytes[cursor]!;
|
|
193
|
+
cursor++;
|
|
194
|
+
if (code > 128) {
|
|
195
|
+
// RLE run: next byte repeated (code - 128) times
|
|
196
|
+
const count = code - 128;
|
|
197
|
+
if (cursor >= bytes.length || x + count > width) return null;
|
|
198
|
+
// biome-ignore lint/style/noNonNullAssertion: checked above
|
|
199
|
+
const val = bytes[cursor]!;
|
|
200
|
+
cursor++;
|
|
201
|
+
data.fill(val, x, x + count);
|
|
202
|
+
x += count;
|
|
203
|
+
} else {
|
|
204
|
+
// Literal run: next `code` bytes copied verbatim
|
|
205
|
+
if (code === 0) continue;
|
|
206
|
+
if (cursor + code > bytes.length || x + code > width) return null;
|
|
207
|
+
for (let k = 0; k < code; k++) {
|
|
208
|
+
// biome-ignore lint/style/noNonNullAssertion: checked above
|
|
209
|
+
data[x + k] = bytes[cursor + k]!;
|
|
210
|
+
}
|
|
211
|
+
cursor += code;
|
|
212
|
+
x += code;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
channels.push(data);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const ch0 = channels[0];
|
|
219
|
+
const ch1 = channels[1];
|
|
220
|
+
const ch2 = channels[2];
|
|
221
|
+
const ch3 = channels[3];
|
|
222
|
+
if (ch0 === undefined || ch1 === undefined || ch2 === undefined || ch3 === undefined) {
|
|
223
|
+
return null; // channels should always have 4 entries
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
0: ch0,
|
|
227
|
+
1: ch1,
|
|
228
|
+
2: ch2,
|
|
229
|
+
3: ch3,
|
|
230
|
+
totalBytes: cursor - start,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function findByte(bytes: Uint8Array, target: number, start: number): number {
|
|
235
|
+
for (let i = start; i < bytes.length; i++) {
|
|
236
|
+
if (bytes[i] === target) return i;
|
|
237
|
+
}
|
|
238
|
+
return -1;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function asciiSubstring(bytes: Uint8Array, start: number, end: number): string {
|
|
242
|
+
let s = '';
|
|
243
|
+
for (let i = start; i < end; i++) {
|
|
244
|
+
// biome-ignore lint/style/noNonNullAssertion: in bounds
|
|
245
|
+
s += String.fromCharCode(bytes[i]!);
|
|
246
|
+
}
|
|
247
|
+
return s;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function hdrDecodeError(reason: string): ImageError {
|
|
251
|
+
return imageError({
|
|
252
|
+
code: 'image-hdr-decode-failed',
|
|
253
|
+
reason,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { DecodedImage, ImageColorSpace, ImageError } from '@forgeax/engine-types';
|
|
2
|
+
import { imageError } from './errors.js';
|
|
3
|
+
import type { Result } from './result.js';
|
|
4
|
+
import { err, ok } from './result.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Browser image decoder (plan-strategy section 3.3 + section 2.4 D Open Q-3).
|
|
8
|
+
*
|
|
9
|
+
* Uses `createImageBitmap(blob, { colorSpaceConversion: 'none' })` to keep
|
|
10
|
+
* the bytes in their authored color space (sRGB / linear); the runtime
|
|
11
|
+
* uploadTexture entry asserts `format <-> colorSpace` consistency at GPU
|
|
12
|
+
* upload time (plan-strategy section 2.5 D Open Q-4 (c)).
|
|
13
|
+
*
|
|
14
|
+
* Pixel readback uses an offscreen 2D canvas + `getImageData`; AI users
|
|
15
|
+
* never call this directly -- it is the browser-mode counterpart of
|
|
16
|
+
* `parseImage` (Node-mode upng / jpeg-js path) consumed by future M2b
|
|
17
|
+
* vite-plugin overlay paths and direct browser-mode loaders. The Node
|
|
18
|
+
* decoder remains the SSOT for parseImage; this file is the browser
|
|
19
|
+
* fallback when running inside vitest browser mode or the Vite dev server.
|
|
20
|
+
*/
|
|
21
|
+
export async function decodeImageInBrowser(
|
|
22
|
+
bytes: Uint8Array,
|
|
23
|
+
mime: 'image/png' | 'image/jpeg',
|
|
24
|
+
opts: { colorSpace?: ImageColorSpace; mipmap?: boolean } = {},
|
|
25
|
+
): Promise<Result<DecodedImage, ImageError>> {
|
|
26
|
+
if (typeof createImageBitmap !== 'function') {
|
|
27
|
+
return err(
|
|
28
|
+
imageError({
|
|
29
|
+
code: 'image-decode-failed',
|
|
30
|
+
reason: 'createImageBitmap is not available in this environment',
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let bitmap: ImageBitmap;
|
|
36
|
+
try {
|
|
37
|
+
const blob = new Blob([bytes as BlobPart], { type: mime });
|
|
38
|
+
bitmap = await createImageBitmap(blob, {
|
|
39
|
+
colorSpaceConversion: 'none',
|
|
40
|
+
premultiplyAlpha: 'none',
|
|
41
|
+
});
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return err(
|
|
44
|
+
imageError({
|
|
45
|
+
code: 'image-decode-failed',
|
|
46
|
+
reason: e instanceof Error ? e.message : String(e),
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Read pixels back via OffscreenCanvas (browser context) -- 2D context is
|
|
52
|
+
// ubiquitous and avoids the WebGPU readback round-trip during disk-side
|
|
53
|
+
// decode (charter P5 producer / consumer split: GPU upload happens inside
|
|
54
|
+
// the Render DeviceScope, not in this byte decoder).
|
|
55
|
+
const canvas =
|
|
56
|
+
typeof OffscreenCanvas !== 'undefined'
|
|
57
|
+
? new OffscreenCanvas(bitmap.width, bitmap.height)
|
|
58
|
+
: (() => {
|
|
59
|
+
const c = document.createElement('canvas');
|
|
60
|
+
c.width = bitmap.width;
|
|
61
|
+
c.height = bitmap.height;
|
|
62
|
+
return c;
|
|
63
|
+
})();
|
|
64
|
+
const ctx = canvas.getContext('2d') as
|
|
65
|
+
| OffscreenCanvasRenderingContext2D
|
|
66
|
+
| CanvasRenderingContext2D
|
|
67
|
+
| null;
|
|
68
|
+
if (ctx === null) {
|
|
69
|
+
return err(
|
|
70
|
+
imageError({
|
|
71
|
+
code: 'image-decode-failed',
|
|
72
|
+
reason: 'failed to acquire 2d canvas context for pixel readback',
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
77
|
+
const data = ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
78
|
+
bitmap.close();
|
|
79
|
+
|
|
80
|
+
return ok({
|
|
81
|
+
bytes: new Uint8Array(data.data.buffer.slice(0)),
|
|
82
|
+
width: data.width,
|
|
83
|
+
height: data.height,
|
|
84
|
+
mime,
|
|
85
|
+
colorSpace: opts.colorSpace ?? 'srgb',
|
|
86
|
+
mipmap: opts.mipmap ?? true,
|
|
87
|
+
});
|
|
88
|
+
}
|