Using the Ghostscript's jpeg device to convert CMYK to RGB

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
XFox

Using the Ghostscript's jpeg device to convert CMYK to RGB

Post by XFox »

Few years ago I faced the problem that Java cannot display CMYK JPEG images (see bug 4924909 on the SDN bug database), so when I use ImageMagick to convert from CMYK PS or EPS files to JPEG files, I get a CMYK JPEG that cannot be displayed in the Java application that my plug-in is built for.
I found a note on my computer (evidently written by myself… :shock: ) stating that a way to convert CMYK PS and EPS files to RGB JPEG is to modify delegates.xml to instruct the Ghostscript program or library to use the jpeg device.
So, I modified the lines for ps:alpha, ps:color, ps:cmyk and ps:mono to use the jpeg device (-sDEVICE=jpeg) and, indeed, it works.
However, I cannot find (or recall) where I learned this trick (it probably came from a thread of the now defunct ImageMagick forum on redux.imagemagick.com :( ) and I have two questions about this workaround:

1) Is documented somewhere? If not, the fact that the jpeg device doesn't preserve the original color space has to be considered a defect of Ghostscript (v8.50 GPL)? If this is the case, maybe it will be (or has been) corrected in some later release and I could break my workaround by upgrading the Ghostscript library…

2) What downsides do you see in this workaround? Should I change the device only for ps:cmyk and not for the others?

Thanks in advance.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Using the Ghostscript's jpeg device to convert CMYK to RGB

Post by magick »

Some applications cannot support JPEG images in the CMYK colorspace. The workaround of course is to produce JPEG images in the RGB colorspace. With Postscript there are three methods to achieve this goal: 1) have Ghostscript perform the conversion; 2) have ImageMagick perform the conversion with the -colorspace option; or the solution with the most accurate color conversion is to use profiles with the -profile option. For 1, either add the -colorspace rgb option before the Postscript filename on the command line or change the delegate.xml file so that the ps:cmyk delegate is pnmraw rather than pam. For 2) add the -colorspace rgb option after the filename. Or for 3) use the -profile option twice (one that specifies a SWOP color profile and one that specifies a sRGB color profile).
XFox

Re: Using the Ghostscript's jpeg device to convert CMYK to RGB

Post by XFox »

Thanks a lot magick. :)
Post Reply