X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4616 Rate this article:
No rating

How To Write 2D Palettized Color Images From IDL Direct Graphics to GIF, PNG or TIFF Files

Topic:
Indexed or palettized color images are 2D images, the color of whose pixels are determined by a 256-element color table on your computer's video card. Once upon a time computer monitor hardware used this color table pretty ubiquitously; it allowed much more efficient color display than 24- and 32-bit True Color display. However, with the evolution of faster processor speeds and massively larger video card memory, the 256-color setting on the display monitor has become obsolete.

Nevertheless, there is still a valid use for palettized color in image graphics files like GIF, PNG and TIFF. Unfortunately, the evolution of the modern computer monitor has affected the easiest way for IDL to get a snapshot of a graphics window for export to image file formats. Namely, IDL's TVRD function on a modern computer monitor device no longer provides anything but RGB values (or values from one of the planes). It turns out that, to acquire the color indexes of an IDL indexed color graphic, the IDL Direct Graphics programmer needs to turn to a different device than the computer monitor. This Help Article provides the steps for using this alternative device.

Note: IDL Object Graphics has a completely different approach.

Discussion:
The device in question is the 'Z-Buffer'. This is a "virtual window" device (like a "pixmap") that was originally implemented in order to allow "depth-order rendering" of multiple graphics objects. Essentially, it is designed to simulate 3D graphics. Luckily, its default settings have one great virtue for indexed color processing - the Z-Buffer pixmap is stored strictly in color table indexes. That is, TVRD() only returns the color table index values of the graphics window it is "snapshooting". That is precisely the unit of measure that 2D color GIF, PNG and TIFF files are looking for. Here is an example of how WRITE_GIF, WRITE_PNG or WRITE_TIFF can take advantage of this Z-Buffer property:Solution:
data = dist(360)    ; simple example data
; the Z-Buffer uses the same color table as the 'X' or 'WIN' monitor devices
loadct, 5
oldDevice = !d.name   ; This will be either 'X' or 'WIN'
set_plot, 'Z'
; Set the pixel width/height of the virtual window
device, SET_RESOLUTION=[500, 400]
; Note how no "device, DECOMPOSED=0" call is needed in the Z-Buffer. That
; is because it defaults to using palettized color. DECOMPOSED is not
; even a valid keyword in the 'Z-Buffer'
shade_surf, data, CHARSIZE=1.5   ; a colorful surface plot
snapshot = tvrd()    ; returns a 2D array of color table indices
set_plot, oldDevice   ; restore the original graphics device
; Load color table settings into arrays that can be passed to the image file
tvlct, r, g, b, /GET
; Export the Z-Buffer snapshot and its color table settings
write_png, 'dist_shade_surf.png', snapshot, r, g, b
write_gif, 'dist_shade_surf.gif', snapshot, r, g, b
write_tiff, 'dist_shade_surf.tif', reverse(snapshot, 2), $
    RED=r, GREEN=g, BLUE=b
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »