import type { ImageError, Result, TextureAsset } from '@forgeax/engine-types'; /** * Decode a PNG / JPEG byte stream into a `TextureAsset` POD. * * Runtime SDK entry for AI users who hold image bytes (fetched over the * network, embedded as base64, produced by an out-of-tree decoder, etc.) and * want to feed them into `world.allocSharedRef('TextureAsset', pod)` + * `GpuResourceStore.ensureResident` without the disk-side importer / build * pipeline in the loop (charter P1 progressive disclosure: one-step "bytes * in, POD out"). * * v1 supports the two universally-decodable mime types: `image/png` and * `image/jpeg`. Failure surfaces are all structured via the closed * `ImageError` union (`.code` / `.expected` / `.hint` / `.detail`); the * function never throws for expected failures (AGENTS.md Error model + * charter P3 explicit failure). * * Error codes possible (subset of the closed `ImageErrorCode` union): * - `image-format-unsupported` -- mime not in the v1 whitelist (`detail.actualMime`) * - `image-decode-failed` -- decoder rejected the bytes, or the environment * lacks `createImageBitmap` (`detail.reason`) * * @param bytes - Encoded image byte stream (`Uint8Array` or `ArrayBuffer`). * @param mime - Byte-stream mime type. v1 whitelist: `'image/png' | 'image/jpeg'`. * @param opts - Optional decode overrides: * - `colorSpace`: `'srgb'` (default) or `'linear'`. Derives POD `format`: * `srgb -> 'rgba8unorm-srgb'`, `linear -> 'rgba8unorm'`. * - `mipmap`: `true` (default) or `false`. When true, the producer requests * generated mips; when false, it keeps one authored level. * @returns `ok(TextureAsset)` on success; `err(ImageError)` on failure. * * @example * ```ts * import { decodeImageBytes } from '@forgeax/engine-assets-runtime'; * * const bytes = new Uint8Array(await (await fetch(url)).arrayBuffer()); * const result = await decodeImageBytes(bytes, 'image/png'); * if (!result.ok) { * // The ImageError code and detail are one correlated discriminated union. * switch (result.error.code) { * case 'image-format-unsupported': * console.error('bad mime:', result.error.detail.actualMime); * break; * case 'image-decode-failed': * console.error('decode reason:', result.error.detail.reason); * break; * } * return; * } * const handle = world.allocSharedRef('TextureAsset', result.value); * ``` */ export declare function decodeImageBytes(bytes: Uint8Array | ArrayBuffer, mime: string, opts?: { colorSpace?: 'srgb' | 'linear'; mipmap?: boolean; }): Promise>; //# sourceMappingURL=decode-image-bytes.d.ts.map