RGB vs HSV

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

Most graphics APIs seem to want colours specified in RGB space. But RGB is a
poor choice for doing colour manipulations; for example, if you want a
lighter or darker version of a given colour, naive manipulations directly on
the RGB components are likely to lead to hue shifts.

A better space to work in is HSV. This way, you can, say, tweak the
saturation or brightness, and leave the hue unchanged. It is also easier to
predict what colour you are likely to get from a given set of HSV values.
Even if your graphics API doesn’t support it directly, you can still convert
to HSV, do your manipulations there, then convert back to RGB.

Wikipedia has formulas for the conversion. Or you can use code like the HSVA
class here
<https://github.com/ldo/ti5x_android/blob/master/src/GraphicsUseful.java>.
 
L

Lawrence D'Oliveiro

I found this, the algorithm seems a bit more compact than yours. Might
want to give it a look:

<http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html>

In what way more compact? The RGB-to-HSV seems to involve just as many
comparisons (not counting the special case, where they return an out-of-
ange value, while I don’t), and the hue calculation is written out three
times, instead of just once. HSV-to-RGB seems to be no more simple than my
version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top