FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Read a CLUT table


This leads me to a question. Photoshop stores it's CLUTs as 768 bytes worth of RGB values in a data file. Every three bytes is the start of a new RGB record. Are CLUT resources stored the same way? If so, it should be rather easy. Just load the resource as a handle and step through it. Each byte is an unsigned char (value 0 - 255) so you could do something like this:

DIM myRGB.6(255)
DIM bytePos%, index%

bytePos% = 0 : index% = 0

WHILE index% < 256
  myRGB.0(index%) = PEEK([myCLUTHandle]+bytePos%)
  myRGB.2(index%) = PEEK([myCLUTHandle]+bytePos%+1)
  myRGB.4(index%) = PEEK([myCLUTHandle]+bytePos%+2)
  index% = index%+1
  bytePos% = bytePos%+3
WEND

That's totally untested while I'm sitting here at work so take it with a grain of salt, but it looks right :) My array & record definition may be off because I've been using C a lot lately and I think I might be confusing some aspects of the two. The idea is to have a 6 byte record and 256 of 'em.

If I totally missed your question then let me know, I'm rather distracted and would like to know if I'm asleep at the wheel :)

*Chris


In my globals :


DIM palette(255,2):' two dimensional array for the colour RGB

Somewhere in my application :

LOCAL FN load256CLUT:' load the colour clut for the 256 default colours
  DIM theGapper,masterR,masterG,masterB:' for the colour pallette
  Hndl&=FN GETRESOURCE(_"clut",256):' colour palette to use
  LONG IF Hndl&:' did we manage to load it in?
    OSErr=FN HLOCK(Hndl&):' lock down the handle first
    dataPtr&=[Hndl&]+8:' point to the first record of colour info
    FOR count=0 TO 255:' and away we go
      BLOCKMOVE dataPtr&,@theGapper,8:' copy out a full colour rec

      palette(count,0)=masterR:' copy out the data information
      palette(count,1)=masterG
      palette(count,2)=masterB
      dataPtr&=dataPtr&+8:' now skip to the nest record
    NEXT count
    OSErr=FN HUNLOCK(Hndl&):' unlock the handle, allow mem to free
    CALL RELEASERESOURCE(Hndl&):' and then clear out the memory used
  END IF
END FN
'

I think the variable "theGapper" is the tolerance part of the RGB record but since I didn't need it, I ignored it. If you want to read out individual values, you start at 8 bytes into the clut table, then take the index value you want (0-255) multiply it by 8, move the pointer there, copy out the data.

Mel Patrick