Clone original pixels by translation and keep the tracked footprint stable
这个提交包含在:
1 父节点
dff9134be7
当前提交
1659f3d385
12 个文件已更改
+47
-30
没有与搜索条件相匹配的文件
@@ -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;
|
||||
|
||||
@@ -347,7 +347,7 @@ kernel void dyLensRepair(texture2d<float> source [[texture(0)]],texture2d<float,
|
||||
constexpr sampler f(coord::normalized,address::clamp_to_zero,filter::linear);output.write(source.sample(f,sample),p);
|
||||
}
|
||||
|
||||
kernel void dyCloneStamps(texture2d<float,access::sample> input [[texture(0)]],
|
||||
kernel void dyCloneStamps(texture2d<float,access::read> input [[texture(0)]],
|
||||
texture2d<float,access::write> output [[texture(1)]],
|
||||
constant DYCloneStamp *stamps [[buffer(0)]],
|
||||
constant uint &count [[buffer(1)]],
|
||||
@@ -358,21 +358,21 @@ kernel void dyCloneStamps(texture2d<float,access::sample> 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;i<count;i++){
|
||||
constant DYCloneStamp &stamp=stamps[i];
|
||||
float2 delta=uv-float2(stamp.centerX,stamp.centerY);
|
||||
float2 local=float2(dot(delta,float2(stamp.localXX,stamp.localXY)),
|
||||
dot(delta,float2(stamp.localYX,stamp.localYY)));
|
||||
float2 center=float2(stamp.centerX,stamp.centerY);
|
||||
float2 local=(uv-center)*float2(stamp.inverseRadiusX,stamp.inverseRadiusY);
|
||||
float radiusSquared=dot(local,local);
|
||||
if(radiusSquared>1)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);
|
||||
}
|
||||
@@ -30,15 +30,13 @@
|
||||
std::vector<DYCloneStamp> 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){
|
||||
|
||||
@@ -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;}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];id<FxUndoAPI>undo=[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));
|
||||
|
||||
+3
-4
@@ -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;
|
||||
};
|
||||
@@ -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;y<frame.height;y+=8)for(int x=0;x<frame.width;x+=8){float p=frame.pixels[y*frame.width+x];same+=fabs(p-_trackingReferenceFrame.pixels[y*frame.width+x]);flip+=fabs(p-_trackingReferenceFrame.pixels[(frame.height-1-y)*frame.width+x]);count++;}same/=MAX(size_t(1),count);flip/=MAX(size_t(1),count);_trackingFlip=flip<.035&&flip+.008<same&&flip<same*.8;}os_log(OS_LOG_DEFAULT,"dayu_tool_track_seed width=%{public}d height=%{public}d flip=%{public}d time=%{public}.6f",frame.width,frame.height,(int)_trackingFlip,CMTimeGetSeconds(time));}
|
||||
if(_trackingFlip)for(int y=0;y<frame.height/2;y++)for(int x=0;x<frame.width;x++)std::swap(frame.pixels[y*frame.width+x],frame.pixels[(frame.height-1-y)*frame.width+x]);
|
||||
if(!_trackingSamples.count){if(!_toolTracker.reset(frame,{_trackingSeed.centerX,_trackingSeed.centerY,_trackingSeed.width,_trackingSeed.height,_trackingSeed.angle}))return [self finishToolAnalysis:@"蒙版内纹理不足,原蒙版已保留" error:error];}else if(!_toolTracker.track(frame).valid){auto lost=_toolTracker.result();NSString *reason=@"区域内运动不一致";switch(lost.failure){case dy::TrackFailure::InsufficientMatches:reason=@"可用特征点不足";break;case dy::TrackFailure::LowConfidence:reason=@"运动可信度不足";break;case dy::TrackFailure::OutsideFrame:reason=@"目标已离开画面";break;case dy::TrackFailure::InvalidTransform:reason=@"运动变换过大";break;case dy::TrackFailure::Backend:case dy::TrackFailure::InvalidFrame:reason=@"源画面或跟踪引擎异常";break;default:break;}os_log(OS_LOG_DEFAULT,"dayu_tool_track_loss time=%{public}.6f reason=%{public}d features=%{public}d matches=%{public}d inliers=%{public}d confidence=%{public}.3f residual=%{public}.3f",CMTimeGetSeconds(time),(int)lost.failure,lost.features,lost.matches,lost.inliers,lost.confidence,lost.medianError);return [self finishToolAnalysis:[NSString stringWithFormat:@"%@,已保留 %lu 帧可信轨迹;可调整蒙版后从此处继续",reason,(unsigned long)_trackingSamples.count] error:error];}
|
||||
auto result=_toolTracker.result();DYMaskParameters p=DYMaskAtTime(_trackingFrozenMask,time);p.centerX=result.cx;p.centerY=result.cy;p.width=_trackingSeed.width*result.scaleX;p.height=_trackingSeed.height*result.scaleY;p.angle=_trackingSeed.angle+result.rotation;if(!dyValidMaskParameters(p))return [self stopToolAnalysis:@"跟踪变换无效,未写入错误结果" error:error];[_trackingSamples addObject:DYMaskKey(time,p,NO,result.confidence)];_trackingPreviousTime=time;
|
||||
auto result=_toolTracker.result();DYMaskParameters p=DYMaskAtTime(_trackingFrozenMask,time);p.centerX=result.cx;p.centerY=result.cy;if(!_trackingFrozenMask[@"stampSource"]){p.width=_trackingSeed.width*result.scaleX;p.height=_trackingSeed.height*result.scaleY;p.angle=_trackingSeed.angle+result.rotation;}if(!dyValidMaskParameters(p))return [self stopToolAnalysis:@"跟踪变换无效,未写入错误结果" error:error];[_trackingSamples addObject:DYMaskKey(time,p,NO,result.confidence)];_trackingPreviousTime=time;
|
||||
if(_trackingSamples.count==1||_trackingSamples.count%15==0)[self toolStatus:[NSString stringWithFormat:@"已分析 %lu 帧 · 置信度 %.0f%%",(unsigned long)_trackingSamples.count,result.confidence*100]];return YES;
|
||||
}@finally{_trackingInFrame.store(false);}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
else if(p.kind==DYMaskLinearGradient){[_outline moveToPoint:[self canvasPoint:0 y:-2 parameters:p]];[_outline lineToPoint:[self canvasPoint:0 y:2 parameters:p]];}
|
||||
if([mask[@"coverage"]boolValue]&&p.kind<3){[[NSColor colorWithCalibratedRed:1 green:.7 blue:.05 alpha:.2]setFill];[_outline fill];}
|
||||
[[NSColor colorWithWhite:0 alpha:.8]setStroke];_outline.lineWidth=3.5*_uiScale;[_outline stroke];[[NSColor colorWithCalibratedRed:1 green:.8 blue:.15 alpha:1]setStroke];_outline.lineWidth=1.5*_uiScale;[_outline stroke];
|
||||
if(p.kind<4&&![mask[@"drawing"]boolValue]&&![mask[@"drawShape"]boolValue]){[self addHandle:[self canvasPoint:0 y:0 parameters:p] part:1];if(p.kind!=DYMaskBezier){for(int i=0;i<4;i++)[self addHandle:[self canvasPoint:((float[]){-.5,.5,.5,-.5})[i] y:((float[]){-.5,-.5,.5,.5})[i] parameters:p] part:2+i];}[self addHandle:[self canvasPoint:0 y:-.68 parameters:p] part:6];}
|
||||
if(p.kind<4&&![mask[@"drawing"]boolValue]&&![mask[@"drawShape"]boolValue]){[self addHandle:[self canvasPoint:0 y:0 parameters:p] part:1];if(p.kind!=DYMaskBezier){for(int i=0;i<4;i++)[self addHandle:[self canvasPoint:((float[]){-.5,.5,.5,-.5})[i] y:((float[]){-.5,-.5,.5,.5})[i] parameters:p] part:2+i];}if(![mask[@"stampSource"]count])[self addHandle:[self canvasPoint:0 y:-.68 parameters:p] part:6];}
|
||||
for(NSDictionary *handle in _handles){NSPoint point=[handle[@"point"]pointValue];NSRect rect=NSMakeRect(point.x-4*_uiScale,point.y-4*_uiScale,8*_uiScale,8*_uiScale);[[NSColor colorWithWhite:.1 alpha:1]setFill];[[NSBezierPath bezierPathWithOvalInRect:rect]fill];[NSColor.whiteColor setStroke];[[NSBezierPath bezierPathWithOvalInRect:rect]stroke];}
|
||||
if([mask[@"drawing"]boolValue]){
|
||||
NSShadow *shadow=[[[NSShadow alloc]init]autorelease];shadow.shadowColor=[NSColor colorWithWhite:0 alpha:.95];shadow.shadowBlurRadius=2;shadow.shadowOffset=NSZeroSize;
|
||||
|
||||
@@ -158,9 +158,9 @@ static NSDictionary *DYExpandSharedMasks(NSDictionary *doc,BOOL keepKeys){
|
||||
for(NSString *type in doc[@"baseMasks"])base[type]=resolve([@"base:" stringByAppendingString:type]);out[@"baseMasks"]=base;NSMutableArray *layers=[NSMutableArray array];for(NSDictionary *node in doc[@"layers"]){NSMutableDictionary *copy=[[node mutableCopy]autorelease];copy[@"masks"]=resolve(node[@"id"]);[layers addObject:copy];}out[@"layers"]=layers;out[@"schema"]=@2;[out removeObjectForKey:@"sharedMasks"];return out;
|
||||
}
|
||||
NSDictionary *DYResolvedToolDocument(NSDictionary *doc){return DYExpandSharedMasks(doc,NO);}
|
||||
DYMaskParameters DYMaskAtTime(NSDictionary *mask,CMTime time){DYMaskParameters p=dyDefaultMaskParameters();readParameters(mask[@"parameters"],&p);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(low<high){NSUInteger mid=low+(high-low)/2;if(CMTimeCompare(keyTime(keys[mid]),time)<0)low=mid+1;else high=mid;}NSDictionary *left=keys[low?low-1:0],*right=keys[MIN(low,keys.count-1)];DYMaskParameters a,b;readParameters(left[@"parameters"],&a);readParameters(right[@"parameters"],&b);double duration=CMTimeGetSeconds(CMTimeSubtract(keyTime(right),keyTime(left)));float w=duration>0?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(low<high){NSUInteger mid=low+(high-low)/2;if(CMTimeCompare(keyTime(keys[mid]),time)<0)low=mid+1;else high=mid;}NSDictionary *left=keys[low?low-1:0],*right=keys[MIN(low,keys.count-1)];DYMaskParameters a,b;readParameters(left[@"parameters"],&a);readParameters(right[@"parameters"],&b);double duration=CMTimeGetSeconds(CMTimeSubtract(keyTime(right),keyTime(left)));float w=duration>0?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){
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.13.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>84</string>
|
||||
<string>85</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string></string>
|
||||
<key>PlugInKit</key>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.13.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>84</string>
|
||||
<string>85</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
在新工单中引用
屏蔽一个用户