@flighthq/image-codec 0.3.0-next.906.07cea63 → 0.3.1-next.1041.35b950c
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/dist/contract.d.ts +3 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +3 -0
- package/dist/contract.js.map +1 -1
- package/dist/detectImageMimeType.d.ts.map +1 -1
- package/dist/detectImageMimeType.js +30 -0
- package/dist/detectImageMimeType.js.map +1 -1
- package/dist/explainImageDecodeFailure.d.ts +3 -0
- package/dist/explainImageDecodeFailure.d.ts.map +1 -0
- package/dist/explainImageDecodeFailure.js +13 -0
- package/dist/explainImageDecodeFailure.js.map +1 -0
- package/dist/explainImageEncodeFailure.d.ts +3 -0
- package/dist/explainImageEncodeFailure.d.ts.map +1 -0
- package/dist/explainImageEncodeFailure.js +9 -0
- package/dist/explainImageEncodeFailure.js.map +1 -0
- package/dist/imageBitmapComposerRegistry.d.ts +8 -0
- package/dist/imageBitmapComposerRegistry.d.ts.map +1 -0
- package/dist/imageBitmapComposerRegistry.js +23 -0
- package/dist/imageBitmapComposerRegistry.js.map +1 -0
- package/dist/imageDecoderRegistry.d.ts +1 -0
- package/dist/imageDecoderRegistry.d.ts.map +1 -1
- package/dist/imageDecoderRegistry.js +5 -0
- package/dist/imageDecoderRegistry.js.map +1 -1
- package/dist/imageEncoderRegistry.d.ts +1 -0
- package/dist/imageEncoderRegistry.d.ts.map +1 -1
- package/dist/imageEncoderRegistry.js +5 -0
- package/dist/imageEncoderRegistry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/decodeImage.test.ts +8 -1
- package/src/detectImageMimeType.test.ts +42 -0
- package/src/explainImageDecodeFailure.test.ts +37 -0
- package/src/explainImageEncodeFailure.test.ts +24 -0
- package/src/imageBitmapComposerRegistry.test.ts +72 -0
- package/src/imageDecoderRegistry.test.ts +15 -0
- package/src/imageEncoderRegistry.test.ts +15 -0
- package/src/registerWebImageDecoders.test.ts +24 -11
- package/src/registerWebImageEncoders.test.ts +15 -11
package/dist/contract.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './decodeImage';
|
|
2
2
|
export * from './detectImageMimeType';
|
|
3
3
|
export * from './encodeImage';
|
|
4
|
+
export * from './explainImageDecodeFailure';
|
|
5
|
+
export * from './explainImageEncodeFailure';
|
|
4
6
|
export * from './imageDecoderRegistry';
|
|
7
|
+
export * from './imageBitmapComposerRegistry';
|
|
5
8
|
export * from './imageEncoderRegistry';
|
|
6
9
|
export * from './registerWebImageDecoders';
|
|
7
10
|
export * from './registerWebImageEncoders';
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './decodeImage';
|
|
2
2
|
export * from './detectImageMimeType';
|
|
3
3
|
export * from './encodeImage';
|
|
4
|
+
export * from './explainImageDecodeFailure';
|
|
5
|
+
export * from './explainImageEncodeFailure';
|
|
4
6
|
export * from './imageDecoderRegistry';
|
|
7
|
+
export * from './imageBitmapComposerRegistry';
|
|
5
8
|
export * from './imageEncoderRegistry';
|
|
6
9
|
export * from './registerWebImageDecoders';
|
|
7
10
|
export * from './registerWebImageEncoders';
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectImageMimeType.d.ts","sourceRoot":"","sources":["../src/detectImageMimeType.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"detectImageMimeType.d.ts","sourceRoot":"","sources":["../src/detectImageMimeType.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,CA4C3F"}
|
|
@@ -25,9 +25,39 @@ export function detectImageMimeType(data) {
|
|
|
25
25
|
b[10] === 0x42 &&
|
|
26
26
|
b[11] === 0x50)
|
|
27
27
|
return 'image/webp';
|
|
28
|
+
// AVIF: ISO-BMFF FileTypeBox whose major or compatible brands include avif/avis.
|
|
29
|
+
if (isAvifFileTypeBox(b))
|
|
30
|
+
return 'image/avif';
|
|
31
|
+
// ICO: 00 00 01 00
|
|
32
|
+
if (b[0] === 0x00 && b[1] === 0x00 && b[2] === 0x01 && b[3] === 0x00)
|
|
33
|
+
return 'image/x-icon';
|
|
34
|
+
// TIFF: little-endian II*\0 or big-endian MM\0*
|
|
35
|
+
if ((b[0] === 0x49 && b[1] === 0x49 && b[2] === 0x2a && b[3] === 0x00) ||
|
|
36
|
+
(b[0] === 0x4d && b[1] === 0x4d && b[2] === 0x00 && b[3] === 0x2a))
|
|
37
|
+
return 'image/tiff';
|
|
28
38
|
// BMP: 42 4D
|
|
29
39
|
if (b[0] === 0x42 && b[1] === 0x4d)
|
|
30
40
|
return 'image/bmp';
|
|
31
41
|
return null;
|
|
32
42
|
}
|
|
43
|
+
function isAvifFileTypeBox(bytes) {
|
|
44
|
+
if (bytes.byteLength < 16 || bytes[4] !== 0x66 || bytes[5] !== 0x74 || bytes[6] !== 0x79 || bytes[7] !== 0x70)
|
|
45
|
+
return false;
|
|
46
|
+
const boxSize = bytes[0] * 0x1000000 + bytes[1] * 0x10000 + bytes[2] * 0x100 + bytes[3];
|
|
47
|
+
if (boxSize < 16 || boxSize > bytes.byteLength || (boxSize - 16) % 4 !== 0)
|
|
48
|
+
return false;
|
|
49
|
+
if (isAvifBrand(bytes, 8))
|
|
50
|
+
return true;
|
|
51
|
+
for (let offset = 16; offset < boxSize; offset += 4) {
|
|
52
|
+
if (isAvifBrand(bytes, offset))
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function isAvifBrand(bytes, offset) {
|
|
58
|
+
return (bytes[offset] === 0x61 &&
|
|
59
|
+
bytes[offset + 1] === 0x76 &&
|
|
60
|
+
bytes[offset + 2] === 0x69 &&
|
|
61
|
+
(bytes[offset + 3] === 0x66 || bytes[offset + 3] === 0x73));
|
|
62
|
+
}
|
|
33
63
|
//# sourceMappingURL=detectImageMimeType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectImageMimeType.js","sourceRoot":"","sources":["../src/detectImageMimeType.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,iGAAiG;AACjG,yFAAyF;AACzF,MAAM,UAAU,mBAAmB,CAAC,IAAwC;IAC1E,MAAM,CAAC,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACnE,IAAI,CAAC,CAAC,UAAU,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAElC,+BAA+B;IAC/B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,WAAW,CAAC;IAEzF,iBAAiB;IACjB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC;IAEzE,+BAA+B;IAC/B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;QAAE,OAAO,W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AAC;AAED,SAAS,WAAW,CAAC,KAA2B,EAAE,MAAc;IAC9D,OAAO,CACL,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;QACtB,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI;QAC1B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI;QAC1B,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explainImageDecodeFailure.d.ts","sourceRoot":"","sources":["../src/explainImageDecodeFailure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAO9E,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,EAC3B,QAAQ,CAAC,EAAE,MAAM,GAChB,6BAA6B,GAAG,IAAI,CAKtC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { detectImageMimeType } from './detectImageMimeType';
|
|
2
|
+
import { getImageDecoder } from './imageDecoderRegistry';
|
|
3
|
+
// Explains the two dispatcher failures that decodeImage represents with null. Returns null when the
|
|
4
|
+
// same request can reach a registered decoder. This is a read-only query and never invokes the codec.
|
|
5
|
+
export function explainImageDecodeFailure(bytes, mimeType) {
|
|
6
|
+
const type = mimeType ?? detectImageMimeType(bytes);
|
|
7
|
+
if (type === null)
|
|
8
|
+
return { mimeType: null, reason: 'mime-type-undetected' };
|
|
9
|
+
if (getImageDecoder(type) === null)
|
|
10
|
+
return { mimeType: type, reason: 'decoder-not-registered' };
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=explainImageDecodeFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explainImageDecodeFailure.js","sourceRoot":"","sources":["../src/explainImageDecodeFailure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,oGAAoG;AACpG,sGAAsG;AACtG,MAAM,UAAU,yBAAyB,CACvC,KAA2B,EAC3B,QAAiB;IAEjB,MAAM,IAAI,GAAG,QAAQ,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACpD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;IAC7E,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;IAChG,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explainImageEncodeFailure.d.ts","sourceRoot":"","sources":["../src/explainImageEncodeFailure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAM9E,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,6BAA6B,GAAG,IAAI,CAGhG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getImageEncoder } from './imageEncoderRegistry';
|
|
2
|
+
// Explains the dispatcher failure that encodeImage represents with null. Returns null when an encoder
|
|
3
|
+
// is registered for the requested MIME type. This is a read-only query and never invokes the codec.
|
|
4
|
+
export function explainImageEncodeFailure(mimeType) {
|
|
5
|
+
if (getImageEncoder(mimeType) !== null)
|
|
6
|
+
return null;
|
|
7
|
+
return { mimeType, reason: 'encoder-not-registered' };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=explainImageEncodeFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explainImageEncodeFailure.js","sourceRoot":"","sources":["../src/explainImageEncodeFailure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,sGAAsG;AACtG,oGAAoG;AACpG,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,IAAI,eAAe,CAAC,QAAQ,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ImageBitmapComposer } from '@flighthq/types/contract';
|
|
2
|
+
export declare function clearImageBitmapComposers(): void;
|
|
3
|
+
export declare function getImageBitmapComposer(kind: string): ImageBitmapComposer | null;
|
|
4
|
+
export declare function getImageBitmapComposerKinds(): readonly string[];
|
|
5
|
+
export declare function hasImageBitmapComposer(kind: string): boolean;
|
|
6
|
+
export declare function registerImageBitmapComposer(kind: string, composer: ImageBitmapComposer): void;
|
|
7
|
+
export declare function unregisterImageBitmapComposer(kind: string): void;
|
|
8
|
+
//# sourceMappingURL=imageBitmapComposerRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageBitmapComposerRegistry.d.ts","sourceRoot":"","sources":["../src/imageBitmapComposerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAE/E;AAED,wBAAgB,2BAA2B,IAAI,SAAS,MAAM,EAAE,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAE7F;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function clearImageBitmapComposers() {
|
|
2
|
+
composers.clear();
|
|
3
|
+
}
|
|
4
|
+
export function getImageBitmapComposer(kind) {
|
|
5
|
+
return composers.get(kind) ?? null;
|
|
6
|
+
}
|
|
7
|
+
export function getImageBitmapComposerKinds() {
|
|
8
|
+
return Array.from(composers.keys());
|
|
9
|
+
}
|
|
10
|
+
export function hasImageBitmapComposer(kind) {
|
|
11
|
+
return composers.has(kind);
|
|
12
|
+
}
|
|
13
|
+
export function registerImageBitmapComposer(kind, composer) {
|
|
14
|
+
composers.set(kind, composer);
|
|
15
|
+
}
|
|
16
|
+
export function unregisterImageBitmapComposer(kind) {
|
|
17
|
+
composers.delete(kind);
|
|
18
|
+
}
|
|
19
|
+
// Open, format-neutral composer registry. A container puts only the stable key and payload bytes on a
|
|
20
|
+
// reference; its package owns the callback that understands those bytes. Last registration wins so an
|
|
21
|
+
// application can replace a built-in producer deliberately without embedding executable state in a scene.
|
|
22
|
+
const composers = new Map();
|
|
23
|
+
//# sourceMappingURL=imageBitmapComposerRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageBitmapComposerRegistry.js","sourceRoot":"","sources":["../src/imageBitmapComposerRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,yBAAyB;IACvC,SAAS,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAY,EAAE,QAA6B;IACrF,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,IAAY;IACxD,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,sGAAsG;AACtG,sGAAsG;AACtG,0GAA0G;AAC1G,MAAM,SAAS,GAAG,IAAI,GAAG,EAA+B,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ImageDecoder } from '@flighthq/types/contract';
|
|
2
2
|
export declare function clearImageDecoders(): void;
|
|
3
3
|
export declare function getImageDecoder(mimeType: string): ImageDecoder | null;
|
|
4
|
+
export declare function getImageDecoderMimeTypes(): readonly string[];
|
|
4
5
|
export declare function hasImageDecoder(mimeType: string): boolean;
|
|
5
6
|
export declare function registerImageDecoder(mimeType: string, decoder: ImageDecoder): void;
|
|
6
7
|
export declare function unregisterImageDecoder(mimeType: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageDecoderRegistry.d.ts","sourceRoot":"","sources":["../src/imageDecoderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAErE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAElF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE7D"}
|
|
1
|
+
{"version":3,"file":"imageDecoderRegistry.d.ts","sourceRoot":"","sources":["../src/imageDecoderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAErE;AAID,wBAAgB,wBAAwB,IAAI,SAAS,MAAM,EAAE,CAE5D;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAElF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE7D"}
|
|
@@ -4,6 +4,11 @@ export function clearImageDecoders() {
|
|
|
4
4
|
export function getImageDecoder(mimeType) {
|
|
5
5
|
return decoders.get(mimeType) ?? null;
|
|
6
6
|
}
|
|
7
|
+
// Returns an insertion-ordered snapshot of the MIME types with registered decoders. Mutating the
|
|
8
|
+
// returned array cannot change registry state.
|
|
9
|
+
export function getImageDecoderMimeTypes() {
|
|
10
|
+
return Array.from(decoders.keys());
|
|
11
|
+
}
|
|
7
12
|
export function hasImageDecoder(mimeType) {
|
|
8
13
|
return decoders.has(mimeType);
|
|
9
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageDecoderRegistry.js","sourceRoot":"","sources":["../src/imageDecoderRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AACxC,CAAC;AA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ACtD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ImageEncoder } from '@flighthq/types/contract';
|
|
2
2
|
export declare function clearImageEncoders(): void;
|
|
3
3
|
export declare function getImageEncoder(mimeType: string): ImageEncoder | null;
|
|
4
|
+
export declare function getImageEncoderMimeTypes(): readonly string[];
|
|
4
5
|
export declare function hasImageEncoder(mimeType: string): boolean;
|
|
5
6
|
export declare function registerImageEncoder(mimeType: string, encoder: ImageEncoder): void;
|
|
6
7
|
export declare function unregisterImageEncoder(mimeType: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageEncoderRegistry.d.ts","sourceRoot":"","sources":["../src/imageEncoderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAErE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAElF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE7D"}
|
|
1
|
+
{"version":3,"file":"imageEncoderRegistry.d.ts","sourceRoot":"","sources":["../src/imageEncoderRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAErE;AAID,wBAAgB,wBAAwB,IAAI,SAAS,MAAM,EAAE,CAE5D;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAElF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE7D"}
|
|
@@ -4,6 +4,11 @@ export function clearImageEncoders() {
|
|
|
4
4
|
export function getImageEncoder(mimeType) {
|
|
5
5
|
return encoders.get(mimeType) ?? null;
|
|
6
6
|
}
|
|
7
|
+
// Returns an insertion-ordered snapshot of the MIME types with registered encoders. Mutating the
|
|
8
|
+
// returned array cannot change registry state.
|
|
9
|
+
export function getImageEncoderMimeTypes() {
|
|
10
|
+
return Array.from(encoders.keys());
|
|
11
|
+
}
|
|
7
12
|
export function hasImageEncoder(mimeType) {
|
|
8
13
|
return encoders.has(mimeType);
|
|
9
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageEncoderRegistry.js","sourceRoot":"","sources":["../src/imageEncoderRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAgB,EAAE,OAAqB;IAC1E,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAED,uGAAuG;AACvG,sGAAsG;AACtG,sDAAsD;AACtD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"imageEncoderRegistry.js","sourceRoot":"","sources":["../src/imageEncoderRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AACxC,CAAC;AAED,iGAAiG;AACjG,+CAA+C;AAC/C,MAAM,UAAU,wBAAwB;IACtC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAgB,EAAE,OAAqB;IAC1E,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAED,uGAAuG;AACvG,sGAAsG;AACtG,sDAAsD;AACtD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { clearImageDecoders, clearImageEncoders, decodeImage, decodeImagePremultiplied, detectImageMimeType, encodeImage, getImageDecoder, getImageEncoder, hasImageDecoder, hasImageEncoder, registerImageDecoder, registerImageEncoder, registerWebImageDecoders, registerWebImageEncoders, unregisterImageDecoder, unregisterImageEncoder, } from './contract';
|
|
1
|
+
export { clearImageDecoders, clearImageEncoders, decodeImage, decodeImagePremultiplied, detectImageMimeType, encodeImage, explainImageDecodeFailure, explainImageEncodeFailure, getImageDecoder, getImageDecoderMimeTypes, getImageEncoder, getImageEncoderMimeTypes, hasImageDecoder, hasImageEncoder, registerImageDecoder, registerImageEncoder, registerWebImageDecoders, registerWebImageEncoders, unregisterImageDecoder, unregisterImageEncoder, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EACzB,yBAAyB,EACzB,eAAe,EACf,wBAAwB,EACxB,eAAe,EACf,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { clearImageDecoders, clearImageEncoders, decodeImage, decodeImagePremultiplied, detectImageMimeType, encodeImage, getImageDecoder, getImageEncoder, hasImageDecoder, hasImageEncoder, registerImageDecoder, registerImageEncoder, registerWebImageDecoders, registerWebImageEncoders, unregisterImageDecoder, unregisterImageEncoder, } from './contract';
|
|
1
|
+
export { clearImageDecoders, clearImageEncoders, decodeImage, decodeImagePremultiplied, detectImageMimeType, encodeImage, explainImageDecodeFailure, explainImageEncodeFailure, getImageDecoder, getImageDecoderMimeTypes, getImageEncoder, getImageEncoderMimeTypes, hasImageDecoder, hasImageEncoder, registerImageDecoder, registerImageEncoder, registerWebImageDecoders, registerWebImageEncoders, unregisterImageDecoder, unregisterImageEncoder, } from './contract';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,WAAW,EACX,yBAAyB,EACzB,yBAAyB,EACzB,eAAe,EACf,wBAAwB,EACxB,eAAe,EACf,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/image-codec",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1-next.1041.35b950c",
|
|
4
|
+
"author": "Joshua Granick and other contributors",
|
|
5
|
+
"license": "MIT",
|
|
4
6
|
"repository": {
|
|
5
7
|
"type": "git",
|
|
6
8
|
"url": "https://github.com/flighthq/flight.git",
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@flighthq/types": "0.3.
|
|
41
|
+
"@flighthq/types": "0.3.1-next.1041.35b950c"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"typescript": "^5.3.0"
|
package/src/decodeImage.test.ts
CHANGED
|
@@ -53,7 +53,14 @@ describe('decodeImagePremultiplied', () => {
|
|
|
53
53
|
fakeDecoded(),
|
|
54
54
|
);
|
|
55
55
|
registerImageDecoder('image/png', decoder);
|
|
56
|
-
await decodeImagePremultiplied(pngBytes);
|
|
56
|
+
await decodeImagePremultiplied(pngBytes, 'image/png');
|
|
57
|
+
expect(decoder).toHaveBeenCalledWith(pngBytes, { premultiplyAlpha: true });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('auto-detects the MIME type when omitted', async () => {
|
|
61
|
+
const decoder = vi.fn(async () => fakeDecoded());
|
|
62
|
+
registerImageDecoder('image/png', decoder);
|
|
63
|
+
expect(await decodeImagePremultiplied(pngBytes)).toEqual(fakeDecoded());
|
|
57
64
|
expect(decoder).toHaveBeenCalledWith(pngBytes, { premultiplyAlpha: true });
|
|
58
65
|
});
|
|
59
66
|
|
|
@@ -48,6 +48,32 @@ describe('detectImageMimeType', () => {
|
|
|
48
48
|
expect(detectImageMimeType(buf)).toBe('image/webp');
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
it('detects AVIF from its major brand', () => {
|
|
52
|
+
expect(detectImageMimeType(createFileTypeBox('avif'))).toBe('image/avif');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('detects AVIF sequences from a compatible brand', () => {
|
|
56
|
+
expect(detectImageMimeType(createFileTypeBox('mif1', 'avis'))).toBe('image/avif');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('rejects a non-AVIF or truncated file type box', () => {
|
|
60
|
+
const brandOutsideBox = new Uint8Array(20);
|
|
61
|
+
brandOutsideBox.set(createFileTypeBox('isom'));
|
|
62
|
+
writeAscii(brandOutsideBox, 16, 'avif');
|
|
63
|
+
expect(detectImageMimeType(createFileTypeBox('isom', 'mp42'))).toBeNull();
|
|
64
|
+
expect(detectImageMimeType(createFileTypeBox('avif').subarray(0, 12))).toBeNull();
|
|
65
|
+
expect(detectImageMimeType(brandOutsideBox)).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('detects ICO', () => {
|
|
69
|
+
expect(detectImageMimeType(new Uint8Array([0x00, 0x00, 0x01, 0x00]))).toBe('image/x-icon');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('detects little-endian and big-endian TIFF', () => {
|
|
73
|
+
expect(detectImageMimeType(new Uint8Array([0x49, 0x49, 0x2a, 0x00]))).toBe('image/tiff');
|
|
74
|
+
expect(detectImageMimeType(new Uint8Array([0x4d, 0x4d, 0x00, 0x2a]))).toBe('image/tiff');
|
|
75
|
+
});
|
|
76
|
+
|
|
51
77
|
it('detects BMP', () => {
|
|
52
78
|
const buf = new ArrayBuffer(16);
|
|
53
79
|
new Uint8Array(buf).set([0x42, 0x4d]);
|
|
@@ -58,3 +84,19 @@ describe('detectImageMimeType', () => {
|
|
|
58
84
|
expect(detectImageMimeType(new Uint8Array([0x89, 0x50, 0x4e, 0x47]))).toBe('image/png');
|
|
59
85
|
});
|
|
60
86
|
});
|
|
87
|
+
|
|
88
|
+
function createFileTypeBox(majorBrand: string, ...compatibleBrands: string[]): Uint8Array {
|
|
89
|
+
const bytes = new Uint8Array(16 + compatibleBrands.length * 4);
|
|
90
|
+
const size = bytes.byteLength;
|
|
91
|
+
bytes.set([(size >>> 24) & 0xff, (size >>> 16) & 0xff, (size >>> 8) & 0xff, size & 0xff]);
|
|
92
|
+
writeAscii(bytes, 4, 'ftyp');
|
|
93
|
+
writeAscii(bytes, 8, majorBrand);
|
|
94
|
+
for (let index = 0; index < compatibleBrands.length; index++) {
|
|
95
|
+
writeAscii(bytes, 16 + index * 4, compatibleBrands[index]);
|
|
96
|
+
}
|
|
97
|
+
return bytes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function writeAscii(bytes: Uint8Array, offset: number, value: string): void {
|
|
101
|
+
for (let index = 0; index < 4; index++) bytes[offset + index] = value.charCodeAt(index);
|
|
102
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { explainImageDecodeFailure } from './explainImageDecodeFailure';
|
|
4
|
+
import { clearImageDecoders, registerImageDecoder } from './imageDecoderRegistry';
|
|
5
|
+
|
|
6
|
+
const pngBytes = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
clearImageDecoders();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('explainImageDecodeFailure', () => {
|
|
13
|
+
it('distinguishes an undetected MIME type from a missing decoder', () => {
|
|
14
|
+
expect(explainImageDecodeFailure(new Uint8Array([0, 1, 2, 3]))).toEqual({
|
|
15
|
+
mimeType: null,
|
|
16
|
+
reason: 'mime-type-undetected',
|
|
17
|
+
});
|
|
18
|
+
expect(explainImageDecodeFailure(pngBytes)).toEqual({
|
|
19
|
+
mimeType: 'image/png',
|
|
20
|
+
reason: 'decoder-not-registered',
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('reports the explicit MIME type when its decoder is missing', () => {
|
|
25
|
+
expect(explainImageDecodeFailure(pngBytes, 'image/custom')).toEqual({
|
|
26
|
+
mimeType: 'image/custom',
|
|
27
|
+
reason: 'decoder-not-registered',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('returns null without invoking a registered decoder', () => {
|
|
32
|
+
const decoder = vi.fn();
|
|
33
|
+
registerImageDecoder('image/png', decoder);
|
|
34
|
+
expect(explainImageDecodeFailure(pngBytes)).toBeNull();
|
|
35
|
+
expect(decoder).not.toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { explainImageEncodeFailure } from './explainImageEncodeFailure';
|
|
4
|
+
import { clearImageEncoders, registerImageEncoder } from './imageEncoderRegistry';
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
clearImageEncoders();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('explainImageEncodeFailure', () => {
|
|
11
|
+
it('reports a missing encoder and its requested MIME type', () => {
|
|
12
|
+
expect(explainImageEncodeFailure('image/custom')).toEqual({
|
|
13
|
+
mimeType: 'image/custom',
|
|
14
|
+
reason: 'encoder-not-registered',
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns null without invoking a registered encoder', () => {
|
|
19
|
+
const encoder = vi.fn();
|
|
20
|
+
registerImageEncoder('image/png', encoder);
|
|
21
|
+
expect(explainImageEncodeFailure('image/png')).toBeNull();
|
|
22
|
+
expect(encoder).not.toHaveBeenCalled();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ImageBitmapComposer } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
clearImageBitmapComposers,
|
|
5
|
+
getImageBitmapComposer,
|
|
6
|
+
getImageBitmapComposerKinds,
|
|
7
|
+
hasImageBitmapComposer,
|
|
8
|
+
registerImageBitmapComposer,
|
|
9
|
+
unregisterImageBitmapComposer,
|
|
10
|
+
} from './imageBitmapComposerRegistry';
|
|
11
|
+
|
|
12
|
+
const composer: ImageBitmapComposer = () => null;
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
clearImageBitmapComposers();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('clearImageBitmapComposers', () => {
|
|
19
|
+
it('removes every registered composer', () => {
|
|
20
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
21
|
+
clearImageBitmapComposers();
|
|
22
|
+
|
|
23
|
+
expect(hasImageBitmapComposer('acme/raw-raster')).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('getImageBitmapComposer', () => {
|
|
28
|
+
it('returns the registered composer or null for a missing kind', () => {
|
|
29
|
+
expect(getImageBitmapComposer('acme/raw-raster')).toBeNull();
|
|
30
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
31
|
+
|
|
32
|
+
expect(getImageBitmapComposer('acme/raw-raster')).toBe(composer);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('getImageBitmapComposerKinds', () => {
|
|
37
|
+
it('returns an insertion-ordered enumeration detached from registry state', () => {
|
|
38
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
39
|
+
expect(getImageBitmapComposerKinds()).toEqual(['acme/raw-raster']);
|
|
40
|
+
(getImageBitmapComposerKinds() as string[]).length = 0;
|
|
41
|
+
|
|
42
|
+
expect(getImageBitmapComposerKinds()).toEqual(['acme/raw-raster']);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('hasImageBitmapComposer', () => {
|
|
47
|
+
it('reports whether a kind is registered', () => {
|
|
48
|
+
expect(hasImageBitmapComposer('acme/raw-raster')).toBe(false);
|
|
49
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
50
|
+
|
|
51
|
+
expect(hasImageBitmapComposer('acme/raw-raster')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('registerImageBitmapComposer', () => {
|
|
56
|
+
it('uses the final registration for a kind', () => {
|
|
57
|
+
const replacement: ImageBitmapComposer = () => null;
|
|
58
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
59
|
+
registerImageBitmapComposer('acme/raw-raster', replacement);
|
|
60
|
+
|
|
61
|
+
expect(getImageBitmapComposer('acme/raw-raster')).toBe(replacement);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('unregisterImageBitmapComposer', () => {
|
|
66
|
+
it('removes one registered kind', () => {
|
|
67
|
+
registerImageBitmapComposer('acme/raw-raster', composer);
|
|
68
|
+
unregisterImageBitmapComposer('acme/raw-raster');
|
|
69
|
+
|
|
70
|
+
expect(getImageBitmapComposer('acme/raw-raster')).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -3,6 +3,7 @@ import type { DecodedImage, ImageDecoder } from '@flighthq/types/contract';
|
|
|
3
3
|
import {
|
|
4
4
|
clearImageDecoders,
|
|
5
5
|
getImageDecoder,
|
|
6
|
+
getImageDecoderMimeTypes,
|
|
6
7
|
hasImageDecoder,
|
|
7
8
|
registerImageDecoder,
|
|
8
9
|
unregisterImageDecoder,
|
|
@@ -39,6 +40,20 @@ describe('getImageDecoder', () => {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
|
|
43
|
+
describe('getImageDecoderMimeTypes', () => {
|
|
44
|
+
it('returns an empty snapshot before registration', () => {
|
|
45
|
+
expect(getImageDecoderMimeTypes()).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns an insertion-ordered snapshot isolated from the registry', () => {
|
|
49
|
+
registerImageDecoder('image/png', fakeDecoder);
|
|
50
|
+
registerImageDecoder('image/jpeg', fakeDecoder);
|
|
51
|
+
const mimeTypes = getImageDecoderMimeTypes() as string[];
|
|
52
|
+
mimeTypes.push('image/webp');
|
|
53
|
+
expect(getImageDecoderMimeTypes()).toEqual(['image/png', 'image/jpeg']);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
42
57
|
describe('hasImageDecoder', () => {
|
|
43
58
|
it('reflects registration state', () => {
|
|
44
59
|
expect(hasImageDecoder('image/png')).toBe(false);
|
|
@@ -3,6 +3,7 @@ import type { ImageEncoder } from '@flighthq/types/contract';
|
|
|
3
3
|
import {
|
|
4
4
|
clearImageEncoders,
|
|
5
5
|
getImageEncoder,
|
|
6
|
+
getImageEncoderMimeTypes,
|
|
6
7
|
hasImageEncoder,
|
|
7
8
|
registerImageEncoder,
|
|
8
9
|
unregisterImageEncoder,
|
|
@@ -35,6 +36,20 @@ describe('getImageEncoder', () => {
|
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
|
|
39
|
+
describe('getImageEncoderMimeTypes', () => {
|
|
40
|
+
it('returns an empty snapshot before registration', () => {
|
|
41
|
+
expect(getImageEncoderMimeTypes()).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns an insertion-ordered snapshot isolated from the registry', () => {
|
|
45
|
+
registerImageEncoder('image/png', fakeEncoder);
|
|
46
|
+
registerImageEncoder('image/jpeg', fakeEncoder);
|
|
47
|
+
const mimeTypes = getImageEncoderMimeTypes() as string[];
|
|
48
|
+
mimeTypes.push('image/webp');
|
|
49
|
+
expect(getImageEncoderMimeTypes()).toEqual(['image/png', 'image/jpeg']);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
38
53
|
describe('hasImageEncoder', () => {
|
|
39
54
|
it('reflects registration state', () => {
|
|
40
55
|
expect(hasImageEncoder('image/png')).toBe(false);
|
|
@@ -6,6 +6,12 @@ import { registerWebImageDecoders } from './registerWebImageDecoders';
|
|
|
6
6
|
// jsdom / node lack createImageBitmap + OffscreenCanvas + Blob; these minimal stand-ins let the
|
|
7
7
|
// canvas decoder run. getImageData always returns straight (non-premultiplied) RGBA, matching the browser.
|
|
8
8
|
const straightPixels = [200, 100, 50, 128];
|
|
9
|
+
let bitmapCloseMock: ReturnType<typeof vi.fn>;
|
|
10
|
+
let createImageBitmapMock: ReturnType<typeof vi.fn>;
|
|
11
|
+
|
|
12
|
+
class MockBlob {
|
|
13
|
+
constructor(readonly parts: readonly unknown[]) {}
|
|
14
|
+
}
|
|
9
15
|
|
|
10
16
|
class MockOffscreenCanvas {
|
|
11
17
|
constructor(
|
|
@@ -13,7 +19,8 @@ class MockOffscreenCanvas {
|
|
|
13
19
|
readonly height: number,
|
|
14
20
|
) {}
|
|
15
21
|
|
|
16
|
-
getContext(): unknown {
|
|
22
|
+
getContext(contextId: string): unknown {
|
|
23
|
+
if (contextId !== '2d') return null;
|
|
17
24
|
return {
|
|
18
25
|
drawImage: vi.fn(),
|
|
19
26
|
getImageData: () => ({ data: new Uint8ClampedArray(straightPixels) }),
|
|
@@ -22,17 +29,11 @@ class MockOffscreenCanvas {
|
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
beforeEach(() => {
|
|
25
|
-
vi.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
32
|
+
bitmapCloseMock = vi.fn();
|
|
33
|
+
createImageBitmapMock = vi.fn(async () => ({ width: 1, height: 1, close: bitmapCloseMock }));
|
|
34
|
+
vi.stubGlobal('createImageBitmap', createImageBitmapMock);
|
|
29
35
|
vi.stubGlobal('OffscreenCanvas', MockOffscreenCanvas);
|
|
30
|
-
vi.stubGlobal(
|
|
31
|
-
'Blob',
|
|
32
|
-
class {
|
|
33
|
-
constructor(readonly parts: readonly unknown[]) {}
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
+
vi.stubGlobal('Blob', MockBlob);
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
afterEach(() => {
|
|
@@ -55,6 +56,18 @@ describe('registerWebImageDecoders', () => {
|
|
|
55
56
|
expect(result.width).toBe(1);
|
|
56
57
|
expect(result.height).toBe(1);
|
|
57
58
|
expect(Array.from(result.data)).toEqual(straightPixels);
|
|
59
|
+
expect(bitmapCloseMock).toHaveBeenCalledOnce();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('forwards only the bytes inside the supplied view to createImageBitmap', async () => {
|
|
63
|
+
registerWebImageDecoders();
|
|
64
|
+
const decoder = getImageDecoder('image/png');
|
|
65
|
+
const backing = new Uint8Array([1, 2, 3, 4, 5, 6]);
|
|
66
|
+
|
|
67
|
+
await decoder!(backing.subarray(1, 5));
|
|
68
|
+
|
|
69
|
+
const blob = createImageBitmapMock.mock.calls[0][0] as MockBlob;
|
|
70
|
+
expect(Array.from(blob.parts[0] as Uint8Array)).toEqual([2, 3, 4, 5]);
|
|
58
71
|
});
|
|
59
72
|
|
|
60
73
|
it('premultiplies the straight result when premultiplyAlpha is requested', async () => {
|
|
@@ -16,7 +16,8 @@ class MockOffscreenCanvas {
|
|
|
16
16
|
readonly height: number,
|
|
17
17
|
) {}
|
|
18
18
|
|
|
19
|
-
getContext(): unknown {
|
|
19
|
+
getContext(contextId: string): unknown {
|
|
20
|
+
if (contextId !== '2d') return null;
|
|
20
21
|
return { putImageData: vi.fn() };
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -25,22 +26,25 @@ class MockOffscreenCanvas {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
class MockImageData {
|
|
30
|
+
constructor(
|
|
31
|
+
readonly data: Uint8ClampedArray,
|
|
32
|
+
readonly width: number,
|
|
33
|
+
readonly height: number,
|
|
34
|
+
) {
|
|
35
|
+
if (data.length !== width * height * 4) {
|
|
36
|
+
throw new DOMException('ImageData data length must equal width * height * 4', 'IndexSizeError');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
function fakeImage(): DecodedImage {
|
|
29
42
|
return { data: new Uint8ClampedArray([10, 20, 30, 255]), width: 1, height: 1 };
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
beforeEach(() => {
|
|
33
46
|
vi.stubGlobal('OffscreenCanvas', MockOffscreenCanvas);
|
|
34
|
-
vi.stubGlobal(
|
|
35
|
-
'ImageData',
|
|
36
|
-
class {
|
|
37
|
-
constructor(
|
|
38
|
-
readonly data: Uint8ClampedArray,
|
|
39
|
-
readonly width: number,
|
|
40
|
-
readonly height: number,
|
|
41
|
-
) {}
|
|
42
|
-
},
|
|
43
|
-
);
|
|
47
|
+
vi.stubGlobal('ImageData', MockImageData);
|
|
44
48
|
});
|
|
45
49
|
|
|
46
50
|
afterEach(() => {
|