复用 LUT 浏览器位图并消除点击闪黑

这个提交包含在:
mac 于 2026-11-08 21:50:39 +08:00 提交
1 父节点 a0225404a2
当前提交 e0bd8342c0
9 个文件已更改
+150 -83

没有与搜索条件相匹配的文件

+8 -2
查看文件
@@ -303,6 +303,10 @@ static NSData *DYLUTFallback(void) {
});return chart;
}
static inline uint8_t DYLUTPreviewByte(float value) {
return (uint8_t)lroundf(std::max(0.f,std::min(1.f,value))*255);
}
NSImage *DYLUTThumbnail(NSString *path,NSData *source,NSUInteger sourceWidth,NSUInteger sourceHeight,NSSize outputSize,NSError **error) {
if(!std::isfinite(outputSize.width)||!std::isfinite(outputSize.height)||outputSize.width<1||outputSize.height<1||outputSize.width>2048||outputSize.height>2048) {
DYLUTFail(error,@"缩略图尺寸无效");return nil;
@@ -315,7 +319,9 @@ NSImage *DYLUTThumbnail(NSString *path,NSData *source,NSUInteger sourceWidth,NSU
bitmapFormat:NSBitmapFormatAlphaNonpremultiplied bytesPerRow:width*4 bitsPerPixel:32]autorelease];
if(!bitmap){DYLUTFail(error,@"无法分配缩略图位图");return nil;}
const float *p=(const float *)transformed.bytes;uint8_t *q=bitmap.bitmapData;
for(NSUInteger y=0;y<height;y++)for(NSUInteger x=0;x<width;x++) {
if(width==sourceWidth&&height==sourceHeight){
for(NSUInteger i=0;i<width*height*4;i++)q[i]=DYLUTPreviewByte(p[i]);
}else for(NSUInteger y=0;y<height;y++)for(NSUInteger x=0;x<width;x++) {
// Center-aligned bilinear scaling, independent of NSGraphicsContext.
float fx=(float(x)+.5f)*sourceWidth/width-.5f,fy=(float(y)+.5f)*sourceHeight/height-.5f;
fx=std::max(0.f,std::min(float(sourceWidth-1),fx));fy=std::max(0.f,std::min(float(sourceHeight-1),fy));
@@ -324,7 +330,7 @@ NSImage *DYLUTThumbnail(NSString *path,NSData *source,NSUInteger sourceWidth,NSU
for(int c=0;c<4;c++) {
float v=(p[(y0*sourceWidth+x0)*4+c]*(1-tx)+p[(y0*sourceWidth+x1)*4+c]*tx)*(1-ty)
+(p[(y1*sourceWidth+x0)*4+c]*(1-tx)+p[(y1*sourceWidth+x1)*4+c]*tx)*ty;
q[(y*width+x)*4+c]=(uint8_t)lroundf(std::max(0.f,std::min(1.f,v))*255);
q[(y*width+x)*4+c]=DYLUTPreviewByte(v);
}
}
NSImage *image=[[[NSImage alloc]initWithSize:NSMakeSize(width,height)]autorelease];[image addRepresentation:bitmap];return image;