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.



2384 Rate this article:
No rating

How to specify the number of colors loaded into IDLgrPalette by LoadCT

In the IDLgrPalette object, user can specify any number of colors using the ared, ablue, agreen arguments or the respective keywords. However, when the user loads a table with the LoadCT method, user will always load all 255 colors.

It is more practical to use the feature from the "old" Loadct procedure where you can "squeeze" a colortable into a smaller number of colors. In other words, IDLgrPalette::LoadCT should accept NCOLORS keyword.
 
The following code provides an example of how to specify the number of colors loaded into IDLgrPalette by LoadCT.

;
; Copyright (c) 2000, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;
;--------------------------------------------------------------
;+
; METHODNAME:
; IDLgrPalette::LoadCT2
;
; PURPOSE:
; Loads one of the IDL predefined color tables into this palette.
; (Identical to IDLgrPalette::LoadCT, except that it also allows
; the NCOLORS keyword to be set and handled.)
;
; CALLING SEQUENCE:
; oObj->[IDLgrPalette::]LoadCT2, TableNum
;
; KEYWORD PARAMETERS:
; FILENAME: Set this keyword to the name of a colortable
; file to be used instead of the file colors1.tbl
; in the IDL distribution.
; NCOLORS: Set this keyword to the number of colors to which
; the loaded colortable should be interpolated. The
; default is 256.
;
; MODIFICATION HISTORY:
; Written by: DLD, December 2000.
;-
pro IDLgrPalette::LoadCT2, table_number, FILENAME=filename, NCOLORS=ncolors

; Default to 256 colors, but allow keyword override.
nc = 256
if (N_ELEMENTS(ncolors) ne 0) then $
nc = nc < ncolors
if (nc eq 0) then $
return

; Use the default color table file unless provided by keyword.
if (N_ELEMENTS(filename) ne 0) then $
fname = filename $
else $
fname = FILEPATH('colors1.tbl', SUBDIR=['resource','colors'])


OPENR, lun, fname, /GET_LUN

ntables = 0b
READU, lun, ntables

; Ensure the requested table number is within range.
if (table_number ge ntables) or (table_number lt 0) then $
MESSAGE, 'Table number must be from 0 to ' + STRTRIM(ntables-1, 2)

; Load the colors for the requested table.
aa = ASSOC(lun, BYTARR(256),1) ;Read 256 long ints
r = aa[table_number*3]
g = aa[table_number*3+1]
b = aa[table_number*3+2]

; Interpolate if necessary.
if nc ne 256 then begin
p = (LINDGEN(nc) * 255) / (nc-1)
r = r[p]
g = g[p]
b = b[p]
endif

FREE_LUN,lun

self->SetProperty, RED_VALUES=r, GREEN_VALUES=g, BLUE_VALUES=b
end

Review on 12/31/2013 MM

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 »