Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
MoofEncoder/ICL8Encode.cp
/* |
File: ICL8Encode.cp |
Contains: |
Written by: Timothy Carroll |
Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
7/1/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
4/2/97 Timothy Carroll The icon and compiled sprite could be double |
disposed before. Spotlight noticed this one in the |
PICTEncode, but the same bug was in this code. Now |
I NULL out the variables after I dispose of them the |
first time. |
2/24/97 Timothy Carroll Now explicitly include main.h |
8/15/96 Timothy Carroll Initial Release |
*/ |
#include <Resources.h> |
#include "Main.h" |
#include "TGraphic.h" |
#include "ICL8Encode.h" |
OSStatus ICL8Encode (short inputFileResNum, short outputFileResNum) |
{ |
OSStatus theErr; |
UInt16 numIcons, loop; |
// we pass these to GetResInfo so that we can get the actual resource ID. |
SInt16 resID; |
ResType resType; |
Str255 resName; |
// Holds the last value on the resource chain since we change the top resource a lot |
SInt16 saveResNum; |
// Temporarily holds the resource so we can get information on it |
Handle icon = NULL; |
TGraphic *compiled = NULL; |
saveResNum = CurResFile(); |
UseResFile (inputFileResNum); |
// First thing is to copy the color table resource to the output. |
theErr = CopyResource (inputFileResNum, outputFileResNum,'clut', kAppColorTableResID); |
FAIL_OSERR (theErr, "\pFailed to copy the color table to the destination file") |
// get the color table |
gAppColorTable = GetCTable( kAppColorTableResID ); |
FAIL_NIL (gAppColorTable, "\pFailed to open the color table") |
// determine the number of icl8 resources |
numIcons = Count1Resources( 'icl8' ); |
// get each one, |
for( loop = 1; loop <= numIcons; loop++ ) |
{ |
// load the icon |
UseResFile (inputFileResNum); |
// we'll get the icon first so that we can get the information out of it. |
icon = Get1IndResource( 'icl8', loop ); |
theErr = ResError(); |
FAIL_NIL (icon, "\pFailed to load the icon") |
FAIL_OSERR (theErr, "\pFailed to load the icon") |
// determine its id and name |
GetResInfo( icon, &resID, &resType, resName ); |
theErr = ResError(); |
FAIL_OSERR( theErr, "\pFailed to get info on the resource") |
ReleaseResource (icon); |
icon = NULL; // So that the error code doesn't double dispose of it. |
// Okay, we know the icl8's resID, build the compiled graphic and write it to the output file. |
compiled = TGraphic::NewGraphic (resID); |
FAIL_NIL (compiled, "\pFailed to compile the TGraphic") |
UseResFile (outputFileResNum); |
compiled->WriteToGraphicResource(); |
compiled->WriteToPICTResource(); |
compiled->DisposeReference(); |
compiled = NULL; // so that the error code doesn't double dispose of it. |
} |
// restore the previous port and device |
goto cleanup; |
error: |
if (theErr == noErr) |
theErr = paramErr; |
if (icon) |
ReleaseResource (icon); |
if (compiled) |
compiled->DisposeReference(); |
cleanup: |
UseResFile (saveResNum); |
if (gAppColorTable != NULL) |
DisposeCTable (gAppColorTable); |
gAppColorTable = NULL; |
return theErr; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-10-14