INTRODUCTION TO MY PROBLEM I wish to create a resource containing an
array of color tables. I have succeeded, but after creating an array
by running the program from the source code, the computer sometimes
freezes. This shows up when I attempt to Quit the File. I feel that
this is the result of a failure to properly "tidy up" and I am looking
for help to find where I am failing. From experience with several
related programs, I am assuming that it is the creation of resources
that is responsible for upsetting the computer.
A GUIDE TO THE APPROACH TAKEN I require an array of color table resources
but I am only aware of how to create new palette reources through the
function FN NEWPALETTE. I therefore created my color tables via palette
tables. Because I am creating an array of tables, I believe that I should
reserve sufficient space for all of those before entering the LOCAL FN, which
explains the FN NEWHANDLE calls in the main program. Within the LOCAL FN,
I used FN NEWHANDLE to reserve space for the Color Tables because, without
this, I found that my color tables were healthy, but the palette tables were
garbled. Because INSIDE MACINTOSH warns against using DISPOSHANDLE to
remove resource handles, I have not yet used DISPOSHANDLE to remove those
Handles which I created with FN NEWHANDLE, which I would normally do.
I am very much hoping that some members of the list will have a glance
at those instructions which concern resources and guide me towards
a more computer-friendly program. I have included the LOCAL FN in its
entirety and, I hope, sufficient of the Main Program to show the
relevant parts of my code.
Yours sincerely
Vic Maslen
LOCAL
DIM thisColor.6
DIM paletteH&(3,120) 'handle to "pltt" entries
DIM cTableH&(3,120) 'handle to "clut" entries
REM Do not dispose of resource handles!
REM (3,120,25) First index,rotation angle:Second index,tilt angle:
REM Third index, palette element.
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
REM color palettes
REM and color tables for each angle of rotation and 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)
REM CHECK APPROPRIATENESS OF PALETTE TYPE AND TOLERANCE VALUE.!!!!!!!!!!!!!!!
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%
LONG IF Kelem% <> 10
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)
END IF
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 2 palType$ 'left,right or full
'...................................................
DIM rIndex&
XREF@ rIndex%(3,120,25)
DIM gIndex&
XREF@ gIndex%(3,120,25)
DIM bIndex&
XREF@ bIndex%(3,120,25)
'......................................................
REM Calculate an intensity index on a 5/9th power law scale for each signal.
REM First, reserve memory for these indices.
size& = 4 * 121* 26 * 2 'size for one degree tilt intervals
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