click
here for more groovy stuff like this
; output. eg, FF00FF becomes
func ConvertColorValue(
$color,
$mode=
"web",
$prefix=false,
$index=0)
if StringLeft(
$color, 1) =
" then $color = StringTrimLeft($color, 1) $pre =
"" switch
$mode case
"i",
"RGB Integer",
"RGB Int",
"int" switch
$index case 0
$color = Dec(StringLeft(
$color, 2)) &
"," & Dec(StringMid(
$color, 3, 2)) &
"," & Dec(StringRight(
$color, 2))
case 1
return Dec(StringLeft(
$color, 2))
case 2
return Dec(StringMid(
$color, 3, 2))
case 3
return Dec(StringRight(
$color, 2))
endswitch
case
"a",
"Autoit RGB Hex",
"Autoit RGB",
"AutoIt Hex",
"AutoIt" $color = '0x' &
$color case
"b",
"Autoit BGR Hex",
"Autoit BGR",
"BGR Hex",
"bgr" $color = '0x' & StringRight(
$color, 2) & StringMid(
$color, 3, 2) & StringLeft(
$color, 2)
case
"d",
"Delphi",
"Delphi Hex" $color =
"00" & StringRight(
$color, 2) & StringMid(
$color, 3, 2) & StringLeft(
$color, 2)
$pre =
"$" case
"v",
"vc",
"Visual C++ Hex",
"Visual C++ BGR",
"Visual C++",
"Visual C++ BGR Hex",
"C++" $color =
"0x00" & StringRight(
$color, 2) & StringMid(
$color, 3, 2) & StringLeft(
$color, 2)
case
"RGB Float",
"float",
"f" $r = Round((1/255) * Dec(StringLeft(
$color, 2)), 2)
$g = Round((1/255) * Dec(StringMid(
$color, 3, 2)), 2)
$b = Round((1/255) * Dec(StringRight(
$color, 2)),2)
$color = StringFormat(
"%, $r) & "," & StringFormat("%#.2f", $g) & "," & StringFormat("%#.2f", $b) case
"h",
"Hue/Sat/Lum",
"HSL",
"h/s/l" $color = RGBToHSL(
$color,
",", 100)
case
"k",
"cmyk",
"c/m/y/k" if
$prefix = 1 then
$color = RGBToCMYK(
$color, true)
else
$color = RGBToCMYK(
$color)
endif
case
"w",
"Web Hex",
"Web",
"Hex" $pre =
" endswitch
if not
$prefix or
$prefix = 4 then
$pre =
"" return
$pre &
$colorendfunc
func RGBToCMYK(
$rgb_color,
$norm=0)
$rc_r = ConvertColorValue(
$rgb_color,
"i", 0, 1) / 255
$rc_g = ConvertColorValue(
$rgb_color,
"i", 0, 2) / 255
$rc_b = ConvertColorValue(
$rgb_color,
"i", 0, 3) / 255
$k = MinMin(1-
$rc_r, 1-
$rc_g, 1-
$rc_b)
$c = (1 -
$rc_r -
$k) / ( 1 -
$k)
$m = (1 -
$rc_g -
$k) / ( 1 -
$k)
$y = (1 -
$rc_b -
$k) / ( 1 -
$k)
if
$norm then
return Round(
$c * 100, 1) &
"," & Round(
$m * 100, 1) &
"," & Round(
$y * 100, 1) &
"," & Round(
$k * 100, 1)
else
return Round(
$c, 3) &
"," & Round(
$m, 3) &
"," & Round(
$y, 3) &
"," & Round(
$k, 3)
endif
endfunc
func RGBToHSL(
$rgb_color,
$idx=
"",
$hsl_scale=1)
$rh_r = ConvertColorValue(
$rgb_color,
"i", 0, 1) / 255
$rh_g = ConvertColorValue(
$rgb_color,
"i", 0, 2) / 255
$rh_b = ConvertColorValue(
$rgb_color,
"i", 0, 3) / 255
$rh_min = MinMin(
$rh_r,
$rh_g,
$rh_b)
$rh_max = MaxMax(
$rh_r,
$rh_g,
$rh_b)
$rh_delta =
$rh_max -
$rh_min if
$idx <> 1 then
$rh_lightness = (
$rh_min +
$rh_max) / 2
if
$idx = 3 then return Round(
$rh_lightness*
$hsl_scale, 2)
$rh_saturation = 0
if
$rh_lightness > 0 and
$rh_lightness < 1 then
if
$rh_lightness < 0.5 then
$rh_saturation =
$rh_delta / (2 *
$rh_lightness)
else
$rh_saturation =
$rh_delta / (2 - 2 *
$rh_lightness)
endif
endif
if
$idx = 2 then return Round(
$rh_saturation*
$hsl_scale, 2)
endif
$rh_hue = 0
if
$rh_delta > 0 then
if
$rh_max =
$rh_r and
$rh_max <>
$rh_g then
$rh_hue += (
$rh_g -
$rh_b) /
$rh_delta endif
if
$rh_max =
$rh_g and
$rh_max <>
$rh_b then
$rh_hue += 2 + (
$rh_b -
$rh_r) /
$rh_delta endif
if
$rh_max =
$rh_b and
$rh_max <>
$rh_r then
$rh_hue += 4 + (
$rh_r -
$rh_g) /
$rh_delta endif
$rh_hue *= 60
endif
if
$rh_hue < 0 then
$rh_hue += 360
if
$idx = 1 then return Round(
$rh_hue)
$do_string = true
if not
$idx then
$idx =
"," $do_string = false
endif
$hsl = Round(
$rh_hue) &
$idx & Round(
$rh_saturation*
$hsl_scale, 2) &
$idx & Round(
$rh_lightness*
$hsl_scale, 2)
if
$do_string then return
$hsl return StringSplit(
$hsl,
$idx)
endfunc
Func GetColorRed(
$nColor)
Return BitAND( BitShift(
$nColor, 16), 0xff)
EndFunc
Func GetColorGreen(
$nColor)
Return BitAND( BitShift(
$nColor, 8), 0xff)
EndFunc
Func GetColorBlue(
$nColor)
Return BitAND(
$nColor, 0xff)
EndFunc