[Rd] rgb to cmyk conversion is wrong in src/library/grDevices/src/devPS.c (PR#11509)

m1jjh00 at frb.gov m1jjh00 at frb.gov
Fri May 23 18:50:17 CEST 2008


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



More information about the R-devel mailing list