// Presentation-only changes must never rewrite a host's grading parameters. { DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil); NSDictionary *values=[[host->_values copy]autorelease],*custom=[[host->_custom copy]autorelease];int starts=host->_undoStarts,ends=host->_undoEnds; DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host]autorelease]; NSButton *settings=[view valueForKey:@"colorSettings"];NSView *panel=[view valueForKey:@"managedPanel"];NSArray *cards=[view valueForKey:@"cards"]; BOOL expanded=YES;NSUInteger visible=0;CGFloat bottom=0; for(NSDictionary *card in cards)if(![card[@"removed"]boolValue]){expanded&=![card[@"collapsed"]boolValue];visible++;bottom=MAX(bottom,NSMaxY([card[@"view"]frame]));} NSView *document=[view valueForKey:@"document"];NSView *brandLabel=[view valueForKey:@"brand"]; run.record(@"inspector-all-existing-modules-expanded-before-host-creation",expanded&&visible==DYToolTypes().count&&!panel.hidden,@{@"visibleModules":@(visible),@"height":@(view.frame.size.height)}); run.record(@"inspector-returned-frame-contains-complete-expanded-document",NSMaxY(document.frame)<=view.frame.size.height&&bottom<=document.bounds.size.height&&view.frame.size.height==view.intrinsicContentSize.height); run.record(@"inspector-complete-content-has-no-inner-scroll-view",[view valueForKey:@"scroll"]==nil&&NSContainsRect(view.bounds,brandLabel.frame)); for(int i=0;i<10;i++){[settings performClick:nil];for(NSDictionary *card in cards)[card[@"header"]performClick:nil];[view layoutSubtreeIfNeeded];} expanded=YES;for(NSDictionary *card in cards)expanded&=![card[@"collapsed"]boolValue]; run.record(@"inspector-headers-keep-modules-expanded-without-editing-grade",expanded&&!panel.hidden&&[values isEqual:host->_values]&&[custom isEqual:host->_custom]&&starts==host->_undoStarts&&ends==host->_undoEnds); DYInspectorToken *folds=[[[DYInspectorToken alloc]init]autorelease];folds.folds=@{@"primary":@YES,@"hsl":@YES};[host setCustomParameterValue:folds toParameter:DYInspectorParameterID atTime:kCMTimeZero]; [view refresh];expanded=YES;for(NSDictionary *card in cards)expanded&=![card[@"collapsed"]boolValue]; run.record(@"inspector-old-fold-state-does-not-collapse-new-presentation",expanded&&[DYReadTools(host,kCMTimeZero).document isKindOfClass:NSDictionary.class]); for(NSDictionary *state in @[@{},DYManagedColorDefaults(),DYPrimaryColorDefaults(),DYUnifiedColorDefaults()]){ DYAssetState *assets=[[[DYAssetState alloc]init]autorelease];assets.colorManagement=state.count?state:nil;DYWriteAssets(host,assets,kCMTimeZero);[view refresh];NSDictionary *snapshot=[view presetSnapshot];[settings performClick:nil]; run.record([NSString stringWithFormat:@"expanded-settings-preserve-CMS-version-%@",state[@"version"]?:@1],[[view presetSnapshot]isEqual:snapshot]); } for(NSNumber *width in @[@280,@320,@400]){ [view setFrameSize:NSMakeSize(width.doubleValue,780)];[view layoutSubtreeIfNeeded];NSArray *buttons=@[[view valueForKey:@"save"],[view valueForKey:@"load"],[view valueForKey:@"export"],settings];BOOL fit=YES; for(NSView *button in buttons){fit&=NSMinX(button.frame)>=0&&NSMaxX(button.frame)<=width.doubleValue&&button.frame.size.width>=66;for(NSView *other in buttons)if(button!=other)fit&=!NSIntersectsRect(button.frame,other.frame);} NSArray *themes=[view valueForKey:@"themeButtons"];NSView *brand=[view valueForKey:@"brand"];fit&=themes.count==2&&NSMaxX(brand.frame)<=NSMinX([themes.firstObject frame]); for(NSButton *mode in themes){fit&=mode.frame.size.width>=44&&NSMaxX(mode.frame)<=NSMinX([[view valueForKey:@"resetAll"]frame])&&mode.title.length>0;for(NSButton *other in themes)if(mode!=other)fit&=!NSIntersectsRect(mode.frame,other.frame);} run.record([NSString stringWithFormat:@"compact-header-controls-fit-%@",width],fit); } DYDiagnosticManager *fresh=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(fresh,nil);run.record(@"compact-new-host-stays-original-flow",!DYReadAssets(fresh,kCMTimeZero).colorManagement); NSInteger previous=DYThemeIndex();@try{ BOOL colors=DYThemeNames().count==2&&[DYThemeNames()[0]isEqual:@"浅色"]&&[DYThemeNames()[1]isEqual:@"深色"]; for(NSInteger i=7;i<=8;i++){DYSetThemeIndex(i);colors&=DYThemeIndex()==i&&DYThemePalette()[@"background"]&&DYThemePalette()[@"text"];} run.record(@"compact-only-light-dark-choices",colors); auto luminance=[](NSColor *color){NSColor *c=[color colorUsingColorSpace:NSColorSpace.sRGBColorSpace];auto linear=[](double x){return x<=.04045?x/12.92:pow((x+.055)/1.055,2.4);};return .2126*linear(c.redComponent)+.7152*linear(c.greenComponent)+.0722*linear(c.blueComponent);}; NSDictionary *themeSnapshot=[view presetSnapshot];int themeUndo=host->_undoStarts; DYSetThemeIndex(7);double lightMinimum=100; for(NSString *text in @[@"text",@"secondary",@"slot15",@"accent"])for(NSString *surface in @[@"background",@"backgroundEnd",@"card",@"cardEnd",@"field",@"headerTop",@"headerBottom"]) lightMinimum=std::min(lightMinimum,(luminance(DYThemePalette()[surface])+.05)/(luminance(DYThemePalette()[text])+.05)); run.record(@"soft-light-text-contrast-at-least-4.5",lightMinimum>=4.5,@{@"minimumContrast":@(lightMinimum)}); [view performSelector:@selector(themeChanged:) withObject:nil]; run.record(@"soft-native-controls-use-light-appearance",[view.appearance.name isEqual:NSAppearanceNameAqua]&&DYThemeTextShadow()==nil); run.record(@"soft-theme-preserves-grade-and-undo",[themeSnapshot isEqual:[view presetSnapshot]]&&themeUndo==host->_undoStarts); DYSetThemeIndex(8);double darkMinimum=100; for(NSString *text in @[@"text",@"secondary",@"slot15",@"accent"])for(NSString *surface in @[@"background",@"backgroundEnd",@"card",@"cardEnd",@"field",@"headerTop",@"headerBottom"]) darkMinimum=std::min(darkMinimum,(luminance(DYThemePalette()[text])+.05)/(luminance(DYThemePalette()[surface])+.05)); run.record(@"soft-dark-text-contrast-at-least-4.5",darkMinimum>=4.5,@{@"minimumContrast":@(darkMinimum)}); [view performSelector:@selector(themeChanged:) withObject:nil]; run.record(@"soft-dark-native-appearance-without-text-glow",[view.appearance.name isEqual:NSAppearanceNameDarkAqua]&&DYThemeTextShadow()==nil); run.record(@"soft-dark-theme-preserves-grade-and-undo",[themeSnapshot isEqual:[view presetSnapshot]]&&themeUndo==host->_undoStarts); DYSetThemeIndex(6);run.record(@"compact-removed-themes-cannot-be-selected",DYThemeIndex()==8); DYThemePopUpButton *pullDown=[[[DYThemePopUpButton alloc]initWithFrame:NSMakeRect(0,0,240,28) pullsDown:YES]autorelease];[pullDown addItemWithTitle:@"+ 添加模块"];pullDown.font=[NSFont systemFontOfSize:11]; NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:240 pixelsHigh:28 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]autorelease]; [NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];[pullDown drawRect:pullDown.bounds];[NSGraphicsContext restoreGraphicsState];NSUInteger glyphPixels=0; for(int y=6;y<23;y++)for(int x=9;x<90;x++){NSColor *c=[bitmap colorAtX:x y:y];if(c.redComponent>.55&&c.greenComponent>.35)glyphPixels++;} run.record(@"compact-dark-pull-down-draws-readable-caption",glyphPixels>30,@{@"brightCaptionPixels":@(glyphPixels)}); }@finally{DYSetThemeIndex(previous);} } // Histogram math is independent of UI palettes and never edits a host document. { float pixels[][4]={{0,0,0,1},{1,1,1,1},{1,0,0,1},{0,1,0,1},{0,0,1,1},{-.5,2,.5,1},{1,1,1,0},{NAN,0,0,1},{0,0,0,INFINITY}}; NSData *input=[NSData dataWithBytes:pixels length:sizeof(pixels)];NSData *data=DYHistogramFromRGBA(input);const DYHistogram *h=(const DYHistogram*)data.bytes; run.record(@"histogram-rejects-transparent-and-nonfinite",h->samples==6); run.record(@"histogram-rgb-endpoints-and-clamped-headroom",h->bins[1][0]==4&&h->bins[1][255]==2&&h->bins[2][255]==3&&h->bins[3][128]==1); run.record(@"histogram-luma-primary-coefficients",h->bins[0][54]==1&&h->bins[0][182]==1&&h->bins[0][18]==1); BOOL totals=YES;for(int c=0;c<4;c++){uint32_t total=0;for(int b=0;b<256;b++)total+=h->bins[c][b];totals&=total==6;} run.record(@"histogram-each-channel-conserves-valid-samples",totals); run.record(@"histogram-malformed-and-empty-safe",!DYHistogramFromRGBA([NSData dataWithBytes:pixels length:3])&&((const DYHistogram*)DYHistogramFromRGBA([NSData data]).bytes)->samples==0); DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil);DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease]; DYScopeSample *sample=[[[DYScopeSample alloc]init]autorelease];sample.pixels=input;[renderer setValue:sample forKey:@"scopeLatest"]; DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host renderer:renderer]autorelease];[view refresh];NSDictionary *before=[view presetSnapshot]; for(NSMutableDictionary *card in [view valueForKey:@"cards"])if([card[@"section"][@"key"]isEqual:@"curve"]){card[@"removed"]=@NO;card[@"collapsed"]=@NO;} [view setNeedsLayout:YES];[view layoutSubtreeIfNeeded]; NSView *graph=nil;for(NSView *v in [view valueForKey:@"graphics"])if([v.identifier isEqual:@"curveGraph"])graph=v; NSButton *toggle=[graph valueForKey:@"histogramToggle"];NSSegmentedControl *channels=[graph valueForKey:@"channels"]; run.record(@"histogram-open-inspector-uses-cached-effect-output",[[graph valueForKey:@"histogram"]isEqual:data]&&toggle.state==NSControlStateValueOn); NSMutableSet *images=[NSMutableSet set]; for(NSInteger c=0;c<4;c++){ channels.selectedSegment=c;[graph performSelector:@selector(channelChanged:) withObject:channels];[graph setFrameSize:NSMakeSize(320,240)];[graph layoutSubtreeIfNeeded]; NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:320 pixelsHigh:240 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]autorelease]; [NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];[graph drawRect:graph.bounds];[NSGraphicsContext restoreGraphicsState];[images addObject:[NSData dataWithBytes:bitmap.bitmapData length:bitmap.bytesPerRow*bitmap.pixelsHigh]]; } [toggle performClick:nil];[toggle performClick:nil]; run.record(@"histogram-four-channel-drawings-distinct",images.count==4); run.record(@"histogram-channel-and-overlay-presentation-does-not-edit-grade",[before isEqual:[view presetSnapshot]]&&host->_undoStarts==0&&host->_undoEnds==0); [renderer invalidatePreview]; run.record(@"histogram-keeps-final-output-while-a-new-render-is-pending",[[graph valueForKey:@"histogram"]isEqual:data]); DYDiagnosticTile *updated=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:2 height:2]autorelease]; const __fp16 colors[16]={.25f,.4f,.6f,1,.25f,.4f,.6f,1,.25f,.4f,.6f,1,.25f,.4f,.6f,1}; [[updated metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,2,2)mipmapLevel:0 withBytes:colors bytesPerRow:16]; [renderer captureScopeTile:updated atTime:kCMTimeZero]; double until=NSProcessInfo.processInfo.systemUptime+1; while([[graph valueForKey:@"histogram"]isEqual:data]&&NSProcessInfo.processInfo.systemUptime