fabric-texture
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
69 lines (68 loc) • 2.73 kB
TypeScript
import type { Texture } from '../texture.class';
/**
* WebGL 贴图渲染器
*
* 使用 WebGL 技术将源图像按照指定的变形网格渲染到目标画布。
* 相比 Canvas 2D 渲染器,具有更好的性能和更丰富的渲染效果。
*
* 功能特性:
* 1. 高性能图像变形:利用 GPU 加速实现平滑的图像变形
* 2. 网格可视化:支持显示变形网格和控制点
* 3. 抗锯齿:支持边缘平滑处理
*
* @param texture - 贴图对象,包含变形网格和渲染选项
* @param source - 源图像画布或图像数据
* @param destination - 目标渲染画布
* @param options - 渲染配置选项
* @property {number} x - 渲染位置 X 坐标
* @property {number} y - 渲染位置 Y 坐标
* @property {number} width - 渲染宽度
* @property {number} height - 渲染高度
* @property {number} [sourceScale=1] - 源图像缩放比例
* @property {number} [destinationScale=1] - 目标画布缩放比例
*
* @returns {Canvas} 渲染完成的画布对象
*
* @throws {Error}
* - 当 WebGL 上下文初始化失败时
* - 当着色器程序初始化失败时
* - 当纹理对象创建失败时
*/
export declare const createWebGLTexture: <Canvas extends HTMLCanvasElement | OffscreenCanvas>(texture: Texture, source: HTMLCanvasElement | ImageData, destination: Canvas, options: {
x: number;
y: number;
width: number;
height: number;
sourceScale?: number;
destinationScale?: number;
}) => Canvas;
/**
* 创建并渲染贴图的便捷方法
*
* 提供一个简化的接口来创建和渲染贴图:
* 1. 自动创建目标画布(如果未提供)
* 2. 自动计算画布尺寸
* 3. 使用 WebGL 进行高性能渲染
*
* @param texture - 贴图对象,包含变形网格和渲染选项
* @param source - 源图像画布
* @param destination - 目标渲染画布,如果为 null 则自动创建新画布
* @param options - 渲染配置选项
* @property {number} x - 渲染位置 X 坐标
* @property {number} y - 渲染位置 Y 坐标
* @property {number} width - 渲染宽度
* @property {number} height - 渲染高度
* @property {number} [sourceScale=1] - 源图像缩放比例,大于1放大,小于1缩小
* @property {number} [destinationScale=1] - 目标画布缩放比例,大于1放大,小于1缩小
*
* @returns {HTMLCanvasElement} 渲染完成的画布对象
*/
declare const createTexture: (texture: Texture, source: HTMLCanvasElement, destination: HTMLCanvasElement | null, options: {
x: number;
y: number;
width: number;
height: number;
sourceScale?: number;
destinationScale?: number;
}) => HTMLCanvasElement;
export default createTexture;