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

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

Postby 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
Screenshot of stack "RGB to HSV and back"

LC6_Convert_RGB_to_HSV_and_back.zip
Stack "RGB to HSV and back"
(1.92 KiB) Downloaded 21 times
capellan
 
Posts: 320
Joined: Wed Aug 15, 2007 11:09 pm

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

Postby [-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.
Plagiarism is basic to all culture.
(Pete Seeger in a concert, he didn't name an author ...)
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Livecode Membership
 
Posts: 1396
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

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

Postby 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
capellan
 
Posts: 320
Joined: Wed Aug 15, 2007 11:09 pm


Return to Rich Media

Who is online

Users browsing this forum: No registered users and 1 guest