ripley at stats.ox.ac.uk
2008-May-27 10:45 UTC
[Rd] (PR#11509) rgb to cmyk conversion is wrong in
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
Jeffrey J. Hallman
2008-May-27 14:51 UTC
[Rd] (PR#11509) rgb to cmyk conversion is wrong in
ripley at stats.ox.ac.uk writes:> 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.I thought fixes were also applied to R-patched, which you can see I did check. I also searched the bug reports and the release notes for R-devel. I follow the r-devel mailing list and did not see this bug mentioned there either. Nor did I find anything on CRAN's R site search.> Also, there is no unique way to do undercover removal in conversion to > CMYK, and so it is wrong to call any method 'wrong'More accurately, it is wrong to call any method "right", as they are all "wrong". But some are more wrong than others, and the code I reported was very wrong. Some of the CMYK numbers it produced were outside the [0,1] closed interval, which is clearly an error according to PostScript documentation. And both the printed output and PDFs produced via ps2pdf looked horrible. When I substituted CMYK numbers produced by my R function into the .ps file, the colors were, in fact, very close to the ones produced using the default rgb colormodel.> -- in fact the one used in earlier versions of R was a documented method and > within the family described in the PDF reference manual.OK, maybe it's just because I'm a bit annoyed by your tone, but why is deleted code from an earlier version of R relevant here? It doesn't make my bug report any less valid.> -- > 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Jeff