fix: import legacy-title Cube folders and verify all 26 supplied LUTs

这个提交包含在:
mac 于 2026-11-01 15:21:18 +08:00 提交
1 父节点 593aad9ecb
当前提交 497eef29fe
9 个文件已更改
+343 -25

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

+15 -9
查看文件
@@ -74,6 +74,13 @@ static BOOL DYLUTCancelled(NSProgress *progress,NSError **error) {
if(error)*error=[NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:@{NSLocalizedDescriptionKey:@"已取消 LUT 加载"}];
return YES;
}
static NSError *DYLUTFileError(NSError *error,NSURL *url) {
if(error.code==NSUserCancelledError&&[error.domain isEqual:NSCocoaErrorDomain])return error;
NSMutableDictionary *info=[NSMutableDictionary dictionaryWithDictionary:error.userInfo?:@{}];
info[NSLocalizedDescriptionKey]=[NSString stringWithFormat:@"%@:%@",url.lastPathComponent,error.localizedDescription?:@"无法读取此 LUT"];
info[NSFilePathErrorKey]=url.path;if(error)info[NSUnderlyingErrorKey]=error;
return [NSError errorWithDomain:error.domain?:DYLUTLibraryErrorDomain code:error?error.code:1 userInfo:info];
}
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];
@@ -92,10 +99,9 @@ static BOOL DYLUTParse(NSString *path,std::vector<float>& data,NSUInteger& size,
for(float v:data)if(!std::isfinite(v))return DYLUTFail(error,@"输入 LUT 含无效数字");
size=n;return YES;
}
// Validate encoding once, then parse byte spans without allocating an
// NSString, NSArray and temporary strings for every numeric row.
NSString *text=[[NSString alloc]initWithData:bytes encoding:NSUTF8StringEncoding];
if(!text)return DYLUTFail(error,@"LUT 必须是 UTF-8 文本");[text release];
// Cube commands and numbers use ASCII. Descriptive TITLE/comments can
// legitimately use legacy encodings; they never affect the numeric table.
if(!bytes.length)return DYLUTFail(error,@"LUT 文件为空");
std::string storage((const char *)bytes.bytes,bytes.length);
static locale_t numericLocale;static dispatch_once_t localeOnce;dispatch_once(&localeOnce,^{numericLocale=newlocale(LC_NUMERIC_MASK,"C",NULL);});
float domainMin[3]={0,0,0},domainMax[3]={1,1,1};BOOL foundSize=NO;
@@ -112,15 +118,15 @@ static BOOL DYLUTParse(NSString *path,std::vector<float>& data,NSUInteger& size,
auto starts=[&](std::string_view prefix){return line.substr(0,prefix.size())==prefix;};
if(starts("LUT_3D_SIZE")) {
auto v=trim(line.substr(11));int n=0;auto result=std::from_chars(v.data(),v.data()+v.size(),n);
if(result.ec!=std::errc{}||foundSize||n<2||n>128)return DYLUTFail(error,@"LUT 尺寸应为 2–128,且只能声明一次");
if(result.ec!=std::errc{}||!trim(v.substr(result.ptr-v.data())).empty()||foundSize||n<2||n>128)return DYLUTFail(error,@"LUT 尺寸应为 2–128,且只能声明一次");
size=n;foundSize=YES;data.reserve(size*size*size*4);
} else if(starts("DOMAIN_MIN")||starts("DOMAIN_MAX")) {
auto v=line.substr(10);if(!number(v,r)||!number(v,g)||!number(v,b))return DYLUTFail(error,@"LUT DOMAIN 范围无效");
auto v=line.substr(10);if(!number(v,r)||!number(v,g)||!number(v,b)||!trim(v).empty())return DYLUTFail(error,@"LUT DOMAIN 范围无效");
float *domain=starts("DOMAIN_MIN")?domainMin:domainMax;domain[0]=r;domain[1]=g;domain[2]=b;
} 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)||!std::isfinite(r)||!std::isfinite(g)||!std::isfinite(b))return DYLUTFail(error,@"LUT 含无效数据行");
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]);
data.insert(data.end(),{r,g,b,1});if(data.size()>128*128*128*4)return DYLUTFail(error,@"LUT 数据过多");
}
}
@@ -370,7 +376,7 @@ static BOOL DYLUTEnsureDirectory(NSURL *directory,NSURL *root,NSError **error) {
NSError *itemError=nil;BOOL valid=NO;
@autoreleasepool{
progress.localizedDescription=[NSString stringWithFormat:@"正在校验 %lld/%lu",progress.completedUnitCount+1,(unsigned long)plans.count];progress.localizedAdditionalDescription=[plan[@"source"]lastPathComponent];
std::vector<float> values;NSUInteger n=0;valid=!DYLUTCancelled(progress,&itemError)&&DYLUTReadCancellable([plan[@"source"]path],values,n,progress,&itemError);[itemError retain];
std::vector<float> values;NSUInteger n=0;valid=!DYLUTCancelled(progress,&itemError)&&DYLUTReadCancellable([plan[@"source"]path],values,n,progress,&itemError);if(!valid)itemError=DYLUTFileError(itemError,plan[@"source"]);[itemError retain];
}
if(!valid){if(error)*error=[itemError autorelease];else[itemError release];return nil;}[itemError release];progress.completedUnitCount++;
}
@@ -389,7 +395,7 @@ static BOOL DYLUTEnsureDirectory(NSURL *directory,NSURL *root,NSError **error) {
if(![fm copyItemAtURL:plan[@"source"] toURL:destination error:&itemError])return NO;[created addObject:destination];
std::vector<float> values;NSUInteger n=0;if(!DYLUTReadCancellable(destination.path,values,n,progress,&itemError))return NO;
[imported addObject:DYLUTEntry(destination,_rootURL)];return YES;
}();[itemError retain];
}();if(!copied)itemError=DYLUTFileError(itemError,plan[@"source"]);[itemError retain];
}
if(!copied){if(error)*error=[itemError autorelease];else[itemError release];success=NO;break;}[itemError release];progress.completedUnitCount++;
}