让 Metal 直写 Vision 追踪输入并加入 LUT 高清分屏预览

这个提交包含在:
mac 于 2026-11-08 19:11:01 +08:00 提交
1 父节点 ef0e62419a
当前提交 63c49b0135
22 个文件已更改
+496 -86

没有与搜索条件相匹配的文件

+166 -26
查看文件
@@ -1,6 +1,8 @@
#import "DYLUTBrowser.h"
#import "DYLookPreview.h"
#import "DYLUTLibrary.h"
#import <QuartzCore/QuartzCore.h>
#include <algorithm>
#include <cmath>
static NSColor *DYBrowserColor(NSDictionary *palette, NSString *key) {
@@ -13,6 +15,7 @@ static NSColor *DYBrowserColor(NSDictionary *palette, NSString *key) {
return [NSColor colorWithWhite:.12 alpha:1];
}
static NSString *const DYBrowserHDPreference=@"com.dayu.color.lookLUTPreview.highResolution";
static NSString *const DYBrowserSizePreference=@"com.dayu.color.lookLUTPreview.thumbnailSize";
static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview.selectedFolder";
static NSString *const DYBrowserFramePreference=@"com.dayu.color.lookLUTPreview.windowFrame";
@@ -134,6 +137,60 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
}
@end
@interface DYBrowserCompareView : NSView
@property(nonatomic) CGFloat position;
@property(nonatomic,assign) NSSlider *slider;
- (void)setOriginal:(NSImage *)original styled:(NSImage *)styled;
@end
@implementation DYBrowserCompareView {
NSImage *_original,*_styled;
}
- (BOOL)isFlipped{return YES;}
- (void)dealloc{[_original release];[_styled release];[super dealloc];}
- (void)setOriginal:(NSImage *)original styled:(NSImage *)styled{
if(_original!=original){[_original release];_original=[original retain];}
if(_styled!=styled){[_styled release];_styled=[styled retain];}
[self setNeedsDisplay:YES];
}
- (void)setPosition:(CGFloat)position{
_position=std::clamp(position,(CGFloat)0,(CGFloat)1);
self.slider.doubleValue=_position;
[self setNeedsDisplay:YES];
}
- (NSRect)pictureRect{
if(!_original)return self.bounds;
CGFloat scale=MIN(NSWidth(self.bounds)/_original.size.width,NSHeight(self.bounds)/_original.size.height);
NSSize size=NSMakeSize(_original.size.width*scale,_original.size.height*scale);
return NSMakeRect(NSMidX(self.bounds)-size.width*.5,NSMidY(self.bounds)-size.height*.5,size.width,size.height);
}
- (void)moveDivider:(NSEvent *)event{
if(!_styled||!self.slider.enabled)return;
NSRect picture=[self pictureRect];
if(NSWidth(picture)>0)self.position=([self convertPoint:event.locationInWindow fromView:nil].x-NSMinX(picture))/NSWidth(picture);
}
- (void)mouseDown:(NSEvent *)event{[self moveDivider:event];}
- (void)mouseDragged:(NSEvent *)event{[self moveDivider:event];}
- (void)drawRect:(NSRect)dirty{
[NSColor.blackColor setFill];NSRectFill(NSIntersectionRect(dirty,self.bounds));
if(!_original)return;
NSRect picture=[self pictureRect];
[_original drawInRect:picture fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
if(!_styled||!self.slider.enabled)return;
CGFloat divider=NSMinX(picture)+NSWidth(picture)*_position;
[NSGraphicsContext saveGraphicsState];
NSRect styledArea=NSMakeRect(divider,NSMinY(picture),NSMaxX(picture)-divider,NSHeight(picture));
NSRectClip(styledArea);
[NSColor.blackColor setFill];NSRectFill(styledArea);
[_styled drawInRect:picture fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
[NSGraphicsContext restoreGraphicsState];
if(_position>0&&_position<1){
[[NSColor blackColor] setFill];NSRectFill(NSMakeRect(divider-1.5,NSMinY(picture),3,NSHeight(picture)));
[[NSColor whiteColor] setFill];NSRectFill(NSMakeRect(divider-.5,NSMinY(picture),1,NSHeight(picture)));
}
}
@end
@class DYLUTBrowser;
/// The jobs own this token, never the browser or its host selection block.
@interface DYBrowserWork : NSObject
@@ -144,7 +201,7 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
@interface DYLUTBrowser () <NSWindowDelegate,NSPopoverDelegate,NSSearchFieldDelegate,NSSplitViewDelegate> {
DYLUTLibrary *_library;
NSData *_preview;
NSData *_preview,*_previewHD;
NSString *_selectedPath,*_folder;
NSDictionary *_palette;
DYLUTSelectionHandler _selection;
@@ -155,15 +212,18 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
NSScrollView *_folderScroll,*_gridScroll;
NSTextField *_titleLabel,*_countLabel,*_statusLabel,*_sizeLabel,*_emptyLabel;
NSSearchField *_search;
NSButton *_importFiles,*_importFolder,*_reveal,*_refresh,*_none,*_done;
NSSlider *_sizeSlider;
NSButton *_importFiles,*_importFolder,*_reveal,*_refresh,*_none,*_done,*_hd;
NSSlider *_sizeSlider,*_compareSlider;
DYBrowserCanvas *_comparePanel;
DYBrowserCompareView *_compareView;
NSTextField *_compareTitle,*_compareStatus,*_originalLabel,*_styledLabel;
NSMutableArray *_folderButtons;
NSMutableDictionary *_tiles;
NSArray *_visibleEntries,*_folderPaths;
NSMutableSet *_queuedPaths;
NSCache *_thumbnailCache;
dispatch_queue_t _previewQueue;
DYBrowserWork *_work;
dispatch_queue_t _previewQueue,_compareQueue;
DYBrowserWork *_work,*_compareWork;
BOOL _closed,_sizing,_visible,_remoteMode,_importing,_layingOut,_detached,_embedded,_compactRecent;
NSArray *_recentSnapshot;
NSProgress *_libraryTask,*_selectionTask;
@@ -209,6 +269,21 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_none=[BrowserButton(@"无 LUT",self,@selector(clearSelection:))retain];
_done=[BrowserButton(@"完成",self,@selector(done:))retain];_done.keyEquivalent=@"\r";
NSUserDefaults *preferences=NSUserDefaults.standardUserDefaults;
_hd=[[NSButton checkboxWithTitle:@"高清预览" target:self action:@selector(qualityChanged:)]retain];
_hd.font=[NSFont systemFontOfSize:11];_hd.state=[preferences boolForKey:DYBrowserPreference(DYBrowserHDPreference,library)]?NSControlStateValueOn:NSControlStateValueOff;
_hd.toolTip=@"从源帧取样并以双倍像素生成缩略图";
_comparePanel=[[DYBrowserCanvas alloc]initWithFrame:NSZeroRect];_comparePanel.fillKey=@"card";
_compareTitle=[BrowserLabel(@"原图与 LUT 对比",13)retain];_compareTitle.font=[NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
_compareStatus=[BrowserLabel(@"等待播放头画面",11)retain];
_originalLabel=[BrowserLabel(@"原图",11)retain];_originalLabel.toolTip=@"同一帧加载此 LUT 之前的画面";
_styledLabel=[BrowserLabel(@"LUT 效果 · 100%",11)retain];_styledLabel.alignment=NSTextAlignmentRight;
_compareView=[[DYBrowserCompareView alloc]initWithFrame:NSZeroRect];_compareView.accessibilityLabel=@"原图与 LUT 滑动对比图";
_compareSlider=[[NSSlider alloc]initWithFrame:NSZeroRect];_compareSlider.minValue=0;_compareSlider.maxValue=1;_compareSlider.continuous=YES;_compareSlider.enabled=NO;
_compareSlider.target=self;_compareSlider.action=@selector(comparePositionChanged:);_compareSlider.accessibilityLabel=@"原图与 LUT 对比分界线";
_compareView.slider=_compareSlider;_compareView.position=.5;
for(NSView *view in @[_compareTitle,_compareStatus,_compareView,_compareSlider,_originalLabel,_styledLabel])[_comparePanel addSubview:view];
_compareQueue=dispatch_queue_create("com.dayu.color.lut-comparison",DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(_compareQueue,dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0));
NSNumber *storedSize=[preferences objectForKey:DYBrowserPreference(DYBrowserSizePreference,library)]?:[preferences objectForKey:DYBrowserSizePreference];double size=storedSize?storedSize.doubleValue:120;
_layoutMenu=[[NSPopUpButton alloc]initWithFrame:NSZeroRect pullsDown:NO];[_layoutMenu addItemsWithTitles:@[@"网格",@"列表"]];_layoutMenu.font=[NSFont systemFontOfSize:11];_layoutMenu.target=self;_layoutMenu.action=@selector(layoutChanged:);_layoutMenu.accessibilityLabel=@"LUT 浏览布局";
[_layoutMenu selectItemAtIndex:[preferences integerForKey:DYBrowserPreference(DYBrowserLayoutPreference,library)]==1?1:0];
@@ -225,7 +300,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gridScrolled:) name:NSViewBoundsDidChangeNotification object:_gridScroll.contentView];
_splitView=[[NSSplitView alloc]initWithFrame:NSMakeRect(12,80,736,425)];_splitView.vertical=YES;_splitView.dividerStyle=NSSplitViewDividerStyleThin;_splitView.accessibilityLabel=@"调整 LUT 文件夹与预览宽度";
_folderScroll.frame=NSMakeRect(0,0,162,425);_gridScroll.frame=NSMakeRect(163,0,573,425);[_splitView addSubview:_folderScroll];[_splitView addSubview:_gridScroll];
for(NSView *view in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_sizeSlider,_layoutMenu,_splitView])[_root addSubview:view];
for(NSView *view in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_hd,_sizeSlider,_layoutMenu,_splitView,_comparePanel])[_root addSubview:view];
[_gridDocument addSubview:_emptyLabel];
_root.postsFrameChangedNotifications=YES;_root.postsBoundsChangedNotifications=YES;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browserRootResized:) name:NSViewFrameDidChangeNotification object:_root];
@@ -240,12 +315,15 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
[_libraryTask cancel];[_libraryTask release];[_selectionTask cancel];[_selectionTask release];[_progressTimer invalidate];[_progressTimer release];
_work.cancelled=YES;_work.owner=nil;[_work release];self.window.delegate=nil;
_popover.delegate=nil;[_popover close];[_popover release];[_root removeFromSuperview];
[_library release];[_preview release];[_selectedPath release];[_folder release];[_palette release];[_selection release];[_closeAction release];
_compareWork.cancelled=YES;_compareWork.owner=nil;[_compareWork release];
[_library release];[_preview release];[_previewHD release];[_selectedPath release];[_folder release];[_palette release];[_selection release];[_closeAction release];
[_root release];[_folderDocument release];[_gridDocument release];[_folderScroll release];[_gridScroll release];
[_titleLabel release];[_countLabel release];[_statusLabel release];[_sizeLabel release];[_emptyLabel release];[_search release];
[_importFiles release];[_importFolder release];[_reveal release];[_refresh release];[_none release];[_done release];[_sizeSlider release];[_layoutMenu release];_splitView.delegate=nil;[_splitView release];[_presentationWindow release];
[_folderButtons release];[_folderPaths release];[_tiles release];[_visibleEntries release];[_queuedPaths release];[_thumbnailCache release];
dispatch_release(_previewQueue);[super dealloc];
_compareView.slider=nil;[_compareView release];[_compareSlider release];[_comparePanel release];[_hd release];
[_compareTitle release];[_compareStatus release];[_originalLabel release];[_styledLabel release];
dispatch_release(_compareQueue);dispatch_release(_previewQueue);[super dealloc];
}
- (void)showRelativeToView:(NSView *)view{
if(_closed||_remoteMode||!view.window||_popover.shown)return;
@@ -254,7 +332,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_popover=[[NSPopover alloc]init];_popover.behavior=NSPopoverBehaviorSemitransient;_popover.animates=YES;_popover.delegate=self;_popover.contentSize=size;
NSViewController *controller=[[[NSViewController alloc]init]autorelease];controller.title=@"风格 LUT";controller.view=_root;_popover.contentViewController=controller;
[self layoutBrowser];
@try {[_popover showRelativeToRect:view.bounds ofView:view preferredEdge:NSRectEdgeMaxX];_visible=_popover.shown;}
@try {[_popover showRelativeToRect:view.bounds ofView:view preferredEdge:NSRectEdgeMaxX];_visible=_popover.shown;[self refreshComparison];}
@catch(NSException *exception){[self finishClosing];}
}
- (BOOL)visible{return !_closed&&((_remoteMode||_detached)?_visible:_popover.shown);}
@@ -270,7 +348,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
[parent addSubview:_root];DYBrowserGeometrySample(_root,@"before-content-origin-alignment");[self fitRemoteParent];
DYBrowserGeometrySample(_root,@"attached-before-sdk-reply");
// Attach synchronously: the SDK reads the first child before reply returns.
dispatch_async(dispatch_get_main_queue(),^{if(!_closed){[self configurePresentationWindow];DYBrowserGeometrySample(_root,@"after-sdk-reply");}});
dispatch_async(dispatch_get_main_queue(),^{if(!_closed){[self configurePresentationWindow];[self refreshComparison];DYBrowserGeometrySample(_root,@"after-sdk-reply");}});
if([NSUserDefaults.standardUserDefaults boolForKey:@"DYBrowserGeometryDiagnostics"])dispatch_after(dispatch_time(DISPATCH_TIME_NOW,NSEC_PER_SEC),dispatch_get_main_queue(),^{if(!_closed)DYBrowserGeometrySample(_root,@"settled");});
NSAccessibilityPostNotification(parent,NSAccessibilityLayoutChangedNotification);
}
@@ -283,7 +361,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_root.accessibilityLabel=@"最近使用 LUT 快捷入口";
_titleLabel.stringValue=@"最近使用";_titleLabel.font=[NSFont systemFontOfSize:11 weight:NSFontWeightSemibold];
[_layoutMenu selectItemAtIndex:0];_sizeSlider.doubleValue=120;
for(NSView *view in @[_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_sizeLabel,_sizeSlider,_layoutMenu,_splitView])view.hidden=YES;
for(NSView *view in @[_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_hd,_comparePanel,_sizeLabel,_sizeSlider,_layoutMenu,_splitView])view.hidden=YES;
[_root addSubview:_gridScroll];_gridScroll.hasHorizontalScroller=NO;_gridScroll.scrollerStyle=NSScrollerStyleOverlay;
[self showInRemoteParent:parent close:nil];[self refreshRecentSelection:_selectedPath];
}
@@ -366,7 +444,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
// The API owner's completion may release this controller synchronously.
[self retain];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
_closed=YES;_visible=NO;_work.cancelled=YES;_work.owner=nil;[_libraryTask cancel];[_selectionTask cancel];[_progressTimer invalidate];[_progressTimer release];_progressTimer=nil;
_closed=YES;_visible=NO;_work.cancelled=YES;_work.owner=nil;_compareWork.cancelled=YES;_compareWork.owner=nil;[_libraryTask cancel];[_selectionTask cancel];[_progressTimer invalidate];[_progressTimer release];_progressTimer=nil;
_popover.delegate=nil;if(_popover.shown)[_popover close];
if(_remoteMode&&_root.superview)for(NSNotificationName name in @[NSViewFrameDidChangeNotification,NSViewBoundsDidChangeNotification])[[NSNotificationCenter defaultCenter]removeObserver:self name:name object:_root.superview];
[_root removeFromSuperview];[_queuedPaths removeAllObjects];[_thumbnailCache removeAllObjects];
@@ -387,7 +465,8 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_reveal.frame=NSMakeRect(w-153,9,139,27);_none.frame=NSMakeRect(14,h-44,75,27);_layoutMenu.frame=NSMakeRect(100,h-44,97,27);
_sizeLabel.frame=NSMakeRect(211,h-39,74,18);_sizeSlider.frame=NSMakeRect(288,h-41,MIN(150,MAX(80,w-550)),20);
_done.frame=NSMakeRect(w-98,h-44,78,27);
CGFloat statusX=NSMaxX(_sizeSlider.frame)+14;_statusLabel.frame=NSMakeRect(statusX,h-39,MAX(0,w-statusX-112),18);
CGFloat hdX=NSMaxX(_sizeSlider.frame)+12;_hd.frame=NSMakeRect(hdX,h-43,86,24);
CGFloat statusX=NSMaxX(_hd.frame)+6;_statusLabel.frame=NSMakeRect(statusX,h-39,MAX(0,w-statusX-112),18);
if(_embedded&&!_compactRecent){
_search.frame=NSMakeRect(12,36,MAX(125,w-310),24);
_importFiles.frame=NSMakeRect(w-284,34,88,28);_importFolder.frame=NSMakeRect(w-192,34,100,28);_refresh.frame=NSMakeRect(w-88,34,76,28);
@@ -395,8 +474,28 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_reveal.hidden=w<620;_titleLabel.frame=NSMakeRect(12,8,152,20);_countLabel.frame=NSMakeRect(166,10,100,18);
_none.frame=NSMakeRect(10,h-34,70,27);_layoutMenu.frame=NSMakeRect(86,h-34,80,27);_done.frame=NSMakeRect(w-88,h-34,78,27);
BOOL small=w<650;_sizeLabel.hidden=small;_sizeSlider.hidden=small;_statusLabel.hidden=small;
if(!small){_sizeLabel.frame=NSMakeRect(174,h-29,68,18);_sizeSlider.frame=NSMakeRect(246,h-31,100,20);_statusLabel.frame=NSMakeRect(354,h-29,MAX(0,w-454),18);}
_hd.frame=NSMakeRect(small?174:352,h-33,86,24);
if(!small){_sizeLabel.frame=NSMakeRect(174,h-29,68,18);_sizeSlider.frame=NSMakeRect(246,h-31,100,20);_statusLabel.frame=NSMakeRect(444,h-29,MAX(0,w-540),18);}
}
NSRect browser=_splitView.frame,comparison=browser;
if(w>=620){
CGFloat width=MIN(560,w*.42);
browser.size.width=MAX(1,NSWidth(browser)-width-10);
comparison.origin.x=NSMaxX(browser)+10;comparison.size.width=width;
}else{
CGFloat height=MIN(NSHeight(browser)*.52,235);
browser.size.height=MAX(1,NSHeight(browser)-height-8);
comparison.origin.y=NSMaxY(browser)+8;comparison.size.height=height;
}
_splitView.frame=browser;[_splitView adjustSubviews];
CGFloat left=MAX(100,MIN(_sidebarWidth,NSWidth(browser)*.41));[_splitView setPosition:left ofDividerAtIndex:0];
_comparePanel.frame=comparison;
CGFloat cw=NSWidth(comparison),ch=NSHeight(comparison),margin=10,body=MAX(1,cw-2*margin);
_compareTitle.frame=NSMakeRect(margin,6,body,20);_compareStatus.frame=NSMakeRect(margin,25,body,16);
_compareView.frame=NSMakeRect(margin,46,body,MAX(1,ch-88));
_compareSlider.frame=NSMakeRect(margin,MAX(47,ch-40),body,18);
_originalLabel.frame=NSMakeRect(margin,MAX(66,ch-20),body*.44,15);
_styledLabel.frame=NSMakeRect(margin+body*.44,MAX(66,ch-20),body*.56,15);
}
if(_compactRecent){
_titleLabel.frame=NSMakeRect(0,2,92,18);_countLabel.frame=NSMakeRect(94,2,100,18);
@@ -443,23 +542,60 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
NSColor *background=[palette[@"background"]colorUsingColorSpace:NSColorSpace.sRGBColorSpace];
BOOL light=background&&background.redComponent>.7&&background.greenComponent>.7;
// Keep the supplied neutral surface in both relief themes.
[_palette release];_palette=[browserPalette copy];_root.palette=_palette;_folderDocument.palette=_palette;_gridDocument.palette=_palette;
[_palette release];_palette=[browserPalette copy];_root.palette=_palette;_folderDocument.palette=_palette;_gridDocument.palette=_palette;_comparePanel.palette=_palette;
self.window.backgroundColor=DYBrowserColor(_palette,@"background");self.window.appearance=[NSAppearance appearanceNamed:light?NSAppearanceNameAqua:NSAppearanceNameDarkAqua];
_root.appearance=[NSAppearance appearanceNamed:light?NSAppearanceNameAqua:NSAppearanceNameDarkAqua];
for(NSTextField *label in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_emptyLabel])label.textColor=DYBrowserColor(_palette,label==_titleLabel?@"text":@"secondary");
for(NSTextField *label in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_emptyLabel,_compareTitle,_compareStatus,_originalLabel,_styledLabel])label.textColor=DYBrowserColor(_palette,label==_titleLabel?@"text":@"secondary");
for(NSButton *button in @[_importFiles,_importFolder,_reveal,_refresh,_none,_done,_layoutMenu])button.contentTintColor=DYBrowserColor(_palette,@"accent");
_search.textColor=DYBrowserColor(_palette,@"text");_search.backgroundColor=DYBrowserColor(_palette,@"field");
for(DYBrowserFolderButton *button in _folderButtons){button.palette=_palette;[button setNeedsDisplay:YES];}
for(DYBrowserTile *tile in _tiles.allValues){tile.palette=_palette;[tile setNeedsDisplay:YES];}
[_root setNeedsDisplay:YES];[_folderDocument setNeedsDisplay:YES];[_gridDocument setNeedsDisplay:YES];
}
- (void)updatePreview:(NSData *)rgba{
if(_closed||_preview==rgba||[_preview isEqualToData:rgba])return;
if(rgba&&rgba.length!=320*180*16)return;
[_preview release];_preview=[rgba copy];[_thumbnailCache removeAllObjects];
- (void)updatePreview:(NSData *)rgba{[self updatePreview:rgba highResolution:nil];}
- (void)updatePreview:(NSData *)rgba highResolution:(NSData *)high{
if(_closed||(rgba&&rgba.length!=320*180*16)||(high&&high.length!=DYLookPreviewHDWidth*DYLookPreviewHDHeight*16))return;
BOOL standardChanged=_preview!=rgba&&![_preview isEqualToData:rgba];
BOOL highChanged=_previewHD!=high&&![_previewHD isEqualToData:high];
if(!standardChanged&&!highChanged)return;
[_preview release];_preview=[rgba retain];
[_previewHD release];_previewHD=[high retain];
if(standardChanged||(highChanged&&_hd.state==NSControlStateValueOn)){
[_thumbnailCache removeAllObjects];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refreshThumbnailSize) object:nil];
[self refreshThumbnailSize];
}
[self refreshComparison];
}
- (void)qualityChanged:(id)sender{
[NSUserDefaults.standardUserDefaults setBool:_hd.state==NSControlStateValueOn forKey:DYBrowserPreference(DYBrowserHDPreference,_library)];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refreshThumbnailSize) object:nil];
[self refreshThumbnailSize];
}
- (void)comparePositionChanged:(id)sender{_compareView.position=_compareSlider.doubleValue;}
- (void)refreshComparison{
if(_closed||_compactRecent||!self.visible)return;
_compareWork.cancelled=YES;_compareWork.owner=nil;[_compareWork release];_compareWork=nil;
NSData *frame=_previewHD?:_preview;
if(!frame){[_compareView setOriginal:nil styled:nil];_compareSlider.enabled=NO;_compareStatus.stringValue=@"等待播放头画面";return;}
NSUInteger w=_previewHD?DYLookPreviewHDWidth:320,h=_previewHD?DYLookPreviewHDHeight:180;
NSString *path=_selectedPath;
NSString *name=path.lastPathComponent.stringByDeletingPathExtension;
_compareWork=[DYBrowserWork new];_compareWork.owner=self;DYBrowserWork *work=_compareWork;
dispatch_async(_compareQueue,^{@autoreleasepool{
if(work.cancelled)return;
NSImage *original=DYLUTThumbnail(nil,frame,w,h,NSMakeSize(w,h),nil);
if(work.cancelled)return;
NSImage *styled=path.length?DYLUTThumbnail(path,frame,w,h,NSMakeSize(w,h),nil):nil;
dispatch_async(dispatch_get_main_queue(),^{
DYLUTBrowser *owner=work.owner;if(work.cancelled||!owner)return;
owner->_compareSlider.enabled=styled!=nil&&original!=nil;
[owner->_compareView setOriginal:original styled:styled];
owner->_compareStatus.stringValue=path.length?(styled?name:@"无法预览当前 LUT"):@"选择一个 LUT 查看对比";
owner->_compareStatus.toolTip=owner->_compareStatus.stringValue;
});
}});
}
- (void)setStatus:(NSString *)status{_statusLabel.stringValue=status?:@"";_statusLabel.toolTip=status;}
- (void)rebuildFolders{
NSMutableArray *paths=[NSMutableArray arrayWithObjects:DYBrowserRecentFolder,@"*",nil];NSMutableSet *seen=[NSMutableSet setWithArray:paths];
@@ -499,7 +635,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
[_thumbnailCache removeAllObjects];NSUInteger generation=++_libraryGeneration;
NSProgress *task=[_library reloadAsync:^(NSError *error){
if(_closed||generation!=_libraryGeneration)return;[self endLibraryTask];
[self rebuildFolders];[self rebuildGrid];[self setStatus:error?error.localizedDescription:@"单击缩略图应用 LUT"];
[self rebuildFolders];[self rebuildGrid];[self refreshComparison];[self setStatus:error?error.localizedDescription:@"单击缩略图应用 LUT"];
}];[self beginLibraryTask:task];
}
- (void)folderClicked:(NSButton *)sender{
@@ -526,19 +662,23 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
- (void)generateVisibleThumbnails{
if(_closed||!_work)return;
NSRect visible=NSInsetRect(_gridScroll.contentView.bounds,-30,-180);
BOOL hd=!_compactRecent&&_hd.state==NSControlStateValueOn;
NSUInteger width=MAX((NSUInteger)64,(NSUInteger)llround(_sizeSlider.doubleValue)),height=MAX((NSUInteger)40,(NSUInteger)llround(width*9./16));
if(hd){width*=2;height*=2;}
NSData *frame=hd&&_previewHD?_previewHD:_preview;
NSUInteger sourceWidth=hd&&_previewHD?DYLookPreviewHDWidth:320,sourceHeight=hd&&_previewHD?DYLookPreviewHDHeight:180;
for(NSString *path in _tiles.allKeys){
DYBrowserTile *tile=_tiles[path];
if(!NSIntersectsRect(tile.frame,visible)){if(tile.thumbnail){tile.thumbnail=nil;tile.enabled=NO;}continue;}
if(tile.thumbnail||tile.failure.length)continue;
NSString *cacheKey=[NSString stringWithFormat:@"%lu|%@",(unsigned long)width,path];
NSString *cacheKey=[NSString stringWithFormat:@"%d|%lu|%@",hd,(unsigned long)width,path];
NSDictionary *cached=[_thumbnailCache objectForKey:cacheKey];
if(cached){tile.thumbnail=cached[@"image"];tile.failure=cached[@"error"];tile.enabled=tile.thumbnail!=nil;if(tile.failure.length)tile.toolTip=tile.failure;[tile setNeedsDisplay:YES];continue;}
if([_queuedPaths containsObject:cacheKey])continue;[_queuedPaths addObject:cacheKey];
DYBrowserWork *work=_work;NSData *preview=_preview;
DYBrowserWork *work=_work;
dispatch_async(_previewQueue,^{@autoreleasepool{
if(work.cancelled)return;
NSError *error=nil;NSImage *image=DYLUTThumbnail(path,preview,320,180,NSMakeSize(width,height),&error);NSString *failure=error.localizedDescription;
NSError *error=nil;NSImage *image=DYLUTThumbnail(path,frame,sourceWidth,sourceHeight,NSMakeSize(width,height),&error);NSString *failure=error.localizedDescription;
dispatch_async(dispatch_get_main_queue(),^{
DYLUTBrowser *owner=work.owner;if(work.cancelled||!owner)return;
[owner->_queuedPaths removeObject:cacheKey];
@@ -573,7 +713,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
void (^applied)(NSError *)=^(NSError *error){
if(_closed||generation!=_selectionGeneration)return;[_selectionTask release];_selectionTask=nil;
if(error){[self setStatus:error.localizedDescription];return;}
[_selectedPath release];_selectedPath=[path copy];[_library recordUsedPath:path];[self rebuildGrid];
[_selectedPath release];_selectedPath=[path copy];[_library recordUsedPath:path];[self rebuildGrid];[self refreshComparison];
for(DYBrowserTile *tile in _tiles.allValues){tile.chosen=[tile.identifier isEqualToString:path];[tile setNeedsDisplay:YES];}
[self setStatus:[@"已选择 " stringByAppendingString:name]];if(closeAfter)[self close];
};
@@ -585,7 +725,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
void (^cleared)(NSError *)=^(NSError *error){
if(_closed||generation!=_selectionGeneration)return;[_selectionTask release];_selectionTask=nil;
if(error){[self setStatus:error.localizedDescription];return;}
[_selectedPath release];_selectedPath=nil;
[_selectedPath release];_selectedPath=nil;[self refreshComparison];
for(DYBrowserTile *tile in _tiles.allValues){tile.chosen=NO;[tile setNeedsDisplay:YES];}
[self setStatus:@"已移除 LUT"];
};