2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// lbmlib.c
|
|
|
|
|
|
|
|
// by Hydra - hydra@hydras-world.com
|
|
|
|
//
|
|
|
|
// This module is based on the image module, but just more stripped down.
|
|
|
|
// it still currently supports TGA file loading, even though this is not
|
|
|
|
// required for HalfLife support (unless MD2 files use TGA's)
|
|
|
|
//
|
|
|
|
// use the #defines in imagehl.h to enable/disable the various formats.
|
|
|
|
//
|
|
|
|
// HLW = Half-Life-WAD, I don't know if the actual in data in the WAD files
|
|
|
|
// has it's own name, so I'm just calling the individal textures .HLW files :)
|
|
|
|
//
|
|
|
|
// Thanks to the guys that made Wally for releasing an example WAD loader.
|
|
|
|
// without it this would not have been possible.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include "imagehl.h"
|
|
|
|
#include "lbmlib.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define Sys_Printf g_FuncTable.m_pfnSysPrintf
|
|
|
|
#define Sys_FPrintf g_FuncTable.m_pfnSysFPrintf
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_IDSP
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
IDSP IMAGE (.spr files)
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Some code copied straight from the Q1 source, also used the HalfLife SDK as
|
|
|
|
a reference.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
typedef enum {ST_SYNC = 0, ST_RAND } synctype_t;
|
|
|
|
typedef enum { SPR_SINGLE = 0, SPR_GROUP } spriteframetype_t;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
typedef struct dspriteheader_s {
|
2012-03-17 20:01:54 +00:00
|
|
|
int ident;
|
|
|
|
int version;
|
2007-11-04 03:51:54 +00:00
|
|
|
} dspriteheader_t;
|
|
|
|
|
|
|
|
// Quake1
|
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
int type;
|
|
|
|
float boundingradius;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int numframes;
|
|
|
|
float beamlength;
|
|
|
|
synctype_t synctype;
|
2007-11-04 03:51:54 +00:00
|
|
|
} dspritev1_t;
|
|
|
|
|
|
|
|
// Halflife
|
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
int type;
|
|
|
|
int texFormat;
|
|
|
|
float boundingradius;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int numframes;
|
|
|
|
float beamlength;
|
|
|
|
synctype_t synctype;
|
2007-11-04 03:51:54 +00:00
|
|
|
} dspritev2_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
int origin[2];
|
|
|
|
int width;
|
|
|
|
int height;
|
2007-11-04 03:51:54 +00:00
|
|
|
} dspriteframe_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2012-03-17 20:01:54 +00:00
|
|
|
short type;
|
2007-11-04 03:51:54 +00:00
|
|
|
} dspriteframetype_t;
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
typedef struct {
|
|
|
|
byte rgb[256][3];
|
|
|
|
} dpalette_t;
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define IDSPRITEHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' )
|
|
|
|
// little-endian "IDSP"
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
LoadIDSP
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void LoadIDSP( const char *name, byte ** pic, int *width, int *height ){
|
|
|
|
byte *buffer;
|
|
|
|
byte *buf_p;
|
|
|
|
unsigned int length;
|
|
|
|
int columns, rows, numPixels;
|
|
|
|
byte *pixbuf;
|
|
|
|
|
|
|
|
int row, column;
|
|
|
|
byte *bmpRGBA;
|
|
|
|
byte *palette;
|
2007-11-04 03:51:54 +00:00
|
|
|
unsigned char red, green, blue, alphabyte;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dspriteheader_t *header;
|
|
|
|
dspritev1_t *pinv1;
|
|
|
|
dspritev2_t *pinv2;
|
|
|
|
dspriteframetype_t *pframetype;
|
|
|
|
int version;
|
|
|
|
int numframes;
|
|
|
|
dspriteframe_t *spriteframe;
|
|
|
|
|
|
|
|
*pic = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// load the file
|
|
|
|
//
|
|
|
|
length = vfsLoadFile( (char *) name, (void **) &buffer, 0 );
|
|
|
|
if ( length == (unsigned int) -1 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
header = (dspriteheader_t *)buffer;
|
|
|
|
|
|
|
|
if ( header->ident != IDSPRITEHEADER ) {
|
|
|
|
Sys_Printf( "WARNING: %s has wrong header\n" );
|
|
|
|
vfsFreeFile( buffer );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
version = header->version;
|
|
|
|
if ( version != 1 && version != 2 ) {
|
|
|
|
Sys_Printf( "WARNING: %s has wrong version number "
|
|
|
|
"(%i should be 1 or 2)\n", name, version );
|
|
|
|
vfsFreeFile( buffer );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialise variables depending on the sprite version.
|
|
|
|
switch ( version )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
pinv1 = (dspritev1_t *)( header + 1 );
|
|
|
|
numframes = pinv1->numframes;
|
|
|
|
columns = pinv1->width;
|
|
|
|
rows = pinv1->height;
|
|
|
|
pframetype = (dspriteframetype_t *)( pinv1 + 1 );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pinv2 = (dspritev2_t *)( header + 1 );
|
|
|
|
numframes = pinv2->numframes;
|
|
|
|
columns = pinv2->width;
|
|
|
|
rows = pinv2->height;
|
|
|
|
pframetype = (dspriteframetype_t *)( pinv2 + 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( numframes > 1 ) {
|
|
|
|
Sys_Printf( "WARNING: %s has multiple frames, only the first frame will be used.\n", name );
|
|
|
|
}
|
|
|
|
|
|
|
|
// palette = buffer+mipdatasize+2;
|
|
|
|
// buf_p = buffer+lpMip->offsets[0];
|
|
|
|
|
|
|
|
numPixels = columns * rows;
|
|
|
|
|
|
|
|
if ( width ) {
|
|
|
|
*width = columns;
|
|
|
|
}
|
|
|
|
if ( height ) {
|
|
|
|
*height = rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
bmpRGBA = reinterpret_cast < unsigned char *>( g_malloc( numPixels * 4 ) );
|
|
|
|
*pic = bmpRGBA;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-03-17 22:09:08 +00:00
|
|
|
spriteframetype_t frametype = spriteframetype_t( LittleLong( pframetype->type ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( frametype == SPR_SINGLE ) {
|
|
|
|
Sys_Printf( "Single Frame\n" );
|
|
|
|
}
|
|
|
|
else if ( frametype == SPR_GROUP ) {
|
|
|
|
Sys_Printf( "Group of Frames\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sys_Printf( "Bleh!\n" ); // <-- we always get this, wtf!
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
palette = (byte *)( pframetype + 1 );
|
|
|
|
spriteframe = (dspriteframe_t *)( palette + ( 256 * 3 ) + 4 ); // what are those 4 extra bytes ? what's missing ?
|
|
|
|
buf_p = (byte *)( spriteframe + 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int temp;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
temp = buf_p - buffer;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( row = 0; row < rows; row++ )
|
|
|
|
{
|
|
|
|
pixbuf = bmpRGBA + row * columns * 4;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( column = 0; column < columns; column++ )
|
|
|
|
{
|
|
|
|
int palIndex;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
palIndex = *buf_p++;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
red = *( palette + ( palIndex * 3 ) );
|
|
|
|
green = *( palette + ( palIndex * 3 ) + 1 );
|
|
|
|
blue = *( palette + ( palIndex * 3 ) + 2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// HalfLife engine makes pixels that are BLUE transparent. (RGB = 0x0000FF)
|
|
|
|
// So show them that way in the editor.
|
|
|
|
if ( blue == 0xff && red == 0x00 && green == 0x00 ) {
|
|
|
|
alphabyte = 0xff; //FIXME: backwards? (so sprite models to render correctly)
|
|
|
|
blue = 0x00; // don't set the resulting pixel to blue
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alphabyte = 0x00; //FIXME: backwards? (so sprite models to render correctly)
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*pixbuf++ = red;
|
|
|
|
*pixbuf++ = green;
|
|
|
|
*pixbuf++ = blue;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*pixbuf++ = alphabyte;
|
|
|
|
}
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vfsFreeFile( buffer );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_HLW
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
HLW IMAGE
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
HalfLife WAD files contain files that look like this:
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Mip section
|
|
|
|
First mip
|
|
|
|
Mip header
|
|
|
|
First mip (width * height)
|
|
|
|
Second mip (width * height / 4)
|
|
|
|
Third mip (width * height / 16)
|
|
|
|
Fourth mip (width * height / 64)
|
|
|
|
Palette size (WORD)
|
|
|
|
Palette (Palette size * 3)
|
|
|
|
Padding (WORD)
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define GET_MIP_DATA_SIZE( WIDTH, HEIGHT ) ( sizeof( WAD3_MIP ) + ( WIDTH * HEIGHT ) + ( WIDTH * HEIGHT / 4 ) + ( WIDTH * HEIGHT / 16 ) + ( WIDTH * HEIGHT / 64 ) )
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
char name[16];
|
|
|
|
DWORD width, height;
|
|
|
|
DWORD offsets[4]; // four mip maps stored
|
2007-11-04 03:51:54 +00:00
|
|
|
} WAD3_MIP, *LPWAD3_MIP;
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=========================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
HLW LOADING
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Hydra: this code isn't bullet proof and probably won't
|
|
|
|
like corrupt WAD files, but it works for now.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TODO: make it more robust.
|
|
|
|
=========================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
LoadHLW
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void LoadHLW( const char *name, byte ** pic, int *width, int *height ){
|
|
|
|
byte *buffer;
|
|
|
|
byte *buf_p;
|
|
|
|
unsigned int length;
|
|
|
|
unsigned long mipdatasize;
|
|
|
|
int columns, rows, numPixels;
|
|
|
|
byte *pixbuf;
|
|
|
|
int row, column;
|
|
|
|
byte *bmpRGBA;
|
|
|
|
byte *palette;
|
|
|
|
LPWAD3_MIP lpMip;
|
2007-11-04 03:51:54 +00:00
|
|
|
unsigned char red, green, blue, alphabyte;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*pic = NULL;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
//
|
|
|
|
// load the file
|
|
|
|
//
|
|
|
|
length = vfsLoadFile( (char *) name, (void **) &buffer, 0 );
|
|
|
|
if ( length == (unsigned int) -1 ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
lpMip = (LPWAD3_MIP)buffer;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
mipdatasize = GET_MIP_DATA_SIZE( lpMip->width,lpMip->height );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
palette = buffer + mipdatasize + 2;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
buf_p = buffer + lpMip->offsets[0];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
columns = lpMip->width;
|
|
|
|
rows = lpMip->height;
|
|
|
|
numPixels = columns * rows;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( width ) {
|
|
|
|
*width = columns;
|
|
|
|
}
|
|
|
|
if ( height ) {
|
|
|
|
*height = rows;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
bmpRGBA = reinterpret_cast < unsigned char *>( g_malloc( numPixels * 4 ) );
|
|
|
|
*pic = bmpRGBA;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( row = 0; row < rows; row++ )
|
|
|
|
{
|
|
|
|
pixbuf = bmpRGBA + row * columns * 4;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( column = 0; column < columns; column++ )
|
|
|
|
{
|
|
|
|
int palIndex;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
palIndex = *buf_p++;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
red = *( palette + ( palIndex * 3 ) );
|
|
|
|
green = *( palette + ( palIndex * 3 ) + 1 );
|
|
|
|
blue = *( palette + ( palIndex * 3 ) + 2 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// HalfLife engine makes pixels that are BLUE transparent.
|
|
|
|
// So show them that way in the editor.
|
|
|
|
if ( blue == 0xff && red == 0x00 && green == 0x00 ) {
|
|
|
|
alphabyte = 0x00;
|
|
|
|
blue = 0x00; // don't set the resulting pixel to blue
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alphabyte = 0xff;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*pixbuf++ = red;
|
|
|
|
*pixbuf++ = green;
|
|
|
|
*pixbuf++ = blue;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*pixbuf++ = alphabyte;
|
|
|
|
}
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vfsFreeFile( buffer );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_MIP
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
MIP IMAGE
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Quake WAD files contain miptex files that look like this:
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Mip section
|
|
|
|
First mip
|
|
|
|
Mip header
|
|
|
|
First mip (width * height)
|
|
|
|
Second mip (width * height / 4)
|
|
|
|
Third mip (width * height / 16)
|
|
|
|
Fourth mip (width * height / 64)
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
============================================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=========================================================
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
MIP LOADING
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LordHavoc: this code is based on the HLW code above.
|
|
|
|
=========================================================
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const byte quakepalette[768] =
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
0x00,0x00,0x00, 0x0f,0x0f,0x0f, 0x1f,0x1f,0x1f, 0x2f,0x2f,0x2f,
|
|
|
|
0x3f,0x3f,0x3f, 0x4b,0x4b,0x4b, 0x5b,0x5b,0x5b, 0x6b,0x6b,0x6b,
|
|
|
|
0x7b,0x7b,0x7b, 0x8b,0x8b,0x8b, 0x9b,0x9b,0x9b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|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
LoadMIP
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void LoadMIP( const char *name, byte ** pic, int *width, int *height ){
|
|
|
|
byte *buffer;
|
|
|
|
byte *buf_p;
|
|
|
|
unsigned int length, palettelength;
|
|
|
|
unsigned long mipdatasize;
|
|
|
|
int columns, rows, numPixels;
|
|
|
|
byte *pixbuf;
|
|
|
|
int i;
|
|
|
|
byte *bmpRGBA;
|
|
|
|
byte *loadedpalette;
|
|
|
|
const byte *palette;
|
|
|
|
LPWAD3_MIP lpMip;
|
|
|
|
|
|
|
|
*pic = NULL;
|
|
|
|
loadedpalette = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// load the file
|
|
|
|
//
|
|
|
|
length = vfsLoadFile( (char *) name, (void **) &buffer, 0 );
|
|
|
|
if ( length == (unsigned int) -1 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpMip = (LPWAD3_MIP)buffer;
|
|
|
|
|
|
|
|
mipdatasize = GET_MIP_DATA_SIZE( lpMip->width,lpMip->height );
|
|
|
|
|
|
|
|
palettelength = vfsLoadFile( "textures/palette.lmp", (void **) &loadedpalette, 0 );
|
|
|
|
if ( palettelength == 768 ) {
|
|
|
|
palette = loadedpalette;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loadedpalette = NULL;
|
|
|
|
palette = quakepalette;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf_p = buffer + lpMip->offsets[0];
|
|
|
|
|
|
|
|
columns = lpMip->width;
|
|
|
|
rows = lpMip->height;
|
|
|
|
numPixels = columns * rows;
|
|
|
|
|
|
|
|
if ( width ) {
|
|
|
|
*width = columns;
|
|
|
|
}
|
|
|
|
if ( height ) {
|
|
|
|
*height = rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Sys_Printf("lpMip->width = %i, lpMip->height = %i, lpMip->offsets[0] = %i, lpMip->offsets[1] = %i, lpMip->offsets[2] = %i, lpMip->offsets[3] = %i, numPixels = %i\n", lpMip->width, lpMip->height, lpMip->offsets[0], lpMip->offsets[1], lpMip->offsets[2], lpMip->offsets[3], numPixels);
|
|
|
|
//for (i = 0; i < sizeof(*lpMip); i++)
|
|
|
|
// Sys_Printf("%02x", (int) ((unsigned char *)lpMip)[i]);
|
|
|
|
|
|
|
|
bmpRGBA = reinterpret_cast < unsigned char *>( g_malloc( numPixels * 4 ) );
|
|
|
|
*pic = bmpRGBA;
|
|
|
|
pixbuf = bmpRGBA;
|
|
|
|
|
|
|
|
for ( i = 0; i < numPixels; i++ )
|
|
|
|
{
|
|
|
|
int palIndex = *buf_p++;
|
|
|
|
*pixbuf++ = palette[palIndex * 3];
|
|
|
|
*pixbuf++ = palette[palIndex * 3 + 1];
|
|
|
|
*pixbuf++ = palette[palIndex * 3 + 2];
|
|
|
|
*pixbuf++ = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfsFreeFile( buffer );
|
|
|
|
if ( loadedpalette != NULL ) {
|
|
|
|
vfsFreeFile( loadedpalette );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
LoadImage
|
|
|
|
|
|
|
|
Loads any of the supported image types into a cannonical
|
|
|
|
32 bit format.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void LoadImage( const char *name, byte ** pic, int *width, int *height ){
|
|
|
|
int len;
|
|
|
|
*pic = NULL;
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
len = strlen( name );
|
|
|
|
if ( len < 5 ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#ifdef USE_HLW
|
2013-05-03 06:57:29 +00:00
|
|
|
if ( *pic == NULL && !g_ascii_strcasecmp( name + len - 4, ".hlw" ) ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHLW( name, pic, width, height );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_MIP
|
2013-05-03 06:57:29 +00:00
|
|
|
if ( *pic == NULL && !g_ascii_strcasecmp( name + len - 4, ".mip" ) ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadMIP( name, pic, width, height );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_IDSP
|
2013-05-03 06:57:29 +00:00
|
|
|
if ( *pic == NULL && !g_ascii_strcasecmp( name + len - 4, ".spr" ) ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadIDSP( name, pic, width, height );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
}
|