/** * Source-image correspondence (HELIX-120 S-SRC-CORR): does a retained `source-image.` object really belong to web texture n? * * Retained sources are mapped to glTF image indexes by index alone. A web texture that was REBAKED (a different UV atlas, * e.g. Cargo Pants) is not a downscale of its source, so painting the source onto the web GLB's UVs on the desktop tier * would show the wrong pixels. The test: downscale the source to the web texture's size and require both * (a) a small per-channel mean absolute difference (colour agrees), and * (b) a high structural similarity (SSIM) on the compared channels (layout agrees: the same colours in another layout fail). * * THIS FILE IS DUPLICATED BYTE FOR BYTE in helix-backend-api (src/continuum/unreal-rt/item-rt-source-correspondence.core.ts) * and helix-creator-cli (src/sourceCorrespondence.core.ts). It is pure (no I/O, no image library) and both repos hold a * parity fixture test with the same expected numbers. The backend compiler is the authority; the CLI check is UX. * Thresholds were calibrated on real data (see S-SRC-CORR-checkpoint.md): a true downscale through a KTX2/BasisU round trip * sits far inside them, Cargo Man and Female sit far outside. */ export type CorrespondenceRole = 'baseColor' | 'emissive' | 'normal' | 'orm' | 'scalar'; /** Same-size RGBA rasters, row-major, 4 bytes per pixel. */ export type Raster = { width: number; height: number; rgba: Uint8Array; }; export declare const SOURCE_CORRESPONDENCE_THRESHOLDS: { /** Largest allowed mean absolute difference (0-255) of any compared channel. */ readonly maxMad: 8; /** Smallest allowed SSIM (0-1) of any compared channel (windows with real structure, see below). */ readonly minSsim: 0.7; }; export type CorrespondenceResult = { ok: boolean; /** Per compared channel, in channel order (colour/ORM: R,G,B; normal: R,G). */ mad: number[]; ssim: number[]; reason?: string; /** * Normal maps only: the source matches the web normal once its green channel is inverted (DirectX vs glTF convention, as * Unreal exports it). Such a source is ACCEPTED (`ok: true`); the caller must flip green when it encodes from the source * and report `source.normal.dx-flipped`. Any other role with inverted green is a plain mismatch. */ greenInverted?: boolean; }; /** * Compare a web texture with the retained source ALREADY DOWNSCALED to the web texture's size. Both rasters must be the * same size (the caller resizes the larger one down; see `correspondenceSize`). */ export declare function compareRasters(web: Raster, downscaledSource: Raster, role: CorrespondenceRole): CorrespondenceResult; /** * The size both rasters are compared at: the smaller of the two (a source smaller than the web texture means the web * texture is the one to downscale). Null when the aspect ratios differ by more than 2% (a different layout, for certain). */ export declare function correspondenceSize(web: { width: number; height: number; }, source: { width: number; height: number; }): { width: number; height: number; } | null;