diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index f3e0a90..82e7159 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -418,6 +418,7 @@ static NSImage *DYWheelImage(void) { NSTextField *_brand; NSTextField *_subtitle; NSButton *_resetAll, *_save, *_load, *_export, *_websiteLink; + NSPopUpButton *_addModule; NSArray *_sections; NSMutableArray *_cards; NSMutableDictionary *_controls; @@ -470,7 +471,9 @@ static NSImage *DYWheelImage(void) { _save=[DYButton(@"保存预设",self,@selector(savePreset:)) retain]; _load=[DYButton(@"载入预设",self,@selector(loadPreset:)) retain]; _export=[DYButton(@"导出 LUT",self,@selector(exportLUT:)) retain]; - for(NSView *v in @[_brand,_subtitle,_websiteLink,_resetAll,_save,_load,_export]){[self addSubview:v];v.hidden=_embedded;} + _addModule=[[NSPopUpButton alloc]initWithFrame:NSZeroRect pullsDown:YES];_addModule.font=[NSFont systemFontOfSize:11];_addModule.accessibilityLabel=@"添加模块";[_addModule addItemWithTitle:@"+ 添加模块"]; + for(NSDictionary *section in DYPresentationSections()){NSMenuItem *item=[[[NSMenuItem alloc]initWithTitle:section[@"title"] action:@selector(addModule:) keyEquivalent:@""]autorelease];item.target=self;item.representedObject=section[@"key"];[_addModule.menu addItem:item];} + for(NSView *v in @[_brand,_subtitle,_websiteLink,_resetAll,_save,_load,_export,_addModule]){[self addSubview:v];v.hidden=_embedded;} NSMutableArray *themes=[NSMutableArray array];for(NSInteger i=0;i<5;i++){ DYSwatchButton *b=[[[DYSwatchButton alloc]initWithFrame:NSZeroRect]autorelease];[b setButtonType:NSButtonTypePushOnPushOff];b.swatch=DYThemeSwatch(i);b.tag=i;b.target=self;b.action=@selector(selectTheme:);b.title=@"";b.bordered=NO; b.toolTip=[DYThemeNames()[i] stringByAppendingString:@"主题"];b.accessibilityLabel=b.toolTip;[self addSubview:b];b.hidden=_embedded;[themes addObject:b]; @@ -501,7 +504,7 @@ static NSImage *DYWheelImage(void) { for(NSProgress *p in _assetLoads.allValues)[p cancel];[_assetLoads release];[_assetLoadIDs release];[_menuScan cancel];[_menuScan release];[_pendingAssetMenuCommand release]; [[NSNotificationCenter defaultCenter] removeObserver:self]; if(_embedded)[(id)_manager release];[_stackViews release];[_stackOrder release];[_stackRoots release]; - [_brand release]; [_subtitle release]; [_websiteLink release]; [_resetAll release]; [_save release]; [_load release]; [_export release]; + [_brand release]; [_subtitle release]; [_websiteLink release]; [_resetAll release]; [_save release]; [_load release]; [_export release];[_addModule release]; [_scroll release]; [_document release]; [_sections release]; [_cards release]; [_controls release]; [_assetButtons release]; [_graphics release]; [_sampler release]; [_browser close];[_browser release];[_renderer release];[_library release];[_themeButtons release];[_tabs release]; [super dealloc]; @@ -661,7 +664,7 @@ static NSImage *DYWheelImage(void) { NSButton *mask=DYButton(@"",self,@selector(toolMask:));mask.tag=index;mask.bordered=NO;mask.image=[NSImage imageWithSystemSymbolName:@"circle.dashed.inset.filled" accessibilityDescription:@"添加蒙版"];mask.toolTip=@"添加本工具的独立蒙版";mask.accessibilityLabel=[section[@"title"]stringByAppendingString:@"添加蒙版"];[card addSubview:mask];record[@"maskButton"]=mask; DYMaskCountBadge *maskBadge=[[[DYMaskCountBadge alloc]initWithFrame:NSZeroRect]autorelease];maskBadge.hidden=YES;maskBadge.accessibilityLabel=[section[@"title"] stringByAppendingString:@"蒙版数量"];[card addSubview:maskBadge];record[@"maskBadge"]=maskBadge; NSButton *repeat=DYButton(@"",self,@selector(repeatTool:));repeat.tag=index;repeat.bordered=NO;repeat.image=[NSImage imageWithSystemSymbolName:@"plus.square.on.square" accessibilityDescription:@"再加一层"];repeat.toolTip=@"紧接当前工具插入一层初始化工具";repeat.accessibilityLabel=[section[@"title"]stringByAppendingString:@"再加一层"];[card addSubview:repeat];record[@"repeatButton"]=repeat; - if(_embedded){NSButton *remove=DYButton(@"删除此层",self,@selector(removeTool:));remove.identifier=@"removeTool";[card addSubview:remove];[body addObject:remove];} + NSButton *remove=DYButton(@"",self,@selector(removeTool:));remove.tag=index;remove.bordered=NO;remove.image=[NSImage imageWithSystemSymbolName:@"minus.square" accessibilityDescription:@"删除此层"];remove.toolTip=@"删除此层并还原参数、LUT 与蒙版";remove.accessibilityLabel=[section[@"title"]stringByAppendingString:_embedded?@"删除此层":@"删除模块"];[card addSubview:remove];record[@"removeButton"]=remove; [_cards addObject:record]; index++; } @@ -706,25 +709,26 @@ static NSImage *DYWheelImage(void) { _websiteLink.frame=NSMakeRect(16,41,w-32,20); CGFloat gap=7,bw=(w-32-gap*2)/3; _save.frame=NSMakeRect(16,74,bw,27); _load.frame=NSMakeRect(16+bw+gap,74,bw,27); _export.frame=NSMakeRect(16+(bw+gap)*2,74,bw,27); - _scroll.frame=_embedded?NSMakeRect(0,0,w,h):NSMakeRect(0,112,w,MAX(80,h-112)); + _addModule.frame=NSMakeRect(16,108,w-32,27); + _scroll.frame=_embedded?NSMakeRect(0,0,w,h):NSMakeRect(0,144,w,MAX(80,h-144)); CGFloat cw=MAX(244,_scroll.contentSize.width-32),y=8; for(NSMutableDictionary *c in _cards) { DYCard *card=c[@"view"];BOOL collapsed=[c[@"collapsed"]boolValue];NSString *key=c[@"section"][@"key"]; + card.hidden=[c[@"removed"]boolValue];if(card.hidden){y=[self layoutRepeatedToolsAfter:[@"base:" stringByAppendingString:key] y:y width:w];continue;} NSArray *body=c[@"body"];CGFloat contentHeight=0; for(NSView *row in body)if([self showRow:row section:key]&&!collapsed)contentHeight+=[self heightForRow:row]; [c[@"enabled"]setFrame:NSMakeRect(12,12,20,20)]; - CGFloat titleWidth=MIN(cw-143,MAX(94,[[(NSButton *)c[@"header"]title]sizeWithAttributes:@{NSFontAttributeName:[NSFont boldSystemFontOfSize:12]}].width+36)); + BOOL narrow=cw<300;CGFloat titleWidth=MIN(cw-(narrow?60:171),MAX(94,[[(NSButton *)c[@"header"]title]sizeWithAttributes:@{NSFontAttributeName:[NSFont boldSystemFontOfSize:12]}].width+36)); [c[@"header"]setFrame:NSMakeRect(42,8,titleWidth,28)]; - CGFloat headerHeight=43; + CGFloat headerHeight=narrow?69:43,buttonY=narrow?38:10; card.frame=NSMakeRect(16,y,cw,headerHeight+(contentHeight>0?contentHeight+8:0));y+=card.frame.size.height+12; - [c[@"reset"]setFrame:NSMakeRect(cw-34,10,24,24)]; - [c[@"repeatButton"]setFrame:NSMakeRect(cw-62,10,24,24)];[c[@"maskButton"]setFrame:NSMakeRect(cw-90,10,24,24)];[c[@"maskBadge"]setFrame:NSMakeRect(cw-83,3,18,16)]; + [c[@"reset"]setFrame:NSMakeRect(cw-34,buttonY,24,24)]; + [c[@"repeatButton"]setFrame:NSMakeRect(cw-62,buttonY,24,24)];[c[@"removeButton"]setFrame:NSMakeRect(cw-90,buttonY,24,24)];[c[@"maskButton"]setFrame:NSMakeRect(cw-118,buttonY,24,24)];[c[@"maskBadge"]setFrame:NSMakeRect(cw-111,buttonY-7,18,16)]; [c[@"add"]setFrame:NSMakeRect(cw-33,headerHeight+contentHeight-28,20,24)];[c[@"add"]setEnabled:_visibleLooks<5];[c[@"add"]setHidden:collapsed]; CGFloat rowY=headerHeight; for(NSView *row in body) { BOOL show=!collapsed&&[self showRow:row section:key];row.hidden=!show;if(!show)continue; CGFloat rh=[self heightForRow:row];row.frame=NSMakeRect(12,rowY,cw-24,rh-1);rowY+=rh; - if([row.identifier isEqual:@"removeTool"]){/* NSButton fills its row. */} if([row.identifier isEqual:@"primaryBalance"])for(NSView *v in row.subviews)v.frame=row.bounds; if([row.identifier hasPrefix:@"heading:"])for(NSView *v in row.subviews)v.frame=NSMakeRect(3,7,row.bounds.size.width-6,18); if([row.identifier isEqual:@"autoControls"]||[row.identifier isEqual:@"sampleControls"]) { @@ -793,6 +797,7 @@ static NSImage *DYWheelImage(void) { for(NSView *row in c[@"body"])row.alphaValue=enabled?1:.45; } id maskHost=_embedded?[(DYToolManager*)_manager host]:_manager;NSDictionary *tools=DYReadTools(maskHost,t).document;for(NSDictionary *card in _cards){ + ((NSMutableDictionary *)card)[@"removed"]=@(!_embedded&&DYBaseToolRemoved(tools,card[@"section"][@"key"])); [card[@"maskPanel"]refreshWithDocument:tools time:t]; NSString *nodeID=_embedded?[(DYToolManager*)_manager nodeID]:[@"base:" stringByAppendingString:card[@"section"][@"key"]];NSUInteger count=[DYMasksForTool(tools,nodeID) count]; [(DYMaskCountBadge*)card[@"maskBadge"]setCount:count];NSString *hint=count?[NSString stringWithFormat:@"已有 %lu 个蒙版;点击添加独立蒙版",(unsigned long)count]:@"添加本工具的独立蒙版"; @@ -950,14 +955,14 @@ static NSImage *DYWheelImage(void) { - (void)resetAll:(id)sender { [self cancelAssetLoads]; id action=[self actionAPI];if(!action)return; - [action startAction:self]; + [action startAction:self];idundo=[_manager apiForProtocol:@protocol(FxUndoAPI)];BOOL grouped=[undo startUndoGroup:@"还原全部模块与参数"]; @try { CMTime t=action.currentTime;id set=[_manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; - for(NSDictionary *d in DYDescriptors())[set setFloatValue:[d[@"default"] doubleValue] toParameter:[d[@"pid"] unsignedIntValue] atTime:t]; + NSError *failure=nil;if(!DYResetToolParameters(_manager,DYDescriptors(),t,&failure)){dispatch_async(dispatch_get_main_queue(),^{[self showError:failure.localizedDescription?:@"未能完整还原参数。"];});return;} DYAssetState *assets=[[[DYAssetState alloc] init] autorelease];assets.paths=@{};DYWriteAssets(_manager,assets,t);DYWriteTools(_manager,[[[DYToolDocument alloc]init]autorelease].document,t); [set setCustomParameterValue:[[[DYInspectorToken alloc]init]autorelease] toParameter:DYInspectorParameterID atTime:t]; for(NSMutableDictionary *card in _cards)card[@"collapsed"]=@(![@[@"primary",@"spider",@"base"]containsObject:card[@"section"][@"key"]]); - } @finally {[action endAction:self];} + } @finally {if(grouped)[undo endUndoGroup];[action endAction:self];} [self postChanged]; } - (void)chooseAsset:(NSButton *)sender { diff --git a/大鱼调色/Plugin/DYToolInspector.inc.h b/大鱼调色/Plugin/DYToolInspector.inc.h index b9d2336..c985a74 100644 --- a/大鱼调色/Plugin/DYToolInspector.inc.h +++ b/大鱼调色/Plugin/DYToolInspector.inc.h @@ -1,9 +1,9 @@ - (void)synchronizeTools { ida=[self actionAPI];if(!a)return;[a startAction:self];NSDictionary *document=nil;@try{document=[DYReadTools(_manager,a.currentTime).document copy];}@finally{[a endAction:self];} NSMutableArray *order=[NSMutableArray array];NSMutableDictionary *numbers=[NSMutableDictionary dictionary],*roots=[NSMutableDictionary dictionary]; - for(NSString *orderedID in DYToolDisplayOrder(document)){NSDictionary *node=DYToolWithID(document,orderedID);if(!node)continue;NSString *ID=node[@"id"],*type=node[@"type"];[order addObject:ID];roots[ID]=DYToolRootAnchor(document,ID)?:@"tail";NSInteger number=MAX(1,[numbers[type]integerValue])+1;numbers[type]=@(number); + for(NSString *orderedID in DYToolDisplayOrder(document)){NSDictionary *node=DYToolWithID(document,orderedID);if(!node)continue;NSString *ID=node[@"id"],*type=node[@"type"];[order addObject:ID];roots[ID]=DYToolRootAnchor(document,ID)?:@"tail";NSInteger number=(numbers[type]?[numbers[type]integerValue]:(DYBaseToolRemoved(document,type)?0:1))+1;numbers[type]=@(number); DYInspector *view=_stackViews[ID];if(!view){DYToolManager *manager=[[[DYToolManager alloc]initWithHost:_manager node:node]autorelease];view=[[[DYInspector alloc]initWithAPIManager:manager renderer:_renderer]autorelease];_stackViews[ID]=view;[_document addSubview:view];} - if(view->_cards.count){NSDictionary *section=view->_cards[0][@"section"];[view->_cards[0][@"header"]setTitle:[NSString stringWithFormat:@"%@ %ld",section[@"title"],(long)number]];} + if(view->_cards.count){NSDictionary *section=view->_cards[0][@"section"];NSString *title=[NSString stringWithFormat:@"%@ %ld",section[@"title"],(long)number];[view->_cards[0][@"header"]setTitle:title];[view->_cards[0][@"removeButton"]setAccessibilityLabel:[title stringByAppendingString:@"删除此层"]];} [view refresh];[view setNeedsLayout:YES]; } for(NSString *ID in [[_stackViews.allKeys copy]autorelease])if(![order containsObject:ID]){[_stackViews[ID]removeFromSuperview];[_stackViews removeObjectForKey:ID];} @@ -14,7 +14,39 @@ if(sender.tag<0||sender.tag>=_cards.count)return;idhost=_embedded?[(DYToolManager*)_manager host]:_manager;ida=[host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];if(!a)return;[a startAction:self]; NSString *addedID=nil;@try{NSMutableDictionary *doc=DYMutablePlist(DYReadTools(host,a.currentTime).document);if([doc[@"layers"]count]>=DYToolLimit){[self showError:@"最多可添加 32 个独立工具层。"];return;}NSString *type=_cards[sender.tag][@"section"][@"key"],*anchor=_embedded?[(DYToolManager*)_manager nodeID]:[@"base:" stringByAppendingString:type];NSDictionary *node=DYInsertTool(doc,type,anchor);if(!node)return;addedID=[node[@"id"]copy];idundo=[host apiForProtocol:@protocol(FxUndoAPI)];[undo startUndoGroup:@"再加一层初始化工具"];DYWriteTools(host,doc,a.currentTime);[undo endUndoGroup];}@finally{[a endAction:self];}[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:host userInfo:@{@"scrollToTool":addedID?:@""}];[addedID release]; } -- (void)removeTool:(id)sender{if(!_embedded)return;idhost=[(DYToolManager*)_manager host];ida=[host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];if(!a)return;[a startAction:self];@try{NSMutableDictionary *doc=DYMutablePlist(DYReadTools(host,a.currentTime).document);if(!DYRemoveTool(doc,[(DYToolManager*)_manager nodeID]))return;idundo=[host apiForProtocol:@protocol(FxUndoAPI)];[undo startUndoGroup:@"删除独立工具层"];DYWriteTools(host,doc,a.currentTime);[undo endUndoGroup];}@finally{[a endAction:self];}dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:host];});} +- (void)addModule:(NSMenuItem *)sender{ + if(_embedded)return;NSString *type=sender.representedObject;for(NSUInteger i=0;i<_cards.count;i++)if([_cards[i][@"section"][@"key"]isEqual:type]){NSButton *source=[[[NSButton alloc]init]autorelease];source.tag=i;[self repeatTool:source];return;} +} +- (void)removeTool:(NSButton *)sender{ + if(!_embedded&&(sender.tag<0||sender.tag>=_cards.count))return; + [self cancelAssetLoads];[_browser close]; + idhost=_embedded?[(DYToolManager*)_manager host]:_manager;ida=[host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)];if(!a)return; + NSError *failure=nil;BOOL changed=NO,attempted=NO;[a startAction:self];idundo=[host apiForProtocol:@protocol(FxUndoAPI)];BOOL grouped=[undo startUndoGroup:@"删除模块并还原参数"]; + @try{ + CMTime time=a.currentTime;NSMutableDictionary *doc=DYMutablePlist(DYReadTools(host,time).document); + if(_embedded){attempted=DYToolWithID(doc,[(DYToolManager*)_manager nodeID])!=nil;if(DYRemoveTool(doc,[(DYToolManager*)_manager nodeID]))changed=DYWriteTools(host,doc,time);} + else{ + NSString *type=_cards[sender.tag][@"section"][@"key"];if(DYBaseToolRemoved(doc,type))return;attempted=YES; + if(!DYResetToolParameters(host,DYBaseToolDescriptors(type),time,&failure))return; + DYAssetState *assets=[[DYReadAssets(host,time)copy]autorelease];NSMutableDictionary *paths=[[assets.paths mutableCopy]autorelease]?:[NSMutableDictionary dictionary]; + if([type isEqual:@"primary"])[paths removeObjectForKey:@"input"]; + if([type isEqual:@"look"]){for(NSInteger i=0;i<5;i++)[paths removeObjectForKey:[NSString stringWithFormat:@"look%ld",(long)i]];_visibleLooks=1;} + if([type isEqual:@"spider"]){assets.spiderMesh=nil;assets.spiderLinked=YES;} + assets.paths=paths;if(!DYWriteAssets(host,assets,time))return; + // Stored flags are disabled as well as the document exclusion, keeping + // older readers neutral and preventing historical automation from leaking. + idset=[host apiForProtocol:@protocol(FxParameterSettingAPI_v6)];NSDictionary *section=_cards[sender.tag][@"section"]; + NSMutableArray *flags=[NSMutableArray arrayWithObject:section[@"enabled"]];if(section[@"extraEnabled"])[flags addObject:section[@"extraEnabled"]];[flags addObjectsFromArray:section[@"enableParameters"]?:@[]]; + for(NSNumber *pid in flags)if(![set setFloatValue:0 toParameter:pid.unsignedIntValue atTime:time])return; + if(DYSetBaseToolRemoved(doc,type,YES))changed=DYWriteTools(host,doc,time); + } + }@finally{ + if(grouped)[undo endUndoGroup];[a endAction:self]; + if(attempted&&!changed&&!failure)failure=[NSError errorWithDomain:@"com.dayu.color.ToolRemoval" code:1 userInfo:@{NSLocalizedDescriptionKey:@"未能完成删除,模块已保留。可撤销本次参数还原。"}]; + dispatch_async(dispatch_get_main_queue(),^{[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:host];if(failure)[self showError:failure.localizedDescription];}); + } + if(changed)NSAccessibilityPostNotification(self,NSAccessibilityLayoutChangedNotification); +} - (CGFloat)layoutRepeatedToolsAfter:(NSString*)anchor y:(CGFloat)y width:(CGFloat)w {if(_embedded)return y;for(NSString *ID in _stackOrder)if([_stackRoots[ID]isEqual:anchor]){DYInspector *child=_stackViews[ID];child.frame=NSMakeRect(0,y,w,MAX(60,child->_stackHeight));[child layoutSubtreeIfNeeded];CGFloat height=MAX(60,child->_stackHeight);child.frame=NSMakeRect(0,y,w,height);y+=height;}return y;} diff --git a/大鱼调色/Plugin/DYToolRender.inc.h b/大鱼调色/Plugin/DYToolRender.inc.h index cc07d32..86f0249 100644 --- a/大鱼调色/Plugin/DYToolRender.inc.h +++ b/大鱼调色/Plugin/DYToolRender.inc.h @@ -42,6 +42,7 @@ } - (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){@autoreleasepool{ if(!tools)tools=@{@"schema":@1,@"layers":@[],@"baseMasks":@{}};if(!DYValidToolDocument(tools))return fail(error,@"工具或蒙版数据损坏,未更改原工程"); + DYApplyRemovedBaseTools(&u,tools);paths=DYVisibleBaseToolPaths(paths,tools);if(DYBaseToolRemoved(tools,@"spider"))spider=nil; NSArray *layers=tools[@"layers"];BOOL active=NO,anchored=NO;for(NSDictionary *node in layers)if(!DYToolIsNeutral(node)){active=YES;anchored|=![DYToolRootAnchor(tools,node[@"id"])isEqual:@"tail"];} // No active extra tool keeps the exact historical fused path, including HDR. if(!active&&!DYChannelMixerActive(u)&&!DYFilmToolActive(u))return [self renderLegacy:src destination:dst uniforms:u paths:paths spider:spider masks:tools[@"baseMasks"] error:error]; @@ -97,6 +98,7 @@ }@finally{[originalReference release];[skinReference release];[tile release];} }}} - (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){ + if(tools&&!DYValidToolDocument(tools))return fail(error,@"工具或蒙版数据损坏,未更改原工程");DYApplyRemovedBaseTools(&u,tools);paths=DYVisibleBaseToolPaths(paths,tools);if(DYBaseToolRemoved(tools,@"spider"))spider=nil; if(DYFilmToolActive(u)&&DYFilmSpatialActive(u.film))return fail(error,@"当前胶片含晕光、辉光、颗粒或暗角,无法完整保存到静态 Cube。请保存完整预设,或关闭这些处理后再导出。");for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);if([node[@"type"]isEqual:@"film"]&&DYFilmToolActive(layer)&&DYFilmSpatialActive(layer.film))return fail(error,@"新增胶片层含空间或时间处理,无法完整保存到静态 Cube。请保存完整预设。");} for(NSArray *masks in [tools[@"baseMasks"]allValues])if(masks.count)return fail(error,@"当前调色含空间蒙版或跟踪,Cube 无法保存这些信息。请先保存完整预设,或移除蒙版后导出。");for(NSDictionary *node in tools[@"layers"])if([node[@"masks"]count])return fail(error,@"新增工具含蒙版,无法完整导出为 Cube。请保存完整预设。"); _toolDocument=tools;BOOL ok=NO;@try{ok=[self exportLUT:url uniforms:u paths:paths spider:spider error:error];}@finally{_toolDocument=nil;}return ok; diff --git a/大鱼调色/Plugin/DYToolState.h b/大鱼调色/Plugin/DYToolState.h index 0b3d373..c9222de 100644 --- a/大鱼调色/Plugin/DYToolState.h +++ b/大鱼调色/Plugin/DYToolState.h @@ -8,6 +8,12 @@ enum { DYToolsParameterID=9002, DYCanvasSessionParameterID=9003, DYToolLimit=32, @property(nonatomic,copy) NSDictionary *document; @end NSArray *DYToolTypes(void); +NSArray *DYBaseToolDescriptors(NSString *type); +BOOL DYBaseToolRemoved(NSDictionary *document,NSString *type); +BOOL DYSetBaseToolRemoved(NSMutableDictionary *document,NSString *type,BOOL removed); +void DYApplyRemovedBaseTools(DYUniforms *uniforms,NSDictionary *document); +NSDictionary *DYVisibleBaseToolPaths(NSDictionary *paths,NSDictionary *document); +BOOL DYResetToolParameters(id host,NSArray *descriptors,CMTime time,NSError **error); NSDictionary *DYToolSection(NSString *type); NSDictionary *DYNewTool(NSString *type); // New documents splice a UUID after the clicked base/extra tool. Schema 1 diff --git a/大鱼调色/Plugin/DYToolState.mm b/大鱼调色/Plugin/DYToolState.mm index 739b5e3..1090187 100644 --- a/大鱼调色/Plugin/DYToolState.mm +++ b/大鱼调色/Plugin/DYToolState.mm @@ -6,6 +6,47 @@ NSArray *DYToolTypes(void){return @[@"primary",@"spider",@"base",@"skin",@"look",@"hsl",@"curve",@"grading",@"primaries",@"levels",@"blackwhite",@"balance",@"mixer",@"film"];} NSDictionary *DYToolSection(NSString *type){for(NSDictionary *s in DYSections())if([s[@"key"]isEqual:type])return s;return nil;} +static NSArray *DYBaseToolParts(NSString *type){return [type isEqual:@"primary"]?@[@"input",@"primary",@"output"]:[type isEqual:@"base"]?@[@"base",@"color"]:@[type];} +NSArray *DYBaseToolDescriptors(NSString *type){ + if(![DYToolTypes()containsObject:type])return @[];NSMutableSet *pids=[NSMutableSet set]; + for(NSString *part in DYBaseToolParts(type)){NSDictionary *section=DYToolSection(part);if(section[@"enabled"])[pids addObject:section[@"enabled"]];for(NSDictionary *row in section[@"rows"]){if(row[@"pid"])[pids addObject:row[@"pid"]];if(row[@"enabled"])[pids addObject:row[@"enabled"]];}} + NSMutableArray *result=[NSMutableArray array];for(NSDictionary *d in DYDescriptors()){ + NSString *key=d[@"key"];BOOL extra=([type isEqual:@"primary"]&&([key hasPrefix:@"cm"]||[@[@"primaryMasterEnabled",@"inputProfile",@"preLUTStrength"]containsObject:key]))||([type isEqual:@"base"]&&[@[@"skinEnabled",@"copyAutoGrade"]containsObject:key])||([type isEqual:@"look"]&&([key hasPrefix:@"look"]||[key isEqual:@"postLUTStrength"]))||([type isEqual:@"film"]&&[key hasPrefix:@"film"]); + if(extra||[pids containsObject:d[@"pid"]])[result addObject:d]; + }return result; +} +BOOL DYBaseToolRemoved(NSDictionary *doc,NSString *type){return [doc[@"removedBase"]containsObject:type];} +BOOL DYSetBaseToolRemoved(NSMutableDictionary *doc,NSString *type,BOOL removed){ + if(!DYValidToolDocument(doc)||![DYToolTypes()containsObject:type])return NO; + NSMutableArray *types=[NSMutableArray arrayWithArray:doc[@"removedBase"]?:@[]];[types removeObject:type];if(removed){[types addObject:type];[doc[@"baseMasks"]removeObjectForKey:type];} + if(types.count)doc[@"removedBase"]=types;else[doc removeObjectForKey:@"removedBase"];return YES; +} +void DYApplyRemovedBaseTools(DYUniforms *u,NSDictionary *doc){ + for(NSString *type in doc[@"removedBase"]){ + for(NSDictionary *d in DYBaseToolDescriptors(type))if([d[@"offset"]integerValue]>=0)*(float*)((uint8_t*)u+[d[@"offset"]unsignedIntegerValue])=[d[@"default"]floatValue]; + for(NSString *part in DYBaseToolParts(type))for(NSDictionary *d in DYDescriptors())if([d[@"pid"]isEqual:DYToolSection(part)[@"enabled"]])*(float*)((uint8_t*)u+[d[@"offset"]unsignedIntegerValue])=0; + if([type isEqual:@"primary"]){u->primarySectionEnabled=0;u->inputProfile=0;u->preLUTStrength=0;} + if([type isEqual:@"base"])u->skinProtection.x=0; + } +} +NSDictionary *DYVisibleBaseToolPaths(NSDictionary *paths,NSDictionary *doc){ + if(!DYBaseToolRemoved(doc,@"primary")&&!DYBaseToolRemoved(doc,@"look"))return paths; + NSMutableDictionary *result=[[paths mutableCopy]autorelease]?:[NSMutableDictionary dictionary];if(DYBaseToolRemoved(doc,@"primary"))[result removeObjectForKey:@"input"]; + if(DYBaseToolRemoved(doc,@"look"))for(NSInteger i=0;i<5;i++)[result removeObjectForKey:[NSString stringWithFormat:@"look%ld",(long)i]];return result; +} +BOOL DYResetToolParameters(id host,NSArray *rows,CMTime time,NSError **error){ + id animation=[host apiForProtocol:@protocol(FxKeyframeAPI_v3)];NSMutableArray *channels=[NSMutableArray array]; + // Query every affected channel before making the first edit. Deleted base + // tools also stay excluded by document state if a host lacks this API. + if(animation)for(NSDictionary *d in rows)if(![d[@"notAnimatable"]boolValue]){ + NSUInteger count=0;NSError *failure=[animation channelCount:&count forParameter:[d[@"pid"]unsignedIntegerValue]];if(failure){if(error)*error=failure;return NO;} + for(NSUInteger channel=0;channel set=[host apiForProtocol:@protocol(FxParameterSettingAPI_v6)]; + for(NSDictionary *d in rows)if(![set setFloatValue:[d[@"default"]doubleValue] toParameter:[d[@"pid"]unsignedIntValue] atTime:time]){if(error)*error=[NSError errorWithDomain:@"com.dayu.color.ToolReset" code:1 userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"未能还原“%@”,模块已保留。",d[@"title"]?:d[@"key"]]}];return NO;} + return YES; +} NSMutableDictionary *DYMutablePlist(NSDictionary *value){if(!value)return [NSMutableDictionary dictionary];NSData *data=[NSPropertyListSerialization dataWithPropertyList:value format:NSPropertyListBinaryFormat_v1_0 options:0 error:nil];return [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainersAndLeaves format:NULL error:nil];} static NSDictionary *DYEmptyTools(){return @{@"schema":@1,@"layers":@[],@"baseMasks":@{}};} static BOOL finiteNumber(id v){return [v isKindOfClass:NSNumber.class]&&std::isfinite([v doubleValue]);} @@ -26,6 +67,7 @@ static BOOL validMasks(id masks,NSMutableSet *ids){if(![masks isKindOfClass:NSAr BOOL DYValidToolDocument(NSDictionary *doc){ if(![NSPropertyListSerialization propertyList:doc isValidForFormat:NSPropertyListBinaryFormat_v1_0])return NO; if(![doc isKindOfClass:NSDictionary.class]||(![doc[@"schema"]isEqual:@1]&&![doc[@"schema"]isEqual:@2])||![doc[@"layers"]isKindOfClass:NSArray.class]||[doc[@"layers"]count]>DYToolLimit||![doc[@"baseMasks"]isKindOfClass:NSDictionary.class]||[doc[@"baseMasks"]count]>DYToolTypes().count)return NO; + id removed=doc[@"removedBase"];if(removed){if(![removed isKindOfClass:NSArray.class]||[removed count]>DYToolTypes().count)return NO;NSMutableSet *unique=[NSMutableSet set];for(id type in removed){if(![type isKindOfClass:NSString.class]||![DYToolTypes()containsObject:type]||[unique containsObject:type]||[doc[@"baseMasks"][type]count])return NO;[unique addObject:type];}} NSMutableSet *ids=[NSMutableSet set];for(NSString *key in doc[@"baseMasks"]){if(![DYToolTypes()containsObject:key]||!validMasks(doc[@"baseMasks"][key],ids))return NO;} NSMutableDictionary *descriptors=[NSMutableDictionary dictionary];for(NSDictionary *d in DYDescriptors())descriptors[d[@"key"]]=d; for(NSDictionary *node in doc[@"layers"]){if(![node isKindOfClass:NSDictionary.class]||!validID(node[@"id"])||[ids containsObject:node[@"id"]]||![DYToolTypes()containsObject:node[@"type"]]||![node[@"values"]isKindOfClass:NSDictionary.class]||[node[@"values"]count]>descriptors.count||![node[@"paths"]isKindOfClass:NSDictionary.class]||[node[@"paths"]count]>6||!validMasks(node[@"masks"],ids))return NO;[ids addObject:node[@"id"]]; diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index 67dbb96..10cd468 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.7.3 + 1.7.4 CFBundleVersion - 49 + 50 NSHumanReadableCopyright PlugInKit @@ -71,7 +71,7 @@ uuid 1C17B73B-F229-4C09-A434-EAF6DFF5F22A version - 1.7.3 + 1.7.4 className diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 3cb5549..171f739 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.7.3 + 1.7.4 CFBundleVersion - 49 + 50 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright