Re: Saving Color Tables [message #40863] |
Tue, 14 September 2004 13:09  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Rick Towler writes:
> On a similar note, how can you create a brand new color table file? I
> tried the obvious, setting the FILE keyword to a new file name and
> selecting an ITAB of 0(or 1 or 10 or 100) but that fails.
>
> Not a pressing issue, and the workaround was trivial (I already had a
> function that created the table so I simply create an instance of
> IDLgrPalette when the application starts) but I did find this annoying.
> Also, I am sure I could copy the built in color table file and then
> modify that but it really seems like I should be able to create a shiny
> new color table file... Is it possible?
A standard color table file has a byte that tells you how many
color tables are in the file, and then three 256-byte vectors
with the red, green, and blue values. These are replicated by
as many color tables as there are in the file. The file is
stored in binary format. Should be fairly easy to duplicate. :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
|
|
|
|
|
|
Re: Saving Color Tables [message #41044 is a reply to message #40863] |
Wed, 15 September 2004 13:57  |
kklare
Messages: 7 Registered: April 2004
|
Junior Member |
|
|
In 1995 and 1996 I added a number of tables ~62. Some are stolen from
defunct Macintosh Spygrlass Transform (an uncredited rip off of public
domain NCSA Image), the NIH Image program with correction for 13
converted into 10 or vv, and the old MAC-OS colors. One is 10 cycles
of colors with different shading and is good for contours. The routine
to read these was last changed 2/2000 and given below and is not
checked to be current. Replace JINIT and EXTR_FILE_NAME by your own
path parser. BTW for true color, I did a 26 cycles of colors but have
never used it.
;+
;NAME: CT_READ
;PURPOSE: read Macintosh color tables for use in IDL
; reads 970 byte Spyglass/NIH Image
; and 2056 byte ResEdit resource saved using HexEdit
;CATEGORY: Colors
;CALL:
;INPUT:
; file name of file to read, default is a Pickfile
;OUTPUTS:
; R, G, B 256-byte lists of color components
;SIDE EFFECTS:
; opens file on unit 1
; overwrites current window
; changes color table
; may modify system colors
;HISTORY:
; KAK 960913 New
;-
PRO CT_READ, file, r, g, b
IF NOT KEYWORD_SET(path) THEN path = XPICKFILE(/READ, /MUST_EXIST)
IF NOT KEYWORD_SET(path) THEN RETURN
JINIT
file = EXTR_FILE_NAME(path)
PRINT, 'For color table name "'+file+'"'
ON_IOERROR, err
CLOSE, 1
OPENR, 1, path
stat = FSTAT(1)
CASE stat.size OF
970: BEGIN
x = BYTARR(202) & READU, 1, x
x = BYTARR(3,256) & READU, 1, x
ENDCASE
2056: BEGIN
x = BYTARR(8) & READU, 1, x
x = INTARR(4,256) & READU, 1, x
x = BYTE(ISHFT(x(1:3,*),-8))
ENDCASE
ELSE: BEGIN
MESSAGE, /INFO, 'Unknown file size '+STRTRIM(stat.size)
RETURN
ENDCASE
ENDCASE
CLOSE, 1
r = REFORM(x(0,*))
g = REFORM(x(1,*))
b = REFORM(x(2,*))
TVLCT, r, g, b
ERASE
PLOT, r, YRANGE=[0,255], TITLE=file & OPLOT, g & OPLOT, b
TV, BINDGEN(256)#REPLICATE(1b,20)
PRINT, ' 0:', r(0), g(0), b(0)
PRINT, '255:', r(255), g(255), b(255)
PRINT, 'Enter id (42-255) of local file=colors1.tlb'
PRINT, 'To cancel enter 0.'
PRINT, 'To assign a new number enter 255.'
id = 0B
READ, id
IF id LT 42B THEN PRINT, 'Cannot change standard colors'$
ELSE BEGIN
MODIFYCT, id, file, r, g, b, FILE='colors1.tbl'
PRINT, id, ' entry modified'
ENDELSE
RETURN
err:
HELP, /STR, stat
MESSAGE, /INFO, !err_string
CLOSE, 1
RETURN
END
|
|
|