[futurebasic] Creating array of color table resources:some questions

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1999 : Group Archive : Group : All Groups

From: Vic Maslen Advanced Materials <maslen@...>
Date: Wed, 19 May 1999 10:29:34 +1000 (EST)
 My program for creating an array of about 500 color tables results in 
 occasional freezes when run on two computers, indicating bad programming.
 I am seeking help from anyone prepared to look critically at those few 
 commands in the program excerpt below which involve the creation of resources.
 The excerpt includes the local function which creates the tables and a few
 lines from the main program which are relevant to it.

 Four particular questions are as follows.
 1. Can the color tables be created more directly than via FN NEWPALETTE
 and CALL PALETTE2CTAB?
 2. Before entering the local function which creates them, I have, in the
 main program, reserved space for the arrays of palettes and color tables.
 Is that good programming practice?
 3. The line
 cTableH&(Irot%,Jtilt%) = FN NEWHANDLE _clear(240)
 was included in the local function when I found that my color tables 
 were healthy but the palette tables were not (overwritten, perhaps?).
 Is that good programming practice?
 4.Should I use FN DISPOSHANDLE to dispose of the handles palResH&,cTabResH&
 and cTableH&(Irot%,Jtilt%) whose purpose was to reserve memory for resources?

 I posted this query in a slightly different form a few days ago, but
 it failed to spark a response.  I am very keen to clean up the matter
 and I would greatly appreciate your help
 Vic Maslen 
     
'---------------------------------------------------------------------------
LOCAL
DIM thisColor.6
DIM paletteH&(3,120)                   'handle to "pltt" entries
DIM cTableH&(3,120)                    'handle to "clut" entries

DIM rIndex&
XREF@ rIndex%(3,120,25)                'colour index of red signal
DIM gIndex&
XREF@ gIndex%(3,120,25)
DIM bIndex&
XREF@ bIndex%(3,120,25)
LOCAL FN buildPalResFiles(palName$,beginElem%,finalElem%,rIndexH&,gIndexH&,bIndexH&,palResH&,cTabResH&)
  
  REM  This routine uses the stored colour index information to create 28 entry color palettes
  REM  and color tables for 4 angles of rotation and 121 angles of tilt.
  
  REM  Establish link between local handles and parameter list handles
  
  rIndex& = rIndexH&
  gIndex& = gIndexH&
  bIndex& = bIndexH&
  paletteH&(0,0) = palResH&            'reserve space for these handles
  cTableH&(0,0) = cTabResH&
  
  REM  IMPORTANT NOTE. ORDER OF PALETTE ELEMENTS IS W,B,1,2,3,...25,26.
  
  vRn% = SYSTEM(_aplVol)
  RFname$ = palName$ + ".rsrc"         'name of resource file
  CALL HCREATERESFILE(vRn%,0,RFname$)
  RFnum% = FN HOPENRESFILE(vRn%,0,RFname$,_fsRdWrPerm)
  LONG IF RFnum% = -1
    title$ = "color palette resource"
    msg$ = "Failed to open resource file"
    FN doWarn(1,title$,msg$,0)
  END IF
  
  FOR Irot% = 0 TO 3
    a$ = STR$(45 * (Irot% - 1))        'caption for palette entries
    IF Irot% > 0 THEN a$ = RIGHT$(a$,LEN(a$) - 1)'shed space
    paletteIdStart% = 200 * (1 + Irot%)
    FOR Jtilt% = 0 TO 120
      LONG IF Jtilt% < 42 OR Jtilt% > 48
        b$ = STR$(Jtilt% - 60)         'caption for palette entries
        IF Jtilt% >=  60 THEN b$ = RIGHT$(b$,LEN(b$) - 1)'shed space
        paletteName$ = a$ + "," + b$
        paletteH&(Irot%,Jtilt%) = FN NEWPALETTE(_maxColour + 1,0,_pmTolerant,4000)
        cTableH&(Irot%,Jtilt%) = FN NEWHANDLE _clear(240)
        paletteId% = paletteIdStart% + Jtilt%
        thisColor.red% = 65535:thisColor.green% = 65535:thisColor.blue% = 65535'white
        CALL SETENTRYCOLOR(paletteH&(Irot%,Jtilt%),0,#@thisColor)
        CALL SETENTRYUSAGE(paletteH&(Irot%,Jtilt%),0,_pmTolerant,0)'exact color
        thisColor.red% = 0:thisColor.green% = 0:thisColor.blue% = 0'black
        CALL SETENTRYCOLOR(paletteH&(Irot%,Jtilt%),1,#@thisColor)
        CALL SETENTRYUSAGE(paletteH&(Irot%,Jtilt%),1,_pmTolerant,0)'exact color
        FOR Kelem% = beginElem% TO finalElem%
          peIndex% = Kelem% - 1
          thisColor.red% = 257 * rIndex%(Irot%,Jtilt%,peIndex%)
          thisColor.green% = 257 * gIndex%(Irot%,Jtilt%,peIndex%)
          thisColor.blue% = 257 * bIndex%(Irot%,Jtilt%,peIndex%)
          CALL SETENTRYCOLOR(paletteH&(Irot%,Jtilt%),Kelem% + 1,#@thisColor)
        NEXT Kelem%
        CALL ADDRESOURCE(paletteH&(Irot%,Jtilt%),_"pltt",paletteId%,paletteName$)
        CALL ADDRESOURCE(cTableH&(Irot%,Jtilt%),_"clut",paletteId%,paletteName$)'empty colour tables
        CALL PALETTE2CTAB(paletteH&(Irot%,Jtilt%),cTableH&(Irot%,Jtilt%))'transfer
      END IF
    NEXT Jtilt%
  NEXT Irot%
  CALL CLOSERESFILE(RFnum%)
END FN

'-------------------------------Main Program
DIM 6 palName$                         'name of palette
'...................................................
DIM rIndex&
XREF@ rIndex%(3,120,25)
DIM gIndex&
XREF@ gIndex%(3,120,25)
DIM bIndex&
XREF@ bIndex%(3,120,25)

'......................................................

REM   Reserve memory for these index arrays

size& = 4 * 121 * 26 * 2               
rIndex& = FN allocateHandle(size&)
gIndex& = FN allocateHandle(size&)
bIndex& = FN allocateHandle(size&)
'.................................................................

REM  Build color palette resources

palResH& = FN NEWHANDLE _clear(4 * 121 * 480)'room for 30 entries
cTabResH& = FN NEWHANDLE _clear(4 * 121 * 240)'room for 30 entries

FN buildPalResFiles(palName$,beginElem%,finalElem%,rIndex&,gIndex&,bIndex&,palResH&,cTabResH&)

REM  Dispose of handles no longer required

FN disposeHandle(rIndex&)
FN disposeHandle(gIndex&)
FN disposeHandle(bIndex&)

END