#pragma once #include #include #include #include #include #include // Display-reference measurements only. Values remain unclipped; the plot // covers -10%...110% and explicitly counts samples beyond that range. namespace dyscope { inline constexpr unsigned Width=320,Height=180,Bins=256; inline constexpr float Low=-.1f,High=1.1f; // Conventional positive-I flesh-tone reference: 33 degrees left of +Cr. inline constexpr double SkinToneAngle=123.0*3.14159265358979323846/180.0; inline constexpr double SkinToneCb=-0.5446390350150271,SkinToneCr=0.8386705679454240; struct RGBA { float r,g,b,a; }; struct Result { std::vector wave=std::vector(Width*Bins),parade=std::vector(3*Width*Bins),vectors=std::vector(Bins*Bins); std::array histogram{}; uint64_t valid=0,transparent=0,nonfinite=0,below=0,above=0; float minimum=0,maximum=0; }; inline unsigned bin(float v){if(!(v>Low))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){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;yHigh;r.valid++; } return r; } inline std::vector densityImage(std::span counts,bool parade){ std::vector out(counts.size()*4);uint32_t maximum=0;for(uint32_t n:counts)maximum=std::max(maximum,n); float divisor=std::log1p(float(maximum));unsigned width=parade?3*Width:Width; for(size_t i=0;i0?std::pow(std::log1p(float(counts[i]))/divisor,.65f):0; unsigned channel=parade?unsigned(i%width)/Width:3;uint8_t v=uint8_t(std::lround(intensity*255)); out[i*4]=channel==0||channel==3?v:uint8_t(v*.14f);out[i*4+1]=channel==1||channel==3?v:uint8_t(v*.14f);out[i*4+2]=channel==2||channel==3?v:uint8_t(v*.14f);out[i*4+3]=255; } return out; } inline std::vector vectorImage(std::span counts){ if(counts.size()!=Bins*Bins)return {};std::vector out(counts.size()*4);uint32_t maximum=0;for(uint32_t n:counts)maximum=std::max(maximum,n);float divisor=std::log1p(float(maximum)); for(size_t i=0;i0?std::pow(std::log1p(float(counts[i]))/divisor,.65f):0;float colors[]={.5f+1.5748f*cr,.5f-.187324f*cb-.468124f*cr,.5f+1.8556f*cb};float peak=std::max({colors[0],colors[1],colors[2],.001f});for(int c=0;c<3;c++)out[i*4+c]=uint8_t(std::lround(std::clamp(colors[c]/peak,0.f,1.f)*intensity*255));out[i*4+3]=255;}return out; } }