修复 LUT 浏览器帧比例和会话内排序
这个提交包含在:
1 父节点
5c0f177bde
当前提交
b7c2e291ec
18 个文件已更改
+205
-139
没有与搜索条件相匹配的文件
+50
-39
@@ -1,5 +1,4 @@
|
||||
#import "DYLUTBrowser.h"
|
||||
#import "DYLookPreview.h"
|
||||
#import "DYLUTLibrary.h"
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#include <algorithm>
|
||||
@@ -77,6 +76,16 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
|
||||
- (void)dealloc{[_palette release];[_fillKey release];[super dealloc];}
|
||||
@end
|
||||
|
||||
static NSSize DYBrowserFitSize(NSSize source,NSSize box) {
|
||||
CGFloat scale=MIN(box.width/source.width,box.height/source.height);
|
||||
return NSMakeSize(source.width*scale,source.height*scale);
|
||||
}
|
||||
|
||||
static NSRect DYBrowserTileImageRect(NSRect bounds,BOOL list) {
|
||||
return list?NSMakeRect(3,3,104,MAX(1,NSHeight(bounds)-6))
|
||||
:NSMakeRect(2,2,MAX(1,NSWidth(bounds)-4),MAX(1,NSHeight(bounds)-27));
|
||||
}
|
||||
|
||||
@interface DYBrowserTile : NSButton
|
||||
@property(retain) NSImage *thumbnail;
|
||||
@property(copy) NSString *displayName;
|
||||
@@ -101,12 +110,12 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
|
||||
NSRect bounds=NSInsetRect(self.bounds,1,1);
|
||||
NSBezierPath *outline=[NSBezierPath bezierPathWithRoundedRect:bounds xRadius:7 yRadius:7];
|
||||
[DYBrowserColor(_palette,_chosen?@"field":@"card") setFill];[outline fill];
|
||||
NSRect imageRect=_listLayout?NSMakeRect(3,3,104,bounds.size.height-4):NSMakeRect(2,2,MAX(1,bounds.size.width-2),MAX(1,bounds.size.height-25));
|
||||
NSRect imageRect=DYBrowserTileImageRect(self.bounds,_listLayout);
|
||||
if(_thumbnail){
|
||||
[NSGraphicsContext saveGraphicsState];
|
||||
[[NSBezierPath bezierPathWithRoundedRect:imageRect xRadius:4 yRadius:4]addClip];
|
||||
NSSize size=_thumbnail.size;CGFloat scale=MAX(imageRect.size.width/MAX(1,size.width),imageRect.size.height/MAX(1,size.height));
|
||||
NSRect dest=NSMakeRect(NSMidX(imageRect)-size.width*scale/2,NSMidY(imageRect)-size.height*scale/2,size.width*scale,size.height*scale);
|
||||
NSSize size=DYBrowserFitSize(_thumbnail.size,imageRect.size);
|
||||
NSRect dest=NSMakeRect(NSMidX(imageRect)-size.width/2,NSMidY(imageRect)-size.height/2,size.width,size.height);
|
||||
[_thumbnail drawInRect:dest fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
}else{
|
||||
@@ -201,7 +210,7 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
|
||||
|
||||
@interface DYLUTBrowser () <NSWindowDelegate,NSPopoverDelegate,NSSearchFieldDelegate,NSSplitViewDelegate> {
|
||||
DYLUTLibrary *_library;
|
||||
NSData *_preview,*_previewHD;
|
||||
NSDictionary *_previewFrames;
|
||||
NSString *_selectedPath,*_folder;
|
||||
NSDictionary *_palette;
|
||||
DYLUTSelectionHandler _selection;
|
||||
@@ -246,13 +255,13 @@ static void DYBrowserGeometrySample(NSView *root,NSString *phase){
|
||||
}
|
||||
static NSTextField *BrowserLabel(NSString *title,CGFloat size){NSTextField *label=[NSTextField labelWithString:title];label.font=[NSFont systemFontOfSize:size];label.lineBreakMode=NSLineBreakByTruncatingTail;return label;}
|
||||
static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *button=[NSButton buttonWithTitle:title target:target action:action];button.font=[NSFont systemFontOfSize:11];button.bezelStyle=NSBezelStyleRounded;return button;}
|
||||
- (instancetype)initWithLibrary:(DYLUTLibrary *)library preview:(NSData *)rgba selectedPath:(NSString *)path palette:(NSDictionary *)palette selection:(DYLUTSelectionHandler)selection{
|
||||
- (instancetype)initWithLibrary:(DYLUTLibrary *)library preview:(NSDictionary *)frames selectedPath:(NSString *)path palette:(NSDictionary *)palette selection:(DYLUTSelectionHandler)selection{
|
||||
NSPanel *panel=[[[NSPanel alloc]initWithContentRect:NSMakeRect(0,0,760,560) styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO]autorelease];
|
||||
if((self=[super initWithWindow:panel])){
|
||||
NSString *savedFolder=[[NSUserDefaults standardUserDefaults]stringForKey:DYBrowserPreference(DYBrowserFolderPreference,library)]?:[[NSUserDefaults standardUserDefaults]stringForKey:DYBrowserFolderPreference];
|
||||
if(!library.recentPaths.count&&path.length)[library recordUsedPath:path];
|
||||
if(!savedFolder)savedFolder=library.recentPaths.count?DYBrowserRecentFolder:@"*";
|
||||
_library=[library retain];_preview=[rgba copy];_selectedPath=[path copy];_folder=[(savedFolder?:@"*") copy];_selection=[selection copy];
|
||||
_library=[library retain];_previewFrames=[frames copy];_recentSnapshot=[library.recentPaths copy];_selectedPath=[path copy];_folder=[(savedFolder?:@"*") copy];_selection=[selection copy];
|
||||
_folderButtons=[NSMutableArray new];_tiles=[NSMutableDictionary new];_queuedPaths=[NSMutableSet new];_thumbnailCache=[NSCache new];_thumbnailCache.countLimit=600;_thumbnailCache.totalCostLimit=64*1024*1024;_previewQueue=dispatch_queue_create("com.dayu.color.lut-thumbnails",DISPATCH_QUEUE_SERIAL);dispatch_set_target_queue(_previewQueue,dispatch_get_global_queue(QOS_CLASS_UTILITY,0));
|
||||
panel.title=@"风格 LUT";panel.contentMinSize=self.class.minimumContentSize;panel.contentMaxSize=self.class.maximumContentSize;panel.releasedWhenClosed=NO;panel.hidesOnDeactivate=NO;panel.delegate=self;
|
||||
_root=[[DYBrowserCanvas alloc]initWithFrame:NSMakeRect(0,0,760,560)];_root.accessibilityLabel=@"LUT 缩略图浏览库";panel.contentView=_root;
|
||||
@@ -316,7 +325,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
_work.cancelled=YES;_work.owner=nil;[_work release];self.window.delegate=nil;
|
||||
_popover.delegate=nil;[_popover close];[_popover release];[_root removeFromSuperview];
|
||||
_compareWork.cancelled=YES;_compareWork.owner=nil;[_compareWork release];
|
||||
[_library release];[_preview release];[_previewHD release];[_selectedPath release];[_folder release];[_palette release];[_selection release];[_closeAction release];
|
||||
[_library release];[_previewFrames 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];
|
||||
@@ -363,7 +372,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
[_layoutMenu selectItemAtIndex:0];_sizeSlider.doubleValue=120;
|
||||
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];
|
||||
[self showInRemoteParent:parent close:nil];[self rebuildGrid];[self refreshRecentSelection:_selectedPath];
|
||||
}
|
||||
- (void)refreshRecentSelection:(NSString *)path{
|
||||
if(!_compactRecent||_closed)return;
|
||||
@@ -505,9 +514,12 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
if(!_compactRecent){CGFloat fw=MAX(100,_folderScroll.contentSize.width);
|
||||
_folderDocument.frame=NSMakeRect(0,0,fw,MAX(_folderPaths.count*35+4,_folderScroll.contentSize.height));
|
||||
[self updateVisibleFolders];}
|
||||
CGFloat available=MAX(80,_gridScroll.contentSize.width),tileWidth=_sizeSlider.doubleValue,gap=10;
|
||||
CGFloat available=MAX(80,_gridScroll.contentSize.width),edge=_sizeSlider.doubleValue,gap=10;
|
||||
NSSize source=[self previewSize],preferred=DYBrowserFitSize(source,NSMakeSize(edge-4,edge-4));
|
||||
CGFloat tileWidth=MAX(70,ceil(preferred.width)+4);
|
||||
BOOL list=_layoutMenu.indexOfSelectedItem==1;NSInteger columns=list?1:MAX(1,(NSInteger)floor((available+gap)/(tileWidth+gap)));tileWidth=list?MAX(110,available-14):MIN(tileWidth,(available-gap*(columns-1)-14)/columns);tileWidth=MAX(70,tileWidth);
|
||||
_columns=columns;_tileWidth=tileWidth;_tileHeight=list?70:ceil(tileWidth*9/16)+24;
|
||||
_columns=columns;_tileWidth=tileWidth;
|
||||
_tileHeight=list?70:ceil(DYBrowserFitSize(source,NSMakeSize(tileWidth-4,edge-4)).height)+27;
|
||||
NSInteger rows=(_visibleEntries.count+columns-1)/columns;CGFloat contentHeight=MAX(_gridScroll.contentSize.height,rows*(_tileHeight+gap)+12);
|
||||
_gridDocument.frame=NSMakeRect(0,0,available,contentHeight);_emptyLabel.frame=NSMakeRect(20,MAX(36,_gridScroll.contentSize.height/2-45),MAX(50,available-40),90);
|
||||
_layingOut=NO;[self updateVisibleTiles];
|
||||
@@ -552,19 +564,16 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
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{[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];
|
||||
}
|
||||
- (NSSize)previewSize {
|
||||
NSValue *size=_previewFrames[@"standardSize"]?:_previewFrames[@"highSize"];
|
||||
return size?size.sizeValue:NSMakeSize(320,180);
|
||||
}
|
||||
- (void)updatePreview:(NSDictionary *)frames{
|
||||
if(_closed||_previewFrames==frames||[_previewFrames isEqual:frames])return;
|
||||
[_previewFrames release];_previewFrames=[frames copy];
|
||||
[_thumbnailCache removeAllObjects];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(refreshThumbnailSize) object:nil];
|
||||
[self refreshThumbnailSize];
|
||||
[self refreshComparison];
|
||||
}
|
||||
- (void)qualityChanged:(id)sender{
|
||||
@@ -576,17 +585,17 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
- (void)refreshComparison{
|
||||
if(_closed||_compactRecent||!self.visible)return;
|
||||
_compareWork.cancelled=YES;_compareWork.owner=nil;[_compareWork release];_compareWork=nil;
|
||||
NSData *frame=_previewHD?:_preview;
|
||||
NSData *frame=_previewFrames[@"high"]?:_previewFrames[@"standard"];
|
||||
if(!frame){[_compareView setOriginal:nil styled:nil];_compareSlider.enabled=NO;_compareStatus.stringValue=@"等待播放头画面";return;}
|
||||
NSUInteger w=_previewHD?DYLookPreviewHDWidth:320,h=_previewHD?DYLookPreviewHDHeight:180;
|
||||
NSSize size=[(_previewFrames[@"highSize"]?:_previewFrames[@"standardSize"]) sizeValue];
|
||||
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);
|
||||
NSImage *original=DYLUTThumbnail(nil,frame,size.width,size.height,size,nil);
|
||||
if(work.cancelled)return;
|
||||
NSImage *styled=path.length?DYLUTThumbnail(path,frame,w,h,NSMakeSize(w,h),nil):nil;
|
||||
NSImage *styled=path.length?DYLUTThumbnail(path,frame,size.width,size.height,size,nil):nil;
|
||||
dispatch_async(dispatch_get_main_queue(),^{
|
||||
DYLUTBrowser *owner=work.owner;if(work.cancelled||!owner)return;
|
||||
owner->_compareSlider.enabled=styled!=nil&&original!=nil;
|
||||
@@ -656,29 +665,31 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
if(_closed)return;_sizing=NO;
|
||||
_work.cancelled=YES;_work.owner=nil;[_work release];_work=[DYBrowserWork new];_work.owner=self;[_queuedPaths removeAllObjects];
|
||||
for(DYBrowserTile *tile in _tiles.allValues){tile.thumbnail=nil;tile.failure=nil;tile.enabled=YES;[tile setNeedsDisplay:YES];}
|
||||
[self generateVisibleThumbnails];
|
||||
[self layoutBrowser];
|
||||
}
|
||||
- (void)gridScrolled:(NSNotification *)notification{[self updateVisibleTiles];}
|
||||
- (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;
|
||||
BOOL useHigh=_previewFrames[@"high"]&&(hd||!_previewFrames[@"standard"]);
|
||||
NSData *frame=_previewFrames[useHigh?@"high":@"standard"];
|
||||
NSSize source=useHigh?[_previewFrames[@"highSize"] sizeValue]:[self previewSize];
|
||||
NSSize box=DYBrowserTileImageRect(NSMakeRect(0,0,_tileWidth,_tileHeight),_layoutMenu.indexOfSelectedItem==1).size;
|
||||
NSSize target=DYBrowserFitSize([self previewSize],box);
|
||||
NSUInteger width=MAX(1,llround(target.width*(hd?2:1))),height=MAX(1,llround(target.height*(hd?2:1)));
|
||||
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:@"%d|%lu|%@",hd,(unsigned long)width,path];
|
||||
NSString *cacheKey=[NSString stringWithFormat:@"%d|%lux%lu|%@",hd,(unsigned long)width,(unsigned long)height,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;
|
||||
dispatch_async(_previewQueue,^{@autoreleasepool{
|
||||
if(work.cancelled)return;
|
||||
NSError *error=nil;NSImage *image=DYLUTThumbnail(path,frame,sourceWidth,sourceHeight,NSMakeSize(width,height),&error);NSString *failure=error.localizedDescription;
|
||||
NSError *error=nil;NSImage *image=DYLUTThumbnail(path,frame,source.width,source.height,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];
|
||||
@@ -694,14 +705,14 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
[self resetThumbnailWork];
|
||||
for(NSView *tile in _tiles.allValues)[tile removeFromSuperview];[_tiles removeAllObjects];
|
||||
NSString *query=[_search.stringValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];NSMutableArray *entries=[NSMutableArray array];
|
||||
BOOL recent=[_folder isEqual:DYBrowserRecentFolder];NSArray *history=_library.recentPaths;
|
||||
for(NSDictionary *entry in (recent?_library.recentEntries:_library.entries)){
|
||||
BOOL recent=[_folder isEqual:DYBrowserRecentFolder];NSArray *history=_recentSnapshot;
|
||||
for(NSDictionary *entry in (recent?[_library recentEntriesForPaths:history]:_library.entries)){
|
||||
NSString *folder=entry[@"relativeFolder"]?:@"";
|
||||
BOOL folderMatch=recent||[_folder isEqualToString:@"*"]||[folder isEqualToString:_folder]||(_folder.length&&[folder hasPrefix:[_folder stringByAppendingString:@"/"]]);
|
||||
if(folderMatch&&(!query.length||[entry[@"name"]localizedCaseInsensitiveContainsString:query]||[entry[@"relativePath"]localizedCaseInsensitiveContainsString:query]))[entries addObject:entry];
|
||||
}
|
||||
if(!recent)[entries sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){NSUInteger i=[history indexOfObject:a[@"path"]],j=[history indexOfObject:b[@"path"]];if(i==j)return [a[@"relativePath"]localizedStandardCompare:b[@"relativePath"]];return i<j?NSOrderedAscending:NSOrderedDescending;}];
|
||||
_emptyLabel.stringValue=recent?@"尚未使用 LUT。成功应用后会在这里按最近使用排序。":@"此文件夹还没有 LUT。\n点“导入文件”或“导入文件夹”添加 .cube 文件。";
|
||||
_emptyLabel.stringValue=recent?@"尚未使用 LUT。应用后,下次打开会显示最近使用记录。":@"此文件夹还没有 LUT。\n点“导入文件”或“导入文件夹”添加 .cube 文件。";
|
||||
[_visibleEntries release];_visibleEntries=[entries copy];_countLabel.stringValue=[NSString stringWithFormat:@"%lu 个 LUT",(unsigned long)entries.count];_emptyLabel.hidden=entries.count>0;
|
||||
[_gridScroll.contentView scrollToPoint:NSZeroPoint];[self layoutBrowser];[_gridScroll reflectScrolledClipView:_gridScroll.contentView];
|
||||
NSAccessibilityPostNotification(_gridDocument,NSAccessibilityLayoutChangedNotification);
|
||||
@@ -713,7 +724,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];[self refreshComparison];
|
||||
[_selectedPath release];_selectedPath=[path copy];[_library recordUsedPath:path];[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];
|
||||
};
|
||||
|
||||
在新工单中引用
屏蔽一个用户