diff --git a/research/CanvasTools-20261105.md b/research/CanvasTools-20261105.md index 7b6a24e..e6022c4 100644 --- a/research/CanvasTools-20261105.md +++ b/research/CanvasTools-20261105.md @@ -26,3 +26,13 @@ FCP-BeautyGirl 参考提交 `42fecaa3b55471fea928339127d53484663d4057`,MIT 许 mFilmLook 3.1.4 arm64 SHA-256 `b1cee1dffd3b490afa0c22db646404b018a0aaadf70d9a6827e95cb178c74357`。REA Ghidra 12.1.4 观察到 Lens Distortion、ParamLensDistortionEnable/Strength、RenderDistortionKernel,证据 `ev_77ca21689086d3b977243f1b81b3833a89b9e48aa5cd3e38594572abad5296a2`、`ev_5c4653c5bdd4316ec067c530085235c5c37733b2490065ed6d5ea855611057a7`。本项目独立编写反向径向采样,不宣称已证明目标GPU逐像素等价。 Uniform 仅在原1312字节之后追加32字节,旧参数ID与完整前缀不变;新增独立镜头模块、肤色范围预览及默认人脸限定。当前编译/验证中,未安装。 + +## 第二阶段验证 + +原生回归已扩展至719项,新增真实 OSC 图形手势、UUID网格资产、外部拓扑冲突、畸变GPU与独立CPU采样对照、NASA公共领域真人及同色背景检查。原695项按新15工具和四卡折叠布局更新展示预期,旧点颜色/Cube参照显式排除新空间人脸选区。 + +AddressSanitizer 发现旧 renderLegacy 的 C++ 引用捕获向异步通知泄漏栈 self 地址;改为独立 Objective-C 通知方法后完整内存检查运行结束,无该内存错误。先前未检测到问题的旧正式版695项仍通过,原栈布局偶然掩盖缺陷。 + +肤色预览改为在原生皮肤阶段读取同一个色选算法、同一预HSL参考、同一用户蒙版与人脸覆盖,白色代表保护权重。初次真人测试识别人脸但MTLTexture→CIImage上下相反,已按TOP_LEFT归一化修正,正在重跑;未通过前不交付。 + +曲线直方图由成功渲染的分析更新发布到同时间快照,播放头不匹配时不展示旧帧。人脸只缓存完全相同的标准化像素;无脸或输入失败时为空,不延续上一镜头。新增空间处理的Cube导出会明确拒绝,完整预设继续保存。 diff --git a/tools/build_masked_kernel.py b/tools/build_masked_kernel.py index ed6244c..cb92c84 100644 --- a/tools/build_masked_kernel.py +++ b/tools/build_masked_kernel.py @@ -8,7 +8,7 @@ import re def masked_kernel(source): original = re.search(r'define <4 x half> @dy_grade\(.*?\n\}', source, re.S).group() body = original.replace('@dy_grade(', '@dy_gradeMasked(', 1) - args = ', '.join(f'float %dyWeight{i}' for i in range(12)) + args = ', '.join(f'float %dyWeight{i}' for i in range(12)) + ', float %dySkinVisualize' body = body.replace(') local_unnamed_addr #0 {', ', '+args+') local_unnamed_addr #0 {', 1) # Each stage mixes against its actual input. Split basic adjustment has # two native locations; both use the same per-module coverage. @@ -58,6 +58,26 @@ def masked_kernel(source): ' %dyIncludesFinalLast = icmp uge i32 %dyStageLast, 11', ' %dyIncludesFinal = and i1 %dyIncludesFinalFirst, %dyIncludesFinalLast', ' %v672 = select i1 %dyIncludesFinal, <3 x float> %dyClamped672, <3 x float> %v669']), 1) + def preview(code, reference, ranged=False): + regular=next(line for line in code.splitlines() if line.startswith(' %v669 = tail call')) + extra=[regular.replace('%v669 = ', '%dySkinNormal = ', 1), + ' %dySkinSelection = call float @dy_skinWeight(<3 x float> %v668, <3 x float> '+reference+', %struct.DYUniforms addrspace(2)* %v12)', + ' %dySkinPointer = getelementptr inbounds %struct.DYUniforms, %struct.DYUniforms addrspace(2)* %v12, i64 0, i32 65', + ' %dySkinVector = load <3 x float>, <3 x float> addrspace(2)* %dySkinPointer, align 16', + ' %dySkinStrength = extractelement <3 x float> %dySkinVector, i64 1', + ' %dySkinRatio = fmul float %dySkinStrength, 0x3F847AE140000000', + ' %dySkinSelected = fmul float %dySkinSelection, %dyWeight3', + ' %dySkinAmount = fmul float %dySkinSelected, %dySkinRatio', + ' %dySkinGray0 = insertelement <3 x float> undef, float %dySkinAmount, i64 0', + ' %dySkinGray = shufflevector <3 x float> %dySkinGray0, <3 x float> undef, <3 x i32> zeroinitializer', + ' %dySkinShow = fcmp ogt float %dySkinVisualize, 5.000000e-01'] + condition='%dySkinShow' + if ranged: + extra+=[' %dySkinShowActive = and i1 %dySkinShow, %dyStageActive669'];condition='%dySkinShowActive' + extra+=[' %v669 = select i1 '+condition+', <3 x float> %dySkinGray, <3 x float> %dySkinNormal'] + return code.replace(regular, '\n'.join(extra), 1) + body=preview(body,'%v411') + segment=preview(segment,'%dySkinReference',True) skin=''' define <3 x float> @dy_skinExtra(<3 x float> %color, <3 x float> %reference, %struct.DYUniforms addrspace(2)* %uniforms) { entry: diff --git a/tools/fixtures/README.md b/tools/fixtures/README.md new file mode 100644 index 0000000..7aaccf6 --- /dev/null +++ b/tools/fixtures/README.md @@ -0,0 +1,9 @@ +# Person mask regression fixture + +`astronaut.png` is the 512×512 NASA photograph of Eileen Collins distributed by scikit-image v0.25.2. It is used solely as a local segmentation test fixture, not as a product asset or endorsement. It is not copied into the APP. + +- Source: https://raw.githubusercontent.com/scikit-image/scikit-image/v0.25.2/skimage/data/astronaut.png +- Attribution and rights: https://scikit-image.org/docs/0.25.x/api/skimage.data.html#skimage.data.astronaut (NASA Great Images database; released into the public domain, no known copyright restrictions). +- SHA-256: `88431cd9653ccd539741b555fb0a46b61558b301d4110412b5bc28b5e3ea6cb5` + +The tests derive a two-person composition, a shifted image, and an occluded image in memory. They check basic foreground/background separation and request independence; they do not establish broad segmentation accuracy or equivalence to Color Finale. diff --git a/tools/fixtures/astronaut.png b/tools/fixtures/astronaut.png new file mode 100644 index 0000000..834cda0 Binary files /dev/null and b/tools/fixtures/astronaut.png differ diff --git a/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h new file mode 100644 index 0000000..877ee85 --- /dev/null +++ b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h @@ -0,0 +1,56 @@ +// Exercise actual OSC hit geometry, host writes and production Metal output. +{ + DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,nil); + DYToolCanvasProbe *host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero; + idbridge=(id)[[NSClassFromString(@"DYViewerParameterBridge")alloc]initWithAPIManager:host]; + idpanel=(id)[NSClassFromString(@"DYViewerParameterPanel")new];panel.bridge=bridge; + auto drain=[](){double until=NSProcessInfo.processInfo.systemUptime+.06;while(NSProcessInfo.processInfo.systemUptime_time,&u);[bridge publishUniforms:&u document:DYReadTools(host,host->_time).document atTime:host->_time];[bridge publishAssets:DYReadAssets(host,host->_time)histogram:nil atTime:host->_time];[panel prepareWithSize:NSMakeSize(1280,720)scale:1 atTime:host->_time];}; + auto area=[&](NSString *kind)->NSDictionary*{for(NSDictionary*a in [(id)panel valueForKey:@"areas"])if([a[@"kind"]isEqual:kind])return [[a copy]autorelease];return nil;}; + auto drag=[&](NSPoint a,NSPoint b){[panel event:NSEventTypeLeftMouseDown point:a atTime:host->_time];[panel event:NSEventTypeLeftMouseDragged point:b atTime:host->_time];drain();[panel event:NSEventTypeLeftMouseUp point:b atTime:host->_time];drain();publish();}; + [(id)panel setValue:@"hsl" forKey:@"toolType"];publish();NSRect plot=[area(@"hslPlot")[@"rect"]rectValue];int undo=base->_undoStarts; + NSPoint a=NSMakePoint(NSMinX(plot)+plot.size.width*2.5/8,NSMidY(plot)),b=NSMakePoint(a.x,NSMinY(plot)-40);drag(a,b); + DYUniforms edited;DYReadUniforms(host,kCMTimeZero,&edited);run.record(@"canvas-hsl-plot-captures-outside-and-commits-one-undo",edited.hslHueA[2]==100&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1); + NSMutableDictionary *doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);NSString *layerID=DYInsertTool(doc,@"hsl",@"base:hsl")[@"id"];DYWriteTools(host,doc,kCMTimeZero);publish();[(id)panel setValue:layerID forKey:@"nodeID"];publish();plot=[area(@"hslPlot")[@"rect"]rectValue];a=NSMakePoint(NSMinX(plot)+plot.size.width*2.5/8,NSMidY(plot));b=NSMakePoint(a.x,NSMidY(plot)-plot.size.height*.25);drag(a,b);DYReadUniforms(host,kCMTimeZero,&edited); + run.record(@"canvas-hsl-independent-uuid-does-not-edit-base",edited.hslHueA[2]==100&&fabs([DYToolWithID(DYReadTools(host,kCMTimeZero).document,layerID)[@"values"][@"hsl0_2"]doubleValue]-50)<1e-5); + [(id)panel setValue:@"spider" forKey:@"toolType"];publish();plot=[area(@"spiderPlot")[@"rect"]rectValue];auto mesh=dy::neutralMesh();int selected=dy::meshIndex(mesh,0,2);a=NSMakePoint(plot.origin.x+mesh.x[selected]*plot.size.width,plot.origin.y+mesh.y[selected]*plot.size.height);b=NSMakePoint(a.x+9,a.y-6);undo=base->_undoStarts;drag(a,b); + NSData *saved=DYReadAssets(host,kCMTimeZero).spiderMesh;auto changed=DYSpiderMesh(saved);run.record(@"canvas-spider-drags-real-mesh-and-closes-one-undo",saved.length&&fabs(changed.x[selected]-mesh.x[selected])>.001&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1); + doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);NSString *spiderID=DYInsertTool(doc,@"spider",@"base:spider")[@"id"];DYWriteTools(host,doc,kCMTimeZero);publish();[(id)panel setValue:spiderID forKey:@"nodeID"];publish();plot=[area(@"spiderPlot")[@"rect"]rectValue];a=NSMakePoint(plot.origin.x+mesh.x[selected]*plot.size.width,plot.origin.y+mesh.y[selected]*plot.size.height);b=NSMakePoint(a.x-8,a.y+5);drag(a,b); + run.record(@"canvas-spider-uuid-persists-mesh-without-touching-base",[saved isEqual:DYReadAssets(host,kCMTimeZero).spiderMesh]&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"]length]>0); + NSData *current=DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"];[bridge beginSpider:current node:spiderID enabled:1 atTime:kCMTimeZero];drain();doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);auto external=dy::neutralMesh(12,12);NSData *externalData=[NSData dataWithBytes:&external length:sizeof(external)];((NSMutableDictionary*)DYToolWithID(doc,spiderID))[@"spider"]=externalData;DYWriteTools(host,doc,kCMTimeZero);[bridge changeSpider:current];[bridge endGesture];drain(); + run.record(@"canvas-spider-external-topology-change-wins",[DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"]isEqual:externalData]); + DYHistogram hist{};hist.samples=1;hist.bins[1][100]=1;NSData *histData=[NSData dataWithBytes:&hist length:sizeof(hist)];[bridge publishHistogram:histData atTime:kCMTimeZero];run.record(@"canvas-histogram-is-frozen-to-matching-frame",[[bridge snapshotAtTime:kCMTimeZero][@"histogram"]isEqual:histData]&&![bridge snapshotAtTime:CMTimeMake(1,24)]); + [panel finishCapture];panel.bridge=nil;[bridge invalidate];drain();[(id)panel release];[(id)bridge release]; +} +{ + const NSUInteger w=64,h=48;DYDiagnosticTile *src=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease],*dst=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels grid(w*h*4); + for(NSUInteger y=0;yidentity[sample]&&negative[sample].01); + BOOL finite=YES,alpha=YES;for(NSUInteger i=0;i=0&&positive[i*4+3]<=1;} + run.record(@"lens-keeps-finite-premultiplied-border-alpha",finite&&alpha&&positive[3]<1); + double worst=0;for(NSUInteger y=4;y=1,@{@"faces":@(faces),@"centerX":@(faceX),@"centerY":@(faceY)});u.skinProtection.x=0;Pixels unprotected=render(run,face,src,dst,gpu,u,@{},@"face-unprotected-reference-render");double inside=0,outside=0; + for(NSUInteger y=65;y<185;y++)for(NSUInteger x=175;x<275;x++)for(int c=0;c<3;c++)inside=MAX(inside,fabs((float)protectedFrame[(y*w+x)*4+c]-(float)unprotected[(y*w+x)*4+c]));for(NSUInteger y=410;y<470;y++)for(NSUInteger x=410;x<470;x++)for(int c=0;c<3;c++)outside=MAX(outside,fabs((float)protectedFrame[(y*w+x)*4+c]-(float)unprotected[(y*w+x)*4+c])); + run.record(@"face-protects-face-color-without-same-hue-background",inside>.005&&outside<.002,@{@"faceDifference":@(inside),@"backgroundDifference":@(outside)}); + u.skinProtection.x=1;u.skinVisualize=1;Pixels selection=render(run,face,src,dst,gpu,u,@{},@"face-actual-selection-preview-render");double white=0,black=0;for(NSUInteger y=65;y<185;y++)for(NSUInteger x=175;x<275;x++)white=MAX(white,(float)selection[(y*w+x)*4]);for(NSUInteger y=410;y<470;y++)for(NSUInteger x=410;x<470;x++)black=MAX(black,(float)selection[(y*w+x)*4]); + double maximum=0;NSUInteger maxX=0,maxY=0;for(NSUInteger y=0;ymaximum){maximum=selection[(y*w+x)*4];maxX=x;maxY=y;} + run.record(@"face-preview-shows-actual-weight-and-excludes-background",white>.01&&black<.001,@{@"faceWeight":@(white),@"backgroundWeight":@(black),@"maximum":@(maximum),@"maxX":@(maxX),@"maxY":@(maxY)}); + Pixels noFace(w*h*4);for(NSUInteger i=0;i #import #import @@ -141,6 +142,7 @@ struct Run { bool passed=true; void record(NSString *name,bool ok,NSDictionary *details=nil) { NSMutableDictionary *row=[NSMutableDictionary dictionaryWithDictionary:details?:@{}]; + if(getenv("DAYU_DIAGNOSTICS_PROGRESS"))fprintf(stderr,"%s %s\n",ok?"PASS":"FAIL",name.UTF8String); row[@"name"]=name;row[@"pass"]=@(ok);[rows addObject:row];if(!ok)passed=false; } void need(NSString *name,bool ok,NSDictionary *details=nil) { @@ -249,8 +251,8 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { 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",@"spider",@"base"]containsObject:card[@"section"][@"key"]])&&[(NSButton*)card[@"enabled"]state]==NSControlStateValueOn; - run.record(@"default-primary-spider-base-expanded-all-eyes-on",initialUI,@{@"modules":@(cards.count)}); + for(NSDictionary *card in cards){BOOL expected=[@[@"primary",@"spider",@"base",@"hsl"]containsObject:card[@"section"][@"key"]];initialUI&=[card[@"collapsed"]boolValue]&&[card[@"removed"]boolValue]!=expected;} + run.record(@"default-only-primary-spider-base-hsl-visible-and-collapsed",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); @@ -272,7 +274,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { NSWindow *interactionWindow=[[[NSWindow alloc]initWithContentRect:NSMakeRect(0,0,400,780) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]autorelease];interactionWindow.contentView=inspector;[inspector layoutSubtreeIfNeeded]; NSArray *graphics=[inspector valueForKey:@"graphics"];NSView *wheel=nil;for(NSView *graphic in graphics)if([NSStringFromClass(graphic.class)isEqual:@"DYPrimaryBalanceWheel"])wheel=graphic; run.need(@"primary-balance-wheel-restored-and-palette-loaded",wheel&&[wheel valueForKey:@"wheel"]!=nil); - BOOL merged=cards.count==14&&[cards[0][@"section"][@"key"]isEqual:@"primary"]&&[cards[1][@"section"][@"key"]isEqual:@"spider"];for(NSDictionary *card in cards)merged&=![@[@"input",@"output"]containsObject:card[@"section"][@"key"]]; + BOOL merged=cards.count==DYToolTypes().count&&[cards[0][@"section"][@"key"]isEqual:@"primary"]&&[cards[1][@"section"][@"key"]isEqual:@"spider"];for(NSDictionary *card in cards)merged&=![@[@"input",@"output"]containsObject:card[@"section"][@"key"]]; NSDictionary *controls=[inspector valueForKey:@"controls"];for(NSDictionary *record in controls.allValues)merged&=![[record[@"descriptor"]objectForKey:@"key"]hasPrefix:@"cmbypass"]; run.record(@"single-primary-card-no-bypass-checkboxes",merged); auto mouseFor=[&](NSView *view,NSEventType type,NSPoint point,NSEventModifierFlags flags=0,NSInteger clicks=1){return [NSEvent mouseEventWithType:type location:[view convertPoint:point toView:nil] modifierFlags:flags timestamp:0 windowNumber:interactionWindow.windowNumber context:nil eventNumber:0 clickCount:clicks pressure:type==NSEventTypeLeftMouseUp?0:1];}; @@ -305,6 +307,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { [disc resetMesh];NSData *beforeCancel=[[disc.meshData copy]autorelease];NSPoint anchor=[disc point:2];[disc mouseDown:mouseFor(disc,NSEventTypeLeftMouseDown,anchor)];[disc mouseDragged:mouseFor(disc,NSEventTypeLeftMouseDragged,NSMakePoint(anchor.x+10,anchor.y+5))];[disc keyDown:[NSEvent keyEventWithType:NSEventTypeKeyDown location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:interactionWindow.windowNumber context:nil characters:@"\x1b" charactersIgnoringModifiers:@"\x1b" isARepeat:NO keyCode:53]];run.record(@"spider-escape-restores-coordinates-and-pins",[beforeCancel isEqual:disc.meshData]); run.record(@"native-interaction-window-never-visible",!interactionWindow.visible);[inspector resetAll:nil];[inspector refresh]; id gpu=MTLCreateSystemDefaultDevice();run.need(@"metal-device",gpu!=nil);gpuName=gpu.name; + defaults.skinFaceOnly=0; // legacy point-color and Cube reference suite 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); Pixels input(width*height*4);for(NSUInteger y=0;y entries; FxRect image=source.imagePixelBounds,tile=source.tilePixelBounds; - if(image.left!=tile.left||image.right!=tile.right||image.top!=tile.top||image.bottom!=tile.bottom)return; + if(image.left!=tile.left||image.right!=tile.right||image.top!=tile.top||image.bottom!=tile.bottom){[_faceEntries release];_faceEntries=nil;[_faceInput release];_faceInput=nil;return;} NSMutableDictionary *device=[self device:source.deviceRegistryID error:nil];idtexture=[source metalTextureForDevice:device[@"device"]];if(!texture)return; if(!_faceContext)_faceContext=[[CIContext contextWithMTLDevice:device[@"device"] options:@{kCIContextCacheIntermediates:@NO}]retain]; CGColorSpaceRef linear=CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB); CIImage *input=[CIImage imageWithMTLTexture:texture options:@{kCIImageColorSpace:(id)linear}];CGColorSpaceRelease(linear);if(!input)return; - // FxPlug's bottom-left textures need the same visual orientation as mask UV. - if(source.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)input=[input imageByApplyingTransform:CGAffineTransformMake(1,0,0,-1,0,input.extent.size.height)]; + // CIImage's MTLTexture coordinates are bottom-up; normalize FxPlug top-first rows. + if(source.imageOrigin==kFxImageOrigin_TOP_LEFT)input=[input imageByApplyingTransform:CGAffineTransformMake(1,0,0,-1,0,input.extent.size.height)]; CGFloat scale=MIN(1.,960./MAX(input.extent.size.width,input.extent.size.height));input=[input imageByApplyingTransform:CGAffineTransformMakeScale(scale,scale)]; CGColorSpaceRef srgb=CGColorSpaceCreateWithName(kCGColorSpaceSRGB);CGImageRef cg=[_faceContext createCGImage:input fromRect:input.extent format:kCIFormatRGBA8 colorSpace:srgb];CGColorSpaceRelease(srgb);if(!cg)return; + CFDataRef raster=CGDataProviderCopyData(CGImageGetDataProvider(cg));BOOL same=raster&&[_faceInput isEqual:(NSData*)raster];if(same){_faceEntries=[_faceCachedEntries retain];CFRelease(raster);CGImageRelease(cg);return;}[_faceInput release];_faceInput=raster?[(NSData*)raster copy]:nil;if(raster)CFRelease(raster);[_faceEntries release];_faceEntries=nil; VNDetectFaceLandmarksRequest *request=[VNDetectFaceLandmarksRequest new];request.revision=VNDetectFaceLandmarksRequestRevision3;request.constellation=VNRequestFaceLandmarksConstellation76Points; VNImageRequestHandler *handler=[[VNImageRequestHandler alloc]initWithCGImage:cg orientation:kCGImagePropertyOrientationUp options:@{}];CGImageRelease(cg); if([handler performRequests:@[request] error:nil])for(VNFaceObservation *face in request.results){ @@ -26,21 +27,16 @@ DYToolMaskEntry hole{};hole.section=-101;hole.mask.parameters=dyDefaultMaskParameters();auto &h=hole.mask.parameters;h.kind=DYMaskEllipse;h.centerX=box.origin.x+(loX+hiX)*.5*box.size.width;h.centerY=1-(box.origin.y+(loY+hiY)*.5*box.size.height);h.width=(hiX-loX)*box.size.width*1.2;h.height=MAX(.035,hiY-loY)*box.size.height*1.6;h.feather=.35;entries.push_back(hole); } } - [handler release];[request release];_faceEntries=[[NSData alloc]initWithBytes:entries.data() length:entries.size()*sizeof(DYToolMaskEntry)]; + [handler release];[request release];_faceEntries=[[NSData alloc]initWithBytes:entries.data() length:entries.size()*sizeof(DYToolMaskEntry)];[_faceCachedEntries release];_faceCachedEntries=[_faceEntries copy]; } - (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){ BOOL face=(u.skinProtection.x>.5&&u.skinFaceOnly>.5)||u.skinVisualize>.5;for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);face|=[node[@"type"]isEqual:@"skin"]&&layer.skinProtection.x>.5&&layer.skinFaceOnly>.5;} if(face&&!_exporting)[self prepareFaceSupport:src];else{[_faceEntries release];_faceEntries=nil;} BOOL ok=[self renderToolsSource:src destination:dst uniforms:u paths:paths spider:spider tools:tools error:error]; - if(ok&&u.skinVisualize>.5&&!DYBaseToolRemoved(tools,@"skin")){ - NSMutableDictionary *entry=[self device:dst.deviceRegistryID error:error];idd=entry[@"device"];idoutput=[dst metalTextureForDevice:d],input=[src metalTextureForDevice:d]; - MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:output.pixelFormat width:output.width height:output.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget;idpreview=[d newTextureWithDescriptor:desc]; - if(!preview)return fail(error,@"无法分配肤色区域预览");DYToolMaskHeader header{};header.section=3;header.faceOnly=u.skinFaceOnly>.5;idmasks=[self maskBuffer:tools[@"baseMasks"] tile:src device:d header:&header];idcb=[entry[@"queue"]commandBuffer];idce=[cb computeCommandEncoder];[ce setComputePipelineState:entry[@"dySkinOverlay"]];[ce setTexture:input atIndex:0];[ce setTexture:output atIndex:1];[ce setTexture:preview atIndex:2];[ce setBuffer:masks offset:0 atIndex:0];[ce setBytes:&header length:sizeof(header) atIndex:1];[ce setBytes:&u length:sizeof(u) atIndex:2];[ce dispatchThreads:MTLSizeMake(output.width,output.height,1)threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];[cb commit];[cb waitUntilCompleted]; - DYExportTile *tile=[[DYExportTile alloc]initWithTexture:preview registry:d.registryID];[tile setBounds:dst.tilePixelBounds origin:dst.imageOrigin];[tile setPixelAspect:dst.pixelAspect];ok=cb.status==MTLCommandBufferStatusCompleted&&[self copyTile:tile to:dst entry:entry error:error];[tile release];[preview release]; - } return ok; }} - (BOOL)renderLens:(FxImageTile*)source destination:(FxImageTile*)destination uniforms:(DYUniforms)u masks:(NSArray*)masks entry:(NSDictionary*)entry error:(NSError**)error { + if(source.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)u.lensCenterY=1-u.lensCenterY; idd=entry[@"device"];idbefore=[source metalTextureForDevice:d],output=[destination metalTextureForDevice:d]; idcb=[entry[@"queue"]commandBuffer];idce=[cb computeCommandEncoder];[ce setComputePipelineState:entry[@"dyLensRepair"]];[ce setTexture:before atIndex:0];[ce setTexture:output atIndex:1];[ce setBytes:&u length:sizeof(u) atIndex:0];float aspect=before.width*source.pixelAspect/MAX(1.,(double)before.height);[ce setBytes:&aspect length:sizeof(aspect) atIndex:1];[ce dispatchThreads:MTLSizeMake(output.width,output.height,1)threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];[cb commit];[cb waitUntilCompleted];if(cb.status!=MTLCommandBufferStatusCompleted)return fail(error,cb.error.localizedDescription); if(!masks.count)return YES;MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:output.pixelFormat width:output.width height:output.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget;idblend=[d newTextureWithDescriptor:desc];if(!blend)return fail(error,@"无法分配修复蒙版");DYToolMaskHeader h{};h.section=(int)[DYToolTypes()indexOfObject:@"lens"];idbuffer=[self maskBuffer:@{@"lens":masks}tile:source device:d header:&h];cb=[entry[@"queue"]commandBuffer];[self encodeBlend:before after:output output:blend masks:buffer header:h entry:entry commands:cb];[cb commit];[cb waitUntilCompleted];DYExportTile *tile=[[DYExportTile alloc]initWithTexture:blend registry:d.registryID];[tile setBounds:destination.tilePixelBounds origin:destination.imageOrigin];[tile setPixelAspect:destination.pixelAspect];BOOL ok=cb.status==MTLCommandBufferStatusCompleted&&[self copyTile:tile to:destination entry:entry error:error];[tile release];[blend release];return ok; diff --git a/大鱼调色/Plugin/DYFilmDiagnostics.inc.h b/大鱼调色/Plugin/DYFilmDiagnostics.inc.h index 455fe71..aac69b6 100644 --- a/大鱼调色/Plugin/DYFilmDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYFilmDiagnostics.inc.h @@ -4,7 +4,7 @@ auto filmRender=[&](DYUniforms value,NSDictionary *tools,NSString *name){NSError *failure=nil;BOOL ok=[renderer renderSource:source destination:destination uniforms:value paths:@{} spider:nil tools:tools?:empty.document error:&failure];run.need(name,ok,@{@"error":reason(failure)});return read(destination,gpu);}; uploadFilm(input);DYUniforms neutral=DYToolUniforms(@{@"type":@"mixer"});neutral.mixerSectionEnabled=1; Pixels before=filmRender(neutral,nil,@"film-neutral-production-render"); - run.record(@"new-tools-default-to-neutral",!DYChannelMixerActive(neutral)&&!DYFilmActive(defaults.film)&&DYToolTypes().count==14&&DYToolIsNeutral(DYNewTool(@"film"))&&DYToolIsNeutral(DYNewTool(@"mixer"))); + run.record(@"new-tools-default-to-neutral",!DYChannelMixerActive(neutral)&&!DYFilmActive(defaults.film)&&DYToolTypes().count==15&&DYToolIsNeutral(DYNewTool(@"lens"))&&DYToolIsNeutral(DYNewTool(@"film"))&&DYToolIsNeutral(DYNewTool(@"mixer"))); BOOL alpha=YES;for(size_t i=0;i50&&delta.nonfinite==0,measure(delta)); diff --git a/大鱼调色/Plugin/DYGrade.metal b/大鱼调色/Plugin/DYGrade.metal index 7b02891..59a7b50 100644 --- a/大鱼调色/Plugin/DYGrade.metal +++ b/大鱼调色/Plugin/DYGrade.metal @@ -17,13 +17,13 @@ extern "C" half4 dy_gradeMasked(half4 sample, float2 uv, texture2d source, texture3d look3, texture3d look4, texture3d look5, texture3d hslMixer, texture3d whiteBalance, texture3d colorGrading, constant DYUniforms& uniforms, - constant float& sceneLevel,float w0,float w1,float w2,float w3,float w4,float w5,float w6,float w7,float w8,float w9,float w10,float w11); + constant float& sceneLevel,float w0,float w1,float w2,float w3,float w4,float w5,float w6,float w7,float w8,float w9,float w10,float w11,float skinVisualize); extern "C" half4 dy_gradeSegment(half4 sample, float2 uv, texture2d source, texture3d preLUT, texture3d look1, texture3d look2, texture3d look3, texture3d look4, texture3d look5, texture3d hslMixer, texture3d whiteBalance, texture3d colorGrading, constant DYUniforms& uniforms, - constant float& sceneLevel,float w0,float w1,float w2,float w3,float w4,float w5,float w6,float w7,float w8,float w9,float w10,float w11,uint stageFirst,uint stageLast,float3 skinReference,float3 originalReference); + constant float& sceneLevel,float w0,float w1,float w2,float w3,float w4,float w5,float w6,float w7,float w8,float w9,float w10,float w11,float skinVisualize,uint stageFirst,uint stageLast,float3 skinReference,float3 originalReference); struct DYRaster { float4 position [[position]]; @@ -65,7 +65,7 @@ fragment half4 dyFragment(DYRaster in [[stage_in]], half4 color=dy_grade(sample,in.uv,source,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel); result.rgb=mix(color.rgb,result.rgb,half(options.blackWhiteMix)); } - if(spiderSize.x>0 && uniforms.spiderSectionEnabled>.5f && uniforms.spiderMix>0.0f){ + if(uniforms.skinVisualize<.5f && spiderSize.x>0 && uniforms.spiderSectionEnabled>.5f && uniforms.spiderMix>0.0f){ float3 color=float3(result.rgb);float3 warped=dyVariableSpider(color,spiderSize.x,spiderSize.y,spiderSamples); result.rgb=half3(dyLimit(mix(color,warped,uniforms.spiderMix))); } @@ -173,12 +173,12 @@ fragment half4 dyMaskedFragment(DYRaster in [[stage_in]], float weights[12];float3 encoded=dyToolEncode(float3(sample.rgb)); for(int i=0;i<12;i++)weights[i]=dyToolCoverage(in.uv,encoded,masks,maskHeader,i); half4 result = dy_gradeMasked(sample, in.uv, source, preLUT, look1, look2, look3, - look4, look5, hslMixer, whiteBalance, colorGrading, uniforms, sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11]); + look4, look5, hslMixer, whiteBalance, colorGrading, uniforms, sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uniforms.skinVisualize); if(options.blackWhiteMix>0.0f && options.blackWhiteMix<1.0f) { - half4 color=dy_gradeMasked(sample,in.uv,source,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11]); + half4 color=dy_gradeMasked(sample,in.uv,source,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uniforms.skinVisualize); result.rgb=mix(color.rgb,result.rgb,half(options.blackWhiteMix)); } - if(spiderSize.x>0 && uniforms.spiderSectionEnabled>.5f && uniforms.spiderMix>0.0f){ + if(uniforms.skinVisualize<.5f && spiderSize.x>0 && uniforms.spiderSectionEnabled>.5f && uniforms.spiderMix>0.0f){ float3 color=float3(result.rgb);float3 warped=dyVariableSpider(color,spiderSize.x,spiderSize.y,spiderSamples); result.rgb=half3(dyLimit(mix(color,warped,uniforms.spiderMix*weights[1]))); } @@ -219,9 +219,9 @@ fragment half4 dySegmentFragment(DYRaster in [[stage_in]], half4 reference=skinReference.sample(sampleFilter,in.uv); float3 skinEncoded=dyToolEncode(reference.a>half(0)?float3(reference.rgb/reference.a):float3(0)); half4 result = dy_gradeSegment(sample, in.uv, nativeSource, preLUT, look1, look2, look3, - look4, look5, hslMixer, whiteBalance, colorGrading, uniforms, sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uint(stages.first),uint(stages.last),skinEncoded,encoded); + look4, look5, hslMixer, whiteBalance, colorGrading, uniforms, sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uniforms.skinVisualize,uint(stages.first),uint(stages.last),skinEncoded,encoded); if(stages.first<=9 && stages.last>=9 && options.blackWhiteMix>0.0f && options.blackWhiteMix<1.0f) { - half4 color=dy_gradeSegment(sample,in.uv,nativeSource,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uint(stages.first),uint(stages.last),skinEncoded,encoded); + half4 color=dy_gradeSegment(sample,in.uv,nativeSource,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel,weights[0],weights[1],weights[2],weights[3],weights[4],weights[5],weights[6],weights[7],weights[8],weights[9],weights[10],weights[11],uniforms.skinVisualize,uint(stages.first),uint(stages.last),skinEncoded,encoded); result.rgb=mix(color.rgb,result.rgb,half(options.blackWhiteMix)); } result.a = sample.a; @@ -327,11 +327,12 @@ kernel void dyColorManagement(texture2d source [[texture(0)] // Premultiplication is preserved by mixing the two equally-alpha images. kernel void dyToolBlend(texture2d before [[texture(0)]],texture2d after [[texture(1)]],texture2d output [[texture(2)]],device const DYToolMaskEntry* masks [[buffer(0)]],constant DYToolMaskHeader& h [[buffer(1)]],uint2 pos [[thread_position_in_grid]]){ - if(pos.x>=output.get_width()||pos.y>=output.get_height())return;float4 a=before.read(pos),b=after.read(pos);float2 uv=(float2(pos)+.5f)/float2(output.get_width(),output.get_height());float amount=dyToolCoverage(uv,dyToolEncode(a.a>0?(h.premultiplied?a.rgb/a.a:a.rgb):float3(0)),masks,h,h.section);output.write(half4(mix(a,b,amount)),pos); + if(pos.x>=output.get_width()||pos.y>=output.get_height())return;float4 a=before.read(pos),b=after.read(pos);float2 uv=(float2(pos)+.5f)/float2(output.get_width(),output.get_height());float amount=dyToolCoverage(uv,dyToolEncode(a.a>0?(h.premultiplied?a.rgb/a.a:a.rgb):float3(0)),masks,h,h.section);output.write(half4(h.skinPreview?float4(b.rgb*amount,a.a):mix(a,b,amount)),pos); } +extern "C" float dy_skinWeight(float3 color,float3 reference,constant DYUniforms& uniforms); extern "C" float3 dy_skinExtra(float3 color,float3 reference,constant DYUniforms& uniforms); kernel void dyToolSkin(texture2d before [[texture(0)]],texture2d reference [[texture(1)]],texture2d output [[texture(2)]],constant DYUniforms& u [[buffer(0)]],uint2 pos [[thread_position_in_grid]]){ - if(pos.x>=output.get_width()||pos.y>=output.get_height())return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);float4 a=before.read(pos),b=reference.sample(f,(float2(pos)+.5f)/float2(output.get_width(),output.get_height()));if(a.a>0){float3 c=dy_skinExtra(dyToolEncode(a.rgb/a.a),dyToolEncode(b.a>0?b.rgb/b.a:float3(0)),u);a.rgb=dyToolDecode(c)*a.a;}output.write(half4(a),pos); + if(pos.x>=output.get_width()||pos.y>=output.get_height())return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);float4 a=before.read(pos),b=reference.sample(f,(float2(pos)+.5f)/float2(output.get_width(),output.get_height()));if(a.a>0){float3 c=dy_skinExtra(dyToolEncode(a.rgb/a.a),dyToolEncode(b.a>0?b.rgb/b.a:float3(0)),u);a.rgb=u.skinVisualize>.5?float3(dy_skinWeight(float3(0),dyToolEncode(b.a>0?b.rgb/b.a:float3(0)),u)*clamp(u.skinProtection.y*.01f,0.f,1.f)*a.a):dyToolDecode(c)*a.a;}output.write(half4(a),pos); } fragment half4 dyToolCopyFragment(DYRaster in [[stage_in]],texture2d source [[texture(0)]]){constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);return source.sample(f,in.uv);} @@ -345,7 +346,3 @@ kernel void dyLensRepair(texture2d source [[texture(0)]],texture2d=output.get_width()||p.y>=output.get_height())return;float2 uv=(float2(p)+.5f)/float2(output.get_width(),output.get_height()),center=float2(u.lensCenterX,u.lensCenterY);float2 q=(uv-center)/max(1.f,u.lensScale),metric=q*float2(aspect,1);float2 corner=max(center,1-center)*float2(aspect,1);float radius=dot(metric,metric)/max(1e-6f,dot(corner,corner));float2 sample=center+q*(1+clamp(u.lensStrength,-100.f,100.f)*.0025f*radius); constexpr sampler f(coord::normalized,address::clamp_to_zero,filter::linear);output.write(source.sample(f,sample),p); } -extern "C" float dy_skinWeight(float3 color,float3 reference,constant DYUniforms& uniforms); -kernel void dySkinOverlay(texture2d source [[texture(0)]],texture2d graded [[texture(1)]],texture2d output [[texture(2)]],device const DYToolMaskEntry* masks [[buffer(0)]],constant DYToolMaskHeader& h [[buffer(1)]],constant DYUniforms& u [[buffer(2)]],uint2 p [[thread_position_in_grid]]){ - if(p.x>=output.get_width()||p.y>=output.get_height())return;float4 a=source.read(p),b=graded.read(p);float3 encoded=dyToolEncode(a.a>0?a.rgb/a.a:float3(0));float2 uv=(float2(p)+.5f)/float2(output.get_width(),output.get_height());float weight=dy_skinWeight(encoded,encoded,u)*dyToolCoverage(uv,encoded,masks,h,3)*clamp(u.skinProtection.y*.01f,0.f,1.f);float gray=dot(b.a>0?b.rgb/b.a:float3(0),float3(.2126,.7152,.0722));float3 color=mix(float3(gray*.3f),float3(1,.15f,.04f),weight*.85f);output.write(float4(color*b.a,b.a),p); -} diff --git a/大鱼调色/Plugin/DYPlugIn.mm b/大鱼调色/Plugin/DYPlugIn.mm index 6d2a46c..ff15ea7 100644 --- a/大鱼调色/Plugin/DYPlugIn.mm +++ b/大鱼调色/Plugin/DYPlugIn.mm @@ -30,12 +30,12 @@ - (NSView*)createViewForParameterID:(UInt32)pid{[self scheduleToolCanvasRegistration];return pid==DYInspectorParameterID?[[DYInspector alloc]initWithAPIManager:_apiManager renderer:_renderer]:[[NSView alloc]initWithFrame:NSZeroRect];} - (BOOL)parameterChanged:(UInt32)pid atTime:(CMTime)t error:(NSError**)e{if(pid==DYToolsParameterID)[self adoptToolCanvasDocument:DYReadTools(_apiManager,t).document];if(pid==DYToolsParameterID||pid==2013||pid==2014||(pid>=2236&&pid<2400)||pid==DYAssetsParameterID)[_renderer invalidatePreview];dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self.apiManager];});return YES;} - (BOOL)pluginState:(NSData**)state atTime:(CMTime)t quality:(FxQuality)q error:(NSError**)e{ - DYUniforms u;DYReadUniforms(_apiManager,t,&u);CMTime frameDuration=kCMTimeInvalid,origin=kCMTimeZero;idtiming=[_apiManager apiForProtocol:@protocol(FxTimingAPI_v4)];if([timing respondsToSelector:@selector(frameDuration:)])[timing frameDuration:&frameDuration];if([timing respondsToSelector:@selector(startTimeForEffect:)])[timing startTimeForEffect:&origin];int64_t frame=DYFilmFrameIndex(t,frameDuration,origin);u.filmFrameKey=DYFilmFrameKey(frame,u.film.grainHold,u.film.grainSeed);DYAssetState*a=DYReadAssets(_apiManager,t);DYToolDocument *tools=DYReadTools(_apiManager,t);[self adoptToolCanvasDocument:tools.document];[_viewerParameterBridge publishUniforms:&u document:tools.document atTime:t];[_viewerParameterBridge publishAssets:a histogram:[_renderer histogram] atTime:t];double copyAuto=0;[[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:©Auto fromParameter:8800 atTime:t];NSMutableDictionary *snapshot=DYMutablePlist(DYToolRenderSnapshot(tools.document,t));for(NSMutableDictionary *node in snapshot[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"])node[@"filmFrameKey"]=@(DYFilmFrameKey(frame,layer.film.grainHold,layer.film.grainSeed));}NSInteger primaries=-1;idgamut=[_apiManager apiForProtocol:@protocol(FxColorGamutAPI_v2)];if([gamut respondsToSelector:@selector(colorPrimaries)])primaries=gamut.colorPrimaries;NSDictionary*s=@{@"colorManagement":a.colorManagement?:@{},@"hostPrimaries":@(primaries),@"schema":@2,@"tools":snapshot,@"copyAuto":@(copyAuto>.5),@"uniforms":[NSData dataWithBytes:&u length:sizeof(u)],@"paths":a.paths?:@{},@"spider":a.spiderMesh?:[NSData data]};*state=[NSPropertyListSerialization dataWithPropertyList:s format:NSPropertyListBinaryFormat_v1_0 options:0 error:e];return *state!=nil; + DYUniforms u;DYReadUniforms(_apiManager,t,&u);CMTime frameDuration=kCMTimeInvalid,origin=kCMTimeZero;idtiming=[_apiManager apiForProtocol:@protocol(FxTimingAPI_v4)];if([timing respondsToSelector:@selector(frameDuration:)])[timing frameDuration:&frameDuration];if([timing respondsToSelector:@selector(startTimeForEffect:)])[timing startTimeForEffect:&origin];int64_t frame=DYFilmFrameIndex(t,frameDuration,origin);u.filmFrameKey=DYFilmFrameKey(frame,u.film.grainHold,u.film.grainSeed);DYAssetState*a=DYReadAssets(_apiManager,t);DYToolDocument *tools=DYReadTools(_apiManager,t);[self adoptToolCanvasDocument:tools.document];[_viewerParameterBridge publishUniforms:&u document:tools.document atTime:t];[_viewerParameterBridge publishAssets:a histogram:nil atTime:t];double copyAuto=0;[[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:©Auto fromParameter:8800 atTime:t];NSMutableDictionary *snapshot=DYMutablePlist(DYToolRenderSnapshot(tools.document,t));for(NSMutableDictionary *node in snapshot[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"])node[@"filmFrameKey"]=@(DYFilmFrameKey(frame,layer.film.grainHold,layer.film.grainSeed));}NSInteger primaries=-1;idgamut=[_apiManager apiForProtocol:@protocol(FxColorGamutAPI_v2)];if([gamut respondsToSelector:@selector(colorPrimaries)])primaries=gamut.colorPrimaries;NSDictionary*s=@{@"colorManagement":a.colorManagement?:@{},@"hostPrimaries":@(primaries),@"schema":@2,@"tools":snapshot,@"copyAuto":@(copyAuto>.5),@"uniforms":[NSData dataWithBytes:&u length:sizeof(u)],@"paths":a.paths?:@{},@"spider":a.spiderMesh?:[NSData data]};*state=[NSPropertyListSerialization dataWithPropertyList:s format:NSPropertyListBinaryFormat_v1_0 options:0 error:e];return *state!=nil; } - (BOOL)destinationImageRect:(FxRect*)rect sourceImages:(NSArray*)src destinationImage:(FxImageTile*)dst pluginState:(NSData*)s atTime:(CMTime)t error:(NSError**)e{if(!src.count)return NO;*rect=src[0].imagePixelBounds;return YES;} - (BOOL)sourceTileRect:(FxRect*)rect sourceImageIndex:(NSUInteger)i sourceImages:(NSArray*)src destinationTileRect:(FxRect)dstRect destinationImage:(FxImageTile*)dst pluginState:(NSData*)s atTime:(CMTime)t error:(NSError**)e{if(i>=src.count)return NO;*rect=src[i].imagePixelBounds;return YES;} - (BOOL)renderDestinationImage:(FxImageTile*)dst sourceImages:(NSArray*)src pluginState:(NSData*)s atTime:(CMTime)t error:(NSError**)e{ - if(!src.count||!src[0].ioSurface||!dst.ioSurface||!s.length)return NO;NSDictionary*p=[NSPropertyListSerialization propertyListWithData:s options:NSPropertyListImmutable format:NULL error:e];if(![p isKindOfClass:NSDictionary.class])return NO;NSData*b=p[@"uniforms"];if(![@[@1,@2]containsObject:p[@"schema"]]||![b isKindOfClass:NSData.class]||b.length!=sizeof(DYUniforms)||![p[@"paths"]isKindOfClass:NSDictionary.class])return NO;DYUniforms u;[b getBytes:&u length:sizeof(u)];uint64_t beta=!_betaFirstRenderStarted.exchange(true)?DYBetaSpanBegin(@"first_render",nil):0;BOOL ok=[_renderer renderSource:src[0] destination:dst uniforms:u paths:p[@"paths"] spider:p[@"spider"] tools:p[@"tools"] colorManagement:p[@"colorManagement"] hostPrimaries:p[@"hostPrimaries"]?[p[@"hostPrimaries"]integerValue]:-1 error:e];DYBetaSpanEnd(beta,@{@"status":ok?@"passed":@"failed"});if(!ok)DYBetaEvent(@"render_error",@{@"error_domain":(e&&*e)?(*e).domain:@"unknown",@"error_code":@((e&&*e)?(*e).code:0)});if(ok){[_renderer captureScopeTile:dst atTime:t];if(_toolCaptureEnabled&&!_trackingActive.load()){dy::GrayFrame frame=[self toolGrayFrame:src[0] error:nil];if(frame.valid()){@synchronized(self){_toolSourceFrame=std::move(frame);_toolSourceTime=t;}}}BOOL analyze=NO;@synchronized(self){if(![p[@"copyAuto"]boolValue])_copyAnalyzed=NO;else if(!_copyAnalyzed){_copyAnalyzed=YES;analyze=YES;}}if(analyze){NSDictionary*values=DYAutoGrade([_renderer preview]);if(values)dispatch_async(dispatch_get_main_queue(),^{[self applyValues:values];});}}return ok; + if(!src.count||!src[0].ioSurface||!dst.ioSurface||!s.length)return NO;NSDictionary*p=[NSPropertyListSerialization propertyListWithData:s options:NSPropertyListImmutable format:NULL error:e];if(![p isKindOfClass:NSDictionary.class])return NO;NSData*b=p[@"uniforms"];if(![@[@1,@2]containsObject:p[@"schema"]]||![b isKindOfClass:NSData.class]||b.length!=sizeof(DYUniforms)||![p[@"paths"]isKindOfClass:NSDictionary.class])return NO;DYUniforms u;[b getBytes:&u length:sizeof(u)];uint64_t beta=!_betaFirstRenderStarted.exchange(true)?DYBetaSpanBegin(@"first_render",nil):0;NSData *previousHistogram=[_renderer histogram];BOOL ok=[_renderer renderSource:src[0] destination:dst uniforms:u paths:p[@"paths"] spider:p[@"spider"] tools:p[@"tools"] colorManagement:p[@"colorManagement"] hostPrimaries:p[@"hostPrimaries"]?[p[@"hostPrimaries"]integerValue]:-1 error:e];DYBetaSpanEnd(beta,@{@"status":ok?@"passed":@"failed"});if(!ok)DYBetaEvent(@"render_error",@{@"error_domain":(e&&*e)?(*e).domain:@"unknown",@"error_code":@((e&&*e)?(*e).code:0)});if(ok){NSData *histogram=[_renderer histogram];if(histogram&&histogram!=previousHistogram)[_viewerParameterBridge publishHistogram:histogram atTime:t];[_renderer captureScopeTile:dst atTime:t];if(_toolCaptureEnabled&&!_trackingActive.load()){dy::GrayFrame frame=[self toolGrayFrame:src[0] error:nil];if(frame.valid()){@synchronized(self){_toolSourceFrame=std::move(frame);_toolSourceTime=t;}}}BOOL analyze=NO;@synchronized(self){if(![p[@"copyAuto"]boolValue])_copyAnalyzed=NO;else if(!_copyAnalyzed){_copyAnalyzed=YES;analyze=YES;}}if(analyze){NSDictionary*values=DYAutoGrade([_renderer preview]);if(values)dispatch_async(dispatch_get_main_queue(),^{[self applyValues:values];});}}return ok; } - (void)alert:(NSString*)message{dispatch_async(dispatch_get_main_queue(),^{NSAlert*a=[NSAlert new];a.messageText=@"大鱼调色";a.informativeText=message?:@"操作未完成";[a runModal];[a release];});} - (void)exportRequested:(NSNotification*)n{ diff --git a/大鱼调色/Plugin/DYRenderer.mm b/大鱼调色/Plugin/DYRenderer.mm index e69c348..1aaf5ca 100644 --- a/大鱼调色/Plugin/DYRenderer.mm +++ b/大鱼调色/Plugin/DYRenderer.mm @@ -68,6 +68,7 @@ static void bypassNeutralTools(DYUniforms *u){ } } static void bypassIdleSkin(DYUniforms *u){ + if(u->skinVisualize>.5)return; 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; @@ -114,7 +115,7 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData CFTimeInterval _lastPreview; BOOL _exporting; NSDictionary *_toolDocument,*_colorContext,*_exportManagedState; - BOOL _managedFinishing;NSData *_faceEntries;CIContext *_faceContext; + BOOL _managedFinishing;NSData *_faceEntries,*_faceInput,*_faceCachedEntries;CIContext *_faceContext; dispatch_queue_t _scopeQueue; BOOL _scopeEnabled,_scopeWorkerRunning; NSUInteger _scopeGeneration; @@ -132,7 +133,7 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData #include "DYFaceRender.inc.h" #include "DYToolRender.inc.h" - (instancetype)init{if((self=[super init])){_previewLock=[NSObject new];_scopeQueue=dispatch_queue_create("com.dayu.color.final-output-scopes",DISPATCH_QUEUE_SERIAL);_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{[_faceEntries release];[_faceContext release];[_scopePending release];[_scopePreview release];[_scopeMetadata release];[_scopeProfile release];dispatch_release(_scopeQueue);[_devices release];[_luts release];[_preparedLUTs release];[_activeLUTPaths release];dispatch_release(_lutPreparationQueue);[_tables release];[_preview release];[_lookLUTPreview release];[_histogram release];[_colorContext release];[_previewLock release];[super dealloc];} +- (void)dealloc{[_faceEntries release];[_faceInput release];[_faceCachedEntries release];[_faceContext release];[_scopePending release];[_scopePreview release];[_scopeMetadata release];[_scopeProfile release];dispatch_release(_scopeQueue);[_devices release];[_luts release];[_preparedLUTs release];[_activeLUTPaths release];dispatch_release(_lutPreparationQueue);[_tables release];[_preview release];[_lookLUTPreview release];[_histogram release];[_colorContext release];[_previewLock release];[super dealloc];} - (void)trimPreparedLUTsKeeping:(NSString *)path { if(_preparedLUTs.count<=12)return; for(NSString *key in _preparedLUTs.allKeys)if(![_activeLUTPaths containsObject:key]&&![key isEqualToString:path])[_preparedLUTs removeObjectForKey:key]; @@ -155,6 +156,7 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData progress.completedUnitCount=2;dispatch_async(dispatch_get_main_queue(),^{NSError *result=progress.cancelled?[NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]:error;if(completion)completion(result);}); }});return progress; } +- (void)notifyPreviewChanged{dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:@"DYPreviewDidChange" object:self];});} - (void)invalidatePreview{@synchronized(_previewLock){[_preview release];_preview=nil;[_lookLUTPreview release];_lookLUTPreview=nil;[_histogram release];_histogram=nil;_lastPreview=0;}dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:@"DYPreviewDidChange" object:self];});} - (NSData*)histogram{@synchronized(_previewLock){return [[_histogram retain]autorelease];}} - (NSData*)preview{@synchronized(_previewLock){return [[_preview retain]autorelease];}} @@ -166,7 +168,7 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData NSURL*url=[[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"]; idlib=[d newLibraryWithURL:url error:err];if(!lib){[d release];return nil;} idq=[d newCommandQueue];entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"library":lib,@"queue":q,@"pipelines":[NSMutableDictionary dictionary]}]; - for(NSString*fn in @[@"dyLensRepair",@"dySkinOverlay",@"dyUnpremultiply",@"dyWhitesSceneStatistics",@"dyLUTExportKernel",@"dyInputAnalysis",@"dyScopeSample",@"dyColorManagement",@"dyToolBlend",@"dyToolSkin",@"dyFilmPoint",@"dyFilmNoise",@"dyFilmSparseBlur",@"dyFilmBloomEdges",@"dyFilmMix",@"dyFilmPrint"]){idf=[lib newFunctionWithName:fn];if(!f){fail(err,[fn stringByAppendingString:@" 缺失"]);[lib release];[q release];[d release];return nil;}uint64_t pipelineSpan=DYBetaSpanBegin(@"gpu_pipeline",@{@"pipeline":fn,@"gpu":d.name?:@"unknown"});idp=[d newComputePipelineStateWithFunction:f error:err];DYBetaSpanEnd(pipelineSpan,@{@"status":p?@"passed":@"failed"});[f release];if(!p){[lib release];[q release];[d release];return nil;}entry[fn]=p;[p release];} + for(NSString*fn in @[@"dyLensRepair",@"dyUnpremultiply",@"dyWhitesSceneStatistics",@"dyLUTExportKernel",@"dyInputAnalysis",@"dyScopeSample",@"dyColorManagement",@"dyToolBlend",@"dyToolSkin",@"dyFilmPoint",@"dyFilmNoise",@"dyFilmSparseBlur",@"dyFilmBloomEdges",@"dyFilmMix",@"dyFilmPrint"]){idf=[lib newFunctionWithName:fn];if(!f){fail(err,[fn stringByAppendingString:@" 缺失"]);[lib release];[q release];[d release];return nil;}uint64_t pipelineSpan=DYBetaSpanBegin(@"gpu_pipeline",@{@"pipeline":fn,@"gpu":d.name?:@"unknown"});idp=[d newComputePipelineStateWithFunction:f error:err];DYBetaSpanEnd(pipelineSpan,@{@"status":p?@"passed":@"failed"});[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; // Preparing before the first frame may use registry 0. Reuse those pipelines // when the host subsequently supplies that device's actual registry ID. @@ -253,7 +255,7 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData for(NSUInteger y=0;y<180;y++)memcpy((uint8_t*)topFirst.mutableBytes+y*rowBytes,(const uint8_t*)_preview.bytes+(179-y)*rowBytes,rowBytes); _lookLUTPreview=[topFirst copy]; }else _lookLUTPreview=[_preview retain]; - _lastPreview=CACurrentMediaTime();dispatch_async(dispatch_get_main_queue(),^{[[NSNotificationCenter defaultCenter]postNotificationName:@"DYPreviewDidChange" object:self];}); + _lastPreview=CACurrentMediaTime();[self notifyPreviewChanged]; }} if(!ok)fail(err,cb.error.localizedDescription);[pb release];[straight release];[scene release];return ok; });}} diff --git a/大鱼调色/Plugin/DYToolGPU.h b/大鱼调色/Plugin/DYToolGPU.h index b824cea..d01daa2 100644 --- a/大鱼调色/Plugin/DYToolGPU.h +++ b/大鱼调色/Plugin/DYToolGPU.h @@ -1,5 +1,5 @@ #pragma once #include "MaskCore/DYMaskOperator.h" struct DYToolMaskEntry {DYResolvedMask mask;int section,combine;}; -struct DYToolMaskHeader {unsigned count;float offsetX,offsetY,scaleX,scaleY;int section,premultiplied,faceOnly;}; +struct DYToolMaskHeader {unsigned count;float offsetX,offsetY,scaleX,scaleY;int section,premultiplied,faceOnly,skinPreview;}; struct DYToolStageRange {int first,last,suppressBlackWhite;}; diff --git a/大鱼调色/Plugin/DYToolInsertionDiagnostics.inc.h b/大鱼调色/Plugin/DYToolInsertionDiagnostics.inc.h index 8a89ac5..02ce281 100644 --- a/大鱼调色/Plugin/DYToolInsertionDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYToolInsertionDiagnostics.inc.h @@ -8,7 +8,7 @@ DYToolDocument *authored=[[[DYToolDocument alloc]init]autorelease];authored.document=doc;NSData *archive=[NSKeyedArchiver archivedDataWithRootObject:authored requiringSecureCoding:YES error:&error];DYToolDocument *restored=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:archive error:&error];run.record(@"inserted-order-secure-archive-roundtrip",[restored isEqual:authored]&&[DYToolDisplayOrder(restored.document)isEqual:order]); NSMutableDictionary *bad=DYMutablePlist(doc);bad[@"layers"][0][@"after"]=@"base:unknown";run.record(@"insertion-rejects-unknown-base-anchor",!DYValidToolDocument(bad));bad=DYMutablePlist(doc);bad[@"layers"][0][@"after"]=bad[@"layers"][0][@"id"];run.record(@"insertion-rejects-cyclic-anchor",!DYValidToolDocument(bad)); BOOL removed=DYRemoveTool(doc,one[@"id"]);order=DYToolDisplayOrder(doc);hslIndex=[order indexOfObject:@"base:hsl"];run.record(@"delete-reconnects-child-without-moving-to-bottom",removed&&DYValidToolDocument(doc)&&[order[hslIndex+1]isEqual:newest[@"id"]]&&[order[hslIndex+2]isEqual:two[@"id"]]); - DYWriteTools(manager,doc,kCMTimeZero);DYInspector *inspector=[[[DYInspector alloc]initWithAPIManager:manager renderer:renderer]autorelease];[inspector refresh];[inspector setFrameSize:NSMakeSize(360,780)];[inspector layoutSubtreeIfNeeded];NSDictionary *views=[inspector valueForKey:@"_stackViews"];NSArray *cards=[inspector valueForKey:@"_cards"];NSView *baseHSL=nil,*baseCurve=nil;for(NSDictionary *card in cards){if([card[@"section"][@"key"]isEqual:@"hsl"])baseHSL=card[@"view"];if([card[@"section"][@"key"]isEqual:@"curve"])baseCurve=card[@"view"];}NSView *newView=views[newest[@"id"]],*secondView=views[two[@"id"]];run.record(@"new-native-card-is-laid-out-between-its-source-and-next-module",newView&&secondView&&NSMinY(newView.frame)>=NSMaxY(baseHSL.frame)&&NSMinY(secondView.frame)>=NSMaxY(newView.frame)&&NSMinY(baseCurve.frame)>=NSMaxY(secondView.frame)); + DYWriteTools(manager,doc,kCMTimeZero);DYInspector *inspector=[[[DYInspector alloc]initWithAPIManager:manager renderer:renderer]autorelease];[inspector refresh];[inspector setFrameSize:NSMakeSize(360,780)];[inspector layoutSubtreeIfNeeded];NSDictionary *views=[inspector valueForKey:@"_stackViews"];NSArray *cards=[inspector valueForKey:@"_cards"];NSView *baseHSL=nil,*baseCurve=nil;for(NSDictionary *card in cards){if([card[@"section"][@"key"]isEqual:@"hsl"])baseHSL=card[@"view"];if([card[@"section"][@"key"]isEqual:@"curve"])baseCurve=card[@"view"];}NSView *newView=views[newest[@"id"]],*secondView=views[two[@"id"]];run.record(@"new-native-card-is-laid-out-between-its-source-and-next-module",newView&&secondView&&NSMinY(newView.frame)>=NSMaxY(baseHSL.frame)&&NSMinY(secondView.frame)>=NSMaxY(newView.frame)&&(baseCurve.hidden||NSMinY(baseCurve.frame)>=NSMaxY(secondView.frame))); doc=DYMutablePlist(empty.document);NSMutableDictionary *legacy=DYMutablePlist(DYNewTool(@"hsl"));[doc[@"layers"]addObject:legacy];NSDictionary *child=DYInsertTool(doc,@"hsl",legacy[@"id"]);run.record(@"schema-one-tail-layer-retains-tail-root-with-new-child",[DYToolRootAnchor(doc,legacy[@"id"])isEqual:@"tail"]&&[DYToolRootAnchor(doc,child[@"id"])isEqual:@"tail"]&&[DYToolDisplayOrder(doc).lastObject isEqual:child[@"id"]]); auto renderInserted=[&](NSDictionary *tools,DYUniforms u,NSString *name){NSError *failure=nil;BOOL ok=[renderer renderSource:source destination:destination uniforms:u paths:@{} spider:nil tools:tools error:&failure];run.need(name,ok,@{@"error":reason(failure)});return read(destination,gpu);}; auto upload=[&](DYDiagnosticTile *tile,const Pixels &pixels){[[tile metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:width*8];}; diff --git a/大鱼调色/Plugin/DYToolInspector.inc.h b/大鱼调色/Plugin/DYToolInspector.inc.h index c33aeb5..c33f632 100644 --- a/大鱼调色/Plugin/DYToolInspector.inc.h +++ b/大鱼调色/Plugin/DYToolInspector.inc.h @@ -48,7 +48,8 @@ }@finally{ if(grouped)[undo endUndoGroup];[a endAction:self]; if(attempted&&!changed&&!failure)failure=[NSError errorWithDomain:@"com.dayu.color.ToolRemoval" code:1 userInfo:@{NSLocalizedDescriptionKey:@"未能完成删除,模块已保留。可撤销本次参数还原。"}]; - dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:host];if(failure)[self showError:failure.localizedDescription];}); + id retainedHost=[(id)host retain];NSError *retainedFailure=[failure retain]; + dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:retainedHost];if(retainedFailure)[self showError:retainedFailure.localizedDescription];[retainedHost release];[retainedFailure release];}); } // Model refresh posts accessibility changes after the remote action unwinds. // Synchronous notification here can re-enter the host's ViewBridge callback. diff --git a/大鱼调色/Plugin/DYToolRender.inc.h b/大鱼调色/Plugin/DYToolRender.inc.h index b159bfc..414ef0f 100644 --- a/大鱼调色/Plugin/DYToolRender.inc.h +++ b/大鱼调色/Plugin/DYToolRender.inc.h @@ -36,9 +36,9 @@ if(![type isEqual:@"skin"])return [self renderLegacy:source destination:destination uniforms:layer paths:node[@"paths"] spider:node[@"spider"] masks:@{type:node[@"masks"]} error:error]; idd=entry[@"device"];idbefore=[source metalTextureForDevice:d],input=[original metalTextureForDevice:d],after=[destination metalTextureForDevice:d]; idcb=[entry[@"queue"]commandBuffer];idce=[cb computeCommandEncoder];[ce setComputePipelineState:entry[@"dyToolSkin"]];[ce setTexture:before atIndex:0];[ce setTexture:input atIndex:1];[ce setTexture:after atIndex:2];[ce setBytes:&layer length:sizeof(layer) atIndex:0];[ce dispatchThreads:MTLSizeMake(after.width,after.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];[cb commit];[cb waitUntilCompleted];if(cb.status!=MTLCommandBufferStatusCompleted)return fail(error,cb.error.localizedDescription); - if(![node[@"masks"]count]&&layer.skinFaceOnly<.5)return YES; + if(![node[@"masks"]count]&&layer.skinFaceOnly<.5&&layer.skinVisualize<.5)return YES; MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:after.width height:after.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageRenderTarget|MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;idblend=[d newTextureWithDescriptor:desc];if(!blend)return fail(error,@"无法分配新增工具蒙版缓冲区"); - DYToolMaskHeader h{};h.section=3;h.faceOnly=layer.skinFaceOnly>.5;idbuffer=[self maskBuffer:@{type:node[@"masks"]} tile:source device:d header:&h];cb=[entry[@"queue"]commandBuffer];[self encodeBlend:before after:after output:blend masks:buffer header:h entry:entry commands:cb];[cb commit];[cb waitUntilCompleted];BOOL ok=cb.status==MTLCommandBufferStatusCompleted; + DYToolMaskHeader h{};h.section=3;h.faceOnly=layer.skinFaceOnly>.5;h.skinPreview=layer.skinVisualize>.5;idbuffer=[self maskBuffer:@{type:node[@"masks"]} tile:source device:d header:&h];cb=[entry[@"queue"]commandBuffer];[self encodeBlend:before after:after output:blend masks:buffer header:h entry:entry commands:cb];[cb commit];[cb waitUntilCompleted];BOOL ok=cb.status==MTLCommandBufferStatusCompleted; DYExportTile *blended=[[DYExportTile alloc]initWithTexture:blend registry:d.registryID];[blended setBounds:source.tilePixelBounds origin:source.imageOrigin];[blended setPixelAspect:source.pixelAspect];[blend release];if(ok)ok=[self copyTile:blended to:destination entry:entry error:error];else fail(error,cb.error.localizedDescription);[blended release];return ok; } - (BOOL)renderToolsSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){return DYRenderWithPool(error,[&]()->BOOL{ @@ -101,6 +101,7 @@ - (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){ if(tools&&!DYValidToolDocument(tools))return fail(error,@"工具或蒙版数据损坏,未更改原工程");DYApplyRemovedBaseTools(&u,tools);paths=DYVisibleBaseToolPaths(paths,tools);if(DYBaseToolRemoved(tools,@"spider"))spider=nil; if((u.lensSectionEnabled>.5&&(u.lensStrength!=0||u.lensScale!=1))||u.skinVisualize>.5)return fail(error,@"镜头修复与肤色区域显示无法保存到 Cube,请保存完整预设。");for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"lens"]&&!DYToolIsNeutral(node))return fail(error,@"镜头畸变属于空间处理,请保存完整预设。");} + DYUniforms effective=u;bypassNeutralTools(&effective);bypassIdleSkin(&effective);if(effective.skinFaceOnly>.5&&effective.skinProtection.x>.5&&effective.skinProtection.y>0)return fail(error,@"人脸限定肤色保护属于空间选区,Cube 无法保存。请保存完整预设,或关闭人脸限定后导出。");for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"skin"]&&layer.skinProtection.x>.5&&layer.skinProtection.y>0&&(layer.skinFaceOnly>.5||layer.skinVisualize>.5))return fail(error,@"新增肤色层含人脸空间选区,请保存完整预设。");} if(DYFilmToolActive(u)&&DYFilmSpatialActive(u.film))return fail(error,@"当前胶片含晕光、辉光、颗粒或暗角,无法完整保存到静态 Cube。请保存完整预设,或关闭这些处理后再导出。");for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"]&&DYFilmToolActive(layer)&&DYFilmSpatialActive(layer.film))return fail(error,@"新增胶片层含空间或时间处理,无法完整保存到静态 Cube。请保存完整预设。");} for(NSArray *masks in [tools[@"baseMasks"]allValues])if(masks.count)return fail(error,@"当前调色含空间蒙版或跟踪,Cube 无法保存这些信息。请先保存完整预设,或移除蒙版后导出。");for(NSDictionary *node in tools[@"layers"])if([node[@"masks"]count])return fail(error,@"新增工具含蒙版,无法完整导出为 Cube。请保存完整预设。"); _toolDocument=tools;BOOL ok=NO;@try{ok=[self exportLUT:url uniforms:u paths:paths spider:spider error:error];}@finally{_toolDocument=nil;}return ok; diff --git a/大鱼调色/Plugin/DYViewerControlsDiagnostics.inc.h b/大鱼调色/Plugin/DYViewerControlsDiagnostics.inc.h index 5c951af..2e2c378 100644 --- a/大鱼调色/Plugin/DYViewerControlsDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYViewerControlsDiagnostics.inc.h @@ -13,9 +13,9 @@ publish();int undo=base->_undoStarts;NSDictionary*initial=[[base->_values copy]autorelease]; NSMutableSet*types=[NSMutableSet set];CGFloat x=-1,lastY=-1;BOOL vertical=YES; for(NSDictionary*a in [controls valueForKey:@"areas"])if([a[@"kind"]isEqual:@"tool"]){NSRect r=[a[@"rect"]rectValue];if(x>=0)vertical&=r.origin.x==x&&r.origin.y>lastY;x=r.origin.x;lastY=r.origin.y;[types addObject:a[@"toolType"]];} - run.record(@"viewer-vertical-rail-exposes-fourteen-tools-without-a-parameter-panel",vertical&&types.count==14&&[[controls valueForKey:@"panels"]count]==0); + run.record(@"viewer-vertical-rail-exposes-all-tools-without-a-parameter-panel",vertical&&types.count==DYToolTypes().count&&[[controls valueForKey:@"panels"]count]==0); BOOL allOpen=YES;for(NSString*type in DYToolTypes()){click(areaFor(controls,@"tool",type));allOpen&=panelFor(type)!=nil;} - run.record(@"viewer-tools-open-independent-panels-without-editing-the-grade",allOpen&&[[controls valueForKey:@"panels"]count]==14&&[initial isEqual:base->_values]&&base->_undoStarts==undo); + run.record(@"viewer-tools-open-independent-panels-without-editing-the-grade",allOpen&&[[controls valueForKey:@"panels"]count]==DYToolTypes().count&&[initial isEqual:base->_values]&&base->_undoStarts==undo); click(areaFor(controls,@"hidePanels",nil));click(areaFor(controls,@"tool",@"base"));id panel=panelFor(@"base"); NSRect before=[[panel valueForKey:@"panel"]rectValue],header=[areaFor(panel,@"open",nil)[@"rect"]rectValue];NSPoint hp=NSMakePoint(NSMidX(header),NSMidY(header)); [controls event:NSEventTypeLeftMouseDown point:hp atTime:host->_time];[controls event:NSEventTypeLeftMouseDragged point:NSMakePoint(hp.x+90,hp.y+20) atTime:host->_time];[controls event:NSEventTypeLeftMouseUp point:NSMakePoint(hp.x+140,hp.y+30) atTime:host->_time];NSRect after=[[panel valueForKey:@"panel"]rectValue]; @@ -74,11 +74,11 @@ [controls setViewport:NSMakeRect(40,30,1160,650)];[controls prepareWithSize:size scale:1 atTime:host->_time];NSRect rail=[[controls valueForKey:@"rail"]rectValue];run.record(@"viewer-rail-is-anchored-to-image-and-not-letterbox",NSContainsRect(NSMakeRect(40,30,1160,650),rail)&&[controls partAtPoint:NSMakePoint(NSMidX(rail),20)]==0); // Offscreen drawing checks the actual OSC renderer, without opening an APP. [controls setViewport:NSMakeRect(0,0,1280,720)];[controls prepareWithSize:size scale:1 atTime:host->_time]; - for(NSString*type in @[@"base",@"curve",@"grading"]){click(areaFor(controls,@"tool",type));id p=panelFor(type);CGFloat px=[type isEqual:@"base"]?.05:[type isEqual:@"curve"]?.32:.59;[p setValue:[NSValue valueWithPoint:NSMakePoint(px,.1)]forKey:@"position"];} + for(NSString*type in @[@"hsl",@"curve",@"spider"]){click(areaFor(controls,@"tool",type));id p=panelFor(type);CGFloat px=[type isEqual:@"hsl"]?.05:[type isEqual:@"curve"]?.32:.59;[p setValue:[NSValue valueWithPoint:NSMakePoint(px,.1)]forKey:@"position"];} [controls prepareWithSize:size scale:1 atTime:host->_time]; NSBitmapImageRep*bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:1280 pixelsHigh:720 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:1280*4 bitsPerPixel:32]autorelease]; [NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];NSAffineTransform*flip=[NSAffineTransform transform];[flip translateXBy:0 yBy:720];[flip scaleXBy:1 yBy:-1];[flip concat];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:NSGraphicsContext.currentContext.CGContext flipped:YES]]; [[NSColor colorWithCalibratedWhite:.2 alpha:1]setFill];NSRectFill(NSMakeRect(0,0,1280,720));[controls draw];[NSGraphicsContext restoreGraphicsState];NSString*png=[runtime stringByAppendingPathComponent:@"viewer-workspace.png"]; - run.record(@"viewer-real-osc-draws-vertical-rail-curves-and-wheels-offscreen",[[bitmap representationUsingType:NSBitmapImageFileTypePNG properties:@{}]writeToFile:png atomically:YES],@{@"path":png}); + run.record(@"viewer-real-osc-draws-curves-hsl-and-spider-offscreen",[[bitmap representationUsingType:NSBitmapImageFileTypePNG properties:@{}]writeToFile:png atomically:YES],@{@"path":png}); [controls finishCapture];controls.bridge=nil;[bridge invalidate];drain();[controls release];[bridge release]; } diff --git a/大鱼调色/Plugin/DYViewerParameterBridge.inc.h b/大鱼调色/Plugin/DYViewerParameterBridge.inc.h index 6cc9cf0..1d37d1b 100644 --- a/大鱼调色/Plugin/DYViewerParameterBridge.inc.h +++ b/大鱼调色/Plugin/DYViewerParameterBridge.inc.h @@ -21,6 +21,7 @@ - (void)publishAssets:(DYAssetState*)assets histogram:(NSData*)histogram atTime:(CMTime)time; - (void)beginSpider:(NSData*)mesh node:(NSString*)node enabled:(double)enabled atTime:(CMTime)time; - (void)changeSpider:(NSData*)mesh; +- (void)publishHistogram:(NSData*)histogram atTime:(CMTime)time; @end static BOOL DYViewerSameValue(double a,double b) { @@ -81,6 +82,9 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) { - (void)publishAssets:(DYAssetState*)assets histogram:(NSData*)histogram atTime:(CMTime)time { @synchronized(self){if(_invalidated||!_snapshot||CMTimeCompare(time,_snapshotTime)!=0)return;NSMutableDictionary *next=[[_snapshot mutableCopy]autorelease];next[@"spider"]=assets.spiderMesh?:[NSData data];if(histogram)next[@"histogram"]=histogram;[_snapshot release];_snapshot=[next copy];} } +- (void)publishHistogram:(NSData*)histogram atTime:(CMTime)time { + if(histogram.length!=sizeof(DYHistogram))return;@synchronized(self){if(_invalidated||!_snapshot||CMTimeCompare(time,_snapshotTime)!=0)return;NSMutableDictionary *next=[[_snapshot mutableCopy]autorelease];next[@"histogram"]=histogram;[_snapshot release];_snapshot=[next copy];} +} - (void)requestTool:(NSString*)type { if(![DYToolTypes()containsObject:type])return; dispatch_async(dispatch_get_main_queue(),^{id manager=nil;@synchronized(self){if(!self->_invalidated)manager=self->_apiManager;}if(manager)[NSNotificationCenter.defaultCenter postNotificationName:@"DYViewerToolRequested" object:manager userInfo:@{@"type":type}];}); @@ -102,7 +106,9 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) { NSData *bytes=[NSData dataWithBytes:uniforms length:sizeof(*uniforms)];BOOL validate=NO; @synchronized(self){ if(!_invalidated){ + NSData *sameHistogram=CMTimeCompare(_snapshotTime,time)==0?[_snapshot[@"histogram"]retain]:nil; [_snapshot release];_snapshot=[@{@"uniforms":bytes,@"document":frozen,@"timeValue":@(time.value),@"timeScale":@(time.timescale),@"timeEpoch":@(time.epoch)}copy]; + if(sameHistogram){NSMutableDictionary *withHistogram=[[_snapshot mutableCopy]autorelease];withHistogram[@"histogram"]=sameHistogram;[_snapshot release];_snapshot=[withHistogram copy];[sameHistogram release];} [_sourceDocument release];_sourceDocument=[document retain];_snapshotTime=time; if(_requestedGesture&&!_validationScheduled){_validationScheduled=YES;validate=YES;} } @@ -218,7 +224,7 @@ static BOOL DYViewerSanitizeValue(NSDictionary *d,double input,double *output) { } }@finally{[a endAction:self];} // Re-read after DYToolManager commits its document at the outer boundary. - if(changed){NSData *actual=DYReadAssets(self->_writerTarget,self->_writerTime).spiderMesh;if(![actual isEqual:frozen])failed=YES;else{[self->_writerLastMesh release];self->_writerLastMesh=[frozen copy];[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self->_apiManager];}} + if(changed){[a startAction:self];NSData *actual=nil;@try{actual=[DYReadAssets(self->_writerTarget,self->_writerTime).spiderMesh retain];}@finally{[a endAction:self];}BOOL saved=[actual isEqual:frozen];[actual release];if(!saved)failed=YES;else{[self->_writerLastMesh release];self->_writerLastMesh=[frozen copy];[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self->_apiManager];}} if(failed)[self closeWriter]; });[frozen release]; } diff --git a/大鱼调色/Plugin/DYViewerParameterProbe.h b/大鱼调色/Plugin/DYViewerParameterProbe.h index 516a287..1442b63 100644 --- a/大鱼调色/Plugin/DYViewerParameterProbe.h +++ b/大鱼调色/Plugin/DYViewerParameterProbe.h @@ -7,6 +7,10 @@ - (void)changeValue:(double)value; - (void)beginParameters:(NSArray*)descriptors node:(NSString*)nodeID values:(NSDictionary*)values atTime:(CMTime)time; - (void)changeValues:(NSDictionary*)values; +- (void)publishAssets:(DYAssetState*)assets histogram:(NSData*)histogram atTime:(CMTime)time; +- (void)publishHistogram:(NSData*)histogram atTime:(CMTime)time; +- (void)beginSpider:(NSData*)mesh node:(NSString*)node enabled:(double)enabled atTime:(CMTime)time; +- (void)changeSpider:(NSData*)mesh; - (void)endGesture; - (void)invalidate; @end