@flighthq/image 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.
@@ -1,3 +1,5 @@
1
+ export * from './imageBackend';
1
2
  export * from './imageResource';
2
3
  export * from './imageResourceFrom';
4
+ export * from './imageResourceReference';
3
5
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC"}
package/dist/contract.js CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './imageBackend';
1
2
  export * from './imageResource';
2
3
  export * from './imageResourceFrom';
4
+ export * from './imageResourceReference';
3
5
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ImageBackend } from '@flighthq/types/contract';
2
+ export declare function createWebImageBackend(): ImageBackend;
3
+ export declare function getImageBackend(): ImageBackend;
4
+ export declare function setImageBackend(backend: ImageBackend | null): void;
5
+ //# sourceMappingURL=imageBackend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageBackend.d.ts","sourceRoot":"","sources":["../src/imageBackend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAYpE,wBAAgB,qBAAqB,IAAI,YAAY,CA8BpD;AAGD,wBAAgB,eAAe,IAAI,YAAY,CAG9C;AAKD,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAElE"}
@@ -0,0 +1,57 @@
1
+ import { createImageResourceFromImageElement } from './imageResourceFrom';
2
+ // Builds the default web backend over `Image` + `decode()`. Created lazily by `getImageBackend` — no
3
+ // DOM is touched at import time, so importing the package has no side effect.
4
+ //
5
+ // ★ THIS BODY IS THE PREVIOUS `loadImageResourceFromUrl` MOVED VERBATIM, INCLUDING ITS KNOWN ABORT
6
+ // RACE: aborting rejects the caller and clears `src`, but the underlying load may already be in
7
+ // flight and is not guaranteed to stop. That defect is preserved deliberately rather than repaired
8
+ // here — this change is the seam, and fixing behaviour while relocating it would make the seam
9
+ // unreviewable against the approval that authorised it.
10
+ export function createWebImageBackend() {
11
+ return {
12
+ async loadImageFromUrl(url, crossOrigin, signal) {
13
+ signal?.throwIfAborted();
14
+ const img = new Image();
15
+ if (crossOrigin !== undefined)
16
+ img.crossOrigin = crossOrigin;
17
+ img.src = url;
18
+ // Wire abort to cancel the pending decode and reject with the signal's reason. Always remove the
19
+ // listener when the race settles so a long-lived signal does not retain the image and closure.
20
+ if (signal !== undefined) {
21
+ let rejectAbort = () => { };
22
+ const abortPromise = new Promise((_, reject) => {
23
+ rejectAbort = reject;
24
+ });
25
+ const onAbort = () => {
26
+ img.src = '';
27
+ rejectAbort(signal.reason);
28
+ };
29
+ signal.addEventListener('abort', onAbort, { once: true });
30
+ try {
31
+ await Promise.race([img.decode(), abortPromise]);
32
+ }
33
+ finally {
34
+ signal.removeEventListener('abort', onAbort);
35
+ }
36
+ }
37
+ else {
38
+ await img.decode();
39
+ }
40
+ return createImageResourceFromImageElement(img);
41
+ },
42
+ };
43
+ }
44
+ // The active image backend, lazily defaulting to the web one. There is always a backend.
45
+ export function getImageBackend() {
46
+ if (_backend === null)
47
+ _backend = createWebImageBackend();
48
+ return _backend;
49
+ }
50
+ // Installs a native host image backend; pass null to fall back to the lazy web default. Resettable on
51
+ // purpose: a seam a caller cannot restore is a one-way door, and a test that swapped the backend could
52
+ // not put it back.
53
+ export function setImageBackend(backend) {
54
+ _backend = backend;
55
+ }
56
+ let _backend = null;
57
+ //# sourceMappingURL=imageBackend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageBackend.js","sourceRoot":"","sources":["../src/imageBackend.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAE1E,qGAAqG;AACrG,8EAA8E;AAC9E,EAAE;AACF,mGAAmG;AACnG,gGAAgG;AAChG,mGAAmG;AACnG,+FAA+F;AAC/F,wDAAwD;AACxD,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,KAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM;YAC7C,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,WAAW,KAAK,SAAS;gBAAE,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;YAC7D,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;YACd,iGAAiG;YACjG,+FAA+F;YAC/F,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,WAAW,GAA+B,GAAG,EAAE,GAAE,CAAC,CAAC;gBACvD,MAAM,YAAY,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;oBACpD,WAAW,GAAG,MAAM,CAAC;gBACvB,CAAC,CAAC,CAAC;gBACH,MAAM,OAAO,GAAG,GAAS,EAAE;oBACzB,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;oBACb,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC7B,CAAC,CAAC;gBACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;gBACnD,CAAC;wBAAS,CAAC;oBACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YACrB,CAAC;YACD,OAAO,mCAAmC,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,eAAe;IAC7B,IAAI,QAAQ,KAAK,IAAI;QAAE,QAAQ,GAAG,qBAAqB,EAAE,CAAC;IAC1D,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,sGAAsG;AACtG,uGAAuG;AACvG,mBAAmB;AACnB,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,QAAQ,GAAG,OAAO,CAAC;AACrB,CAAC;AAED,IAAI,QAAQ,GAAwB,IAAI,CAAC"}
@@ -1,13 +1,7 @@
1
- import type { ImageResource, ImageResourceCompressed } from '@flighthq/types/contract';
2
- export declare function cloneImageResource(resource: Readonly<ImageResource>): ImageResource;
3
- export declare function createCompressedImageResource(compressed: Readonly<ImageResourceCompressed>): ImageResource;
4
- export declare function createImageResource(image?: CanvasImageSource): ImageResource;
5
- export declare function disposeImageResource(resource: ImageResource): void;
6
- export declare function getImageResourceByteSize(resource: Readonly<ImageResource>): number;
7
- export declare function hasImageResourceData(resource: Readonly<ImageResource>): boolean;
8
- export declare function hasImageResourcePixels(resource: Readonly<ImageResource>): boolean;
9
- export declare function hasImageResourceSource(resource: Readonly<ImageResource>): boolean;
10
- export declare function invalidateImageResource(resource: ImageResource): void;
11
- export declare function isImageResourceEmpty(resource: Readonly<ImageResource>): boolean;
12
- export declare function setImageResourceSource(resource: ImageResource, element: CanvasImageSource | null): void;
1
+ import type { CompressedImage, CompressedImageData, Image } from '@flighthq/types/contract';
2
+ export declare function cloneImageResource(resource: Readonly<Image>): Image;
3
+ export declare function createCompressedImage(compressed: Readonly<CompressedImageData>): CompressedImage;
4
+ export declare function createImageResource(image: CanvasImageSource): Image;
5
+ export declare function invalidateImageResource(resource: Image): void;
6
+ export declare function isImageResourceEmpty(resource: Readonly<Image>): boolean;
13
7
  //# sourceMappingURL=imageResource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageResource.d.ts","sourceRoot":"","sources":["../src/imageResource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAMvF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,aAAa,CAWnF;AAMD,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,QAAQ,CAAC,uBAAuB,CAAC,GAAG,aAAa,CAW1G;AAED,wBAAgB,mBAAmB,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,aAAa,CAa5E;AAMD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAKlE;AAMD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,MAAM,CAElF;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,OAAO,CAE/E;AAQD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,OAAO,CAEjF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,OAAO,CAEjF;AAKD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAErE;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,OAAO,CAE/E;AAID,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,IAAI,CAIvG"}
