// 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)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=DYSpiderPlotPoint(plot,mesh.x[selected],mesh.y[selected]);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=DYSpiderPlotPoint(plot,mesh.x[selected],mesh.y[selected]);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]); [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)}); // Both FxPlug row conventions must resolve the same visual face. Pixels flipped(portrait.size());for(NSUInteger y=0;y.01&&layerBackground<.001); DYDiagnosticTile *twoSource=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:1024 height:512]autorelease],*twoDest=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:1024 height:512]autorelease];Pixels two(1024*512*4);for(NSUInteger y=0;y<512;y++)for(NSUInteger x=0;x<1024;x++)memcpy(two.data()+(y*1024+x)*4,portrait.data()+(y*512+x%512)*4,8);[[twoSource metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,1024,512)mipmapLevel:0 withBytes:two.data()bytesPerRow:1024*8];u.skinProtection.x=1;BOOL twoOK=[face renderSource:twoSource destination:twoDest uniforms:u paths:@{}error:&maskError];NSData *twoEntries=[face valueForKey:@"faceEntries"];const DYToolMaskEntry *twoMasks=(const DYToolMaskEntry*)twoEntries.bytes;NSInteger faceCount=0;for(NSUInteger i=0;i.05&&privateOutside==0,@{@"faceChange":@(privateInside),@"backgroundChange":@(privateOutside)}); // The same production menu writer turns two detected faces into independent, // serializable masks, then toggles only one while preserving the other pixels. privacy[@"mosaic"]=@{@"enabled":@YES,@"source":@"face",@"size":@64}; BOOL fastOK=[face renderSource:twoSource destination:twoDest uniforms:privacyU paths:@{} spider:nil tools:DYToolRenderSnapshot(privacy,kCMTimeZero) colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&maskError]; NSDictionary *detected=[face mosaicFaceSnapshot];Pixels bothFaces=read(twoDest,gpu); run.record(@"mosaic-fast-rectangles-detect-two-faces-without-landmarks",fastOK&&[detected[@"boxes"]count]==2,@{@"faces":@([detected[@"boxes"]count])}); if([detected[@"boxes"]count]==2){ DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,nil);DYWriteTools(base,privacy,kCMTimeZero); DYToolCanvasProbe *host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero; id bridge=[[NSClassFromString(@"DYViewerParameterBridge")alloc]initWithAPIManager:host];[bridge setValue:face forKey:@"renderer"]; NSMenuItem *item=[[[NSMenuItem alloc]init]autorelease];item.representedObject=@{@"importFaces":detected,@"actionTime":detected[@"time"]}; int undo=base->_undoStarts;[bridge performSelector:@selector(applyMosaicMenu:) withObject:item]; NSDictionary *saved=DYReadTools(host,kCMTimeZero).document;NSArray *IDs=saved[@"mosaic"][@"maskIDs"]; run.record(@"mosaic-import-faces-creates-two-stable-masks-in-one-undo",IDs.count==2&&DYSharedMasks(saved).count==2&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1); BOOL savedOK=[face renderSource:twoSource destination:twoDest uniforms:privacyU paths:@{} spider:nil tools:DYToolRenderSnapshot(saved,kCMTimeZero) colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&maskError]; run.record(@"mosaic-imported-selection-matches-live-two-face-render",savedOK&&difference(bothFaces,read(twoDest,gpu)).maximum<.002); if(IDs.count==2){ item.representedObject=@{@"toggleMask":IDs[1]};[bridge performSelector:@selector(applyMosaicMenu:) withObject:item];saved=DYReadTools(host,kCMTimeZero).document; [face renderSource:twoSource destination:twoDest uniforms:privacyU paths:@{} spider:nil tools:DYToolRenderSnapshot(saved,kCMTimeZero) colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&maskError];Pixels single=read(twoDest,gpu); privacy[@"mosaic"]=@{@"enabled":@NO,@"source":@"face",@"size":@64};[face renderSource:twoSource destination:twoDest uniforms:privacyU paths:@{} spider:nil tools:privacy colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&maskError];Pixels reference=read(twoDest,gpu); double left=0,right=0;for(NSUInteger y=0;y<512;y++)for(NSUInteger x=0;x<1024;x++)for(int c=0;c<3;c++){double delta=fabs((float)single[(y*1024+x)*4+c]-(float)reference[(y*1024+x)*4+c]);if(x<512)left=MAX(left,delta);else right=MAX(right,delta);} run.record(@"mosaic-selects-one-person-with-other-person-pixel-identical",left>.05&&right==0&&[saved[@"mosaic"][@"maskIDs"]count]==1,@{@"selectedChange":@(left),@"unselectedChange":@(right)}); NSData *archive=[NSKeyedArchiver archivedDataWithRootObject:DYReadTools(host,kCMTimeZero) requiringSecureCoding:YES error:nil];DYToolDocument *restored=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:archive error:nil];run.record(@"mosaic-person-selection-survives-secure-save-and-reopen",[restored.document isEqual:saved]); NSMutableDictionary *malformed=DYMutablePlist(saved);malformed[@"mosaic"][@"maskIDs"]=@[IDs[0],IDs[0]];run.record(@"mosaic-duplicate-mask-identities-rejected",!DYValidToolDocument(malformed)); } [bridge invalidate];[bridge release]; } Pixels noFace(w*h*4);for(NSUInteger i=0;i.01&&difference(warped,opposite).maximum>.01); u.lensStrength=0;doc[@"levelMeasureOnly"]=@YES; BOOL measured=[renderer renderSource:source destination:destination uniforms:u paths:@{} spider:nil tools:doc colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&failure]; run.record(@"level-measure-only-preserves-source-pixels",measured&&difference(read(destination,gpu),grid).maximum<.002); [doc removeObjectForKey:@"levelMeasureOnly"]; NSURL *cube=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"unsupported-level.cube"]]; run.record(@"level-spatial-transform-is-refused-by-cube-export",![renderer exportLUT:cube uniforms:u paths:@{} spider:nil tools:doc error:&failure]&&failure); } { DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,nil); DYToolCanvasProbe *host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero; id plugin=(id)[[NSClassFromString(@"DYPlugIn")alloc]initWithAPIManager:host]; [plugin scheduleToolCanvasRegistration]; NSData *state=nil;[plugin pluginState:&state atTime:kCMTimeZero quality:(FxQuality)0 error:&error]; auto drain=[](){double end=NSProcessInfo.processInfo.systemUptime+.07;while(NSProcessInfo.processInfo.systemUptime osc=(id)[[NSClassFromString(@"DYToolOSC")alloc]initWithAPIManager:host]; DYDiagnosticTile *overlay=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:640 height:400]autorelease]; [osc drawOSCWithWidth:640 height:400 activePart:0 destinationImage:overlay atTime:kCMTimeZero]; id viewer=[(id)osc valueForKey:@"viewerControls"]; BOOL update=NO; auto down=[&](double x,double y){ NSInteger part=0; [osc hitTestOSCAtMousePositionX:x mousePositionY:y activePart:&part atTime:kCMTimeZero]; [osc mouseDownAtPositionX:x positionY:y activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];return part; }; auto up=[&](double x,double y,NSInteger part){[osc mouseUpAtPositionX:x positionY:y activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero];}; auto click=[&](double x,double y){NSInteger part=down(x,y);up(x,y,part);}; auto control=[&](NSInteger part){ for(NSDictionary *a in [viewer valueForKey:@"areas"])if([a[@"part"]integerValue]==part){ NSRect r=[a[@"rect"]rectValue];click(NSMidX(r),400-NSMidY(r));break; } }; auto angle=[&](){return [DYReadTools(host,kCMTimeZero).document[@"levelRotation"] doubleValue];}; int undo=base->_undoStarts; control(20026); click(150,280);click(390,200);drain(); run.record(@"level-osc-two-points-horizontal-one-undo",fabs(angle()+atan2(80.,240.))<1e-6&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1); NSDictionary *savedLevel=[[DYReadTools(host,kCMTimeZero).document copy]autorelease]; run.record(@"level-placed-line-is-persisted-with-reference-points",[savedLevel[@"levelReference"][@"points"]count]==4&&[[(id)osc valueForKey:@"levelPlaced"]boolValue]); [osc drawOSCWithWidth:640 height:400 activePart:0 destinationImage:overlay atTime:kCMTimeZero]; NSPoint lineFirst=[[(id)osc valueForKey:@"levelFirst"]pointValue]; NSRect imageRect=[[(id)osc valueForKey:@"imageRect"]rectValue]; DYLevelTransform transform(angle(),NSWidth(imageRect)/NSHeight(imageRect));NSPoint display=transform.toOutput(lineFirst); double endpointX=NSMinX(imageRect)+display.x*NSWidth(imageRect),endpointY=400-NSMinY(imageRect)-display.y*NSHeight(imageRect); NSInteger endpoint=down(endpointX,endpointY);up(endpointX+6,endpointY+10,endpoint);drain(); run.record(@"level-retained-endpoint-edits-with-one-undo",endpoint==10016&&base->_undoStarts==undo+2&&base->_undoEnds==undo+2&&![DYReadTools(host,kCMTimeZero).document[@"levelReference"]isEqual:savedLevel[@"levelReference"]]); control(20034);drain(); run.record(@"level-measure-toggle-preserves-line-and-angle",[DYReadTools(host,kCMTimeZero).document[@"levelMeasureOnly"]boolValue]&&[DYReadTools(host,kCMTimeZero).document[@"levelReference"][@"points"]count]==4); control(20026);control(20026);drain(); run.record(@"level-reopening-restores-saved-line",[[(id)osc valueForKey:@"levelPlaced"]boolValue]); undo=base->_undoStarts-1; control(20033);drain(); control(20032); NSInteger part=down(200,270);up(230,150,part);drain(); run.record(@"level-osc-reset-and-vertical-drag-each-create-one-undo",fabs(angle()-(M_PI_2-atan2(120.,30.)))<1e-6&&base->_undoStarts==undo+3&&base->_undoEnds==undo+3); double previous=angle(); click(180,200); BOOL handled=NO; [osc keyDownAtPositionX:250 positionY:225 keyPressed:27 modifiers:0 forceUpdate:&update didHandle:&handled atTime:kCMTimeZero];drain(); run.record(@"level-osc-escape-discards-uncommitted-point",handled&&angle()==previous&&base->_undoStarts==undo+3); [osc release];[plugin release];drain(); } { for(NSString *starter in [DYToolTypes()arrayByAddingObject:@"cst"]){ DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil); NSDictionary *doc=DYInitialToolDocument(starter);BOOL valid=DYValidToolDocument(doc)&&DYWriteTools(host,doc,kCMTimeZero); DYInspector *inspector=[[[DYInspector alloc]initWithAPIManager:host]autorelease];[inspector refresh]; NSString *expected=[starter isEqual:@"cst"]?@"primary":starter; NSUInteger visible=0;BOOL match=NO,cstFields=YES; for(NSDictionary *card in [inspector valueForKey:@"cards"])if(![card[@"removed"]boolValue]){visible++;match=[card[@"section"][@"key"]isEqual:expected];if([starter isEqual:@"cst"]){cstFields=[card[@"section"][@"title"]isEqual:@"CST 色彩空间转换"];for(NSDictionary *row in card[@"section"][@"rows"])cstFields&=![row[@"key"]isEqual:@"cmexposure"]&&![row[@"key"]isEqual:@"primaryBalance"];}} NSMutableDictionary *expanded=DYMutablePlist(doc);BOOL add=DYInsertTool(expanded,@"curve",[@"base:" stringByAppendingString:expected])!=nil; run.record([@"standalone-initial-module-and-add-layer-" stringByAppendingString:starter],valid&&visible==1&&match&&cstFields&&add&&DYValidToolDocument(expanded)); } }