WIP: integrate source CST primary pipeline and independent module disclosure; validation pending
这个提交包含在:
1 父节点
76537da0a6
当前提交
d2bf0696bd
19 个文件已更改
+7972
-79
没有与搜索条件相匹配的文件
@@ -0,0 +1,29 @@
|
||||
#ifndef DAYU_SHADER_TYPES_H
|
||||
#define DAYU_SHADER_TYPES_H
|
||||
#include <simd/simd.h>
|
||||
typedef struct CSTParams { int inputGamut, inputTransfer, outputGamut, outputTransfer, toneMapping; } CSTParams;
|
||||
typedef struct BasisParams {
|
||||
int colorspace;
|
||||
float exposure, balanceTarget, balanceStrength, contrast, pivot, highlights, midtones, shadows;
|
||||
float trimLow, trimHigh, trimToeStrength, trimShoulderStrength, shadowContrast, shadowPivot, hiContrast, hiPivot, chromaMix;
|
||||
unsigned char bypassBalance, bypassTone, bypassExposure, bypassContrast;
|
||||
float saturation;
|
||||
} BasisParams;
|
||||
typedef struct DayuRenderParams {
|
||||
CSTParams input;
|
||||
CSTParams output;
|
||||
BasisParams basis;
|
||||
int stages;
|
||||
int sourceLinear;
|
||||
int destinationLinear;
|
||||
int reserved;
|
||||
// Additional curve-only adapters for working encodings absent from original BASIS.
|
||||
CSTParams basisInput;
|
||||
CSTParams basisOutput;
|
||||
} DayuRenderParams;
|
||||
#ifndef __METAL_VERSION__
|
||||
_Static_assert(sizeof(CSTParams)==20, "CST target layout");
|
||||
_Static_assert(sizeof(BasisParams)==80, "BASIS target layout");
|
||||
_Static_assert(sizeof(DayuRenderParams)==176, "Integrated layout; legacy prefix remains 136 bytes");
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
// Raw, animatable CST controls. The first 944 bytes of DYUniforms stay unchanged.
|
||||
#pragma once
|
||||
#include "DYCSTTypes.h"
|
||||
typedef struct DYCMSettings {
|
||||
float configured;
|
||||
float inputTransfer;
|
||||
float inputGamut;
|
||||
float workingTransfer;
|
||||
float workingGamut;
|
||||
float inputEnabled;
|
||||
float basisEnabled;
|
||||
float outputEnabled;
|
||||
float outputTransfer;
|
||||
float outputGamut;
|
||||
float toneMapping;
|
||||
float exposure;
|
||||
float balanceAngle;
|
||||
float balanceStrength;
|
||||
float saturation;
|
||||
float contrast;
|
||||
float pivot;
|
||||
float hiContrast;
|
||||
float hiPivot;
|
||||
float shadowContrast;
|
||||
float shadowPivot;
|
||||
float white;
|
||||
float shoulder;
|
||||
float highlights;
|
||||
float midtones;
|
||||
float shadows;
|
||||
float black;
|
||||
float toe;
|
||||
float chromaMix;
|
||||
float bypassExposure;
|
||||
float bypassBalance;
|
||||
float bypassContrast;
|
||||
float bypassTone;
|
||||
float mix;
|
||||
float blackWhiteMix;
|
||||
} DYCMSettings;
|
||||
#ifndef __METAL_VERSION__
|
||||
#include <math.h>
|
||||
static inline int DYBasisMode(int c) {
|
||||
if(c==99)return 0;if(c>=1&&c<=11)return c;
|
||||
switch(c){case 14:return 12;case 15:return 13;case 16:return 14;case 19:return 15;case 20:return 16;case 21:return 17;case 22:return 18;case 25:return 19;case 27:return 20;case 28:return 21;default:return -1;}
|
||||
}
|
||||
static inline DayuRenderParams DYCMRender(DYCMSettings s) {
|
||||
DayuRenderParams p={0};
|
||||
p.input=(CSTParams){(int)lroundf(s.inputGamut),(int)lroundf(s.inputTransfer),(int)lroundf(s.workingGamut),(int)lroundf(s.workingTransfer),0};
|
||||
p.output=(CSTParams){p.input.outputGamut,p.input.outputTransfer,(int)lroundf(s.outputGamut),(int)lroundf(s.outputTransfer),(int)lroundf(s.toneMapping)};
|
||||
p.stages=(s.inputEnabled>.5?1:0)|(s.basisEnabled>.5?2:0)|(s.outputEnabled>.5?4:0);
|
||||
if(s.toneMapping>.5){p.input.toneMapping=(p.input.inputTransfer>1000?2:0)+(p.input.outputTransfer>1000?1:0);p.output.toneMapping=(p.output.inputTransfer>1000?2:0)+(p.output.outputTransfer>1000?1:0);}
|
||||
int mode=DYBasisMode(p.input.outputTransfer);p.basis.colorspace=mode<0?10:mode;
|
||||
if(mode<0){p.reserved|=8;p.basisInput=(CSTParams){p.input.outputGamut,p.input.outputTransfer,p.input.outputGamut,10,0};p.basisOutput=(CSTParams){p.input.outputGamut,10,p.input.outputGamut,p.input.outputTransfer,0};}
|
||||
BasisParams *b=&p.basis;
|
||||
b->exposure=exp2f(s.exposure);b->balanceTarget=s.balanceAngle;b->balanceStrength=s.balanceStrength*s.balanceStrength*4;
|
||||
b->contrast=exp2f(s.contrast);b->pivot=exp2f(s.pivot);b->highlights=s.highlights;b->midtones=s.midtones*.3330000042915344f;b->shadows=s.shadows*1.5f;
|
||||
b->trimLow=1.0+(double)s.black*-.5;b->trimHigh=s.white;b->trimToeStrength=1+15*s.toe;b->trimShoulderStrength=1+7*s.shoulder;
|
||||
b->shadowContrast=(double)s.shadowContrast*-1.3;b->shadowPivot=exp2f(.20000000298023224f*s.shadowPivot);b->hiContrast=s.hiContrast*2;b->hiPivot=exp2f(-.20000000298023224f*s.hiPivot);b->chromaMix=s.chromaMix;
|
||||
b->bypassExposure=s.bypassExposure>.5;b->bypassBalance=s.bypassBalance>.5;b->bypassContrast=s.bypassContrast>.5;b->bypassTone=s.bypassTone>.5;b->saturation=s.saturation;
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
+28
-1
@@ -38,12 +38,17 @@ fragment half4 dyFragment(DYRaster in [[stage_in]],
|
||||
texture3d<float> colorGrading [[texture(9)]],
|
||||
constant DYUniforms& uniforms [[buffer(0)]],
|
||||
constant float& sceneLevel [[buffer(1)]],
|
||||
constant DYRenderOptions& options [[buffer(2)]]) {
|
||||
constant DYRenderOptions& options [[buffer(2)]],
|
||||
constant DYUniforms& colorUniforms [[buffer(3)]]) {
|
||||
constexpr sampler sampleFilter(coord::normalized, address::clamp_to_edge, filter::linear);
|
||||
half4 sample = source.sample(sampleFilter, in.uv);
|
||||
if (!(sample.a > half(0.0))) return half4(0.0h);
|
||||
half4 result = dy_grade(sample, in.uv, source, preLUT, look1, look2, look3,
|
||||
look4, look5, hslMixer, whiteBalance, colorGrading, uniforms, sceneLevel);
|
||||
if(options.blackWhiteMix>0.0f && options.blackWhiteMix<1.0f) {
|
||||
half4 color=dy_grade(sample,in.uv,source,preLUT,look1,look2,look3,look4,look5,hslMixer,whiteBalance,colorGrading,colorUniforms,sceneLevel);
|
||||
result.rgb=mix(color.rgb,result.rgb,half(options.blackWhiteMix));
|
||||
}
|
||||
result.a = sample.a;
|
||||
if (options.outputPremultiplied) result.rgb *= result.a;
|
||||
return result;
|
||||
@@ -110,3 +115,25 @@ kernel void dyInputAnalysis(texture2d<half> source [[texture(0)]],
|
||||
encoded=round(clamp(encoded,0.0f,1.0f)*255.0f)/255.0f;
|
||||
outRGBA[pixel.y*320+pixel.x]=float4(encoded,float(sample.a));
|
||||
}
|
||||
|
||||
// CST/BASIS arithmetic is reused verbatim from the versioned dayu-cst source.
|
||||
float4 cst_air(half4 sample, constant CSTParams& params);
|
||||
float4 basis_air(half4 sample, constant BasisParams& params);
|
||||
inline float3 dyEncode(float3 linear) {
|
||||
return select(1.055f*pow(max(linear,float3(0)),float3(1.0f/2.4f))-.055f,linear*12.92f,linear<=.0031308f);
|
||||
}
|
||||
inline float3 dyDecode(float3 encoded) {
|
||||
return select(pow(max((encoded+.055f)/1.055f,float3(0)),float3(2.4f)),encoded/12.92f,encoded<=.04045f);
|
||||
}
|
||||
kernel void dyColorManagement(texture2d<float,access::read> source [[texture(0)]],
|
||||
texture2d<half,access::write> destination [[texture(1)]],
|
||||
constant DayuRenderParams& p [[buffer(0)]],constant float& amount [[buffer(1)]],uint2 pos [[thread_position_in_grid]]) {
|
||||
if(pos.x>=source.get_width()||pos.y>=source.get_height())return;
|
||||
float4 sample=source.read(pos);if(!(sample.a>0)){destination.write(half4(0),pos);return;}
|
||||
float4 raw=float4(dyEncode(sample.rgb),sample.a),c=raw;
|
||||
if(p.stages&1)c=cst_air(half4(c),p.input);
|
||||
if(p.stages&2){if(p.reserved&8)c=cst_air(half4(c),p.basisInput);c=basis_air(half4(c),p.basis);if(p.reserved&8)c=cst_air(half4(c),p.basisOutput);}
|
||||
if(p.stages&4)c=cst_air(half4(c),p.output);
|
||||
c.rgb=mix(raw.rgb,c.rgb,amount);
|
||||
destination.write(half4(half3(dyDecode(c.rgb)),half(sample.a)),pos);
|
||||
}
|
||||
+40
-22
@@ -167,11 +167,12 @@ static NSArray *DYPresentationSections(void) {
|
||||
NSMutableDictionary *bySection=[NSMutableDictionary dictionary],*byKey=[NSMutableDictionary dictionary];
|
||||
for(NSDictionary *s in DYSections())bySection[s[@"key"]]=s;
|
||||
for(NSDictionary *d in DYDescriptors())byKey[d[@"key"]]=d;
|
||||
NSMutableDictionary *input=[[bySection[@"input"] mutableCopy]autorelease];input[@"rows"]=@[byKey[@"preLUTStrength"]];
|
||||
NSMutableDictionary *input=[[bySection[@"input"] mutableCopy]autorelease];
|
||||
NSMutableDictionary *base=[[bySection[@"base"] mutableCopy]autorelease];NSMutableArray *rows=[NSMutableArray array];
|
||||
for(NSString *key in @[@"temperature",@"tint",@"exposure",@"contrast",@"highlights",@"shadows",@"whites",@"blacks",@"texture",@"clarity",@"dehaze",@"vibrance",@"saturation",@"skinEnabled",@"copyAutoGrade"]){NSDictionary*d=byKey[key];if(d)[rows addObject:d];}
|
||||
base[@"rows"]=rows;base[@"extraEnabled"]=bySection[@"color"][@"enabled"];
|
||||
return @[input,base,bySection[@"skin"],bySection[@"look"],bySection[@"hsl"],bySection[@"curve"],bySection[@"grading"],bySection[@"primaries"],bySection[@"levels"],bySection[@"blackwhite"],bySection[@"balance"]];
|
||||
base[@"title"]=@"基础调整";
|
||||
return @[input,bySection[@"primary"],bySection[@"output"],base,bySection[@"skin"],bySection[@"look"],bySection[@"hsl"],bySection[@"curve"],bySection[@"grading"],bySection[@"primaries"],bySection[@"levels"],bySection[@"blackwhite"],bySection[@"balance"]];
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +496,7 @@ static NSImage *DYWheelImage(void) {
|
||||
[header setButtonType:NSButtonTypePushOnPushOff];
|
||||
header.bordered=NO; header.alignment=NSTextAlignmentLeft; header.font=[NSFont boldSystemFontOfSize:12];
|
||||
header.contentTintColor=DYInk(); header.target=self; header.action=@selector(toggleSection:); header.tag=index;
|
||||
header.doubleClickAction=@selector(resetSection:); header.toolTip=@"展开启用,折叠停用;双击还原本组";
|
||||
header.doubleClickAction=@selector(resetSection:); header.toolTip=@"展开或折叠界面;双击还原本组";
|
||||
[card addSubview:header];
|
||||
NSButton *enabled=DYButton(@"",self,@selector(groupEnabled:));enabled.bordered=NO;[enabled setButtonType:NSButtonTypePushOnPushOff];enabled.image=[NSImage imageWithSystemSymbolName:@"eye" accessibilityDescription:@"启用本组"];
|
||||
enabled.tag=index; enabled.contentTintColor=DYAccent(); enabled.toolTip=@"启用或旁路本组";
|
||||
@@ -507,8 +508,8 @@ static NSImage *DYWheelImage(void) {
|
||||
[card addSubview:reset];
|
||||
NSMutableArray *body=[NSMutableArray array];
|
||||
NSString *key=section[@"key"]?:@"";
|
||||
if([key localizedCaseInsensitiveContainsString:@"input"]) {
|
||||
[body addObject:[self assetRowForKey:@"input" title:@"输入色彩" inCard:card]];
|
||||
if([key isEqual:@"input"]) {
|
||||
NSButton *migrate=DYButton(@"旧版输入 → 改用 CST",self,@selector(useCST:));migrate.identifier=@"legacyInput";migrate.toolTip=@"保留旧工程输入效果;点击后改用上方 CST 设置,可撤销";[card addSubview:migrate];[body addObject:migrate];
|
||||
}
|
||||
if([key localizedCaseInsensitiveContainsString:@"look"]) {
|
||||
for(NSInteger i=0;i<5;i++) {
|
||||
@@ -552,7 +553,7 @@ static NSImage *DYWheelImage(void) {
|
||||
NSButton *eye=DYButton(@"",self,@selector(itemEnabled:));eye.bordered=NO;[eye setButtonType:NSButtonTypePushOnPushOff];eye.image=[NSImage imageWithSystemSymbolName:@"eye" accessibilityDescription:@"启用"];eye.tag=[pid integerValue];eye.contentTintColor=DYAccent();eye.accessibilityLabel=[d[@"title"] stringByAppendingString:@"启用"];eye.toolTip=@"启用或旁路此项";[row addSubview:eye];record[@"itemEnabled"]=eye;
|
||||
}
|
||||
NSString *kind=d[@"kind"]?:@"float";
|
||||
if([kind isEqualToString:@"bool"]) {
|
||||
if([kind isEqualToString:@"bool"]||[d[@"key"]hasPrefix:@"cmbypass"]) {
|
||||
NSButton *toggle=[NSButton checkboxWithTitle:@"" target:self action:@selector(scalarChanged:)];
|
||||
toggle.tag=[pid integerValue]; toggle.contentTintColor=DYAccent(); toggle.accessibilityLabel=d[@"title"];
|
||||
[row addSubview:toggle]; record[@"toggle"]=toggle;
|
||||
@@ -589,7 +590,7 @@ static NSImage *DYWheelImage(void) {
|
||||
}
|
||||
for(NSView *row in body)if(![ordered containsObject:row])row.hidden=YES;body=ordered;
|
||||
}
|
||||
NSMutableDictionary *record=[NSMutableDictionary dictionaryWithDictionary:@{@"section":section,@"view":card,@"header":header,@"enabled":enabled,@"reset":reset,@"body":body,@"collapsed":@(![section[@"defaultEnabled"]boolValue])}];
|
||||
NSMutableDictionary *record=[NSMutableDictionary dictionaryWithDictionary:@{@"section":section,@"view":card,@"header":header,@"enabled":enabled,@"reset":reset,@"body":body,@"collapsed":@(![@[@"primary",@"base"]containsObject:key])}];
|
||||
if([key isEqual:@"look"]){NSButton *add=DYButton(@"+",self,@selector(addLook:));add.bordered=NO;add.font=[NSFont boldSystemFontOfSize:20];add.accessibilityLabel=@"添加风格 LUT";[card addSubview:add];record[@"add"]=add;}
|
||||
[_cards addObject:record];
|
||||
index++;
|
||||
@@ -611,6 +612,7 @@ static NSImage *DYWheelImage(void) {
|
||||
}
|
||||
- (BOOL)showRow:(NSView *)row section:(NSString *)section {
|
||||
NSString *key=row.identifier?:@"";NSInteger tab=[_tabs[section]integerValue];
|
||||
if([key isEqual:@"legacyInput"])return [_tabs[@"legacyInput"]boolValue];
|
||||
if([section isEqual:@"curve"] && ![key isEqual:@"curveGraph"])return NO;
|
||||
if([section isEqual:@"hsl"]) {
|
||||
int axis=0,color=0;if(sscanf(key.UTF8String,"hsl%d_%d",&axis,&color)==2)return color==tab;
|
||||
@@ -689,7 +691,7 @@ static NSImage *DYWheelImage(void) {
|
||||
if(d[@"enabled"]) {double enabled=1;[get getFloatValue:&enabled fromParameter:[d[@"enabled"] unsignedIntValue] atTime:t];[r[@"itemEnabled"] setState:enabled>=.5?NSControlStateValueOn:NSControlStateValueOff];[r[@"itemEnabled"] setImage:[NSImage imageWithSystemSymbolName:enabled>=.5?@"eye":@"eye.slash" accessibilityDescription:enabled>=.5?@"启用":@"旁路"]];for(NSString *control in @[@"slider",@"field",@"popup"]) [r[control] setAlphaValue:enabled>=.5?1:.45];}
|
||||
[r[@"slider"] setDoubleValue:v]; [r[@"field"] setStringValue:DYNumber(v,d)];
|
||||
[r[@"toggle"] setState:v>=.5?NSControlStateValueOn:NSControlStateValueOff];
|
||||
NSPopUpButton *popup=r[@"popup"]; if(popup.numberOfItems>0) [popup selectItemAtIndex:MAX(0,MIN((NSInteger)llround(v),popup.numberOfItems-1))];
|
||||
NSPopUpButton *popup=r[@"popup"]; if(popup.numberOfItems>0){NSArray *values=d[@"values"];NSInteger index=values?[values indexOfObject:@((int)llround(v))]:(NSInteger)llround(v);[popup selectItemAtIndex:index==NSNotFound?0:MAX(0,MIN(index,popup.numberOfItems-1))];}
|
||||
}
|
||||
for(id graphic in _graphics)[graphic setValues:graphicValues];
|
||||
for(NSMutableDictionary *c in _cards) {
|
||||
@@ -698,19 +700,21 @@ static NSImage *DYWheelImage(void) {
|
||||
NSNumber *extra=c[@"section"][@"extraEnabled"];double extraValue=0;
|
||||
if(extra)[get getFloatValue:&extraValue fromParameter:extra.unsignedIntValue atTime:t];
|
||||
BOOL enabled=v>=.5||extraValue>=.5;
|
||||
BOOL collapsed=!enabled;groupingChanged|=collapsed!=[c[@"collapsed"]boolValue];c[@"collapsed"]=@(collapsed);
|
||||
[c[@"header"]setState:enabled?NSControlStateValueOn:NSControlStateValueOff];
|
||||
[c[@"header"]setToolTip:enabled?@"折叠并停用本组,保留参数值;双击还原本组":@"展开并启用本组,恢复之前的参数值;双击还原本组"];
|
||||
[c[@"header"]setAccessibilityHelp:[c[@"header"]toolTip]];
|
||||
[c[@"header"]setNeedsDisplay:YES];
|
||||
[c[@"enabled"] setState:enabled?NSControlStateValueOn:NSControlStateValueOff];
|
||||
[c[@"enabled"]setImage:[NSImage imageWithSystemSymbolName:enabled?@"eye":@"eye.slash" accessibilityDescription:enabled?@"折叠并停用本组":@"展开并启用本组"]];
|
||||
[c[@"enabled"]setToolTip:enabled?@"折叠并停用本组,保留参数值":@"展开并启用本组,恢复之前的参数值"];
|
||||
[c[@"enabled"]setAccessibilityHelp:[c[@"enabled"]toolTip]];
|
||||
// Visibility and rendering share the host's section enable value.
|
||||
for(NSView *row in c[@"body"])row.alphaValue=1;
|
||||
DYInspectorToken *token=nil;[get getCustomParameterValue:&token fromParameter:DYInspectorParameterID atTime:t];
|
||||
NSNumber *saved=[token isKindOfClass:DYInspectorToken.class]?token.folds[c[@"section"][@"key"]]:nil;
|
||||
BOOL collapsed=saved?saved.boolValue:[c[@"collapsed"]boolValue];groupingChanged|=collapsed!=[c[@"collapsed"]boolValue];c[@"collapsed"]=@(collapsed);
|
||||
[c[@"header"]setState:collapsed?NSControlStateValueOff:NSControlStateValueOn];
|
||||
[c[@"header"]setToolTip:collapsed?@"展开界面,不改变启用状态;双击还原本组":@"折叠界面,保持当前效果;双击还原本组"];
|
||||
[c[@"header"]setAccessibilityHelp:[c[@"header"]toolTip]];[c[@"header"]setNeedsDisplay:YES];
|
||||
[c[@"enabled"]setState:enabled?NSControlStateValueOn:NSControlStateValueOff];
|
||||
[c[@"enabled"]setImage:[NSImage imageWithSystemSymbolName:enabled?@"eye":@"eye.slash" accessibilityDescription:enabled?@"停用本组":@"启用本组"]];
|
||||
[c[@"enabled"]setToolTip:enabled?@"停用本组,保留参数和展开状态":@"启用本组,保留展开状态"];[c[@"enabled"]setAccessibilityHelp:[c[@"enabled"]toolTip]];
|
||||
for(NSView *row in c[@"body"])row.alphaValue=enabled?1:.45;
|
||||
}
|
||||
DYAssetState *assets=DYReadAssets(_manager,t);
|
||||
double profile=0,configured=0;[get getFloatValue:&profile fromParameter:2013 atTime:t];[get getFloatValue:&configured fromParameter:2236 atTime:t];
|
||||
DYInspectorToken *oldToken=nil;[get getCustomParameterValue:&oldToken fromParameter:DYInspectorParameterID atTime:t];
|
||||
_tabs[@"legacyInput"]=@(configured<.5&&(profile>.5||[assets.paths[@"input"]length]||oldToken.schema<2));
|
||||
for(NSString *key in _assetButtons) {
|
||||
NSString *path=assets.paths[key]; NSButton *button=_assetButtons[key][@"choose"];
|
||||
NSString *name=path.length?path.lastPathComponent.stringByDeletingPathExtension:@"无";
|
||||
@@ -731,7 +735,7 @@ static NSImage *DYWheelImage(void) {
|
||||
if(_refreshing)return;
|
||||
NSNumber *pid=@(sender.tag); NSDictionary *r=_controls[pid],*d=r[@"descriptor"]; if(!d)return;
|
||||
double v;
|
||||
if([sender isKindOfClass:[NSPopUpButton class]])v=[(NSPopUpButton *)sender indexOfSelectedItem];
|
||||
if([sender isKindOfClass:[NSPopUpButton class]]){NSInteger i=[(NSPopUpButton *)sender indexOfSelectedItem];v=d[@"values"]?[d[@"values"][i]doubleValue]:i;}
|
||||
else if([sender isKindOfClass:[NSButton class]])v=[(NSButton *)sender state]==NSControlStateValueOn?1:0;
|
||||
else {
|
||||
if([sender isKindOfClass:[NSTextField class]]) {
|
||||
@@ -745,7 +749,7 @@ static NSImage *DYWheelImage(void) {
|
||||
v=fmax([d[@"min"] doubleValue],fmin([d[@"max"] doubleValue],v));
|
||||
id<FxCustomParameterActionAPI_v4> action=[self actionAPI];if(!action)return;
|
||||
[action startAction:self];
|
||||
@try { id<FxParameterSettingAPI_v6> set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; [set setFloatValue:v toParameter:pid.unsignedIntValue atTime:action.currentTime]; }
|
||||
@try { id<FxParameterSettingAPI_v6> set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; [set setFloatValue:v toParameter:pid.unsignedIntValue atTime:action.currentTime];if([d[@"key"]hasPrefix:@"cm"])[set setFloatValue:1 toParameter:2236 atTime:action.currentTime]; }
|
||||
@finally { [action endAction:self]; }
|
||||
[self postChanged];
|
||||
}
|
||||
@@ -792,7 +796,19 @@ static NSImage *DYWheelImage(void) {
|
||||
- (void)groupEnabled:(NSButton *)sender { [self setSectionEnabled:sender.state==NSControlStateValueOn atIndex:sender.tag]; }
|
||||
- (void)toggleSection:(NSButton *)sender {
|
||||
if(sender.tag<0||sender.tag>=_cards.count)return;
|
||||
[self setSectionEnabled:[_cards[sender.tag][@"collapsed"]boolValue] atIndex:sender.tag];
|
||||
id<FxCustomParameterActionAPI_v4> action=[self actionAPI];if(!action)return;[action startAction:self];
|
||||
@try {
|
||||
id<FxParameterRetrievalAPI_v6> get=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];id<FxParameterSettingAPI_v6> set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];
|
||||
DYInspectorToken *old=nil;[get getCustomParameterValue:&old fromParameter:DYInspectorParameterID atTime:action.currentTime];DYInspectorToken *token=[old isKindOfClass:DYInspectorToken.class]?[[old copy]autorelease]:[[[DYInspectorToken alloc]init]autorelease];
|
||||
NSMutableDictionary *folds=[[token.folds mutableCopy]autorelease];
|
||||
for(NSDictionary *card in _cards)folds[card[@"section"][@"key"]]=card[@"collapsed"];
|
||||
NSString *key=_cards[sender.tag][@"section"][@"key"];folds[key]=@(![_cards[sender.tag][@"collapsed"]boolValue]);token.folds=folds;
|
||||
[set setCustomParameterValue:token toParameter:DYInspectorParameterID atTime:action.currentTime];
|
||||
}@finally{[action endAction:self];}[self postChanged];
|
||||
}
|
||||
- (void)useCST:(id)sender {
|
||||
id<FxCustomParameterActionAPI_v4> a=[self actionAPI];if(!a)return;[a startAction:self];
|
||||
@try{id<FxParameterSettingAPI_v6> set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];[set setFloatValue:1 toParameter:2236 atTime:a.currentTime];} @finally{[a endAction:self];}[self postChanged];
|
||||
}
|
||||
- (void)resetSection:(NSButton *)sender {
|
||||
[self cancelAssetLoads];
|
||||
@@ -827,6 +843,8 @@ static NSImage *DYWheelImage(void) {
|
||||
CMTime t=action.currentTime;id<FxParameterSettingAPI_v6> set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];
|
||||
for(NSDictionary *d in DYDescriptors())[set setFloatValue:[d[@"default"] doubleValue] toParameter:[d[@"pid"] unsignedIntValue] atTime:t];
|
||||
DYAssetState *assets=[[[DYAssetState alloc] init] autorelease];assets.paths=@{};DYWriteAssets(_manager,assets,t);
|
||||
[set setCustomParameterValue:[[[DYInspectorToken alloc]init]autorelease] toParameter:DYInspectorParameterID atTime:t];
|
||||
for(NSMutableDictionary *card in _cards)card[@"collapsed"]=@(![@[@"primary",@"base"]containsObject:card[@"section"][@"key"]]);
|
||||
} @finally {[action endAction:self];}
|
||||
[self postChanged];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ FOUNDATION_EXPORT void DYReadUniforms(id<PROAPIAccessing> manager,CMTime time,DY
|
||||
@property(copy) NSDictionary *paths;
|
||||
@end
|
||||
@interface DYInspectorToken : NSObject<NSSecureCoding,NSCopying,FxCustomParameterInterpolation_v2>
|
||||
@property(copy) NSDictionary *folds;
|
||||
@property NSInteger schema;
|
||||
@end
|
||||
FOUNDATION_EXPORT DYAssetState *DYReadAssets(id<PROAPIAccessing> manager,CMTime time);
|
||||
FOUNDATION_EXPORT BOOL DYWriteAssets(id<PROAPIAccessing> manager,DYAssetState *assets,CMTime time);
|
||||
+114
-10
@@ -7,16 +7,116 @@ static NSDictionary *row(NSString*k,NSString*t,NSUInteger o,double lo,double hi,
|
||||
NSMutableDictionary*r=[@{@"key":k,@"title":t,@"pid":@(PID(o)),@"offset":@(o),@"min":@(lo),@"max":@(hi),@"default":@(d),@"step":@(hi-lo>10?1:.01),@"kind":kind?:@"float"}mutableCopy];
|
||||
[descriptors addObject:r];return [r autorelease];
|
||||
}
|
||||
static void section(NSString*k,NSString*t,NSUInteger offset,NSArray*rows,double def=0){
|
||||
static void section(NSString*k,NSString*t,NSUInteger offset,NSArray*rows,double def=1){
|
||||
NSDictionary*e=row([k stringByAppendingString:@"Enabled"],t,offset,0,1,def,@"bool");
|
||||
[sections addObject:@{@"key":k,@"title":t,@"enabled":e[@"pid"],@"defaultEnabled":@(def),@"rows":rows}];
|
||||
}
|
||||
static NSDictionary *scalar(NSString*k,NSString*t,NSUInteger o,double lo=-100,double hi=100,double def=0){return row(k,t,o,lo,hi,def,@"float");}
|
||||
NSArray<NSDictionary *> *DYCMSceneSpaces(void) { return @[
|
||||
@{ @"id":@99, @"name":@"KOLOR Default" },
|
||||
@{ @"id":@1, @"name":@"ACEScct" },
|
||||
@{ @"id":@2, @"name":@"Apple Log" },
|
||||
@{ @"id":@3, @"name":@"Apple Log 2" },
|
||||
@{ @"id":@4, @"name":@"ARRI LogC3" },
|
||||
@{ @"id":@5, @"name":@"ARRI LogC4" },
|
||||
@{ @"id":@6, @"name":@"Blackmagic Film Gen 5" },
|
||||
@{ @"id":@7, @"name":@"Canon C-Log" },
|
||||
@{ @"id":@8, @"name":@"Canon C-Log 2" },
|
||||
@{ @"id":@9, @"name":@"Canon C-Log 3" },
|
||||
@{ @"id":@10, @"name":@"DaVinci Intermediate" },
|
||||
@{ @"id":@11, @"name":@"DJI D-Log" },
|
||||
@{ @"id":@12, @"name":@"DJI D-Log 2" },
|
||||
@{ @"id":@13, @"name":@"DJI D-Log M" },
|
||||
@{ @"id":@14, @"name":@"Fujifilm F-Log" },
|
||||
@{ @"id":@15, @"name":@"Fujifilm F-Log2" },
|
||||
@{ @"id":@16, @"name":@"Fujifilm F-Log2 C" },
|
||||
@{ @"id":@17, @"name":@"GoPro GP-Log" },
|
||||
@{ @"id":@18, @"name":@"GoPro GP-Log2" },
|
||||
@{ @"id":@30, @"name":@"GoPro GP-Log2 (Official, 0 EV)" },
|
||||
@{ @"id":@29, @"name":@"Insta I-Log" },
|
||||
@{ @"id":@19, @"name":@"Leica L-Log" },
|
||||
@{ @"id":@20, @"name":@"Linear" },
|
||||
@{ @"id":@21, @"name":@"Nikon N-Log" },
|
||||
@{ @"id":@22, @"name":@"Panasonic V-Log" },
|
||||
@{ @"id":@23, @"name":@"Phantom Log 1" },
|
||||
@{ @"id":@24, @"name":@"Phantom Log 2" },
|
||||
@{ @"id":@25, @"name":@"REDLog3G10" },
|
||||
@{ @"id":@26, @"name":@"Samsung Log" },
|
||||
@{ @"id":@27, @"name":@"Sony S-Log2" },
|
||||
@{ @"id":@28, @"name":@"Sony S-Log3" }
|
||||
]; }
|
||||
NSArray<NSDictionary *> *DYCMDisplaySpaces(void) { return @[
|
||||
@{ @"id":@1001, @"name":@"Gamma 2.2" },
|
||||
@{ @"id":@1002, @"name":@"Gamma 2.4" },
|
||||
@{ @"id":@1003, @"name":@"Gamma 2.6" }
|
||||
]; }
|
||||
NSArray<NSDictionary *> *DYCMGamuts(void) { return @[
|
||||
@{ @"id":@99, @"name":@"KOLOR Default" },
|
||||
@{ @"id":@1, @"name":@"ACES AP0" },
|
||||
@{ @"id":@2, @"name":@"ACES AP1" },
|
||||
@{ @"id":@3, @"name":@"Apple Log 2" },
|
||||
@{ @"id":@4, @"name":@"ARRI WG3" },
|
||||
@{ @"id":@5, @"name":@"ARRI WG4" },
|
||||
@{ @"id":@6, @"name":@"Blackmagic Wide Gamut" },
|
||||
@{ @"id":@7, @"name":@"Canon Cinema Gamut" },
|
||||
@{ @"id":@16, @"name":@"DaVinci Wide Gamut" },
|
||||
@{ @"id":@8, @"name":@"DJI Action 5" },
|
||||
@{ @"id":@9, @"name":@"DJI Air 2S" },
|
||||
@{ @"id":@10, @"name":@"DJI D-Gamut" },
|
||||
@{ @"id":@28, @"name":@"DJI D-Gamut 2" },
|
||||
@{ @"id":@11, @"name":@"DJI Mavic2 Pro" },
|
||||
@{ @"id":@12, @"name":@"DJI Mavic 3 Pro" },
|
||||
@{ @"id":@13, @"name":@"DJI Mini 4 Pro" },
|
||||
@{ @"id":@14, @"name":@"DJI Mini 5 Pro" },
|
||||
@{ @"id":@15, @"name":@"DJI Pocket 3" },
|
||||
@{ @"id":@17, @"name":@"Fujifilm F-GamutC" },
|
||||
@{ @"id":@18, @"name":@"GoPro GP-Log" },
|
||||
@{ @"id":@19, @"name":@"P3-DCI" },
|
||||
@{ @"id":@20, @"name":@"P3 D65" },
|
||||
@{ @"id":@21, @"name":@"Panasonic V-Gamut" },
|
||||
@{ @"id":@22, @"name":@"Rec.709 / BT.709" },
|
||||
@{ @"id":@23, @"name":@"Rec.2020 / BT.2020" },
|
||||
@{ @"id":@24, @"name":@"RED Wide Gamut RGB" },
|
||||
@{ @"id":@25, @"name":@"Sony S-Gamut" },
|
||||
@{ @"id":@26, @"name":@"Sony S-Gamut3" },
|
||||
@{ @"id":@27, @"name":@"Sony S-Gamut3.Cine" }
|
||||
]; }
|
||||
|
||||
static NSDictionary *cmRow(NSString*k,NSString*t,NSUInteger o,double lo,double hi,double def,int tab,NSArray *choices=nil){
|
||||
NSMutableDictionary *d=[[row(k,t,offsetof(DYUniforms,cm)+o,lo,hi,def,choices?@"popup":@"float")mutableCopy]autorelease];d[@"cmTab"]=@(tab);
|
||||
if(choices){d[@"options"]=[choices valueForKey:@"name"];d[@"values"]=[choices valueForKey:@"id"];}
|
||||
[descriptors replaceObjectAtIndex:descriptors.count-1 withObject:d];return d;
|
||||
}
|
||||
static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{
|
||||
sections=[[NSMutableArray alloc]init];descriptors=[[NSMutableArray alloc]init];
|
||||
NSMutableDictionary*profile=[[scalar(@"inputProfile",@"相机输入",52,0,17)mutableCopy]autorelease];profile[@"kind"]=@"popup";profile[@"options"]=@[@"无",@"Apple Log",@"ARRI LogC3",@"ARRI LogC4",@"Blackmagic Film Gen5",@"Canon C-Log",@"Canon C-Log2",@"Canon C-Log3",@"DJI D-Log",@"DJI D-Log M",@"Fujifilm F-Log",@"Fujifilm F-Log2",@"Nikon N-Log",@"Panasonic V-Log",@"RED Log3G10",@"Sony S-Log2",@"Sony S-Log3",@"Sony HLG"];
|
||||
[descriptors replaceObjectAtIndex:0 withObject:profile];
|
||||
section(@"input",@"输入 / LUT",132,@[profile,scalar(@"preLUTStrength",@"输入强度",56,0,1,1)]);
|
||||
// Legacy IDs remain registered for existing FCP documents and presets.
|
||||
scalar(@"preLUTStrength",@"旧版输入强度",56,0,1,1);
|
||||
row(@"cmConfigured",@"CST 配置版本",offsetof(DYUniforms,cm)+offsetof(DYCMSettings,configured),0,1,0,@"bool");
|
||||
NSArray *transfers=[DYCMSceneSpaces() arrayByAddingObjectsFromArray:DYCMDisplaySpaces()];
|
||||
NSMutableArray *cm=[NSMutableArray array];
|
||||
#define CM(f,t,lo,hi,def,tab) [cm addObject:cmRow(@"cm" #f,t,offsetof(DYCMSettings,f),lo,hi,def,tab)]
|
||||
#define CH(f,t,def,tab,list) [cm addObject:cmRow(@"cm" #f,t,offsetof(DYCMSettings,f),0,1003,def,tab,list)]
|
||||
CM(inputEnabled,@"输入转换启用",0,1,1,0);
|
||||
CH(inputTransfer,@"输入曲线",1002,0,transfers);CH(inputGamut,@"输入色域",22,0,DYCMGamuts());
|
||||
CH(workingTransfer,@"工作曲线",10,0,transfers);CH(workingGamut,@"工作色域",16,0,DYCMGamuts());
|
||||
CM(mix,@"CST 混合",0,1,1,0);
|
||||
CM(basisEnabled,@"一级调色启用",0,1,1,1);
|
||||
CM(exposure,@"一级曝光",-5,5,0,1);CM(balanceAngle,@"色彩平衡方向",0,1,0,1);CM(balanceStrength,@"色彩平衡强度",0,1,0,1);CM(saturation,@"一级饱和度",0,2,1,1);
|
||||
CM(contrast,@"一级对比度",-1,1,0,1);CM(pivot,@"对比度轴心",-3,3,0,1);CM(hiContrast,@"高光对比度",-1,1,0,1);CM(hiPivot,@"高光轴心",-1,1,0,1);CM(shadowContrast,@"阴影对比度",-1,1,0,1);CM(shadowPivot,@"阴影轴心",-1,1,0,1);
|
||||
CM(white,@"白点",.5,1.5,1,1);CM(shoulder,@"肩部压缩",0,1,.5,1);CM(highlights,@"一级高光",-1,1,0,1);CM(midtones,@"一级中间调",-1,1,0,1);CM(shadows,@"一级阴影",-1,1,0,1);CM(black,@"黑点",-1,1,0,1);CM(toe,@"趾部压缩",0,1,.5,1);CM(chromaMix,@"色度混合",0,1,.5,1);
|
||||
CM(bypassExposure,@"旁路一级曝光",0,1,0,1);CM(bypassBalance,@"旁路一级色彩",0,1,0,1);CM(bypassContrast,@"旁路一级对比",0,1,0,1);CM(bypassTone,@"旁路一级影调",0,1,0,1);
|
||||
CM(outputEnabled,@"输出转换启用",0,1,1,2);CH(outputTransfer,@"输出曲线",1002,2,transfers);CH(outputGamut,@"输出色域",22,2,DYCMGamuts());
|
||||
[cm addObject:cmRow(@"cmtoneMapping",@"输出色调映射",offsetof(DYCMSettings,toneMapping),0,1,0,2,@[@{@"id":@0,@"name":@"关闭"},@{@"id":@1,@"name":@"开启"}])];
|
||||
#undef CM
|
||||
#undef CH
|
||||
NSMutableArray *input=[NSMutableArray array],*primary=[NSMutableArray array],*output=[NSMutableArray array];
|
||||
for(NSDictionary *d in cm){NSString *key=d[@"key"];if([@[@"cminputEnabled",@"cmbasisEnabled",@"cmoutputEnabled"]containsObject:key])continue;[([d[@"cmTab"]intValue]==0?input:[d[@"cmTab"]intValue]==1?primary:output) addObject:d];}
|
||||
section(@"input",@"输入转换 / CST",132,input);
|
||||
// Enable descriptors already exist; do not register the same offset twice.
|
||||
[sections addObject:@{@"key":@"primary",@"title":@"一级调色",@"enabled":@(PID(offsetof(DYUniforms,cm)+offsetof(DYCMSettings,basisEnabled))),@"defaultEnabled":@1,@"rows":primary}];
|
||||
[sections addObject:@{@"key":@"output",@"title":@"输出转换 / CST",@"enabled":@(PID(offsetof(DYUniforms,cm)+offsetof(DYCMSettings,outputEnabled))),@"defaultEnabled":@1,@"rows":output}];
|
||||
NSMutableArray*base=[NSMutableArray array];
|
||||
NSArray*names=@[@"曝光",@"对比度",@"高光",@"阴影",@"白色色阶",@"黑色色阶",@"色温",@"色调",@"饱和度",@"鲜艳度",@"纹理",@"清晰度",@"去朦胧"];
|
||||
NSArray*keys=@[@"exposure",@"contrast",@"highlights",@"shadows",@"whites",@"blacks",@"temperature",@"tint",@"saturation",@"vibrance",@"texture",@"clarity",@"dehaze"];
|
||||
@@ -28,7 +128,7 @@ static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{
|
||||
NSDictionary*copyAuto=@{@"key":@"copyAutoGrade",@"title":@"复制时自动调色",@"pid":@8800,@"offset":@(-1),@"min":@0,@"max":@1,@"default":@0,@"step":@1,@"kind":@"bool",@"notAnimatable":@YES};[descriptors addObject:copyAuto];
|
||||
section(@"base",@"基础调色",136,[[[base subarrayWithRange:NSMakeRange(0,6)]arrayByAddingObjectsFromArray:[base subarrayWithRange:NSMakeRange(10,3)]]arrayByAddingObject:copyAuto],1);
|
||||
section(@"color",@"白平衡与颜色",140,@[base[6],base[7],base[9],base[8]],1);
|
||||
section(@"skin",@"肤色保护",464,@[scalar(@"skinStrength",@"保护程度",468,0,100,60),scalar(@"skinHue",@"肤色色相",472,0,60,28)],0);
|
||||
section(@"skin",@"肤色保护",464,@[scalar(@"skinStrength",@"保护程度",468,0,100,60),scalar(@"skinHue",@"肤色色相",472,0,60,28)],1);
|
||||
NSMutableArray*look=[NSMutableArray arrayWithObject:scalar(@"postLUTStrength",@"风格 1 强度",60,0,1,1)];
|
||||
for(int i=0;i<4;i++){[look addObject:row([NSString stringWithFormat:@"look%dEnabled",i+2],[NSString stringWithFormat:@"风格 %d 启用",i+2],160+i*4,0,1,1,@"bool")];[look addObject:scalar([NSString stringWithFormat:@"look%dStrength",i+2],[NSString stringWithFormat:@"风格 %d 强度",i+2],64+i*4,0,1,1)];}
|
||||
section(@"look",@"风格 LUT",144,look);
|
||||
@@ -49,12 +149,14 @@ static void initialize(){static dispatch_once_t once;dispatch_once(&once,^{
|
||||
[grade addObject:scalar(@"gradingBlending",@"混合",404,0,100,50)];[grade addObject:scalar(@"gradingBalance",@"平衡",408)];section(@"grading",@"颜色分级",400,grade);
|
||||
NSMutableArray*prim=[NSMutableArray array];for(int c=0;c<3;c++)for(int a=0;a<2;a++)[prim addObject:scalar([NSString stringWithFormat:@"primary%d_%d",c,a],[NSString stringWithFormat:@"%@原色 %@",@[@"红",@"绿",@"蓝"][c],a?@"饱和度":@"色相"],484+c*8+a*4)];section(@"primaries",@"三原色",480,prim);
|
||||
NSMutableArray*levels=[NSMutableArray array];for(int c=0;c<4;c++)for(int a=0;a<5;a++)[levels addObject:scalar([NSString stringWithFormat:@"level%d_%d",c,a],[NSString stringWithFormat:@"%@ %@",@[@"RGB",@"红",@"绿",@"蓝"][c],@[@"输入黑",@"伽马",@"输入白",@"输出黑",@"输出白"][a]],624+a*16+c*4,a==1?.1:0,a==1?10:255,a==1?1:(a==2||a==4)?255:0)];section(@"levels",@"色阶",608,levels);
|
||||
NSMutableArray*bw=[NSMutableArray array];for(int c=0;c<6;c++)[bw addObject:scalar([NSString stringWithFormat:@"bw%d",c],[NSString stringWithFormat:@"黑白 %@",@[@"红",@"黄",@"绿",@"青",@"蓝",@"洋红"][c]],c<4?720+c*4:736+(c-4)*4,0,200,((double[]){40,60,40,60,20,80})[c])];[bw addObject:scalar(@"bwHue",@"着色色相",744,0,360)];[bw addObject:scalar(@"bwSat",@"着色饱和度",748,0,100)];section(@"blackwhite",@"黑白混色",704,bw,0);
|
||||
NSMutableArray*bw=[NSMutableArray array];for(int c=0;c<6;c++)[bw addObject:scalar([NSString stringWithFormat:@"bw%d",c],[NSString stringWithFormat:@"黑白 %@",@[@"红",@"黄",@"绿",@"青",@"蓝",@"洋红"][c]],c<4?720+c*4:736+(c-4)*4,0,200,((double[]){40,60,40,60,20,80})[c])];[bw addObject:scalar(@"bwHue",@"着色色相",744,0,360)];[bw addObject:scalar(@"bwSat",@"着色饱和度",748,0,100)];[bw insertObject:scalar(@"blackWhiteMix",@"黑白混合",offsetof(DYUniforms,cm)+offsetof(DYCMSettings,blackWhiteMix),0,1,0) atIndex:0];section(@"blackwhite",@"黑白混色",704,bw,1);
|
||||
NSMutableArray*balance=[NSMutableArray arrayWithObject:row(@"preserveLuma",@"保持明度",756,0,1,1,@"bool")];for(int c=0;c<3;c++)for(int a=0;a<3;a++)[balance addObject:scalar([NSString stringWithFormat:@"balance%d_%d",c,a],[NSString stringWithFormat:@"%@ %@",@[@"阴影",@"中间调",@"高光"][c],@[@"青 ↔ 红",@"洋红 ↔ 绿",@"黄 ↔ 蓝"][a]],768+c*16+a*4)];section(@"balance",@"色彩平衡",752,balance);
|
||||
});}
|
||||
NSArray<NSDictionary*> *DYSections(void){initialize();return sections;} NSArray<NSDictionary*> *DYDescriptors(void){initialize();return descriptors;}
|
||||
void DYDefaultUniforms(DYUniforms*u){memset(u,0,sizeof(*u));for(NSDictionary*r in DYDescriptors())if([r[@"offset"]integerValue]>=0)*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=[r[@"default"]floatValue];u->primariesM0=(DYFloat3){1,0,0};u->primariesM1=(DYFloat3){0,1,0};u->primariesM2=(DYFloat3){0,0,1};}
|
||||
void DYReadUniforms(id<PROAPIAccessing>m,CMTime t,DYUniforms*u){DYDefaultUniforms(u);id<FxParameterRetrievalAPI_v6>g=[m apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];for(NSDictionary*r in DYDescriptors()){if([r[@"offset"]integerValue]<0)continue;double v=[r[@"default"]doubleValue];if([g getFloatValue:&v fromParameter:[r[@"pid"]unsignedIntValue] atTime:t]&&std::isfinite(v))*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=fmin([r[@"max"]doubleValue],fmax([r[@"min"]doubleValue],v));}}
|
||||
void DYReadUniforms(id<PROAPIAccessing>m,CMTime t,DYUniforms*u){DYDefaultUniforms(u);id<FxParameterRetrievalAPI_v6>g=[m apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];for(NSDictionary*r in DYDescriptors()){if([r[@"offset"]integerValue]<0)continue;double v=[r[@"default"]doubleValue];if([g getFloatValue:&v fromParameter:[r[@"pid"]unsignedIntValue] atTime:t]&&std::isfinite(v))*(float*)((uint8_t*)u+[r[@"offset"]unsignedIntegerValue])=fmin([r[@"max"]doubleValue],fmax([r[@"min"]doubleValue],v));}NSObject<NSSecureCoding,NSCopying> *token=nil;[g getCustomParameterValue:&token fromParameter:DYInspectorParameterID atTime:t];
|
||||
if([token isKindOfClass:DYInspectorToken.class]&&[(DYInspectorToken*)token schema]<2){if(u->cm.configured<.5)u->cm.configured=-1;u->cm.blackWhiteMix=1;}
|
||||
}
|
||||
BOOL DYCreateParameters(id<PROAPIAccessing>m,NSError**error){id<FxParameterCreationAPI_v5>a=[m apiForProtocol:@protocol(FxParameterCreationAPI_v5)];BOOL ok=a!=nil;
|
||||
ok=[a addCustomParameterWithName:@"大鱼调色" parameterID:DYInspectorParameterID defaultValue:[[[DYInspectorToken alloc]init]autorelease] parameterFlags:kFxParameterFlag_CUSTOM_UI|kFxParameterFlag_USE_FULL_VIEW_WIDTH|kFxParameterFlag_DONT_DISPLAY_IN_DASHBOARD|kFxParameterFlag_NOT_ANIMATABLE]&&ok;
|
||||
for(NSDictionary*r in DYDescriptors())ok=[a addFloatSliderWithName:r[@"title"] parameterID:[r[@"pid"]unsignedIntValue] defaultValue:[r[@"default"]doubleValue] parameterMin:[r[@"min"]doubleValue] parameterMax:[r[@"max"]doubleValue] sliderMin:[r[@"min"]doubleValue] sliderMax:[r[@"max"]doubleValue] delta:[r[@"step"]doubleValue] parameterFlags:kFxParameterFlag_HIDDEN|([r[@"notAnimatable"]boolValue]?kFxParameterFlag_NOT_ANIMATABLE:0)]&&ok;
|
||||
@@ -73,12 +175,14 @@ BOOL DYCreateParameters(id<PROAPIAccessing>m,NSError**error){id<FxParameterCreat
|
||||
@end
|
||||
@implementation DYInspectorToken
|
||||
+ (BOOL)supportsSecureCoding{return YES;}
|
||||
- (void)encodeWithCoder:(NSCoder*)c{[c encodeInt:1 forKey:@"schema"];}
|
||||
- (instancetype)initWithCoder:(NSCoder*)c{return [self init];}
|
||||
- (id)copyWithZone:(NSZone*)z{return [[[self class]allocWithZone:z]init];}
|
||||
- (instancetype)init{if((self=[super init])){_folds=[@{} copy];_schema=2;}return self;}
|
||||
- (void)dealloc{[_folds release];[super dealloc];}
|
||||
- (void)encodeWithCoder:(NSCoder*)c{[c encodeInteger:_schema forKey:@"schema"];[c encodeObject:_folds forKey:@"folds"];}
|
||||
- (instancetype)initWithCoder:(NSCoder*)c{if((self=[self init])){NSDictionary *v=[c decodeObjectOfClasses:[NSSet setWithObjects:NSDictionary.class,NSString.class,NSNumber.class,nil] forKey:@"folds"];if(v)self.folds=v;_schema=[c decodeIntegerForKey:@"schema"];}return self;}
|
||||
- (id)copyWithZone:(NSZone*)z{DYInspectorToken *v=[[[self class]allocWithZone:z]init];v.folds=_folds;v.schema=_schema;return v;}
|
||||
- (id)interpolateBetween:(id)r withWeight:(float)w{return [[self copy]autorelease];}
|
||||
- (BOOL)isEqual:(id)o{return [o isKindOfClass:self.class];}
|
||||
- (NSUInteger)hash{return 1;}
|
||||
- (BOOL)isEqual:(id)o{return [o isKindOfClass:self.class]&&_schema==[o schema]&&[_folds isEqual:[o folds]];}
|
||||
- (NSUInteger)hash{return _folds.hash;}
|
||||
@end
|
||||
DYAssetState*DYReadAssets(id<PROAPIAccessing>m,CMTime t){DYAssetState*v=nil;id<FxParameterRetrievalAPI_v6>g=[m apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];[g getCustomParameterValue:&v fromParameter:DYAssetsParameterID atTime:t];return [v isKindOfClass:DYAssetState.class]?v:[[[DYAssetState alloc]init]autorelease];}
|
||||
BOOL DYWriteAssets(id<PROAPIAccessing>m,DYAssetState*v,CMTime t){id<FxParameterSettingAPI_v6>s=[m apiForProtocol:@protocol(FxParameterSettingAPI_v6)];return [s setCustomParameterValue:v toParameter:DYAssetsParameterID atTime:t];}
|
||||
+2
-2
@@ -12,9 +12,9 @@
|
||||
- (void)dealloc{[NSNotificationCenter.defaultCenter removeObserver:self];[_renderer release];[super dealloc];}
|
||||
- (BOOL)properties:(NSDictionary**)p error:(NSError**)e{*p=@{kFxPropertyKey_MayRemapTime:@NO,kFxPropertyKey_PixelTransformSupport:@(kFxPixelTransform_ScaleTranslate),kFxPropertyKey_VariesWhenParamsAreStatic:@NO,kFxPropertyKey_DesiredProcessingColorInfo:@(kFxImageColorInfo_RGB_LINEAR),kFxPropertyKey_NeedsFullBuffer:@YES};return YES;}
|
||||
- (BOOL)addParametersWithError:(NSError**)e{return DYCreateParameters(_apiManager,e);}
|
||||
- (NSSet<Class>*)classesForCustomParameterID:(UInt32)pid{return pid==DYAssetsParameterID?[NSSet setWithObjects:DYAssetState.class,NSDictionary.class,NSString.class,nil]:[NSSet setWithObject:DYInspectorToken.class];}
|
||||
- (NSSet<Class>*)classesForCustomParameterID:(UInt32)pid{return pid==DYAssetsParameterID?[NSSet setWithObjects:DYAssetState.class,NSDictionary.class,NSString.class,nil]:[NSSet setWithObjects:DYInspectorToken.class,NSDictionary.class,NSString.class,NSNumber.class,nil];}
|
||||
- (NSView*)createViewForParameterID:(UInt32)pid{return pid==DYInspectorParameterID?[[DYInspector alloc]initWithAPIManager:_apiManager renderer:_renderer]:[[NSView alloc]initWithFrame:NSZeroRect];}
|
||||
- (BOOL)parameterChanged:(UInt32)pid atTime:(CMTime)t error:(NSError**)e{if(pid==2013||pid==2014||pid==DYAssetsParameterID)[_renderer invalidatePreview];dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self.apiManager];});return YES;}
|
||||
- (BOOL)parameterChanged:(UInt32)pid atTime:(CMTime)t error:(NSError**)e{if(pid==2013||pid==2014||(pid>=2236&&pid<2400)||pid==DYAssetsParameterID)[_renderer invalidatePreview];dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:self.apiManager];});return YES;}
|
||||
- (BOOL)pluginState:(NSData**)state atTime:(CMTime)t quality:(FxQuality)q error:(NSError**)e{
|
||||
DYUniforms u;DYReadUniforms(_apiManager,t,&u);DYAssetState*a=DYReadAssets(_apiManager,t);double copyAuto=0;[[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getFloatValue:©Auto fromParameter:8800 atTime:t];NSDictionary*s=@{@"schema":@1,@"copyAuto":@(copyAuto>.5),@"uniforms":[NSData dataWithBytes:&u length:sizeof(u)],@"paths":a.paths?:@{}};*state=[NSPropertyListSerialization dataWithPropertyList:s format:NSPropertyListBinaryFormat_v1_0 options:0 error:e];return *state!=nil;
|
||||
}
|
||||
|
||||
+40
-8
@@ -8,6 +8,20 @@
|
||||
static BOOL fail(NSError**e,NSString*m){if(e)*e=[NSError errorWithDomain:@"com.dayu.color" code:1 userInfo:@{NSLocalizedDescriptionKey:m?:@"Metal 调色失败"}];return NO;}
|
||||
static NSArray *inputFiles(){return @[@"",@"apple_log_to_rec709",@"arri_logc3_to_rec709",@"arri_logc4_to_rec709",@"blackmagic_film_gen5_to_rec709",@"canon_clog_bt709_to_rec709",@"canon_clog2_cinema_gamut_to_rec709",@"canon_clog3_cinema_gamut_to_rec709",@"dji_dlog_to_rec709",@"dji_dlog_m_to_rec709",@"fujifilm_flog_to_rec709",@"fujifilm_flog2_to_rec709",@"nikon_nlog_to_rec709",@"panasonic_vlog_vgamut_to_rec709",@"red_log3g10_rwg_to_rec709",@"sony_slog2_sgamut_to_rec709",@"sony_slog3_sgamut3cine_to_rec709",@"sony_hlg_bt2020_to_rec709"];}
|
||||
static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){MTLTextureDescriptor*t=[MTLTextureDescriptor new];t.textureType=MTLTextureType3D;t.pixelFormat=MTLPixelFormatRGBA32Float;t.width=n;t.height=n;t.depth=n;t.storageMode=MTLStorageModeShared;t.usage=MTLTextureUsageShaderRead;id<MTLTexture>x=[d newTextureWithDescriptor:t];[t release];if(x)[x replaceRegion:MTLRegionMake3D(0,0,0,n,n,n) mipmapLevel:0 slice:0 withBytes:values bytesPerRow:n*16 bytesPerImage:n*n*16];return [x autorelease];}
|
||||
// A synthetic texture lattice uses exactly the production render path for Cube export.
|
||||
@interface DYExportTile : FxImageTile { id<MTLTexture> _tex; uint64_t _registry; }
|
||||
- (instancetype)initWithTexture:(id<MTLTexture>)texture registry:(uint64_t)registry;
|
||||
@end
|
||||
@implementation DYExportTile
|
||||
- (instancetype)initWithTexture:(id<MTLTexture>)texture registry:(uint64_t)registry{if((self=[super init])){_tex=[texture retain];_registry=registry;}return self;}
|
||||
- (void)dealloc{[_tex release];[super dealloc];}
|
||||
- (id<MTLTexture>)metalTextureForDevice:(id<MTLDevice>)d{return d.registryID==_registry?_tex:nil;}
|
||||
- (FxRect)tilePixelBounds{return (FxRect){0,0,(SInt32)_tex.width,(SInt32)_tex.height};}
|
||||
- (FxRect)imagePixelBounds{return self.tilePixelBounds;}
|
||||
- (uint64_t)deviceRegistryID{return _registry;}
|
||||
- (FxImageOrigin)imageOrigin{return kFxImageOrigin_TOP_LEFT;}
|
||||
@end
|
||||
static BOOL managed(DYUniforms u,NSDictionary *paths){return u.cm.configured>=0&&(u.cm.configured>.5||(![paths[@"input"]length]&&u.inputProfile<.5));}
|
||||
@interface DYRenderer(){
|
||||
NSMutableDictionary *_devices,*_luts,*_preparedLUTs;
|
||||
NSSet *_activeLUTPaths;
|
||||
@@ -16,6 +30,7 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
|
||||
NSObject *_previewLock;
|
||||
NSData *_preview,*_lookLUTPreview;
|
||||
CFTimeInterval _lastPreview;
|
||||
BOOL _exporting;
|
||||
}
|
||||
@end
|
||||
@implementation DYRenderer
|
||||
@@ -52,7 +67,7 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
|
||||
NSURL*url=[[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"];
|
||||
id<MTLLibrary>lib=[d newLibraryWithURL:url error:err];if(!lib){[d release];return nil;}
|
||||
id<MTLCommandQueue>q=[d newCommandQueue];entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"library":lib,@"queue":q,@"pipelines":[NSMutableDictionary dictionary]}];
|
||||
for(NSString*fn in @[@"dyUnpremultiply",@"dyWhitesSceneStatistics",@"dyLUTExportKernel",@"dyInputAnalysis"]){id<MTLFunction>f=[lib newFunctionWithName:fn];if(!f){fail(err,[fn stringByAppendingString:@" 缺失"]);[lib release];[q release];[d release];return nil;}id<MTLComputePipelineState>p=[d newComputePipelineStateWithFunction:f error:err];[f release];if(!p){[lib release];[q release];[d release];return nil;}entry[fn]=p;[p release];}
|
||||
for(NSString*fn in @[@"dyUnpremultiply",@"dyWhitesSceneStatistics",@"dyLUTExportKernel",@"dyInputAnalysis",@"dyColorManagement"]){id<MTLFunction>f=[lib newFunctionWithName:fn];if(!f){fail(err,[fn stringByAppendingString:@" 缺失"]);[lib release];[q release];[d release];return nil;}id<MTLComputePipelineState>p=[d newComputePipelineStateWithFunction:f error:err];[f release];if(!p){[lib release];[q release];[d release];return nil;}entry[fn]=p;[p release];}
|
||||
float identity[32];for(int z=0;z<2;z++)for(int y=0;y<2;y++)for(int x=0;x<2;x++){int i=((z*2+y)*2+x)*4;identity[i]=x;identity[i+1]=y;identity[i+2]=z;identity[i+3]=1;}id<MTLTexture>neutral=texture3D(d,identity,2);if(!neutral){fail(err,@"无法分配中性 LUT");return nil;}entry[@"identity"]=neutral;
|
||||
// Preparing before the first frame may use registry 0. Reuse those pipelines
|
||||
// when the host subsequently supplies that device's actual registry ID.
|
||||
@@ -67,9 +82,9 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
|
||||
return [self textureForTable:table entry:e error:err];
|
||||
}
|
||||
- (NSArray*)textures:(NSDictionary*)paths uniforms:(DYUniforms*)u entry:(NSDictionary*)e error:(NSError**)err{
|
||||
// Normalize only this render copy. Folded groups retain their host parameters
|
||||
// Normalize only this render copy. Disabled groups retain their host parameters
|
||||
// and paths, while inactive LUTs neither load files nor affect any layer.
|
||||
BOOL inputEnabled=u->inputSectionEnabled>.5;
|
||||
BOOL inputEnabled=u->inputSectionEnabled>.5&&!managed(*u,paths);
|
||||
NSString*input=inputEnabled?paths[@"input"]:nil;int profile=inputEnabled?(int)roundf(u->inputProfile):0;
|
||||
if(!inputEnabled){u->inputProfile=0;u->preLUTStrength=0;}
|
||||
if(!input.length&&profile>0&&profile<(int)inputFiles().count)input=[[NSBundle bundleForClass:self.class]pathForResource:inputFiles()[profile] ofType:@"dylut" inDirectory:@"InputLUTs"];
|
||||
@@ -84,19 +99,26 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
|
||||
- (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths error:(NSError**)err{@synchronized(self){@autoreleasepool{
|
||||
[_activeLUTPaths release];_activeLUTPaths=[[NSSet alloc]initWithArray:paths.allValues?:@[]];
|
||||
NSMutableDictionary*e=[self device:dst.deviceRegistryID error:err];if(!e)return NO;id<MTLDevice>d=e[@"device"];id<MTLTexture>input=[src metalTextureForDevice:d],output=[dst metalTextureForDevice:d];if(!input||!output)return fail(err,@"宿主图像纹理不可用");
|
||||
BOOL useCM=managed(u,paths);float bwMix=fmaxf(0,fminf(1,u.cm.blackWhiteMix));if(bwMix<=0)u.blackWhiteSectionEnabled=0;
|
||||
NSArray*ts=[self textures:paths uniforms:&u entry:e error:err];if(!ts)return NO;
|
||||
NSMutableDictionary*ps=e[@"pipelines"];NSNumber*format=@(output.pixelFormat);id<MTLRenderPipelineState>pipeline=ps[format];if(!pipeline){MTLRenderPipelineDescriptor*p=[MTLRenderPipelineDescriptor new];p.vertexFunction=[e[@"library"]newFunctionWithName:@"dyVertex"];p.fragmentFunction=[e[@"library"]newFunctionWithName:@"dyFragment"];p.colorAttachments[0].pixelFormat=output.pixelFormat;pipeline=[d newRenderPipelineStateWithDescriptor:p error:err];[p.vertexFunction release];[p.fragmentFunction release];[p release];if(!pipeline)return NO;ps[format]=pipeline;[pipeline release];}
|
||||
MTLTextureDescriptor*td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:input.width height:input.height mipmapped:NO];td.storageMode=MTLStorageModePrivate;td.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;id<MTLTexture>straight=[d newTextureWithDescriptor:td];if(!straight)return fail(err,@"无法分配调色缓冲区");
|
||||
id<MTLCommandBuffer>cb=[e[@"queue"]commandBuffer];id<MTLComputeCommandEncoder>ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyUnpremultiply"]];[ce setTexture:input atIndex:0];[ce setTexture:straight atIndex:1];[ce dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];
|
||||
if(useCM&&u.cm.mix>0){
|
||||
DayuRenderParams cm=DYCMRender(u.cm);cm.stages=(cm.stages&~1)|(u.inputSectionEnabled>.5?1:0);
|
||||
if(cm.stages){id<MTLTexture>converted=[d newTextureWithDescriptor:td];if(!converted){[straight release];return fail(err,@"无法分配 CST 缓冲区");}
|
||||
ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyColorManagement"]];[ce setTexture:straight atIndex:0];[ce setTexture:converted atIndex:1];[ce setBytes:&cm length:sizeof(cm) atIndex:0];[ce setBytes:&u.cm.mix length:4 atIndex:1];[ce dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding];[straight release];straight=converted;
|
||||
}
|
||||
}
|
||||
float level=.5;id<MTLBuffer>scene=[d newBufferWithBytes:&level length:4 options:MTLResourceStorageModeShared];
|
||||
if(u.whites>0&&u.whitesEnabled>.5&&u.baseSectionEnabled>.5){ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyWhitesSceneStatistics"]];[ce setTexture:straight atIndex:0];[ce setTexture:ts[7] atIndex:1];[ce setBytes:&u length:sizeof(u) atIndex:0];[ce setBuffer:scene offset:0 atIndex:1];[ce dispatchThreadgroups:MTLSizeMake(1,1,1) threadsPerThreadgroup:MTLSizeMake(256,1,1)];[ce endEncoding];}
|
||||
BOOL preview=NO;@synchronized(_previewLock){preview=CACurrentMediaTime()-_lastPreview>.5;}id<MTLBuffer>pb=nil;if(preview){pb=[d newBufferWithLength:320*180*16 options:MTLResourceStorageModeShared];ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyInputAnalysis"]];[ce setTexture:straight atIndex:0];[ce setTexture:ts[0] atIndex:1];float inputStrength=u.inputSectionEnabled>.5?u.preLUTStrength:0;[ce setBytes:&inputStrength length:4 atIndex:1];[ce setBuffer:pb offset:0 atIndex:0];[ce dispatchThreads:MTLSizeMake(320,180,1) threadsPerThreadgroup:MTLSizeMake(8,8,1)];[ce endEncoding];}
|
||||
if(!_exporting&&u.whites>0&&u.whitesEnabled>.5&&u.baseSectionEnabled>.5){ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyWhitesSceneStatistics"]];[ce setTexture:straight atIndex:0];[ce setTexture:ts[7] atIndex:1];[ce setBytes:&u length:sizeof(u) atIndex:0];[ce setBuffer:scene offset:0 atIndex:1];[ce dispatchThreadgroups:MTLSizeMake(1,1,1) threadsPerThreadgroup:MTLSizeMake(256,1,1)];[ce endEncoding];}
|
||||
BOOL preview=NO;@synchronized(_previewLock){preview=!_exporting&&CACurrentMediaTime()-_lastPreview>.5;}id<MTLBuffer>pb=nil;if(preview){pb=[d newBufferWithLength:320*180*16 options:MTLResourceStorageModeShared];ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyInputAnalysis"]];[ce setTexture:straight atIndex:0];[ce setTexture:ts[0] atIndex:1];float inputStrength=u.inputSectionEnabled>.5?u.preLUTStrength:0;[ce setBytes:&inputStrength length:4 atIndex:1];[ce setBuffer:pb offset:0 atIndex:0];[ce dispatchThreads:MTLSizeMake(320,180,1) threadsPerThreadgroup:MTLSizeMake(8,8,1)];[ce endEncoding];}
|
||||
MTLRenderPassDescriptor*rp=[MTLRenderPassDescriptor renderPassDescriptor];rp.colorAttachments[0].texture=output;rp.colorAttachments[0].loadAction=MTLLoadActionDontCare;rp.colorAttachments[0].storeAction=MTLStoreActionStore;id<MTLRenderCommandEncoder>re=[cb renderCommandEncoderWithDescriptor:rp];[re setRenderPipelineState:pipeline];
|
||||
float w=output.width,h=output.height;FxRect s=src.tilePixelBounds,t=dst.tilePixelBounds;float sw=s.right-s.left,sh=s.top-s.bottom;float l=(t.left-s.left)/sw,r=(t.right-s.left)/sw,top=(s.top-t.top)/sh,bottom=(s.top-t.bottom)/sh;
|
||||
if(src.imageOrigin==kFxImageOrigin_BOTTOM_LEFT){top=1-top;bottom=1-bottom;}
|
||||
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;i<ts.count;i++)[re setFragmentTexture:ts[i] atIndex:i+1];[re setFragmentBytes:&u length:sizeof(u) atIndex:0];[re setFragmentBuffer:scene offset:0 atIndex:1];DYRenderOptions options={1,0,0,0};[re setFragmentBytes:&options length:sizeof(options) atIndex:2];[re drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];[re endEncoding];[cb commit];[cb waitUntilCompleted];BOOL ok=cb.status==MTLCommandBufferStatusCompleted;
|
||||
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;i<ts.count;i++)[re setFragmentTexture:ts[i] atIndex:i+1];[re setFragmentBytes:&u length:sizeof(u) atIndex:0];[re setFragmentBuffer:scene offset:0 atIndex:1];DYRenderOptions options={1,bwMix,0,0};[re setFragmentBytes:&options length:sizeof(options) atIndex:2];DYUniforms color=u;color.blackWhiteSectionEnabled=0;[re setFragmentBytes:&color length:sizeof(color) atIndex:3];[re drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];[re endEncoding];[cb commit];[cb waitUntilCompleted];BOOL ok=cb.status==MTLCommandBufferStatusCompleted;
|
||||
if(ok&&pb){@synchronized(_previewLock){
|
||||
[_preview release];_preview=[[NSData alloc]initWithBytes:pb.contents length:320*180*16];
|
||||
// The analysis kernel reads physical texture rows. Its result remains intact
|
||||
@@ -112,7 +134,17 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
|
||||
if(!ok)fail(err,cb.error.localizedDescription);[pb release];[straight release];[scene release];return ok;
|
||||
}}}
|
||||
- (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)u paths:(NSDictionary*)paths error:(NSError**)err{@synchronized(self){
|
||||
NSMutableDictionary*e=[self device:0 error:err];if(!e)return NO;NSArray*ts=[self textures:paths uniforms:&u entry:e error:err];if(!ts)return NO;id<MTLDevice>d=e[@"device"];uint32_t n=33;NSUInteger count=n*n*n;id<MTLBuffer>out=[d newBufferWithLength:count*3*4 options:MTLResourceStorageModeShared];if(!out)return fail(err,@"无法分配 LUT 输出");id<MTLCommandBuffer>cb=[e[@"queue"]commandBuffer];id<MTLComputeCommandEncoder>ce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyLUTExportKernel"]];for(NSUInteger i=0;i<ts.count;i++)[ce setTexture:ts[i] atIndex:i];[ce setBytes:&u length:sizeof(u) atIndex:0];[ce setBuffer:out offset:0 atIndex:1];[ce setBytes:&n length:4 atIndex:2];[ce dispatchThreads:MTLSizeMake(count,1,1) threadsPerThreadgroup:MTLSizeMake(64,1,1)];[ce endEncoding];[cb commit];[cb waitUntilCompleted];if(cb.status!=MTLCommandBufferStatusCompleted){[out release];return fail(err,cb.error.localizedDescription);}
|
||||
NSMutableString*s=[NSMutableString stringWithString:@"TITLE \"大鱼调色\"\n# 仅包含逐像素颜色;纹理、清晰度和画面分析不写入 LUT。\nLUT_3D_SIZE 33\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n"];float*v=(float*)out.contents;for(NSUInteger i=0;i<count;i++){if(!std::isfinite(v[i*3])||!std::isfinite(v[i*3+1])||!std::isfinite(v[i*3+2])){[out release];return fail(err,@"LUT GPU 输出含无效值");}[s appendFormat:@"%.8f %.8f %.8f\n",v[i*3],v[i*3+1],v[i*3+2]];}[out release];return [s writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:err];
|
||||
NSMutableDictionary *e=[self device:0 error:err];if(!e)return NO;id<MTLDevice>d=e[@"device"];const NSUInteger n=33,count=n*n*n,width=n*n,height=n;
|
||||
MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO];desc.storageMode=MTLStorageModeShared;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget;
|
||||
id<MTLTexture>input=[d newTextureWithDescriptor:desc],output=[d newTextureWithDescriptor:desc];if(!input||!output){[input release];[output release];return fail(err,@"无法分配 LUT 色格");}
|
||||
std::vector<__fp16>values(count*4);for(NSUInteger i=0;i<count;i++){float v[3]={(float)(i%n)/(n-1),(float)((i/n)%n)/(n-1),(float)(i/(n*n))/(n-1)};for(int c=0;c<3;c++)values[i*4+c]=v[c]<=.04045f?v[c]/12.92f:powf((v[c]+.055f)/1.055f,2.4f);values[i*4+3]=1;}
|
||||
[input replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:values.data() bytesPerRow:width*8];
|
||||
DYExportTile *source=[[[DYExportTile alloc]initWithTexture:input registry:d.registryID]autorelease],*dest=[[[DYExportTile alloc]initWithTexture:output registry:d.registryID]autorelease];
|
||||
u.textureEnabled=0;u.clarityEnabled=0;u.dehazeEnabled=0;BOOL ok=NO;_exporting=YES;
|
||||
@try{ok=[self renderSource:source destination:dest uniforms:u paths:paths error:err];}@finally{_exporting=NO;}
|
||||
if(ok)[output getBytes:values.data() bytesPerRow:width*8 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0];[input release];[output release];if(!ok)return NO;
|
||||
NSMutableString *text=[NSMutableString stringWithString:@"TITLE \"大鱼调色\"\n# 包含 CST 与逐像素颜色;不包含纹理、清晰度和逐画面分析。\nLUT_3D_SIZE 33\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n"];
|
||||
for(NSUInteger i=0;i<count;i++){float rgb[3];for(int c=0;c<3;c++){float v=values[i*4+c];rgb[c]=v<=.0031308f?v*12.92f:1.055f*powf(v,1/2.4f)-.055f;if(!std::isfinite(rgb[c]))return fail(err,@"LUT 输出含无效值");}[text appendFormat:@"%.8f %.8f %.8f\n",rgb[0],rgb[1],rgb[2]];}
|
||||
return [text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:err];
|
||||
}}
|
||||
@end
|
||||
+6
-2
@@ -16,6 +16,8 @@ typedef vector_float4 DYFloat4;
|
||||
typedef uint32_t DYUInt;
|
||||
#endif
|
||||
|
||||
#include "DYColorManagement.h"
|
||||
|
||||
typedef struct DYUniforms {
|
||||
float exposure; // offset 0
|
||||
float contrast; // offset 4
|
||||
@@ -119,12 +121,14 @@ typedef struct DYUniforms {
|
||||
DYFloat4 greenCurveExtraX; // offset 896
|
||||
DYFloat4 blueCurveExtra; // offset 912
|
||||
DYFloat4 blueCurveExtraX; // offset 928
|
||||
DYCMSettings cm; // appended; recovered color arithmetic reads only the stable prefix
|
||||
} DYUniforms;
|
||||
|
||||
typedef struct DYVertex2D { DYFloat2 position; DYFloat2 textureCoordinate; } DYVertex2D;
|
||||
typedef struct DYRenderOptions {
|
||||
DYUInt outputPremultiplied;
|
||||
DYUInt reserved[3];
|
||||
float blackWhiteMix;
|
||||
DYUInt reserved[2];
|
||||
} DYRenderOptions;
|
||||
|
||||
#ifndef __METAL_VERSION__
|
||||
@@ -133,7 +137,7 @@ typedef struct DYRenderOptions {
|
||||
#else
|
||||
#define DY_ABI_ASSERT _Static_assert
|
||||
#endif
|
||||
DY_ABI_ASSERT(sizeof(DYUniforms) == 944, "DYUniforms must match recovered GPU ABI");
|
||||
DY_ABI_ASSERT(offsetof(DYUniforms, cm) == 944, "DYUniforms must match recovered GPU ABI");
|
||||
DY_ABI_ASSERT(offsetof(DYUniforms, exposure) == 0, "exposure offset");
|
||||
DY_ABI_ASSERT(offsetof(DYUniforms, contrast) == 4, "contrast offset");
|
||||
DY_ABI_ASSERT(offsetof(DYUniforms, highlights) == 8, "highlights offset");
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.1.5</string>
|
||||
<string>1.2.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>16</string>
|
||||
<string>17</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string></string>
|
||||
<key>PlugInKit</key>
|
||||
|
||||
在新工单中引用
屏蔽一个用户