UNPKG

@thi.ng/text-canvas

Version:

Text based canvas, drawing, plotting, tables with arbitrary formatting (incl. ANSI/HTML)

205 lines 6.22 kB
import type { FnN4, NumOrString, UIntArray } from "@thi.ng/api"; import { type BlendFn, type ImageOpts } from "./api.js"; import { Canvas } from "./canvas.js"; /** * * @param dest * @param src * @param x * @param y */ export declare const blit: (dest: Canvas, src: Canvas, x?: number, y?: number) => void; /** * Similar to {@link blit}. Pastes `src` {@link Canvas} into `dest` at given * position and uses `mask` to exclude pixels from being copied (and therefore * achieve a form of on/off transparency, similar to GIFs), i.e. only non-`mask` * pixels/chars will be copied. Supports region clipping. * * @example * ```ts tangle:../export/blit-mask.ts * import { * blitMask, canvas, canvasFromText, clear, formatCanvas * } from "@thi.ng/text-canvas"; * * // source canvas * const a = canvasFromText([ * "###==###", * "##====##", * "#======#", * "##====##", * "###==###", * ]); * * console.log(formatCanvas(a)); * * // destination canvas (filled w/ "-") * const b = canvas(12,7); * clear(b, true, "-"); * * // paste `a` several times into `b` using "#" as mask * blitMask(b, a, -4, -2, "#"); // top-left (partially outside) * blitMask(b, a, 2, 1, "#"); // center * blitMask(b, a, 8, 4, "#"); // bottom-right (part outside) * * // show result * console.log(formatCanvas(b)); * // ===--------- * // ==---==----- * // =---====---- * // ---======--- * // ----====---= * // -----==---== * // ---------=== * ``` * * @param dest * @param src * @param x * @param y * @param mask */ export declare const blitMask: (dest: Canvas, src: Canvas, x?: number, y?: number, mask?: NumOrString) => void; export declare const blitBarsV: (dest: Canvas, src: Canvas, x?: number, y?: number, blend?: BlendFn) => void; /** * Blending function for {@link blendBarsVAdd}. Additive blending for vertical * box drawing characters. * * @param a * @param b */ export declare const blendBarsVAdd: FnN4; /** * @remarks * Lookups in this index are symmetrical (see {@link __blend}). Grays are * handled via the last group of entries. * * The order of entries in each group should be B,G,R,C,M,Y, followed by light * versions (in same order) */ export declare const BLEND_ADD: Record<number, Record<number, number>>; export declare const resize: (canvas: Canvas, newWidth: number, newHeight: number) => void; export declare const extract: (canvas: Canvas, x: number, y: number, w: number, h: number) => Canvas; /** * Scrolls canvas vertically by `dy` lines. If `dy > 0` content moves * upward, if `dy < 0` downward. The new empty space will be filled with * `clear` char (default: ` `). * * @param canvas - * @param dy - * @param clear - */ export declare const scrollV: (canvas: Canvas, dy: number, clear?: number) => void; /** * * @param canvas - * @param x - * @param y - * @param w - * @param h - * @param pixels - * @param opts - */ export declare const image: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, opts?: Partial<ImageOpts>) => void; /** * Optimized version of {@link image}, which only uses a single char for all * pixels and applies pixel values directly as formatting data (for each pixel). * * @param canvas - * @param x - * @param y - * @param w - * @param h - * @param pixels - * @param char - */ export declare const imageRaw: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, char?: string) => void; /** * Similar to {@link imageRaw}, but **only** directly modifies the format bits * of the specified region (any character data remains intact). * * @param canvas * @param x * @param y * @param w * @param h * @param pixels */ export declare const imageRawFmtOnly: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>) => void; /** * Similar to {@link imageRaw}, but always thresholds pixels given `thresh` and * converts groups of 2x4 pixels into Unicode Braille characters. Each written * char will use given `format` ID (optional) or default to canvas' currently * active format. * * @remarks * For best results, it's recommended to pre-dither the image (e.g. using * thi.ng/pixel-dither or other dither tools). * * Reference: * https://en.wikipedia.org/wiki/Braille_Patterns#Identifying.2C_naming_and_ordering * * @param canvas - * @param x - * @param y - * @param w - * @param h - * @param pixels - * @param thresh - * @param format - */ export declare const imageBraille: (canvas: Canvas, x: number, y: number, w: number, h: number, pixels: ArrayLike<number>, thresh: number, format?: number) => void; /** * Syntax sugar for {@link imageBraille}. Takes a thi.ng/pixel compatible 8bit * grayscale pixel buffer and converts it into a new {@link canvas}. * * @remarks * The returned canvas will have 50% width and 25% height of the original image * (due to each Braille character encoding 2x4 pixels). * * @param src - * @param thresh - * @param format - */ export declare const imageCanvasBraille: (src: { width: number; height: number; data: UIntArray; }, thresh: number, format?: number) => Canvas; /** * Same as {@link imageCanvasBraille}, but returns resulting canvas as plain * string (of Unicode Braille characters). * * @param src - * @param thresh - */ export declare const imageStringBraille: (src: { width: number; height: number; data: UIntArray; }, thresh: number) => string; /** * Syntax sugar for {@link imageRaw}. Takes a thi.ng/pixel compatible 16bit * pixel buffer in RGB565 format and converts it into a new {@link canvas}. The * optional `char` will be used as character for each pixel. * * @param src - * @param char - */ export declare const imageCanvas565: (src: { width: number; height: number; data: UIntArray; }, char?: string) => Canvas; /** * Same as {@link imageCanvas565}, but returns resulting canvas as 24bit ANSI * string. * * @param src - * @param char - */ export declare const imageString565: (src: { width: number; height: number; data: UIntArray; }, char?: string, fmt?: import("@thi.ng/text-format").StringFormat) => string; //# sourceMappingURL=image.d.ts.map