IDL 7.1: 24-bit PostScript output!
posted Fri 5 Jun 2009 by Michael Galloy under IDLLately, I find myself sharing PNG images of graphics more and more. And the method I have been using to produce better quality images is to make PostScript output in IDL and convert that to PNG using ImageMagick. But it’s a major pain to have to do everything in 8-bit color. No longer! Set the DECOMPOSED
keyword to DEVICE
(and make sure COLOR
is set too) and normal 24-bit colors work in the PostScript direct graphics device just like in the X and WIN devices.
For example, the following produces the PostScript file to create the plot above:
IDL> orig_device = !d.name
IDL> set_plot, 'ps'
IDL> device, decomposed=1, /color
IDL> device, filename='test.ps', xsize=3, ysize=2, /inches
IDL> x = findgen(360) * !dtor
IDL> y = sin(x)
IDL> plot, x, y, /nodata, xstyle=9, ystyle=8
IDL> oplot, x, y, color='ff0000'x, thick=2
IDL> device, /close_file
IDL> set_plot, orig_device
Then I run test.ps
through ImageMagick to get the PNG file displayed.
While the documentation says that the GET_DECOMPOSED
keyword to DEVICE
should return whether the PostScript device is in indexed or decomposed color, it does not. In fact, it does not recognize the GET_DECOMPOSED
keyword. The only way to tell right now is the output from help, /device
.
UPDATE: I changed the color of the plot from red to blue because red is a bad color to test whether we’re in indexed or decomposed color as noted by David in the comments.
June 5th, 2009 at 3:16 pm
Well, uh, the color red isn’t really a very good test now, is it? I mean, I’m sure it probably works. But this just doesn’t prove it. :-)
June 5th, 2009 at 3:33 pm
Yep, that is an unfortunate color choice. Switched to blue.
June 6th, 2009 at 7:02 am
The inability of the PostScript device to use the Get_Decomposed keyword is certainly unfortunate, but using HELP, /DEVICE is not the only alternative. I’ve written a program, named DecomposedColor, which can be used to programmatically determine if any IDL graphics device is set up to use decomposed color, including the PostScript device. For PostScript, of course, I have to parse the output from the HELP command, which is a pain in the kiester, but at least it only has to be done once, and users of DecomposedColor don’t have to worry about the details. The program can be downloaded from the Coyote’s Guide to IDL Programming web page.
June 6th, 2009 at 9:48 am
I suppose it depends on what you mean by “only way” — it comes down to that one way or another.
June 7th, 2009 at 10:57 am
Hi Michael,
Looks interesting. Perhaps even worth an upgrade from IDL 6.4 which has suited me just fine.
Question: Can you use a color table at the same time? For example, use my existing code to TV or IMDISP or something a data set that has been scaled 1-252, and then use hex to define color for some PLOTS or legend or other command that adds extra data?
June 7th, 2009 at 12:04 pm
Yes, in the normal way:
IDL> nlevels = 15
IDL> set_plot, 'ps'
IDL> device, /color, decomposed=0
IDL> loadct, 5
IDL> contour, hanning(20, 20), /fill, nlevels=nlevels
IDL> device, decomposed=1
IDL> contour, hanning(20, 20), /overplot, color='ff0000'x, nlevels=nlevels
IDL> device, /close_file
IDL> set_plot, 'x'
This produces a plot with fill colors from color table 5 and blue contour lines.
September 28th, 2009 at 2:48 pm
[…] the GET_DECOMPOSED keyword for Postscript devices as the documentation says it should, which I have complained about before). See the full releases notes for details. No Comments […]