From 58a17de43810798570b4965166d33129d949de3d Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 2 Nov 2026 20:13:29 +0800 Subject: [PATCH] Support text-annotated Cube rows with Custom LUT zero-fill compatibility --- Packaging/Release-1.7.1.md | 9 + research/LUTNotes1.7.1.md | 25 + tools/verify_lut_annotations.mm | 49 + verification/LUTAnnotations.json | 403 +++++ verification/LUTEncoding.json | 1791 +++++++++-------------- verification/LUTNoteAppleReference.json | 44 + 大鱼调色/Plugin/DYDiagnostics.mm | 23 + 大鱼调色/Plugin/DYLUTLibrary.mm | 25 +- 大鱼调色/Plugin/Info.plist | 6 +- 大鱼调色/Wrapper Application/Info.plist | 4 +- 10 files changed, 1307 insertions(+), 1072 deletions(-) create mode 100644 Packaging/Release-1.7.1.md create mode 100644 research/LUTNotes1.7.1.md create mode 100644 tools/verify_lut_annotations.mm create mode 100644 verification/LUTAnnotations.json create mode 100644 verification/LUTNoteAppleReference.json diff --git a/Packaging/Release-1.7.1.md b/Packaging/Release-1.7.1.md new file mode 100644 index 0000000..1cc479e --- /dev/null +++ b/Packaging/Release-1.7.1.md @@ -0,0 +1,9 @@ +# 大鱼调色 1.7.1(46) + +兼容部分 Cube LUT 在颜色数据行中夹带文字的情况:保留开头的有效数值,读不到的后续通道补 0,忽略文字尾注并保持各行位置,与本机 FCP“自定 LUT”处理用户提供文件的方式一致。编码兼容、正常 LUT 的浮点精度和原始文件保持不变。 + +仍拒绝缺失数据行、无效数值、损坏编码及错误尺寸。此兼容不会恢复被文字替换的原始颜色数值,也不对其进行插值猜测。 + +要求 Apple Silicon、macOS 14.6 或更新。唯一安装位置 `/Library/Plug-Ins/FxPlug/大鱼调色.app`,Bundle ID `com.dayu.color`。本轮不修改网站、公测更新清单或后端。 + +正式签名、公证、验证及发行包摘要见 `verification/Delivery.json`、`verification/Package.json` 与 `verification/Release.json`。 diff --git a/research/LUTNotes1.7.1.md b/research/LUTNotes1.7.1.md new file mode 100644 index 0000000..cc5a082 --- /dev/null +++ b/research/LUTNotes1.7.1.md @@ -0,0 +1,25 @@ +# 1.7.1:带文字行的 Cube 容错 + +基线为 `5c547100c1a15feb7a1a9a67c98f2ac44056583a`,正式版 1.7.0(45)。用户提供的 `tlfs.cube` 为 UTF-8、65³;两行保留 R 数值,G/B 位置被文字替换。原解析器报第 1899 行无效,编码识别本身没有失败。 + +## 苹果行为依据 + +本机 Final Cut Pro 12.4(454072)的 ProCore 中,`cc::lut_t::readCUBE` 逐行调用 `_readrow`,后者连续调用 `qdcstr2float`;遇到文字不会继续寻找其中的数字,读不到的通道输出 0,每行仍推进三个表格位置。只读分析使用 REA/Ghidra,临时提取 arm64 切片,未修改 Apple APP。 + +通过已签名原始框架的实际行读取函数,对用户原文件全部 274625 行进行受控重放:两处结果分别为 `(559,0,0)`、`(45643,0,0)`(16 位);本产品保留原有浮点精度,对应 `(0.00854505,0,0)`、`(0.696468,0,0)`。全表差异不超过一个 16 位量化单位。摘要、版本、源文件与框架摘要见 `verification/LUTNoteAppleReference.json`。这证明本文件的数据读取规则,不代表与 FCP 的完整色彩管理、插值和最终画面逐像素相同。 + +## 独立实现及边界 + +- 数值与尾部文字必须以空白分开,至少存在一个有效前导数值;文字必须是有效 UTF-8 且以字母/汉字起始。已有 UTF-16/32 先按原机制归一化。 +- 保留已读取通道,文字起始后的未读取通道补 0;读满 RGB 后允许同样的文字尾注。不扫描尾注中的数字,不删除行、不插值、不重排。 +- 缺少数据行、纯文字行、没有尾注的残缺 RGB、NaN/Inf、四个数值、数值粘连文字、损坏字节、无效尺寸与 DOMAIN 继续拒绝。兼容范围有意小于苹果读取器的所有宽松行为。 +- 标准 LUT 仍使用既有浮点精度、DOMAIN 与缓存/异步/取消机制;产品不加载 Apple 私有框架,也不携带 Apple 代码。 +- 原文件及导入副本逐字节保留。用户 LUT 和仅供验证的完整数值副本不进入源码、安装包或远端。 + +## 验证入口 + +独立 `tools/verify_lut_annotations.mm` 覆盖 UTF-8/16/32、三种换行、补零与后续行位置、尾注数字、数值基准、缩略图、原字节导入及拒绝边界;既有库/编码回归同步运行。编译方法与现有原生检查一致:使用 `clang++ -std=c++17 -fblocks` 链接 `DYLUTLibrary.mm`、AppKit 与 zlib。 + +正式插件 `--self-test` 新增合成 Cube 与完整数值基准的 GPU 对照。可通过 `DY_DIAGNOSTIC_LUT_FILE` 和 `DY_DIAGNOSTIC_LUT_ORACLE` 追加只读用户文件检查,导入到本次自检的独立临时库,比较全表、缩略图、GPU 结果及源/导入字节;自检结束清理。不要把这些路径写入公测上传数据。 + +最终安装、公证、宿主、打包和 Release 状态以本轮交付记录为准。 diff --git a/tools/verify_lut_annotations.mm b/tools/verify_lut_annotations.mm new file mode 100644 index 0000000..5c98729 --- /dev/null +++ b/tools/verify_lut_annotations.mm @@ -0,0 +1,49 @@ +#import +#import "../大鱼调色/Plugin/DYLUTLibrary.h" +#include + +static NSMutableArray *checks; +static void need(BOOL pass,NSString *name){[checks addObject:@{@"name":name,@"pass":@(pass)}];if(!pass){fprintf(stderr,"FAIL %s\n",name.UTF8String);exit(1);}} +int main(int argc,const char **argv){@autoreleasepool{ + if(argc!=2)return 2;checks=[NSMutableArray new];NSError *error=nil; + NSFileManager *fm=NSFileManager.defaultManager; + NSURL *root=[NSURL fileURLWithPath:[NSTemporaryDirectory()stringByAppendingPathComponent:[@"dayu-lut-notes-" stringByAppendingString:NSUUID.UUID.UUIDString]]]; + need([fm createDirectoryAtURL:root withIntermediateDirectories:YES attributes:nil error:&error],@"isolated fixtures"); + NSString *header=@"TITLE \"Synthetic note compatibility\"\nLUT_3D_SIZE 2\n"; + NSString *normal=@"0.25 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n"; + NSString *notes=@"0.25 v3文字 100 分\n1 0 说明99\n0 1 0 完整数值 后记123\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n"; + NSURL *baseline=[root URLByAppendingPathComponent:@"baseline.cube"]; + need([[header stringByAppendingString:normal]writeToURL:baseline atomically:YES encoding:NSUTF8StringEncoding error:&error],@"write independent numeric oracle"); + std::vector expected;NSUInteger side=0; + need(DYLUTReadCube(baseline.path,expected,side,&error)&&side==2,@"read numeric oracle"); + float pixel[]={.37,.28,.81,.6};NSData *input=[NSData dataWithBytes:pixel length:sizeof(pixel)]; + NSData *reference=DYLUTTransformRGBA(input,1,1,baseline.path,&error); + NSArray *encodings=@[@(NSUTF8StringEncoding),@(NSUTF16LittleEndianStringEncoding),@(NSUTF16BigEndianStringEncoding),@(NSUTF32LittleEndianStringEncoding),@(NSUTF32BigEndianStringEncoding)]; + NSMutableArray *sources=[NSMutableArray array]; + for(NSNumber *encoding in encodings)for(NSString *newline in @[@"\n",@"\r\n",@"\r"]){@autoreleasepool{ + NSString *text=[[header stringByAppendingString:notes]stringByReplacingOccurrencesOfString:@"\n" withString:newline]; + NSURL *url=[root URLByAppendingPathComponent:[NSString stringWithFormat:@"note-%lu.cube",(unsigned long)sources.count]]; + NSData *bytes=[text dataUsingEncoding:encoding.unsignedIntegerValue]; + need([bytes writeToURL:url atomically:YES],@"write encoded annotations");[sources addObject:url]; + std::vector actual;NSUInteger n=0; + need(DYLUTReadCube(url.path,actual,n,&error)&&n==2&&actual==expected,@"zero unread channels, ignore note digits, preserve every later row"); + need([DYLUTTransformRGBA(input,1,1,url.path,&error)isEqual:reference],@"annotated and canonical cubes give exactly the same colors"); + need(DYLUTThumbnail(url.path,nil,0,0,NSMakeSize(32,18),&error)!=nil,@"annotated cube thumbnail"); + }} + NSArray *invalid=@[@"0.25\n",@"0.25 0\n",@"0.25 NaN 0\n",@"0.25 Inf 0\n",@"0.25 0 0 100\n",@"0.25oops 0 0\n",@"0.25 0broken 0\n",@"0.25 0 0broken\n",@"note only 100\n",@"0.25 0 0 NaN\n"]; + NSUInteger index=0; + for(NSString *first in invalid){ + NSURL *url=[root URLByAppendingPathComponent:[NSString stringWithFormat:@"invalid-%lu.cube",(unsigned long)index++]]; + NSString *text=[header stringByAppendingString:[normal stringByReplacingCharactersInRange:NSMakeRange(0,9) withString:first]]; + need([text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:&error],@"write invalid numeric fixture"); + std::vector actual;NSUInteger n=0; + need(!DYLUTReadCube(url.path,actual,n,&error)&&actual.empty()&&n==0,@"notes do not excuse malformed numbers, bare truncation, extra values or text-only rows"); + } + DYLUTLibrary *library=[[[DYLUTLibrary alloc]initWithRootURL:[root URLByAppendingPathComponent:@"library"]]autorelease]; + NSArray *imported=[library importURLs:sources error:&error]; + need(imported.count==sources.count,@"all annotated encodings import"); + for(NSUInteger i=0;i100,@{@"changedComponents":@(analysisChanges),@"maxAbsoluteError":@(analysisMaximum)}); NSString *lookFile=[runtime stringByAppendingPathComponent:@"diagnostic-look.cube"];NSMutableString *cube=[NSMutableString stringWithString:@"TITLE \"Self test look\"\nLUT_3D_SIZE 2\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n"]; for(int b=0;b<2;b++)for(int g=0;g<2;g++)for(int r=0;r<2;r++)[cube appendFormat:@"%.8f %.8f %.8f\n",.7f*r+.1f,.8f*g+.05f,.85f*b+.02f];error=nil;run.need(@"temporary-look-file",[cube writeToFile:lookFile atomically:YES encoding:NSUTF8StringEncoding error:&error],@{@"error":reason(error)}); + NSString *noteFile=[runtime stringByAppendingPathComponent:@"noted.cube"],*noteOracle=[runtime stringByAppendingPathComponent:@"note-oracle.cube"]; + NSString *noteRows=@"LUT_3D_SIZE 2\n0.25 v3文字 100 分\n1 0 说明99\n0 1 0 后记123\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n"; + NSString *oracleRows=@"LUT_3D_SIZE 2\n0.25 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n"; + run.need(@"lut-note-fixtures",[noteRows writeToFile:noteFile atomically:YES encoding:NSUTF8StringEncoding error:&error]&&[oracleRows writeToFile:noteOracle atomically:YES encoding:NSUTF8StringEncoding error:&error]); + std::vector notedTable,oracleTable;NSUInteger notedSide=0,oracleSide=0; + run.record(@"lut-note-retains-prefix-zero-fills-without-row-shift",DYLUTReadCube(noteFile,notedTable,notedSide,&error)&&DYLUTReadCube(noteOracle,oracleTable,oracleSide,&error)&¬edSide==2&&oracleSide==2&¬edTable==oracleTable); + u=defaults;u.lookSectionEnabled=1;u.postLUTStrength=1; + Pixels notePixels=render(run,renderer,source,destination,gpu,u,@{@"look0":noteFile},@"lut-note-metal-render"); + Pixels oraclePixels=render(run,renderer,source,destination,gpu,u,@{@"look0":noteOracle},@"lut-note-oracle-metal-render"); + Difference noteDelta=difference(notePixels,oraclePixels);run.record(@"lut-note-metal-exact-canonical-colors",noteDelta.nonfinite==0&¬eDelta.maximum==0,measure(noteDelta)); + NSString *userLUT=NSProcessInfo.processInfo.environment[@"DY_DIAGNOSTIC_LUT_FILE"],*userOracle=NSProcessInfo.processInfo.environment[@"DY_DIAGNOSTIC_LUT_ORACLE"]; + if(userLUT.length&&userOracle.length){ + NSData *original=[NSData dataWithContentsOfFile:userLUT];DYLUTLibrary *isolated=[[[DYLUTLibrary alloc]initWithRootURL:[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"user-lut-library"]]]autorelease]; + NSArray *items=[isolated importURLs:@[[NSURL fileURLWithPath:userLUT]] error:&error]; + run.need(@"user-lut-isolated-import",items.count==1,@{@"error":reason(error)}); + NSString *imported=items[0][@"path"];std::vector userTable,userExpected;NSUInteger userSide=0,expectedSide=0; + run.record(@"user-lut-exact-canonical-table",DYLUTReadCube(imported,userTable,userSide,&error)&&DYLUTReadCube(userOracle,userExpected,expectedSide,&error)&&userSide==expectedSide&&userTable==userExpected,@{@"dimension":@(userSide),@"rows":@(userTable.size()/4)}); + run.record(@"user-lut-thumbnail",DYLUTThumbnail(imported,nil,0,0,NSMakeSize(160,90),&error)!=nil); + Pixels actual=render(run,renderer,source,destination,gpu,u,@{@"look0":imported},@"user-lut-metal-render"); + Pixels expected=render(run,renderer,source,destination,gpu,u,@{@"look0":userOracle},@"user-lut-oracle-metal-render"); + Difference delta=difference(actual,expected);run.record(@"user-lut-metal-exact-canonical-colors",delta.nonfinite==0&&delta.maximum==0,measure(delta)); + run.record(@"user-lut-original-and-import-bytes-preserved",original&&[original isEqual:[NSData dataWithContentsOfFile:userLUT]]&&[original isEqual:[NSData dataWithContentsOfFile:imported]]); + } NSDictionary *paths=@{@"look0":lookFile,@"look1":lookFile,@"look2":lookFile,@"look3":lookFile,@"look4":lookFile};u=defaults;u.lookSectionEnabled=1;u.postLUTStrength=.35f;u.extraPostLUTStrengths=(DYFloat4){.4f,.5f,.6f,.7f};Pixels looks=render(run,renderer,source,destination,gpu,u,paths,@"renderer-five-look-pass");Difference looksDifference=difference(neutral,looks);run.record(@"five-look-mixes-affect-frame",looksDifference.nonfinite==0&&looksDifference.different>100,measure(looksDifference)); checkFoldedGroup(u,offsetof(DYUniforms,lookSectionEnabled),paths,@"disabled-look-bypasses-retained-LUTs"); NSURL *exportURL=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"diagnostic-export.cube"]];error=nil;run.need(@"renderer-export-33cube",[renderer exportLUT:exportURL uniforms:u paths:paths error:&error],@{@"error":reason(error),@"path":exportURL.path}); diff --git a/大鱼调色/Plugin/DYLUTLibrary.mm b/大鱼调色/Plugin/DYLUTLibrary.mm index d2ffe6b..20939fc 100644 --- a/大鱼调色/Plugin/DYLUTLibrary.mm +++ b/大鱼调色/Plugin/DYLUTLibrary.mm @@ -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& 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& 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 数据过多"); } } diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index a297cb8..3a8b85d 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.7.0 + 1.7.1 CFBundleVersion - 45 + 46 NSHumanReadableCopyright PlugInKit @@ -71,7 +71,7 @@ uuid 1C17B73B-F229-4C09-A434-EAF6DFF5F22A version - 1.7.0 + 1.7.1 className diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 80a37b0..0347c1a 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.7.0 + 1.7.1 CFBundleVersion - 45 + 46 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright