65 行
9.0 KiB
C
65 行
9.0 KiB
C
// Production render tests for the ordered chain and spatial privacy operator.
|
|
{
|
|
NSDictionary *v4=DYUnifiedColorDefaults();run.need(@"unified-v4-valid-and-distinct-from-v3",DYManagedColorValid(v4,nil)&&DYUnifiedColorState(v4)&&![v4 isEqual:DYPrimaryColorDefaults()]);
|
|
NSMutableDictionary *doc=DYMutablePlist(DYInitialToolDocument(nil));run.record(@"unified-default-output-is-last",[DYUnifiedRenderOrder(doc).lastObject isEqual:@"output"]);
|
|
NSDictionary *node=DYInsertTool(doc,@"curve",@"base:hsl");doc[@"outputAfter"]=node[@"id"];
|
|
NSArray *order=DYUnifiedRenderOrder(doc);run.record(@"unified-output-follows-stable-uuid",[order indexOfObject:@"output"]==[order indexOfObject:node[@"id"]]+1&&DYValidToolDocument(doc));
|
|
DYRemoveTool(doc,node[@"id"]);run.record(@"unified-deleting-anchor-keeps-valid-output-order",DYValidToolDocument(doc)&&[doc[@"outputAfter"]isEqual:@"base:hsl"]);
|
|
doc[@"outputAfter"]=@"unknown";run.record(@"unified-rejects-unknown-output-anchor",!DYValidToolDocument(doc));doc=DYMutablePlist(DYInitialToolDocument(nil));
|
|
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];
|
|
auto decode=[](float x){return x<=.04045f?x/12.92f:powf((x+.055f)/1.055f,2.4f);};
|
|
Pixels chart(w*h*4);for(NSUInteger i=0;i<w*h;i++){chart[i*4]=decode(-.04f);chart[i*4+1]=decode(.18f+(i%w)/100.f);chart[i*4+2]=decode(4.f);chart[i*4+3]=1;}
|
|
[[src metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h)mipmapLevel:0 withBytes:chart.data()bytesPerRow:w*8];
|
|
DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease];DYUniforms u=defaults;u.skinProtection.x=0;u.cm.configured=1;u.cm.inputTransfer=u.cm.workingTransfer=u.cm.outputTransfer=20;u.cm.inputGamut=u.cm.workingGamut=u.cm.outputGamut=22;u.cm.toneMapping=0;
|
|
auto frame=[&](DYUniforms values,NSDictionary *document,NSString *name){NSError *e=nil;BOOL ok=[renderer renderSource:src destination:dst uniforms:values paths:@{} spider:nil tools:document colorManagement:v4 hostPrimaries:kFxColorPrimaries_Rec709 error:&e];run.need(name,ok,@{@"error":reason(e)});return read(dst,gpu);};
|
|
Pixels plain=frame(u,doc,@"unified-neutral-wide-chain-renders");run.record(@"unified-neutral-preserves-negative-and-superwhite",fabs((float)plain[0]+.04)<.002&&fabs((float)plain[2]-4)<.01&&difference(plain,plain).nonfinite==0);
|
|
DYUniforms exposure=u;exposure.exposure=1;Pixels raised=frame(exposure,doc,@"unified-scene-exposure");run.record(@"unified-scene-exposure-doubles-negative-and-superwhite",fabs((float)raised[0]+.08)<.003&&fabs((float)raised[2]-8)<.03,@{@"red":@((float)raised[0]),@"blue":@((float)raised[2])});
|
|
DYUniforms changed=u;changed.hslHueA.x=20;changed.hslHueB.x=20;Pixels modified=frame(changed,doc,@"unified-HSL-before-output-accepts-linear-domain");run.record(@"unified-active-bounded-tool-carries-superwhite-residual",modified[2]>2.9&&difference(plain,modified).nonfinite==0);
|
|
NSMutableDictionary *zero=DYMutablePlist(DYNewMask(DYMaskRectangle));DYMaskParameters p=DYMaskAtTime(zero,kCMTimeZero);p.strength=0;zero[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];doc[@"baseMasks"][@"hsl"]=@[zero];
|
|
Pixels masked=frame(changed,doc,@"unified-zero-mask");run.record(@"unified-zero-mask-is-exact-neutral",difference(masked,plain).maximum==0);[doc[@"baseMasks"]removeObjectForKey:@"hsl"];
|
|
changed.cm.outputTransfer=1002;changed.cm.toneMapping=1;changed.hslSatA.x=40;Pixels last=frame(changed,doc,@"unified-last-output");doc[@"outputAfter"]=@"base:primary";Pixels middle=frame(changed,doc,@"unified-middle-output");run.record(@"unified-moving-output-changes-actual-domain-order",difference(last,middle).maximum>.001,@{@"difference":@(difference(last,middle).maximum)});
|
|
{
|
|
Pixels patch(w*h*4);
|
|
for(size_t i=0;i<patch.size();i+=4){patch[i]=decode(.08f);patch[i+1]=decode(.045f);patch[i+2]=decode(.022f);patch[i+3]=1;}
|
|
[[src metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h)mipmapLevel:0 withBytes:patch.data()bytesPerRow:w*8];
|
|
NSMutableDictionary *keyDoc=DYMutablePlist(DYInitialToolDocument(nil));
|
|
DYUniforms exposed=u;exposed.exposure=3;
|
|
DYUniforms hue=exposed;hue.hslHueA=hue.hslHueB=(DYFloat4){48,48,48,48};
|
|
Pixels withoutHSL=frame(exposed,keyDoc,@"unified-luma-key-input-reference");
|
|
Pixels unmaskedHSL=frame(hue,keyDoc,@"unified-luma-key-graded-reference");
|
|
NSMutableDictionary *key=DYMutablePlist(DYNewMask(DYMaskLumaKey));
|
|
DYMaskParameters parameters=DYMaskAtTime(key,kCMTimeZero);parameters.inputBlack=.33f;parameters.inputWhite=.53f;
|
|
parameters.sourceStage=DYMaskSourceOriginal;
|
|
key[@"parameters"]=[NSData dataWithBytes:¶meters length:sizeof(parameters)];
|
|
keyDoc[@"baseMasks"][@"hsl"]=@[key];
|
|
Pixels originalKey=frame(hue,keyDoc,@"unified-luma-key-original-render");
|
|
parameters.sourceStage=DYMaskSourceLayerInput;
|
|
key[@"parameters"]=[NSData dataWithBytes:¶meters length:sizeof(parameters)];
|
|
Pixels layerKey=frame(hue,keyDoc,@"unified-luma-key-layer-render");
|
|
run.record(@"unified-mask-key-source-selects-original-or-current-color",
|
|
difference(withoutHSL,unmaskedHSL).maximum>.001&&
|
|
difference(originalKey,withoutHSL).maximum==0&&difference(layerKey,unmaskedHSL).maximum==0);
|
|
}
|
|
DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil);DYAssetState *assets=[[[DYAssetState alloc]init]autorelease];assets.colorManagement=v4;DYWriteAssets(host,assets,kCMTimeZero);
|
|
DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host]autorelease];[view refresh];[view setFrameSize:NSMakeSize(400,400)];[view layoutSubtreeIfNeeded];NSDictionary *output=nil;for(NSDictionary *card in [view valueForKey:@"cards"])if([card[@"section"][@"key"]isEqual:@"output"])output=card;
|
|
run.record(@"unified-inspector-output-visible-at-chain-tail",output&&![output[@"view"]isHidden]&&NSMaxY([output[@"view"]frame])>NSMaxY([[[view valueForKey:@"cards"]firstObject][@"view"]frame]));
|
|
[(NSButton*)output[@"repeatButton"]performClick:nil];run.record(@"unified-output-arrow-persists-and-creates-one-undo",[DYReadTools(host,kCMTimeZero).document[@"outputAfter"]isEqual:@"base:film"]&&host->_undoStarts==1&&host->_undoEnds==1);
|
|
}
|
|
{
|
|
const NSUInteger w=128,h=96;DYDiagnosticTile *src=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease],*dst=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels chart(w*h*4);
|
|
for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++){NSUInteger i=(y*w+x)*4;chart[i]=x/double(w);chart[i+1]=y/double(h);chart[i+2]=(x%2)*.4;chart[i+3]=1;}
|
|
[[src metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h)mipmapLevel:0 withBytes:chart.data()bytesPerRow:w*8];
|
|
DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease];DYUniforms u=defaults;u.primarySectionEnabled=0;u.skinProtection.x=0;
|
|
NSMutableDictionary *doc=DYMutablePlist(DYInitialToolDocument(nil));NSMutableDictionary *mask=(id)DYAddSharedMask(doc,DYMaskRectangle);DYMaskParameters p=DYMaskAtTime(mask,kCMTimeZero);p.width=p.height=.4;p.centerX=.25;p.centerY=.5;p.feather=0;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];
|
|
doc[@"mosaic"]=@{@"source":@"mask",@"maskID":mask[@"id"],@"enabled":@YES,@"size":@96};NSError *e=nil;
|
|
auto frame=[&](NSDictionary *document,NSString *name){BOOL ok=[renderer renderSource:src destination:dst uniforms:u paths:@{} spider:nil tools:document colorManagement:nil hostPrimaries:kFxColorPrimaries_Rec709 error:&e];run.need(name,ok,@{@"error":reason(e)});return read(dst,gpu);};
|
|
Pixels baseline=frame(DYInitialToolDocument(nil),@"mosaic-baseline");Pixels first=frame(DYToolRenderSnapshot(doc,kCMTimeZero),@"mosaic-shared-rectangle-render");
|
|
double inside=0,outside=0;for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++)for(int c=0;c<3;c++){double delta=fabs((float)first[(y*w+x)*4+c]-(float)baseline[(y*w+x)*4+c]);if(x>15&&x<48&&y>35&&y<60)inside=MAX(inside,delta);if(x>75)outside=MAX(outside,delta);}
|
|
run.record(@"mosaic-changes-selection-and-preserves-outside",inside>.05&&outside==0,@{@"inside":@(inside),@"outside":@(outside)});
|
|
DYMaskParameters moved=p;moved.centerX=.75;mask[@"keys"]=@[DYMaskKey(kCMTimeZero,p,YES,1),DYMaskKey(CMTimeMake(1,1),moved,YES,1)];
|
|
Pixels tracked=frame(DYToolRenderSnapshot(doc,CMTimeMake(1,1)),@"mosaic-follow-existing-tracking");run.record(@"mosaic-tracked-selection-vacates-previous-region",tracked[(48*w+31)*4+2]==baseline[(48*w+31)*4+2]&&tracked[(48*w+95)*4+2]!=baseline[(48*w+95)*4+2]);
|
|
doc[@"mosaic"]=@{@"source":@"mask",@"maskID":NSUUID.UUID.UUIDString,@"enabled":@YES,@"size":@96};Pixels missing=frame(DYToolRenderSnapshot(doc,kCMTimeZero),@"mosaic-missing-mask");run.record(@"mosaic-missing-mask-does-not-cover-whole-frame",difference(missing,baseline).maximum==0);
|
|
NSURL *cube=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"mosaic-refused.cube"]];run.record(@"mosaic-refuses-incomplete-cube-export",![renderer exportLUT:cube uniforms:u paths:@{} spider:nil tools:doc colorManagement:nil error:&e]&&e);
|
|
NSMutableDictionary *bad=DYMutablePlist(doc);bad[@"mosaic"][@"size"]=@0;run.record(@"mosaic-invalid-block-size-rejected",!DYValidToolDocument(bad));
|
|
}
|