79 行
13 KiB
C++
79 行
13 KiB
C++
{
|
|
DYToolDocument *empty=[[[DYToolDocument alloc]init]autorelease];
|
|
auto uploadFilm=[&](const Pixels& pixels){[[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:width*8];};
|
|
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==15&&DYToolIsNeutral(DYNewTool(@"lens"))&&DYToolIsNeutral(DYNewTool(@"film"))&&DYToolIsNeutral(DYNewTool(@"mixer")));
|
|
BOOL alpha=YES;for(size_t i=0;i<before.size()/4;i++)alpha&=before[i*4+3]==input[i*4+3];run.record(@"new-neutral-tools-preserve-existing-alpha",alpha);
|
|
DYUniforms matrix=neutral;matrix.mixerRed=(DYFloat4){.8,.25,-.05,0};matrix.mixerBlue=(DYFloat4){.1,0,.9,0};
|
|
Pixels mixed=filmRender(matrix,nil,@"channel-mixer-production-render");auto delta=difference(before,mixed);run.record(@"channel-mixer-affects-real-frame",delta.different>50&&delta.nonfinite==0,measure(delta));
|
|
matrix.mixerSectionEnabled=0;Pixels bypass=filmRender(matrix,nil,@"channel-mixer-eye-bypass-render");run.record(@"channel-mixer-eye-exact-bypass",difference(before,bypass).maximum==0);
|
|
matrix.mixerSectionEnabled=1;matrix.mixerMix=0;bypass=filmRender(matrix,nil,@"channel-mixer-zero-render");run.record(@"channel-mixer-zero-exact-bypass",difference(before,bypass).maximum==0);
|
|
for(int stage=0;stage<5;stage++){
|
|
DYUniforms value=neutral;value.film.enabled=1;
|
|
if(stage==0){value.film.subtractiveEnabled=1;value.film.gammaCyan=1.4;value.film.gammaYellow=.8;value.film.density=.35;}
|
|
if(stage==1){value.film.halationEnabled=1;value.film.scatter=4;value.film.boost=2;value.film.dyeTransmission=60;}
|
|
if(stage==2){value.film.bloomEnabled=1;value.film.sensitivity=1;value.film.diffusion=3;value.film.intensity=75;}
|
|
if(stage==3){value.film.grainEnabled=1;value.film.grainAmount=.7;value.film.grainColor=.35;value.film.grainSize=3;value.filmFrameKey=7;}
|
|
if(stage==4){value.film.vignetteEnabled=1;value.film.vignetteIntensity=1;value.film.vignetteRadius=15;}
|
|
Pixels after=filmRender(value,nil,[NSString stringWithFormat:@"film-stage-%d-production",stage]);Difference change=difference(before,after);BOOL sameAlpha=YES;for(size_t i=0;i<after.size()/4;i++)sameAlpha&=after[i*4+3]==before[i*4+3];run.record([NSString stringWithFormat:@"film-stage-%d-finite-active-alpha",stage],change.different>20&&change.nonfinite==0&&sameAlpha,measure(change));
|
|
if(stage==3){Pixels repeat=filmRender(value,nil,@"grain-random-access-repeat");run.record(@"grain-identical-frozen-frame-is-bit-exact",difference(after,repeat).maximum==0);value.filmFrameKey=8;Pixels next=filmRender(value,nil,@"grain-next-frozen-frame");run.record(@"grain-frame-changes-noise",difference(after,next).different>100);}
|
|
value.film.mix=0;bypass=filmRender(value,nil,[NSString stringWithFormat:@"film-stage-%d-zero-mix",stage]);run.record([NSString stringWithFormat:@"film-stage-%d-zero-is-exact",stage],difference(before,bypass).maximum==0);
|
|
value.film.mix=1;value.film.enabled=0;bypass=filmRender(value,nil,[NSString stringWithFormat:@"film-stage-%d-eye-off",stage]);run.record([NSString stringWithFormat:@"film-stage-%d-eye-preserves-old-frame",stage],difference(before,bypass).maximum==0);
|
|
}
|
|
DYUniforms originGrain=neutral;originGrain.film.enabled=1;originGrain.film.grainEnabled=1;originGrain.film.grainAmount=.7;originGrain.filmFrameKey=31;
|
|
Pixels topGrain=filmRender(originGrain,nil,@"grain-top-origin-render"),bottomInput(input.size());for(NSUInteger y=0;y<height;y++)memcpy(bottomInput.data()+y*width*4,input.data()+(height-1-y)*width*4,width*8);uploadFilm(bottomInput);[source setDiagnosticImageOrigin:kFxImageOrigin_BOTTOM_LEFT];Pixels bottomGrain=filmRender(originGrain,nil,@"grain-bottom-origin-render");run.record(@"grain-canonical-coordinates-survive-texture-origin",difference(topGrain,bottomGrain).maximum==0,measure(difference(topGrain,bottomGrain)));[source setDiagnosticImageOrigin:kFxImageOrigin_TOP_LEFT];uploadFilm(input);
|
|
CMTime duration=CMTimeMake(1001,30000),origin=CMTimeMake(17,3);BOOL rational=YES;
|
|
for(int i=-12;i<=12;i++){CMTime t=CMTimeAdd(origin,CMTimeMultiply(duration,i));rational&=DYFilmFrameIndex(t,duration,origin)==i;for(int hold=1;hold<=5;hold++)rational&=DYFilmFrameKey(i,hold,0)==(uint32_t)(int64_t)floor(double(i)/hold);}
|
|
rational&=DYFilmFrameIndex(CMTimeMake(-1,1000000),duration,kCMTimeZero)==-1;
|
|
run.record(@"grain-exact-ntsc-signed-frame-and-hold",rational);
|
|
NSMutableDictionary *doc=DYMutablePlist(empty.document);NSMutableDictionary *mixer=(id)DYInsertTool(doc,@"mixer",@"base:mixer");mixer[@"values"][@"mixer01"]=@.3;
|
|
NSMutableDictionary *film=(id)DYInsertTool(doc,@"film",mixer[@"id"]);film[@"values"][@"filmSubtractive"]=@1;film[@"values"][@"filmGammaCyan"]=@1.5;
|
|
run.record(@"film-mixer-adjacent-schema-two-valid",DYValidToolDocument(doc)&&[[DYToolDisplayOrder(doc) objectAtIndex:13]isEqual:mixer[@"id"]]&&[[DYToolDisplayOrder(doc)objectAtIndex:14]isEqual:film[@"id"]]);
|
|
Pixels layered=filmRender(neutral,doc,@"film-mixer-adjacent-render");run.record(@"film-mixer-adjacent-layers-affect-frame",difference(before,layered).different>50);
|
|
NSMutableDictionary *mask=DYMutablePlist(DYNewMask(DYMaskRectangle));DYMaskParameters p=DYMaskAtTime(mask,kCMTimeZero);p.strength=0;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];[mixer[@"masks"]addObject:mask];[film[@"masks"]addObject:DYMutablePlist(DYNewMask(DYMaskEllipse))];
|
|
DYToolDocument *saved=[[[DYToolDocument alloc]init]autorelease];saved.document=doc;NSData *archive=[NSKeyedArchiver archivedDataWithRootObject:saved requiringSecureCoding:YES error:&error];DYToolDocument *restored=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:archive error:&error];run.record(@"film-mixer-mask-archive-exact-roundtrip",[saved isEqual:restored]);
|
|
NSMutableDictionary *baseMask=DYMutablePlist(empty.document);baseMask[@"baseMasks"][@"film"]=@[mask];DYUniforms masked=neutral;masked.film.enabled=1;masked.film.grainEnabled=1;masked.film.grainAmount=.5;Pixels zeroMask=filmRender(masked,baseMask,@"film-zero-mask-render");run.record(@"film-zero-mask-exact-source",difference(before,zeroMask).maximum==0);
|
|
NSURL *cube=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"film-mixer.cube"]];error=nil;
|
|
BOOL rejected=![renderer exportLUT:cube uniforms:masked paths:@{} spider:nil tools:empty.document error:&error];run.record(@"grain-rejected-by-static-cube",rejected&&error!=nil);
|
|
masked.film.grainEnabled=0;masked.film.subtractiveEnabled=1;masked.film.gammaAll=1.1;error=nil;run.record(@"pure-subtractive-cube-supported",[renderer exportLUT:cube uniforms:masked paths:@{} spider:nil tools:empty.document error:&error],@{@"error":reason(error)});
|
|
masked=matrix;masked.mixerMix=1;error=nil;run.record(@"channel-mixer-cube-supported",[renderer exportLUT:cube uniforms:masked paths:@{} spider:nil tools:empty.document error:&error],@{@"error":reason(error)});
|
|
// Exercise the shipped print resources through the complete production path.
|
|
// The separate installed-reference oracle checks interpolation and color math.
|
|
NSArray *printNames=@[@"kodak_2383",@"kodak_2393",@"kodak_2302_bw",@"fuji_3510",@"fuji_3513",@"fuji_3519",@"fuji_3521",@"agfa_cp30"];
|
|
std::vector<Pixels> printFrames;BOOL printFramesDistinct=YES;
|
|
DYUniforms printValue=neutral;printValue.film.enabled=1;printValue.filmPrint.y=1;
|
|
for(NSUInteger index=0;index<printNames.count;index++){
|
|
NSString *resource=[[NSBundle bundleForClass:renderer.class]pathForResource:printNames[index] ofType:@"dylut" inDirectory:@"PrintLooks"];std::vector<float> table;NSUInteger side=0;error=nil;
|
|
BOOL resourceOK=resource&&DYLUTReadCube(resource,table,side,&error)&&side==65&&table.size()==65*65*65*4;
|
|
run.record([NSString stringWithFormat:@"print-%lu-shipped-65cube",(unsigned long)index+1],resourceOK,@{@"error":reason(error),@"side":@(side)});
|
|
printValue.filmPrint.x=index+1;Pixels printed=filmRender(printValue,nil,[NSString stringWithFormat:@"print-%lu-production-render",(unsigned long)index+1]);Difference change=difference(before,printed);BOOL sameAlpha=YES;
|
|
for(size_t pixel=0;pixel<printed.size()/4;pixel++)sameAlpha&=printed[pixel*4+3]==before[pixel*4+3];
|
|
run.record([NSString stringWithFormat:@"print-%lu-active-finite-preserves-alpha",(unsigned long)index+1],change.different>20&&change.nonfinite==0&&sameAlpha,measure(change));
|
|
for(const Pixels& previous:printFrames)printFramesDistinct&=difference(previous,printed).different>20;printFrames.push_back(printed);
|
|
}
|
|
run.record(@"all-eight-print-looks-have-distinct-production-output",printFramesDistinct);
|
|
printValue.filmPrint.y=0;bypass=filmRender(printValue,nil,@"print-zero-strength-render");run.record(@"print-zero-strength-exact-old-frame",difference(before,bypass).maximum==0);
|
|
printValue.filmPrint.y=1;printValue.film.mix=0;bypass=filmRender(printValue,nil,@"print-zero-film-mix-render");run.record(@"print-zero-film-mix-exact-old-frame",difference(before,bypass).maximum==0);
|
|
printValue.film.mix=1;printValue.film.enabled=0;bypass=filmRender(printValue,nil,@"print-eye-off-render");run.record(@"print-eye-off-exact-old-frame",difference(before,bypass).maximum==0);printValue.film.enabled=1;
|
|
DYUniforms freshPrint=DYToolUniforms(DYNewTool(@"film"));run.record(@"new-film-layer-print-default-is-none",freshPrint.filmPrint.x==0&&freshPrint.filmPrint.y==1&&DYToolIsNeutral(DYNewTool(@"film")));
|
|
NSMutableDictionary *printDoc=DYMutablePlist(empty.document),*printLayer=(id)DYInsertTool(printDoc,@"film",@"base:film");printLayer[@"values"][@"filmPrintLook"]=@2;
|
|
run.record(@"print-only-independent-layer-is-active",DYValidToolDocument(printDoc)&&!DYToolIsNeutral(printLayer)&&DYFilmPrintActive(DYToolUniforms(printLayer)));
|
|
Pixels printLayerFrame=filmRender(neutral,printDoc,@"print-only-independent-layer-render");run.record(@"print-only-independent-layer-affects-frame",difference(before,printLayerFrame).different>20);
|
|
NSMutableDictionary *secondPrintLayer=(id)DYInsertTool(printDoc,@"film",printLayer[@"id"]);secondPrintLayer[@"values"][@"filmPrintLook"]=@8;secondPrintLayer[@"values"][@"filmPrintStrength"]=@.4;
|
|
DYToolDocument *printSaved=[[[DYToolDocument alloc]init]autorelease];printSaved.document=printDoc;error=nil;NSData *printArchive=[NSKeyedArchiver archivedDataWithRootObject:printSaved requiringSecureCoding:YES error:&error];DYToolDocument *printRestored=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:printArchive error:&error];
|
|
DYUniforms firstRestored=DYToolUniforms(DYToolWithID(printRestored.document,printLayer[@"id"])),secondRestored=DYToolUniforms(DYToolWithID(printRestored.document,secondPrintLayer[@"id"]));
|
|
run.record(@"two-print-layers-archive-independent-choices-and-strength",[printSaved isEqual:printRestored]&&firstRestored.filmPrint.x==2&&firstRestored.filmPrint.y==1&&secondRestored.filmPrint.x==8&&secondRestored.filmPrint.y==.4f,@{@"error":reason(error)});
|
|
Pixels twoPrintLayers=filmRender(neutral,printRestored.document,@"two-print-layers-production-render");run.record(@"second-print-layer-is-rendered-independently",difference(printLayerFrame,twoPrintLayers).different>20);
|
|
Pixels printZeroMask=filmRender(printValue,baseMask,@"print-zero-mask-render");run.record(@"print-zero-mask-exact-source",difference(before,printZeroMask).maximum==0);
|
|
printValue.filmPrint.x=1;error=nil;BOOL printExported=[renderer exportLUT:cube uniforms:printValue paths:@{} spider:nil tools:empty.document error:&error];run.record(@"print-only-static-cube-supported",printExported,@{@"error":reason(error)});
|
|
std::vector<float> printCubeValues;NSUInteger printCubeSide=0;error=nil;BOOL printCubeParsed=printExported&&DYLUTReadCube(cube.path,printCubeValues,printCubeSide,&error)&&printCubeSide==33;
|
|
Pixels printCubeInput(input.size());float printCodes[3]={.5f,.25f,.75f};for(size_t pixel=0;pixel<printCubeInput.size()/4;pixel++){for(int channel=0;channel<3;channel++){float code=printCodes[channel];printCubeInput[pixel*4+channel]=code<=.04045f?code/12.92f:powf((code+.055f)/1.055f,2.4f);}printCubeInput[pixel*4+3]=1;}
|
|
uploadFilm(printCubeInput);Pixels printCubeRendered=filmRender(printValue,nil,@"print-cube-production-lattice-point");BOOL printCubeMatches=printCubeParsed&&printCubeValues.size()==33*33*33*4;
|
|
for(int channel=0;channel<3&&printCubeMatches;channel++){float code=printCubeValues[((24*33+8)*33+16)*4+channel],linear=code<=.04045f?code/12.92f:powf((code+.055f)/1.055f,2.4f);printCubeMatches&=fabs(linear-(float)printCubeRendered[channel])<.0005;}
|
|
run.record(@"print-static-cube-matches-production-lattice-point",printCubeMatches,@{@"side":@(printCubeSide),@"error":reason(error)});
|
|
printValue.film.grainEnabled=1;printValue.film.grainAmount=.5;error=nil;run.record(@"print-with-grain-still-rejected-by-static-cube",![renderer exportLUT:cube uniforms:printValue paths:@{} spider:nil tools:empty.document error:&error]&&error!=nil);
|
|
uploadFilm(input);
|
|
}
|