/** * Image Processing Utilities * * Provides methods for converting images to printer-compatible formats. * Supports multiple dithering algorithms and image preprocessing. */ export declare class ImageProcessing { private static readonly BAYER_MATRIX_2; private static readonly BAYER_MATRIX_4; private static readonly BAYER_MATRIX_8; private static readonly QUALITY_PRESETS; private static readonly ERROR_KERNELS; private static readonly halftoneThresholdCache; /** * Convert RGBA data to monochrome bitmap (1 bit per pixel) * suitable for ESC/POS GS v 0 command. * * @example * ```typescript * const bitmap = ImageProcessing.toBitmap(rgbaData, width, height, { * targetWidth: 384, * ditheringAlgorithm: 'ordered', * contrast: 1.2, * brightness: 0.1 * }); * ``` */ static toBitmap(data: Uint8Array, width: number, height: number, options?: { targetWidth?: number; targetHeight?: number; useDithering?: boolean; /** 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki' (default: 'floyd-steinberg') */ ditheringAlgorithm?: 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki'; scalingAlgorithm?: 'nearest' | 'bilinear'; contrast?: number; brightness?: number; threshold?: number; orderedMatrixSize?: 2 | 4 | 8; halftoneDotType?: 'round' | 'diamond' | 'square'; qualityPreset?: 'draft' | 'normal' | 'high'; }): Uint8Array; /** * Image preprocessing pipeline * @example * ```typescript * const processed = ImageProcessing.preprocessImage(data, w, h, { * denoise: true, * sharpen: true, * gamma: 1.2, * posterize: 4 * }); * ``` */ static preprocessImage(data: Uint8Array, width: number, height: number, options?: { denoise?: boolean; sharpen?: boolean; gamma?: number; posterize?: number; }): Uint8Array; /** * Fused RGBA→grayscale + contrast/brightness adjustment in a single pass. * Eliminates the extra Float32Array allocation from the separate methods. */ private static toGrayscaleAdjusted; /** Dispatch to the appropriate dithering algorithm. */ private static applyDithering; /** * Data-driven error-diffusion dithering. Replaces the four independent * methods (Floyd-Steinberg / Atkinson / Sierra / Stucki) with a single * loop that reads from a kernel table. * * Error distribution is inlined to eliminate per-pixel function-call overhead. * Bit operations (>> 3, & 7, 0x80 >>) replace Math.floor and %. */ private static applyErrorDiffusionDithering; /** * Process a single row of error-diffusion dithering. * Extracted to reduce cognitive complexity of the main function. */ private static processErrorDiffusionRow; /** * Write a black pixel to the bitmap at the given position. * Uses bit operations for efficiency. */ private static writeBlackPixel; /** * Distribute quantization error to neighboring pixels according to the kernel. * Clamps values to [0, 255] range. */ private static distributeError; /** * Unified threshold dithering for ordered / halftone / simple threshold. * Bit operations replace Math.floor and %. */ private static applyThresholdDithering; private static getHalftoneThresholds; private static computeHalftoneThresholds; private static scaleImage; private static applyNearestNeighbor; private static applyBilinearInterpolation; private static resampleImage; private static applyGammaCorrection; private static processPixels; private static applyMedianFilter; /** * Collect pixel values from a 3x3 neighborhood around the given position. * Handles boundary conditions by clamping coordinates. * Returns an array of 36 values (9 pixels × 4 channels). */ private static collectNeighborhoodWindow; /** * Clamp a coordinate to valid image bounds [0, max - 1]. */ private static clampCoordinate; private static applyUnsharpMask; /** * Get the pre-defined sharpening kernel. * Center weight = 3, edge weights = -0.5, corner weights = -1.0 */ private static getSharpeningKernel; /** * Apply convolution for a single channel at the given position. * Handles boundary conditions by clamping coordinates. */ private static convolveChannel; /** * Clamp a numeric value to valid byte range [0, 255]. */ private static clampToByte; private static applyPosterization; }