{ 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==14&&DYToolIsNeutral(DYNewTool(@"film"))&&DYToolIsNeutral(DYNewTool(@"mixer"))); BOOL alpha=YES;for(size_t i=0;i50&&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;i20&&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;y50); 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 printFrames;BOOL printFramesDistinct=YES; DYUniforms printValue=neutral;printValue.film.enabled=1;printValue.filmPrint.y=1; for(NSUInteger index=0;index 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;pixel20&&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 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