WIP: benchmark Metal mask flow and reduce inspector repeated work
这个提交包含在:
1 父节点
ca4abaf2c3
当前提交
48ac192d4b
12 个文件已更改
+392
-18
没有与搜索条件相匹配的文件
@@ -0,0 +1,9 @@
|
||||
# 1.18.1 跟踪与界面候选
|
||||
|
||||
2026-11-06。尚未正式构建交付,当前正式安装和文章均为 1.18.0(105)。
|
||||
|
||||
- 基线实际使用 Metal 预处理、CPU OpenCV 特征检测与双向 LK、CPU RANSAC。旧 Metal 光流存在但未接入当前跟踪器。
|
||||
- 候选保留完整 4K 分析分辨率、OpenCV 特征阈值、亚像素细化、仿射估计与可信轨迹保护。特征检测限定至目标凸包加 12px 边缘。HD 以上普通蒙版接入 Metal 金字塔和双向 LK;小图及图章保留 CPU。GPU 初始化不可用时保留 CPU,运行错误明确停止。
|
||||
- 同帧六组合生成图及 Metal 版 12 项算法回归通过。4K 小目标 12 帧从 523.46ms 到 161.89ms,不代表宿主整体速度。实拍、正式宿主、遮挡和界面交互待继续验证。
|
||||
- UI:DYToolManager 每次单个参数读取都重建完整层状态;Inspector 每组重复读取宿主参数;工作区每次标量变化都重建列表。候选改为单次 Action 快照、复用本次读回、仅在列表模型变化时重建。加入同 Action 写后读与外部编辑失效检查。
|
||||
- 资料:[Apple GPU 同步](https://developer.apple.com/documentation/metal/resource-synchronization)、[Apple MPS 调优](https://developer.apple.com/documentation/metalperformanceshaders/tuning-hints)、[OpenCV LK](https://docs.opencv.org/3.4.4/dc/d6b/group__video__track.html)。Metal LK 是本产品原有实现,不能声称与 OpenCV 逐帧严格等价。
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace dy {
|
||||
struct OpenCVTracker::Impl {
|
||||
cv::Mat previous;
|
||||
std::shared_ptr<FlowBackend> flow;
|
||||
std::vector<cv::Point2f> points, polygon;
|
||||
std::vector<FlowPoint> mask;
|
||||
TrackerROI seed{};
|
||||
@@ -34,7 +35,15 @@ struct OpenCVTracker::Impl {
|
||||
cv::convexHull(vertices,hull,false,true);
|
||||
cv::Mat area=cv::Mat::zeros(height,width,CV_8UC1);
|
||||
cv::fillPoly(area,std::vector<std::vector<cv::Point>>{hull},cv::Scalar(255),cv::LINE_AA);
|
||||
cv::goodFeaturesToTrack(previous,points,300,.03,10.,area,3,false,.04);
|
||||
// Corner detection previously evaluated the whole 4K frame even for a
|
||||
// small face. Keep a halo for the gradient/local-maximum stencil, then
|
||||
// restore full-frame coordinates before subpixel refinement and flow.
|
||||
cv::Rect bounds=cv::boundingRect(hull);
|
||||
bounds.x-=12;bounds.y-=12;bounds.width+=24;bounds.height+=24;
|
||||
bounds&=cv::Rect(0,0,width,height);
|
||||
if(bounds.empty())return;
|
||||
cv::goodFeaturesToTrack(previous(bounds),points,300,.03,10.,area(bounds),3,false,.04);
|
||||
for(auto& p:points)p+=cv::Point2f(float(bounds.x),float(bounds.y));
|
||||
if(!points.empty())cv::cornerSubPix(previous,points,{10,10},{-1,-1},
|
||||
{cv::TermCriteria::COUNT|cv::TermCriteria::EPS,20,.03});
|
||||
}
|
||||
@@ -46,6 +55,7 @@ struct OpenCVTracker::Impl {
|
||||
OpenCVTracker::OpenCVTracker():impl_(std::make_shared<Impl>()){}
|
||||
OpenCVTracker::~OpenCVTracker()=default;
|
||||
void OpenCVTracker::setMask(std::vector<FlowPoint> p){impl_->mask=std::move(p);}
|
||||
void OpenCVTracker::setFlowBackend(std::shared_ptr<FlowBackend> flow){impl_->flow=std::move(flow);stop();}
|
||||
const char* OpenCVTracker::version(){return CV_VERSION;}
|
||||
TrackResult OpenCVTracker::result()const{return impl_->value;}
|
||||
bool OpenCVTracker::active()const{return impl_->running;}
|
||||
@@ -70,6 +80,7 @@ bool OpenCVTracker::reset(const GrayFrame& f,TrackerROI roi) {
|
||||
t.polygon.emplace_back(t.center.x+c*x-s*y,t.center.y+s*x+c*y);}
|
||||
t.detect();t.value.features=int(t.points.size());t.value.inliers=t.value.features;
|
||||
if(t.points.size()<4){t.fail(TrackFailure::InsufficientTexture);return false;}
|
||||
if(t.flow&&!t.flow->reset(f)){t.fail(TrackFailure::Backend);return false;}
|
||||
t.running=true;t.value.valid=true;t.value.confidence=1;return true;
|
||||
} catch(const cv::Exception&){t.fail(TrackFailure::Backend);return false;}
|
||||
}
|
||||
@@ -84,19 +95,27 @@ TrackResult OpenCVTracker::track(const GrayFrame& f) {
|
||||
if(t.frameIndex<2||t.frameIndex%2==0)t.detect();
|
||||
t.value.features=int(t.points.size());t.value.matches=0;t.value.inliers=0;t.value.medianError=0;
|
||||
if(t.points.size()<4)return t.fail(TrackFailure::InsufficientTexture);
|
||||
std::vector<cv::Point2f> src,dst,movingSrc,movingDst;
|
||||
if(t.flow){
|
||||
std::vector<FlowPoint> input;input.reserve(t.points.size());
|
||||
for(auto p:t.points)input.push_back({p.x,p.y});
|
||||
std::vector<FlowMatch> matches;
|
||||
if(!t.flow->advance(f,input,matches))return t.fail(TrackFailure::Backend);
|
||||
for(auto m:matches){src.emplace_back(m.p.x,m.p.y);dst.emplace_back(m.q.x,m.q.y);}
|
||||
}else{
|
||||
std::vector<cv::Point2f> forward,backward;
|
||||
std::vector<uchar> fs,bs;std::vector<float> fe,be;
|
||||
cv::TermCriteria termination(cv::TermCriteria::COUNT|cv::TermCriteria::EPS,30,.01);
|
||||
cv::calcOpticalFlowPyrLK(t.previous,next,t.points,forward,fs,fe,{21,21},3,termination,0,1e-4);
|
||||
cv::calcOpticalFlowPyrLK(next,t.previous,forward,backward,bs,be,{21,21},3,termination,0,1e-4);
|
||||
std::vector<cv::Point2f> src,dst,movingSrc,movingDst;
|
||||
const float motionThreshold=std::max(t.width,t.height)*.01f;
|
||||
for(size_t i=0;i<t.points.size();++i) {
|
||||
// Checking both statuses also rejects a failed backward solve.
|
||||
if(!fs[i]||!bs[i]||cv::norm(backward[i]-t.points[i])>=1.)continue;
|
||||
src.push_back(t.points[i]);dst.push_back(forward[i]);
|
||||
if(cv::norm(forward[i]-t.points[i])>=motionThreshold){movingSrc.push_back(t.points[i]);movingDst.push_back(forward[i]);}
|
||||
}
|
||||
}
|
||||
const float motionThreshold=std::max(t.width,t.height)*.01f;
|
||||
for(size_t i=0;i<src.size();++i)if(cv::norm(dst[i]-src[i])>=motionThreshold){movingSrc.push_back(src[i]);movingDst.push_back(dst[i]);}
|
||||
if(movingSrc.size()>src.size()/2){src.swap(movingSrc);dst.swap(movingDst);}
|
||||
t.value.matches=int(src.size());
|
||||
if(src.size()<4)return t.fail(TrackFailure::InsufficientMatches);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Same generated frames and full resolution for CPU/GPU. No host or UI runs.
|
||||
#import <Foundation/Foundation.h>
|
||||
#define main originalCPUTrackerChecks
|
||||
#include "verify_opencv_tracker.cpp"
|
||||
#undef main
|
||||
#include "../../大鱼调色/Plugin/DYToolFlow.inc.h"
|
||||
#include <iomanip>
|
||||
|
||||
int main(int argc,const char**argv){@autoreleasepool{
|
||||
if(argc!=2)return 2;
|
||||
NSURL*library=[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];
|
||||
int failures=0;std::cout<<std::setprecision(8)<<"{\"cases\":[";bool first=true;
|
||||
for(auto dimensions:std::vector<std::pair<int,int>>{{640,480},{1920,1080},{3840,2160}}){
|
||||
int w=dimensions.first,h=dimensions.second;
|
||||
for(float size:{.12f,.7f}){
|
||||
std::vector<dy::GrayFrame> images;
|
||||
for(int i=0;i<=12;++i)images.push_back(frame(w,h,1.25*i,.5*i,.001*i,1+.001*i,1-.0007*i));
|
||||
double elapsed[2]={},maxError[2]={},maxDifference=0;bool good[2]={true,true};
|
||||
std::vector<dy::TrackResult> reference;
|
||||
for(int gpu=0;gpu<2;++gpu){
|
||||
dy::OpenCVTracker tracker;
|
||||
if(gpu){auto flow=DYToolCreateMetalFlow(library,nullptr);if(!flow)return 3;tracker.setFlowBackend(flow);}
|
||||
good[gpu]=tracker.reset(images[0],{.5f,.5f,size,size,0});
|
||||
for(size_t i=1;i<images.size()&&good[gpu];++i){
|
||||
auto begin=std::chrono::steady_clock::now();auto r=tracker.track(images[i]);
|
||||
elapsed[gpu]+=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-begin).count();
|
||||
good[gpu]&=r.valid;
|
||||
maxError[gpu]=std::max(maxError[gpu],std::hypot((r.cx-.5)*w-1.25*i,(r.cy-.5)*h-.5*i));
|
||||
if(!gpu)reference.push_back(r);
|
||||
else if(i<=reference.size())maxDifference=std::max(maxDifference,std::hypot(double(r.cx-reference[i-1].cx)*w,double(r.cy-reference[i-1].cy)*h));
|
||||
}
|
||||
good[gpu]&=maxError[gpu]<1.;
|
||||
failures+=!good[gpu];
|
||||
}
|
||||
if(!first)std::cout<<",";first=false;
|
||||
std::cout<<"{\"width\":"<<w<<",\"height\":"<<h<<",\"roi\":"<<size<<",\"frames\":12,\"cpuMs\":"<<elapsed[0]<<",\"metalMs\":"<<elapsed[1]<<",\"cpuErrorPx\":"<<maxError[0]<<",\"metalErrorPx\":"<<maxError[1]<<",\"differencePx\":"<<maxDifference<<",\"pass\":"<<(good[0]&&good[1]?"true":"false")<<"}";
|
||||
}
|
||||
}
|
||||
std::cout<<"],\"pass\":"<<(failures?"false":"true")<<"}\n";return failures?1:0;
|
||||
}}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Reads caller-decoded gray8, excludes file reads and conversion from timings.
|
||||
// Does not modify or persist media; CPU/GPU receive the same full-size frames.
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "../../大鱼调色/Plugin/MaskCore/DYOpenCVTracker.hpp"
|
||||
#include "../../大鱼调色/Plugin/DYToolFlow.inc.h"
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
int main(int argc,const char **argv){@autoreleasepool{
|
||||
if(argc!=9)return 2;int w=atoi(argv[2]),h=atoi(argv[3]);if(w<16||h<16||w>8192||h>8192)return 2;
|
||||
dy::TrackerROI roi{float(atof(argv[5])),float(atof(argv[6])),float(atof(argv[7])),float(atof(argv[8])),0};
|
||||
NSMutableArray *runs=[NSMutableArray array];
|
||||
for(int gpu=0;gpu<2;++gpu){
|
||||
dy::OpenCVTracker tracker;if(gpu){auto b=DYToolCreateMetalFlow([NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[4]]],nullptr);if(!b)return 3;tracker.setFlowBackend(b);}
|
||||
std::ifstream input(argv[1],std::ios::binary);if(!input)return 2;
|
||||
std::vector<uint8_t> bytes(size_t(w)*h);dy::GrayFrame f{w,h,std::vector<float>(bytes.size())};
|
||||
NSMutableArray *frames=[NSMutableArray array];double total=0,maximum=0;
|
||||
while(input.read((char*)bytes.data(),bytes.size())){
|
||||
for(size_t i=0;i<bytes.size();++i)f.pixels[i]=bytes[i]/255.f;
|
||||
auto start=std::chrono::steady_clock::now();bool ok=frames.count?tracker.track(f).valid:tracker.reset(f,roi);
|
||||
double ms=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-start).count();total+=ms;maximum=std::max(maximum,ms);auto r=tracker.result();
|
||||
[frames addObject:@{@"valid":@(ok),@"cx":@(r.cx),@"cy":@(r.cy),@"scaleX":@(r.scaleX),@"scaleY":@(r.scaleY),@"rotation":@(r.rotation),@"confidence":@(r.confidence),@"failure":@((int)r.failure)}];if(!ok)break;
|
||||
}
|
||||
[runs addObject:@{@"backend":gpu?@"Metal":@"CPU",@"frames":frames,@"milliseconds":@(total),@"maximumMs":@(maximum)}];
|
||||
}
|
||||
NSData *data=[NSJSONSerialization dataWithJSONObject:@{@"width":@(w),@"height":@(h),@"runs":runs} options:NSJSONWritingPrettyPrinted error:nil];fwrite(data.bytes,1,data.length,stdout);return 0;
|
||||
}}
|
||||
@@ -0,0 +1,20 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "../../大鱼调色/Plugin/MaskCore/DYOpenCVTracker.hpp"
|
||||
#include "../../大鱼调色/Plugin/DYToolFlow.inc.h"
|
||||
static NSURL *testLibrary;
|
||||
namespace dy {
|
||||
class MetalTestTracker : public OpenCVTracker {
|
||||
public:
|
||||
MetalTestTracker(){auto flow=DYToolCreateMetalFlow(testLibrary,nullptr);if(!flow)throw std::runtime_error("Metal backend unavailable");setFlowBackend(flow);}
|
||||
};
|
||||
}
|
||||
#define OpenCVTracker MetalTestTracker
|
||||
#define main runMetalCases
|
||||
#include "verify_opencv_tracker.cpp"
|
||||
#undef main
|
||||
#undef OpenCVTracker
|
||||
int main(int argc,const char **argv){@autoreleasepool{
|
||||
if(argc!=2)return 2;
|
||||
testLibrary=[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];
|
||||
return runMetalCases();
|
||||
}}
|
||||
@@ -0,0 +1,225 @@
|
||||
{
|
||||
"scope": "Identical synthetic full-resolution CPU/Metal comparison. Candidate not installed.",
|
||||
"initial": {
|
||||
"cases": [
|
||||
{
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 30.007459,
|
||||
"metalMs": 32.543915,
|
||||
"cpuErrorPx": 0.014766356,
|
||||
"metalErrorPx": 0.015058941,
|
||||
"differencePx": 0.001211279,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 69.944751,
|
||||
"metalMs": 65.5695,
|
||||
"cpuErrorPx": 0.0059646107,
|
||||
"metalErrorPx": 0.0061500019,
|
||||
"differencePx": 0.00032044025,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 158.51942,
|
||||
"metalMs": 157.27908,
|
||||
"cpuErrorPx": 0.010653597,
|
||||
"metalErrorPx": 0.010528938,
|
||||
"differencePx": 0.00073837814,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 189.76521,
|
||||
"metalMs": 197.53042,
|
||||
"cpuErrorPx": 0.0044298672,
|
||||
"metalErrorPx": 0.0043980019,
|
||||
"differencePx": 0.00028177808,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 3840,
|
||||
"height": 2160,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 523.4585,
|
||||
"metalMs": 481.38763,
|
||||
"cpuErrorPx": 0.0058081044,
|
||||
"metalErrorPx": 0.0058169868,
|
||||
"differencePx": 0.00047552405,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 3840,
|
||||
"height": 2160,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 626.79046,
|
||||
"metalMs": 593.42783,
|
||||
"cpuErrorPx": 0.00352694,
|
||||
"metalErrorPx": 0.00352694,
|
||||
"differencePx": 0.00034451278,
|
||||
"pass": true
|
||||
}
|
||||
],
|
||||
"pass": true
|
||||
},
|
||||
"cropped": {
|
||||
"cases": [
|
||||
{
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 17.140793,
|
||||
"metalMs": 23.460209,
|
||||
"cpuErrorPx": 0.014766356,
|
||||
"metalErrorPx": 0.015058941,
|
||||
"differencePx": 0.001211279,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 63.894127,
|
||||
"metalMs": 65.146207,
|
||||
"cpuErrorPx": 0.0059646107,
|
||||
"metalErrorPx": 0.0061500019,
|
||||
"differencePx": 0.00032044025,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 69.389456,
|
||||
"metalMs": 63.493252,
|
||||
"cpuErrorPx": 0.010653597,
|
||||
"metalErrorPx": 0.010528938,
|
||||
"differencePx": 0.00073837814,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 156.90271,
|
||||
"metalMs": 159.282,
|
||||
"cpuErrorPx": 0.0044298672,
|
||||
"metalErrorPx": 0.0043980019,
|
||||
"differencePx": 0.00028177808,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 3840,
|
||||
"height": 2160,
|
||||
"roi": 0.12,
|
||||
"frames": 12,
|
||||
"cpuMs": 186.95491,
|
||||
"metalMs": 161.89333,
|
||||
"cpuErrorPx": 0.0058081044,
|
||||
"metalErrorPx": 0.0058169868,
|
||||
"differencePx": 0.00047552405,
|
||||
"pass": true
|
||||
},
|
||||
{
|
||||
"width": 3840,
|
||||
"height": 2160,
|
||||
"roi": 0.69999999,
|
||||
"frames": 12,
|
||||
"cpuMs": 553.42904,
|
||||
"metalMs": 426.87983,
|
||||
"cpuErrorPx": 0.00352694,
|
||||
"metalErrorPx": 0.00352694,
|
||||
"differencePx": 0.00034451278,
|
||||
"pass": true
|
||||
}
|
||||
],
|
||||
"pass": true
|
||||
},
|
||||
"metalRegression": {
|
||||
"version": "4.5.1",
|
||||
"checks": [
|
||||
{
|
||||
"name": "pinned-public-opencv-version",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "300-feature-capacity",
|
||||
"pass": true,
|
||||
"error": 300
|
||||
},
|
||||
{
|
||||
"name": "translation-rotation-independent-xy-scale",
|
||||
"pass": true,
|
||||
"error": 0.00257472
|
||||
},
|
||||
{
|
||||
"name": "free-path-outside-creation-box-12-frame-subpixel",
|
||||
"pass": true,
|
||||
"error": 0.014958
|
||||
},
|
||||
{
|
||||
"name": "periodic-redetection-keeps-static-position",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "unrelated-cut-stops-with-last-trusted-position",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "flat-mask-rejected",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "moving-majority-prefers-subject-over-static-background",
|
||||
"pass": true,
|
||||
"error": 0.0010376
|
||||
},
|
||||
{
|
||||
"name": "independent-tracker-objects-do-not-share-motion",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "invalid-frame-preserves-authored-geometry",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "nonfinite-source-rejected",
|
||||
"pass": true,
|
||||
"error": 0
|
||||
},
|
||||
{
|
||||
"name": "4k-complete-source-frame",
|
||||
"pass": true,
|
||||
"error": 0.000107325
|
||||
}
|
||||
],
|
||||
"pass": true,
|
||||
"count": 12,
|
||||
"runtimeTargetAppUsed": false
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -980,15 +980,20 @@ NSView<DYWorkspaceMaskEditing> *DYCreateWorkspaceMaskEditor(id<PROAPIAccessing>
|
||||
@try {
|
||||
CMTime t=action.currentTime;
|
||||
id<FxParameterRetrievalAPI_v6> get=[_manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];
|
||||
_unified=DYUnifiedColorState(DYReadAssets(_embedded?[(DYToolManager*)_manager host]:_manager,t).colorManagement);
|
||||
id<PROAPIAccessing> maskHost=_embedded?[(DYToolManager*)_manager host]:_manager;
|
||||
DYAssetState *assets=DYReadAssets(_manager,t);
|
||||
NSDictionary *cms=_embedded?DYReadAssets(maskHost,t).colorManagement:assets.colorManagement;
|
||||
NSDictionary *tools=DYReadTools(maskHost,t).document;
|
||||
DYInspectorToken *oldToken=nil;[get getCustomParameterValue:&oldToken fromParameter:DYInspectorParameterID atTime:t];
|
||||
_unified=DYUnifiedColorState(cms);
|
||||
if(!_embedded&&!_workspaceEditor){
|
||||
[_renderOrder release];_renderOrder=[DYUnifiedRenderOrder(DYReadTools(_manager,t).document)copy];
|
||||
[_renderOrder release];_renderOrder=[DYUnifiedRenderOrder(tools)copy];
|
||||
NSMutableDictionary *primary=nil,*output=nil;for(NSMutableDictionary *card in _cards){if([card[@"section"][@"key"]isEqual:@"primary"])primary=card;if([card[@"section"][@"key"]isEqual:@"output"])output=card;}
|
||||
NSMutableArray *body=[NSMutableArray arrayWithArray:primary[@"body"]];
|
||||
for(NSView *row in output[@"body"]){if([row.identifier isEqual:@"toolMasks"])continue;[body removeObjectIdenticalTo:row];[(_unified?output:primary)[@"view"]addSubview:row];if(!_unified)[body addObject:row];}
|
||||
primary[@"body"]=body;
|
||||
}
|
||||
NSDictionary *initialTools=DYReadTools(_embedded?[(DYToolManager*)_manager host]:_manager,t).document;
|
||||
NSDictionary *initialTools=tools;
|
||||
for(NSMutableDictionary *card in _cards){NSString *type=card[@"section"][@"key"];card[@"removed"]=@([type isEqual:@"output"]?!_unified:!_embedded&&DYBaseToolRemoved(initialTools,type));}
|
||||
NSMutableDictionary *graphicValues=[NSMutableDictionary dictionary];
|
||||
for(NSNumber *pid in _controls) {
|
||||
@@ -1009,8 +1014,7 @@ NSView<DYWorkspaceMaskEditing> *DYCreateWorkspaceMaskEditor(id<PROAPIAccessing>
|
||||
NSNumber *extra=c[@"section"][@"extraEnabled"];double extraValue=0;
|
||||
if(extra)[get getFloatValue:&extraValue fromParameter:extra.unsignedIntValue atTime:t];
|
||||
BOOL enabled=v>=.5||extraValue>=.5;
|
||||
DYInspectorToken *token=nil;[get getCustomParameterValue:&token fromParameter:DYInspectorParameterID atTime:t];
|
||||
NSNumber *saved=[token isKindOfClass:DYInspectorToken.class]?token.folds[c[@"section"][@"key"]]:nil;
|
||||
NSNumber *saved=[oldToken isKindOfClass:DYInspectorToken.class]?oldToken.folds[c[@"section"][@"key"]]:nil;
|
||||
BOOL collapsed=_workspaceEditor?NO:saved?saved.boolValue:![self initiallyExpandedSection:c[@"section"][@"key"]];
|
||||
groupingChanged|=collapsed!=[c[@"collapsed"]boolValue];c[@"collapsed"]=@(collapsed);
|
||||
[c[@"header"]setState:collapsed?NSControlStateValueOff:NSControlStateValueOn];
|
||||
@@ -1021,7 +1025,7 @@ NSView<DYWorkspaceMaskEditing> *DYCreateWorkspaceMaskEditor(id<PROAPIAccessing>
|
||||
[c[@"enabled"]setToolTip:enabled?@"停用本组,保留参数和展开状态":@"启用本组,保留展开状态"];[c[@"enabled"]setAccessibilityHelp:[c[@"enabled"]toolTip]];
|
||||
for(NSView *row in c[@"body"])row.alphaValue=enabled?1:.45;
|
||||
}
|
||||
id<PROAPIAccessing> maskHost=_embedded?[(DYToolManager*)_manager host]:_manager;NSDictionary *tools=DYReadTools(maskHost,t).document;for(NSDictionary *card in _cards){
|
||||
for(NSDictionary *card in _cards){
|
||||
NSString *type=card[@"section"][@"key"];
|
||||
BOOL removed=[type isEqual:@"output"]?!_unified:!_embedded&&DYBaseToolRemoved(tools,type);groupingChanged|=[card[@"removed"]boolValue]!=removed;((NSMutableDictionary *)card)[@"removed"]=@(removed);
|
||||
[card[@"maskPanel"]refreshWithDocument:tools time:t];
|
||||
@@ -1029,11 +1033,10 @@ NSView<DYWorkspaceMaskEditing> *DYCreateWorkspaceMaskEditor(id<PROAPIAccessing>
|
||||
[(DYMaskCountBadge*)card[@"maskBadge"]setCount:count];NSString *hint=count?[NSString stringWithFormat:@"已有 %lu 个蒙版;点击添加独立蒙版",(unsigned long)count]:@"添加本工具的独立蒙版";
|
||||
[card[@"maskButton"]setToolTip:hint];[card[@"maskButton"]setAccessibilityHelp:hint];
|
||||
}
|
||||
DYAssetState *assets=DYReadAssets(_manager,t);NSDictionary *cms=_embedded?DYReadAssets([(DYToolManager*)_manager host],t).colorManagement:assets.colorManagement;_tabs[@"managedColor"]=@(cms.count>0&&!DYPrimaryColorState(cms));_tabs[@"primaryCMS"]=@(DYPrimaryColorState(cms));[_managedPanel refreshWithState:assets.colorManagement context:[_renderer colorContext]];[_managedPanel setInputLUTPath:assets.paths[@"input"]];for(NSDictionary *r in _controls.allValues)if([r[@"descriptor"][@"key"]isEqual:@"cmmix"])[r[@"label"]setStringValue:([_tabs[@"managedColor"]boolValue]||[_tabs[@"primaryCMS"]boolValue])?@"调色混合":@"CST 混合"];
|
||||
_tabs[@"managedColor"]=@(cms.count>0&&!DYPrimaryColorState(cms));_tabs[@"primaryCMS"]=@(DYPrimaryColorState(cms));[_managedPanel refreshWithState:assets.colorManagement context:[_renderer colorContext]];[_managedPanel setInputLUTPath:assets.paths[@"input"]];for(NSDictionary *r in _controls.allValues)if([r[@"descriptor"][@"key"]isEqual:@"cmmix"])[r[@"label"]setStringValue:([_tabs[@"managedColor"]boolValue]||[_tabs[@"primaryCMS"]boolValue])?@"调色混合":@"CST 混合"];
|
||||
for(NSDictionary *c in _cards)if([c[@"section"][@"key"]isEqual:@"primary"]){[c[@"enabled"]setToolTip:([_tabs[@"managedColor"]boolValue]||_unified)?@"启停此层一级调色;全局色彩管理保持当前方式":@"启停此层输入、一级调色与输出转换"];[c[@"enabled"]setAccessibilityHelp:[c[@"enabled"]toolTip]];}
|
||||
[_spiderPanel setMesh:assets.spiderMesh linked:assets.spiderLinked];
|
||||
double profile=0,configured=0;[get getFloatValue:&profile fromParameter:2013 atTime:t];[get getFloatValue:&configured fromParameter:2236 atTime:t];
|
||||
DYInspectorToken *oldToken=nil;[get getCustomParameterValue:&oldToken fromParameter:DYInspectorParameterID atTime:t];
|
||||
_tabs[@"legacyInput"]=@(configured<.5&&(configured<0||profile>.5||[assets.paths[@"input"]length]||oldToken.schema<2));
|
||||
for(NSString *key in _assetButtons) {
|
||||
NSString *path=assets.paths[key]; NSButton *button=_assetButtons[key][@"choose"];
|
||||
|
||||
@@ -9,6 +9,19 @@
|
||||
DYToolManager *one=[[[DYToolManager alloc]initWithHost:manager node:first]autorelease];DYWriteTools(manager,doc,kCMTimeZero);id<FxCustomParameterActionAPI_v4>action=(id)one;[action startAction:one];
|
||||
[(id<FxParameterSettingAPI_v6>)one setFloatValue:17 toParameter:2068 atTime:kCMTimeZero];[(id<FxParameterSettingAPI_v6>)one setFloatValue:26 toParameter:2076 atTime:kCMTimeZero];[action endAction:one];NSDictionary *written=DYReadTools(manager,kCMTimeZero).document;
|
||||
run.record(@"instance-proxy-batches-multiple-fields-without-clobber",[DYToolWithID(written,first[@"id"])[@"values"][@"hsl0_0"]isEqual:@17]&&[DYToolWithID(written,first[@"id"])[@"values"][@"hsl1_0"]isEqual:@26]&&[DYToolWithID(written,second[@"id"])[@"values"][@"hsl1_2"]isEqual:@55]);
|
||||
// A cached action must see writes immediately, and a later action must see
|
||||
// host-side undo/external edits. Exercise both the numeric snapshot and scope.
|
||||
[action startAction:one];double before=0,after=0;
|
||||
[(id<FxParameterRetrievalAPI_v6>)one getFloatValue:&before fromParameter:2068 atTime:kCMTimeZero];
|
||||
[(id<FxParameterSettingAPI_v6>)one setFloatValue:19 toParameter:2068 atTime:kCMTimeZero];
|
||||
[(id<FxParameterRetrievalAPI_v6>)one getFloatValue:&after fromParameter:2068 atTime:kCMTimeZero];
|
||||
[action endAction:one];run.record(@"layer-snapshot-read-after-write-in-one-action",before==17&&after==19);
|
||||
NSMutableDictionary *external=DYMutablePlist(DYReadTools(manager,kCMTimeZero).document);
|
||||
((NSMutableDictionary*)DYToolWithID(external,first[@"id"]))[@"values"][@"hsl0_0"]=@23;
|
||||
DYWriteTools(manager,external,kCMTimeZero);[action startAction:one];
|
||||
[(id<FxParameterRetrievalAPI_v6>)one getFloatValue:&after fromParameter:2068 atTime:kCMTimeZero];[action endAction:one];
|
||||
run.record(@"layer-snapshot-next-action-sees-external-edit",after==23);
|
||||
DYWriteTools(manager,written,kCMTimeZero);
|
||||
DYInspector *stackInspector=[[[DYInspector alloc]initWithAPIManager:manager renderer:renderer]autorelease];[stackInspector refresh];[stackInspector setFrameSize:NSMakeSize(360,780)];[stackInspector layoutSubtreeIfNeeded];NSDictionary *stackViews=[stackInspector valueForKey:@"_stackViews"];BOOL nativeViews=stackViews.count==2;for(NSString *ID in stackViews){NSArray *c=[stackViews[ID]valueForKey:@"_cards"];nativeViews&=c.count==1&&c[0][@"maskButton"]&&c[0][@"repeatButton"]&&[c[0][@"section"][@"key"]isEqual:@"hsl"];}run.record(@"two-native-hsl-panels-with-mask-and-repeat-buttons",nativeViews);
|
||||
NSMutableDictionary *invalid=DYMutablePlist(doc);invalid[@"layers"][1][@"id"]=first[@"id"];run.record(@"tool-document-rejects-duplicate-identity",!DYValidToolDocument(invalid));invalid=DYMutablePlist(doc);invalid[@"layers"][0][@"values"][@"hsl0_0"]=@(NAN);run.record(@"tool-document-rejects-nonfinite",!DYValidToolDocument(invalid));
|
||||
NSMutableDictionary *mask=DYMutablePlist(DYNewMask(DYMaskRectangle));DYMaskParameters p=DYMaskAtTime(mask,kCMTimeZero);p.feather=0;p.width=.5;p.height=.5;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];CMTime a=CMTimeMake(1001,24000),b=CMTimeMake(2002,24000);DYMaskParameters moved=p;moved.centerX=.7;moved.width=.6;moved.angle=.2;mask[@"keys"]=@[DYMaskKey(a,p,YES,1),DYMaskKey(b,moved,NO,.9)];
|
||||
|
||||
@@ -243,6 +243,13 @@
|
||||
BOOL stamp=_trackingStampMotion.active;
|
||||
dy::TrackResult target,source;
|
||||
if(!_trackingSamples.count){
|
||||
// Full-resolution mask analysis benefits from GPU flow. Tiny inputs and
|
||||
// the separately tuned clone-stamp pair retain the CPU implementation.
|
||||
std::shared_ptr<dy::FlowBackend> flow;
|
||||
if(!stamp&&size_t(frame.width)*frame.height>=1920u*1080u)
|
||||
flow=DYToolCreateMetalFlow([[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"],nullptr);
|
||||
_toolTracker.setFlowBackend(flow);
|
||||
os_log(OS_LOG_DEFAULT,"dayu_tool_track_backend metal=%{public}d",bool(flow));
|
||||
dy::TrackerROI targetROI={_trackingSeed.centerX,_trackingSeed.centerY,_trackingSeed.width,_trackingSeed.height,_trackingSeed.angle};
|
||||
if(!_toolTracker.reset(frame,targetROI))
|
||||
return [self finishToolAnalysis:stamp?@"覆盖区域内纹理不足,原图章已保留":@"蒙版内纹理不足,原蒙版已保留" error:error];
|
||||
@@ -306,7 +313,7 @@
|
||||
}
|
||||
- (BOOL)cleanupAnalysis:(NSError**)error {
|
||||
if(!_trackingActive.load()||_trackingFinishing.exchange(true))return YES;BOOL changed=_trackingSamples.count>1;if(changed&&!DYMergeTracking(_trackingCandidate,_trackingSamples,_trackingFrameDuration)){[_trackingMessage release];_trackingMessage=[@"轨迹合并失败,原蒙版已保留" copy];_trackingDiscard=YES;}
|
||||
_toolTracker.stop();
|
||||
_toolTracker.stop();_toolTracker.setFlowBackend({});
|
||||
if(_trackingStampMotion.active)_stampSourceTracker.stop();
|
||||
uint64_t generation=_trackingGeneration;BOOL second=_trackingBoth&&!_trackingBackward&&!_trackingCancelled.load()&&!_trackingDiscard;
|
||||
dispatch_async(dispatch_get_main_queue(),^{if(self->_trackingGeneration!=generation)return;
|
||||
|
||||
+10
-4
@@ -395,12 +395,13 @@ BOOL DYToolIsNeutral(NSDictionary *node){NSString *type=node[@"type"];DYUniforms
|
||||
|
||||
@implementation DYToolManager {
|
||||
id<PROAPIAccessing> _host;NSString *_nodeID,*_type;NSInteger _depth;CMTime _time;NSMutableDictionary *_pending;DYInspectorToken *_token;
|
||||
DYUniforms _readUniforms;BOOL _readUniformsValid;
|
||||
}
|
||||
@synthesize host=_host,nodeID=_nodeID,type=_type;
|
||||
- (instancetype)initWithHost:(id<PROAPIAccessing>)h node:(NSDictionary*)n{if((self=[super init])){_host=h;_nodeID=[n[@"id"]copy];_type=[n[@"type"]copy];}return self;}
|
||||
- (void)dealloc{[_nodeID release];[_type release];[_pending release];[_token release];[super dealloc];}
|
||||
- (id)apiForProtocol:(Protocol*)p{if(protocol_isEqual(p,@protocol(FxParameterRetrievalAPI_v6))||protocol_isEqual(p,@protocol(FxParameterSettingAPI_v6))||protocol_isEqual(p,@protocol(FxCustomParameterActionAPI_v4)))return self;return [_host apiForProtocol:p];}
|
||||
- (void)startAction:(id)sender{if(_depth++==0){[[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]startAction:sender];_time=[(id<FxCustomParameterActionAPI_v4>)[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]currentTime];[_pending release];_pending=[DYMutablePlist(DYReadTools(_host,_time).document)retain];}}
|
||||
- (void)startAction:(id)sender{if(_depth++==0){_readUniformsValid=NO;[[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]startAction:sender];_time=[(id<FxCustomParameterActionAPI_v4>)[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]currentTime];[_pending release];_pending=[DYMutablePlist(DYReadTools(_host,_time).document)retain];}}
|
||||
- (void)endAction:(id)sender{
|
||||
if(_depth<=0||--_depth>0)return;
|
||||
@try{
|
||||
@@ -415,9 +416,14 @@ BOOL DYToolIsNeutral(NSDictionary *node){NSString *type=node[@"type"];DYUniforms
|
||||
}
|
||||
}
|
||||
- (CMTime)currentTime{return _time;}
|
||||
- (NSDictionary*)node{return DYToolWithID(_pending?:DYReadTools(_host,_time).document,_nodeID);}
|
||||
- (BOOL)getFloatValue:(double*)out fromParameter:(UInt32)pid atTime:(CMTime)t{NSDictionary *n=[self node];DYUniforms u=DYToolUniforms(n?:@{@"type":_type});for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){*out=[d[@"offset"]integerValue]>=0?*(float*)((uint8_t*)&u+[d[@"offset"]unsignedIntegerValue]):[d[@"default"]doubleValue];return YES;}return NO;}
|
||||
- (BOOL)setFloatValue:(double)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth||!std::isfinite(v))return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){NSString *key=d[@"key"];if(n[@"primaryFollow"]&&([key hasSuffix:@"Transfer"]||[key hasSuffix:@"Gamut"])){NSUInteger bit=[key hasPrefix:@"cminput"]?1:[key hasPrefix:@"cmworking"]?2:[key hasPrefix:@"cmoutput"]?4:0;n[@"primaryFollow"]=@([n[@"primaryFollow"]unsignedIntegerValue]&~bit);}n[@"values"][key]=@(v);return YES;}return NO;}
|
||||
- (NSDictionary*)node{return DYToolWithID(_depth?_pending:DYReadTools(_host,_time).document,_nodeID);}
|
||||
- (BOOL)getFloatValue:(double*)out fromParameter:(UInt32)pid atTime:(CMTime)t{
|
||||
// One coherent snapshot per action, invalidated by any authoring write.
|
||||
// Inspector controls previously rebuilt every section for every scalar.
|
||||
if(!_depth||!_readUniformsValid){_readUniforms=DYToolUniforms([self node]?:@{@"type":_type});_readUniformsValid=_depth>0;}
|
||||
for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){if(out)*out=[d[@"offset"]integerValue]>=0?*(float*)((uint8_t*)&_readUniforms+[d[@"offset"]unsignedIntegerValue]):[d[@"default"]doubleValue];return YES;}return NO;
|
||||
}
|
||||
- (BOOL)setFloatValue:(double)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth||!std::isfinite(v))return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){NSString *key=d[@"key"];if(n[@"primaryFollow"]&&([key hasSuffix:@"Transfer"]||[key hasSuffix:@"Gamut"])){NSUInteger bit=[key hasPrefix:@"cminput"]?1:[key hasPrefix:@"cmworking"]?2:[key hasPrefix:@"cmoutput"]?4:0;n[@"primaryFollow"]=@([n[@"primaryFollow"]unsignedIntegerValue]&~bit);}n[@"values"][key]=@(v);_readUniformsValid=NO;return YES;}return NO;}
|
||||
- (BOOL)getCustomParameterValue:(id*)out fromParameter:(UInt32)pid atTime:(CMTime)t{if(pid==DYAssetsParameterID){DYAssetState *a=[[[DYAssetState alloc]init]autorelease];NSDictionary *n=[self node];a.paths=n[@"paths"]?:@{};a.spiderMesh=n[@"spider"];a.spiderLinked=[n[@"spiderLinked"]boolValue];*out=a;return YES;}if(pid==DYInspectorParameterID){DYInspectorToken *global=_token; if(!global)[[_host apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getCustomParameterValue:&global fromParameter:pid atTime:t];DYInspectorToken *local=[[[DYInspectorToken alloc]init]autorelease];NSMutableDictionary *folds=[NSMutableDictionary dictionary];for(NSString *key in global.folds)if([key hasPrefix:[_nodeID stringByAppendingString:@":"]])folds[[key substringFromIndex:_nodeID.length+1]]=global.folds[key];local.folds=folds;*out=local;return YES;}return NO;}
|
||||
- (BOOL)setCustomParameterValue:(id)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth)return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;if(pid==DYAssetsParameterID&&[v isKindOfClass:DYAssetState.class]){n[@"paths"]=DYMutablePlist([v paths]);if([v spiderMesh])n[@"spider"]=[v spiderMesh];else[n removeObjectForKey:@"spider"];n[@"spiderLinked"]=@([v spiderLinked]);return YES;}if(pid==DYInspectorParameterID){DYInspectorToken *old=nil;[[_host apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getCustomParameterValue:&old fromParameter:pid atTime:t];[_token release];_token=old?[old copy]:[DYInspectorToken new];NSMutableDictionary *folds=[[_token.folds mutableCopy]autorelease];for(NSString *key in [v folds])folds[[_nodeID stringByAppendingFormat:@":%@",key]]=[v folds][key];_token.folds=folds;return YES;}return NO;}
|
||||
@end
|
||||
@@ -65,7 +65,10 @@
|
||||
}
|
||||
for(NSDictionary*mask in DYSharedMasks(document))if(!DYToolIDsForSharedMask(document,mask[@"id"]).count){DYMaskParameters p=DYMaskAtTime(mask,_toolTime);[rows addObject:@{@"node":@"shared",@"mask":mask[@"id"],@"enabled":mask[@"enabled"],@"title":mask[@"stampSource"]?@"◩ 仿制图章":[@"◩ " stringByAppendingString:mask[@"label"]?:[@"未分配 · " stringByAppendingString:@[@"椭圆",@"矩形",@"钢笔",@"渐变",@"HSL",@"亮度"][p.kind]]],@"kind":@"mask"}];}
|
||||
}@finally{[action endAction:self];}
|
||||
[_toolDocument release];_toolDocument=document;[_layerRows release];_layerRows=[rows copy];[_layerTable reloadData];
|
||||
[_toolDocument release];_toolDocument=document;
|
||||
// A scalar drag changes the editor, not the layer list. Retain row views and
|
||||
// selection while their actual displayed model is unchanged.
|
||||
if(![_layerRows isEqual:rows]){[_layerRows release];_layerRows=[rows copy];[_layerTable reloadData];}
|
||||
NSString *requested=note.userInfo[@"scrollToTool"];if(requested.length){_hasUserSelection=YES;[_selectedNode release];_selectedNode=[requested copy];[_selectedMask release];_selectedMask=nil;}
|
||||
NSInteger selected=-1;for(NSUInteger i=0;i<_layerRows.count;i++){NSDictionary*row=_layerRows[i];if([row[@"node"]isEqual:_selectedNode]&&(_selectedMask?[row[@"mask"]isEqual:_selectedMask]:!row[@"mask"])){selected=i;break;}}
|
||||
if(selected<0&&_selectedMask)for(NSUInteger i=0;i<_layerRows.count;i++)if([_layerRows[i][@"mask"]isEqual:_selectedMask]){selected=i;[_selectedNode release];_selectedNode=[_layerRows[i][@"node"]copy];break;}
|
||||
|
||||
@@ -13,6 +13,9 @@ public:
|
||||
OpenCVTracker(const OpenCVTracker&) = delete;
|
||||
OpenCVTracker& operator=(const OpenCVTracker&) = delete;
|
||||
void setMask(std::vector<FlowPoint>);
|
||||
// Optional GPU optical flow; feature selection and robust fitting stay in
|
||||
// the pinned OpenCV implementation. A backend failure stops this run.
|
||||
void setFlowBackend(std::shared_ptr<FlowBackend>);
|
||||
bool reset(const GrayFrame&, TrackerROI);
|
||||
TrackResult track(const GrayFrame&);
|
||||
TrackResult result() const;
|
||||
|
||||
在新工单中引用
屏蔽一个用户