import { type AdjustmentQuality, type ClarityOptions, type ColorMatchingMode, type DynamicRangeCompressionOptions, type ImageProcessingOptions, type LevelCompressionMode, type LevelCompressionOptions, type LevelRGB, type PaperNormalizationOptions, type PercentileClip, type ProcessingPreset, type ProcessingPresetName, type RGB, type RGBA, type ToneMappingMode, type ToneMappingOptions } from "./processing"; import { type PaletteColorEntry } from "./functions/palette-order"; export type DitheringType = "errorDiffusion" | "ordered" | "random" | "quantizationOnly" | "hueMix" | "blueNoise" | "simple2D" | "riemersma" | "ditherItErrorDiffusion" | "ditherItOrdered" | "ditherItBlueNoise" | "ditherItSimple2D" | "ditherItRiemersma" | (string & {}); export type DitherProcessingEngine = "js" | "wasm" | "auto"; export type AdjustmentProcessingEngine = "auto" | "js" | "worker" | "wasm"; export interface AdjustmentPreviewOptions { maxPixels?: number; maxLongEdge?: number; mode?: "fast" | "final"; } export interface DitherImageOptions { /** * Upstream-style processing preset. Presets fill in tone mapping, dynamic * range compression, color matching, and diffusion defaults unless overridden. */ processingPreset?: ProcessingPresetName; /** Main dithering algorithm. */ ditheringType?: DitheringType; /** * Processing engine for supported hot paths. * * Default: "auto". "wasm" and "auto" currently accelerate RGB error diffusion * and fall back to JS for unsupported modes. */ processingEngine?: DitherProcessingEngine; /** * Processing engine for image adjustments. * * Default: "auto". "worker" and "auto" move supported async adjustment calls * off the main thread where browser Workers are available. "wasm" is * reserved for future adjustment kernels and currently falls back to JS. */ adjustmentEngine?: AdjustmentProcessingEngine; /** * Preview controls for interactive editors. Final mode preserves current * quality; fast mode can downscale and use cheaper adjustment paths. */ preview?: AdjustmentPreviewOptions; /** Error diffusion kernel (e.g. `floydSteinberg`). */ errorDiffusionMatrix?: string; /** * Backwards-compatible alias for `errorDiffusionMatrix`. * (The README historically used `algorithm`.) */ algorithm?: string; serpentine?: boolean; orderedDitheringType?: string; /** Tuple preferred; `number[]` accepted for convenience. */ orderedDitheringMatrix?: [number, number] | number[]; randomDitheringType?: "blackAndWhite" | "rgb" | (string & {}); /** Palette name, custom hex strings, or combined palette entries. */ palette?: string | string[] | PaletteColorEntry[]; /** Color distance model for palette matching. */ colorMatching?: ColorMatchingMode; sampleColorsFromImage?: boolean; numberOfSampleColors?: number; /** Reserved/ignored by current implementation (kept for UI compatibility). */ calibrate?: boolean; /** * Optional preprocessing step to remap pixel values into the display’s effective black/white limits. * * Default: undefined (disabled) for backwards compatibility. */ levelCompression?: LevelCompressionOptions; /** * Exposure/saturation plus contrast or S-curve tone mapping. */ toneMapping?: ToneMappingOptions; /** * LAB lightness compression into the calibrated display black/white range. */ dynamicRangeCompression?: DynamicRangeCompressionOptions | boolean; /** * Selective cleanup for scanned paper/poster sources before tone mapping. */ paperNormalization?: PaperNormalizationOptions; /** * Midtone local-contrast adjustment before tone mapping. */ clarity?: ClarityOptions; /** * Preserve hard text/line-art edges by replacing strong edge-core pixels with * direct palette quantization after the main dithering pass. */ edgePreservation?: EdgePreservationOptions; /** * Reduce jagged teeth on antialiased full-color transitions by constraining * edge-band pixels to the two local palette colors on either side of an edge. */ edgeAntialiasing?: EdgeAntialiasingOptions; } export interface EdgePreservationOptions { enabled?: boolean; /** * 0..1. Higher values preserve more edge-core pixels. */ strength?: number; /** * Luma-gradient threshold used to detect strong transitions. */ threshold?: number; /** * Optional dilation radius for the protected edge core. */ radius?: number; } export interface EdgeAntialiasingOptions { enabled?: boolean; /** * 0..1. Higher values replace more eligible edge-band pixels. */ strength?: number; /** * Luma-gradient threshold used to detect antialias transition bands. */ threshold?: number; /** * Edge-band dilation radius, in pixels. */ bandRadius?: number; /** * Neighborhood radius used to find the two local palette colors. */ localRadius?: number; } export interface ImageDataLike { width: number; height: number; data: Uint8ClampedArray; } export interface Canvas2DContextLike { getImageData(sx: number, sy: number, sw: number, sh: number): ImageDataLike; putImageData(imageData: ImageDataLike, dx: number, dy: number): void; } export interface CanvasLike { width: number; height: number; getContext(contextId: "2d"): Canvas2DContextLike | null; } export type { ClarityOptions, AdjustmentQuality, ColorMatchingMode, DynamicRangeCompressionOptions, ImageProcessingOptions, LevelCompressionMode, LevelCompressionOptions, LevelRGB, PaperNormalizationOptions, PercentileClip, ProcessingPreset, ProcessingPresetName, RGB, RGBA, ToneMappingMode, ToneMappingOptions, }; declare const applyImageAdjustments: (sourceCanvas: CanvasLike, canvas: CanvasLike, opts?: DitherImageOptions) => Promise; declare const applyImageDataAdjustments: (image: ImageDataLike, opts?: DitherImageOptions) => ImageDataLike | undefined; declare const applyImageDataAdjustmentsAsync: (image: ImageDataLike, opts?: DitherImageOptions) => Promise; declare const applyImageAdjustmentsPreview: (sourceCanvas: CanvasLike, canvas: CanvasLike, opts?: DitherImageOptions) => Promise; declare const ditherCanvas: (sourceCanvas: CanvasLike, canvas: CanvasLike, opts?: DitherImageOptions) => Promise; declare const ditherImage: (sourceCanvas: CanvasLike, canvas: CanvasLike, opts?: DitherImageOptions) => Promise; export { applyImageAdjustments, applyImageAdjustmentsPreview, applyImageDataAdjustments, applyImageDataAdjustmentsAsync, ditherCanvas, ditherImage, };