1

I am writing a VirtualDub plug-in where there's a requirement to change hue/chroma of image without affecting luminance.

Here's some code:

Pixel32 *dst= fa->dst.data;

int U= (*dst>>16) & 0xff;
int Y= (*dst>> 8) & 0xff;
int V= (*dst    ) & 0xff;

Before converting to RGB, I need to adjust the hue of UV by x angle. UV range is between -0.5 and +0.5. Is there a conversion table/formula/already-written-function to adjust, say, hue, by -45 degrees in the colour space?

Captain Jack
  • 144
  • 13
  • 1
    You can perform a rotation in the UV plane. Written in complex numbers, U'+iV' = (U + iV).e^iΘ. –  Apr 19 '18 at 09:05
  • @YvesDaoust Thanks - that's what I am looking for. Can you give me an idea of code that I can use for this? – Captain Jack Apr 19 '18 at 09:36
  • Lookup "2D rotation" –  Apr 19 '18 at 09:40
  • I think that helped - thanks! – Captain Jack Apr 19 '18 at 13:39
  • A follow up question. I have an issue with some colours being converted back to original hue - there are subtle colour differences on bright saturates such as red and yellow. For example: I rotate the hue by 45 degrees and then I want to rotate it back 45 degrees, by either subtracting 45 or adding 315 to go all the way round. The colour is slightly different. Any ideas why that might be? I tried changing hue in HSL and changing it back works flawlessly but in HSL I am not able to preserve luminance during the operation - unless there's a way to do this? – Captain Jack Apr 19 '18 at 17:19
  • 2
    All color transformation modify some colors in an irreversible way because of saturation. There is nothing you can do. –  Apr 19 '18 at 19:51
  • 1
    To expand on what @YvesDaoust said, the RGB color space is a cube not a sphere. That means when you rotate any color in the corner of the cube, it may end up outside of the boundaries of the cube and it will be clipped. Once clipped there's no way to get the original color back again. Even if you're just rotating UV in 2D space, you have the same problems at the corners of the square. – Mark Ransom Apr 19 '18 at 21:37
  • Thanks Mark, that explains it. With HSL, when changing hue (and back) I don't have this issue - does it work in a different way? Also, is there a way to ensure that the cube boundaries aren't breached when working with UV? – Captain Jack Apr 20 '18 at 08:10
  • HSL is cylindrical - that's why. But if there's a way to avoid clipping in UV model, please share :) – Captain Jack Apr 20 '18 at 10:43

0 Answers0