[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Baffled by color postscript



David Fanning wrote:
> Liam Gumley (Liam.Gumley@ssec.wisc.edu) writes:
> > I guess I'm not sure I understand the problem. I'm able to display true
> > color images with colored graphics overlays; I've attached a Postscript
> > example to this message. The postscript file includes 6 test images.
> > Images 2, 4, and 6 are true color (24 bit) with colored lines (axes,
> > title, colorbar) overlaid. I've also attached a JPEG version that was
> > created from the postscript (using ImageMagick).
> Very nice. But can we have a peak at the code that is used
> to generate them. In particular, at the code to generate the
> colored lines. Thanks.

I use a technique I call 'color table splitting'. It involves reserving
part of the color table for images, and part of the color table for
overlays (e.g. titles, axes, contours etc.).

Try executing the following immediately after starting IDL (requires
http://www.dfanning.com/programs/tvimage.pro, and colors.pro attached):

;---cut here---
;- Set display mode to true color if available, pseudo color if not

;- Windows case (TRUE_COLOR keyword not supported)

if !d.name eq 'WIN' then $
  device, decomposed=0, retain=2

;- X and Macintosh case (reverts to pseudo color if true color fails)

if !d.name eq 'X' or !d.name eq 'MAC' then $
  device, true_color=24, decomposed=0, retain=2

;- Create a true color data array

dim = 256
truedata = rebin( indgen( dim ), dim, dim )
data = intarr( dim, dim, 3 )
data[ *, *, 0 ] = truedata
data[ *, *, 1 ] = rotate( truedata, 1 )
data[ *, *, 2 ] = rotate( truedata, 2 )

;- Create byte scaled true color image (reserve colors 0-15)

bottom = 16B
ncolors = !d.table_size-bottom
image = bytscl( data, top=ncolors-1 ) + bottom

;- Load overlay colors from 0 to 15

colors

;- Load greyscale from 16 to !d.table_size-1

loadct, 0, bottom=bottom

;- Display image with color overlay

erase, 7
pos = [0.1,0.1,0.9,0.9]
tvimage, image, /keep, pos=pos
plot, [0], /nodata, /noerase, pos=pos, color=1, title='True Color'
;---cut here---

To make this work in Postscript, you need to modify tvimage.pro to
accept BOTTOM and NCOLORS keywords thus:

(1) Add the following to the keywords in the PRO statement:
BOTTOM=bottom, NCOLORS=ncolors

(2) Add the following lines after 'Check for keywords'
IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0
IF N_ELEMENTS(ncolors) EQ 0 THEN ncolors = !d.table_size - bottom

(3) Change the line that reads
IF true GT 0 THEN LOADCT, 0, /Silent
to
IF true GT 0 THEN LOADCT, 0, /Silent, BOTTOM=bottom, NCOLORS=ncolors

And of course remember to switch to Postscript using
SET_PLOT, 'PS'
DEVICE, /COLOR, BITS=8

Cheers,
Liam.

---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley

;---cut here---
PRO COLORS, START = START

;+
; Purpose:
;     Load the sixteen McIDAS graphics colors.
;
; Usage:
;     COLORS
;
; Input:
;     None
;
; Output:
;     None
;
; Optional Keywords:
;     START   Start index in the color table where the graphics
;             colors will be loaded (default = 0).
;
; Notes:
;     The color table assignments are as follows
;      0 => black
;      1 => magenta
;      2 => cyan
;      3 => yellow
;      4 => green
;      5 => red
;      6 => blue
;      7 => white
;      8 => navy
;      9 => gold
;     10 => pink
;     11 => aquamarine
;     12 => orchid
;     13 => gray
;     14 => sky
;     15 => beige
;
; Example:
;colors
;xyouts, 0,   0, 'Magenta', /device, color=1
;xyouts, 0, 100,     'Red', /device, color=5
;xyouts, 0, 200,   'Green', /device, color=4
;xyouts, 0, 300,    'Blue', /device, color=6
;
; Author:
;     Liam.Gumley@ssec.wisc.edu
;-

;- Check keywords

if n_elements( start ) ne 1 then start = 0

;- Load McIDAS graphics colors

r = [0,255,0,255,0,255,0,255,0,255,255,112,219,127,0,255]
g = [0,0,255,255,255,0,0,255,0,187,127,219,112,127,163,171]
b = [0,255,255,0,0,0,255,255,115,0,127,147,219,127,255,127]
tvlct, r, g, b, start

END
;---cut here---