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

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

+51
查看文件
@@ -0,0 +1,51 @@
#import <AppKit/AppKit.h>
#import "../大鱼调色/Plugin/DYLUTLibrary.h"
#include <CommonCrypto/CommonDigest.h>
// Read user-provided files in place; only import into a unique disposable library.
static NSString *digest(NSURL *url) {
NSData *data=[NSData dataWithContentsOfURL:url];if(!data)return @"unreadable";
unsigned char bytes[CC_SHA256_DIGEST_LENGTH];CC_SHA256(data.bytes,(CC_LONG)data.length,bytes);
NSMutableString *hex=[NSMutableString string];for(unsigned char byte:bytes)[hex appendFormat:@"%02x",byte];return hex;
}
int main(int argc,const char **argv){@autoreleasepool{
if(argc!=3){fprintf(stderr,"usage: verify-external-lut-folder <folder> <report.json>\n");return 2;}
NSFileManager *fm=NSFileManager.defaultManager;NSURL *source=[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];
NSMutableArray *files=[NSMutableArray array],*rows=[NSMutableArray array];NSUInteger sidecars=0;
for(NSURL *url in [fm enumeratorAtURL:source includingPropertiesForKeys:@[NSURLIsRegularFileKey] options:0 errorHandler:nil]){
if([url.lastPathComponent hasPrefix:@"._"]){sidecars++;continue;}
NSNumber *regular=nil;[url getResourceValue:&regular forKey:NSURLIsRegularFileKey error:nil];
if(regular.boolValue&&[url.pathExtension.lowercaseString isEqual:@"cube"])[files addObject:url];
}
[files sortUsingComparator:^NSComparisonResult(NSURL *a,NSURL *b){return [a.path localizedStandardCompare:b.path];}];
BOOL parsedAll=files.count>0;NSMutableDictionary *originalHashes=[NSMutableDictionary dictionary];
for(NSURL *url in files){@autoreleasepool{
NSError *error=nil;std::vector<float> values;NSUInteger size=0;BOOL parsed=DYLUTReadCube(url.path,values,size,&error);parsedAll&=parsed;
originalHashes[url.lastPathComponent]=digest(url);
[rows addObject:@{@"file":url.lastPathComponent,@"dimension":@(size),@"parsed":@(parsed),@"error":error.localizedDescription?:@""}];
}}
NSURL *temporary=[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[@"dayu-external-lut-folder-" stringByAppendingString:NSUUID.UUID.UUIDString]]];
DYLUTLibrary *library=[[DYLUTLibrary alloc]initWithRootURL:[temporary URLByAppendingPathComponent:@"library"]];
__block BOOL done=NO;__block NSUInteger importedCount=0;__block NSError *importError=nil;
__block double last=NSProcessInfo.processInfo.systemUptime,maxGap=0;__block NSUInteger ticks=0;
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:.005 repeats:YES block:^(NSTimer *t){double now=NSProcessInfo.processInfo.systemUptime;maxGap=MAX(maxGap,now-last);last=now;ticks++;(void)library.entries;}];
NSProgress *task=[library importURLsAsync:@[source] completion:^(NSArray *imported,NSError *error){importedCount=imported.count;importError=[error retain];done=YES;}];
double deadline=NSProcessInfo.processInfo.systemUptime+120;
while(!done&&NSProcessInfo.processInfo.systemUptime<deadline)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
[timer invalidate];if(!done)[task cancel];
BOOL thumbnails=done&&!importError&&importedCount==files.count,identical=thumbnails;
if(done&&!importError)for(NSDictionary *entry in library.entries){@autoreleasepool{
NSError *error=nil;thumbnails&=DYLUTThumbnail(entry[@"path"],nil,0,0,NSMakeSize(64,36),&error)!=nil;
identical&=[digest([NSURL fileURLWithPath:entry[@"path"]])isEqual:originalHashes[[entry[@"path"]lastPathComponent]]];
}}
BOOL originalUnchanged=YES;for(NSURL *url in files)originalUnchanged&=[digest(url)isEqual:originalHashes[url.lastPathComponent]];
BOOL pass=done&&parsedAll&&!importError&&importedCount==files.count&&thumbnails&&identical&&originalUnchanged&&maxGap<.15;
NSDictionary *report=@{@"pass":@(pass),@"sourceFolder":source.path,@"sourceFiles":@(files.count),@"appleDoubleSidecars":@(sidecars),@"files":rows,
@"plannedFiles":@(MAX((int64_t)0,task.totalUnitCount)/2),@"importedFiles":@(importedCount),@"importError":importError.localizedDescription?:@"",
@"allThumbnailsGenerated":@(thumbnails),@"importedContentsIdentical":@(identical),@"sourceFilesUnchanged":@(originalUnchanged),
@"mainHeartbeatMaxGapMS":@(maxGap*1000),@"mainHeartbeatTicks":@(ticks),@"userLibraryModified":@NO,
@"scope":@"User-supplied LUTs read only; isolated library import and thumbnail generation. No LUT data redistributed, no GUI or host parameter edits."};
NSData *json=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:nil];[json writeToFile:[NSString stringWithUTF8String:argv[2]] atomically:YES];
if(done&&[fm fileExistsAtPath:temporary.path])[fm removeItemAtURL:temporary error:nil];[library release];[importError release];
printf("%s: %lu sources, %lu imported\n",pass?"PASS":"FAIL",(unsigned long)files.count,(unsigned long)importedCount);return pass?0:1;
}}
+19 -1
查看文件
@@ -45,6 +45,24 @@ int main(int argc,const char **argv){@autoreleasepool{
require(gain&&near(out[0],.555)&&near(out[1],.28)&&near(out[2],.81),@"red gain trilinear interpolation");
NSData *ranged=DYLUTTransformRGBA(input,1,1,domain.path,&error);out=(const float *)ranged.bytes;
require(ranged&&near(out[0],.185)&&near(out[1],.14)&&near(out[2],.405),@"DOMAIN normalization resamples Cube");
NSURL *legacy=write(temporary,@"LegacyMetadata/Legacy.cube",@"");
NSMutableData *legacyBytes=[NSMutableData dataWithBytes:"TITLE \"" length:7];
const unsigned char titleBytes[]={0xc7,0xe0,0xb3,0xc8};[legacyBytes appendBytes:titleBytes length:sizeof(titleBytes)];
[legacyBytes appendData:[@"\"\n# legacy comment " dataUsingEncoding:NSUTF8StringEncoding]];[legacyBytes appendBytes:titleBytes length:sizeof(titleBytes)];
[legacyBytes appendData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];[legacyBytes appendData:[cube()dataUsingEncoding:NSUTF8StringEncoding]];
require([legacyBytes writeToURL:legacy atomically:YES],@"write legacy-encoded descriptive metadata fixture");
require(DYLUTReadCube(legacy.path,values,n,&error)&&n==2,@"legacy TITLE and comments do not invalidate ASCII numeric payload");
require([DYLUTTransformRGBA(input,1,1,legacy.path,&error)isEqual:neutral],@"legacy descriptive encoding leaves numeric colors unchanged");
NSURL *invalidNumeric=write(temporary,@"LegacyMetadata/InvalidNumeric.cube",@"");
NSMutableData *invalidBytes=[NSMutableData dataWithData:[@"LUT_3D_SIZE 2\n0 0 0" dataUsingEncoding:NSUTF8StringEncoding]];
const unsigned char invalidByte=0xff;[invalidBytes appendBytes:&invalidByte length:1];
[invalidBytes appendData:[@"\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n" dataUsingEncoding:NSUTF8StringEncoding]];
require([invalidBytes writeToURL:invalidNumeric atomically:YES],@"write corrupt numeric suffix fixture");
require(!DYLUTReadCube(invalidNumeric.path,values,n,&error)&&values.empty()&&n==0,@"non-ASCII numeric suffix remains invalid");
DYLUTLibrary *metadataLibrary=[[[DYLUTLibrary alloc]initWithRootURL:[temporary URLByAppendingPathComponent:@"MetadataLibrary"]]autorelease];
NSArray *metadataImported=[metadataLibrary importURLs:@[legacy] error:&error];
require(metadataImported.count==1&&[[NSData dataWithContentsOfFile:metadataImported[0][@"path"]]isEqual:legacyBytes],@"legacy metadata imports without rewriting source bytes");
require(![metadataLibrary importURLs:@[invalidNumeric] error:&error]&&[error.localizedDescription containsString:@"InvalidNumeric.cube"]&&metadataLibrary.entries.count==1,@"failed import names the file and preserves previous library");
NSData *clear=DYLUTTransformRGBA(sample(NAN,.2,.3),1,1,nil,&error);out=(const float *)clear.bytes;
require(clear&&out[0]==0&&out[1]==0&&out[2]==0&&out[3]==0,@"invalid float samples become clear");
require(!DYLUTTransformRGBA([NSData data],1,1,nil,&error),@"reject malformed float RGBA length");
@@ -66,7 +84,7 @@ int main(int argc,const char **argv){@autoreleasepool{
if(!DYLUTReadCube(red.path,local,dimension,NULL)||dimension!=2||!near(local[4],1.6))parallelState->store(false);
}});
require(parallelOK,@"concurrent table cache reads stay consistent");
NSArray *invalid=@[@"LUT_3D_SIZE 1\n0 0 0\n",@"LUT_3D_SIZE 129\n",@"LUT_3D_SIZE 2\n0 0 0\n",@"LUT_1D_SIZE 2\n0 0 0\n1 1 1\n",@"LUT_3D_SIZE 2\nNaN 0 0\n",[cube() stringByAppendingString:@"0 0 0\n"],[cube() stringByAppendingString:@"DOMAIN_MAX 0 1 1\n"],[cube() stringByAppendingString:@"garbage\n"],[cube() stringByAppendingString:@"LUT_3D_SIZE 2\n"]];
NSArray *invalid=@[@"",[cube()stringByReplacingOccurrencesOfString:@"LUT_3D_SIZE 2" withString:@"LUT_3D_SIZE 2junk"],[cube()stringByAppendingString:@"DOMAIN_MAX 1 1 1 junk\n"],@"LUT_3D_SIZE 1\n0 0 0\n",@"LUT_3D_SIZE 129\n",@"LUT_3D_SIZE 2\n0 0 0\n",@"LUT_1D_SIZE 2\n0 0 0\n1 1 1\n",@"LUT_3D_SIZE 2\nNaN 0 0\n",[cube() stringByAppendingString:@"0 0 0\n"],[cube() stringByAppendingString:@"DOMAIN_MAX 0 1 1\n"],[cube() stringByAppendingString:@"garbage\n"],[cube() stringByAppendingString:@"LUT_3D_SIZE 2\n"]];
NSUInteger invalidIndex=0;
for(NSString *text in invalid) {
NSURL *url=write(temporary,[NSString stringWithFormat:@"Invalid%lu.cube",(unsigned long)invalidIndex++],text);
+25
查看文件
@@ -94,6 +94,31 @@ int main(int argc,const char *argv[]) {@autoreleasepool {
NSUInteger folderViews=[[browser valueForKey:@"folderButtons"]count];
[browser importSelectedURLs:@[source]];[browser close];done=NO;[library reloadAsync:^(NSError *failure){require(!failure,@"scan after browser close completes");done=YES;}];pump(^{return done;});
require(library.entries.count==3025,@"closing during import cancels without changing existing library");
// Host acknowledgement is the selection boundary, including rejection,
// cancellation and an older completion arriving after a newer click.
NSMutableArray *acknowledgements=[NSMutableArray array],*applyTasks=[NSMutableArray array];
DYLUTBrowser *ackBrowser=[[DYLUTBrowser alloc]initWithLibrary:library preview:nil selectedPath:anchor.path palette:@{} selection:^NSProgress *(NSString *path,void (^completion)(NSError *)){
[acknowledgements addObject:[[completion copy]autorelease]];NSProgress *task=[NSProgress discreteProgressWithTotalUnitCount:1];[applyTasks addObject:task];return task;
}];
pump(^{return [ackBrowser valueForKey:@"libraryTask"]==nil;});
NSDictionary *ackTiles=[ackBrowser valueForKey:@"tiles"];NSArray *ackPaths=ackTiles.allKeys;require(ackPaths.count>=2,@"acknowledgement fixture has selectable thumbnails");
id firstTile=ackTiles[ackPaths[0]],secondTile=ackTiles[ackPaths[1]];[firstTile setEnabled:YES];[secondTile setEnabled:YES];
[ackBrowser thumbnailClicked:firstTile];
require([[ackBrowser valueForKey:@"selectedPath"]isEqual:anchor.path]&&[[[ackBrowser valueForKey:@"statusLabel"]stringValue]hasPrefix:@"正在载入"],@"thumbnail stays loading until host application acknowledges");
void (^rejected)(NSError *)=acknowledgements[0];rejected([NSError errorWithDomain:@"test.host" code:1 userInfo:@{NSLocalizedDescriptionKey:@"Host rejected this edit"}]);
require([[ackBrowser valueForKey:@"selectedPath"]isEqual:anchor.path]&&[[[ackBrowser valueForKey:@"statusLabel"]stringValue]isEqual:@"Host rejected this edit"],@"host rejection preserves previous selection and reports the error");
[ackBrowser thumbnailClicked:firstTile];[ackBrowser thumbnailClicked:secondTile];
require([applyTasks[1]isCancelled],@"new thumbnail click cancels previous application task");
void (^older)(NSError *)=acknowledgements[1];older(nil);
require([[ackBrowser valueForKey:@"selectedPath"]isEqual:anchor.path],@"late older acknowledgement cannot mark a stale LUT selected");
void (^latest)(NSError *)=acknowledgements[2];latest(nil);
require([[ackBrowser valueForKey:@"selectedPath"]isEqual:ackPaths[1]],@"only acknowledged latest thumbnail becomes selected");
[ackBrowser clearSelection:nil];
require([[ackBrowser valueForKey:@"selectedPath"]isEqual:ackPaths[1]],@"removal also waits for host acknowledgement");
void (^removed)(NSError *)=acknowledgements[3];removed(nil);require([ackBrowser valueForKey:@"selectedPath"]==nil,@"acknowledged removal clears selection");
[ackBrowser thumbnailClicked:firstTile];[ackBrowser close];require([applyTasks.lastObject isCancelled],@"closing the browser cancels pending host application");
void (^afterClose)(NSError *)=acknowledgements[4];afterClose(nil);require([ackBrowser valueForKey:@"selectedPath"]==nil,@"completion after close cannot change the selection");
[acknowledgements removeAllObjects];[ackBrowser release];
[browser release];report[@"largeCatalogEntries"]=@(visible);report[@"initialLiveThumbnailViews"]=@(tileCount);report[@"initialLiveFolderViews"]=@(folderViews);report[@"pass"]=@YES;
#else
report[@"mode"]=@"baseline synchronous import";