home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
274.lha
/
SimGen_Src
/
MYIFF2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-26
|
3KB
|
143 lines
/*
** File: MYIFF2.c
**
** Routines to load and "track" IFF images.
*/
#include <iff/intuall.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <iff/ilbm.h>
#include <iff/readpict.h>
#include <iff/remalloc.h>
#include <functions.h>
#include "picture.h"
/*--------------------------------------------------------------*/
extern char *PreFix;
extern char *IFFPMessages[];
Picture LastPicture;
UBYTE *MyAllocMem (size, flags)
ULONG size;
ULONG flags;
{
return (AllocMem (size, flags));
}
ClearMem (pntr, size)
UBYTE *pntr;
ULONG size;
{
register UBYTE *rpntr = pntr;
register ULONG rsize = size;
while (size) {
*pntr++ = NULL;
size--;
}
}
Picture *CreatePic (filename, width, height)
char *filename;
int width;
int height;
{
ILBMFrame ilbmFrame;
Picture *newpic = NULL;
NewImage ni;
struct FileHandle *file;
IFFP iffp;
char errormsg[250];
char tempname[250];
ClearMem (&ni, sizeof (ni));
ClearMem (&ilbmFrame, sizeof (ilbmFrame));
if (!( newpic = (Picture *)MyAllocMem (sizeof (*newpic), MEMF_CLEAR))) {
SYSMESS ("Couldn't allocate picture");
return (NULL);
}
InitRastPort (&newpic->RastPort);
newpic->RastPort.BitMap = &newpic->BitMap;
strcpy (tempname, PreFix);
strcat (tempname, filename);
if (!( file = Open (tempname, MODE_OLDFILE))) {
DeletePic (newpic);
SYSMESS ("Couldn't open picture file");
return (NULL);
}
ilbmFrame.pic = newpic;
ilbmFrame.ni = ∋
ilbmFrame.allocmem = MyAllocMem;
ni.Width = width;
ni.Height = height;
ni.Flags = NI_GETCOLORS |
NI_CREATEPIC |
NI_CLIPIMAGE |
NI_USEBITMAP;
iffp = myReadPicture(file, &ilbmFrame);
Close(file);
if (iffp != IFF_DONE) {
DeletePic (newpic);
strcpy (errormsg, "Couldn't read file ");
strcat (errormsg, filename);
strcat (errormsg, ". ");
strcat (errormsg, IFFPMessages[-iffp]);
SYSMESS (errormsg);
return (NULL);
}
/*
** Changed for SIMGEN
PicHotX(newpic) = ilbmFrame.bmHdr.x;
PicHotY(newpic) = ilbmFrame.bmHdr.y;
**
*/
PicHotX(newpic) = ni.Left;
PicHotY(newpic) = ni.Top;
PicWidth(newpic) = ilbmFrame.bmHdr.w;
PicHeight(newpic) = ilbmFrame.bmHdr.h;
PicDepth(newpic) = ilbmFrame.bmHdr.nPlanes;
PicTColor(newpic) = ilbmFrame.bmHdr.transparentColor;
return (newpic);
}
DeletePic (pic)
Picture *pic;
{
int i;
CycleRange *cr;
CycleRange *nextcr;
if (pic) {
for (i=0; i<pic->BitMap.Depth; i++) {
if (pic->BitMap.Planes[i]) {
FreeMem (pic->BitMap.Planes[i],
pic->BitMap.BytesPerRow *
pic->BitMap.Rows);
}
}
cr = pic->CycleRanges;
while (cr) {
nextcr = (CycleRange *)cr->NextRange;
FreeMem (cr, sizeof (*cr));
cr = nextcr;
}
FreeMem (pic, sizeof (*pic));
}
}