fix: prepare and pin external LUT snapshots before acknowledging thumbnail application

这个提交包含在:
mac 于 2026-11-01 15:05:42 +08:00 提交
1 父节点 a2c8dfafcf
当前提交 593aad9ecb
12 个文件已更改
+247 -49

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

+25 -13
查看文件
@@ -32,12 +32,19 @@ static BOOL DYLUTFail(NSError **error,NSString *message) {
return NO;
}
@interface DYLUTTable : NSObject {
@interface DYLUTPreparedTable () {
@public std::vector<float> values;
@public NSUInteger dimension;
@public NSUInteger _dimension;
@public NSString *_path,*_revision;
}
@end
@implementation DYLUTTable @end
@implementation DYLUTPreparedTable
- (void)dealloc {[_path release];[_revision release];[super dealloc];}
- (NSUInteger)dimension {return _dimension;}
- (NSString *)path {return _path;}
- (NSString *)revision {return _revision;}
- (const float *)rgbaValues {return values.data();}
@end
static NSCache *DYLUTTableCache(void) {
static NSCache *cache;static dispatch_once_t once;
@@ -137,19 +144,24 @@ static BOOL DYLUTParse(NSString *path,std::vector<float>& data,NSUInteger& size,
return YES;
}
static BOOL DYLUTReadCancellable(NSString *path,std::vector<float>& data,NSUInteger& size,NSProgress *progress,NSError **error) {
data.clear();size=0;
if(!path.length)return DYLUTFail(error,@"未选择 LUT 文件");
DYLUTPreparedTable *DYLUTReadPreparedTable(NSString *path,NSProgress *progress,NSError **error) {
if(DYLUTCancelled(progress,error))return nil;
if(!path.length){DYLUTFail(error,@"未选择 LUT 文件");return nil;}
NSDictionary *a=[[NSFileManager defaultManager]attributesOfItemAtPath:path error:error];
if(!a)return NO;
if(!a)return nil;
NSString *key=[NSString stringWithFormat:@"%@|%.9f|%@|%@",path.stringByStandardizingPath,[a[NSFileModificationDate]timeIntervalSinceReferenceDate],a[NSFileSize],a[NSFileSystemFileNumber]];
DYLUTTable *cached=[DYLUTTableCache()objectForKey:key];
if(cached){data=cached->values;size=cached->dimension;return YES;}
DYLUTPreparedTable *cached=[DYLUTTableCache()objectForKey:key];
if(cached)return cached;
std::vector<float> parsed;NSUInteger n=0;
if(DYLUTCancelled(progress,error)||!DYLUTParse(path,parsed,n,progress,error))return NO;
DYLUTTable *table=[[[DYLUTTable alloc]init]autorelease];table->values=std::move(parsed);table->dimension=n;
if(DYLUTCancelled(progress,error)||!DYLUTParse(path,parsed,n,progress,error))return nil;
DYLUTPreparedTable *table=[[[DYLUTPreparedTable alloc]init]autorelease];table->values=std::move(parsed);table->_dimension=n;
table->_path=[path copy];table->_revision=[key copy];
[DYLUTTableCache()setObject:table forKey:key cost:table->values.size()*sizeof(float)];
data=table->values;size=n;return YES;
return table;
}
static BOOL DYLUTReadCancellable(NSString *path,std::vector<float>& data,NSUInteger& size,NSProgress *progress,NSError **error) {
data.clear();size=0;DYLUTPreparedTable *table=DYLUTReadPreparedTable(path,progress,error);
if(!table)return NO;data=table->values;size=table.dimension;return YES;
}
BOOL DYLUTReadCube(NSString *path,std::vector<float>& data,NSUInteger& size,NSError **error) {
@@ -162,7 +174,7 @@ NSProgress *DYLUTPrepareAsync(NSString *path,void (^completion)(NSError *)) {
dispatch_async(queue,^{@autoreleasepool{
NSError *error=nil;std::vector<float> values;NSUInteger n=0;
DYLUTReadCancellable(path,values,n,progress,&error);DYLUTCancelled(progress,&error);progress.completedUnitCount=1;
dispatch_async(dispatch_get_main_queue(),^{if(completion)completion(error);});
dispatch_async(dispatch_get_main_queue(),^{NSError *result=error;DYLUTCancelled(progress,&result);if(completion)completion(result);});
}});return progress;
}