1
+ {"version":3,"file":"imageResource.d.ts","sourceRoot":"","sources":["../src/imageResource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAK5F,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAUnE;AAID,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,eAAe,CAUhG;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,GAAG,KAAK,CAYnE;AAGD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,CAG7D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAEvE"}
@@ -1,104 +1,58 @@
1
1
  import { createEntity } from '@flighthq/entity/contract';
2
- // Allocates a new resource identity over the SAME underlying pixels. The element, the `data` array, and
3
- // the `compressed` payload are shared by reference, not duplicated — clone gives you an independent
4
- // version counter and entity identity over the same pixels, e.g. to upload one image into two render
5
- // states with separate invalidation. Use a Surface copy when you need the pixels themselves duplicated.
2
+ import { CompressedImageTextureSourceKind, ImageTextureSourceKind } from '@flighthq/types/contract';
3
+ // Allocates a new resource identity over the same borrowed host image. The host handle is shared by
4
+ // reference; the clone owns an independent version counter for renderer cache invalidation.
6
5
  export function cloneImageResource(resource) {
7
6
  return createEntity({
8
7
  alphaType: resource.alphaType,
9
- compressed: resource.compressed,
10
- data: resource.data,
11
- format: resource.format,
8
+ gamut: resource.gamut,
12
9
  height: resource.height,
10
+ kind: resource.kind,
13
11
  source: resource.source,
14
12
  version: resource.version,
15
13
  width: resource.width,
16
14
  });
17
15
  }
18
- // Wraps a parsed block-compressed (KTX2/DDS/Basis) payload as an ImageResource. `width`/`height` mirror
19
- // the container's base-mip dimensions so the same 2D draw path sizes the quad; `source`/`data` stay null
20
- // (a GPU backend uploads the `compressed` payload instead, and a Canvas/DOM backend ignores it). The
21
- // caller owns the payload bytes the container's level ranges index into.
22
- export function createCompressedImageResource(compressed) {
16
+ // Wraps a parsed block-compressed payload as its own GPU-only source. The caller owns the payload
17
+ // bytes indexed by the container's level ranges.
18
+ export function createCompressedImage(compressed) {
23
19
  return createEntity({
24
- alphaType: 'straight',
20
+ alphaType: DECODED_ALPHA_TYPE,
25
21
  compressed,
26
- data: null,
27
- format: 'rgba8unorm',
22
+ gamut: DECODED_GAMUT,
28
23
  height: compressed.container.height,
29
- source: null,
24
+ kind: CompressedImageTextureSourceKind,
30
25
  version: 0,
31
26
  width: compressed.container.width,
32
27
  });
33
28
  }
34
29
  export function createImageResource(image) {
35
30
  const resource = createEntity({
36
- alphaType: 'straight',
37
- compressed: null,
38
- data: null,
39
- format: 'rgba8unorm',
31
+ alphaType: DECODED_ALPHA_TYPE,
32
+ gamut: DECODED_GAMUT,
40
33
  height: 0,
41
- source: image ?? null,
34
+ kind: ImageTextureSourceKind,
35
+ source: image,
42
36
  version: 0,
43
37
  width: 0,
44
38
  });
45
- if (resource.source !== null)
46
- updateImageResourceSize(resource);
39
+ updateImageResourceSize(resource);
47
40
  return resource;
48
41
  }
49
- // Releases the element and raw-data references so they become eligible for GC, and marks the resource
50
- // changed. This does NOT free the backend GPU texture (that is owned per render state — call the
51
- // backend's destroy*Texture) and does NOT close an owned ImageBitmap (ownership is ambiguous; close it
52
- // explicitly if you own it). Dimensions are left intact; setImageResourceSource repopulates the resource.
53
- export function disposeImageResource(resource) {
54
- resource.compressed = null;
55
- resource.data = null;
56
- resource.source = null;
57
- invalidateImageResource(resource);
58
- }
59
- // Returns the byte footprint of the CPU-side pixel data (`data` array). Returns 0 when `data` is
60
- // null (element-only resource — the GPU texture footprint is tracked by the render state, not here).
61
- // For `rgba8unorm` (the default) the result equals width × height × 4; other formats are not yet
62
- // exercised but the formula still applies (byteLength of the actual buffer is authoritative).
63
- export function getImageResourceByteSize(resource) {
64
- return resource.data !== null ? resource.data.byteLength : 0;
65
- }
66
- export function hasImageResourceData(resource) {
67
- return resource.data !== null;
68
- }
69
- // True when the resource carries pixels in any representation — a decoded `source` element, raw CPU
70
- // `data`, or a block-`compressed` payload. The upload-readiness predicate for backends that can consume
71
- // any of them: an element-only load, a data-only generated Surface, a compressed-only parsed container,
72
- // or a resource holding several are all uploadable. Prefer this over hasImageResourceSource at any gate
73
- // that feeds a source-or-data uploader (bindGlTexture, bindWgpuTexture), so a memory-generated Surface
74
- // or a compressed container is not rejected for lacking an element.
75
- export function hasImageResourcePixels(resource) {
76
- return resource.source !== null || resource.data !== null || resource.compressed !== null;
77
- }
78
- export function hasImageResourceSource(resource) {
79
- return resource.source !== null;
80
- }
81
- // Bumps the resource content revision so consumers (renderer texture caches) know the pixels behind
82
- // this image changed even though the object identity is the same. Call after mutating the backing
83
- // pixels in place; the Surface API calls it for you. Resource-tier analog of invalidateNodeLocalContent.
42
+ // Marks changed pixels behind the same borrowed host handle. The handle itself remains immutable.
84
43
  export function invalidateImageResource(resource) {
44
+ updateImageResourceSize(resource);
85
45
  resource.version = (resource.version + 1) >>> 0;
86
46
  }
87
47
  export function isImageResourceEmpty(resource) {
88
48
  return resource.width <= 0 || resource.height <= 0;
89
49
  }
90
- // Swaps the element representation, re-reads its dimensions, and marks the resource changed. Pass
91
- // null to clear the element (dimensions are left intact; use disposeImageResource to release for GC).
92
- export function setImageResourceSource(resource, element) {
93
- resource.source = element;
94
- if (element !== null)
95
- updateImageResourceSize(resource);
96
- invalidateImageResource(resource);
97
- }
98
- // Reads pixel dimensions from the current (non-null) element. Video sources carry their size on
50
+ // Reads pixel dimensions from the current host element. Video sources carry their size on
99
51
  // videoWidth/videoHeight; every other CanvasImageSource exposes width/height directly.
100
52
  function updateImageResourceSize(resource) {
101
53
  const element = resource.source;
54
+ if (element === null)
55
+ return;
102
56
  if (element instanceof HTMLVideoElement) {
103
57
  resource.width = element.videoWidth;
104
58
  resource.height = element.videoHeight;
@@ -109,4 +63,11 @@ function updateImageResourceSize(resource) {
109
63
  resource.height = sized.height;
110
64
  }
111
65
  }
66
+ // What a HOST decode yields, and the only honest default for a source whose pixels we never touch.
67
+ // Every browser image/canvas/ImageBitmap decode is straight-alpha sRGB, so declaring it is a statement
68
+ // of fact rather than an assumption — which is the point: a producer that knows otherwise (a native
69
+ // iOS/Android decode commonly premultiplies) now has somewhere to say so, and the uploaders' existing
70
+ // `alphaType !== 'premultiplied'` guard starts protecting Image the way it already protects Bitmap.
71
+ const DECODED_ALPHA_TYPE = 'straight';
72
+ const DECODED_GAMUT = 'srgb';
112
73
  //# sourceMappingURL=imageResource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageResource.js","sourceRoot":"","sources":["../src/imageResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,wGAAwG;AACxG,oGAAoG;AACpG,qGAAqG;AACrG,wGAAwG;AACxG,MAAM,UAAU,kBAAkB,CAAC,QAAiC;IAClE,OAAO,YAAY,CAAC;QAClB,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB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C;IACjC,CAAC;AACH,CAAC;AAED,mGAAmG;AACnG,uGAAuG;AACvG,oGAAoG;AACpG,sGAAsG;AACtG,oGAAoG;AACpG,MAAM,kBAAkB,GAAG,UAAU,CAAC;AACtC,MAAM,aAAa,GAAG,MAAM,CAAC"}
@@ -1,11 +1,11 @@
1
- import type { ImageResource } from '@flighthq/types/contract';
2
- export declare function createCanvasFromImageResource(image: Readonly<ImageResource>): HTMLCanvasElement | null;
3
- export declare function createImageResourceFromCanvas(canvas: HTMLCanvasElement): ImageResource;
4
- export declare function createImageResourceFromImageBitmap(bitmap: ImageBitmap): ImageResource;
5
- export declare function createImageResourceFromImageElement(img: HTMLImageElement): ImageResource;
6
- export declare function isImageResourceSameOrigin(url: string): boolean;
7
- export declare function loadImageResourceFromBase64(base64: string, mimeType: string, signal?: AbortSignal): Promise<ImageResource>;
8
- export declare function loadImageResourceFromBlob(blob: Blob, signal?: AbortSignal): Promise<ImageResource>;
9
- export declare function loadImageResourceFromBytes(bytes: Uint8Array, mimeType?: string, signal?: AbortSignal): Promise<ImageResource>;
10
- export declare function loadImageResourceFromUrl(url: string, crossOrigin?: string, signal?: AbortSignal): Promise<ImageResource>;
1
+ import type { Bitmap, Image } from '@flighthq/types/contract';
2
+ export declare function createImageResourceFromBitmap(bitmap: Readonly<Bitmap>): Image;
3
+ export declare function createImageResourceFromCanvas(canvas: HTMLCanvasElement): Image;
4
+ export declare function createImageResourceFromImageBitmap(bitmap: ImageBitmap): Image;
5
+ export declare function createImageResourceFromImageElement(img: HTMLImageElement): Image;
6
+ export declare function isImageUrlSameOrigin(url: string): boolean;
7
+ export declare function loadImageResourceFromBase64(base64: string, mimeType: string, signal?: AbortSignal): Promise<Image>;
8
+ export declare function loadImageResourceFromBlob(blob: Blob, signal?: AbortSignal): Promise<Image>;
9
+ export declare function loadImageResourceFromBytes(bytes: Uint8Array, mimeType?: string, signal?: AbortSignal): Promise<Image>;
10
+ export declare function loadImageResourceFromUrl(url: string, crossOrigin?: 'anonymous' | 'use-credentials', signal?: AbortSignal): Promise<Image>;
11
11
  //# sourceMappingURL=imageResourceFrom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageResourceFrom.d.ts","sourceRoot":"","sources":["../src/imageResourceFrom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQ9D,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,iBAAiB,GAAG,IAAI,CAStG;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,iBAAiB,GAAG,aAAa,CAWtF;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa,CAWrF;AAED,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,CAWxF;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAExB;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAOxG;AAED,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAexB"}
1
+ {"version":3,"file":"imageResourceFrom.d.ts","sourceRoot":"","sources":["../src/imageResourceFrom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAS9D,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,CAQ7E;AAsBD,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,iBAAiB,GAAG,KAAK,CAU9E;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAU7E;AAED,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,gBAAgB,GAAG,KAAK,CAUhF;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,KAAK,CAAC,CAEhB;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAOhG;AAED,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,KAAK,CAAC,CAOhB;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,WAAW,GAAG,iBAAiB,EAC7C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,KAAK,CAAC,CAEhB"}
@@ -1,29 +1,45 @@
1
1
  import { createEntity } from '@flighthq/entity/contract';
2
2
  import { detectImageMimeType } from '@flighthq/image-codec/contract';
3
- // Materializes a data-backed ImageResource's raw pixels into a detached, drawable HTMLCanvasElement
4
- // via putImageData. The inverse of createImageResourceFromCanvas: it turns the portable `data`
5
- // representation of a generated Surface into the host element that Canvas/DOM `drawImage` needs.
6
- // Returns null for an element-only resource (no `data` to transcode). Straight-alpha in, straight-alpha
7
- // out — the drawn canvas matches the source's `alphaType`. Callers that draw data-only resources cache
8
- // the result keyed on `version`; this primitive allocates a fresh canvas on every call.
9
- export function createCanvasFromImageResource(image) {
10
- if (image.data === null)
11
- return null;
3
+ import { ImageTextureSourceKind } from '@flighthq/types/contract';
4
+ import { getImageBackend } from './imageBackend';
5
+ // Transcodes a Bitmap's raw pixels into an element-backed Image, via a detached canvas.
6
+ // The inverse of captureBitmapFromImageResource. Lives here rather than in @flighthq/bitmap because a
7
+ // conversion belongs with the type it PRODUCES: you look for it under what you want to end up with.
8
+ // Allocates a fresh canvas on every call; callers that draw repeatedly should hold the result.
9
+ export function createImageResourceFromBitmap(bitmap) {
12
10
  const canvas = document.createElement('canvas');
13
- canvas.width = image.width;
14
- canvas.height = image.height;
15
- const imageData = new globalThis.ImageData(image.width, image.height);
16
- imageData.data.set(image.data);
17
- canvas.getContext('2d').putImageData(imageData, 0, 0);
18
- return canvas;
11
+ canvas.width = bitmap.width;
12
+ canvas.height = bitmap.height;
13
+ const domImageData = new globalThis.ImageData(bitmap.width, bitmap.height);
14
+ domImageData.data.set(bitmap.alphaType === 'premultiplied' ? unpremultiplyRgba8(bitmap.data) : bitmap.data);
15
+ canvas.getContext('2d').putImageData(domImageData, 0, 0);
16
+ return createImageResourceFromCanvas(canvas);
17
+ }
18
+ // ImageData is straight-alpha by contract. Preserve a Bitmap's declared representation at its own seam,
19
+ // then normalize only the scratch browser copy used to materialize a CanvasImageSource for Canvas/DOM.
20
+ function unpremultiplyRgba8(source) {
21
+ const data = new Uint8ClampedArray(source);
22
+ for (let i = 0; i < data.length; i += 4) {
23
+ const alpha = data[i + 3];
24
+ if (alpha === 0) {
25
+ data[i] = 0;
26
+ data[i + 1] = 0;
27
+ data[i + 2] = 0;
28
+ continue;
29
+ }
30
+ const scale = 255 / alpha;
31
+ data[i] = Math.min(255, Math.round(data[i] * scale));
32
+ data[i + 1] = Math.min(255, Math.round(data[i + 1] * scale));
33
+ data[i + 2] = Math.min(255, Math.round(data[i + 2] * scale));
34
+ }
35
+ return data;
19
36
  }
20
37
  export function createImageResourceFromCanvas(canvas) {
21
38
  return createEntity({
22
- alphaType: 'straight',
23
- compressed: null,
24
- data: null,
25
- format: 'rgba8unorm',
39
+ alphaType: DECODED_ALPHA_TYPE,
40
+ gamut: DECODED_GAMUT,
26
41
  height: canvas.height,
42
+ kind: ImageTextureSourceKind,
27
43
  source: canvas,
28
44
  version: 0,
29
45
  width: canvas.width,
@@ -31,11 +47,10 @@ export function createImageResourceFromCanvas(canvas) {
31
47
  }
32
48
  export function createImageResourceFromImageBitmap(bitmap) {
33
49
  return createEntity({
34
- alphaType: 'straight',
35
- compressed: null,
36
- data: null,
37
- format: 'rgba8unorm',
50
+ alphaType: DECODED_ALPHA_TYPE,
51
+ gamut: DECODED_GAMUT,
38
52
  height: bitmap.height,
53
+ kind: ImageTextureSourceKind,
39
54
  source: bitmap,
40
55
  version: 0,
41
56
  width: bitmap.width,
@@ -43,17 +58,16 @@ export function createImageResourceFromImageBitmap(bitmap) {
43
58
  }
44
59
  export function createImageResourceFromImageElement(img) {
45
60
  return createEntity({
46
- alphaType: 'straight',
47
- compressed: null,
48
- data: null,
49
- format: 'rgba8unorm',
61
+ alphaType: DECODED_ALPHA_TYPE,
62
+ gamut: DECODED_GAMUT,
50
63
  height: img.height,
64
+ kind: ImageTextureSourceKind,
51
65
  source: img,
52
66
  version: 0,
53
67
  width: img.width,
54
68
  });
55
69
  }
56
- export function isImageResourceSameOrigin(url) {
70
+ export function isImageUrlSameOrigin(url) {
57
71
  if (url.startsWith('data:') || url.startsWith('blob:'))
58
72
  return true;
59
73
  try {
@@ -84,21 +98,9 @@ export async function loadImageResourceFromBytes(bytes, mimeType, signal) {
84
98
  return loadImageResourceFromBlob(new Blob([buf], { type }), signal);
85
99
  }
86
100
  export async function loadImageResourceFromUrl(url, crossOrigin, signal) {
87
- signal?.throwIfAborted();
88
- const img = new Image();
89
- if (crossOrigin !== undefined)
90
- img.crossOrigin = crossOrigin;
91
- img.src = url;
92
- // Wire abort to cancel the pending decode by rejecting the promise.
93
- if (signal !== undefined) {
94
- await Promise.race([
95
- img.decode(),
96
- new Promise((_, reject) => signal.addEventListener('abort', () => reject(signal.reason), { once: true })),
97
- ]);
98
- }
99
- else {
100
- await img.decode();
101
- }
102
- return createImageResourceFromImageElement(img);
101
+ return getImageBackend().loadImageFromUrl(url, crossOrigin, signal);
103
102
  }
103
+ // The host-decode truth for every browser-backed source; see imageResource.ts.
104
+ const DECODED_ALPHA_TYPE = 'straight';
105
+ const DECODED_GAMUT = 'srgb';
104
106
  //# sourceMappingURL=imageResourceFrom.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageResourceFrom.js","sourceRoot":"","sources":["../src/imageResourceFrom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,oGAAoG;AACpG,+FAA+F;AAC/F,iGAAiG;AACjG,wGAAwG;AACxG,uGAAuG;AACvG,wFAAwF;AACxF,MAAM,UAAU,6BAA6B,CAAC,KAA8B;IAC1E,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC3B,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE,CAAC,YAAY,CAAC,SAAS,EAAE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AyB,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,GAAW,EACX,WAA6C,EAC7C,MAAoB;IAEpB,OAAO,eAAe,EAAE,CAAC,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC;AAED,+EAA+E;AAC/E,MAAM,kBAAkB,GAAG,UAAU,CAAC;AACtC,MAAM,aAAa,GAAG,MAAM,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { AlphaType, EmbeddedImageResourceReference, ExternalImageResourceReference, ImageResourceFailure, ImageResourceFetch, ImageResourceReference, ImageResourceReferenceResolutionExplanation, TextureSource } from '@flighthq/types/contract';
2
+ export declare function createEmbeddedImageResourceReference(bytes: Uint8Array, mimeType?: string | null, alphaType?: AlphaType): EmbeddedImageResourceReference;
3
+ export declare function createExternalImageResourceReference(uri: string, basePath?: string | null): ExternalImageResourceReference;
4
+ export declare function createImageResourceFailure(cause: unknown): ImageResourceFailure;
5
+ export declare function disableImageBitmapComposition(): void;
6
+ export declare function enableImageBitmapComposition(): void;
7
+ export declare function explainImageResourceReferenceResolution(ref: Readonly<ImageResourceReference>): ImageResourceReferenceResolutionExplanation;
8
+ export declare function resetFailedImageResourceReference(ref: ImageResourceReference): boolean;
9
+ export declare function resolveImageResourceReference(ref: ImageResourceReference, fetch: ImageResourceFetch, signal: AbortSignal): Promise<TextureSource | null>;
10
+ //# sourceMappingURL=imageResourceReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageResourceReference.d.ts","sourceRoot":"","sources":["../src/imageResourceReference.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,SAAS,EAET,8BAA8B,EAE9B,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,2CAA2C,EAC3C,aAAa,EACd,MAAM,0BAA0B,CAAC;AAWlC,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,UAAU,EACjB,QAAQ,GAAE,MAAM,GAAG,IAAW,EAC9B,SAAS,GAAE,SAAsB,GAChC,8BAA8B,CAUhC;AAgCD,wBAAgB,oCAAoC,CAClD,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAM,GAAG,IAAW,GAC7B,8BAA8B,CAUhC;AAID,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAK/E;AAwBD,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD;AAKD,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD;AAID,wBAAgB,uCAAuC,CACrD,GAAG,EAAE,QAAQ,CAAC,sBAAsB,CAAC,GACpC,2CAA2C,CAO7C;AAID,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAKtF;AAUD,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAkC/B"}