#pragma once #import #include #include // Immutable renderer-owned snapshot. Channel 0 uses Rec.709 weights after // any signal encoding, as luma is weighted from R′G′B′. struct DYHistogram { uint32_t bins[4][256]{}; uint32_t samples=0; uint32_t rec709VideoLevels=0; }; static inline NSData *DYHistogramFromRGBA(NSData *rgba, bool premultiplied=false, bool encodeRec709=false) { DYHistogram h; if(rgba.length%sizeof(float[4]))return nil; h.rec709VideoLevels=encodeRec709; const float *p=(const float *)rgba.bytes; auto bin=[](double v){return (int)std::lround(std::fmax(0.,std::fmin(1.,v))*255.);}; auto rec709=[](double linear){return linear<.018?4.5*linear:1.099*std::pow(linear,.45)-.099;}; for(NSUInteger i=0;i