|
Author |
Topic: Color conversions formulas: CMYK <> RGB (Read 2126 times) |
|
amoeba
|
Color conversions formulas: CMYK <> RGB
« on: Apr 15th, 2004, 8:56pm » |
|
Found some pseudocode for color conversions between RGB and CMYK on the EasyRGB site. Posting it here for reference. They also have other formulas and useful links to computer color resources. Code:CMYK -> CMY CMYK values = From 0 to 1 C = ( C * ( 1 - K ) + K ) M = ( M * ( 1 - K ) + K ) Y = ( Y * ( 1 - K ) + K ) -- CMY -> RGB CMY values = From 0 to 1 R = ( 1 - C ) * 255 G = ( 1 - M ) * 255 B = ( 1 - Y ) * 255 -- RGB -> CMY RGB values = From 0 to 255 C = 1 - ( R / 255 ) M = 1 - ( G / 255 ) Y = 1 - ( B / 255 ) -- CMY -> CMYK CMY values = From 0 to 1 var_K = 1 if ( C < var_K ) var_K = C if ( M < var_K ) var_K = M if ( Y < var_K ) var_K = Y C = ( C - var_K ) / ( 1 - var_K ) M = ( M - var_K ) / ( 1 - var_K ) Y = ( Y - var_K ) / ( 1 - var_K ) K = var_K |
|
|
« Last Edit: Apr 15th, 2004, 9:12pm by amoeba » |
|
marius watz // amoeba http://processing.unlekker.net/
|
|
|
fry
|
Re: Color conversions formulas: CMYK <> RGB
« Reply #1 on: Apr 15th, 2004, 11:43pm » |
|
i've been thinking about colorMode(CMYK), which would do this for on-screen stuff, but perhaps for postscript export would instead store the "real" cmyk values (internally) for output.. these versions of the CMYK/RGB conversion are crude, but maybe it'd be useful.. i believe that things like photoshop and illustrator use different (i think they're different from one another, even), more complicated models for the conversion, but maybe just keeping track of things internally (for when it matters, which print imaging) it'd be ok. thoughts?
|
|
|
|
amoeba
|
Re: Color conversions formulas: CMYK <> RGB
« Reply #2 on: Apr 16th, 2004, 1:33pm » |
|
A CMYK colorspace would be great, both for Postscript stuff and in general. I sometimes develop color schemes in CMYK since it's more flexible than RGB in some respects. The reason I was researching these conversions is because I'm working on an import library for Illustrator EPS files. The idea is to parse enough of the code to read vector objects as a chain of Postscript commands. These can then either be output back out as Postscript or converted to Processing drawing commands. The latter would be excellent, but of course won't work too well right now since the polygon code is broken. I need CMYK conversion for this project anyway, so it'd be great if it was included in Processing at some point. And it'd be great just for the sake of completeness.
|
marius watz // amoeba http://processing.unlekker.net/
|
|
|
Markavian
|
Re: Color conversions formulas: CMYK <> RGB
« Reply #4 on: Apr 17th, 2004, 11:14am » |
|
A point on the issue of CMYK, can the current 'save' formats support CYMK data? I don't know much about the format, I've never really done much printing from PCs, but I'm sure you'd still have to work on screen before you could print anything... will anyone be 'that' serious about getting the colours 'just right' in processing before export. What about just taking an RGB export, tweaking it in Photoshop, and resaving?
|
|
|
|
amoeba
|
Re: Color conversions formulas: CMYK <> RGB
« Reply #5 on: Apr 17th, 2004, 3:36pm » |
|
on Apr 17th, 2004, 11:14am, Markavian wrote:will anyone be 'that' serious about getting the colours 'just right' in processing before export. What about just taking an RGB export, tweaking it in Photoshop, and resaving |
| Not a bad point, I don't think anyone will start using Processing as a preprint package anytime soon. TIFF does support CMYK, but the save() obviously doesn't at the moment. Another point is that the inkjet printers most people use for color prints aren't actually CMYK processes, and so the input should be RGB. I think a CMYK colorspace should be included for completeness in terms of color theory, and also for reading and writing PostScript /PDF. CMYK raster output is probably irrelevant, for the reasons you mention. To color proof CMYK you need to use something like Photoshop anyway.
|
« Last Edit: Apr 17th, 2004, 3:38pm by amoeba » |
|
marius watz // amoeba http://processing.unlekker.net/
|
|
|
fry
|
Re: Color conversions formulas: CMYK <> RGB
« Reply #6 on: Apr 19th, 2004, 1:33am » |
|
righto.. cmyk would not be the imaging model used on screen (makes no sense for interactive graphics).. the idea was that the colorMode would be faked on screen but then stored internally, so when outputting to a postscript file (the export-to-postscript function that's on its way) it would be emitting the proper numbers for cmyk coloring. the postscript export code is something like a slightly more complete version of amoeba's SimplePostscript class, and is one of those things that i use heavily in my own work but haven't fully adapted for processing just yet. the idea is that you'll be able to switch from screen rendering to file rendering and have the image you create spew out as postscript (or whatever other format folks write for..)
|
|
|
|
|