diff --git a/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h index dd665d8..809f3d7 100644 --- a/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYCanvasToolsDiagnostics.inc.h @@ -124,6 +124,24 @@ if(faceFixture.length){ stamp[@"keys"]=@[DYStampKey(next,moved,YES,1,endMotion)]; Pixels equalZoom=frame(next,@"clone-stamp-equal-scale-production-render"); run.record(@"clone-stamp-equal-zoom-preserves-pixel-exact-copy",pixel(equalZoom,52,38,baseline,24,18)==0); + DYStampMotion subpixel=startMotion; + subpixel.sourceOffsetX=.5f/w; + stamp[@"keys"]=@[DYStampKey(next,p,NO,1,subpixel)]; + Pixels atUnit=frame(next,@"clone-stamp-fractional-translation-at-unit-zoom"); + subpixel.sourceScaleX=1.0002f; + stamp[@"keys"]=@[DYStampKey(next,p,NO,1,subpixel)]; + Pixels nearUnit=frame(next,@"clone-stamp-fractional-translation-near-unit-zoom"); + float unitPixel=(baseline[(12*w+16)*4]+baseline[(12*w+17)*4])*.5f; + run.record(@"clone-stamp-fractional-translation-is-continuous-through-unit-zoom", + fabs(atUnit[(24*w+48)*4]-unitPixel)<.0004f&&pixel(atUnit,48,24,nearUnit,48,24)<.0004f); + subpixel.sourceOffsetX=-16.5f/w; + subpixel.sourceScaleX=1; + stamp[@"keys"]=@[DYStampKey(next,p,NO,1,subpixel)]; + Pixels atEdge=frame(next,@"clone-stamp-fractional-source-crossing-image-edge"); + float edgePixel=(baseline[(12*w)*4]+baseline[(24*w+48)*4])*.5f; + run.record(@"clone-stamp-source-fades-continuously-at-image-edge", + fabs(atEdge[(24*w+48)*4]-edgePixel)<.0005f); + stamp[@"keys"]=@[DYStampKey(next,moved,YES,1,endMotion)]; DYMaskParameters differentTarget=moved;differentTarget.centerY=.45f; endMotion.sourceScaleX=1.25f; run.record(@"clone-stamp-retracking-updates-paired-data-without-overwriting-manual-target", @@ -141,6 +159,31 @@ if(faceFixture.length){ merged&&mergedKeys.count==5&&[mergedKeys[0] isEqual:DYMaskKey(previous,p,NO,1)]&& [mergedKeys[1] isEqual:pairKeys[0]]&&[mergedKeys[2] isEqual:DYMaskKey(authored,p,YES,1)]&& [mergedKeys[3] isEqual:pairKeys[1]]&&[mergedKeys[4] isEqual:DYMaskKey(following,p,NO,1)]); + NSMutableArray *jitter=[NSMutableArray array]; + for(int i=0;i<7;i++){ + DYMaskParameters shape=p; + shape.centerX+=i*.01f+(i==3?.04f:0); + DYStampMotion motion=startMotion; + motion.sourceOffsetY=i*.01f+(i==3?.04f:0); + motion.sourceScaleX=expf(i*.02f+(i==3?.08f:0)); + motion.targetScaleY=expf(i*-.02f+(i==3?-.08f:0)); + [jitter addObject:DYStampKey(CMTimeMake(i,25),shape,NO,.9f,motion)]; + } + stamp[@"keys"]=@[]; + BOOL stable=DYMergeTracking(stamp,jitter,frameDuration); + NSArray *smoothed=stamp[@"keys"]; + CMTime center=CMTimeMake(3,25); + auto filtered=DYStampMotionAtTime(stamp,center); + float expectedSpike=.04f*6/16; + run.record(@"clone-stamp-smooths-both-positions-and-log-scales-and-keeps-analysis-endpoints", + stable&&smoothed.count==7&&[smoothed.firstObject isEqual:jitter.firstObject]&& + [smoothed.lastObject isEqual:jitter.lastObject]&& + fabs(DYMaskAtTime(stamp,center).centerX-p.centerX-.03f-expectedSpike)<1e-6&& + fabs(filtered.sourceOffsetY-.03f-expectedSpike)<1e-6&& + fabs(logf(filtered.sourceScaleX)-.09f)<1e-6&&fabs(logf(filtered.targetScaleY)+.09f)<1e-6); + stamp[@"keys"]=@[]; + stable=DYMergeTracking(stamp,jitter.reverseObjectEnumerator.allObjects,frameDuration); + run.record(@"clone-stamp-smoothing-is-independent-of-analysis-direction",stable&&[stamp[@"keys"] isEqual:smoothed]); 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 a720a31..1d3050e 100644 --- a/大鱼调色/Plugin/DYGrade.metal +++ b/大鱼调色/Plugin/DYGrade.metal @@ -367,18 +367,22 @@ kernel void dyCloneStamps(texture2d input [[texture(0)]], float2 sampleCenter(stamp.sourceX,stamp.sourceY); float2 sampleScale(stamp.samplingScaleX,stamp.samplingScaleY); float4 sampled; - if(all(abs(sampleScale-1.f)<.0001f)){ + float sourceCoverage=1; + float2 offset=(sampleCenter-center+(uv-center)*(sampleScale-1))*float2(size); + if(flip)offset.y=-offset.y; + if(!stamp.subpixel){ // Preserve pixel values for stamps with translation alone. - float2 offset=(sampleCenter-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; sampled=input.read(uint2(source)); }else{ - float2 source=sampleCenter+(uv-center)*sampleScale; - if(flip)source.y=1-source.y; - if(any(source<0)||any(source>=1))continue; - float2 pixel=clamp(source*float2(size)-.5f,0.f,float2(size-1)); + // Follow fractional motion through unit zoom and fade the sample + // across the last pixel instead of dropping it at the image edge. + float2 source=float2(gid)+offset; + float2 edge=min(source+1,float2(size)-source); + sourceCoverage=saturate(min(edge.x,edge.y)); + if(sourceCoverage<=0)continue; + float2 pixel=clamp(source,0.f,float2(size-1)); uint2 lo=uint2(floor(pixel)),hi=min(lo+1,size-1); float2 blend=fract(pixel); float4 top=mix(input.read(lo),input.read(uint2(hi.x,lo.y)),blend.x); @@ -388,7 +392,7 @@ kernel void dyCloneStamps(texture2d input [[texture(0)]], 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,sampled,coverage*stamp.strength); + color=mix(color,sampled,coverage*stamp.strength*sourceCoverage); } output.write(color,gid); } diff --git a/大鱼调色/Plugin/DYManagedRender.inc.h b/大鱼调色/Plugin/DYManagedRender.inc.h index 5708dd9..8d4b8e0 100644 --- a/大鱼调色/Plugin/DYManagedRender.inc.h +++ b/大鱼调色/Plugin/DYManagedRender.inc.h @@ -38,7 +38,7 @@ NSArray *scale=mask[@"stampSamplingScale"]; stamps.push_back({p.centerX,p.centerY,[patch[0]floatValue],[patch[1]floatValue], scale?[scale[0]floatValue]:1.f,scale?[scale[1]floatValue]:1.f, - 2/p.width,2/p.height,p.feather,p.strength,p.inputBlack,p.inputWhite,p.inputGamma}); + 2/p.width,2/p.height,p.feather,p.strength,p.inputBlack,p.inputWhite,p.inputGamma,scale?1u:0u}); } 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/DYToolGPU.h b/大鱼调色/Plugin/DYToolGPU.h index 455c1bf..60aeb63 100644 --- a/大鱼调色/Plugin/DYToolGPU.h +++ b/大鱼调色/Plugin/DYToolGPU.h @@ -8,4 +8,5 @@ struct DYToolStageRange {int first,last,suppressBlackWhite;}; struct DYCloneStamp { float centerX,centerY,sourceX,sourceY,samplingScaleX,samplingScaleY; float inverseRadiusX,inverseRadiusY,feather,strength,inputBlack,inputWhite,inputGamma; + unsigned subpixel; }; diff --git a/大鱼调色/Plugin/DYToolState.mm b/大鱼调色/Plugin/DYToolState.mm index c83cc7c..87317a5 100644 --- a/大鱼调色/Plugin/DYToolState.mm +++ b/大鱼调色/Plugin/DYToolState.mm @@ -251,6 +251,42 @@ NSDictionary *DYStampKey(CMTime time,DYMaskParameters p,BOOL manual,float confid @(motion.sourceScaleY),@(motion.targetScaleX),@(motion.targetScaleY)]; return paired; } +// Analysis supplies a contiguous pass in either time direction. A symmetric +// kernel has no phase lag, and shrinking it at the ends keeps the seed and +// the last trusted frame fixed. Work in log scale so zoom in/out is symmetric. +static NSArray *smoothStampTrackingSamples(NSArray *samples){ + if(samples.count<3)return samples; + for(NSDictionary *key in samples) + if(!key[@"stampMotion"]||[key[@"manual"]boolValue])return samples; + + NSMutableArray *result=[NSMutableArray arrayWithCapacity:samples.count]; + [result addObject:samples.firstObject]; + for(NSUInteger i=1;i+1(2,std::min(i,samples.count-1-i)); + const double weights[]={1,4,6,4,1}; + const double endWeights[]={1,2,1}; + double values[8]={}; + for(NSUInteger j=0;j<=2*radius;j++){ + NSDictionary *neighbor=samples[i-radius+j]; + DYMaskParameters p; + if(!readParameters(neighbor[@"parameters"],&p))return samples; + auto m=stampMotionFromKey(neighbor); + double weight=radius==2?weights[j]/16:endWeights[j]/4; + const double components[]={p.centerX,p.centerY,m.sourceOffsetX,m.sourceOffsetY, + std::log(m.sourceScaleX),std::log(m.sourceScaleY),std::log(m.targetScaleX),std::log(m.targetScaleY)}; + for(int k=0;k<8;k++)values[k]+=weight*components[k]; + } + NSDictionary *original=samples[i]; + DYMaskParameters p; + if(!readParameters(original[@"parameters"],&p))return samples; + p.centerX=values[0];p.centerY=values[1]; + auto scale=[&](int index){return float(std::clamp(std::exp(values[index]),1./16,16.));}; + DYStampMotion m={float(values[2]),float(values[3]),scale(4),scale(5),scale(6),scale(7),true}; + [result addObject:DYStampKey(keyTime(original),p,NO,[original[@"confidence"]floatValue],m)]; + } + [result addObject:samples.lastObject]; + return result; +} BOOL DYMergeTracking(NSMutableDictionary *m,NSArray *samples,CMTime frameDuration){ if(!samples.count)return YES; NSMutableArray *all=[NSMutableArray array]; @@ -258,6 +294,7 @@ BOOL DYMergeTracking(NSMutableDictionary *m,NSArray *samples,CMTime frameDuratio CMTime lo=keyTime(samples.firstObject),hi=keyTime(samples.lastObject); if(CMTimeCompare(lo,hi)>0)std::swap(lo,hi); if(m[@"stampSource"]&&CMTIME_IS_NUMERIC(frameDuration)&&frameDuration.value>0){ + samples=smoothStampTrackingSamples(samples); // FCP can shift analysis timestamps by a fraction of a frame between passes. // Replace an older automatic key belonging to the first or last new frame. CMTime half=CMTimeMultiplyByRatio(frameDuration,1,2); @@ -300,7 +337,7 @@ NSDictionary *DYToolRenderSnapshot(NSDictionary *doc,CMTime t){ NSMutableDictionary *m=[[mask mutableCopy]autorelease];m[@"parameters"]=parameterData(DYMaskAtTime(mask,t));m[@"keys"]=@[]; if(mask[@"stampSource"]){ m[@"stampSource"]=DYStampSourceAtTime(mask,t); - m[@"stampSamplingScale"]=DYStampSamplingScaleAtTime(mask,t); + m[@"stampSamplingScale"]=DYStampSamplingScaleAtTime(mask,t)?:@[@1,@1]; } [result addObject:m]; } diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index ba5a166..5259e25 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.14.0 + 1.14.1 CFBundleVersion - 90 + 91 NSHumanReadableCopyright PlugInKit @@ -71,7 +71,7 @@ uuid 1C17B73B-F229-4C09-A434-EAF6DFF5F22A version - 1.14.0 + 1.14.1 className diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 59e78a0..a2c5bc2 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.14.0 + 1.14.1 CFBundleVersion - 90 + 91 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright