Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 1x 1x 1x 1x 1x 37x 37x 37x 37x 37x 37x 37x 1x 1x 1x 1x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 37x 23x 23x 23x 23x 23x 23x 23x 23x 37x 37x 37x 37x 37x 37x 40x 1x 1x 39x 39x 37x 37x 37x 37x 37x 37x 37x 37x 37x 6x 6x 6x 1x 1x 6x 6x 6x 6x 6x 6x 37x 37x 37x 37x 37x 37x 8x 8x 1x 1x 8x 8x 8x 37x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 37x 37x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 37x 37x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 37x 37x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 37x 37x 37x 37x 37x 2x 2x 2x 37x 1x 1x | import { getUUID } from '../../utils/get-uuid';
import { illusionService } from '../illusion-service';
import { FillType } from '../../enums/fill-type';
class Source {
/**
* @param cSource - 帧数据源实例
* @param imageDataPtr - 图片像素数据头指针地址
*/
constructor(public cSource: CSource, public imageDataPtr: number) {}
}
/**
* 帧数据源工具类
*/
export class SourceHandler {
map: Map<string, Source>;
constructor() {
this.map = new Map();
}
/**
* 构建底层帧数据源实例
* @returns 帧数据源 id
*/
create(): { id: string} {
const id = getUUID();
const cSource = new illusionService.module.Source();
this.map.set(id, {
cSource: cSource,
imageDataPtr: -1
});
return { id };
}
/**
* 获取帧数据源
* @param id - 帧数据源 id
*/
getSource(id: string): Source {
if(!this.map.has(id)) {
throw new Error(`source: ${id} is not exist`);
}
return this.map.get(id)!;
}
/**
* 设置帧数据源的像素数据
* @param id - 帧数据源 id
* @param pixels - 像素数据
* @param width - 宽度
* @param height - 高度
*/
setPixels(id: string, pixels: ArrayLike<number>, width: number, height: number) {
const { module } = illusionService;
const source = this.getSource(id);
if(source.imageDataPtr > 0) {
module._free(source.imageDataPtr);
}
const ptr = module._malloc(pixels.length);
module.HEAPU8.set(pixels, ptr);
source.cSource.setPixels(ptr, width, height);
source.imageDataPtr = ptr;
}
/**
* 销毁帧数据源实例
* @param id - 帧数据源 id
*/
destory(id: string) {
const source = this.getSource(id);
if(source.imageDataPtr > 0) {
illusionService.module._free(source.imageDataPtr);
}
source.cSource.delete();
this.map.delete(id);
}
/**
* 设置填充方式
* @param id - 帧数据源 id
* @param fillType - 填充方式
*/
setFillType(id: string, fillType: FillType): void {
const source = this.getSource(id);
source.cSource.setFillType(fillType);
}
/**
* 设置基于画布宽高与目标宽高比例的裁剪模式
* @param id - 帧数据源 id
* @param ratio - 宽高比例
*/
setClipRatio(id: string, ratio: number): void {
const source = this.getSource(id);
source.cSource.setClipRatio(ratio);
}
/**
* 平移数据源
* @param id - 帧数据源 id
* @param x - x 轴平移量
* @param y - y 轴平移量
* @param z - z 轴平移量
*/
translate(id: string, x: number, y: number, z: number): void {
const source = this.getSource(id);
source.cSource.translate(x, y, z);
}
/**
* 缩放数据源
* @param id - 帧数据源 id
* @param x - x 轴缩放比
* @param y - y 轴缩放比
* @param z - z 轴缩放比
*/
scale(id: string, x: number, y: number, z: number): void {
const source = this.getSource(id);
source.cSource.scale(x, y, z);
}
/**
* 旋转数据源
* @param id - 帧数据源 id
* @param x - x 轴旋转角度
* @param y - y 轴旋转角度
* @param z - z 轴旋转角度
*/
rotate(id: string, x: number, y: number, z: number): void {
const source = this.getSource(id);
source.cSource.rotate(x, y, z);
}
/**
* 数据变更时候需要调用该接口通知基类
* @param id - 帧数据源 id
*/
notifyRefresh(id: string): void {
const source = this.getSource(id);
source.cSource.notifyRefresh();
}
}
export const sourceHandler = new SourceHandler(); |