/** * BrowserDepthProvider — DepthProvider backed by Transformers.js + WebGPU/WASM. * * Adapts {@link DepthEstimationService} (browser-native depth estimation * singleton) to the {@link DepthProvider} interface consumed by * {@link createHologram}. Sprint 0a.2 deliverable. * * Backend selection: * - WebGPU when `navigator.gpu` is present (preferred — ~3× faster) * - WASM when `WebAssembly` is present * - 'cpu' luminance placeholder when Transformers.js is not installed * (returned by the underlying service) * * Image decode: * - Default: `createImageBitmap(Blob)` → `OffscreenCanvas` → `getImageData` * - Configurable via {@link BrowserDepthProviderConfig.imageDecoder} for * deterministic tests + Node fallbacks (no canvas in node-vitest). * * GIF / video sources: * - Sprint 0a.2 ships single-frame paths only. Multi-frame inputs degrade * to "decode the first frame" with `frames: 1` in the result. Multi- * frame depth lands in Sprint 0b (GIF decompose + WebCodecs video). * * @see W.148: Browser-native depth estimation is production-ready * @see D.019: HoloGram product line * @see F.016: Scope discipline — Sprint 0a.2 = providers only, no orchestration shift */ import { DepthEstimationService, type DepthEstimationConfig } from '../DepthEstimationService'; import type { DepthInferenceResult, DepthProvider } from '../createHologram'; import type { HologramSourceKind } from '../HologramBundle'; /** * Decoded pixel buffer in canvas-native ImageData shape. Provider input. */ export interface DecodedImage { /** RGBA8 pixel data, row-major, length = width * height * 4 */ data: Uint8ClampedArray; width: number; height: number; } /** * Pluggable image decoder. Receives raw bytes + source kind, returns * RGBA8 pixels. Implementations MUST NOT mutate the input bytes. */ export type ImageDecoder = (media: Uint8Array, sourceKind: HologramSourceKind) => Promise; export interface BrowserDepthProviderConfig { /** Override the singleton DepthEstimationService — useful for tests */ service?: DepthEstimationService; /** * Override the default image decoder. The default uses `createImageBitmap` * + `OffscreenCanvas`, which is unavailable in Node test environments. * Tests inject a deterministic synthetic decoder. */ imageDecoder?: ImageDecoder; /** * Forwarded to {@link DepthEstimationService.initialize} on first use. * If undefined and the service is uninitialized, defaults are used. */ estimationConfig?: DepthEstimationConfig; /** * When true, skip the lazy `service.initialize()` call. Use this when * the caller has already initialized the singleton and wants a strict * "no side effects" provider. Default: false. */ skipInitialize?: boolean; } /** * Default browser image decoder. Uses `createImageBitmap(Blob)` then * `OffscreenCanvas.getContext('2d').drawImage` + `getImageData`. * * Throws a descriptive error if the canvas APIs are unavailable so the * orchestrator's `depth_failed` wrapper carries a useful message instead * of a cryptic `is not a function`. Tests must inject `imageDecoder`. */ export declare const defaultBrowserImageDecoder: ImageDecoder; /** * BrowserDepthProvider — implementation of {@link DepthProvider} using the * browser-native {@link DepthEstimationService} (Transformers.js + WebGPU). * * Stateless aside from the underlying singleton. Constructing the provider * does NOT initialize the depth model — initialization is lazy on first * `infer()` call so that orchestrators which never call `infer()` (e.g., * tests that exercise validation paths) don't pay the model-download cost. */ export declare class BrowserDepthProvider implements DepthProvider { private readonly service; private readonly imageDecoder; private readonly estimationConfig; private readonly skipInitialize; private initPromise; constructor(config?: BrowserDepthProviderConfig); infer(media: Uint8Array, sourceKind: HologramSourceKind): Promise; /** * Reach into the service's private config to surface the modelId. The * service exposes `backend` publicly but not `modelId`; we read it via * the constructor-stored config object on the singleton. This is * intentional: we want the bundle's `meta.modelId` to reflect what the * service actually used, not a hard-coded constant. */ private resolveModelId; /** * Adapt the service's backend type to the bundle's backend type. The * service uses `'webgpu' | 'wasm' | 'cpu'`; the bundle adds * `'onnxruntime-node'` for the Node-side path (Sprint 0c). Browser paths * always emit one of the first three. */ private adaptBackend; } //# sourceMappingURL=BrowserDepthProvider.d.ts.map