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
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( Q_stristr( name, "normal" ))
|
2008-10-19 22:00:00 +02:00
|
|
|
|
rendermode = LUMP_NORMAL;
|
2011-03-09 22:00:00 +01:00
|
|
|
|
else if( Q_stristr( name, "transparent" ))
|
2008-10-19 22:00:00 +02:00
|
|
|
|
rendermode = LUMP_TRANSPARENT;
|
2011-03-09 22:00:00 +01:00
|
|
|
|
else if( Q_stristr( name, "decal" ))
|
2008-10-19 22:00:00 +02:00
|
|
|
|
rendermode = LUMP_DECAL;
|
2011-03-09 22:00:00 +01:00
|
|
|
|
else if( Q_stristr( name, "indexalpha" ))
|
2010-12-27 22:00:00 +01:00
|
|
|
|
rendermode = LUMP_INDEXALPHA;
|
2011-03-09 22:00:00 +01:00
|
|
|
|
else if( Q_stristr( name, "qfont" ))
|
2008-10-19 22:00:00 +02:00
|
|
|
|
rendermode = LUMP_QFONT;
|
2011-03-09 22:00:00 +01:00
|
|
|
|
else if( Q_stristr( name, "valve" ))
|
2010-11-06 22:00:00 +01:00
|
|
|
|
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
|
|
|
|
|
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;
|
2011-03-10 22:00:00 +01:00
|
|
|
|
Q_memcpy( &font, buffer, sizeof( font ));
|
2009-10-18 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
// 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.type = PF_INDEXED_32; // 32-bit palette
|
|
|
|
|
|
2010-11-29 22:00:00 +01:00
|
|
|
|
return Image_AddIndexedImageToPack( fin, image.width, image.height );
|
2009-10-18 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
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
|
2011-02-28 22:00:00 +01:00
|
|
|
|
pal[255*3+0] = pal[255*3+1] = pal[255*3+2] = 0;
|
2010-05-27 22:00:00 +02:00
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
2011-02-11 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_HAS_LUMA;
|
2009-08-25 22:00:00 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
image.type = PF_INDEXED_32; // 32-bit palete
|
|
|
|
|
|
2010-11-29 22:00:00 +01:00
|
|
|
|
return Image_AddIndexedImageToPack( fin, image.width, image.height );
|
2008-10-19 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
============
|
|
|
|
|
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;
|
|
|
|
|
image.type = PF_INDEXED_32; // 32-bit palete
|
|
|
|
|
|
2008-10-20 22:00:00 +02:00
|
|
|
|
// detect alpha-channel by palette type
|
2011-01-02 22:00:00 +01:00
|
|
|
|
switch( image.d_rendermode )
|
|
|
|
|
{
|
|
|
|
|
case LUMP_DECAL:
|
|
|
|
|
case LUMP_INDEXALPHA:
|
|
|
|
|
case LUMP_TRANSPARENT:
|
2008-11-03 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_HAS_ALPHA;
|
2011-01-02 22:00:00 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2008-10-20 22:00:00 +02:00
|
|
|
|
|
2010-12-15 22:00:00 +01:00
|
|
|
|
// make transparent color is black, blue color looks ugly
|
2011-02-28 22:00:00 +01:00
|
|
|
|
if( image.d_rendermode == LUMP_TRANSPARENT )
|
2010-12-15 22:00:00 +01:00
|
|
|
|
image.d_currentpal[255] = 0;
|
|
|
|
|
|
2010-11-29 22:00:00 +01:00
|
|
|
|
return Image_AddIndexedImageToPack( (byte *)(pin + 1), image.width, image.height );
|
2008-10-19 22:00:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( Q_stristr( name, "palette.lmp" ))
|
2010-11-06 22:00:00 +01:00
|
|
|
|
return Image_LoadPAL( name, buffer, filesize );
|
|
|
|
|
|
2008-10-25 22:00:00 +02:00
|
|
|
|
// greatest hack from id software
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( image.hint != IL_HINT_HL && Q_stristr( name, "conchars" ))
|
2008-10-25 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
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;
|
2011-03-10 22:00:00 +01:00
|
|
|
|
Q_memcpy( &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;
|
|
|
|
|
|
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
|
2010-11-29 22:00:00 +01:00
|
|
|
|
return Image_AddIndexedImageToPack( 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;
|
2011-02-15 22:00:00 +01:00
|
|
|
|
qboolean hl_texture;
|
2008-08-06 22:00:00 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 22:00:00 +01:00
|
|
|
|
Q_memcpy( &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;
|
|
|
|
|
|
2011-03-10 22:00:00 +01:00
|
|
|
|
Q_memcpy( ofs, mip.offsets, sizeof( ofs ));
|
2008-10-19 22:00:00 +02:00
|
|
|
|
pixels = image.width * image.height;
|
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
|
|
|
|
|
|
2011-02-15 22:00:00 +01:00
|
|
|
|
hl_texture = true;
|
|
|
|
|
|
2008-08-06 22:00:00 +02:00
|
|
|
|
// detect rendermode
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( Q_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
|
2011-02-26 22:00:00 +01: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
|
|
|
|
{
|
2011-02-26 22:00:00 +01:00
|
|
|
|
// clear blue color for 'transparent' decals
|
|
|
|
|
if( pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255 )
|
|
|
|
|
pal[255*3+0] = pal[255*3+1] = pal[255*3+2] = 0;
|
|
|
|
|
|
2008-12-06 22:00:00 +01:00
|
|
|
|
// apply decal palette immediately
|
2008-11-27 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_COLORINDEX;
|
2011-02-26 22:00:00 +01:00
|
|
|
|
rendermode = LUMP_DECAL;
|
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
|
2011-02-11 22:00:00 +01:00
|
|
|
|
if( pal_type == PAL_QUAKE1 )
|
2010-06-06 22:00:00 +02:00
|
|
|
|
{
|
|
|
|
|
for( i = 0; i < image.width * image.height; i++ )
|
|
|
|
|
{
|
|
|
|
|
if( fin[i] > 224 )
|
|
|
|
|
{
|
2011-02-11 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_HAS_LUMA;
|
2010-06-06 22:00:00 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rendermode = LUMP_NORMAL;
|
|
|
|
|
}
|
2010-12-06 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
Image_GetPaletteLMP( pal, rendermode );
|
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
|
|
|
|
|
2011-02-15 22:00:00 +01:00
|
|
|
|
hl_texture = false;
|
|
|
|
|
|
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 )
|
|
|
|
|
{
|
2010-12-22 22:00:00 +01:00
|
|
|
|
// don't apply luma to water surfaces because
|
|
|
|
|
// we use glpoly->next for store luma chain each frame
|
|
|
|
|
// and can't modify glpoly_t because many-many HL mods
|
|
|
|
|
// expected unmodified glpoly_t and can crashes on changed struct
|
|
|
|
|
// water surfaces uses glpoly->next as pointer to subdivided surfaces (as q1)
|
|
|
|
|
if( mip.name[0] != '*' && mip.name[0] != '!' )
|
2011-02-11 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_HAS_LUMA;
|
2008-11-13 22:00:00 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-06 22:00:00 +01:00
|
|
|
|
|
|
|
|
|
Image_GetPaletteQ1();
|
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
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 22:00:00 +01:00
|
|
|
|
// check for quake-sky texture
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( !Q_strncmp( mip.name, "sky", 3 ) && image.width == ( image.height * 2 ))
|
2010-12-06 22:00:00 +01:00
|
|
|
|
{
|
2011-02-11 22:00:00 +01:00
|
|
|
|
// g-cont: we need to run additional checks for palette type and colors ?
|
2010-12-06 22:00:00 +01:00
|
|
|
|
image.flags |= IMAGE_QUAKESKY;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-15 22:00:00 +01:00
|
|
|
|
// check for half-life water texture
|
2011-03-09 22:00:00 +01:00
|
|
|
|
if( hl_texture && ( mip.name[0] == '!' || !Q_strnicmp( mip.name, "water", 5 )))
|
2011-02-15 22:00:00 +01:00
|
|
|
|
{
|
|
|
|
|
// grab the fog color
|
|
|
|
|
image.fogParams[0] = pal[3*3+0];
|
|
|
|
|
image.fogParams[1] = pal[3*3+1];
|
|
|
|
|
image.fogParams[2] = pal[3*3+2];
|
|
|
|
|
|
|
|
|
|
// grab the fog density
|
|
|
|
|
image.fogParams[3] = pal[4*3+0];
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-19 22:00:00 +02:00
|
|
|
|
image.type = PF_INDEXED_32; // 32-bit palete
|
2010-11-29 22:00:00 +01:00
|
|
|
|
return Image_AddIndexedImageToPack( fin, image.width, image.height );
|
2008-08-06 22:00:00 +02:00
|
|
|
|
}
|