From 1659f3d3853e2574f06a45687141fb444b5d02ca Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 5 Nov 2026 22:21:25 +0800 Subject: [PATCH] Clone original pixels by translation and keep the tracked footprint stable --- 大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h | 8 +++++++- 大鱼调色/Plugin/DYGrade.metal | 18 +++++++++--------- 大鱼调色/Plugin/DYManagedRender.inc.h | 6 ++---- 大鱼调色/Plugin/DYMaskPanel.inc.h | 4 ++-- 大鱼调色/Plugin/DYToolCanvasDiagnostics.inc.h | 9 +++++++++ 大鱼调色/Plugin/DYToolCanvasEditing.inc.h | 11 ++++++++--- 大鱼调色/Plugin/DYToolGPU.h | 7 +++---- 大鱼调色/Plugin/DYToolHostMethods.inc.h | 2 +- 大鱼调色/Plugin/DYToolOSC.inc.h | 2 +- 大鱼调色/Plugin/DYToolState.mm | 6 +++--- 大鱼调色/Plugin/Info.plist | 2 +- 大鱼调色/Wrapper Application/Info.plist | 2 +- 12 files changed, 47 insertions(+), 30 deletions(-) diff --git a/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h index ceb5bd9..e45f3fa 100644 --- a/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h @@ -80,7 +80,7 @@ if(faceFixture.length){ p.centerX=48.5f/w;p.centerY=24.5f/h;p.width=.25f;p.height=.25f; stamp[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)]; stamp[@"stampSource"]=@[@(16.5f/w),@(12.5f/h),@.25,@.25]; - CMTime next=CMTimeMake(1,25);DYMaskParameters moved=p;moved.centerY=34.5f/h; + CMTime next=CMTimeMake(1,25);DYMaskParameters moved=p;moved.centerY=34.5f/h;moved.width=.5f;moved.height=.12f;moved.angle=.65f; run.record(@"clone-stamp-preserves-source-through-tracking-merge",DYMergeTracking(stamp,@[DYMaskKey(kCMTimeZero,p,NO,1),DYMaskKey(next,moved,NO,1)])&&[stamp[@"stampSource"] count]==4); auto frame=[&](CMTime t,NSString *label){ NSError *failure=nil; @@ -94,6 +94,12 @@ if(faceFixture.length){ run.record(@"clone-stamp-copies-pixels-and-leaves-exterior-intact",pixel(first,48,24,baseline,16,12)<.002&&pixel(first,0,0,baseline,0,0)==0&&pixel(first,16,12,baseline,16,12)==0); Pixels second=frame(next,@"clone-stamp-tracked-production-render"); run.record(@"clone-stamp-tracked-target-moves-while-sampling-the-same-source",pixel(second,48,34,baseline,16,12)<.002&&pixel(second,48,24,baseline,48,24)==0); + DYMaskParameters translated=DYMaskAtTime(stamp,next); + run.record(@"clone-stamp-ignores-legacy-tracking-scale-and-rotation",translated.angle==0&&translated.width==p.width&&translated.height==p.height&&translated.centerY==moved.centerY&&pixel(second,51,35,baseline,19,13)==0); + p.width=.5f;p.height=.35f;p.angle=.55f; // A legacy authored rotation must not rotate copied pixels. + stamp[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)]; + Pixels expanded=frame(kCMTimeZero,@"clone-stamp-resized-production-render"); + run.record(@"clone-stamp-resize-extends-coverage-with-pixel-exact-translation",pixel(expanded,51,25,baseline,19,13)==0&&pixel(expanded,58,24,baseline,26,12)==0&&pixel(first,58,24,baseline,58,24)==0); stamp[@"enabled"]=@NO;Pixels disabled=frame(next,@"clone-stamp-disabled-render"); run.record(@"clone-stamp-disabled-is-identical",difference(disabled,baseline).maximum==0); stamp[@"enabled"]=@YES;NSError *failure=nil; diff --git a/大鱼调色/Plugin/DYGrade.metal b/大鱼调色/Plugin/DYGrade.metal index fcfebb3..9c2efa1 100644 --- a/大鱼调色/Plugin/DYGrade.metal +++ b/大鱼调色/Plugin/DYGrade.metal @@ -347,7 +347,7 @@ kernel void dyLensRepair(texture2d source [[texture(0)]],texture2d input [[texture(0)]], +kernel void dyCloneStamps(texture2d input [[texture(0)]], texture2d output [[texture(1)]], constant DYCloneStamp *stamps [[buffer(0)]], constant uint &count [[buffer(1)]], @@ -358,21 +358,21 @@ kernel void dyCloneStamps(texture2d input [[texture(0)]], float2 uv=(float2(gid)+.5f)/float2(size); if(flip)uv.y=1-uv.y; float4 color=input.read(gid); - constexpr sampler linearFilter(coord::normalized,address::clamp_to_edge,filter::linear); for(uint i=0;i1)continue; - float2 source=float2(stamp.sourceX,stamp.sourceY)+local*float2(stamp.sourceWidth,stamp.sourceHeight)*.5f; - if(any(source<0)||any(source>1))continue; - if(flip)source.y=1-source.y; + // A single integer-pixel offset preserves scale, orientation and sample values. + float2 offset=(float2(stamp.sourceX,stamp.sourceY)-center)*float2(size); + if(flip)offset.y=-offset.y; + int2 source=int2(gid)+int2(round(offset)); + if(any(source<0)||any(source>=int2(size)))continue; float coverage=stamp.feather>0?1-smoothstep(1-stamp.feather,1.f,sqrt(radiusSquared)):1; coverage=saturate((coverage-stamp.inputBlack)/(stamp.inputWhite-stamp.inputBlack)); if(stamp.inputGamma!=1)coverage=pow(coverage,1/stamp.inputGamma); - color=mix(color,input.sample(linearFilter,source),coverage*stamp.strength); + color=mix(color,input.read(uint2(source)),coverage*stamp.strength); } output.write(color,gid); } diff --git a/大鱼调色/Plugin/DYManagedRender.inc.h b/大鱼调色/Plugin/DYManagedRender.inc.h index cdbad74..17040ab 100644 --- a/大鱼调色/Plugin/DYManagedRender.inc.h +++ b/大鱼调色/Plugin/DYManagedRender.inc.h @@ -30,15 +30,13 @@ std::vector stamps; FxRect image=source.imagePixelBounds,bounds=source.tilePixelBounds; if(image.right<=image.left||image.top<=image.bottom)return source; - float aspect=float(image.right-image.left)/(image.top-image.bottom); for(NSDictionary *mask in masks){ NSArray *patch=mask[@"stampSource"]; if(!patch||![mask[@"enabled"]boolValue])continue; DYMaskParameters p=DYMaskAtTime(mask,kCMTimeInvalid); if(p.strength<=0)continue; - float c=cosf(p.angle),s=sinf(p.angle); - stamps.push_back({p.centerX,p.centerY,[patch[0]floatValue],[patch[1]floatValue],[patch[2]floatValue],[patch[3]floatValue], - 2*c/p.width,2*s/(p.width*aspect),-2*s*aspect/p.height,2*c/p.height,p.feather,p.strength,p.inputBlack,p.inputWhite,p.inputGamma}); + stamps.push_back({p.centerX,p.centerY,[patch[0]floatValue],[patch[1]floatValue], + 2/p.width,2/p.height,p.feather,p.strength,p.inputBlack,p.inputWhite,p.inputGamma}); } if(stamps.empty())return source; if(image.left!=bounds.left||image.right!=bounds.right||image.top!=bounds.top||image.bottom!=bounds.bottom){ diff --git a/大鱼调色/Plugin/DYMaskPanel.inc.h b/大鱼调色/Plugin/DYMaskPanel.inc.h index aa7e651..6f07cec 100644 --- a/大鱼调色/Plugin/DYMaskPanel.inc.h +++ b/大鱼调色/Plugin/DYMaskPanel.inc.h @@ -60,7 +60,7 @@ BOOL stamp=m[@"stampSource"]!=nil;_combine.hidden=_invert.hidden=stamp; _eye.state=[m[@"enabled"]boolValue]?NSControlStateValueOn:NSControlStateValueOff;_eye.image=[NSImage imageWithSystemSymbolName:[m[@"enabled"]boolValue]?@"eye":@"eye.slash" accessibilityDescription:@"启用蒙版"];[_combine selectItemAtIndex:[m[@"combine"]integerValue]];_invert.state=(p.flags&DYMaskInvert)?NSControlStateValueOn:NSControlStateValueOff; float values[]={p.strength,p.feather,p.centerX,p.centerY,p.width,p.height,float(p.angle*180.f/M_PI),p.gradientWidth,p.hueCenterTurns*360.f,p.hueCoreHalfWidth*360.f,p.hueSoftWidth*360.f,p.saturationRange.low,p.saturationRange.high,p.lightnessRange.low,p.lightnessRange.high,p.inputBlack,p.inputWhite,p.inputGamma}; - NSInteger visible=0;for(NSInteger i=0;i<_rows.count;i++){BOOL show=i==0||(i==1&&p.kind<3)||(i>=2&&i<=6&&p.kind<4)||(i==7&&p.kind==3)||(i>=8&&i<=14&&p.kind==4)||(i>=15&&p.kind>=4);NSDictionary *row=_rows[i];for(NSView *v in row.allValues)v.hidden=!show;if(!show)continue;visible++;double lo=0,hi=1;if(i==2||i==3)lo=-1,hi=2;if(i==4||i==5||i==7)lo=.001,hi=2;if(i==6)lo=-180,hi=180;if(i==8)hi=360;if(i==9||i==10)hi=180;if(i==15)hi=.99;if(i==16)lo=.01,hi=2;if(i==17)lo=.01,hi=4;NSSlider *slider=row[@"slider"];slider.minValue=lo;slider.maxValue=hi;slider.doubleValue=values[i];[row[@"field"]setStringValue:[NSString stringWithFormat:@"%.3f",values[i]]];} + NSInteger visible=0;for(NSInteger i=0;i<_rows.count;i++){BOOL show=i==0||(i==1&&p.kind<3)||(i>=2&&i<=6&&p.kind<4&&(!stamp||i!=6))||(i==7&&p.kind==3)||(i>=8&&i<=14&&p.kind==4)||(i>=15&&p.kind>=4);NSDictionary *row=_rows[i];for(NSView *v in row.allValues)v.hidden=!show;if(!show)continue;visible++;double lo=0,hi=1;if(i==2||i==3)lo=-1,hi=2;if(i==4||i==5||i==7)lo=.001,hi=2;if(i==6)lo=-180,hi=180;if(i==8)hi=360;if(i==9||i==10)hi=180;if(i==15)hi=.99;if(i==16)lo=.01,hi=2;if(i==17)lo=.01,hi=4;NSSlider *slider=row[@"slider"];slider.minValue=lo;slider.maxValue=hi;slider.doubleValue=values[i];[row[@"field"]setStringValue:[NSString stringWithFormat:@"%.3f",values[i]]];} BOOL shape=p.kind<3;for(NSButton *b in _tracking)b.hidden=!shape;_trackingTitle.hidden=!shape;_clear.hidden=!shape;_clear.enabled=[m[@"keys"]count]>0; BOOL pen=p.kind==DYMaskBezier;_penRedraw.hidden=!pen;_penFinish.hidden=!pen;_penCancel.hidden=!pen; [self updateDrawingControls]; @@ -101,7 +101,7 @@ - (void)enabled:(NSButton*)sender{[self edit:@"启停蒙版" block:^(NSMutableDictionary *d,NSMutableDictionary *m){m[@"enabled"]=@(sender.state==NSControlStateValueOn);}];} - (void)combine:(id)sender{[self edit:@"蒙版组合" block:^(NSMutableDictionary *d,NSMutableDictionary *m){m[@"combine"]=@(self->_combine.indexOfSelectedItem);}];} - (void)inverted:(NSButton*)sender{[self edit:@"反转蒙版" block:^(NSMutableDictionary *d,NSMutableDictionary *m){DYMaskParameters p;[m[@"parameters"]getBytes:&p length:sizeof(p)];if(sender.state)p.flags|=DYMaskInvert;else p.flags&=~DYMaskInvert;m[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];}];} -- (void)valueChanged:(NSControl*)sender{if(_refreshing)return;double value=sender.doubleValue;if([sender isKindOfClass:NSTextField.class]){NSString *text=[sender.stringValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];NSScanner *scanner=[NSScanner scannerWithString:text];if(![scanner scanDouble:&value]||!scanner.isAtEnd){NSBeep();[self refreshWithDocument:_document time:_time];return;}}if(!std::isfinite(value)){NSBeep();return;}NSInteger i=sender.tag;[self edit:@"调整工具蒙版" block:^(NSMutableDictionary *d,NSMutableDictionary *m){DYMaskParameters p=DYMaskAtTime(m,self->_time);float *fields[]={&p.strength,&p.feather,&p.centerX,&p.centerY,&p.width,&p.height,&p.angle,&p.gradientWidth,&p.hueCenterTurns,&p.hueCoreHalfWidth,&p.hueSoftWidth,&p.saturationRange.low,&p.saturationRange.high,&p.lightnessRange.low,&p.lightnessRange.high,&p.inputBlack,&p.inputWhite,&p.inputGamma};*fields[i]=(i==6?value*M_PI/180:i>=8&&i<=10?value/360:value);if(p.kind==DYMaskHSLKey)p.flags|=DYMaskHueEnabled|DYMaskSaturationEnabled|DYMaskLightnessEnabled;if(!dyValidMaskParameters(p))return;if([m[@"keys"]count]&&i<8){NSMutableArray *keys=[[m[@"keys"]mutableCopy]autorelease];[keys filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSDictionary *key,NSDictionary *bindings){CMTime t=CMTimeMakeWithEpoch([key[@"value"]longLongValue],[key[@"scale"]intValue],[key[@"epoch"]longLongValue]);return CMTimeCompare(t,self->_time)!=0;}]];[keys addObject:DYMaskKey(self->_time,p,YES,1)];[keys sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){CMTime x=CMTimeMakeWithEpoch([a[@"value"]longLongValue],[a[@"scale"]intValue],[a[@"epoch"]longLongValue]),y=CMTimeMakeWithEpoch([b[@"value"]longLongValue],[b[@"scale"]intValue],[b[@"epoch"]longLongValue]);return (NSComparisonResult)CMTimeCompare(x,y);}];m[@"keys"]=keys;}else m[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];}];} +- (void)valueChanged:(NSControl*)sender{if(_refreshing)return;double value=sender.doubleValue;if([sender isKindOfClass:NSTextField.class]){NSString *text=[sender.stringValue stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];NSScanner *scanner=[NSScanner scannerWithString:text];if(![scanner scanDouble:&value]||!scanner.isAtEnd){NSBeep();[self refreshWithDocument:_document time:_time];return;}}if(!std::isfinite(value)){NSBeep();return;}NSInteger i=sender.tag;[self edit:@"调整工具蒙版" block:^(NSMutableDictionary *d,NSMutableDictionary *m){BOOL stamp=m[@"stampSource"]!=nil,position=i==2||i==3;DYMaskParameters p=DYMaskAtTime(m,stamp&&!position?kCMTimeInvalid:self->_time);float *fields[]={&p.strength,&p.feather,&p.centerX,&p.centerY,&p.width,&p.height,&p.angle,&p.gradientWidth,&p.hueCenterTurns,&p.hueCoreHalfWidth,&p.hueSoftWidth,&p.saturationRange.low,&p.saturationRange.high,&p.lightnessRange.low,&p.lightnessRange.high,&p.inputBlack,&p.inputWhite,&p.inputGamma};*fields[i]=(i==6?value*M_PI/180:i>=8&&i<=10?value/360:value);if(p.kind==DYMaskHSLKey)p.flags|=DYMaskHueEnabled|DYMaskSaturationEnabled|DYMaskLightnessEnabled;if(!dyValidMaskParameters(p))return;if([m[@"keys"]count]&&(stamp?position:i<8)){NSMutableArray *keys=[[m[@"keys"]mutableCopy]autorelease];[keys filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSDictionary *key,NSDictionary *bindings){CMTime t=CMTimeMakeWithEpoch([key[@"value"]longLongValue],[key[@"scale"]intValue],[key[@"epoch"]longLongValue]);return CMTimeCompare(t,self->_time)!=0;}]];[keys addObject:DYMaskKey(self->_time,p,YES,1)];[keys sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){CMTime x=CMTimeMakeWithEpoch([a[@"value"]longLongValue],[a[@"scale"]intValue],[a[@"epoch"]longLongValue]),y=CMTimeMakeWithEpoch([b[@"value"]longLongValue],[b[@"scale"]intValue],[b[@"epoch"]longLongValue]);return (NSComparisonResult)CMTimeCompare(x,y);}];m[@"keys"]=keys;}else m[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];}];} - (void)updateDrawingControls{for(NSButton *button in _tracking)button.enabled=!_drawing;_clear.enabled=!_drawing&&[[self mask][@"keys"]count]>0;_penFinish.enabled=_drawing;_penCancel.enabled=_drawing;} - (NSString*)canvasNodeID{return DYSharedMaskWithID(_document,_maskID)?@"shared":_nodeID;} - (BOOL)representsCanvasMask:(NSDictionary*)info{NSString *maskID=info[@"mask"];if(!maskID.length)return NO;if([info[@"node"]isEqual:_nodeID])return YES;if(!DYSharedMaskWithID(_document,maskID))return NO;for(NSDictionary *mask in DYMasksForTool(_document,_nodeID))if([mask[@"id"]isEqual:maskID])return YES;return NO;} diff --git a/大鱼调色/Plugin/DYToolCanvasDiagnostics.inc.h b/大鱼调色/Plugin/DYToolCanvasDiagnostics.inc.h index dba3486..ebb6b9d 100644 --- a/大鱼调色/Plugin/DYToolCanvasDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYToolCanvasDiagnostics.inc.h @@ -140,6 +140,15 @@ [osc keyDownAtPositionX:270 positionY:240 keyPressed:27 modifiers:0 forceUpdate:&update didHandle:&handled atTime:kCMTimeZero]; drain(); run.record(@"native-osc-escape-cancels-the-stamp-source-drag-without-another-undo",handled&&[DYSharedMaskWithID(DYReadTools(host,kCMTimeZero).document,stampID)[@"stampSource"]isEqual:relocated]&&base->_undoStarts==undo+1); + [osc drawOSCWithWidth:640 height:400 activePart:0 destinationImage:overlay atTime:kCMTimeZero]; + BOOL rotationHandle=NO; + for(NSDictionary *handle in [(id)osc valueForKey:@"handles"])rotationHandle|=[handle[@"part"]integerValue]==6; + part=down(348,244); + [osc mouseDraggedAtPositionX:320 positionY:260 activePart:part modifiers:0 forceUpdate:&update atTime:kCMTimeZero]; + up(320,260,part);drain(); + NSDictionary *resized=DYSharedMaskWithID(DYReadTools(host,kCMTimeZero).document,stampID); + DYMaskParameters enlarged=DYMaskAtTime(resized,kCMTimeZero); + run.record(@"native-osc-stamp-resizes-coverage-without-rotation-handle-or-track-changes",!rotationHandle&&part==2&&enlarged.width>target.width&&enlarged.height>target.height&&enlarged.centerX==target.centerX&&enlarged.centerY==target.centerY&&[resized[@"keys"]isEqual:keys]); click(251,104);drain(); // top-down viewport y=30...345, forward button is x=212...290. run.record(@"native-osc-stamp-forward-action-starts-the-existing-host-tracker",host->_forwardStarts==1&&host->_backwardStarts==0); [plugin cleanupAnalysis:nil];drain();[(id)osc release];[(id)plugin release]; diff --git a/大鱼调色/Plugin/DYToolCanvasEditing.inc.h b/大鱼调色/Plugin/DYToolCanvasEditing.inc.h index ed59ee1..814812e 100644 --- a/大鱼调色/Plugin/DYToolCanvasEditing.inc.h +++ b/大鱼调色/Plugin/DYToolCanvasEditing.inc.h @@ -8,8 +8,8 @@ @synchronized(self){[_toolCanvasDraft release];_toolCanvasDraft=nil;[_toolCanvasOriginal release];_toolCanvasOriginal=nil;_toolDrawingPen=_toolDrawingShape=NO;_toolCanvasHasHover=NO;_toolCanvasEditTime=kCMTimeInvalid;++_toolCanvasRevision;}[self postToolCanvasStatus:nil]; } - (void)commitToolCanvasDraftAtTime:(CMTime)eventTime { - NSDictionary *draft=nil,*original=nil;NSString *node=nil,*maskID=nil;CMTime time;uint64_t revision;BOOL sourceEdit; - @synchronized(self){if(!_toolCanvasDraft||!_toolCanvasOriginal)return;if(!CMTIME_IS_NUMERIC(eventTime)||CMTimeCompare(eventTime,_toolCanvasEditTime)!=0){[self discardToolCanvasDraft];[self postToolCanvasStatus:@"播放头已移动,请重新绘制。"];return;}draft=[_toolCanvasDraft copy];original=[_toolCanvasOriginal copy];node=[_selectedToolNode copy];maskID=[_selectedToolMask copy];time=_toolCanvasEditTime;sourceEdit=_toolDragPart==DYCloneSourcePart; + NSDictionary *draft=nil,*original=nil;NSString *node=nil,*maskID=nil;CMTime time;uint64_t revision;BOOL sourceEdit,resizeStamp; + @synchronized(self){if(!_toolCanvasDraft||!_toolCanvasOriginal)return;if(!CMTIME_IS_NUMERIC(eventTime)||CMTimeCompare(eventTime,_toolCanvasEditTime)!=0){[self discardToolCanvasDraft];[self postToolCanvasStatus:@"播放头已移动,请重新绘制。"];return;}draft=[_toolCanvasDraft copy];original=[_toolCanvasOriginal copy];node=[_selectedToolNode copy];maskID=[_selectedToolMask copy];time=_toolCanvasEditTime;sourceEdit=_toolDragPart==DYCloneSourcePart;resizeStamp=draft[@"stampSource"]&&_toolDragPart>=2&&_toolDragPart<=5; // Keep the completed path visible until the authoritative write returns. // Discarding it here exposed the new pen mask's default rectangular nodes // during the OSC redraw that immediately follows the closing click. @@ -23,7 +23,12 @@ NSMutableDictionary *doc=DYMutablePlist(DYReadTools(self->_apiManager,time).document),*current=[self toolMask:maskID node:node document:doc]; if(!current||![current isEqual:original]){os_log(OS_LOG_DEFAULT,"dayu_pen_commit conflict current=%{public}d",current!=nil);[self postToolCanvasStatus:@"蒙版已在其它位置修改,本次画面草稿未覆盖它。"];return;} NSMutableDictionary *result=sourceEdit?[[draft mutableCopy]autorelease]:DYMutablePlist(draft); - if(!sourceEdit&&[current[@"keys"]count]){DYMaskParameters p=DYMaskAtTime(result,time);NSMutableArray *keys=[[current[@"keys"]mutableCopy]autorelease];NSIndexSet *same=[keys indexesOfObjectsPassingTest:^BOOL(NSDictionary *key,NSUInteger i,BOOL *stop){return CMTimeCompare(CMTimeMakeWithEpoch([key[@"value"]longLongValue],[key[@"scale"]intValue],[key[@"epoch"]longLongValue]),time)==0;}];[keys removeObjectsAtIndexes:same];[keys addObject:DYMaskKey(time,p,YES,1)];result[@"keys"]=@[];if(!DYMergeTracking(result,keys))return;} + if(resizeStamp){ + DYMaskParameters p=DYMaskAtTime(result,kCMTimeInvalid),authored=DYMaskAtTime(current,kCMTimeInvalid); + authored.width=p.width;authored.height=p.height; + result[@"parameters"]=[NSData dataWithBytes:&authored length:sizeof(authored)]; + result[@"keys"]=current[@"keys"]; + }else if(!sourceEdit&&[current[@"keys"]count]){DYMaskParameters p=DYMaskAtTime(result,time);if(current[@"stampSource"])result[@"parameters"]=current[@"parameters"];NSMutableArray *keys=[[current[@"keys"]mutableCopy]autorelease];NSIndexSet *same=[keys indexesOfObjectsPassingTest:^BOOL(NSDictionary *key,NSUInteger i,BOOL *stop){return CMTimeCompare(CMTimeMakeWithEpoch([key[@"value"]longLongValue],[key[@"scale"]intValue],[key[@"epoch"]longLongValue]),time)==0;}];[keys removeObjectsAtIndexes:same];[keys addObject:DYMaskKey(time,p,YES,1)];result[@"keys"]=@[];if(!DYMergeTracking(result,keys))return;} if(DYValidToolMask(result)&&![current isEqual:result]){[current setDictionary:result];idundo=[self->_apiManager apiForProtocol:@protocol(FxUndoAPI)];[undo startUndoGroup:sourceEdit?@"移动图章取样点":@"编辑工具蒙版"];changed=DYWriteTools(self->_apiManager,doc,time);[undo endUndoGroup];if(changed){DYToolDocument *saved=[[[DYToolDocument alloc]init]autorelease];saved.document=doc;[self adoptToolCanvasDocument:saved.document];}} }@finally{[a endAction:self];} os_log(OS_LOG_DEFAULT,"dayu_pen_commit result=%{public}d valid=%{public}d",changed,DYValidToolMask(draft)); diff --git a/大鱼调色/Plugin/DYToolGPU.h b/大鱼调色/Plugin/DYToolGPU.h index 6123c2a..f475be1 100644 --- a/大鱼调色/Plugin/DYToolGPU.h +++ b/大鱼调色/Plugin/DYToolGPU.h @@ -4,9 +4,8 @@ struct DYToolMaskEntry {DYResolvedMask mask;int section,combine;}; struct DYToolMaskHeader {unsigned count;float offsetX,offsetY,scaleX,scaleY;int section,premultiplied,faceOnly,skinPreview;}; struct DYToolStageRange {int first,last,suppressBlackWhite;}; -// Map normalized destination coordinates to the original source ellipse. +// Destination coverage and source offset are independent. struct DYCloneStamp { - float centerX,centerY,sourceX,sourceY,sourceWidth,sourceHeight; - float localXX,localXY,localYX,localYY; - float feather,strength,inputBlack,inputWhite,inputGamma; + float centerX,centerY,sourceX,sourceY; + float inverseRadiusX,inverseRadiusY,feather,strength,inputBlack,inputWhite,inputGamma; }; diff --git a/大鱼调色/Plugin/DYToolHostMethods.inc.h b/大鱼调色/Plugin/DYToolHostMethods.inc.h index 70ba721..d1bc137 100644 --- a/大鱼调色/Plugin/DYToolHostMethods.inc.h +++ b/大鱼调色/Plugin/DYToolHostMethods.inc.h @@ -106,7 +106,7 @@ if(!_trackingSamples.count){if(_trackingReferenceFrame.valid()&&frame.width==_trackingReferenceFrame.width&&frame.height==_trackingReferenceFrame.height){double same=0,flip=0;size_t count=0;for(int y=0;y0?fmax(0,fmin(1,CMTimeGetSeconds(CMTimeSubtract(time,keyTime(left)))/duration)):0; - // Only temporal geometry/feather/strength interpolate; key selection and levels stay authored. - float *v=&p.centerX,*av=&a.centerX,*bv=&b.centerX;for(int i=0;i<8;i++)v[i]=av[i]+(bv[i]-av[i])*w;return p;} +DYMaskParameters DYMaskAtTime(NSDictionary *mask,CMTime time){DYMaskParameters p=dyDefaultMaskParameters();readParameters(mask[@"parameters"],&p);BOOL stamp=mask[@"stampSource"]!=nil;if(stamp)p.angle=0;NSArray *keys=mask[@"keys"];if(!keys.count||!CMTIME_IS_NUMERIC(time))return p;if(keyTime(keys[0]).epoch!=time.epoch)return p;NSUInteger low=0,high=keys.count;while(low0?fmax(0,fmin(1,CMTimeGetSeconds(CMTimeSubtract(time,keyTime(left)))/duration)):0; + // Clone stamps follow the center only. The authored extent is a coverage control. + float *v=&p.centerX,*av=&a.centerX,*bv=&b.centerX;for(int i=0;i<(stamp?2:8);i++)v[i]=av[i]+(bv[i]-av[i])*w;return p;} NSDictionary *DYMaskKey(CMTime t,DYMaskParameters p,BOOL manual,float confidence){return @{@"value":@(t.value),@"scale":@(t.timescale),@"epoch":@(t.epoch),@"parameters":parameterData(p),@"manual":@(manual),@"confidence":@(confidence)};} BOOL DYMergeTracking(NSMutableDictionary *m,NSArray *samples){if(!samples.count)return YES;NSMutableArray *all=[NSMutableArray array];CMTime lo=keyTime(samples.firstObject),hi=keyTime(samples.lastObject);if(CMTimeCompare(lo,hi)>0)std::swap(lo,hi);for(NSDictionary *key in m[@"keys"])if([key[@"manual"]boolValue]||CMTimeCompare(keyTime(key),lo)<0||CMTimeCompare(keyTime(key),hi)>0)[all addObject:key];for(NSDictionary *key in samples){BOOL manual=NO;for(NSDictionary *old in all)if(CMTimeCompare(keyTime(old),keyTime(key))==0){manual=YES;break;}if(!manual)[all addObject:key];}[all sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){return (NSComparisonResult)CMTimeCompare(keyTime(a),keyTime(b));}];NSMutableDictionary *candidate=DYMutablePlist(m);candidate[@"keys"]=all;if(!DYValidToolMask(candidate))return NO;m[@"keys"]=all;return YES;} NSDictionary *DYToolRenderSnapshot(NSDictionary *doc,CMTime t){ diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index 3234ade..140c8f5 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.13.1 CFBundleVersion - 84 + 85 NSHumanReadableCopyright PlugInKit diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 3e237e3..67ccaaf 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.13.1 CFBundleVersion - 84 + 85 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright