/** * Pixmap - Raster image handling and pixel manipulation * * This module provides comprehensive support for working with raster images (pixmaps) * in PDF documents. Pixmaps represent pixel-based images with support for various * colorspaces, alpha channels, and pixel-level manipulation. * * This module provides 100% API compatibility with MicroPDF's pixmap operations. * * @module pixmap * @example * ```typescript * import { Pixmap, Colorspace, Rect } from 'micropdf'; * * // Create a pixmap from a page * const page = doc.loadPage(0); * const pixmap = page.toPixmap(Matrix.identity()); * * // Create an empty pixmap * const empty = Pixmap.create(Colorspace.deviceRGB(), 100, 100, true); * * // Get pixel data * const width = pixmap.width; * const height = pixmap.height; * const data = pixmap.samples; * * // Manipulate pixels * for (let y = 0; y < height; y++) { * for (let x = 0; x < width; x++) { * const pixel = pixmap.getPixel(x, y); * // Modify pixel... * pixmap.setPixel(x, y, [r, g, b, a]); * } * } * * // Convert colorspace * const gray = pixmap.convert(Colorspace.deviceGray()); * * // Scale * const thumbnail = pixmap.scale(50, 50); * * // Clean up * pixmap.drop(); * gray.drop(); * thumbnail.drop(); * ``` */ import { Colorspace } from './colorspace.js'; import { Rect, IRect, type IRectLike } from './geometry.js'; /** * A raster image with pixel-level manipulation capabilities. * * Pixmap represents a rectangular array of pixels with an associated colorspace * and optional alpha channel. Pixmaps are used for rendering PDF pages, working * with images, and performing pixel-level image processing. * * **Key Features:** * - Multiple colorspace support (Gray, RGB, CMYK, etc.) * - Optional alpha channel for transparency * - Pixel-level read/write access * - Colorspace conversion * - Scaling and transformation * - Tinting and color manipulation * * **Memory Layout**: Pixels are stored row-by-row, left-to-right, with components * interleaved. For RGB with alpha, the order is: R₁G₁B₁A₁, R₂G₂B₂A₂, ... * * **Reference Counting**: Pixmaps use manual reference counting. Call `keep()` to * increment the reference count and `drop()` to decrement it. * * @class Pixmap * @example * ```typescript * // Render a PDF page to a pixmap * const doc = Document.open('document.pdf'); * const page = doc.loadPage(0); * const matrix = Matrix.scale(2, 2); // 2x zoom * const pixmap = page.toPixmap(matrix, Colorspace.deviceRGB(), true); * * console.log(`Size: ${pixmap.width} x ${pixmap.height}`); * console.log(`Components: ${pixmap.n}`); // 4 for RGBA * console.log(`Has alpha: ${pixmap.alpha}`); * * // Access pixel data * const samples = pixmap.samples; // Uint8Array * const pixel = pixmap.getPixel(10, 10); // [r, g, b, a] * * // Modify a pixel * pixmap.setPixel(10, 10, [255, 0, 0, 255]); // Red pixel * * // Convert to grayscale * const gray = pixmap.convert(Colorspace.deviceGray()); * * // Create thumbnail * const thumb = pixmap.scale(100, 100); * * // Clean up * pixmap.drop(); * gray.drop(); * thumb.drop(); * page.drop(); * doc.close(); * ``` * * @example * ```typescript * // Create a blank red image * const pixmap = Pixmap.create( * Colorspace.deviceRGB(), * 200, * 200, * false // No alpha * ); * * // Fill with red * for (let y = 0; y < pixmap.height; y++) { * for (let x = 0; x < pixmap.width; x++) { * pixmap.setPixel(x, y, [255, 0, 0]); // Red * } * } * * // Convert to RGBA * const rgba = pixmap.toRGBA(); * console.log(rgba.length); // 200 * 200 * 4 = 160,000 bytes * ``` * * @example * ```typescript * // Load from raw sample data * const width = 2, height = 2; * const samples = new Uint8Array([ * 255, 0, 0, 255, // Red pixel * 0, 255, 0, 255, // Green pixel * 0, 0, 255, 255, // Blue pixel * 255, 255, 0, 255 // Yellow pixel * ]); * * const pixmap = Pixmap.fromSamples( * Colorspace.deviceRGB(), * width, * height, * true, * samples * ); * * // Tint with red and white * pixmap.tint([255, 0, 0], [255, 255, 255]); * ``` */ export declare class Pixmap { private _width; private _height; private _x; private _y; private _colorspace; private _alpha; private _data; private _xres; private _yres; private _refCount; constructor(colorspace: Colorspace, width: number, height: number, alpha?: boolean, x?: number, y?: number); /** * Create a new pixmap */ static create(colorspace: Colorspace, width: number, height: number, alpha?: boolean): Pixmap; /** * Create pixmap with bounding box */ static createWithBBox(colorspace: Colorspace, bbox: IRectLike, alpha?: boolean): Pixmap; /** * Create pixmap with bounding box (lowercase alias) */ static createWithBbox(colorspace: Colorspace, bbox: IRectLike, alpha?: boolean): Pixmap; /** * Create pixmap from sample data */ static fromSamples(colorspace: Colorspace, width: number, height: number, alpha: boolean, samples: Uint8Array): Pixmap; keep(): this; drop(): void; /** * Clone this pixmap */ clone(): Pixmap; get x(): number; get y(): number; get width(): number; get height(): number; get colorspace(): Colorspace; /** * Get number of color components (colorants only, excluding alpha). * * This matches the MuPDF convention where `n` / `components` is the * number of colorant channels (e.g. 3 for RGB, 4 for CMYK) * regardless of whether an alpha channel is present. */ get components(): number; /** * Get total number of components per pixel (colorants + alpha if present). * * In MuPDF, `n` is the total sample count per pixel, so for an RGB * pixmap with alpha it returns 4 (3 color + 1 alpha). */ get n(): number; /** * Get number of colorant components (excluding alpha) */ get colorants(): number; /** * Total bytes per pixel (colorants + alpha), used internally for * stride calculations and pixel offset arithmetic. */ private get _bytesPerPixel(); /** * Check if pixmap has alpha channel */ get hasAlpha(): boolean; /** * Check if pixmap has alpha channel (short alias) */ get alpha(): boolean; /** * Get stride (bytes per row) */ get stride(): number; /** * Get raw pixel data */ get data(): Uint8Array; /** * Get samples (pixel data) - alias for data */ get samples(): Uint8Array; /** * Get bounding box */ getBounds(): Rect; /** * Get integer bounding box */ getBBox(): IRect; get xres(): number; set xres(res: number); get yres(): number; set yres(res: number); /** * Get resolution as [xres, yres] */ getResolution(): [number, number]; /** * Set resolution */ setResolution(xres: number, yres: number): void; /** * Get a single sample value */ getSample(x: number, y: number, component: number): number; /** * Set a single sample value */ setSample(x: number, y: number, component: number, value: number): void; /** * Get all samples for a pixel */ getPixel(x: number, y: number): number[]; /** * Set all samples for a pixel */ setPixel(x: number, y: number, values: number[]): void; /** * Clear pixmap to transparent/white */ clear(): void; /** * Clear pixmap to specific value */ clearWithValue(value: number): void; /** * Invert pixmap colors */ invert(): void; /** * Apply gamma correction */ gamma(gamma: number): void; /** * Tint pixmap with a color */ tint(black: number[], white?: number[]): void; /** * Convert pixmap to another colorspace */ convert(destColorspace: Colorspace): Pixmap; /** * Convert pixmap to RGBA format */ toRGBA(): Uint8Array; /** * Scale pixmap to new dimensions */ scale(width: number, height: number): Pixmap; /** * Check if pixmap is valid */ isValid(): boolean; /** * Get pixmap info */ getInfo(): PixmapInfo; } /** * Pixmap information */ export interface PixmapInfo { x: number; y: number; width: number; height: number; colorspace: Colorspace; components: number; colorants: number; hasAlpha: boolean; stride: number; xres: number; yres: number; size: number; } //# sourceMappingURL=pixmap.d.ts.map