On 2/4/07, Hans Hagen
Mojca Miklavec wrote:
On 2/4/07, Hans Hagen
wrote: Peter Rolf wrote:
But to my surprise ConTeXt automatically converts my RGB colors (even the MP defined ones), except that the final colors are in the CMY instead of CMYK color space. All I want is a true RGBtoCMYK conversion. I know about the calculating limitations in TeX, so I can wait for an implemetation of that macro in LuaTeX.
but even then ... we need a formula ...
Most pages on the internet list the following simple conversion formula:
C' = 1 - (R/range) C = (C' - K') / (1 - K') M' = 1 - (G/range) M = (M' - K') / (1 - K') Y' = 1 - (B/range) Y = (Y' - K') / (1 - K') K' = MIN(C',Y',M') K = K'
In the special case of K'=1, use (0,0,0,1)
(I'm not a TeX guru, but I assume that conversion with current macros should not be much more difficult than conversion with luaTeX.)
this is what we have now
\def\doconvertRGBtoCMYK#1\to#2% {\colordimen#1\points \multiply\colordimen \plusthousand \colorcount\colordimen \advance\colorcount \medcard \divide\colorcount \maxcard \colorcount-\colorcount \advance\colorcount \plusthousand \edef#2{\realcolorvalue\colorcount}}
\def\convertRGBtoCMYK#1#2#3% {\doconvertRGBtoCMYK#1\to\@@cl@@c \doconvertRGBtoCMYK#2\to\@@cl@@m \doconvertRGBtoCMYK#3\to\@@cl@@y \let\@@cl@@k\@@cl@@z}
well, you can spent the rest of the evening writing an alternative
Since writing reports can sometimes be really boring, you can test if the following works, but please don't ask me what it does ;) I copy-pasted the code (which should be better written with e-TeX, I suppose, or well ... lua is not that bad after all ;). % RGB -> CMYK % c' = 1 - r % m' = 1 - g % y' = 1 - b % k' = MIN(c',y',m') % c = (c' - k') / (1 - k') % m = (m' - k') / (1 - k') % y = (y' - k') / (1 - k') % k = k' % CMYK -> CMY % c = (c * (1 - k) + k) % m = (m * (1 - k) + k) % y = (y * (1 - k) + k) % CMY -> CMYK % k' = min(c,m,y) % if (k==1) % (0,0,0,1) % else % c = (c' - k') / (1 - k') % m = (m' - k') / (1 - k') % y = (y' - k') / (1 - k') % k = k' \unprotect \def\doconvertRGBtoCMY#1\to#2% {\colordimen#1\points \multiply\colordimen \plusthousand \colorcount\colordimen \advance\colorcount \medcard \divide\colorcount \maxcard \colorcount-\colorcount \advance\colorcount \plusthousand \edef#2{\realcolorvalue\colorcount}} \def\doconvertCMYtoCMYK#1\k#2\to#3%% {\colordimen#1\thousandpoint % \colorcount = 1000c \colorcount\colordimen % check if k<1 \colordimen#2\thousandpoint \ifdim\colordimen<\thousandpoint % #3 = (#1-#2)/(1-#2) \advance\colorcount-\colordimen % \colorcount = 1000(c-k) \colordimen-\colordimen % \colordimen = -1000k \divide\colordimen \plusthousand % \colordimen = -k \advance\colordimen \onepoint % \colordimen = 1-k \divide\colorcount \colordimen % \colorcount = 1000(c-k)/(1-k) % TODO: rounding error! \edef#3{\realcolorvalue\colorcount}% \else % if k==1, the component is zero \let#3\@@cl@@z% \fi} \def\convertRGBtoCMY#1#2#3% {\doconvertRGBtoCMY#1\to\@@cl@@c \doconvertRGBtoCMY#2\to\@@cl@@m \doconvertRGBtoCMY#3\to\@@cl@@y \let\@@cl@@k\@@cl@@z} \def\convertRGBtoCMYK#1#2#3% {\edef\@@cl@@r{#1}\edef\@@cl@@g{#2}\edef\@@cl@@b{#3}% \convertRGBtoCMY\@@cl@@r\@@cl@@g\@@cl@@b% \convertCMYtoCMYK\@@cl@@c\@@cl@@m\@@cl@@y} \def\convertCMYtoCMYK#1#2#3% {\edef\@@cl@@c{#1}\edef\@@cl@@m{#2}\edef\@@cl@@y{#3}% % calculate k = min(c,m,y) % k = 1 \colordimen\onepoint \colorcount\colordimen % if (k>c): k=c \ifdim\colordimen>#1\points% \colordimen#1\points \fi % if (k>m): k=m \ifdim\colordimen>#2\points% \colordimen#2\points \fi % if (k>y): k=y \ifdim\colordimen>#3\points% \colordimen#3\points \fi \multiply\colordimen \plusthousand \colorcount\colordimen \advance\colorcount \medcard \divide\colorcount \maxcard % z = min(c,m,y) \edef\@@cl@@k{\realcolorvalue\colorcount}% % \doconvertCMYtoCMYK#1\k\@@cl@@k\to\@@cl@@c \doconvertCMYtoCMYK#2\k\@@cl@@k\to\@@cl@@m \doconvertCMYtoCMYK#3\k\@@cl@@k\to\@@cl@@y } \protect \setupcolors[state=start, cmyk=yes, mpcmyk=yes, rgb=no, ] \pdfcompresslevel=0 \starttext \startMPcode fill unitsquare scaled 3cm withcolor (223/255,223/255,227/255); % CMY(0.12548, 0.12547, 0.10980) % CMYK(0.01762, 0.01760, 0, 0.10980) % results in (0.016, 0.016, 0, 0.110) \stopMPcode \stoptext Mojca