[Rd] (PR#11509) rgb to cmyk conversion is wrong in

ripley at stats.ox.ac.uk ripley at stats.ox.ac.uk
Tue May 27 12:45:09 CEST 2008


Please do study the FAQ and posting guide: R 2.7.0 is not the current 
sources, and this was changed a month ago in R-devel.  You were asked to 
check for such changes before submitting a report.

Also, there is no unique way to do undercover removal in conversion to 
CMYK, and so it is wrong to call any method 'wrong' -- in fact the one 
used in earlier versions of R was a documented method and within the 
family described in the PDF reference manual.

On Fri, 23 May 2008, m1jjh00 at frb.gov wrote:

> The conversion of RGB to CMYK takes place in PostScriptSetCol() starting at
> line 2900 of R-2.7.0/src/library/grDevices/src/devPS.c
>
> 	if(strcmp(mm, "cmyk") == 0) {
> 	    double c = 1.0-r, m=1.0-g, y=1.0-b, k=c;
> 	    k = fmin2(k, m);
> 	    k = fmin2(k, y);
> 	    if(k == 1.0) c = m = y = 0.0;
> 	    else {c /= (1.-k); m /= (1.-k); y /= (1.-k);}
>
> r, g, and b have already been normalized to the range [0,1] before the
> function was called, so this is almost right.  The last line should actually
> be something like
>
> else { c = (c - k)/(1 - k); m = (m - k)/(1 - k); y = (y - k)/(1 - k);}
>
> Here is some R code I wrote that does the conversion, so you can see what it's
> supposed to be doing:
>
> rgb2cmyk <- function(rgb){
>  ## rgb is a vector of 3 numbers in the 0 to 255 range
>  ## returns cmyk vector of 4 numbers in [0,1]
>  cmy <- 1 - rgb/255
>  names(cmy) <- c("c", "m", "y")
>  k <- min(min(min(1, cmy[1]), cmy[2]), cmy[3])
>  if(k == 1) c(cmy, k = 1)
>  else c(c(cmy - k)/(1-k), k = k)
> }
>
> --please do not edit the information below--
>
> Version:
> platform = i686-redhat-linux-gnu
> arch = i686
> os = linux-gnu
> system = i686, linux-gnu
> status = Patched
> major = 2
> minor = 7.0
> year = 2008
> month = 05
> day = 22
> svn rev = 45762
> language = R
> version.string = R version 2.7.0 Patched (2008-05-22 r45762)
>
> Locale:
> LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C
>
> Search Path:
> .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list