diff --git a/大鱼调色/Plugin/DYDiagnostics.mm b/大鱼调色/Plugin/DYDiagnostics.mm index 5c2e6d7..aa86752 100644 --- a/大鱼调色/Plugin/DYDiagnostics.mm +++ b/大鱼调色/Plugin/DYDiagnostics.mm @@ -50,8 +50,10 @@ IOSurfaceRef _surface; FxRect _bounds; uint64_t _registry; + FxImageOrigin _diagnosticOrigin; } - (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height; +- (void)setDiagnosticImageOrigin:(FxImageOrigin)origin; @end @implementation DYDiagnosticTile - (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height { @@ -63,7 +65,7 @@ MTLTextureDescriptor *d=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO]; d.storageMode=MTLStorageModeShared;d.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget; if(_surface)_texture=[device newTextureWithDescriptor:d iosurface:_surface plane:0]; - _bounds=(FxRect){0,0,(SInt32)width,(SInt32)height};_registry=device.registryID; + _bounds=(FxRect){0,0,(SInt32)width,(SInt32)height};_registry=device.registryID;_diagnosticOrigin=kFxImageOrigin_TOP_LEFT; if(!_surface||!_texture){[self release];return nil;} }return self; } @@ -73,7 +75,8 @@ - (FxRect)tilePixelBounds {return _bounds;} - (FxRect)imagePixelBounds {return _bounds;} - (uint64_t)deviceRegistryID {return _registry;} -- (FxImageOrigin)imageOrigin {return kFxImageOrigin_TOP_LEFT;} +- (FxImageOrigin)imageOrigin {return _diagnosticOrigin;} +- (void)setDiagnosticImageOrigin:(FxImageOrigin)origin {_diagnosticOrigin=origin;} @end namespace { @@ -146,6 +149,35 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { NSData *preview=[renderer preview];bool previewFinite=preview.length==320*180*16;if(previewFinite){const float *data=(const float *)preview.bytes;for(NSUInteger i=0;ip[2]&&p[(179*320)*4+2]>p[(179*320)*4];} + run.record(@"look-preview-top-left-is-original-analysis",topOrientation,@{@"error":topRendered?@"":reason(error),@"bytes":@(topLook.length)}); + [orientationRenderer invalidatePreview];[source setDiagnosticImageOrigin:kFxImageOrigin_BOTTOM_LEFT]; + [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:bottomFirst.data() bytesPerRow:width*8]; + error=nil;BOOL bottomRendered=[orientationRenderer renderSource:source destination:destination uniforms:defaults paths:@{} error:&error]; + NSData *bottomAnalysis=[orientationRenderer preview],*bottomLook=[orientationRenderer lookLUTPreview]; + bool bottomOrientation=bottomRendered&&bottomAnalysis.length==320*180*16&&bottomLook.length==bottomAnalysis.length; + if(bottomOrientation){ + const float*a=(const float*)bottomAnalysis.bytes,*b=(const float*)bottomLook.bytes; + bottomOrientation=a[2]>a[0]&&a[(179*320)*4]>a[(179*320)*4+2]&&b[0]>b[2]&&b[(179*320)*4+2]>b[(179*320)*4]; + for(NSUInteger y=0;y<180&&bottomOrientation;y++)bottomOrientation=memcmp((const uint8_t*)bottomLook.bytes+y*320*16,(const uint8_t*)bottomAnalysis.bytes+(179-y)*320*16,320*16)==0; + } + run.record(@"look-preview-bottom-left-flips-only-browser-rows",bottomOrientation,@{@"error":bottomRendered?@"":reason(error),@"analysisKeepsPhysicalRowOrder":@(bottomOrientation),@"all180RowsCompared":@(bottomOrientation)}); + [orientationRenderer invalidatePreview];run.record(@"preview-invalidation-clears-analysis-and-browser",![orientationRenderer preview]&&![orientationRenderer lookLUTPreview]); + [source setDiagnosticImageOrigin:kFxImageOrigin_TOP_LEFT]; + [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; DYUniforms u=defaults;u.exposure=.8f;Pixels exposed=render(run,renderer,source,destination,gpu,u,@{},@"renderer-exposure-pass");Difference exposureDifference=difference(neutral,exposed);run.record(@"exposure-affects-actual-frame",exposureDifference.nonfinite==0&&exposureDifference.different>100,measure(exposureDifference)); u.baseSectionEnabled=0;Pixels bypass=render(run,renderer,source,destination,gpu,u,@{},@"renderer-base-bypass-pass");Difference bypassDifference=difference(neutral,bypass);run.record(@"base-group-bypass",bypassDifference.nonfinite==0&&bypassDifference.maximum==0,measure(bypassDifference)); u=defaults;u.temperature=35;u.tint=-20;Pixels wb=render(run,renderer,source,destination,gpu,u,@{},@"renderer-white-balance-pass");Difference wbDifference=difference(neutral,wb);run.record(@"white-balance-real-table-frame",wbDifference.nonfinite==0&&wbDifference.different>100,measure(wbDifference)); diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index 62087e2..1bfcfd8 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -13,7 +13,7 @@ static NSColor *DYAccent(void) { return DYThemeColor(@"accent"); } static NSColor *DYInk(void) { return DYThemeColor(@"text"); } static NSTextField *DYLabel(NSString *text, CGFloat size) { NSTextField *v=[NSTextField labelWithString:text?:@""]; - v.font=[NSFont systemFontOfSize:size weight:size==11?NSFontWeightMedium:NSFontWeightRegular]; v.textColor=DYInk(); + v.font=[NSFont systemFontOfSize:size weight:size==11?NSFontWeightMedium:NSFontWeightRegular]; v.textColor=DYThemeColor(@"slot15"); v.lineBreakMode=NSLineBreakByTruncatingTail; return v; } @@ -29,10 +29,26 @@ static NSString *DYNumber(double value,NSDictionary *d) { } -@interface DYBlueSliderCell : NSSliderCell @end +@interface DYBlueSliderCell : NSSliderCell +@property(copy) NSString *colorKey; +@end @implementation DYBlueSliderCell +- (void)dealloc {[_colorKey release];[super dealloc];} +- (NSArray *)trackColors { + if([_colorKey isEqual:@"temperature"])return @[[NSColor colorWithSRGBRed:.21 green:.45 blue:1 alpha:1],[NSColor colorWithSRGBRed:1 green:.78 blue:.27 alpha:1]]; + if([_colorKey isEqual:@"tint"])return @[[NSColor colorWithSRGBRed:.2 green:.85 blue:.36 alpha:1],[NSColor colorWithSRGBRed:.95 green:.23 blue:.88 alpha:1]]; + if([_colorKey isEqual:@"vibrance"]||[_colorKey isEqual:@"saturation"])return @[[NSColor colorWithWhite:.45 alpha:1],NSColor.systemYellowColor,NSColor.systemGreenColor,NSColor.systemBlueColor,NSColor.systemPinkColor]; + int axis=0,color=0;if(sscanf(_colorKey.UTF8String?:"","hsl%d_%d",&axis,&color)==2){ + double hue=((double[]){0,.08,.16,.33,.5,.61,.76,.9})[MAX(0,MIN(7,color))];NSColor *center=[NSColor colorWithCalibratedHue:hue saturation:.85 brightness:1 alpha:1]; + if(axis==0)return @[[NSColor colorWithCalibratedHue:fmod(hue+.9,1) saturation:.9 brightness:1 alpha:1],center,[NSColor colorWithCalibratedHue:fmod(hue+.1,1) saturation:.9 brightness:1 alpha:1]]; + if(axis==1)return @[[NSColor colorWithWhite:.45 alpha:1],center]; + return @[[NSColor blackColor],center,[center blendedColorWithFraction:.65 ofColor:NSColor.whiteColor]]; + } + return nil; +} - (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped { NSRect track=NSMakeRect(rect.origin.x,NSMidY(rect)-2.5,rect.size.width,5); + NSArray *colors=[self trackColors];if(colors){NSGradient *g=[[[NSGradient alloc]initWithColors:colors]autorelease];[g drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:track xRadius:2.5 yRadius:2.5] angle:0];return;} NSBezierPath *bar=[NSBezierPath bezierPathWithRoundedRect:track xRadius:2.5 yRadius:2.5];NSGradient *base=[[[NSGradient alloc]initWithStartingColor:DYThemePalette()[@"slot8"] endingColor:DYThemePalette()[@"slot9"]]autorelease];[base drawInBezierPath:bar angle:90];[[NSColor colorWithWhite:0 alpha:.28]setStroke];bar.lineWidth=.6;[bar stroke]; double fraction=(self.doubleValue-self.minValue)/fmax(.000001,self.maxValue-self.minValue); NSRect active=track;active.size.width*=fmax(0,fmin(1,fraction));NSGradient *g=[[[NSGradient alloc]initWithStartingColor:DYThemePalette()[@"activeTop"] endingColor:DYThemePalette()[@"activeBottom"]]autorelease];[g drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:active xRadius:2 yRadius:2] angle:90]; @@ -384,7 +400,7 @@ static NSImage *DYWheelImage(void) { self.wantsLayer=YES; self.layer.masksToBounds=YES; self.layer.backgroundColor=[DYThemePalette()[@"background"] CGColor]; self.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; - _brand=[DYLabel(@"◒ 大鱼调色",16) retain]; _brand.font=[NSFont boldSystemFontOfSize:16]; + _brand=[DYLabel(@"◒ 大鱼调色",16) retain]; _brand.font=[NSFont boldSystemFontOfSize:16];_brand.textColor=DYInk(); _subtitle=[DYLabel(@"1.1",9) retain]; _subtitle.textColor=DYThemeColor(@"secondary"); _resetAll=[DYButton(@"↺",self,@selector(resetAll:)) retain];_resetAll.bordered=NO; _resetAll.toolTip=@"恢复全部调色参数与 LUT";_resetAll.accessibilityLabel=@"全部还原"; _save=[DYButton(@"保存预设",self,@selector(savePreset:)) retain]; @@ -454,7 +470,7 @@ static NSImage *DYWheelImage(void) { [self setNeedsLayout:YES];NSAccessibilityPostNotification(self,NSAccessibilityLayoutChangedNotification); } - (void)addLook:(id)sender {_visibleLooks=MIN(5,_visibleLooks+1);[self setNeedsLayout:YES];} -- (void)previewChanged:(NSNotification *)note {if(_browser.visible)[_browser updatePreview:[_renderer preview]];} +- (void)previewChanged:(NSNotification *)note {if(_browser.visible)[_browser updatePreview:[_renderer lookLUTPreview]];} - (void)buildCards { NSInteger index=0; for(NSDictionary *section in _sections) { @@ -533,7 +549,7 @@ static NSImage *DYWheelImage(void) { popup.accessibilityLabel=d[@"title"]; [row addSubview:popup]; record[@"popup"]=popup; } else { NSSlider *slider=[[[NSSlider alloc]initWithFrame:NSZeroRect]autorelease]; - DYBlueSliderCell *sliderCell=[[[DYBlueSliderCell alloc]init]autorelease];slider.cell=sliderCell; + DYBlueSliderCell *sliderCell=[[[DYBlueSliderCell alloc]init]autorelease];sliderCell.colorKey=d[@"key"];slider.cell=sliderCell; slider.minValue=[d[@"min"]doubleValue];slider.maxValue=[d[@"max"]doubleValue];slider.doubleValue=[d[@"default"]doubleValue];slider.target=self;slider.action=@selector(scalarChanged:); slider.tag=[pid integerValue]; slider.continuous=YES; slider.controlSize=NSControlSizeSmall; slider.accessibilityLabel=d[@"title"]; [row addSubview:slider]; record[@"slider"]=slider; @@ -808,7 +824,7 @@ static NSImage *DYWheelImage(void) { [_browser close];[_browser release];_browser=nil; id a=[self actionAPI];if(!a)return;[a startAction:self];NSString *selected=nil;@try{selected=[DYReadAssets(_manager,a.currentTime).paths[sender.identifier]copy];}@finally{[a endAction:self];} __block DYInspector *owner=self;NSString *key=[[sender.identifier copy]autorelease]; - _browser=[[DYLUTBrowser alloc]initWithLibrary:_library preview:[_renderer preview] selectedPath:selected palette:DYThemePalette() selection:^(NSString *path){[owner setAssetPath:path forKey:key];}];[selected release]; + _browser=[[DYLUTBrowser alloc]initWithLibrary:_library preview:[_renderer lookLUTPreview] selectedPath:selected palette:DYThemePalette() selection:^(NSString *path){[owner setAssetPath:path forKey:key];}];[selected release]; id remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v3)]; if(!remote)remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v2)];if(!remote)remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI)]; DYLUTBrowser *browser=_browser;id closer=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v3)]; diff --git a/大鱼调色/Plugin/DYRenderer.h b/大鱼调色/Plugin/DYRenderer.h index e0fe683..6d08d63 100644 --- a/大鱼调色/Plugin/DYRenderer.h +++ b/大鱼调色/Plugin/DYRenderer.h @@ -6,5 +6,8 @@ - (BOOL)renderSource:(FxImageTile*)source destination:(FxImageTile*)destination uniforms:(DYUniforms)uniforms paths:(NSDictionary*)paths error:(NSError**)error; - (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)uniforms paths:(NSDictionary*)paths error:(NSError**)error; - (NSData*)preview; +/// Display-encoded float RGBA, 320×180, with the visually top row first. +/// Analysis preview retains the host texture's original row order separately. +- (NSData*)lookLUTPreview; - (void)invalidatePreview; @end diff --git a/大鱼调色/Plugin/DYRenderer.mm b/大鱼调色/Plugin/DYRenderer.mm index bcc76de..db271c4 100644 --- a/大鱼调色/Plugin/DYRenderer.mm +++ b/大鱼调色/Plugin/DYRenderer.mm @@ -11,15 +11,16 @@ static id texture3D(idd,const float*values,NSUInteger n){ @interface DYRenderer(){ NSMutableDictionary *_devices,*_luts; DYColorTables *_tables; - NSData *_preview; + NSData *_preview,*_lookLUTPreview; CFTimeInterval _lastPreview; } @end @implementation DYRenderer - (instancetype)init{if((self=[super init])){_devices=[NSMutableDictionary new];_luts=[NSMutableDictionary new];_tables=[DYColorTables new];}return self;} -- (void)dealloc{[_devices release];[_luts release];[_tables release];[_preview release];[super dealloc];} -- (void)invalidatePreview{@synchronized(self){[_preview release];_preview=nil;_lastPreview=0;}} +- (void)dealloc{[_devices release];[_luts release];[_tables release];[_preview release];[_lookLUTPreview release];[super dealloc];} +- (void)invalidatePreview{@synchronized(self){[_preview release];_preview=nil;[_lookLUTPreview release];_lookLUTPreview=nil;_lastPreview=0;}} - (NSData*)preview{@synchronized(self){return [[_preview retain]autorelease];}} +- (NSData*)lookLUTPreview{@synchronized(self){return [[_lookLUTPreview retain]autorelease];}} - (NSMutableDictionary*)device:(uint64_t)registry error:(NSError**)err{ NSNumber*k=@(registry);NSMutableDictionary*entry=_devices[k];if(entry)return entry; idd=nil;NSArray*all=MTLCopyAllDevices();for(idcandidate in all)if(candidate.registryID==registry||!registry){d=[candidate retain];break;}[all release];if(!d){fail(err,@"宿主的 Metal 设备不可用");return nil;} @@ -60,7 +61,18 @@ static id texture3D(idd,const float*values,NSUInteger n){ DYVertex2D vs[]={{{w/2,-h/2},{r,bottom}},{{-w/2,-h/2},{l,bottom}},{{w/2,h/2},{r,top}},{{-w/2,h/2},{l,top}}}; if(dst.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)for(int i=0;i<4;i++)vs[i].position.y=-vs[i].position.y; vector_uint2 vp={(unsigned)output.width,(unsigned)output.height};[re setVertexBytes:vs length:sizeof(vs) atIndex:0];[re setVertexBytes:&vp length:sizeof(vp) atIndex:1];[re setViewport:(MTLViewport){0,0,w,h,0,1}];[re setFragmentTexture:straight atIndex:0];for(NSUInteger i=0;iCFBundleShortVersionString 1.1.0 CFBundleVersion - 4 + 5 NSHumanReadableCopyright PlugInKit diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 1a1d7ac..0cc8184 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.1.0 CFBundleVersion - 4 + 5 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright