AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert CMYK to RGB and vice versa

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Mon Jun 19, 2006 2:52 pm    Post subject: Convert CMYK to RGB and vice versa Reply with quote

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")
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Mon Dec 18, 2006 6:20 pm    Post subject: Reply with quote

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")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group