51 行
16 KiB
C++
51 行
16 KiB
C++
// Regression for the user's failure case: scene grading precedes the main ODT.
|
|
{
|
|
DYRenderer *primaryRenderer=[[[DYRenderer alloc]init]autorelease];NSDictionary *v3=DYPrimaryColorDefaults();DYToolDocument *empty=[[[DYToolDocument alloc]init]autorelease];
|
|
run.need(@"primary-v3-independent-state-valid",DYManagedColorValid(v3,nil)&&DYPrimaryColorState(v3));NSMutableDictionary *bad=DYMutablePlist(v3);bad[@"input"]=@109;run.record(@"primary-v3-rejects-conflicting-global-input",!DYManagedColorValid(bad,nil));
|
|
DYAssetState *saved=[[[DYAssetState alloc]init]autorelease];saved.colorManagement=v3;NSData *encoded=[NSKeyedArchiver archivedDataWithRootObject:saved requiringSecureCoding:YES error:&error];DYAssetState *decoded=[NSKeyedUnarchiver unarchivedObjectOfClass:DYAssetState.class fromData:encoded error:&error];run.record(@"primary-v3-secure-state-roundtrip",[saved isEqual:decoded]);
|
|
DYUniforms u=defaults;u.skinProtection.x=0;u.cm.configured=1;u.cm.inputTransfer=28;u.cm.inputGamut=27;u.cm.workingTransfer=10;u.cm.workingGamut=16;u.cm.outputTransfer=1002;u.cm.outputGamut=22;u.cm.toneMapping=1;
|
|
auto decodeCarrier=[](float x){return x<=.04045f?x/12.92f:powf((x+.055f)/1.055f,2.4f);};auto encodeCarrier=[](float x){return x<=.0031308f?12.92f*x:1.055f*powf(x,1/2.4f)-.055f;};
|
|
std::vector<DYCompositeRGBA>scene(width*height);float levels[]={.002f,.018f,.18f,1,4,16,32,64};for(size_t i=0;i<scene.size();i++){float v=levels[i%8],alpha=i%5?.5f:1;scene[i]={v*alpha,v*(i%3?.9f:1)*alpha,v*(i%3?.6f:1)*alpha,alpha};}
|
|
auto sceneInput=[&](std::vector<DYCompositeRGBA> pixels){dycm::Transform::convert(dycm::Space::ACEScg,dycm::Space::SonySLog3Cine).apply(pixels,dycm::Alpha::Premultiplied);Pixels out(pixels.size()*4);for(size_t i=0;i<pixels.size();i++){float a=pixels[i].a;out[i*4]=decodeCarrier(pixels[i].r/a)*a;out[i*4+1]=decodeCarrier(pixels[i].g/a)*a;out[i*4+2]=decodeCarrier(pixels[i].b/a)*a;out[i*4+3]=a;}return out;};
|
|
Pixels logInput=sceneInput(scene);auto upload=[&](const Pixels&p){[[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:p.data() bytesPerRow:width*8];};upload(logInput);
|
|
auto renderPrimary=[&](DYUniforms values,NSDictionary *doc,NSString *name){NSError *e=nil;BOOL ok=[primaryRenderer renderSource:source destination:destination uniforms:values paths:@{} spider:nil tools:doc colorManagement:v3 hostPrimaries:kFxColorPrimaries_Rec709 error:&e];run.need(name,ok,@{@"error":reason(e)});return read(destination,gpu);};
|
|
auto inputReference=[&](dycm::Space target){std::vector<DYCompositeRGBA>r(scene.size());for(size_t i=0;i<r.size();i++){float a=logInput[i*4+3];r[i]={encodeCarrier((float)logInput[i*4]/a)*a,encodeCarrier((float)logInput[i*4+1]/a)*a,encodeCarrier((float)logInput[i*4+2]/a)*a,a};}dycm::Transform::convert(dycm::Space::SonySLog3Cine,target).apply(r,dycm::Alpha::Premultiplied);return r;};
|
|
auto carrierReference=[&](const std::vector<DYCompositeRGBA>&r){Pixels p(r.size()*4);for(size_t i=0;i<r.size();i++){float a=r[i].a;p[i*4]=decodeCarrier(r[i].r/a)*a;p[i*4+1]=decodeCarrier(r[i].g/a)*a;p[i*4+2]=decodeCarrier(r[i].b/a)*a;p[i*4+3]=a;}return p;};
|
|
Pixels baseline=renderPrimary(u,empty.document,@"primary-main-input-grade-output-render");
|
|
// No main output: independently compare the working code values against OCIO.
|
|
DYUniforms data=u;data.cm.outputEnabled=0;data.cm.toneMapping=0;Pixels intermediate=renderPrimary(data,empty.document,@"primary-DWG-intermediate-without-display-output");Difference di=difference(intermediate,carrierReference(inputReference(dycm::Space::DaVinciIntermediate)));run.record(@"primary-input-goes-directly-to-DWG-DI-not-709",di.maximum<.003&&di.nonfinite==0,measure(di));
|
|
data.cm.workingTransfer=1;data.cm.workingGamut=2;Pixels cct=renderPrimary(data,empty.document,@"primary-ACEScct-without-display-output");Difference aces=difference(cct,carrierReference(inputReference(dycm::Space::ACEScct)));run.record(@"primary-ACEScct-is-selectable-not-forced",aces.maximum<.003&&aces.nonfinite==0,measure(aces));
|
|
DYUniforms changed=u;changed.cm.inputTransfer=4;changed.cm.inputGamut=4;Pixels arri=renderPrimary(changed,empty.document,@"primary-input-selection-ARRI");run.record(@"primary-input-selection-is-effective",difference(baseline,arri).maximum>.05);
|
|
// Neutral additional layers are exact bypasses, with no second display map.
|
|
NSMutableDictionary *doc=DYMutablePlist(empty.document);for(int i=0;i<4;i++)DYSeedPrimaryWorkingSpace((id)DYInsertTool(doc,@"primary",@"base:primary"),10,16);Pixels neutral=renderPrimary(u,doc,@"primary-four-inherited-neutral-layers");run.record(@"primary-new-layer-inherits-workspace-no-remap",difference(baseline,neutral).maximum==0);
|
|
// Move the entire exposure correction into an independent layer. The result
|
|
// must be the same as correcting the root before its one final display map.
|
|
NSMutableDictionary *one=DYMutablePlist(empty.document),*node=(id)DYInsertTool(one,@"primary",@"base:primary");DYSeedPrimaryWorkingSpace(node,10,16);node[@"values"][@"cmexposure"]=@(-4);DYUniforms reduced=u;reduced.cm.exposure=-4;Pixels beforeOutput=renderPrimary(reduced,empty.document,@"primary-four-stop-root-before-output"),extra=renderPrimary(u,one,@"primary-four-stop-extra-before-output");Difference order=difference(beforeOutput,extra);run.record(@"primary-independent-grade-before-main-output",order.maximum<.002&&order.nonfinite==0,measure(order));
|
|
auto reducedScene=scene;for(auto &p:reducedScene){p.r/=16;p.g/=16;p.b/=16;}Pixels reducedInput=sceneInput(reducedScene);upload(reducedInput);Pixels knownReduced=renderPrimary(u,empty.document,@"primary-independent-OCIO-reduced-scene-input");Difference high=difference(beforeOutput,knownReduced);run.record(@"primary-highlights-recovered-before-mapping-reference",high.maximum<.008&&high.nonfinite==0,@{@"maxDifference":@(high.maximum),@"scene64afterMinus4":@((float)beforeOutput[7*4]),@"independentReference":@((float)knownReduced[7*4])});upload(logInput);
|
|
NSMutableArray *patches=[NSMutableArray array];for(int k=0;k<8;k++){size_t i=k*5;float a=logInput[i*4+3];[patches addObject:@{@"index":@(i),@"code":@[@(encodeCarrier((float)logInput[i*4]/a)),@(encodeCarrier((float)logInput[i*4+1]/a)),@(encodeCarrier((float)logInput[i*4+2]/a))],@"expectedMinus4Linear709":@[@((float)beforeOutput[i*4]/a),@((float)beforeOutput[i*4+1]/a),@((float)beforeOutput[i*4+2]/a)]}];}NSData *fixture=[NSJSONSerialization dataWithJSONObject:@{@"patches":patches,@"input":@"Sony S-Log3 / S-Gamut3.Cine code carrier",@"exposure":@(-4)} options:NSJSONWritingPrettyPrinted error:nil];[fixture writeToFile:[runtime stringByAppendingPathComponent:@"primary-host-chart.json"] atomically:YES];
|
|
// Local working curves are read from the node, including BASIS adapters.
|
|
node[@"values"][@"cmexposure"]=@0;node[@"values"][@"cmcontrast"]=@.3;Pixels localDI=renderPrimary(u,one,@"primary-local-DI-contrast");node[@"values"][@"cmworkingTransfer"]=@1;node[@"values"][@"cmworkingGamut"]=@2;Pixels localACES=renderPrimary(u,one,@"primary-local-ACES-contrast");run.record(@"primary-local-working-selection-is-effective",difference(localDI,localACES).maximum>.001);
|
|
node[@"values"][@"cminputTransfer"]=@1;node[@"values"][@"cminputGamut"]=@2;Pixels reinterpret=renderPrimary(u,one,@"primary-local-input-CST-selection");run.record(@"primary-local-input-CST-is-not-overridden",difference(reinterpret,localACES).maximum>.01);
|
|
// Zero masks and zero mix bypass grade while retaining global input/output.
|
|
NSMutableDictionary *mask=DYMutablePlist(DYNewMask(DYMaskRectangle)),*masked=DYMutablePlist(empty.document);DYMaskParameters mp=DYMaskAtTime(mask,kCMTimeZero);mp.strength=0;mask[@"parameters"]=[NSData dataWithBytes:&mp length:sizeof(mp)];masked[@"baseMasks"][@"primary"]=@[mask];Pixels zero=renderPrimary(reduced,masked,@"primary-zero-mask");reduced.cm.mix=0;Pixels zeroMix=renderPrimary(reduced,empty.document,@"primary-zero-grade-mix");run.record(@"primary-zero-mask-and-mix-retain-CST-boundaries",difference(zero,baseline).maximum==0&&difference(zeroMix,baseline).maximum==0);
|
|
// A half-strength one-stop grade is 1.5x light, before mapping.
|
|
DYUniforms half=u;half.cm.exposure=1;half.cm.mix=.5;Pixels halfFrame=renderPrimary(half,empty.document,@"primary-linear-light-half-mix");half.cm.exposure=log2f(1.5f);half.cm.mix=1;Pixels halfReference=renderPrimary(half,empty.document,@"primary-linear-light-mix-reference");run.record(@"primary-mix-in-linear-AP1",difference(halfFrame,halfReference).maximum<.003,measure(difference(halfFrame,halfReference)));
|
|
// Print looks cross into their real ACEScct domain, then return to the chosen
|
|
// working space. Neutral grade must not make the choice alter the print.
|
|
DYUniforms print=u;print.filmPrint.x=1;print.filmPrint.y=.6;Pixels printDI=renderPrimary(print,empty.document,@"primary-print-DWG-before-output");print.cm.workingTransfer=1;print.cm.workingGamut=2;Pixels printACES=renderPrimary(print,empty.document,@"primary-print-ACES-before-output");Difference printDelta=difference(printDI,printACES);run.record(@"primary-print-domain-adapts-to-selected-working-space",printDelta.maximum<.005&&difference(printDI,baseline).different>20,measure(printDelta));
|
|
// The output controls change data output, and the optional display map is last.
|
|
DYUniforms logOut=u;logOut.cm.outputTransfer=10;logOut.cm.outputGamut=16;logOut.cm.toneMapping=0;Pixels selectedOutput=renderPrimary(logOut,empty.document,@"primary-declared-Log-output");run.record(@"primary-declared-output-controls-restored",difference(intermediate,selectedOutput).maximum==0&&difference(selectedOutput,baseline).maximum>.05);
|
|
DYUniforms unmapped=u;unmapped.cm.toneMapping=0;Pixels noMap=renderPrimary(unmapped,empty.document,@"primary-no-output-tone-map");run.record(@"primary-tone-mapping-switch-restored",difference(noMap,baseline).maximum>.05);
|
|
DYUniforms invalid=data;invalid.hslHueA.x=20;NSError *e=nil;BOOL bounded=[primaryRenderer renderSource:source destination:destination uniforms:invalid paths:@{} spider:nil tools:empty.document colorManagement:v3 hostPrimaries:kFxColorPrimaries_Rec709 error:&e];run.record(@"primary-Log-data-output-rejects-SDR-finishing",!bounded&&e.localizedDescription.length>0);
|
|
DYUniforms bypass=u;bypass.primarySectionEnabled=0;bypass.hslHueA.x=20;Pixels bypassFrame=renderPrimary(bypass,empty.document,@"primary-main-eye-keeps-other-tools");Pixels oldBypass=render(run,primaryRenderer,source,destination,gpu,bypass,@{},@"primary-eye-unmanaged-reference");run.record(@"primary-main-eye-bypasses-whole-CST-retains-tools",difference(bypassFrame,oldBypass).maximum==0);
|
|
// Float domain crossings retain negative values, overrange and hidden RGB.
|
|
DYUniforms linear=u;linear.cm.inputTransfer=linear.cm.workingTransfer=linear.cm.outputTransfer=20;linear.cm.inputGamut=linear.cm.workingGamut=linear.cm.outputGamut=2;linear.cm.toneMapping=0;Pixels extended(width*height*4);for(size_t i=0;i<width*height;i++){float a=i%4?.25f:0;extended[i*4]=a?decodeCarrier(-.03f)*a:.07f;extended[i*4+1]=a?decodeCarrier(.18f)*a:-.02f;extended[i*4+2]=a?decodeCarrier(4.f)*a:.5f;extended[i*4+3]=a;}upload(extended);Pixels exact=renderPrimary(linear,empty.document,@"primary-negative-superwhite-hidden-RGB");run.record(@"primary-float-domain-identity-retains-extended-values",difference(extended,exact).maximum<.002&&difference(extended,exact).nonfinite==0,measure(difference(extended,exact)));linear.cm.exposure=1;Pixels doubled=renderPrimary(linear,empty.document,@"primary-linear-exposure-extended-values");BOOL photometric=YES;for(size_t i=1;i<width*height;i++)if(extended[i*4+3]>0){float a=extended[i*4+3];photometric&=fabs(encodeCarrier((float)doubled[i*4+1]/a)-.36f)<.002&&fabs(encodeCarrier((float)doubled[i*4]/a)+.06f)<.002;}run.record(@"primary-one-stop-exposure-is-linear-light-with-negative-values",photometric,@{@"negative":@(encodeCarrier((float)doubled[4]/.25f)),@"grey":@(encodeCarrier((float)doubled[5]/.25f))});upload(logInput);
|
|
DYUniforms idle=logOut;idle.texture=25;idle.textureEnabled=0;idle.postLUTStrength=0;idle.extraPostLUTStrengths[0]=.8;idle.extraLookSectionEnableds[0]=0;e=nil;BOOL idleOK=[primaryRenderer renderSource:source destination:destination uniforms:idle paths:@{@"look0":@"/nonexistent/disabled.cube",@"look1":@"/nonexistent/disabled2.cube"} spider:nil tools:empty.document colorManagement:v3 hostPrimaries:kFxColorPrimaries_Rec709 error:&e];run.record(@"primary-data-output-ignores-disabled-SDR-and-LUT-controls",idleOK&&difference(read(destination,gpu),selectedOutput).maximum==0,@{@"error":reason(e)});
|
|
// Actual inspector must expose all three sets of selectors in V3.
|
|
DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil);DYAssetState *assets=[[[DYAssetState alloc]init]autorelease];assets.colorManagement=v3;DYWriteAssets(host,assets,kCMTimeZero);DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host renderer:primaryRenderer]autorelease];[view refresh];[view setFrame:NSMakeRect(0,0,400,780)];[view layoutSubtreeIfNeeded];NSDictionary *tabs=[view valueForKey:@"tabs"];run.record(@"primary-inspector-no-v2-selector-override",![tabs[@"managedColor"]boolValue]&&[tabs[@"primaryCMS"]boolValue]);NSMenuItem *add=[[[NSMenuItem alloc]init]autorelease];add.representedObject=@"primary";[view addModule:add];NSDictionary *added=[DYReadTools(host,kCMTimeZero).document[@"layers"]lastObject];run.record(@"primary-inspector-add-layer-inherits-workspace",[added[@"values"][@"cminputTransfer"]isEqual:@10]&&[added[@"values"][@"cmoutputGamut"]isEqual:@16]&&[added[@"values"][@"cmtoneMapping"]isEqual:@0]);NSMutableDictionary *followed=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);DYFollowPrimaryWorkingSpace(followed,1,2);NSDictionary *following=[followed[@"layers"]lastObject];run.record(@"primary-workspace-change-updates-inherited-domains",[following[@"values"][@"cminputTransfer"]isEqual:@1]&&[following[@"values"][@"cmworkingGamut"]isEqual:@2]&&[following[@"values"][@"cmoutputTransfer"]isEqual:@1]);DYWriteTools(host,followed,kCMTimeZero);DYToolManager *local=[[[DYToolManager alloc]initWithHost:host node:following]autorelease];UInt32 workingID=0;for(NSDictionary*d in DYDescriptors())if([d[@"key"]isEqual:@"cmworkingTransfer"])workingID=[d[@"pid"]unsignedIntValue];id<FxCustomParameterActionAPI_v4>action=[local apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];[action startAction:nil];[(id<FxParameterSettingAPI_v6>)local setFloatValue:10 toParameter:workingID atTime:kCMTimeZero];[action endAction:nil];followed=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);DYFollowPrimaryWorkingSpace(followed,4,4);following=[followed[@"layers"]lastObject];run.record(@"primary-manual-local-space-retains-choice-and-follows-boundaries",[following[@"values"][@"cmworkingTransfer"]isEqual:@10]&&[following[@"values"][@"cminputTransfer"]isEqual:@4]&&[following[@"values"][@"cmoutputGamut"]isEqual:@4]&&[following[@"primaryFollow"]isEqual:@5]);NSDictionary *preset=[view presetSnapshot];run.record(@"primary-complete-preset-stores-v3-state",[preset[@"colorManagement"]isEqual:v3]&&[preset[@"version"]isEqual:@7]);
|
|
NSURL *cube=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"primary-v3.cube"]];e=nil;BOOL exported=[primaryRenderer exportLUT:cube uniforms:logOut paths:@{} spider:nil tools:empty.document colorManagement:v3 error:&e];std::vector<float>table;NSUInteger side=0;BOOL parsed=exported&&DYLUTReadCube(cube.path,table,side,&e);run.record(@"primary-v3-Cube65-declared-encoding",parsed&&side==65&&[[NSString stringWithContentsOfURL:cube encoding:NSUTF8StringEncoding error:nil]containsString:@"V3 input"],@{@"error":reason(e)});
|
|
// Cube output follows the selected encoding, independent of the monitor.
|
|
linear.cm.exposure=0;linear.cm.outputGamut=22;float gammaValues[2]={};BOOL gammaExports=YES;int gammaIDs[]={1001,1003};for(int j=0;j<2;j++){linear.cm.outputTransfer=gammaIDs[j];NSURL *target=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:[NSString stringWithFormat:@"primary-gamma-%d.cube",gammaIDs[j]]]];e=nil;BOOL ok=[primaryRenderer exportLUT:target uniforms:linear paths:@{} spider:nil tools:empty.document colorManagement:v3 error:&e];std::vector<float>values;NSUInteger n=0;ok=ok&&DYLUTReadCube(target.path,values,n,&e)&&n==65;gammaExports&=ok;if(ok)gammaValues[j]=values[((32*n+32)*n+32)*4];}run.record(@"primary-Cube-restores-output-gamma-selection",gammaExports&&fabs(gammaValues[0]-powf(.5f,1/2.2f))<.001&&fabs(gammaValues[1]-powf(.5f,1/2.6f))<.001,@{@"Gamma22":@(gammaValues[0]),@"Gamma26":@(gammaValues[1])});
|
|
upload(input);
|
|
}
|