cdgraphics
Version:
A fast, flexible CD+Graphics (CD+G) renderer
38 lines (37 loc) • 1.5 kB
TypeScript
/**
* CDGPlayer section
*/
/**
* Options for rendering frames
*/
export interface RenderOptions {
/**
* Forces the background to be transparent, even if the CD+G title did not explicitly specify it.
* @default false
*/
forceKey?: boolean;
}
/**
* Rendered frame data
*/
export interface Frame {
/** The frame's rasterized pixel data. */
imageData: ImageData;
/** Whether the frame changed since the last render. Useful for skipping unnecessary re-paints to a canvas. */
isChanged: boolean;
/** The frame's background color in RGBA, with alpha being 0 or 1. The reported alpha includes the effect of the forceKey option, if enabled. */
backgroundRGBA: [r: number, g: number, b: number, a: 0 | 1];
/** The coordinates of a bounding box that fits the frame's non-transparent pixels. Typically only useful when the forceKey option is enabled. */
contentBounds: [x1: number, y1: number, x2: number, y2: number];
}
/**
* CD+G (CD+Graphics) player for rendering karaoke graphics
*/
export default class CDGraphics {
/** Instantiates a new renderer with the given CD+G file data. The data must be an `ArrayBuffer`, which can be had via the `Response` of a `fetch()`. */
constructor(buffer: ArrayBuffer);
/** Renders the frame at the given time index. */
render(
/** Time index (in fractional seconds) to render. Should usually be the `currentTime` from an `audio` element. */
time: number, opts?: RenderOptions): Frame;
}