Color Conversion - RGB to HSV and back... (almost)

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Color Conversion - RGB to HSV and back... (almost)

Post by capellan » Thu Apr 13, 2017 11:04 pm

Hi All,

Download this GUI Stack for Scott Raney's Color Conversion Functions:
RGB to HSV and HSV to RGB.

Only for certain colors this is a lossy conversion: Once you convert some
RGB colors to HSV, the function HSVtoRGB does not restore them back
exactly as before.
Does anyone knows (or have created) a pair of RGBtoHSV and HSVtoRGB
color conversion functions that do not lose or change color information?

Thanks in advance!

Al
LC6_Convert_RGB_to_HSV_and_back_screenshot.PNG
LC6_Convert_RGB_to_HSV_and_back.zip

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Color Conversion - RGB to HSV and back... (almost)

Post by [-hh] » Fri Apr 14, 2017 4:37 am

Alejandro,

the problem is here the integer rounding.

An integer RGB triple converts correctly to HSV/HSL expressed as floats.
You can then go back 'exactly' (if the floats are exact enough) to RGB.

But obviously you can't go back from the HSV/HSL floats _changed to integer_ to the same RGB. The error will usually be within plus/minus 1 of 255.

H.
shiftLock happens

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: Color Conversion - RGB to HSV and back... (almost)

Post by capellan » Fri Apr 14, 2017 6:32 am

I understand. Then, I just need to change a single number in this script:

Change the script of button "HSV to RGB" from this:
if the number of lines of fld 2 = 2 then
put line 2 of fld 2 into w

To this:
if the number of lines of fld 2 = 2 then
put line 1 of fld 2 into w

Many thanks for pointing this! :)

Al

Post Reply

Return to “Multimedia”