%D \module
%D   [       file=colo-sep,
%D        version=2002.7.4,
%D          title=\CONTEXT\ Color Macros,
%D       subtitle=Color Separation, 
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Context Color Separation}

%D Experimental (and yet undocumented) module. 

\unprotect 

\chardef\colorfilter=0

\let\filteredprocesscolor\empty

\def\negatecolorcomponent#1%
  {\scratchdimen\!!onepoint\advance\scratchdimen-#1\s!pt%
   \edef\colorcomponent{\@EA\withoutpt\the\scratchdimen}}

\let\filtercolorlist\empty

\def\processcolorpct{1}

\def\filtercolor
  {\dodoubleempty\dofiltercolor}

\def\dofiltercolor[#1][#2]% rgb/gray are actually dummies 
  {\doifelse{#1}\v!reset
     {\let\filtercolorlist\empty}
     {\getparameters[\??cr][#2]%
      \pushmacro\exectransparency
      \pushmacro\dostartrgbcolormode    
      \pushmacro\dostartcmykcolormode    
      \pushmacro\dostartgraycolormode         
      \def\exectransparency{\gobbleuntil\od}%
      \def\dostartrgbcolormode    ##1##2##3{}%
      \def\dostartcmykcolormode##1##2##3##4{\docommando{##1:##2:##3:##4}}%
      \def\dostartgraycolormode         ##1{}%
      \def\docommando##1%
        {\edef\filtercolorlist{\filtercolorlist/##1/}%
         \letvalue{\??cr:p:##1}\@@crp}%
      \processcommalist[#1]{\dowithcolor\execcolorRCS}%
      \popmacro\dostartgraycolormode         
      \popmacro\dostartcmykcolormode    
      \popmacro\dostartrgbcolormode    
      \popmacro\exectransparency}}

\def\checkprocesscolor#1#2#3#4%
  {\doifinstringelse{/#1:#2:#3:#4/}\filtercolorlist\donetrue\donefalse
   \ifdone\edef\processcolorpct{\getvalue{\??cr:p:#1:#2:#3:#4}}\fi}

\protect \endinput 

%D Test Data: 

\setupoutput[pdftex] \usespecials[fds]

\setupcolors[state=start]

\definecolor[darkred]    [r=.5]
\definecolor[darkgreen]  [g=.5]
\definecolor[darkblue]   [b=.5]
\definecolor[darkcyan]   [c=.5]
\definecolor[darkmagenta][m=.5]
\definecolor[darkyellow] [y=.5]

\setuplayout
  [header=0pt,footer=1cm,
   width=middle,height=middle,
   topspace=.25cm,backspace=.25cm]

\setupbodyfont[ppl,9pt]

\starttext

\startbuffer
\startcolor[red]         red         : \input zapf \stopcolor \par
\startcolor[darkred]     darkred     : \input zapf \stopcolor \par
\startcolor[green]       green       : \input zapf \stopcolor \par
\startcolor[darkgreen]   darkgreen   : \input zapf \stopcolor \par
\startcolor[blue]        blue        : \input zapf \stopcolor \par
\startcolor[darkblue]    darkblue    : \input zapf \stopcolor \par
\startcolor[cyan]        cyan        : \input zapf \stopcolor \par
\startcolor[darkcyan]    darkcyan    : \input zapf \stopcolor \par
\startcolor[magenta]     magenta     : \input zapf \stopcolor \par
\startcolor[darkmagenta] darkmagenta : \input zapf \stopcolor \par
\startcolor[yellow]      yellow      : \input zapf \stopcolor \par
\startcolor[darkyellow]  darkyellow  : \input zapf \stopcolor \par
\startcolor[black]       black       : \input zapf \stopcolor \blank
\startMPcode
  path p ; p := fullsquare xyscaled (1cm,.5cm) ;
  fill p shifted ( 0cm,0) withcolor \MPcolor {red} ;
  fill p shifted ( 2cm,0) withcolor \MPcolor {green} ;
  fill p shifted ( 4cm,0) withcolor \MPcolor {blue} ;
  fill p shifted ( 6cm,0) withcolor \MPcolor {cyan} ;
  fill p shifted ( 8cm,0) withcolor \MPcolor {magenta} ;
  fill p shifted (10cm,0) withcolor \MPcolor {yellow} ;
  fill p shifted (12cm,0) withcolor \MPcolor {black} ;
\stopMPcode
\page
\stopbuffer

\setuplayout[color=black]

\bf

\setupfootertexts [full]             \setupcolors[split=no] \getbuffer
\setupfootertexts [\cyan    cyan]    \setupcolors[split=c]  \getbuffer
\setupfootertexts [\magenta magenta] \setupcolors[split=m]  \getbuffer
\setupfootertexts [\yellow  yellow]  \setupcolors[split=y]  \getbuffer
\setupfootertexts [\black   black]   \setupcolors[split=k]  \getbuffer

\startbuffer
\startcolor[one]   one   : \input zapf \stopcolor \par
\startcolor[two]   two   : \input zapf \stopcolor \par
\startcolor[gray]  gray  : \input zapf \stopcolor \par
\startcolor[black] black : \input zapf \stopcolor \blank
\startMPcode
  path p ; p := fullsquare xyscaled (1cm,.5cm) ;
  fill p shifted ( 0cm,0) withcolor \MPcolor {one} ;
  fill p shifted ( 2cm,0) withcolor \MPcolor {two} ;
  fill p shifted ( 4cm,0) withcolor \MPcolor {gray} ;
  fill p shifted ( 6cm,0) withcolor \MPcolor {black} ;
\stopMPcode
\page
\stopbuffer

\definecolor[one][c=1,m=.2,k=.3]
\definecolor[two][c=.5,m=.1,k=.15]

\filtercolor[one][p=1]
\filtercolor[two][p=.5]

\setupfootertexts [full]            \setupcolors[split=no] \getbuffer
\setupfootertexts [\one one \& two] \setupcolors[split=p]  \getbuffer
\setupfootertexts [\black black]    \setupcolors[split=s]  \getbuffer

\stoptext
