feat(web-platform): release V0.5.2 前端优化

This commit is contained in:
2026-08-28 13:32:34 +08:00
parent ecfcd3c869
commit 8e3d56d619
23 changed files with 345 additions and 70 deletions
@@ -0,0 +1,14 @@
export function texturePixelsToRgba(source:Uint8Array,pixelCount:number,channels:number):Uint8Array{
if(!Number.isInteger(pixelCount)||pixelCount<0)throw new Error('纹理像素数量无效');
if(!Number.isInteger(channels)||channels<1||channels>4)throw new Error(`不支持 ${channels} 通道纹理`);
if(source.length<pixelCount*channels)throw new Error('纹理像素数据不完整');
const rgba=new Uint8Array(pixelCount*4);
for(let pixel=0;pixel<pixelCount;pixel+=1){
const sourceOffset=pixel*channels,targetOffset=pixel*4,red=source[sourceOffset];
rgba[targetOffset]=red;
rgba[targetOffset+1]=channels===1||channels===2?red:source[sourceOffset+1];
rgba[targetOffset+2]=channels===1||channels===2?red:source[sourceOffset+2];
rgba[targetOffset+3]=channels===2?source[sourceOffset+1]:channels===4?source[sourceOffset+3]:255;
}
return rgba;
}