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