This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/launch/imagelib/img_wad.c

585 lines
14 KiB
C
Raw Normal View History

2008-08-06 22:00:00 +02:00
//=======================================================================
// Copyright XashXT Group 2007 <20>
// img_mip.c - hl1 q1 image mips
//=======================================================================
2008-10-22 22:00:00 +02:00
#include "imagelib.h"
2010-09-10 22:00:00 +02:00
#include "wadfile.h"
#include "studio.h"
#include "sprite.h"
#include "qfont.h"
2008-08-06 22:00:00 +02:00
/*
============
Image_LoadPAL
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadPAL( const char *name, const byte *buffer, size_t filesize )
2008-08-06 22:00:00 +02:00
{
2008-10-19 22:00:00 +02:00
int rendermode = LUMP_NORMAL;
2008-08-06 22:00:00 +02:00
if( filesize != 768 )
{
2008-08-08 22:00:00 +02:00
MsgDev( D_ERROR, "Image_LoadPAL: (%s) have invalid size (%d should be %d)\n", name, filesize, 768 );
2008-08-06 22:00:00 +02:00
return false;
}
2008-10-19 22:00:00 +02:00
if( name[0] == '#' )
{
// using palette name as rendermode
if( com.stristr( name, "normal" ))
rendermode = LUMP_NORMAL;
else if( com.stristr( name, "transparent" ))
rendermode = LUMP_TRANSPARENT;
else if( com.stristr( name, "decal" ))
rendermode = LUMP_DECAL;
else if( com.stristr( name, "qfont" ))
rendermode = LUMP_QFONT;
2010-11-06 22:00:00 +01:00
else if( com.stristr( name, "valve" ))
buffer = NULL; // force to get HL palette
2008-10-19 22:00:00 +02:00
}
// NOTE: image.d_currentpal not cleared with Image_Reset()
// and stay valid any time before new call of Image_SetPalette
Image_GetPaletteLMP( buffer, rendermode );
2008-08-07 22:00:00 +02:00
Image_CopyPalette32bit();
2008-10-19 22:00:00 +02:00
image.rgba = NULL; // only palette, not real image
image.size = 1024; // expanded palette
2009-07-22 22:00:00 +02:00
image.num_mips = image.depth = 0;
2008-10-19 22:00:00 +02:00
image.width = image.height = 0;
2008-08-06 22:00:00 +02:00
return true;
}
2009-10-18 22:00:00 +02:00
/*
============
Image_LoadFNT
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadFNT( const char *name, const byte *buffer, size_t filesize )
2009-10-18 22:00:00 +02:00
{
qfont_t font;
const byte *pal, *fin;
size_t size;
2010-11-21 22:00:00 +01:00
int numcolors;
2009-10-18 22:00:00 +02:00
if( image.hint == IL_HINT_Q1 )
return false; // Quake1 doesn't have qfonts
if( filesize < sizeof( font ))
return false;
Mem_Copy( &font, buffer, sizeof( font ));
// last sixty four bytes - what the hell ????
2010-07-08 22:00:00 +02:00
size = sizeof( qfont_t ) - 4 + ( 128 * font.width * QCHAR_WIDTH ) + sizeof( short ) + 768 + 64;
2009-10-18 22:00:00 +02:00
if( size != filesize )
{
// oldstyle font: "conchars" or "creditsfont"
image.width = 256; // hardcoded
image.height = font.height;
}
else
{
// Half-Life 1.1.0.0 font style (qfont_t)
image.width = font.width * QCHAR_WIDTH;
image.height = font.height;
}
if(!Image_LumpValidSize( name )) return false;
fin = buffer + sizeof( font ) - 4;
2010-07-08 22:00:00 +02:00
pal = fin + (image.width * image.height);
2010-11-21 22:00:00 +01:00
numcolors = *(short *)pal, pal += sizeof( short );
2009-10-18 22:00:00 +02:00
image.flags |= IMAGE_HAS_ALPHA; // fonts always have transparency
if( numcolors == 768 )
{
// newstyle font
Image_GetPaletteLMP( pal, LUMP_QFONT );
}
else if( numcolors == 256 )
{
// oldstyle font
Image_GetPaletteLMP( pal, LUMP_TRANSPARENT );
}
else
{
if( image.hint == IL_HINT_NO )
MsgDev( D_ERROR, "Image_LoadFNT: (%s) have invalid palette size %d\n", name, numcolors );
return false;
}
2010-07-08 22:00:00 +02:00
image.depth = 1;
image.type = PF_INDEXED_32; // 32-bit palette
2009-10-18 22:00:00 +02:00
return FS_AddMipmapToPack( fin, image.width, image.height );
}
2008-10-19 22:00:00 +02:00
/*
============
Image_LoadMDL
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadMDL( const char *name, const byte *buffer, size_t filesize )
2008-10-19 22:00:00 +02:00
{
byte *fin;
size_t pixels;
2010-07-08 22:00:00 +02:00
mstudiotexture_t *pin;
2009-08-25 22:00:00 +02:00
int i, flags;
2008-10-19 22:00:00 +02:00
2010-07-08 22:00:00 +02:00
pin = (mstudiotexture_t *)buffer;
2010-11-21 22:00:00 +01:00
flags = pin->flags;
2008-10-19 22:00:00 +02:00
2010-11-21 22:00:00 +01:00
image.width = pin->width;
image.height = pin->height;
2008-10-19 22:00:00 +02:00
pixels = image.width * image.height;
2009-08-25 22:00:00 +02:00
fin = (byte *)pin->index; // setup buffer
2008-10-19 22:00:00 +02:00
2009-10-16 22:00:00 +02:00
if(!Image_LumpValidSize( name )) return false;
2009-08-25 22:00:00 +02:00
if( image.hint != IL_HINT_Q1 && !( flags & STUDIO_NF_QUAKESKIN ))
2008-10-19 22:00:00 +02:00
{
2009-10-16 22:00:00 +02:00
if( filesize < ( sizeof( *pin ) + pixels + 768 ))
return false;
2009-08-25 22:00:00 +02:00
if( flags & STUDIO_NF_TRANSPARENT )
{
2010-05-27 22:00:00 +02:00
byte *pal = fin + pixels;
// make transparent color is black, blue color looks ugly
if( Sys.app_name == HOST_NORMAL )
pal[255*3+0] = pal[255*3+1] = pal[255*3+2] = 0;
Image_GetPaletteLMP( pal, LUMP_TRANSPARENT );
2009-08-25 22:00:00 +02:00
image.flags |= IMAGE_HAS_ALPHA;
}
2009-09-04 22:00:00 +02:00
else Image_GetPaletteLMP( fin + pixels, LUMP_NORMAL );
2008-10-19 22:00:00 +02:00
}
2009-08-25 22:00:00 +02:00
else if( image.hint != IL_HINT_HL && flags & STUDIO_NF_QUAKESKIN )
2008-10-19 22:00:00 +02:00
{
2009-10-16 22:00:00 +02:00
if( filesize < ( sizeof( *pin ) + pixels ))
return false;
2009-08-25 22:00:00 +02:00
// alias models setup
Image_GetPaletteQ1();
// check for luma pixels
for( i = 0; i < pixels; i++ )
{
if( fin[i] > 224 )
{
Msg( "%s has luma-pixels\n", name );
image.flags |= IMAGE_HAS_LUMA_Q1;
break;
}
}
2008-10-19 22:00:00 +02:00
}
2009-08-25 22:00:00 +02:00
else
{
if( image.hint == IL_HINT_NO )
MsgDev( D_ERROR, "Image_LoadMDL: lump (%s) is corrupted\n", name );
return false; // unknown or unsupported mode rejected
}
2008-10-19 22:00:00 +02:00
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
return FS_AddMipmapToPack( fin, image.width, image.height );
}
/*
============
Image_LoadSPR
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadSPR( const char *name, const byte *buffer, size_t filesize )
2008-10-19 22:00:00 +02:00
{
2008-10-25 22:00:00 +02:00
dspriteframe_t *pin; // indetical for q1\hl sprites
2008-11-03 22:00:00 +01:00
2008-10-19 22:00:00 +02:00
if( image.hint == IL_HINT_HL )
{
if( !image.d_currentpal )
{
MsgDev( D_ERROR, "Image_LoadSPR: (%s) palette not installed\n", name );
return false;
}
}
else if( image.hint == IL_HINT_Q1 )
{
Image_GetPaletteQ1();
}
else return false; // unknown mode rejected
2008-10-25 22:00:00 +02:00
pin = (dspriteframe_t *)buffer;
2010-11-21 22:00:00 +01:00
image.width = pin->width;
image.height = pin->height;
2008-10-19 22:00:00 +02:00
2008-10-20 22:00:00 +02:00
if( filesize < image.width * image.height )
{
MsgDev( D_ERROR, "Image_LoadSPR: file (%s) have invalid size\n", name );
return false;
}
2008-10-19 22:00:00 +02:00
// sorry, can't validate palette rendermode
if(!Image_LumpValidSize( name )) return false;
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
2008-10-20 22:00:00 +02:00
// detect alpha-channel by palette type
if( image.d_rendermode == LUMP_DECAL || image.d_rendermode == LUMP_TRANSPARENT )
2008-11-03 22:00:00 +01:00
image.flags |= IMAGE_HAS_ALPHA;
2008-10-20 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
return FS_AddMipmapToPack( (byte *)(pin + 1), image.width, image.height );
}
2008-08-06 22:00:00 +02:00
/*
==============
Image_LoadWAL
==============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadWAL( const char *name, const byte *buffer, size_t filesize )
2008-08-06 22:00:00 +02:00
{
wal_t wal;
int pixels, ofs[4], mipsize;
int i, flags, value, contents; // wal additional parms
2008-11-13 22:00:00 +01:00
const byte *fin;
2008-08-06 22:00:00 +02:00
2009-08-02 22:00:00 +02:00
if( filesize < (int)sizeof( wal ))
2008-08-06 22:00:00 +02:00
{
MsgDev( D_ERROR, "Image_LoadWAL: file (%s) have invalid size\n", name );
return false;
}
2009-08-02 22:00:00 +02:00
Mem_Copy( &wal, buffer, sizeof( wal ));
2008-08-06 22:00:00 +02:00
2010-11-21 22:00:00 +01:00
flags = wal.flags;
value = wal.value;
contents = wal.contents;
image.width = wal.width;
image.height = wal.height;
Mem_Copy( ofs, wal.offsets, sizeof( ofs ));
if( !Image_LumpValidSize( name ))
return false;
2008-08-06 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
pixels = image.width * image.height;
2008-08-06 22:00:00 +02:00
mipsize = (int)sizeof(wal) + ofs[0] + pixels;
if( pixels > 256 && filesize < mipsize )
{
// NOTE: wal's with dimensions < 32 have invalid sizes.
MsgDev( D_ERROR, "Image_LoadWAL: file (%s) have invalid size\n", name );
return false;
}
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
2008-11-13 22:00:00 +01:00
fin = buffer + ofs[0];
// check for luma pixels
for( i = 0; i < image.width * image.height; i++ )
{
if( fin[i] > 208 && fin[i] < 240 )
{
image.flags |= IMAGE_HAS_LUMA_Q2;
break;
}
}
2008-08-06 22:00:00 +02:00
Image_GetPaletteQ2(); // hardcoded
2008-11-13 22:00:00 +01:00
return FS_AddMipmapToPack( fin, image.width, image.height );
2008-08-06 22:00:00 +02:00
}
/*
============
Image_LoadFLT
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadFLT( const char *name, const byte *buffer, size_t filesize )
2008-08-06 22:00:00 +02:00
{
flat_t flat;
vfile_t *f;
2010-10-26 22:00:00 +02:00
qboolean result = false;
2008-10-19 22:00:00 +02:00
int trans_pixels = 0;
2008-08-06 22:00:00 +02:00
word column_loop, row_loop;
int i, column_offset, pointer_position, first_pos;
byte *Data, post, topdelta, length;
2010-07-29 22:00:00 +02:00
if( filesize < (int)sizeof( flat ))
2008-08-06 22:00:00 +02:00
{
MsgDev( D_ERROR, "Image_LoadFLAT: file (%s) have invalid size\n", name );
return false;
}
// stupid copypaste from DevIL, but it works
f = VFS_Create( buffer, filesize );
first_pos = VFS_Tell( f );
2010-11-21 22:00:00 +01:00
VFS_Read(f, &flat, sizeof( flat ));
image.width = flat.width;
image.height = flat.height;
if( !Image_LumpValidSize( name ))
return false;
2008-08-06 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
Data = (byte *)Mem_Alloc( Sys.imagepool, image.width * image.height );
2008-10-29 22:00:00 +01:00
Mem_Set( Data, 247, image.width * image.height ); // set default transparency
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-08-06 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
for( column_loop = 0; column_loop < image.width; column_loop++ )
2008-08-06 22:00:00 +02:00
{
VFS_Read(f, &column_offset, sizeof(int));
pointer_position = VFS_Tell( f );
VFS_Seek( f, first_pos + column_offset, SEEK_SET );
while( 1 )
{
2008-08-08 22:00:00 +02:00
if(VFS_Read(f, &topdelta, 1) != 1) goto img_trunc;
if( topdelta == 255 ) break;
if(VFS_Read(f, &length, 1) != 1) goto img_trunc;
if(VFS_Read(f, &post, 1) != 1) goto img_trunc;
2008-08-06 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
for( row_loop = 0; row_loop < length; row_loop++ )
2008-08-06 22:00:00 +02:00
{
2008-08-08 22:00:00 +02:00
if(VFS_Read(f, &post, 1) != 1) goto img_trunc;
2008-10-19 22:00:00 +02:00
if(row_loop + topdelta < image.height)
Data[(row_loop + topdelta) * image.width + column_loop] = post;
2008-08-06 22:00:00 +02:00
}
VFS_Read( f, &post, 1 );
}
2008-10-19 22:00:00 +02:00
VFS_Seek( f, pointer_position, SEEK_SET );
2008-08-06 22:00:00 +02:00
}
VFS_Close( f );
2008-08-08 22:00:00 +02:00
// swap colors in image, and check for transparency
2008-10-19 22:00:00 +02:00
for( i = 0; i < image.width * image.height; i++ )
2008-08-06 22:00:00 +02:00
{
if( Data[i] == 247 )
{
2008-08-08 22:00:00 +02:00
Data[i] = 255;
2008-10-19 22:00:00 +02:00
trans_pixels++;
2008-08-06 22:00:00 +02:00
}
2008-08-08 22:00:00 +02:00
else if( Data[i] == 255 ) Data[i] = 247;
2008-08-06 22:00:00 +02:00
}
2008-08-08 22:00:00 +02:00
// yes it's really transparent texture
2008-11-03 22:00:00 +01:00
// otherwise transparency it's a product of lazy designers (or painters ?)
if( trans_pixels > TRANS_THRESHOLD ) image.flags |= IMAGE_HAS_ALPHA;
2008-08-08 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
2008-08-06 22:00:00 +02:00
Image_GetPaletteD1();
2008-10-19 22:00:00 +02:00
result = FS_AddMipmapToPack( Data, image.width, image.height );
2008-08-08 22:00:00 +02:00
if( Data ) Mem_Free( Data );
2008-08-07 22:00:00 +02:00
return result;
2008-08-08 22:00:00 +02:00
img_trunc:
VFS_Close( f );
Mem_Free( Data );
MsgDev( D_NOTE, "Image_LoadFLAT: probably it's not a .flat image)\n" );
return false;
2008-08-06 22:00:00 +02:00
}
/*
============
Image_LoadLMP
============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadLMP( const char *name, const byte *buffer, size_t filesize )
2008-08-06 22:00:00 +02:00
{
lmp_t lmp;
byte *fin, *pal;
2008-10-25 22:00:00 +02:00
int rendermode;
2008-08-06 22:00:00 +02:00
int pixels;
2008-10-25 22:00:00 +02:00
if( filesize < sizeof( lmp ))
2008-08-06 22:00:00 +02:00
{
MsgDev( D_ERROR, "Image_LoadLMP: file (%s) have invalid size\n", name );
return false;
}
2008-10-25 22:00:00 +02:00
2010-11-06 22:00:00 +01:00
// greatest hack from valve software (particle palette)
if( com.stristr( name, "palette.lmp" ))
return Image_LoadPAL( name, buffer, filesize );
2008-10-25 22:00:00 +02:00
// greatest hack from id software
if( image.hint != IL_HINT_HL && com.stristr( name, "conchars" ))
{
image.width = image.height = 128;
2008-11-03 22:00:00 +01:00
image.flags |= IMAGE_HAS_ALPHA;
2008-10-25 22:00:00 +02:00
rendermode = LUMP_QFONT;
filesize += sizeof(lmp);
fin = (byte *)buffer;
}
else
{
fin = (byte *)buffer;
2009-08-02 22:00:00 +02:00
Mem_Copy( &lmp, fin, sizeof( lmp ));
2010-11-21 22:00:00 +01:00
image.width = lmp.width;
image.height = lmp.height;
2008-10-25 22:00:00 +02:00
rendermode = LUMP_NORMAL;
fin += sizeof(lmp);
}
2008-10-19 22:00:00 +02:00
pixels = image.width * image.height;
2008-08-06 22:00:00 +02:00
2008-10-25 22:00:00 +02:00
if( filesize < sizeof( lmp ) + pixels )
2008-08-06 22:00:00 +02:00
{
MsgDev( D_ERROR, "Image_LoadLMP: file (%s) have invalid size %d\n", name, filesize );
return false;
}
2010-11-21 22:00:00 +01:00
if( !Image_ValidSize( name ))
return false;
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-08-06 22:00:00 +02:00
2008-10-19 22:00:00 +02:00
if( image.hint != IL_HINT_Q1 && filesize > (int)sizeof(lmp) + pixels )
2008-08-06 22:00:00 +02:00
{
2008-10-19 22:00:00 +02:00
int numcolors;
2008-08-06 22:00:00 +02:00
pal = fin + pixels;
2010-11-21 22:00:00 +01:00
numcolors = *(short *)pal;
2008-08-06 22:00:00 +02:00
if( numcolors != 256 ) pal = NULL; // corrupted lump ?
2008-10-19 22:00:00 +02:00
else pal += sizeof( short );
2008-08-06 22:00:00 +02:00
}
2008-10-19 22:00:00 +02:00
else if( image.hint != IL_HINT_HL ) pal = NULL;
else return false; // unknown mode rejected
2008-11-03 22:00:00 +01:00
if( fin[0] == 255 ) image.flags |= IMAGE_HAS_ALPHA;
2008-08-06 22:00:00 +02:00
2008-10-25 22:00:00 +02:00
Image_GetPaletteLMP( pal, rendermode );
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
return FS_AddMipmapToPack( fin, image.width, image.height );
2008-08-06 22:00:00 +02:00
}
/*
=============
Image_LoadMIP
=============
*/
2010-10-26 22:00:00 +02:00
qboolean Image_LoadMIP( const char *name, const byte *buffer, size_t filesize )
2008-08-06 22:00:00 +02:00
{
mip_t mip;
byte *fin, *pal;
int ofs[4], rendermode;
int i, pixels, numcolors;
2010-07-29 22:00:00 +02:00
if( filesize < sizeof( mip ))
2008-08-06 22:00:00 +02:00
{
MsgDev( D_ERROR, "Image_LoadMIP: file (%s) have invalid size\n", name );
return false;
}
2009-08-02 22:00:00 +02:00
Mem_Copy( &mip, buffer, sizeof( mip ));
2010-11-21 22:00:00 +01:00
image.width = mip.width;
image.height = mip.height;
if( !Image_ValidSize( name ))
return false;
Mem_Copy( ofs, mip.offsets, sizeof( ofs ));
2008-10-19 22:00:00 +02:00
pixels = image.width * image.height;
2009-07-22 22:00:00 +02:00
image.depth = 1;
2008-08-06 22:00:00 +02:00
2008-10-27 22:00:00 +01:00
if( image.hint != IL_HINT_Q1 && filesize >= (int)sizeof(mip) + ((pixels * 85)>>6) + sizeof(short) + 768)
2008-08-06 22:00:00 +02:00
{
// half-life 1.0.0.1 mip version with palette
fin = (byte *)buffer + mip.offsets[0];
2008-10-19 22:00:00 +02:00
pal = (byte *)buffer + mip.offsets[0] + (((image.width * image.height) * 85)>>6);
2010-11-21 22:00:00 +01:00
numcolors = *(short *)pal;
2008-10-27 22:00:00 +01:00
if( numcolors != 256 ) pal = NULL; // corrupted mip ?
2010-05-24 22:00:00 +02:00
else pal += sizeof( short ); // skip colorsize
2008-08-06 22:00:00 +02:00
// detect rendermode
2010-05-28 22:00:00 +02:00
if( com.strrchr( name, '{' ))
2008-08-06 22:00:00 +02:00
{
2010-05-28 22:00:00 +02:00
color24 *col = (color24 *)pal;
// check for grayscale palette
for( i = 0; i < 255; i++, col++ )
{
if( col->r != col->g || col->g != col->b )
break;
}
if( i != 255 )
{
rendermode = LUMP_TRANSPARENT;
2008-10-27 22:00:00 +01:00
2010-05-27 22:00:00 +02:00
// make transparent color is black, blue color looks ugly
2010-03-06 22:00:00 +01:00
if( Sys.app_name == HOST_NORMAL )
2010-05-27 22:00:00 +02:00
pal[255*3+0] = pal[255*3+1] = pal[255*3+2] = 0;
2010-05-28 22:00:00 +02:00
}
else
2008-11-27 22:00:00 +01:00
{
2008-12-06 22:00:00 +01:00
// apply decal palette immediately
2008-11-27 22:00:00 +01:00
image.flags |= IMAGE_COLORINDEX;
2010-11-20 22:00:00 +01:00
if( Sys.app_name == HOST_NORMAL )
rendermode = LUMP_DECAL;
else rendermode = LUMP_TRANSPARENT;
2008-11-27 22:00:00 +01:00
}
2008-11-03 22:00:00 +01:00
image.flags |= IMAGE_HAS_ALPHA;
2008-08-06 22:00:00 +02:00
}
2010-06-06 22:00:00 +02:00
else
{
int pal_type;
// NOTE: we can have luma-pixels if quake1/2 texture
// converted into the hl texture but palette leave unchanged
// this is a good reason for using fullbright pixels
pal_type = Image_ComparePalette( pal );
// check for luma pixels
switch( pal_type )
{
case PAL_QUAKE1:
for( i = 0; i < image.width * image.height; i++ )
{
if( fin[i] > 224 )
{
image.flags |= IMAGE_HAS_LUMA_Q1;
break;
}
}
break;
case PAL_QUAKE2:
for( i = 0; i < image.width * image.height; i++ )
{
if( fin[i] > 208 && fin[i] < 240 )
{
image.flags |= IMAGE_HAS_LUMA_Q2;
break;
}
}
break;
}
rendermode = LUMP_NORMAL;
}
2008-08-06 22:00:00 +02:00
}
2008-10-19 22:00:00 +02:00
else if( image.hint != IL_HINT_HL && filesize >= (int)sizeof(mip) + ((pixels * 85)>>6))
2008-08-06 22:00:00 +02:00
{
// quake1 1.01 mip version without palette
fin = (byte *)buffer + mip.offsets[0];
pal = NULL; // clear palette
rendermode = LUMP_NORMAL;
2008-11-13 22:00:00 +01:00
// check for luma pixels
for( i = 0; i < image.width * image.height; i++ )
{
if( fin[i] > 224 )
{
image.flags |= IMAGE_HAS_LUMA_Q1;
break;
}
}
2008-08-06 22:00:00 +02:00
}
else
{
2008-10-19 22:00:00 +02:00
if( image.hint == IL_HINT_NO )
MsgDev( D_ERROR, "Image_LoadMIP: lump (%s) is corrupted\n", name );
return false; // unknown or unsupported mode rejected
2008-08-06 22:00:00 +02:00
}
Image_GetPaletteLMP( pal, rendermode );
2008-10-19 22:00:00 +02:00
image.type = PF_INDEXED_32; // 32-bit palete
return FS_AddMipmapToPack( fin, image.width, image.height );
2008-08-06 22:00:00 +02:00
}