• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

TIP - Convert colors in RGB to HLS and vice versa.

Started by Patrice Terrier, January 14, 2012, 03:44:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

#COMPILE EXE

DECLARE SUB ColorRGBToHLS LIB "SHLWAPI.DLL" ALIAS "ColorRGBToHLS" (BYVAL clrRGB AS DWORD, BYREF pwHue AS WORD, BYREF pwLuminance AS WORD, BYREF pwSaturation AS WORD)
DECLARE FUNCTION ColorHLSToRGB LIB "SHLWAPI.DLL" ALIAS "ColorHLSToRGB" (BYVAL wHue AS WORD, BYVAL wLuminance AS WORD, BYVAL wSaturation AS WORD) AS DWORD
DECLARE FUNCTION ColorAdjustLuma LIB "SHLWAPI.DLL" ALIAS "ColorAdjustLuma" (BYVAL clrRGB AS DWORD, BYVAL n AS LONG, BYVAL fScale AS LONG) AS DWORD         

FUNCTION GetRValue(BYVAL clrRGB AS DWORD) AS BYTE
    FUNCTION = (clrRGB AND &H000000FF???)
END FUNCTION

FUNCTION GetGValue(BYVAL clrRGB AS DWORD) AS BYTE
    SHIFT RIGHT clrRGB, 8
    FUNCTION = (clrRGB AND &H000000FF???)
END FUNCTION

FUNCTION GetBValue(BYVAL clrRGB AS DWORD) AS BYTE
    SHIFT RIGHT clrRGB, 16
    FUNCTION = (clrRGB AND &H000000FF???)
END FUNCTION

FUNCTION PBMAIN()

'// RED color in RGB
LOCAL clrRGB AS DWORD
clrRGB = RGB(255, 0, 0)

'// Convert to HLS color space
LOCAL Hue, Luminance, Saturation AS WORD
Hue = 0: Luminance = 0: Saturation = 100
ColorRGBToHLS(clrRGB, Hue, Luminance, Saturation)

'// It is converted to Hue, Luminance and Saturation.
'// You can adjust the parameters according to your preference.
MsgBox "RGB(255, 0, 0) converted to HLS" + $CR _
       + $CR + "Hue =" + STR$(Hue) _
       + $CR + "Luminance =" + STR$(Luminance) _
       + $CR + "Saturation =" + STR$(Saturation),,"RgbHls"

'// Now convert back to RGB.
clrRGB = ColorHLSToRGB(Hue, Luminance, Saturation)
MsgBox "HLS splitted back to RGB values" + $CR _
       + $CR + "Red =" + STR$(GetRValue(clrRGB)) _
       + $CR + "Green =" + STR$(GetGValue(clrRGB)) _
       + $CR + "Blue =" + STR$(GetBValue(clrRGB)),,"RgbHls"

END FUNCTION
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com