UNPKG

textmode.js

Version:

Apply real-time ASCII conversion to any HTML canvas.

90 lines (89 loc) 3.64 kB
import type { Framebuffer } from "../rendering/webgl/Framebuffer"; import type { GLRenderer } from "../rendering/webgl/Renderer"; import { TextmodeConverter } from "./converters"; import type { TextmodeFont } from "./font"; import type { TextmodeGrid } from "./Grid"; /** * Manages the conversion pipeline for textmode rendering. * * A conversion pipeline consists of multiple converters that process the input texture in sequence. * Each converter can modify the texture in various ways, such as applying brightness mapping, * color adjustments, transformations, and more. */ export declare class TextmodeConversionPipeline { private renderer; private font; private grid; private converters; private _resultFramebuffer; private _asciiShader; private _characterFramebuffer; private _primaryColorFramebuffer; private _secondaryColorFramebuffer; private _rotationFramebuffer; private _transformFramebuffer; /** * Creates an instance of TextmodeConversionPipeline. * @param renderer The renderer to use for the pipeline. * @param font The textmode font to use. * @param grid The textmode grid to use. * @ignore */ constructor(renderer: GLRenderer, font: TextmodeFont, grid: TextmodeGrid); /** * Performs the conversion process by applying all converters in the pipeline. * @param sourceFramebuffer The source framebuffer to convert. * @ignore */ render(sourceFramebuffer: Framebuffer): void; /** * Get a specific converter by name. * @param name The name of the converter to retrieve. * @returns The requested `TextmodeConverter` instance. */ get(name: string): TextmodeConverter | void; /** * Adds a new converter to the pipeline. * @param name A unique name for the converter. * @param type The type of converter to add. Can be either "brightness" or "custom". * @returns The newly created {@link TextmodeConverter} instance or `void` if the addition failed. */ add(name: string, type: "brightness" | "custom"): TextmodeConverter | void; /** * Removes a converter from the pipeline by name or instance. * @param nameOrInstance The unique name of the converter or the converter instance to remove. */ remove(nameOrInstance: string | TextmodeConverter): void; /** * Returns the framebuffer containing the textmode conversion result. */ get texture(): Framebuffer; /** * Resizes all internal framebuffers. * @ignore */ resize(): void; /** * Checks if any converter in the pipeline is enabled. * @returns `true` if any converter is enabled, `false` otherwise. */ hasEnabledConverters(): boolean; /** * Disables all converters in the pipeline. */ disable(): void; /** * Enables all converters in the pipeline. */ enable(): void; /** Returns the character framebuffer containing the combined result of all converters. */ get characterFramebuffer(): Framebuffer; /** Returns the primary color framebuffer containing the combined result of all converters. */ get primaryColorFramebuffer(): Framebuffer; /** Returns the secondary color framebuffer containing the combined result of all converters. */ get secondaryColorFramebuffer(): Framebuffer; /** Returns the rotation framebuffer containing the combined result of all converters. */ get rotationFramebuffer(): Framebuffer; /** Returns the transform framebuffer containing the combined result of all converters. */ get transformFramebuffer(): Framebuffer; }