import type { AssetInput, ImageMaskInput } from '../types/images.js'; export { type DecodePngOptions, decodePng, encodePng, type ImageDimensionsInfo, type RgbaImage, readImageDimensions, type SniffedImage, type SniffedImageFormat, sniffImageType, } from './codec.js'; /** * What a provider means by a mask. * * The neutral contract describes a mask by polarity — which colour marks the editable region — * because that is how people draw one. Providers disagree: OpenAI reads the alpha channel and edits * where it is fully transparent, while Imagen and most diffusion backends read a greyscale image and * edit where it is white. Converting between them is this module's whole job. */ export type MaskSemantics = 'white-is-editable' | 'black-is-editable' | 'alpha-transparent-is-editable'; /** What a mask must be converted to. */ export interface MaskTarget { /** How the provider reads masks. */ semantics: MaskSemantics; /** Dimensions of the image the mask applies to. The prepared mask always matches them. */ width: number; /** Height of the image the mask applies to. */ height: number; /** The provider, named in errors. */ provider?: string; } /** A mask converted for one provider, at the image's exact dimensions. */ export interface PreparedMask extends AssetInput { /** Width, equal to the image's. */ width: number; /** Height, equal to the image's. */ height: number; /** Share of pixels marked editable, between 0 and 1. */ coverage: number; } /** * Converts a neutral mask into what one provider expects. * * An injection seam: the bundled `PngMaskTransformer` handles PNG masks, and an application with a * native image library can supply its own to accept JPEG or WebP masks or to resample with * anti-aliasing. */ export interface AssetTransformer { /** Converts a mask to the target's semantics and dimensions. */ prepareMask(mask: ImageMaskInput, target: MaskTarget): Promise | PreparedMask; } /** Options for the bundled PNG mask transformer. */ export interface PngMaskTransformerOptions { /** Luminance, 0–255, at or above which a pixel counts as white. Defaults to 128. */ threshold?: number; /** Largest mask accepted before decoding, as a guard against a decompression bomb. */ maxPixels?: number; } /** * Converts PNG masks between polarities and alpha semantics, resizing with nearest-neighbour when * the mask's `resizeMode` allows. */ export declare class PngMaskTransformer implements AssetTransformer { private readonly threshold; private readonly maxPixels; constructor(options?: PngMaskTransformerOptions); /** * Converts a PNG mask. Throws for a mask that is not PNG bytes, or of the wrong size when * `resizeMode` is `reject`. */ prepareMask(mask: ImageMaskInput, target: MaskTarget): PreparedMask; /** * One byte per pixel, 1 where editable. * * A partly transparent pixel is composited over the non-editable colour first, so transparency in * a hand-drawn mask never silently widens the editable region. */ private toEditableMap; } /** * Reads the dimensions of an image a mask will be applied to. * * Providers need the target size before preparing a mask, and asking them to each parse headers * would repeat the same code in every adapter. */ export declare function requireImageDimensions(asset: AssetInput, provider: string): { width: number; height: number; }; /** Shared default instance, built on first use. */ export declare function defaultMaskTransformer(): AssetTransformer;