import { PdfFile } from './document.js'; import { PdfStream } from '../pdf/objects.js'; /** * The result of {@link decodePdfImage}: either a decoded standalone raster file * (with pixel dimensions and an optional `degraded` note for a partial loss, * e.g. a JPEG's alpha dropped) or a typed failure carrying the loss severity and * a human-readable reason. */ export type DecodedImage = { readonly ok: true; readonly bytes: Uint8Array; readonly format: 'png' | 'jpeg' | 'jpeg2000'; readonly widthPx: number; readonly heightPx: number; /** A partial loss note (e.g. a JPEG's alpha dropped). */ readonly degraded?: string; } | { readonly ok: false; readonly severity: 'dropped' | 'degraded'; readonly detail: string; }; /** * Decode a PDF image XObject (ISO 32000-1 §8.9) into a standalone raster file * the FlowDoc resource store can hold. JPEG (`/DCTDecode`) and JPEG 2000 * (`/JPXDecode`) pass through verbatim — only the filters layered before them * are stripped; everything else is decoded to raw samples and re-wrapped as PNG. * Supports DeviceGray/RGB/CMYK, CalGray/CalRGB, ICCBased (by `/N`) and Indexed * colour spaces; Flate, LZW (EP12), RunLength, ASCII85, ASCIIHex and CCITT * Group 4 / Group 3 1-D fax (EP15) filters; PNG/TIFF predictors; bit depths * 1/2/4/8/16; an `/SMask` folded in as the PNG alpha channel; and a stencil * `/ImageMask` (§8.9.6.2) given back as RGBA in `fillHex`; `Lab` (§8.6.5.8) and * a `Separation`/`DeviceN` through its own tint transform (§8.6.6.4). * Unsupported inputs (CCITT Group 3 2-D) return a typed failure so the caller * records a loss. * * @param file The owning file. * @param stream The image XObject, or an inline image wrapped as one. * @param fillHex §8.9.6.2 — the non-stroking colour a stencil mask paints in. * @returns The decoded image, or `{ ok: false }` with the loss severity and reason. */ export declare function decodePdfImage(file: PdfFile, stream: PdfStream, fillHex?: string): DecodedImage;