Titan
Joined: 11 Aug 2004 Posts: 5009 Location: imaginationland
|
Posted: Mon Jun 19, 2006 2:52 pm Post subject: Convert CMYK to RGB and vice versa |
|
|
rgb(c, m, y, k [, s])
Converts CMYK to RGB. CMYK values must be between 0 and 1.
| Code: | rgb(c1, c2, c3, k, s = "") {
kx := 1 - k, s := s ? s : ", "
Loop, 3
l .= Round((1 - (c%A_Index% * kx + k)) * 255) . s
Return, SubStr(l, 1, -StrLen(s))
} |
cmyk(r, g, b [, s, f])
Converts RGB to CYMK. RGB values must be between 1 and 255.
| Code: | cmyk(r, g, b, s = "", f = 3) {
k := c1 := 1 - r, c2 := 1 - g, c3 := 1 - b, s := s ? s : ", "
ki := 1 - (k := c2 < k ? c2 : k, k := c3 < k ? c3 : k)
Loop, 3
c .= Round((c%A_Index% - k) / ki, f) . s
Return, c . Round(k, f)
} |
s is the delimiter and f is the degree of accuracy in decimal places. There will be a slight loss in accuracy when making conversions because neither RGB nor CMYK is an absolute colour space.
Download _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
Titan
Joined: 11 Aug 2004 Posts: 5009 Location: imaginationland
|
Posted: Mon Dec 18, 2006 6:20 pm Post subject: |
|
|
I shortened both functions with the expression updates in AutoHotkey v1.0.46 _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|