Support text-annotated Cube rows with Custom LUT zero-fill compatibility

这个提交包含在:
mac 于 2026-11-02 20:13:29 +08:00 提交
1 父节点 5c547100c1
当前提交 58a17de438
10 个文件已更改
+1307 -1072

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

+24 -1
查看文件
@@ -146,6 +146,16 @@ static std::string_view DYLUTTrim(std::string_view v) {
if(!count)break;v.remove_prefix(count);
}return v;
}
static bool DYLUTTextNote(std::string_view text,locale_t numericLocale) {
if(text.empty())return false;
// A note must be separated from the preceding number and start with real
// text. Do not reinterpret malformed bytes or NaN/Inf as an annotation.
char *end=nullptr;strtof_l(text.data(),&end,numericLocale);
if(end!=text.data())return false;
NSString *note=[[[NSString alloc]initWithBytes:text.data() length:text.size()
encoding:NSUTF8StringEncoding]autorelease];
return note.length&&[NSCharacterSet.letterCharacterSet characterIsMember:[note characterAtIndex:0]];
}
static BOOL DYLUTParse(NSString *path,std::vector<float>& data,NSUInteger& size,NSProgress *progress,NSError **error) {
data.clear();size=0;
NSDictionary *attributes=[[NSFileManager defaultManager]attributesOfItemAtPath:path error:error];
@@ -188,7 +198,20 @@ static BOOL DYLUTParse(NSString *path,std::vector<float>& data,NSUInteger& size,
} else if(starts("TITLE")||starts("LUT_3D_INPUT_RANGE"))continue;
else if(starts("LUT_1D_SIZE"))return DYLUTFail(error,@"请选择三维 .cube LUT");
else {
auto v=line;if(!number(v,r)||!number(v,g)||!number(v,b)||!trim(v).empty()||!std::isfinite(r)||!std::isfinite(g)||!std::isfinite(b))return DYLUTFail(error,[NSString stringWithFormat:@"LUT 第 %lu 行含无效数字或多余内容",(unsigned long)rows]);
auto v=line;float rgb[3]={0,0,0};bool valid=true;
for(int c=0;c<3;c++) {
auto token=trim(v);
if(!number(v,rgb[c])) {
// Custom LUT compatibility: retain the numeric prefix,
// zero unread channels, and keep this row's table position.
// Never search annotations for digits or skip a table row.
valid=c>0&&DYLUTTextNote(token,numericLocale);v={};break;
}
if(!std::isfinite(rgb[c])||(!v.empty()&&trim(v).size()==v.size())){valid=false;break;}
}
auto tail=trim(v);
if(!valid||(!tail.empty()&&!DYLUTTextNote(tail,numericLocale)))return DYLUTFail(error,[NSString stringWithFormat:@"LUT 第 %lu 行含无效数字或多余内容",(unsigned long)rows]);
r=rgb[0];g=rgb[1];b=rgb[2];
data.insert(data.end(),{r,g,b,1});if(data.size()>128*128*128*4)return DYLUTFail(error,@"LUT 数据过多");
}
}