Why does color change to b/w when using PNG? [message #38540] |
Tue, 16 March 2004 14:59  |
bleau
Messages: 24 Registered: November 1993
|
Junior Member |
|
|
I'm running IDL 5.4 on OpenVMS 7.1-2 and am trying to do some plots.
Previously, we were using the ps device (SET_PLOT,'PS') and generating
PostScript files for each plot. We now want to generate PNG files as well.
I copied all the IDL code that generated the PostScript file, changed
SET_PLOT,'PS' to SET_PLOT,'Z', removed most of the device commands (since
few of them apply to the Z device), and ran the IDL code to test it out.
It ran without errors, which is the good news. The bad news is that the
output PNG file seems to be almost all black, with a few white dots where
the data should be, and absolutely no color; the original had color all
over the place. Sounds like a simple case of the color table being wrong,
I thought.
But wait: the PS device used a color table, too, and I didn't change that
part of the code at all! Here's the code that sets up the color table:
; set up a simple color table
bbc = 255b
bfg = 0b
red = [bbc, bfg, 255b, 0b, 0b, 0b, 255b, 255b, 255b, 127b, 0b, $
0b, 127b, 255b, 85b, 170b]
gre = [bbc, bfg, 0b, 255b, 0b, 255b, 0b, 255b, 127b, 255b, 255b, $
127b, 0b, 0b, 85b, 170b]
blu = [bbc, bfg, 0b, 0b, 255b, 255b, 255b, 0b, 0b, 0b, 127b, $
255b, 255b, 127b, 85b, 170b]
tvlct, red, gre, blu
tvlct, bfg, bfg, bfg, !d.n_colors-1
I checked, and print,!d.n_colors-1 displays 255.
So, what's different between these two plot types (PS vs. PNG) that would
cause the same code to produce different results? TIA.
Lawrence Bleau
University of Maryland
Physics Dept., Space Physics Group
301-405-6223
bleau@umtof.umd.edu
|
|
|
Re: Why does color change to b/w when using PNG? [message #38716 is a reply to message #38540] |
Fri, 19 March 2004 14:12  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Lawrence Bleau writes:
> Previously, we were using the ps device (SET_PLOT,'PS') and generating
> PostScript files for each plot. We now want to generate PNG files as well.
>
> I copied all the IDL code that generated the PostScript file, changed
> SET_PLOT,'PS' to SET_PLOT,'Z', removed most of the device commands (since
> few of them apply to the Z device), and ran the IDL code to test it out.
>
> It ran without errors, which is the good news. The bad news is that the
> output PNG file seems to be almost all black, with a few white dots where
> the data should be, and absolutely no color; the original had color all
> over the place. Sounds like a simple case of the color table being wrong,
> I thought.
>
> But wait: the PS device used a color table, too, and I didn't change that
> part of the code at all! Here's the code that sets up the color table:
>
> ; set up a simple color table
>
> bbc = 255b
> bfg = 0b
>
> red = [bbc, bfg, 255b, 0b, 0b, 0b, 255b, 255b, 255b, 127b, 0b, $
> 0b, 127b, 255b, 85b, 170b]
> gre = [bbc, bfg, 0b, 255b, 0b, 255b, 0b, 255b, 127b, 255b, 255b, $
> 127b, 0b, 0b, 85b, 170b]
> blu = [bbc, bfg, 0b, 0b, 255b, 255b, 255b, 0b, 0b, 0b, 127b, $
> 255b, 255b, 127b, 85b, 170b]
>
> tvlct, red, gre, blu
> tvlct, bfg, bfg, bfg, !d.n_colors-1
>
> I checked, and print,!d.n_colors-1 displays 255.
>
> So, what's different between these two plot types (PS vs. PNG) that would
> cause the same code to produce different results?
I think if you stay away from using color index 0 and color index 255
in your color tables you will be fine. In PostScript, of course, you
can have any background color you like as long at it is white. (Another
way to say this is that PostScipt ignores the color loaded in to
index 255.) PNG is not so particular. What happens when you run this
program on your display? What does it look like then? That is what it
is going to look like in PNG, probably.
Anyway, this kind of thing is done all the time (even, I suppose,
on OpenVMS systems). You really should be able to make identical
plots without much difficulty. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|