Wikipedia and plethora of online resources provide detailed and abundant help with various color space conversions from/to RGB. What I need is a straight YUV->HSL/HSV conversion.
In fact what I need is just the Hue (don't care much for the Saturation or the brightness Lightness/Value). In other words I just need to calculate the "color angle" for a given YUV color.
Code in any language would suffice, though my preference is C-style syntax.
Note that by YUV I mean specifically Y′UV, a.k.a. YCbCr (if that makes any difference).
While YUV->RGB colorspace conversion is linear (same as "can be expressed as a matrix operation") the RGB->HSL is not. Thus it is not possible to combine the two into a single operation.
Thank you Kel Solaar for confirming this for me.
For reference:
Note that mathematically the calculation for Hue is written piecewise as the "base angle" depends on which sector the color is in and the "major color" is driven by the
max(R, G, B)
expression.