MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ rgba_to_hsv() [1/2]

MAYAFLUX_API void MayaFlux::Kinesis::Vision::rgba_to_hsv ( std::span< const float >  rgba,
std::span< float >  dst,
uint32_t  w,
uint32_t  h 
)

Convert RGBA to HSV writing into caller-supplied buffer.

Output is interleaved HSV, 3 floats per pixel. H in [0, 1], S and V in [0, 1]. Alpha channel is discarded.

Parameters
rgbaInterleaved RGBA span, size must be w * h * 4.
dstOutput span, size must be w * h * 3.
wImage width in pixels.
hImage height in pixels.

Definition at line 94 of file PixelOps.cpp.

97{
98 const size_t n = static_cast<size_t>(w) * h;
99 P::for_each(P::par_unseq,
100 std::views::iota(size_t { 0 }, n).begin(),
101 std::views::iota(size_t { 0 }, n).end(),
102 [&](size_t i) {
103 const float r = rgba[i * 4];
104 const float g = rgba[i * 4 + 1];
105 const float b = rgba[i * 4 + 2];
106
107 const float cmax = std::max({ r, g, b });
108 const float cmin = std::min({ r, g, b });
109 const float delta = cmax - cmin;
110
111 float h_val = 0.0F;
112 if (delta > 0.0F) {
113 if (cmax == r) {
114 h_val = std::fmod((g - b) / delta, 6.0F);
115 } else if (cmax == g) {
116 h_val = (b - r) / delta + 2.0F;
117 } else {
118 h_val = (r - g) / delta + 4.0F;
119 }
120 h_val /= 6.0F;
121 if (h_val < 0.0F)
122 h_val += 1.0F;
123 }
124
125 dst[i * 3] = h_val;
126 dst[i * 3 + 1] = cmax > 0.0F ? delta / cmax : 0.0F;
127 dst[i * 3 + 2] = cmax;
128 });
129}
uint32_t h
Definition InkPress.cpp:28
size_t b

References b, and h.

Referenced by rgba_to_hsv(), and MayaFlux::Kinesis::Vision::VisionExecutor::run().

+ Here is the caller graph for this function: