From 497eef29fe8eaa5fb7025aa045b6dfa46a9acc14 Mon Sep 17 00:00:00 2001 From: mac Date: Sun, 1 Nov 2026 15:21:18 +0800 Subject: [PATCH] fix: import legacy-title Cube folders and verify all 26 supplied LUTs --- tools/verify_external_lut_folder.mm | 51 ++++++ tools/verify_lut_library.mm | 20 ++- tools/verify_lut_responsiveness.mm | 25 +++ verification/ExternalLUTActivation.json | 218 ++++++++++++++++++++++-- 大鱼调色/Plugin/DYDiagnostics.mm | 18 ++ 大鱼调色/Plugin/DYInspector.mm | 2 +- 大鱼调色/Plugin/DYLUTBrowser.mm | 2 +- 大鱼调色/Plugin/DYLUTLibrary.mm | 24 ++- 大鱼调色/Plugin/DYRenderer.mm | 8 +- 9 files changed, 343 insertions(+), 25 deletions(-) create mode 100644 tools/verify_external_lut_folder.mm diff --git a/tools/verify_external_lut_folder.mm b/tools/verify_external_lut_folder.mm new file mode 100644 index 0000000..012ab7c --- /dev/null +++ b/tools/verify_external_lut_folder.mm @@ -0,0 +1,51 @@ +#import +#import "../大鱼调色/Plugin/DYLUTLibrary.h" +#include + +// 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 \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:®ular 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 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.systemUptimestore(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); diff --git a/tools/verify_lut_responsiveness.mm b/tools/verify_lut_responsiveness.mm index 68f6ebd..e5d2809 100644 --- a/tools/verify_lut_responsiveness.mm +++ b/tools/verify_lut_responsiveness.mm @@ -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"; diff --git a/verification/ExternalLUTActivation.json b/verification/ExternalLUTActivation.json index a630a69..2a330d0 100644 --- a/verification/ExternalLUTActivation.json +++ b/verification/ExternalLUTActivation.json @@ -1,18 +1,24 @@ { "date": "2026-11-01", - "status": "development-preflight-passed-formal-host-verification-pending", + "status": "real-folder-preflight-passed-formal-host-verification-pending", "version": "1.1.4", "build": "15", - "reportedTrigger": "External LUT imported successfully, then thumbnail clicked to apply", + "reportedTrigger": [ + "External LUT thumbnail application hangs after successful import", + "N12精选luts folder import fails" + ], "baselineCommit": "a2c8dfafcfe8c1974ec560b9586b78052356a0e4", "finding": "A preview-cache preheat did not pin the selected table or GPU texture; frame rendering still performed path metadata queries and could parse external text again. Browser acknowledged selection before the inspector finished application.", "changes": [ "Decode and upload on the renderer preparation queue before committing the host path.", "Retain immutable selected snapshots independently of preview caches; no file metadata or parsing on prepared frame paths.", "Acknowledge browser selection only after preparation and accepted host write.", - "Cancel stale requests before they can overwrite a newer host selection." + "Cancel stale requests before they can overwrite a newer host selection.", + "Keep preview work at utility priority and selected LUT preparation at user-initiated priority.", + "Reuse prepared GPU device pipelines when the host supplies the actual registry ID.", + "Allow legacy-encoded TITLE/comments while strictly validating ASCII numeric data and include the failing filename in import errors." ], - "nativeChecks": 92, + "nativeChecks": 171, "nativePassed": true, "externalChecks": [ { @@ -65,13 +71,205 @@ "pass": true } ], - "browserChecks": 56, + "browserChecks": 67, "browserPassed": true, - "browserMainMaxGapMS": 7.393208332359791, - "libraryChecks": 92, + "browserMainMaxGapMS": 6.391000002622604, + "libraryChecks": 112, "libraryPassed": true, "limitations": [ - "No failing user-supplied LUT file was available in this run; the original user hang is not yet independently reproduced.", - "These preflight cases use synthetic local files and actual Metal/IOSurface rendering; live formal FCP acceptance remains a separate gate." - ] + "The actual supplied folder import failure was reproduced and fixed. The earlier unspecified user thumbnail hang was not captured while occurring.", + "Real-folder import, thumbnail and Metal checks passed; live formal Final Cut Pro acceptance remains pending.", + "No older macOS, Intel or network-volume benchmark; no full VoiceOver audit." + ], + "realFolder": { + "sourceFolder": "/Volumes/备份/N12精选luts", + "baseline": { + "importedFiles": 0, + "error": "LUT 必须是 UTF-8 文本", + "failedFiles": [ + "青橙色.cube", + "青橙色2.cube" + ] + }, + "fixedImport": { + "importError": "", + "sourceFilesUnchanged": true, + "mainHeartbeatMaxGapMS": 6.27491669729352, + "userLibraryModified": false, + "importedContentsIdentical": true, + "mainHeartbeatTicks": 794, + "allThumbnailsGenerated": true, + "scope": "User-supplied LUTs read only; isolated library import and thumbnail generation. No LUT data redistributed, no GUI or host parameter edits.", + "files": [ + { + "parsed": true, + "file": "超强质感高对比.cube", + "error": "", + "dimension": 17 + }, + { + "parsed": true, + "file": "城市莫兰迪灰2 加亮.cube", + "error": "", + "dimension": 32 + }, + { + "parsed": true, + "file": "复古-大白鲨.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "复古胶片风.cube", + "error": "", + "dimension": 32 + }, + { + "parsed": true, + "file": "复古清新干净1.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "复古清新干净2.cube", + "error": "", + "dimension": 32 + }, + { + "parsed": true, + "file": "复古清新干净3.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "感性内敛色调.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "户外森林2.cube", + "error": "", + "dimension": 16 + }, + { + "parsed": true, + "file": "绿转白.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "绿转粉.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "绿转紫.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "内景(柔皮肤).cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "青橙色.cube", + "error": "", + "dimension": 32 + }, + { + "parsed": true, + "file": "青橙色2.cube", + "error": "", + "dimension": 32 + }, + { + "parsed": true, + "file": "清新亮调.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "万能青橙色.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "质感超高对比.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "质感低对比.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "质感高对比1.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "质感高对比2.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "质感高对比暗部发红.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "质感中对比.cube", + "error": "", + "dimension": 33 + }, + { + "parsed": true, + "file": "自然高对比高饱和.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "自然清新.cube", + "error": "", + "dimension": 64 + }, + { + "parsed": true, + "file": "AAChangyong1.cube", + "error": "", + "dimension": 64 + } + ], + "sourceFolder": "/Volumes/备份/N12精选luts", + "pass": true, + "importedFiles": 26, + "sourceFiles": 26, + "appleDoubleSidecars": 0, + "plannedFiles": 26 + }, + "metal": { + "checks": 171, + "pass": true, + "files": 26, + "scope": "Every supplied LUT prepared asynchronously and rendered through actual Metal/IOSurface. No user file changes or LUT redistribution." + } + } } diff --git a/大鱼调色/Plugin/DYDiagnostics.mm b/大鱼调色/Plugin/DYDiagnostics.mm index 033a9ac..f51890c 100644 --- a/大鱼调色/Plugin/DYDiagnostics.mm +++ b/大鱼调色/Plugin/DYDiagnostics.mm @@ -249,6 +249,24 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { deadline=NSProcessInfo.processInfo.systemUptime+10; while(!cancelledDone&&NSProcessInfo.processInfo.systemUptime0&&allUserFrames,@{@"files":@(userCount),@"sourceFolder":userFolder,@"sourceFilesModified":@NO}); + } [gpu release]; } @catch(NSException *exception) { run.record(@"diagnostic-exception",false,@{@"exception":exception.name?:@"unknown",@"message":exception.reason?:@"unknown"}); diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index c2e11c4..5591f16 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -412,7 +412,7 @@ static NSImage *DYWheelImage(void) { self.layer.backgroundColor=[DYThemePalette()[@"background"] CGColor]; self.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; _brand=[DYLabel(@"◒ 大鱼调色",16) retain]; _brand.font=[NSFont boldSystemFontOfSize:16];_brand.textColor=DYInk(); - _subtitle=[DYLabel([[NSBundle bundleForClass:self.class]objectForInfoDictionaryKey:@"CFBundleShortVersionString"]?:@"1.1.3",9) retain]; _subtitle.textColor=DYThemeColor(@"secondary"); + _subtitle=[DYLabel([[NSBundle bundleForClass:self.class]objectForInfoDictionaryKey:@"CFBundleShortVersionString"]?:@"1.1.4",9) retain]; _subtitle.textColor=DYThemeColor(@"secondary"); _resetAll=[DYButton(@"↺",self,@selector(resetAll:)) retain];_resetAll.bordered=NO; _resetAll.toolTip=@"恢复全部调色参数与 LUT";_resetAll.accessibilityLabel=@"全部还原"; _save=[DYButton(@"保存预设",self,@selector(savePreset:)) retain]; _load=[DYButton(@"载入预设",self,@selector(loadPreset:)) retain]; diff --git a/大鱼调色/Plugin/DYLUTBrowser.mm b/大鱼调色/Plugin/DYLUTBrowser.mm index bf7aad6..3493ab6 100644 --- a/大鱼调色/Plugin/DYLUTBrowser.mm +++ b/大鱼调色/Plugin/DYLUTBrowser.mm @@ -138,7 +138,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b if((self=[super initWithWindow:panel])){ NSString *savedFolder=[[NSUserDefaults standardUserDefaults]stringForKey:DYBrowserFolderPreference]; _library=[library retain];_preview=[rgba copy];_selectedPath=[path copy];_folder=[(savedFolder?:@"*") copy];_selection=[selection copy]; - _folderButtons=[NSMutableArray new];_tiles=[NSMutableDictionary new];_queuedPaths=[NSMutableSet new];_thumbnailCache=[NSCache new];_thumbnailCache.countLimit=600;_thumbnailCache.totalCostLimit=64*1024*1024;_previewQueue=dispatch_queue_create("com.dayu.color.lut-thumbnails",DISPATCH_QUEUE_SERIAL); + _folderButtons=[NSMutableArray new];_tiles=[NSMutableDictionary new];_queuedPaths=[NSMutableSet new];_thumbnailCache=[NSCache new];_thumbnailCache.countLimit=600;_thumbnailCache.totalCostLimit=64*1024*1024;_previewQueue=dispatch_queue_create("com.dayu.color.lut-thumbnails",DISPATCH_QUEUE_SERIAL);dispatch_set_target_queue(_previewQueue,dispatch_get_global_queue(QOS_CLASS_UTILITY,0)); panel.title=@"风格 LUT";panel.minSize=NSMakeSize(760,420);panel.releasedWhenClosed=NO;panel.hidesOnDeactivate=NO;panel.delegate=self; _root=[[DYBrowserCanvas alloc]initWithFrame:NSMakeRect(0,0,760,560)];_root.accessibilityLabel=@"LUT 缩略图浏览库";panel.contentView=_root; _titleLabel=[BrowserLabel(@"LUT 文件夹",14)retain];_titleLabel.font=[NSFont systemFontOfSize:14 weight:NSFontWeightSemibold]; diff --git a/大鱼调色/Plugin/DYLUTLibrary.mm b/大鱼调色/Plugin/DYLUTLibrary.mm index b823d2a..7e494e4 100644 --- a/大鱼调色/Plugin/DYLUTLibrary.mm +++ b/大鱼调色/Plugin/DYLUTLibrary.mm @@ -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& 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& 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& 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 values;NSUInteger n=0;valid=!DYLUTCancelled(progress,&itemError)&&DYLUTReadCancellable([plan[@"source"]path],values,n,progress,&itemError);[itemError retain]; + std::vector 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 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++; } diff --git a/大鱼调色/Plugin/DYRenderer.mm b/大鱼调色/Plugin/DYRenderer.mm index 9571832..c40fc75 100644 --- a/大鱼调色/Plugin/DYRenderer.mm +++ b/大鱼调色/Plugin/DYRenderer.mm @@ -19,7 +19,7 @@ static id texture3D(idd,const float*values,NSUInteger n){ } @end @implementation DYRenderer -- (instancetype)init{if((self=[super init])){_previewLock=[NSObject new];_devices=[NSMutableDictionary new];_luts=[NSMutableDictionary new];_preparedLUTs=[NSMutableDictionary new];_activeLUTPaths=[NSSet new];_lutPreparationQueue=dispatch_queue_create("com.dayu.color.lut-upload",DISPATCH_QUEUE_SERIAL);_tables=[DYColorTables new];}return self;} +- (instancetype)init{if((self=[super init])){_previewLock=[NSObject new];_devices=[NSMutableDictionary new];_luts=[NSMutableDictionary new];_preparedLUTs=[NSMutableDictionary new];_activeLUTPaths=[NSSet new];_lutPreparationQueue=dispatch_queue_create("com.dayu.color.lut-upload",DISPATCH_QUEUE_SERIAL);dispatch_set_target_queue(_lutPreparationQueue,dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0));_tables=[DYColorTables new];}return self;} - (void)dealloc{[_devices release];[_luts release];[_preparedLUTs release];[_activeLUTPaths release];dispatch_release(_lutPreparationQueue);[_tables release];[_preview release];[_lookLUTPreview release];[_previewLock release];[super dealloc];} - (void)trimPreparedLUTsKeeping:(NSString *)path { if(_preparedLUTs.count<=12)return; @@ -54,7 +54,9 @@ static id texture3D(idd,const float*values,NSUInteger n){ idq=[d newCommandQueue];entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"library":lib,@"queue":q,@"pipelines":[NSMutableDictionary dictionary]}]; for(NSString*fn in @[@"dyUnpremultiply",@"dyWhitesSceneStatistics",@"dyLUTExportKernel",@"dyInputAnalysis"]){idf=[lib newFunctionWithName:fn];if(!f){fail(err,[fn stringByAppendingString:@" 缺失"]);[lib release];[q release];[d release];return nil;}idp=[d newComputePipelineStateWithFunction:f error:err];[f release];if(!p){[lib release];[q release];[d release];return nil;}entry[fn]=p;[p release];} float identity[32];for(int z=0;z<2;z++)for(int y=0;y<2;y++)for(int x=0;x<2;x++){int i=((z*2+y)*2+x)*4;identity[i]=x;identity[i+1]=y;identity[i+2]=z;identity[i+3]=1;}idneutral=texture3D(d,identity,2);if(!neutral){fail(err,@"无法分配中性 LUT");return nil;}entry[@"identity"]=neutral; - _devices[k]=entry;[d release];[lib release];[q release];return entry; + // Preparing before the first frame may use registry 0. Reuse those pipelines + // when the host subsequently supplies that device's actual registry ID. + _devices[k]=entry;_devices[@(d.registryID)]=entry;[d release];[lib release];[q release];return entry; } - (id)lut:(NSString*)path entry:(NSDictionary*)e error:(NSError**)err{ if(!path.length)return e[@"identity"]; @@ -80,7 +82,7 @@ static id texture3D(idd,const float*values,NSUInteger n){ idh=[_tables hslForDevice:d uniforms:u],w=[_tables whiteBalanceForDevice:d uniforms:u],g=[_tables gradingForDevice:d uniforms:u];if(!h||!w||!g){fail(err,_tables.lastError?:@"颜色查表构建失败");return nil;}[ts addObjectsFromArray:@[h,w,g]];return ts; } - (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths error:(NSError**)err{@synchronized(self){@autoreleasepool{ - [_activeLUTPaths release];_activeLUTPaths=[[NSSet alloc]initWithArray:paths.allValues]; + [_activeLUTPaths release];_activeLUTPaths=[[NSSet alloc]initWithArray:paths.allValues?:@[]]; NSMutableDictionary*e=[self device:dst.deviceRegistryID error:err];if(!e)return NO;idd=e[@"device"];idinput=[src metalTextureForDevice:d],output=[dst metalTextureForDevice:d];if(!input||!output)return fail(err,@"宿主图像纹理不可用"); NSArray*ts=[self textures:paths uniforms:&u entry:e error:err];if(!ts)return NO; NSMutableDictionary*ps=e[@"pipelines"];NSNumber*format=@(output.pixelFormat);idpipeline=ps[format];if(!pipeline){MTLRenderPipelineDescriptor*p=[MTLRenderPipelineDescriptor new];p.vertexFunction=[e[@"library"]newFunctionWithName:@"dyVertex"];p.fragmentFunction=[e[@"library"]newFunctionWithName:@"dyFragment"];p.colorAttachments[0].pixelFormat=output.pixelFormat;pipeline=[d newRenderPipelineStateWithDescriptor:p error:err];[p.vertexFunction release];[p.fragmentFunction release];[p release];if(!pipeline)return NO;ps[format]=pipeline;[pipeline release];}