PostScript Output Always Blank

QUESTION: I got this program from a colleague that he claims produces color PostScript output. But every time I run the program I end up with a blank sheet of paper. Something is written into the file, because the file size is not zero. But nothing is ever printed and I can't see anything in the file when I view it with GhostView. What am I doing wrong?

ANSWER: The problem is a bit of confusion caused by the introduction of 24-bit color PostScript output in IDL 7.1. It is now possible to specify PostScript colors by using a 24-bit color value that can be "decomposed" into three 8-bit color values that represent the red, green, and blue colors that mutually create the requested color. This is sometimes known as true-color, since it is possible to simultaneously display 16.7 million colors, instead of the 256 colors the PostScript device was previously restricted to displaying.

To activate 24-bit PostScript color support, you must have version 7.1 or higher of IDL, and you must set the Decomposed keyword to 1. (Actually, it is slightly more complicated than this, because you must also have set the Color keyword to 1, and the Bits_Per_Pixel keyword to 8, but this is pretty much always done by IDL programmers and is certainly done with PostScript set-up programs like csPS_Config.)

    Set_Plot, 'PS'    Device, DECOMPOSED=1, COLOR=1, BITS_PER_PIXEL=8

With color decomposition turned on, any color value is interpreted as being a color triple encoded into a 24-bit value, with the lowest 8 bits representing the red value and the highest 8 bits representing the blue value. It is perhaps easiest to see this with an example. Take the color "khaki", which is represented by the RGB triple (240, 230, 140).

   IDL> Print, Reform(FSC_Color('khaki', /TRIPLE))      240     230     140

Here the red value (240, in this case) is represented on the left and the blue value on the right (in the traditional RGB arrangement). But, when displaying a number, it is traditional to display the lowest eight bits (the red bits) on the right and higher bits to the left. So, to represent the color khaki, in its 24-bit representation, in binary form, we might do this.

    IDL> khaki = FSC_Color('khaki', DECOMPOSED=1)    IDL> Print, khaki
      9234160    IDL> Print, Binary(khaki, /COLOR, /SEPARATE)
      1 0 0 0 1 1 0 0    1 1 1 0 0 1 1 0    1 1 1 1 0 0 0 0 

In this representation, the red component (1 1 1 1 0 0 0 0) is on the right, and the blue component (1 0 0 0 1 1 0 0) is on the left. We can confirm by printing the binary patterns for the numbers 240 and 140, respectively.

   IDL> Print, Binary(240, /COLOR, /SEPARATE)
      0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0    1 1 1 1 0 0 0 0
   IDL> Print, Binary(140, /COLOR, /SEPARATE)
      0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0    1 0 0 0 1 1 0 0 

In other words, the 24-bit number 9234160 is decomposed into three 8-bit numbers, namely 240, 230, and 140. This is what we mean by "color decomposition."

Color Decomposition Turned Off

But what happens to a color like khaki when color decomposition is turned off? When color decomposition is turned off, we typically say we are using indexed color. We mean by this that we have a color table with 256 possible red, green, and blue color combinations loaded into the table, and that we are specifying a color by means of an 8-bit color index into that color table. (Eight bits are all that are needed to represent a number from 0 to 255, which are the indices into the 256-valued color table.)

Suppose, for example, that we had loaded the khaki color into index 200 of the current color table.

Index Red Green Blue
200 240 230 140
 

To draw a plot with the khaki color, we might do something like this.

    IDL> Plot, data, COLOR=200 

The question here, though, is what happens when the color is specified as a 24-bit value (e.g., the number 9234160), but the PostScript device is set up to use indexed color. In other words, what happens when you execute commands like this.

   Set_Plot, 'PS'    Device, DECOMPOSED=0, COLOR=1, BITS_PER_PIXEL=8
   Plot, data, COLOR=9234160L 

Since, in indexed color mode, a number has to be between 0 and 255, the PostScript device takes the number given and forces it into this range, by doing something like this:

    IDL> number = 9234160L    IDL> index = 0 > number < 255
   IDL> Print, index      255 

In other words, this number is forced into the range of 0 to 255, and since most 24-bit numbers have bits set that make them much larger than 255, almost all of these colors are set to 255 before they are used as look-up indices into the color table. Since color index 255 is more often than not set to the color white in PostScript files, and since PostScript files are almost always produced with white backgrounds, this unfortunate situation results in your graphics output being generated with white colors on a white background. Needless to say, the page does look blank!

The solution, of course, is to set the PostScript device up to use decomposed color if you wish to specify your colors as 24-bit values.

    Set_Plot, 'PS'
   Device, DECOMPOSED=1, COLOR=1, BITS_PER_PIXEL=8    Plot, data, COLOR=9234160L

Remember, PostScript device set-ups are "sticky", meaning that once they are set, they stay set until they are changed. If your PostScript device gets into a indexed color setting, it will stay there until you change it. If you wish to use 24-bit values to express your colors, you must turn color decomposition on for your PostScript device.

Alternatively, if you have color decomposition turned on in your PostScript device, and you specify colors as a color index, there is an excellent chance you will end up with a page of nothing but shades of red as your PostScript output.

The secret to wonderful (and colorful!) PostScript output is to match your color specifications with the proper DECOMPOSED setting. Specifying your colors with cgColor, of course, is one way to assure this happens.

Version of IDL used to prepare this article: IDL 7.1.

Google
 
Web Coyote's Guide to IDL Programming