Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // atan2/cos/sin functions operate in degrees, not radi
- // Compresses RGB32 color to INT format
- // usage: /RGB32toINT #A #R #G #B [ action ]
- // INT variables (separate): $a $r $g $b
- RGB32_to_INT = [
- local a r g b
- a = (<< $arg1 24)
- r = (<< $arg2 16)
- g = (<< $arg3 8)
- b = $arg4
- if (>= $numargs 5) [ doargs $arg5 ] [ + $a $r $g $b ]
- ]
- // Converts INT color to RGB32 format
- // usage: /INT_to_RGB32 #INT [ action ]
- // RGB32 variables: $a $r $g $b
- INT_to_ARGB32 = [
- local a r g b
- a = (>> $arg1 24)
- r = (& (>> $arg1 16) 255)
- g = (& (>> $arg1 8) 255)
- b = (& $arg1 255)
- if (< $numargs 2) [ concat $a $r $g $b ] [ doargs $arg2 ]
- ]
- // Converts RGB32 color to HEX data
- // usage: /RGB32_to_HEX #A #R #G #B #length [ action ]
- // HEX variables: $hex
- RGB32_to_HEX = [
- local hex
- hex = (tohex (
- RGB32_to_INT $arg1 $arg2 $arg3 $arg4
- ) (? $arg5 (min $arg5 16) 6))
- if (< $numargs 6) [ result $hex ] [ doargs $arg6 ]
- ]
- // Converts RGB24 color to CIELch data (CIELab data also available!)
- // usage: /RGB24_to_CIELCH #R #G #B [ action ]
- // CIELch variables: $l $c $h | CIELab variables: $l $a $b
- RGB24_to_CIELCH = [
- local x y z a b l c h
- arg1 = (divf $arg1 255)
- arg2 = (divf $arg2 255)
- arg3 = (divf $arg3 255)
- looplist i "arg1 arg2 arg3" [
- if (>f $$i 0.04045) [
- $i = (*f (pow (divf (+f $$i 0.055) 1.055) 2.4) 100)
- ] [ $i = (*f (divf $$i 12.92) 100) ]
- ]
- x = (divf (+f (*f $arg1 0.4124) (*f $arg2 0.3576) (*f $arg3 0.1805)) 95.047)
- y = (divf (+f (*f $arg1 0.2126) (*f $arg2 0.7152) (*f $arg3 0.0722)) 100.000)
- z = (divf (+f (*f $arg1 0.0193) (*f $arg2 0.1192) (*f $arg3 0.9505)) 108.883)
- looplist i "x y z" [
- if (>f $$i 0.008856) [
- $i = (pow $$i (divf 1 3))
- ] [ $i = (+f (*f 7.787 $$i) (divf 16 116)) ]
- ]
- a = (*f 500 (-f $x $y))
- b = (*f 200 (-f $y $z))
- l = (if (>f $y 0.008856) [-f (*f 116 $y) 16] [*f 903.3 $y])
- c = (sqrt (+f (pow $a 2) (pow $b 2)))
- h = (atan2 $b $a)
- cond (<f $h 0) [ h = (+f $h 360) ] (>=f $h 360) [ h = (-f $h 360) ]
- if (< $numargs 4) [ concat $l $c $h ] [ doargs $arg4 ]
- ]
- // Converts CIELCH data to RGB24 format
- // usage: /CIELCH_to_RGB24 #R #G #B [ action ]
- // RGB24 variables: $r $g $b
- CIELCH_to_RGB24 = [
- local x y z r g b
- y = (divf (+f $arg1 16) 116)
- x = (+f (divf (*f (cos $arg3) $arg2) 500) $y)
- z = (-f $y (divf (*f (sin $arg3) $arg2) 200))
- looplist i "x y z" [
- if (>f (pow $$i 3) 0.008856) [
- $i = (pow $$i 3)
- ] [ $i = (divf (-f $$i (divf 16 116)) 7.787) ]
- ]
- x = (divf (*f $x 95.047) 100)
- z = (divf (*f $z 108.883) 100)
- r = (+f (*f $x 3.2406) (*f $y -1.5372) (*f $z -0.4986))
- g = (+f (*f $x -0.9689) (*f $y 1.8758) (*f $z 0.0415))
- b = (+f (*f $x 0.0557) (*f $y -0.2040) (*f $z 1.0570))
- looplist i "r g b" [
- if (>f $$i 0.0031308) [
- $i = (-f (*f 1.055 (pow $$i (divf 1 2.4))) 0.055)
- ] [ $i = (*f 12.92 $$i) ]
- $i = (round (*f $$i 255))
- ]
- if (< $numargs 4) [ concat $r $g $b ] [ doargs $arg4 ]
- ]
- // Converts RGB24 color to HSV data
- // usage: /RGB24_to_HSV #R #G #B [ action ]
- // HSV variables: $h $s $v
- RGB24_to_HSV = [
- local r g b mn d h s v
- r = (divf $arg1 0xFF)
- g = (divf $arg2 0xFF)
- b = (divf $arg3 0xFF)
- v = (maxf $r $g $b)
- mn = (minf $r $g $b)
- if (=f $mn $v) [
- d = 0
- h = 0
- s = 0
- ] [
- d = (-f $v $mn)
- s = (divf $d $v)
- h = (casef $v $r [
- floor (*f 60 (modf (divf (-f $g $b) $d) 6))
- ] $g [
- *f 60 (+f (divf (-f $b $r) $d) 2)
- ] $b [
- *f 60 (+f (divf (-f $r $g) $d) 4)
- ])
- ]
- if (< $numargs 4) [ concat $h $s $v ] [ doargs $arg4 ]
- ]
- // Converts HSV data to RGB24 format
- // usage: /HSV_to_RGB24 #H #S #V [ action ]
- // RGB24 variables: $r $g $b
- HSV_to_RGB24 = [
- local c x m r g b
- c = (*f $arg3 $arg2)
- x = (*f $c (-f 1 (absf (-f (modf (divf $arg1 60) 2) 1))))
- m = (-f $arg3 $c)
- h = (div $arg1 60)
- r = (round (*f 255 (+f (at [@c @x 0 0 @x @c] $h) $m)))
- g = (round (*f 255 (+f (at [@x @c @c @x 0 0] $h) $m)))
- b = (round (*f 255 (+f (at [0 0 @x @c @c @x] $h) $m)))
- if (< $numargs 4) [ concat $r $g $b ] [ doargs $arg4 ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement