/** * Bitmap manipulation utilities */ import { type Bitmap, PixelMode } from "./types.ts"; import type { Matrix2D, Matrix3x3 } from "../render/outline-transform.ts"; export interface BitmapTransformOptions { /** Glyph bearing X (left edge from origin) */ bearingX?: number; /** Glyph bearing Y (top edge from origin) */ bearingY?: number; /** Optional translation in 26.6 units (applied after matrix) */ offsetX26?: number; /** Optional translation in 26.6 units (applied after matrix) */ offsetY26?: number; } export interface RasterMetrics { width: number; height: number; bearingX: number; bearingY: number; ascent: number; descent: number; } export interface RasterEffectOptions { blur?: number; be?: number; border?: number; shadowX?: number; shadowY?: number; } /** * Embolden a bitmap by dilating pixel values * Makes text bolder by spreading coverage in x and y directions * @param bitmap Source bitmap to embolden * @param xStrength Horizontal dilation strength in pixels * @param yStrength Vertical dilation strength in pixels * @returns New bitmap with emboldened content */ export declare function emboldenBitmap(bitmap: Bitmap, xStrength: number, yStrength: number): Bitmap; /** * Convert bitmap between pixel modes * @param bitmap Source bitmap to convert * @param targetMode Target pixel format * @returns New bitmap in the target format */ export declare function convertBitmap(bitmap: Bitmap, targetMode: PixelMode): Bitmap; /** * Alpha blend src bitmap onto dst bitmap at position (x, y) * @param dst Destination bitmap to blend onto (modified in place) * @param src Source bitmap to blend * @param x X position in destination * @param y Y position in destination * @param opacity Blend opacity from 0 to 1 */ export declare function blendBitmap(dst: Bitmap, src: Bitmap, x: number, y: number, opacity: number): void; /** * Create a deep copy of a bitmap * @param bitmap Bitmap to copy * @returns New bitmap with copied data */ export declare function copyBitmap(bitmap: Bitmap): Bitmap; /** * Resize bitmap using nearest-neighbor interpolation * @param bitmap Source bitmap to resize * @param newWidth Target width in pixels * @param newHeight Target height in pixels * @returns New bitmap resized to target dimensions */ export declare function resizeBitmap(bitmap: Bitmap, newWidth: number, newHeight: number): Bitmap; /** * Resize bitmap using bilinear interpolation * Produces smoother results than nearest-neighbor, ideal for downsampling * @param bitmap Source bitmap to resize * @param newWidth Target width in pixels * @param newHeight Target height in pixels * @returns New bitmap resized with smooth interpolation */ export declare function resizeBitmapBilinear(bitmap: Bitmap, newWidth: number, newHeight: number): Bitmap; /** * Add two bitmaps together (additive blend) * Result: dst = clamp(dst + src, 0, 255) * Used for combining glyph with shadow/glow * @param dst Destination bitmap (modified in place) * @param src Source bitmap to add * @param srcX X offset of source in destination (default: 0) * @param srcY Y offset of source in destination (default: 0) */ export declare function addBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Multiply two bitmaps (multiplicative blend) * Result: dst = (dst * src) / 255 * Used for masking operations * @param dst Destination bitmap (modified in place) * @param src Source bitmap to multiply * @param srcX X offset of source in destination (default: 0) * @param srcY Y offset of source in destination (default: 0) */ export declare function mulBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Subtract src from dst (subtractive blend) * Result: dst = clamp(dst - src, 0, 255) * Used for outline effects * @param dst Destination bitmap (modified in place) * @param src Source bitmap to subtract * @param srcX X offset of source in destination (default: 0) * @param srcY Y offset of source in destination (default: 0) */ export declare function subBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Alpha composite src over dst using src as alpha * Result: dst = src + dst * (1 - src/255) * Standard Porter-Duff "over" operation * @param dst Destination bitmap (modified in place) * @param src Source bitmap to composite * @param srcX X offset of source in destination (default: 0) * @param srcY Y offset of source in destination (default: 0) */ export declare function compositeBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Shift bitmap position by integer offset * Creates a new bitmap with the content shifted * @param bitmap Source bitmap to shift * @param shiftX Horizontal shift in pixels * @param shiftY Vertical shift in pixels * @returns New bitmap with shifted content */ export declare function shiftBitmap(bitmap: Bitmap, shiftX: number, shiftY: number): Bitmap; /** * Fix outline bitmap by removing glyph interior * Used when you want only the border, not the filled shape * Result: outline = outline - glyph (where glyph coverage > threshold) * @param outlineBitmap Outline bitmap to fix (modified in place) * @param glyphBitmap Glyph bitmap containing filled shape * @param glyphX X position of glyph in outline (default: 0) * @param glyphY Y position of glyph in outline (default: 0) * @param threshold Coverage threshold for removal (default: 128) */ export declare function fixOutline(outlineBitmap: Bitmap, glyphBitmap: Bitmap, glyphX?: number, glyphY?: number, threshold?: number): void; /** * Maximum blend: take the maximum of two bitmaps * Result: dst = max(dst, src) * Used for combining multiple layers * @param dst Destination bitmap (modified in place) * @param src Source bitmap to compare * @param srcX X offset of source in destination (default: 0) * @param srcY Y offset of source in destination (default: 0) */ export declare function maxBitmaps(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Create a padded copy of a bitmap with extra space around edges * Useful before blur operations to prevent edge artifacts * @param bitmap Source bitmap to pad * @param padLeft Left padding in pixels * @param padTop Top padding in pixels * @param padRight Right padding in pixels * @param padBottom Bottom padding in pixels * @returns New bitmap with padding added */ export declare function padBitmap(bitmap: Bitmap, padLeft: number, padTop: number, padRight: number, padBottom: number): Bitmap; /** * Create an expanded bitmap that can contain both dst and src * Returns the expanded bitmap and the offsets for both original bitmaps * @param dst Destination bitmap * @param src Source bitmap to fit * @param srcX X position of source relative to destination * @param srcY Y position of source relative to destination * @returns Expanded bitmap and offset positions for both original bitmaps */ export declare function expandToFit(dst: Bitmap, src: Bitmap, srcX: number, srcY: number): { expanded: Bitmap; dstOffsetX: number; dstOffsetY: number; srcOffsetX: number; srcOffsetY: number; }; /** * Subtract src from dst (alias for subBitmaps) */ export declare function subtractBitmap(dst: Bitmap, src: Bitmap, srcX?: number, srcY?: number): void; /** * Fix outline bitmap by removing glyph interior (alias for fixOutline) */ export declare function fixOutlineBitmap(outlineBitmap: Bitmap, glyphBitmap: Bitmap, glyphX?: number, glyphY?: number, threshold?: number): void; /** * Measure rasterized glyph ascent/descent from bitmap coverage */ export declare function measureRasterGlyph(bitmap: Bitmap, bearingX: number, bearingY: number): { ascent: number; descent: number; }; /** * Expand raster metrics to account for blur/border/shadow padding */ export declare function expandRasterMetrics(metrics: RasterMetrics, options: RasterEffectOptions): RasterMetrics & { padLeft: number; padRight: number; padTop: number; padBottom: number; }; /** * Embolden bitmap and adjust bearing by padding to avoid clipping */ export declare function emboldenBitmapWithBearing(bitmap: Bitmap, bearingX: number, bearingY: number, xStrength: number, yStrength: number): { bitmap: Bitmap; bearingX: number; bearingY: number; }; /** * Transform bitmap using 2D affine matrix with bilinear resampling */ export declare function transformBitmap2D(bitmap: Bitmap, matrix: Matrix2D, options?: BitmapTransformOptions): { bitmap: Bitmap; bearingX: number; bearingY: number; }; /** * Transform bitmap using 3x3 matrix with perspective and bilinear resampling */ export declare function transformBitmap3D(bitmap: Bitmap, matrix: Matrix3x3, options?: BitmapTransformOptions): { bitmap: Bitmap; bearingX: number; bearingY: number; }; /** * Shear bitmap horizontally (synthetic italic) */ export declare function shearBitmapX(bitmap: Bitmap, amount: number, options?: BitmapTransformOptions): { bitmap: Bitmap; bearingX: number; bearingY: number; }; /** * Shear bitmap vertically */ export declare function shearBitmapY(bitmap: Bitmap, amount: number, options?: BitmapTransformOptions): { bitmap: Bitmap; bearingX: number; bearingY: number; };