Support text-annotated Cube rows with Custom LUT zero-fill compatibility

这个提交包含在:
mac 于 2026-11-02 20:13:29 +08:00 提交
1 父节点 5c547100c1
当前提交 58a17de438
10 个文件已更改
+1307 -1072

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

+49
查看文件
@@ -0,0 +1,49 @@
#import <AppKit/AppKit.h>
#import "../大鱼调色/Plugin/DYLUTLibrary.h"
#include <cstdio>
static NSMutableArray *checks;
static void need(BOOL pass,NSString *name){[checks addObject:@{@"name":name,@"pass":@(pass)}];if(!pass){fprintf(stderr,"FAIL %s\n",name.UTF8String);exit(1);}}
int main(int argc,const char **argv){@autoreleasepool{
if(argc!=2)return 2;checks=[NSMutableArray new];NSError *error=nil;
NSFileManager *fm=NSFileManager.defaultManager;
NSURL *root=[NSURL fileURLWithPath:[NSTemporaryDirectory()stringByAppendingPathComponent:[@"dayu-lut-notes-" stringByAppendingString:NSUUID.UUID.UUIDString]]];
need([fm createDirectoryAtURL:root withIntermediateDirectories:YES attributes:nil error:&error],@"isolated fixtures");
NSString *header=@"TITLE \"Synthetic note compatibility\"\nLUT_3D_SIZE 2\n";
NSString *normal=@"0.25 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n";
NSString *notes=@"0.25 v3文字 100 分\n1 0 说明99\n0 1 0 完整数值 后记123\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n";
NSURL *baseline=[root URLByAppendingPathComponent:@"baseline.cube"];
need([[header stringByAppendingString:normal]writeToURL:baseline atomically:YES encoding:NSUTF8StringEncoding error:&error],@"write independent numeric oracle");
std::vector<float> expected;NSUInteger side=0;
need(DYLUTReadCube(baseline.path,expected,side,&error)&&side==2,@"read numeric oracle");
float pixel[]={.37,.28,.81,.6};NSData *input=[NSData dataWithBytes:pixel length:sizeof(pixel)];
NSData *reference=DYLUTTransformRGBA(input,1,1,baseline.path,&error);
NSArray *encodings=@[@(NSUTF8StringEncoding),@(NSUTF16LittleEndianStringEncoding),@(NSUTF16BigEndianStringEncoding),@(NSUTF32LittleEndianStringEncoding),@(NSUTF32BigEndianStringEncoding)];
NSMutableArray *sources=[NSMutableArray array];
for(NSNumber *encoding in encodings)for(NSString *newline in @[@"\n",@"\r\n",@"\r"]){@autoreleasepool{
NSString *text=[[header stringByAppendingString:notes]stringByReplacingOccurrencesOfString:@"\n" withString:newline];
NSURL *url=[root URLByAppendingPathComponent:[NSString stringWithFormat:@"note-%lu.cube",(unsigned long)sources.count]];
NSData *bytes=[text dataUsingEncoding:encoding.unsignedIntegerValue];
need([bytes writeToURL:url atomically:YES],@"write encoded annotations");[sources addObject:url];
std::vector<float> actual;NSUInteger n=0;
need(DYLUTReadCube(url.path,actual,n,&error)&&n==2&&actual==expected,@"zero unread channels, ignore note digits, preserve every later row");
need([DYLUTTransformRGBA(input,1,1,url.path,&error)isEqual:reference],@"annotated and canonical cubes give exactly the same colors");
need(DYLUTThumbnail(url.path,nil,0,0,NSMakeSize(32,18),&error)!=nil,@"annotated cube thumbnail");
}}
NSArray *invalid=@[@"0.25\n",@"0.25 0\n",@"0.25 NaN 0\n",@"0.25 Inf 0\n",@"0.25 0 0 100\n",@"0.25oops 0 0\n",@"0.25 0broken 0\n",@"0.25 0 0broken\n",@"note only 100\n",@"0.25 0 0 NaN\n"];
NSUInteger index=0;
for(NSString *first in invalid){
NSURL *url=[root URLByAppendingPathComponent:[NSString stringWithFormat:@"invalid-%lu.cube",(unsigned long)index++]];
NSString *text=[header stringByAppendingString:[normal stringByReplacingCharactersInRange:NSMakeRange(0,9) withString:first]];
need([text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:&error],@"write invalid numeric fixture");
std::vector<float> actual;NSUInteger n=0;
need(!DYLUTReadCube(url.path,actual,n,&error)&&actual.empty()&&n==0,@"notes do not excuse malformed numbers, bare truncation, extra values or text-only rows");
}
DYLUTLibrary *library=[[[DYLUTLibrary alloc]initWithRootURL:[root URLByAppendingPathComponent:@"library"]]autorelease];
NSArray *imported=[library importURLs:sources error:&error];
need(imported.count==sources.count,@"all annotated encodings import");
for(NSUInteger i=0;i<sources.count;i++)need([[NSData dataWithContentsOfURL:sources[i]]isEqual:[NSData dataWithContentsOfFile:imported[i][@"path"]]],@"import retains original annotation bytes");
NSDictionary *report=@{@"pass":@YES,@"checks":@(checks.count),@"results":checks,@"scope":@"Synthetic UTF-8/16/32 notes, zero fill without row shifts, exact canonical colors, thumbnails, byte-preserving import, strict invalid-number checks."};
need([[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:nil]writeToFile:[NSString stringWithUTF8String:argv[1]] atomically:YES],@"write report");
need([fm removeItemAtURL:root error:nil],@"clean fixtures");printf("PASS %lu checks\n",(unsigned long)checks.count);return 0;
}}