2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 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
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "piepalette.h"
|
|
|
|
#include "tex.h"
|
|
|
|
#include "ivispatch.h"
|
|
|
|
#include "bitimage.h"
|
2006-09-23 11:38:12 -07:00
|
|
|
#include "lib/framework/frameresource.h"
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-25 10:21:13 -07:00
|
|
|
static BOOL LoadTextureFile(const char *FileName, iTexture *pSprite, int *texPageID)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
debug(LOG_TEXTURE, "LoadTextureFile: %s", FileName);
|
|
|
|
|
|
|
|
if (!resPresent("IMGPAGE", FileName)) {
|
|
|
|
debug(LOG_ERROR, "Texture file \"%s\" not preloaded.", FileName);
|
|
|
|
assert(FALSE);
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
*pSprite = *(iTexture*)resGetData("IMGPAGE", FileName);
|
|
|
|
debug(LOG_TEXTURE, "Load texture from resource cache: %s (%d, %d)",
|
|
|
|
FileName, pSprite->width, pSprite->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have already loaded this one? */
|
|
|
|
while (i < _TEX_INDEX) {
|
|
|
|
if (strcasecmp(FileName, _TEX_PAGE[i].name) == 0) {
|
|
|
|
*texPageID = _TEX_PAGE[i].id;
|
|
|
|
debug(LOG_TEXTURE, "LoadTextureFile: already loaded");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*texPageID = pie_AddTexPage(pSprite, FileName, 1, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-25 10:58:23 -07:00
|
|
|
IMAGEFILE *iV_LoadImageFile(const char *FileData, WZ_DECL_UNUSED const UDWORD FileSize)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-05-25 10:21:13 -07:00
|
|
|
const char *Ptr;
|
2007-06-28 10:47:08 -07:00
|
|
|
IMAGEHEADER *Header;
|
|
|
|
IMAGEFILE *ImageFile;
|
|
|
|
IMAGEDEF *ImageDef;
|
2007-05-25 10:21:13 -07:00
|
|
|
unsigned int i = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
Ptr = FileData;
|
|
|
|
|
|
|
|
Header = (IMAGEHEADER*)Ptr;
|
|
|
|
Ptr += sizeof(IMAGEHEADER);
|
|
|
|
|
2006-08-12 03:45:49 -07:00
|
|
|
endian_uword(&Header->Version);
|
|
|
|
endian_uword(&Header->NumImages);
|
|
|
|
endian_uword(&Header->BitDepth);
|
|
|
|
endian_uword(&Header->NumTPages);
|
|
|
|
|
2007-04-15 03:43:05 -07:00
|
|
|
ImageFile = (IMAGEFILE*)malloc(sizeof(IMAGEFILE));
|
2007-06-28 10:47:08 -07:00
|
|
|
if(ImageFile == NULL) {
|
2006-07-03 12:43:12 -07:00
|
|
|
debug( LOG_ERROR, "Out of memory" );
|
2007-06-28 10:47:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-15 03:43:05 -07:00
|
|
|
ImageFile->TexturePages = (iTexture*)malloc(sizeof(iTexture)*Header->NumTPages);
|
2007-06-28 10:47:08 -07:00
|
|
|
if(ImageFile->TexturePages == NULL) {
|
2006-07-03 12:43:12 -07:00
|
|
|
debug( LOG_ERROR, "Out of memory" );
|
2007-06-28 10:47:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-15 03:43:05 -07:00
|
|
|
ImageFile->ImageDefs = (IMAGEDEF*)malloc(sizeof(IMAGEDEF)*Header->NumImages);
|
2007-06-28 10:47:08 -07:00
|
|
|
if(ImageFile->ImageDefs == NULL) {
|
2006-07-03 12:43:12 -07:00
|
|
|
debug( LOG_ERROR, "Out of memory" );
|
2007-06-28 10:47:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageFile->Header = *Header;
|
|
|
|
|
|
|
|
// Load the texture pages.
|
|
|
|
for (i = 0; i < Header->NumTPages; i++) {
|
2007-03-16 09:20:16 -07:00
|
|
|
int tmp=0; /* Workaround for MacOS gcc 4.0.0 bug. */
|
2006-11-03 13:35:50 -08:00
|
|
|
LoadTextureFile((char*)Header->TPageFiles[i],
|
2006-08-12 03:45:49 -07:00
|
|
|
&ImageFile->TexturePages[i],
|
|
|
|
&tmp);
|
|
|
|
ImageFile->TPageIDs[i] = tmp;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageDef = (IMAGEDEF*)Ptr;
|
2006-08-12 03:45:49 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
for(i=0; i<Header->NumImages; i++) {
|
2006-08-12 03:45:49 -07:00
|
|
|
endian_uword(&ImageDef->TPageID);
|
|
|
|
endian_uword(&ImageDef->PalID);
|
|
|
|
endian_uword(&ImageDef->Tu);
|
|
|
|
endian_uword(&ImageDef->Tv);
|
|
|
|
endian_uword(&ImageDef->Width);
|
|
|
|
endian_uword(&ImageDef->Height);
|
|
|
|
endian_sword(&ImageDef->XOffset);
|
|
|
|
endian_sword(&ImageDef->YOffset);
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
ImageFile->ImageDefs[i] = *ImageDef;
|
|
|
|
if( (ImageDef->Width <= 0) || (ImageDef->Height <= 0) ) {
|
2006-07-03 12:43:12 -07:00
|
|
|
debug( LOG_ERROR, "Illegal image size" );
|
2007-06-28 10:47:08 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ImageDef++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ImageFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void iV_FreeImageFile(IMAGEFILE *ImageFile)
|
|
|
|
{
|
2007-04-15 03:43:05 -07:00
|
|
|
free(ImageFile->TexturePages);
|
|
|
|
free(ImageFile->ImageDefs);
|
|
|
|
free(ImageFile);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|