From 48b00c85799b0226ba32aba3f2e5397aa0e509ed Mon Sep 17 00:00:00 2001 From: mac Date: Sun, 1 Nov 2026 18:03:41 +0800 Subject: [PATCH] feat: validate CST primary color pipeline, neutral all-on defaults and saved independent disclosure --- research/CSTIntegration.md | 4 +- template/sources/RegisteredParameters.json | 17 +- template/verification/StaticContract.json | 2 +- template/大鱼调色.moef | 16 +- tools/build_template.py | 4 +- tools/verify_gpu.mm | 2 +- verification/CSTIntegration.json | 1019 ++++++++++++++++++++ 大鱼调色/Plugin/DYDiagnostics.mm | 85 +- 大鱼调色/Plugin/DYInspector.mm | 23 +- 大鱼调色/Plugin/DYModel.mm | 10 +- 大鱼调色/Plugin/DYRenderer.mm | 29 +- 11 files changed, 1173 insertions(+), 38 deletions(-) create mode 100644 verification/CSTIntegration.json diff --git a/research/CSTIntegration.md b/research/CSTIntegration.md index c6f0aae..d3e89b3 100644 --- a/research/CSTIntegration.md +++ b/research/CSTIntegration.md @@ -12,4 +12,6 @@ Cube 导出改用生产渲染路径生成 33³ 色格,包含新的 CST 与一级参数;关闭不可写入 Cube 的空间细节工具和逐画面统计。用户 LUT 和宿主资料不进入仓库。 -当前为实现检查点;原生回归、CST 数学对照、正式宿主验证和发行尚待完成。 +原生模型、真实 AppKit 折叠动作、IOSurface/Metal 和 Cube 导出已通过 153 项检查,其中 21 组参数与正式大鱼 CST 着色器直接逐像素对照(包含 17 个相机输入组合、ACEScct/Linear/新增曲线/显示曲线工作空间)。本机 Apple M4 的最大线性预乘分量误差为 0.0000152587890625。具体输入、原库摘要与边界见 verification/CSTIntegration.json。正式宿主与发行由独立记录确认。 + +为避免全眼睛开启让中性查表裁切 HDR,未调整的曲线/HSL/色轮/三原色/色阶/色彩平衡在渲染副本旁路;无其他实际调整时肤色保护也无需执行。原参数、眼睛和界面数值不变。默认输入与输出相同、一级中性且映射关闭时跳过可证明为恒等的往返,避免累积 half 量化误差。 diff --git a/template/sources/RegisteredParameters.json b/template/sources/RegisteredParameters.json index 1e1efa7..1550a35 100644 --- a/template/sources/RegisteredParameters.json +++ b/template/sources/RegisteredParameters.json @@ -51,7 +51,7 @@ "key": "cmConfigured", "kind": "bool", "max": 1, - "min": 0, + "min": -1, "offset": 944, "pid": 2236, "step": 0.01, @@ -76,6 +76,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 948, "options": [ "KOLOR Default", @@ -160,6 +161,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 952, "options": [ "KOLOR Default", @@ -234,6 +236,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 956, "options": [ "KOLOR Default", @@ -318,6 +321,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 960, "options": [ "KOLOR Default", @@ -692,6 +696,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 976, "options": [ "KOLOR Default", @@ -776,6 +781,7 @@ "kind": "popup", "max": 1003, "min": 0, + "notAnimatable": true, "offset": 980, "options": [ "KOLOR Default", @@ -850,6 +856,7 @@ "kind": "popup", "max": 1, "min": 0, + "notAnimatable": true, "offset": 984, "options": [ "关闭", @@ -857,7 +864,7 @@ ], "pid": 2246, "step": 0.01, - "title": "输出色调映射", + "title": "自动色调映射", "values": [ 0, 1 @@ -3025,8 +3032,10 @@ ], "sourceSHA256": { "template/tools/dump_model.mm": "2ef22e010e0cae15b73107d39fb2c125f6049b1e5405e88078f936cf29e79350", + "大鱼调色/Plugin/DYCSTTypes.h": "3372e3cd77248eeb374e54675d2902befceea8e00a2afc4f9543116ef3027696", + "大鱼调色/Plugin/DYColorManagement.h": "b0a4cd1b8c45dbce90a7b4f30f72ebf95ecd382895e74e3bfeda0f7cdb185157", "大鱼调色/Plugin/DYModel.h": "2a1b3064d2c1179347412ad44981aad384165c2238aac06d936a496976d52e63", - "大鱼调色/Plugin/DYModel.mm": "da9edad3d5681c27db1f2700d7946b965e4ba06ae9297d7c98116361c1c57e10", - "大鱼调色/Plugin/DYUniforms.h": "536a2eed28dd4acf1d77959a1667a7d3c0da3433a510c57aa25de67c0a9be927" + "大鱼调色/Plugin/DYModel.mm": "9478a6ec39a3d61946cd1687db7043df29c9f7185fd04ec7b1c4c57fe52ebc5d", + "大鱼调色/Plugin/DYUniforms.h": "d56fd7de758afaca1478fd0ecbb7347cf9986730d7becc998a6ea6233a98f381" } } diff --git a/template/verification/StaticContract.json b/template/verification/StaticContract.json index 9cf0c74..f462dcb 100644 --- a/template/verification/StaticContract.json +++ b/template/verification/StaticContract.json @@ -1,6 +1,6 @@ { "passed": true, - "sha256": "b2c3c6d9037d14e10eefadfcec9ed9c96100b0be668f0f4077ed3e31fc4dd4d4", + "sha256": "f245f1543b6ae4b8ce9dbdf899ee436b73aec44e3d9f2fbae8a1eb524aac97e5", "version": "5.13", "displayversion": "5.6.7", "filterCount": 1, diff --git a/template/大鱼调色.moef b/template/大鱼调色.moef index 39acf51..552fcc0 100644 --- a/template/大鱼调色.moef +++ b/template/大鱼调色.moef @@ -305,10 +305,10 @@ - - - - + + + + @@ -334,9 +334,9 @@ - - - + + + @@ -364,7 +364,7 @@ - + diff --git a/tools/build_template.py b/tools/build_template.py index 23ca00c..18ec918 100644 --- a/tools/build_template.py +++ b/tools/build_template.py @@ -20,7 +20,7 @@ CONTENT_TAGS={'scenenode','layer','group','filter','behavior','mask'} def sha(data):return hashlib.sha256(data).hexdigest() def model_identity(): - files=['大鱼调色/Plugin/DYModel.h','大鱼调色/Plugin/DYModel.mm','大鱼调色/Plugin/DYUniforms.h','template/tools/dump_model.mm'] + files=['大鱼调色/Plugin/DYModel.h','大鱼调色/Plugin/DYModel.mm','大鱼调色/Plugin/DYUniforms.h','大鱼调色/Plugin/DYColorManagement.h','大鱼调色/Plugin/DYCSTTypes.h','template/tools/dump_model.mm'] return {name:sha((ROOT/name).read_bytes()) for name in files} def refresh_metadata(): @@ -82,7 +82,7 @@ def build(model): E.SubElement(param,'defaultVal').text=text;E.SubElement(param,'dataValue').text=text for row in model['parameters']: value=format(float(row['default']),'.17g') - E.SubElement(filt,'parameter',name=row['title'],id=str(row['pid']),flags='12889161760',default=value,value=value) + E.SubElement(filt,'parameter',name=row['title'],id=str(row['pid']),flags='12889161776' if row.get('notAnimatable') else '12889161760',default=value,value=value) for node in host:filt.append(node) source.append(filt) copyright=E.parse(SOURCES/'CopyrightRig.xml').getroot() diff --git a/tools/verify_gpu.mm b/tools/verify_gpu.mm index e9e2544..abee2fb 100644 --- a/tools/verify_gpu.mm +++ b/tools/verify_gpu.mm @@ -93,7 +93,7 @@ static Pixels render(id pipeline, bool dayu, id #import #import @@ -20,13 +21,19 @@ BOOL _duplicate; } @end +@interface DYInspector (DiagnosticActions) +- (void)refresh; +@end @implementation DYDiagnosticManager - (instancetype)init {if((self=[super init])){_values=[NSMutableDictionary new];_custom=[NSMutableDictionary new];}return self;} - (void)dealloc {[_values release];[_custom release];[super dealloc];} - (id)apiForProtocol:(Protocol *)protocol { NSString *name=NSStringFromProtocol(protocol); - return [@[@"FxParameterCreationAPI_v5",@"FxParameterRetrievalAPI_v6",@"FxParameterSettingAPI_v6"]containsObject:name]?self:nil; + return [@[@"FxParameterCreationAPI_v5",@"FxParameterRetrievalAPI_v6",@"FxParameterSettingAPI_v6",@"FxCustomParameterActionAPI_v4"]containsObject:name]?self:nil; } +- (void)startAction:(id)sender{} +- (void)endAction:(id)sender{} +- (CMTime)currentTime{return kCMTimeZero;} - (BOOL)addFloatSliderWithName:(NSString *)name parameterID:(UInt32)pid defaultValue:(double)value parameterMin:(double)minimum parameterMax:(double)maximum sliderMin:(double)sliderMinimum sliderMax:(double)sliderMaximum delta:(double)delta parameterFlags:(FxParameterFlags)flags { if(_values[@(pid)]||_custom[@(pid)]){_duplicate=YES;return NO;}_values[@(pid)]=@(value);return YES; } @@ -109,6 +116,21 @@ static Pixels render(Run& run,DYRenderer *renderer,DYDiagnosticTile *source,DYDi NSError *error=nil;BOOL ok=[renderer renderSource:source destination:destination uniforms:uniforms paths:paths error:&error]; run.need(name,ok,@{@"error":ok?@"":reason(error)});return read(destination,gpu); } +static Pixels referenceFrame(id gpu,id library,const Pixels &premult,NSUInteger width,NSUInteger height,DayuRenderParams params,NSError **error){ + MTLTextureDescriptor *td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO];td.storageMode=MTLStorageModeShared;td.usage=MTLTextureUsageShaderRead; + idsource=[gpu newTextureWithDescriptor:td];td.pixelFormat=MTLPixelFormatRGBA32Float;td.usage=MTLTextureUsageRenderTarget;iddest=[gpu newTextureWithDescriptor:td]; + Pixels encoded(premult.size());for(NSUInteger i=0;i0?(float)(__fp16)((float)premult[i*4+c]/alpha):0;encoded[i*4+c]=v<=.0031308f?v*12.92f:1.055f*powf(v,1/2.4f)-.055f;}encoded[i*4+3]=alpha;} + [source replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:encoded.data() bytesPerRow:width*8]; + MTLRenderPipelineDescriptor *pd=[MTLRenderPipelineDescriptor new];pd.vertexFunction=[library newFunctionWithName:@"vertexShader"];pd.fragmentFunction=[library newFunctionWithName:@"fragmentShader"];pd.colorAttachments[0].pixelFormat=MTLPixelFormatRGBA32Float; + idpipeline=[gpu newRenderPipelineStateWithDescriptor:pd error:error];[pd.vertexFunction release];[pd.fragmentFunction release];[pd release]; + Pixels result;if(pipeline){idq=[gpu newCommandQueue];idcb=[q commandBuffer];MTLRenderPassDescriptor *rp=[MTLRenderPassDescriptor renderPassDescriptor];rp.colorAttachments[0].texture=dest;rp.colorAttachments[0].loadAction=MTLLoadActionDontCare;rp.colorAttachments[0].storeAction=MTLStoreActionStore;ide=[cb renderCommandEncoderWithDescriptor:rp]; + float w=width,h=height;DYVertex2D vertices[]={{{w/2,-h/2},{1,1}},{{-w/2,-h/2},{0,1}},{{w/2,h/2},{1,0}},{{-w/2,h/2},{0,0}}};vector_uint2 vp={(unsigned)width,(unsigned)height};idhist=[gpu newBufferWithLength:800 options:MTLResourceStorageModeShared]; + [e setRenderPipelineState:pipeline];[e setVertexBytes:vertices length:sizeof(vertices) atIndex:0];[e setVertexBytes:&vp length:sizeof(vp) atIndex:1];[e setFragmentTexture:source atIndex:0];[e setFragmentTexture:source atIndex:1];[e setFragmentBytes:¶ms length:sizeof(params) atIndex:0];[e setFragmentBuffer:hist offset:0 atIndex:1];[e drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];[e endEncoding];[cb commit];[cb waitUntilCompleted]; + if(cb.status==MTLCommandBufferStatusCompleted){std::vectorpixels(width*height*4);[dest getBytes:pixels.data() bytesPerRow:width*16 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0];result.resize(premult.size());for(NSUInteger i=0;i0?(__fp16)((float)(__fp16)linear*a):0;}result[i*4+3]=a;}} + [hist release];[q release]; + } + [pipeline release];[source release];[dest release];return result; +} static float *field(DYUniforms *u,NSDictionary *row){return (float *)((uint8_t *)u+[row[@"offset"]unsignedIntegerValue]);} } @@ -128,8 +150,8 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { for(int c=0;c<3;c++)finite&=std::isfinite(defaults.primariesM0[c])&&std::isfinite(defaults.primariesM1[c])&&std::isfinite(defaults.primariesM2[c]); run.need(@"finite-real-model-defaults",finite&&matches); bool initialGroups=true; - for(NSDictionary *section in sections){BOOL base=[@[@"base",@"color"]containsObject:section[@"key"]];for(NSDictionary *row in descriptors)if([row[@"pid"]isEqual:section[@"enabled"]])initialGroups&=([row[@"default"]doubleValue]>=.5)==base;} - run.record(@"only-basic-adjustments-enabled-by-default",initialGroups); + for(NSDictionary *section in sections){BOOL base=YES;for(NSDictionary *row in descriptors)if([row[@"pid"]isEqual:section[@"enabled"]])initialGroups&=([row[@"default"]doubleValue]>=.5)==base;} + run.record(@"all-module-eyes-enabled-by-default",initialGroups); DYDiagnosticManager *manager=[[[DYDiagnosticManager alloc]init]autorelease];error=nil; run.need(@"native-parameter-creation",DYCreateParameters(manager,&error)&&!manager->_duplicate&&manager->_values.count==descriptors.count&&manager->_custom.count==2,@{@"error":reason(error)}); id setter=[manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];id getter=[manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]; @@ -142,6 +164,30 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { run.record(@"secure-asset-archive-roundtrip",decoded&&[assets isEqual:decoded],@{@"archiveBytes":@(archive.length),@"error":reason(error)}); BOOL wrote=DYWriteAssets(manager,assets,kCMTimeZero);DYAssetState *readBack=DYReadAssets(manager,kCMTimeZero);run.record(@"native-custom-asset-get-set",wrote&&[readBack isEqual:assets]); DYAssetState *copy=[[assets copy]autorelease];copy.paths=@{};run.record(@"asset-copy-is-independent",assets.paths.count==2&©.paths.count==0); + // Exercise the real AppKit actions against a separate, in-memory host. + [NSApplication sharedApplication]; + DYDiagnosticManager *uiHost=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(uiHost,nil); + DYInspector *inspector=[[[DYInspector alloc]initWithAPIManager:uiHost]autorelease];[inspector refresh]; + NSArray *cards=[inspector valueForKey:@"cards"];BOOL initialUI=YES; + for(NSDictionary *card in cards)initialUI&=([card[@"collapsed"]boolValue]!=[@[@"primary",@"base"]containsObject:card[@"section"][@"key"]])&&[(NSButton*)card[@"enabled"]state]==NSControlStateValueOn; + run.record(@"default-primary-base-expanded-all-eyes-on",initialUI,@{@"modules":@(cards.count)}); + DYUniforms uiBefore,uiAfter;DYReadUniforms(uiHost,kCMTimeZero,&uiBefore);BOOL foldingIndependent=YES; + for(NSDictionary *card in cards){NSButton *header=card[@"header"];BOOL was=[card[@"collapsed"]boolValue];[header performClick:nil];[inspector refresh];DYReadUniforms(uiHost,kCMTimeZero,&uiAfter);foldingIndependent&=[card[@"collapsed"]boolValue]!=was&&memcmp(&uiBefore,&uiAfter,sizeof(uiBefore))==0;[header performClick:nil];[inspector refresh];} + run.record(@"all-disclosure-actions-preserve-every-render-parameter",foldingIndependent); + NSDictionary *first=cards[0];BOOL wasFolded=[first[@"collapsed"]boolValue];[(NSButton*)first[@"enabled"]performClick:nil];[inspector refresh];DYReadUniforms(uiHost,kCMTimeZero,&uiAfter); + run.record(@"eye-only-toggles-enable-retains-disclosure",[first[@"collapsed"]boolValue]==wasFolded&&uiAfter.inputSectionEnabled==0); + [(NSButton*)first[@"header"]performClick:nil];[inspector refresh];DYReadUniforms(uiHost,kCMTimeZero,&uiAfter); + run.record(@"expanding-disabled-module-keeps-it-disabled",uiAfter.inputSectionEnabled==0&&![first[@"collapsed"]boolValue]); + DYInspector *reopened=[[[DYInspector alloc]initWithAPIManager:uiHost]autorelease];[reopened refresh];NSArray *reopenedCards=[reopened valueForKey:@"cards"]; + run.record(@"inspector-recreation-restores-independent-disclosure",![reopenedCards[0][@"collapsed"]boolValue]&&[(NSButton*)reopenedCards[0][@"enabled"]state]==NSControlStateValueOff); + DYInspectorToken *uiToken=uiHost->_custom[@(DYInspectorParameterID)];error=nil;NSData *foldArchive=[NSKeyedArchiver archivedDataWithRootObject:uiToken requiringSecureCoding:YES error:&error];DYInspectorToken *foldDecoded=[NSKeyedUnarchiver unarchivedObjectOfClass:DYInspectorToken.class fromData:foldArchive error:&error]; + run.record(@"secure-disclosure-archive-roundtrip",[foldDecoded isEqual:uiToken],@{@"error":reason(error)}); + DYInspectorToken *old=[[[DYInspectorToken alloc]init]autorelease];old.schema=1;uiHost->_custom[@(DYInspectorParameterID)]=old;DYReadUniforms(uiHost,kCMTimeZero,&uiAfter); + run.record(@"legacy-inspector-retains-input-and-blackwhite-behavior",uiAfter.cm.configured==-1&&uiAfter.cm.blackWhiteMix==1); + DayuRenderParams cp=DYCMRender(defaults.cm);run.record(@"working-space-shared-by-primary-and-output",cp.input.outputTransfer==cp.output.inputTransfer&&cp.input.outputGamut==cp.output.inputGamut&&cp.basis.colorspace==10); + DYCMSettings converted=defaults.cm;converted.exposure=1.25;converted.contrast=.4;converted.balanceStrength=.3;converted.midtones=.6;converted.shadows=-.4;converted.black=.2;converted.shadowContrast=.3;converted.hiContrast=-.2;DayuRenderParams mapped=DYCMRender(converted); + run.record(@"basis-raw-controls-use-reference-conversion",fabs(mapped.basis.exposure-exp2f(1.25))<1e-6&&fabs(mapped.basis.contrast-exp2f(.4))<1e-6&&fabs(mapped.basis.balanceStrength-.36)<1e-6&&fabs(mapped.basis.midtones-.1998)<1e-5&&fabs(mapped.basis.shadows+.6)<1e-6&&fabs(mapped.basis.trimLow-.9)<1e-6&&fabs(mapped.basis.shadowContrast+.39)<1e-6&&fabs(mapped.basis.hiContrast+.4)<1e-6); + converted.workingTransfer=30;mapped=DYCMRender(converted);run.record(@"unsupported-basis-curve-adapts-through-intermediate",(mapped.reserved&8)&&mapped.basis.colorspace==10&&mapped.basisInput.inputTransfer==30&&mapped.basisOutput.outputTransfer==30); id gpu=MTLCreateSystemDefaultDevice();run.need(@"metal-device",gpu!=nil);gpuName=gpu.name; const NSUInteger width=64,height=48;DYDiagnosticTile *source=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease],*destination=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease]; run.need(@"real-iosurface-image-tiles",source&&destination&&source.ioSurface&&destination.ioSurface); @@ -149,6 +195,22 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease];Pixels neutral=render(run,renderer,source,destination,gpu,defaults,@{},@"renderer-default-pass");Difference neutralDifference=difference(input,neutral); run.record(@"transparent-premultiplied-neutral",neutralDifference.nonfinite==0&&neutralDifference.maximum<=.001,measure(neutralDifference)); + NSString *cstReference=NSProcessInfo.processInfo.environment[@"DY_DIAGNOSTIC_CST_REFERENCE"]; + if(cstReference.length){ + error=nil;idoracle=[gpu newLibraryWithURL:[NSURL fileURLWithPath:cstReference] error:&error];run.need(@"independent-installed-cst-reference-loaded",oracle!=nil,@{@"path":cstReference,@"error":reason(error)}); + const int cases[][3]={{28,27,10},{2,23,10},{4,4,10},{5,5,10},{6,6,10},{8,7,10},{9,7,10},{11,10,10},{12,28,10},{15,23,10},{16,17,10},{21,23,10},{22,21,10},{25,24,10},{27,25,10},{30,23,10},{29,23,10},{28,27,1},{28,27,20},{28,27,30},{28,27,1002}}; + for(unsigned index=0;index100&&monoDiff.nonfinite==0,measure(monoDiff)); + monochrome.cm.blackWhiteMix=.5;Pixels halfMono=render(run,renderer,source,destination,gpu,monochrome,@{},@"blackwhite-half-render");BOOL smooth=YES;for(NSUInteger i=0;icubeValues; + for(NSString *line in [cubeText componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]){float r,g,b;if(sscanf(line.UTF8String,"%f %f %f",&r,&g,&b)==3){cubeValues.push_back(r);cubeValues.push_back(g);cubeValues.push_back(b);}} + Pixels gray(input.size());float grayLinear=powf((.5f+.055f)/1.055f,2.4f);for(NSUInteger i=0;i.01;} + run.record(@"cube-export-includes-cst-primary-and-matches-production",cstCubeMatches,@{@"error":reason(error),@"triples":@(cubeValues.size()/3)}); + [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; DYUniforms u=defaults;u.exposure=.8f;Pixels exposed=render(run,renderer,source,destination,gpu,u,@{},@"renderer-exposure-pass");Difference exposureDifference=difference(neutral,exposed);run.record(@"exposure-affects-actual-frame",exposureDifference.nonfinite==0&&exposureDifference.different>100,measure(exposureDifference)); u.baseSectionEnabled=0;Pixels bypass=render(run,renderer,source,destination,gpu,u,@{},@"renderer-base-bypass-pass");Difference bypassDifference=difference(neutral,bypass);run.record(@"base-group-bypass",bypassDifference.nonfinite==0&&bypassDifference.maximum==0,measure(bypassDifference)); u=defaults;u.temperature=35;u.tint=-20;Pixels wb=render(run,renderer,source,destination,gpu,u,@{},@"renderer-white-balance-pass");Difference wbDifference=difference(neutral,wb);run.record(@"white-balance-real-table-frame",wbDifference.nonfinite==0&&wbDifference.different>100,measure(wbDifference)); u.colorSectionEnabled=0;bypass=render(run,renderer,source,destination,gpu,u,@{},@"renderer-color-bypass-pass");bypassDifference=difference(neutral,bypass);run.record(@"color-group-bypass",bypassDifference.nonfinite==0&&bypassDifference.maximum==0,measure(bypassDifference)); u=defaults;u.hslSectionEnabled=1;u.hslHueA.x=28;u.hslSatA.y=45;u.hslLumB.z=-18;Pixels hsl=render(run,renderer,source,destination,gpu,u,@{},@"renderer-hsl-pass");Difference hslDifference=difference(neutral,hsl);run.record(@"hsl-real-table-frame",hslDifference.nonfinite==0&&hslDifference.different>100,measure(hslDifference)); - checkFoldedGroup(u,offsetof(DYUniforms,hslSectionEnabled),@{},@"folded-hsl-bypasses-retained-adjustments"); + checkFoldedGroup(u,offsetof(DYUniforms,hslSectionEnabled),@{},@"disabled-hsl-bypasses-retained-adjustments"); u=defaults;u.colorGradingSectionEnabled=1;u.colorGradingHueSatA.x=210;u.colorGradingHueSatA.y=42;u.colorGradingLuma.x=18;Pixels grading=render(run,renderer,source,destination,gpu,u,@{},@"renderer-grading-pass");Difference gradingDifference=difference(neutral,grading);run.record(@"grading-real-table-frame",gradingDifference.nonfinite==0&&gradingDifference.different>100,measure(gradingDifference)); - checkFoldedGroup(u,offsetof(DYUniforms,colorGradingSectionEnabled),@{},@"folded-grading-bypasses-retained-adjustments"); + checkFoldedGroup(u,offsetof(DYUniforms,colorGradingSectionEnabled),@{},@"disabled-grading-bypasses-retained-adjustments"); for(int profile=1;profile<=17;profile++){@autoreleasepool{u=defaults;u.inputSectionEnabled=1;u.inputProfile=profile;Pixels transformed=render(run,renderer,source,destination,gpu,u,@{},[NSString stringWithFormat:@"input-profile-%02d-load-render",profile]);Difference delta=difference(neutral,transformed);run.record([NSString stringWithFormat:@"input-profile-%02d-finite-nonzero",profile],delta.nonfinite==0&&delta.nonzero>100,measure(delta));}} - checkFoldedGroup(u,offsetof(DYUniforms,inputSectionEnabled),@{},@"folded-input-bypasses-retained-profile"); + checkFoldedGroup(u,offsetof(DYUniforms,inputSectionEnabled),@{},@"disabled-input-bypasses-retained-profile"); DYRenderer *analysisRenderer=[[[DYRenderer alloc]init]autorelease];u=defaults;u.inputSectionEnabled=1;u.inputProfile=1;render(run,analysisRenderer,source,destination,gpu,u,@{},@"renderer-input-analysis-pass"); NSData *inputPreview=[analysisRenderer preview];bool analysisDifferent=inputPreview.length==preview.length&&preview.length==320*180*16;double analysisMaximum=0;size_t analysisChanges=0; if(analysisDifferent){const float *a=(const float *)preview.bytes,*b=(const float *)inputPreview.bytes;for(NSUInteger i=0;i1e-5)analysisChanges++;}}} @@ -205,7 +276,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { 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)}); 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,@"folded-look-bypasses-retained-LUTs"); + 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}); NSString *exported=[NSString stringWithContentsOfURL:exportURL encoding:NSUTF8StringEncoding error:&error];NSUInteger triples=0,nonzero=0;bool exportFinite=true;for(NSString *line in [exported componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]){float r,g,b;if(sscanf(line.UTF8String,"%f %f %f",&r,&g,&b)==3){triples++;exportFinite&=std::isfinite(r)&&std::isfinite(g)&&std::isfinite(b);if(r!=0||g!=0||b!=0)nonzero++;}} run.record(@"export-33cube-data-contract",[exported containsString:@"LUT_3D_SIZE 33"]&&triples==33*33*33&&exportFinite&&nonzero>0,@{@"rows":@(triples),@"nonzeroRows":@(nonzero),@"bytes":@([[[NSFileManager defaultManager]attributesOfItemAtPath:exportURL.path error:nil][NSFileSize]unsignedLongLongValue])}); diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index a98e4bd..a84bb4f 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -714,7 +714,7 @@ static NSImage *DYWheelImage(void) { DYAssetState *assets=DYReadAssets(_manager,t); double profile=0,configured=0;[get getFloatValue:&profile fromParameter:2013 atTime:t];[get getFloatValue:&configured fromParameter:2236 atTime:t]; DYInspectorToken *oldToken=nil;[get getCustomParameterValue:&oldToken fromParameter:DYInspectorParameterID atTime:t]; - _tabs[@"legacyInput"]=@(configured<.5&&(profile>.5||[assets.paths[@"input"]length]||oldToken.schema<2)); + _tabs[@"legacyInput"]=@(configured<.5&&(configured<0||profile>.5||[assets.paths[@"input"]length]||oldToken.schema<2)); for(NSString *key in _assetButtons) { NSString *path=assets.paths[key]; NSButton *button=_assetButtons[key][@"choose"]; NSString *name=path.length?path.lastPathComponent.stringByDeletingPathExtension:@"无"; @@ -749,7 +749,12 @@ static NSImage *DYWheelImage(void) { v=fmax([d[@"min"] doubleValue],fmin([d[@"max"] doubleValue],v)); id action=[self actionAPI];if(!action)return; [action startAction:self]; - @try { id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; [set setFloatValue:v toParameter:pid.unsignedIntValue atTime:action.currentTime];if([d[@"key"]hasPrefix:@"cm"])[set setFloatValue:1 toParameter:2236 atTime:action.currentTime]; } + @try { id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; [set setFloatValue:v toParameter:pid.unsignedIntValue atTime:action.currentTime];if([d[@"key"]hasPrefix:@"cm"]||[d[@"key"]isEqual:@"blackWhiteMix"]){ + idget=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];DYInspectorToken *old=nil;[get getCustomParameterValue:&old fromParameter:DYInspectorParameterID atTime:action.currentTime]; + if([d[@"key"]hasPrefix:@"cm"])[set setFloatValue:1 toParameter:2236 atTime:action.currentTime]; + else if(old.schema<2){double cfg=0;[get getFloatValue:&cfg fromParameter:2236 atTime:action.currentTime];if(cfg<.5)[set setFloatValue:-1 toParameter:2236 atTime:action.currentTime];} + if(old.schema<2){DYInspectorToken *token=[[old copy]autorelease];token.schema=2;[set setCustomParameterValue:token toParameter:DYInspectorParameterID atTime:action.currentTime];} + } } @finally { [action endAction:self]; } [self postChanged]; } @@ -757,7 +762,7 @@ static NSImage *DYWheelImage(void) { NSDictionary *r=_controls[@(sender.tag)],*d=r[@"descriptor"];if(!d)return; id action=[self actionAPI];if(!action)return; [action startAction:self]; - @try {id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];[set setFloatValue:[d[@"default"] doubleValue] toParameter:(UInt32)sender.tag atTime:action.currentTime];} + @try {id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];[set setFloatValue:[d[@"default"] doubleValue] toParameter:(UInt32)sender.tag atTime:action.currentTime];if([d[@"key"]hasPrefix:@"cm"])[set setFloatValue:1 toParameter:2236 atTime:action.currentTime];} @finally {[action endAction:self];} [self postChanged]; } @@ -789,6 +794,7 @@ static NSImage *DYWheelImage(void) { id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; [set setFloatValue:enabled?1:0 toParameter:pid.unsignedIntValue atTime:action.currentTime]; NSNumber *extra=section[@"extraEnabled"];if(extra)[set setFloatValue:enabled?1:0 toParameter:extra.unsignedIntValue atTime:action.currentTime]; + } @finally {[action endAction:self];} [self postChanged]; @@ -821,6 +827,9 @@ static NSImage *DYWheelImage(void) { for(NSDictionary *d in section[@"rows"]) {[set setFloatValue:[d[@"default"] doubleValue] toParameter:[d[@"pid"] unsignedIntValue] atTime:t];if(d[@"enabled"])[set setFloatValue:1 toParameter:[d[@"enabled"] unsignedIntValue] atTime:t];} double defaultEnabled=[section[@"defaultEnabled"]doubleValue]; NSNumber *enabled=section[@"enabled"];if(enabled)[set setFloatValue:defaultEnabled toParameter:enabled.unsignedIntValue atTime:t]; + if([@[@"input",@"primary",@"output"]containsObject:section[@"key"]])[set setFloatValue:1 toParameter:2236 atTime:t]; + if([section[@"key"]isEqual:@"blackwhite"]){DYInspectorToken *old=nil;[[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getCustomParameterValue:&old fromParameter:DYInspectorParameterID atTime:t];if(old.schema<2){DYInspectorToken *current=[[old copy]autorelease];current.schema=2;[set setCustomParameterValue:current toParameter:DYInspectorParameterID atTime:t];[set setFloatValue:-1 toParameter:2236 atTime:t];}} + NSNumber *extra=section[@"extraEnabled"];if(extra)[set setFloatValue:defaultEnabled toParameter:extra.unsignedIntValue atTime:t]; NSString *key=section[@"key"]?:@""; if([key localizedCaseInsensitiveContainsString:@"input"]||[key localizedCaseInsensitiveContainsString:@"look"]) { @@ -954,9 +963,10 @@ static NSImage *DYWheelImage(void) { @try { CMTime t=action.currentTime;id get=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]; for(NSDictionary *d in DYDescriptors()) {double v=[d[@"default"] doubleValue];[get getFloatValue:&v fromParameter:[d[@"pid"] unsignedIntValue] atTime:t];if(std::isfinite(v))values[d[@"key"]]=@(v);} + DYUniforms effective;DYReadUniforms(_manager,t,&effective);values[@"cmConfigured"]=@(effective.cm.configured);values[@"blackWhiteMix"]=@(effective.cm.blackWhiteMix); paths=[[DYReadAssets(_manager,t).paths copy] autorelease]?:@{}; } @finally {[action endAction:self];} - return @{@"format":@"com.dayu.color.preset",@"version":@1,@"values":values,@"paths":paths}; + return @{@"format":@"com.dayu.color.preset",@"version":@2,@"values":values,@"paths":paths}; } - (void)savePreset:(id)sender { NSDictionary *snapshot=[self presetSnapshot];if(!snapshot)return; @@ -971,11 +981,11 @@ static NSImage *DYWheelImage(void) { NSError *error=nil;NSData *data=[NSData dataWithContentsOfURL:panel.URL options:0 error:&error]; if(!data||data.length>2*1024*1024){[self showError:error.localizedDescription?:@"预设文件过大"];return;} id json=[NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; - if(![json isKindOfClass:NSDictionary.class]||![json[@"format"] isEqual:@"com.dayu.color.preset"]||![json[@"version"] isEqual:@1]||![json[@"values"] isKindOfClass:NSDictionary.class]||![json[@"paths"] isKindOfClass:NSDictionary.class]){[self showError:@"这不是有效的大鱼调色预设。"];return;} + if(![json isKindOfClass:NSDictionary.class]||![json[@"format"] isEqual:@"com.dayu.color.preset"]||![@[@1,@2]containsObject:json[@"version"]]||![json[@"values"] isKindOfClass:NSDictionary.class]||![json[@"paths"] isKindOfClass:NSDictionary.class]){[self showError:@"这不是有效的大鱼调色预设。"];return;} NSDictionary *values=json[@"values"],*paths=json[@"paths"]; for(NSDictionary *d in DYDescriptors()) { id v=values[d[@"key"]];if(!v)continue; - if(![v isKindOfClass:NSNumber.class]||!std::isfinite([v doubleValue])||[v doubleValue]<[d[@"min"] doubleValue]||[v doubleValue]>[d[@"max"] doubleValue]){[self showError:@"预设包含无效参数,尚未修改当前调色。"];return;} + if(![v isKindOfClass:NSNumber.class]||!std::isfinite([v doubleValue])||[v doubleValue]<[d[@"min"] doubleValue]||[v doubleValue]>[d[@"max"] doubleValue]||(d[@"values"]&&![d[@"values"]containsObject:v])){[self showError:@"预设包含无效参数,尚未修改当前调色。"];return;} } NSMutableDictionary *validPaths=[NSMutableDictionary dictionary];NSMutableArray *missing=[NSMutableArray array]; for(NSString *key in @[@"input",@"look0",@"look1",@"look2",@"look3",@"look4"]) { @@ -989,6 +999,7 @@ static NSImage *DYWheelImage(void) { @try { CMTime t=action.currentTime;id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; for(NSDictionary *d in DYDescriptors())if(values[d[@"key"]])[set setFloatValue:[values[d[@"key"]] doubleValue] toParameter:[d[@"pid"] unsignedIntValue] atTime:t]; + if([json[@"version"]isEqual:@1]&&!values[@"cmConfigured"]){[set setFloatValue:-1 toParameter:2236 atTime:t];[set setFloatValue:1 toParameter:2270 atTime:t];} DYAssetState *assets=[[[DYAssetState alloc] init] autorelease];assets.paths=validPaths;DYWriteAssets(_manager,assets,t); } @finally {[action endAction:self];} [self postChanged]; diff --git a/大鱼调色/Plugin/DYModel.mm b/大鱼调色/Plugin/DYModel.mm index 2f28afd..50fa644 100644 --- a/大鱼调色/Plugin/DYModel.mm +++ b/大鱼调色/Plugin/DYModel.mm @@ -84,7 +84,7 @@ NSArray *DYCMGamuts(void) { return @[ static NSDictionary *cmRow(NSString*k,NSString*t,NSUInteger o,double lo,double hi,double def,int tab,NSArray *choices=nil){ NSMutableDictionary *d=[[row(k,t,offsetof(DYUniforms,cm)+o,lo,hi,def,choices?@"popup":@"float")mutableCopy]autorelease];d[@"cmTab"]=@(tab); - if(choices){d[@"options"]=[choices valueForKey:@"name"];d[@"values"]=[choices valueForKey:@"id"];} + if(choices){d[@"notAnimatable"]=@YES;d[@"options"]=[choices valueForKey:@"name"];d[@"values"]=[choices valueForKey:@"id"];} [descriptors replaceObjectAtIndex:descriptors.count-1 withObject:d];return d; } static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{ @@ -93,7 +93,7 @@ static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{ [descriptors replaceObjectAtIndex:0 withObject:profile]; // Legacy IDs remain registered for existing FCP documents and presets. scalar(@"preLUTStrength",@"旧版输入强度",56,0,1,1); - row(@"cmConfigured",@"CST 配置版本",offsetof(DYUniforms,cm)+offsetof(DYCMSettings,configured),0,1,0,@"bool"); + row(@"cmConfigured",@"CST 配置版本",offsetof(DYUniforms,cm)+offsetof(DYCMSettings,configured),-1,1,0,@"bool"); NSArray *transfers=[DYCMSceneSpaces() arrayByAddingObjectsFromArray:DYCMDisplaySpaces()]; NSMutableArray *cm=[NSMutableArray array]; #define CM(f,t,lo,hi,def,tab) [cm addObject:cmRow(@"cm" #f,t,offsetof(DYCMSettings,f),lo,hi,def,tab)] @@ -108,7 +108,7 @@ static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{ CM(white,@"白点",.5,1.5,1,1);CM(shoulder,@"肩部压缩",0,1,.5,1);CM(highlights,@"一级高光",-1,1,0,1);CM(midtones,@"一级中间调",-1,1,0,1);CM(shadows,@"一级阴影",-1,1,0,1);CM(black,@"黑点",-1,1,0,1);CM(toe,@"趾部压缩",0,1,.5,1);CM(chromaMix,@"色度混合",0,1,.5,1); CM(bypassExposure,@"旁路一级曝光",0,1,0,1);CM(bypassBalance,@"旁路一级色彩",0,1,0,1);CM(bypassContrast,@"旁路一级对比",0,1,0,1);CM(bypassTone,@"旁路一级影调",0,1,0,1); CM(outputEnabled,@"输出转换启用",0,1,1,2);CH(outputTransfer,@"输出曲线",1002,2,transfers);CH(outputGamut,@"输出色域",22,2,DYCMGamuts()); - [cm addObject:cmRow(@"cmtoneMapping",@"输出色调映射",offsetof(DYCMSettings,toneMapping),0,1,0,2,@[@{@"id":@0,@"name":@"关闭"},@{@"id":@1,@"name":@"开启"}])]; + [cm addObject:cmRow(@"cmtoneMapping",@"自动色调映射",offsetof(DYCMSettings,toneMapping),0,1,0,2,@[@{@"id":@0,@"name":@"关闭"},@{@"id":@1,@"name":@"开启"}])]; #undef CM #undef CH NSMutableArray *input=[NSMutableArray array],*primary=[NSMutableArray array],*output=[NSMutableArray array]; @@ -154,7 +154,7 @@ static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{ });} NSArray *DYSections(void){initialize();return sections;} NSArray *DYDescriptors(void){initialize();return descriptors;} void DYDefaultUniforms(DYUniforms*u){memset(u,0,sizeof(*u));for(NSDictionary*r in DYDescriptors())if([r[@"offset"]integerValue]>=0)*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=[r[@"default"]floatValue];u->primariesM0=(DYFloat3){1,0,0};u->primariesM1=(DYFloat3){0,1,0};u->primariesM2=(DYFloat3){0,0,1};} -void DYReadUniforms(idm,CMTime t,DYUniforms*u){DYDefaultUniforms(u);idg=[m apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];for(NSDictionary*r in DYDescriptors()){if([r[@"offset"]integerValue]<0)continue;double v=[r[@"default"]doubleValue];if([g getFloatValue:&v fromParameter:[r[@"pid"]unsignedIntValue] atTime:t]&&std::isfinite(v))*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=fmin([r[@"max"]doubleValue],fmax([r[@"min"]doubleValue],v));}NSObject *token=nil;[g getCustomParameterValue:&token fromParameter:DYInspectorParameterID atTime:t]; +void DYReadUniforms(idm,CMTime t,DYUniforms*u){DYDefaultUniforms(u);idg=[m apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];for(NSDictionary*r in DYDescriptors()){if([r[@"offset"]integerValue]<0)continue;double v=[r[@"default"]doubleValue];if([g getFloatValue:&v fromParameter:[r[@"pid"]unsignedIntValue] atTime:t]&&std::isfinite(v)){if(r[@"values"]&&![r[@"values"]containsObject:@((int)llround(v))])v=[r[@"default"]doubleValue];*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=fmin([r[@"max"]doubleValue],fmax([r[@"min"]doubleValue],v));}}NSObject *token=nil;[g getCustomParameterValue:&token fromParameter:DYInspectorParameterID atTime:t]; if([token isKindOfClass:DYInspectorToken.class]&&[(DYInspectorToken*)token schema]<2){if(u->cm.configured<.5)u->cm.configured=-1;u->cm.blackWhiteMix=1;} } BOOL DYCreateParameters(idm,NSError**error){ida=[m apiForProtocol:@protocol(FxParameterCreationAPI_v5)];BOOL ok=a!=nil; @@ -178,7 +178,7 @@ BOOL DYCreateParameters(idm,NSError**error){id @@ -22,6 +23,28 @@ static id texture3D(idd,const float*values,NSUInteger n){ - (FxImageOrigin)imageOrigin{return kFxImageOrigin_TOP_LEFT;} @end static BOOL managed(DYUniforms u,NSDictionary *paths){return u.cm.configured>=0&&(u.cm.configured>.5||(![paths[@"input"]length]&&u.inputProfile<.5));} +static BOOL identityCM(DYUniforms u){ + DYCMSettings s=u.cm; + BOOL neutral=s.basisEnabled<.5||(s.exposure==0&&s.balanceStrength==0&&s.saturation==1&&s.contrast==0&&s.hiContrast==0&&s.shadowContrast==0&&s.white==1&&s.highlights==0&&s.midtones==0&&s.shadows==0&&s.black==0&&s.toe==.5f&&s.shoulder==.5f&&s.chromaMix==.5f); + BOOL transforms=(u.inputSectionEnabled>.5)==(s.outputEnabled>.5)&&((u.inputSectionEnabled<.5)||(s.inputTransfer==s.outputTransfer&&s.inputGamut==s.outputGamut&&s.toneMapping<.5)); + return neutral&&transforms; +} +// An enabled but untouched display tool is mathematically neutral. Bypass its +// finite-domain lookup so that the default "all eyes on" does not clip CST HDR. +static void bypassNeutralTools(DYUniforms *u){ + for(NSDictionary *section in DYSections()){ + if(![@[@"curve",@"hsl",@"grading",@"primaries",@"levels",@"balance"]containsObject:section[@"key"]])continue; + BOOL neutral=YES;for(NSDictionary *row in section[@"rows"]){NSInteger offset=[row[@"offset"]integerValue];if(offset<0)continue;if(*(float*)((uint8_t*)u+offset)!=[row[@"default"]floatValue]){neutral=NO;break;}} + if(neutral)for(NSDictionary *row in DYDescriptors())if([row[@"pid"]isEqual:section[@"enabled"]])*(float*)((uint8_t*)u+[row[@"offset"]unsignedIntegerValue])=0; + } +} +static void bypassIdleSkin(DYUniforms *u){ + if(u->curveSectionEnabled>.5||u->hslSectionEnabled>.5||u->colorGradingSectionEnabled>.5||u->primariesSectionEnabled>.5||u->levelsSectionEnabled>.5||u->blackWhiteSectionEnabled>.5||u->colorBalanceSectionEnabled>.5)return; + if(u->preLUTStrength!=0||u->postLUTStrength!=0||simd_any(u->extraPostLUTStrengths!=0))return; + const float *values=&u->exposure,*enabled=&u->exposureEnabled; + for(int i=0;i<13;i++){BOOL group=(i>=6&&i<=9)?u->colorSectionEnabled>.5:u->baseSectionEnabled>.5;if(group&&enabled[i]>.5&&values[i]!=0)return;} + u->skinProtection.x=0; +} @interface DYRenderer(){ NSMutableDictionary *_devices,*_luts,*_preparedLUTs; NSSet *_activeLUTPaths; @@ -99,12 +122,12 @@ static BOOL managed(DYUniforms u,NSDictionary *paths){return u.cm.configured>=0& - (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?:@[]]; 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,@"宿主图像纹理不可用"); - BOOL useCM=managed(u,paths);float bwMix=fmaxf(0,fminf(1,u.cm.blackWhiteMix));if(bwMix<=0)u.blackWhiteSectionEnabled=0; - NSArray*ts=[self textures:paths uniforms:&u entry:e error:err];if(!ts)return NO; + BOOL useCM=managed(u,paths);bypassNeutralTools(&u);float bwMix=fmaxf(0,fminf(1,u.cm.blackWhiteMix));if(bwMix<=0)u.blackWhiteSectionEnabled=0; + NSArray*ts=[self textures:paths uniforms:&u entry:e error:err];if(!ts)return NO;bypassIdleSkin(&u); 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];} MTLTextureDescriptor*td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:input.width height:input.height mipmapped:NO];td.storageMode=MTLStorageModePrivate;td.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;idstraight=[d newTextureWithDescriptor:td];if(!straight)return fail(err,@"无法分配调色缓冲区"); idcb=[e[@"queue"]commandBuffer];idce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyUnpremultiply"]];[ce setTexture:input atIndex:0];[ce setTexture:straight atIndex:1];[ce dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding]; - if(useCM&&u.cm.mix>0){ + if(useCM&&!identityCM(u)&&u.cm.mix>0){ DayuRenderParams cm=DYCMRender(u.cm);cm.stages=(cm.stages&~1)|(u.inputSectionEnabled>.5?1:0); if(cm.stages){idconverted=[d newTextureWithDescriptor:td];if(!converted){[straight release];return fail(err,@"无法分配 CST 缓冲区");} ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyColorManagement"]];[ce setTexture:straight atIndex:0];[ce setTexture:converted atIndex:1];[ce setBytes:&cm length:sizeof(cm) atIndex:0];[ce setBytes:&u.cm.mix length:4 atIndex:1];[ce dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];[straight release];straight=converted;