home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
gfx
/
edit
/
tsmorph
/
src
/
opalload.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-26
|
49KB
|
1,579 lines
// TSMorph - Amiga Morphing program
// Copyright (C) © 1993 Topicsave Limited
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// mpaddock@cix.compulink.co.uk
// Include precompiled headers if required
#ifndef TSMORPH_H
#include "TSMorph.h"
#endif
#include "JPEG_LS/jinclude.h"
extern UWORD FileFormat = 0; // Format of file being loaded
/* Loads an image (in various formats)
* pic : pointer to Picture structure
* filename: filename to load
* Returns : TRUE if loaded OK
*/
BOOL
MyLoadBrush (struct Picture *pic,UBYTE *filename) {
BOOL OpenILBM = FALSE; // Are we loading a (<24 plane) ILBM
char *e = NULL; // First
char *e1 = NULL; // and second part of error message
long hnum; // Help number
long err; // Error flag
BPTR fh; // File handle
UBYTE buffer[5]="\0\0\0\0"; // First 4 bytes of file for identification
// Try and open file and read 1st 4 bytes
if (fh = Open(filename,MODE_OLDFILE)) {
FRead(fh,buffer,4,1);
// check if a sort of IFF file
if (!strcmp(buffer,"LIST") ||
!strcmp(buffer,"CAT ") ||
!strcmp(buffer,"FORM")) {
FileFormat = FORMAT_IFF;
}
else {
// check if a JFIF JPEG
if ((buffer[0] == 0xFF) &&
(buffer[1] == 0xD8)) {
FileFormat = FORMAT_JPEG;
}
else {
// check if a GIF
if ((buffer[0] == 'G') &&
(buffer[1] == 'I') &&
(buffer[2] == 'F')) {
FileFormat = FORMAT_GIF;
}
else {
// check if a PPM
if ((buffer[0] == 'P') &&
((buffer[1] == '2') ||
(buffer[1] == '3') ||
(buffer[1] == '5') ||
(buffer[1] == '6'))) {
FileFormat = FORMAT_PPM;
}
else {
// Otherwise default to TARGA (the only other format we load)
FileFormat = FORMAT_TARGA;
}
}
}
}
Close(fh);
}
else {
// error file not found
FileFormat = 0;
e = "File does not exist '%s'";
hnum = HE_NoFile;
e1 = filename;
}
// If the file is and IFF and we only open ILBMs in some cases then perform some checks
if ((FileFormat == FORMAT_IFF) && ((OpenMode == OPEN_ILBM_IF_ILBM) || (OpenMode == OPEN_ILBM_IF_COLOURS))) {
if (pic->ilbm->ParseInfo.iff = AllocIFF()) {
err = queryilbm(pic->ilbm,filename);
if (!err) {
if (OpenMode == OPEN_ILBM_IF_COLOURS) {
// if we only open if screen colours then check depth
if (!(pic->ilbm->Bmhd.nPlanes > TSMorphWnd->WScreen->BitMap.Depth)) {
OpenILBM = TRUE;
}
}
else { // OpenMode == OPEN_ILBM_IF_ILBM
// if open if an ILBM then check < 24 bits
if (pic->ilbm->Bmhd.nPlanes < 24) {
OpenILBM = TRUE;
}
}
}
FreeIFF(pic->ilbm->ParseInfo.iff);
pic->ilbm->ParseInfo.iff = NULL;
}
else {
e = "Unable to AllocIFF";
hnum = HE_AllocIFF;
}
}
// If we always open ILBM or the above checks out OK then try and open
if (!EGS && (OpenILBM || ((OpenMode == OPEN_ILBM_ALWAYS) && !e))) {
if (pic->ilbm->ParseInfo.iff = AllocIFF()) {
// set up IFF stuff and load image
pic->ilbm->ParseInfo.propchks = props;
pic->ilbm->ParseInfo.collectchks = nowt;
pic->ilbm->ParseInfo.stopchks = stops;
if (loadbrush(pic->ilbm,filename)) {
closeifile(&(pic->ilbm->ParseInfo));
e = "Failure loading Image '%s'";
e1 = filename;
hnum = HE_LoadImage;
}
else {
closeifile(&(pic->ilbm->ParseInfo));
FreeIFF(pic->ilbm->ParseInfo.iff);
pic->ilbm->ParseInfo.iff = NULL;
return TRUE;
}
}
else {
e = "Unable to AllocIFF";
hnum = HE_AllocIFF;
}
}
else {
// otherwise try and load using another format
if (!e) {
return OpalLoad(pic,filename);
}
}
Error(e,"OK",e1,hnum);
return FALSE;
}
/* Loads an image (in various formats)
* pic : pointer to Picture structure
* filename: filename to load
* Returns : TRUE if loaded OK
*/
BOOL OpalLoad(struct Picture *pic,UBYTE *filename) {
char *e = NULL; // Error message main text
char *e1 = NULL; // sub text,
long Err; // OpalError
ULONG hnum; // Help on error
struct OpalScreen *OScrn; // OpalScreen
UBYTE *p[3]= {NULL,NULL,NULL}; // rbg planes
UBYTE r[256],g[256],b[256]; // rgb colors of screen (8 bit)
ULONG col[4]; // Table for get RGB32
UWORD i,j; // loop counters
UBYTE *plane; // EGB bit map byte pointer
UWORD color; // Colour
UBYTE *red,*green,*blue; // rgb pointers
UWORD maxcol; // Number of colors
UWORD xadd; // bytes to add to get to next line
decompress_info_ptr info; // Load JPEG stuff
BOOL ReMap = FALSE; // Have to remap ourselves
struct RastPort Rp; // Rast port for conversion
struct DCTVCvtHandle *handle=NULL; // DCTV conversion stuff
UWORD *DCTVcolors; // DCTV palette
OpenProgressWindow(); // Open the progress window
if (ProgressWnd) {
GT_SetGadgetAttrs(ProgressGadgets[GDX_Mess],ProgressWnd,NULL,
GTTX_Text,(ULONG)"Creating Colormap",
TAG_END);
HandleProgressIDCMP();
}
// Store and set up to 256 colours
maxcol = min((1 << TSMorphWnd->WScreen->BitMap.Depth),256);
if (GfxBase->lib_Version > 38) {
for (i=0; i < maxcol; ++i) {
GetRGB32(TSMorphWnd->WScreen->ViewPort.ColorMap,i,1,col);
r[i]=(col[0]>>24);
g[i]=(col[1]>>24);
b[i]=(col[2]>>24);
}
}
else {
for (i=0; i < maxcol; ++i) {
color = GetRGB4(TSMorphWnd->WScreen->ViewPort.ColorMap,i);
r[i]=((color&0x0f00)>>4)|((color&0x0f00)>>8);
g[i]=(color&0x00f0)|((color&0x00f0)>>4);
b[i]=((color&0x000f)<<4)|(color&0x000f);
}
}
// If we are not opening OPAL and the file is IFF
if ((OpenMode != OPEN_OPAL) &&
(FileFormat == FORMAT_IFF)) {
// try and load IFF
if (pic->ilbm->ParseInfo.iff = AllocIFF()) {
pic->ilbm->ParseInfo.propchks = props;
pic->ilbm->ParseInfo.collectchks = nowt;
pic->ilbm->ParseInfo.stopchks = stops;
if (ProgressWnd) {
GT_SetGadgetAttrs(ProgressGadgets[GDX_Mess],ProgressWnd,NULL,
GTTX_Text,(ULONG)"Loading ILBM",
TAG_END);
HandleProgressIDCMP();
}
if (loadbrush(pic->ilbm,filename)) {
closeifile(&(pic->ilbm->ParseInfo));
e = "Failure loading Image '%s'";
e1 = filename;
hnum = HE_LoadImage;
}
else {
closeifile(&(pic->ilbm->ParseInfo));
if (pic->ilbm->Bmhd.nPlanes == 24) {
// 24 bit image - free colours
freecolors(pic->ilbm);
if (ProgressWnd) {
GT_SetGadgetAttrs(ProgressGadgets[GDX_Mess],ProgressWnd,NULL,
GTTX_Text,(ULONG)"Converting 24 bit to Chunky",
TAG_END);
HandleProgressIDCMP();
}
// Allocate Chunky planes
if ((p[0] = AllocVec(((((pic->ilbm->Bmhd.w+15)>>4)<<4)*pic->ilbm->Bmhd.h),0)) &&
(p[1] = AllocVec(((((pic->ilbm->Bmhd.w+15)>>4)<<4)*pic->ilbm->Bmhd.h),0)) &&
(p[2] = AllocVec(((((pic->ilbm->Bmhd.w+15)>>4)<<4)*pic->ilbm->Bmhd.h),0))) {
// Convert to chunky RGB
if (InitArray(pic->ilbm->Bmhd.w) && PlanarToChunky(pic,pic->ilbm->Bmhd.w,pic->ilbm->Bmhd.h,p[0],p[1],p[2])) {
// Bytes to add to get to next row
xadd = (((pic->ilbm->Bmhd.w+15)>>4)<<4) - pic->ilbm->Bmhd.w;
red = p[0];
blue = p[2];
green = p[1];
if (EGS) {
// Convert to an EGS BitMap
if (pic->EGS_BitMap = E_AllocBitMap(pic->ilbm->Bmhd.w,pic->ilbm->Bmhd.h,24,E_PIXELMAP,E_EB_NOTSWAPABLE,NULL)) {
plane = pic->EGS_BitMap->Typekey.PixelMap.Planes.Dest;
if (ProgressWnd) {
GT_SetGadgetAttrs(ProgressGadgets[GDX_Mess],ProgressWnd,NULL,
GTTX_Text,(ULONG)"Converting to EGS",