Shop OBEX P1 Docs P2 Docs Learn Events
Need the easiest way to convert HSI to RGB (integer) — Parallax Forums

Need the easiest way to convert HSI to RGB (integer)

BeanBean Posts: 8,129
edited 2007-07-26 19:59 in General Discussion
Is the an easy way to convert HSI (Hue, Saturation, Intensity) to RGB (Red, Green, Blue) with integer math ?

Both the HSI values and the RGB values will be in the range [noparse][[/noparse]0..255].

I've found several formulas on the web, but none seem to work properly. Or maybe it's me...

Bean.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-07-26 18:22
    Bean, I do not have exactly what you want, but maybe I can help.· I have a Quad Nichia module - each Nichia chip has a red, green and blue LED - very tiny.· By PWMing each LED for different times·I can obtain red, green, blue, cyan, yellow, orange, magenta and white.· I will be happy to post the applicable part of my Nichia program if you think it would help.· There certain colors you can not get with LEDs, notably brown, black·and gray.· I can get a pink, but it is a rather marginal pink.

    Sid



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-07-26 18:24
    Hi Bean, did your search include this link http://www.easyrgb.com/math.html . It includes the formulas both ways (HSL,HSB,HSV) to RGB and RGB to (HSL,HSB,HSV).

    Jeff T.
  • NewzedNewzed Posts: 2,503
    edited 2007-07-26 18:43
    Bean, if you open Paint,· then click on Colors/Edit Colors/Define Custom Colors, you will see the HSL value for any color and alongside of that you will see the RGB equivalents.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • BeanBean Posts: 8,129
    edited 2007-07-26 18:58
    Thanks for the hints.

    Where all the forumlas seem to fail is that when I is at the max, R, G and B should be at their max regardless of the H or S value.
    And some values produce negative R, G or B answers.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Dave HeinDave Hein Posts: 6,347
    edited 2007-07-26 19:59
    Bean,

    There are limitations to the colors that can be represented by RGB. As an example, pure colors, such as those in a rainbow can not be generated by combinations of red, green and blue colors. You would need negative values to generate the true colors of a rainbow.

    Even colors that can be generated are limited in one color space versus another. If the luminance is 255, then the RGB values are all 255 as well. It is not possible to represent any color other than white at a luminance of 255. Therefore, saturated colors cannot be represented when the luma is high.

    Saturated colors can be represented when the luma is low. However, if the saturation is artificially increased at low luma values it could result in negative RGB values.

    The 8-bit values may be overflowing if you are getting negative RGB values when the intensity is high. You could clip the values to 255, but the colors will not be correct.

    Dave
Sign In or Register to comment.