From 0ef847f6bb181f11d4040e7516932ffbbac615a2 Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 5 Nov 2026 09:57:59 +0800 Subject: [PATCH] fix: bound vector-scope coordinates before rounding extreme samples --- verification/DYScopeMathDiagnostics.cpp | 1 + 大鱼调色/Plugin/DYScopeMath.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/verification/DYScopeMathDiagnostics.cpp b/verification/DYScopeMathDiagnostics.cpp index a0a2da5..8f5cdaa 100644 --- a/verification/DYScopeMathDiagnostics.cpp +++ b/verification/DYScopeMathDiagnostics.cpp @@ -11,5 +11,6 @@ int main(){ RGBA colors[]={{.5f,.5f,.5f,1},{1,0,0,1},{1,0,1,1},{0,0,1,1},{0,1,1,1},{0,1,0,1},{1,1,0,1},{2,2,2,0},{INFINITY,0,0,1}}; auto v=measure(colors,9,1);uint64_t total=0;for(auto n:v.vectors)total+=n;assert(total==7&&v.transparent==1&&v.nonfinite==1);assert(v.vectors[(Bins-1-chromaBin(0))*Bins+chromaBin(0)]==1); for(unsigned i=1;i<7;i++){auto p=colors[i];float y=.2126f*p.r+.7152f*p.g+.0722f*p.b;unsigned x=chromaBin((p.b-y)/1.8556f),row=Bins-1-chromaBin((p.r-y)/1.5748f);assert(v.vectors[row*Bins+x]==1);} + assert(chromaBin(INFINITY)==Bins-1&&chromaBin(-INFINITY)==0&&chromaBin(std::numeric_limits::max())==Bins-1&&chromaBin(-std::numeric_limits::max())==0); auto vector=vectorImage(v.vectors);assert(vector.size()==Bins*Bins*4);assert(vectorImage({}).empty());for(size_t i=0;iLow))return 0;if(v>=High)return Bins-1;return unsigned(std::clamp(std::lround((v-Low)/(High-Low)*(Bins-1)),0l,long(Bins-1)));} // BT.709 colour-difference coordinates on the same encoded display-reference // RGB used by the existing scopes (ITU-R BT.709-6 section 3.3). Not an IRE meter. -inline unsigned chromaBin(float v){return unsigned(std::clamp(std::lround((v+.6f)/1.2f*(Bins-1)),0l,long(Bins-1)));} +inline unsigned chromaBin(float v){if(!(v>-.6f))return 0;if(v>=.6f)return Bins-1;return unsigned(std::clamp(std::lround((v+.6f)/1.2f*(Bins-1)),0l,long(Bins-1)));} inline Result measure(std::span pixels,unsigned width=Width,unsigned height=Height){ Result r;if(!width||!height||pixels.size()!=size_t(width)*height)return r;bool first=true; for(unsigned y=0;y