20 Dec 2007

This commit is contained in:
g-cont 2007-12-20 00:00:00 +03:00 committed by Alibek Omarov
parent 7d6989a167
commit bf912f84f4
6 changed files with 2529 additions and 336 deletions

View File

@ -10,6 +10,19 @@ SV_Move SV_Trace
SV_ClipMoveToEntity CM_BoxTrace
SV_ClipToLinks SV_ClipMoveToEntities
case TYPE_Q1MIP:
if(FS_Seek(w->file, w->lumps[i].filepos - w->lumps[i].size, SEEK_SET))
{
MsgDev(D_ERROR, "FS_OpenWad3File: corrupt WAD3 file\n");
return NULL;
}
default:
if(FS_Seek(w->file, w->lumps[i].filepos, SEEK_SET))
{
MsgDev(D_ERROR, "FS_OpenWad3File: corrupt WAD3 file\n");
return NULL;
}
studioframeadvance
studiorewindframe

View File

@ -75,6 +75,7 @@ typedef struct wadfile_s
{
char name[64];
int numlumps;
int type; // contains ident
file_t *file;
dlumpinfo_t *lumps;
} wadfile_t;
@ -981,6 +982,7 @@ static bool FS_AddWad3File( const char *filename )
int infotableofs;
file_t *file;
int i, numlumps;
char type[16];
if(!fs_searchwads) // start from scratch
fs_searchwads = Mem_CreateArray( fs_mempool, sizeof(wadfile_t), 16 );
@ -1005,12 +1007,20 @@ static bool FS_AddWad3File( const char *filename )
FS_Close( file );
return false;
}
if( header.ident != IDWAD2HEADER && header.ident != IDWAD3HEADER )
switch( header.ident )
{
case IDWAD2HEADER:
com_strncpy( type, "Quake1", 16 );
break;
case IDWAD3HEADER:
com_strncpy( type, "Half-Life", 16 );
break;
default:
MsgDev(D_ERROR, "FS_AddWad3File: %s have invalid ident\n", filename );
FS_Close( file );
return false;
}
}
numlumps = LittleLong( header.numlumps );
if( numlumps > MAX_FILES_IN_PACK )
@ -1031,6 +1041,7 @@ static bool FS_AddWad3File( const char *filename )
w = Mem_AllocElement( fs_searchwads );
com_strncpy( w->name, filename, sizeof(w->name));
w->file = file;
w->type = header.ident;
w->numlumps = numlumps;
w->lumps = Mem_Alloc( fs_mempool, w->numlumps * sizeof(dlumpinfo_t));
@ -1054,7 +1065,7 @@ static bool FS_AddWad3File( const char *filename )
com_strnlwr(w->lumps[i].name, w->lumps[i].name, sizeof(w->lumps[i].name));
}
// and leaves the file open
MsgDev(D_INFO, "Adding wadfile: %s (%i lumps)\n", filename, numlumps );
MsgDev(D_INFO, "Adding %s wadfile: %s (%i lumps)\n", type, filename, numlumps );
return true;
}
@ -1766,7 +1777,7 @@ FS_OpenWad3File
Look for a file in the loaded wadfiles and returns buffer with image lump
===========
*/
static byte *FS_OpenWad3File( const char *name, fs_offset_t *filesizeptr, int matchtype )
static byte *FS_OpenWadFile( const char *name, fs_offset_t *filesizeptr, int matchtype )
{
uint i, k;
wadfile_t *w;
@ -1797,49 +1808,22 @@ static byte *FS_OpenWad3File( const char *name, fs_offset_t *filesizeptr, int ma
{
if(!com_strcmp(texname, w->lumps[i].name))
{
mip_t *tex;
lmp_t *lmp;
qpic_t *pic;
qfont_t *fnt;
fs_offset_t size;
byte *buf;
size_t size;
if(matchtype != (int)w->lumps[i].type) break; // try next wad
if(matchtype != (int)w->lumps[i].type) return NULL; // try next type
if(FS_Seek(w->file, w->lumps[i].filepos, SEEK_SET))
{
MsgDev(D_ERROR, "FS_OpenWad3File: corrupt WAD3 file\n");
MsgDev(D_ERROR, "FS_OpenWadFile: %s probably corrupted\n", texname );
return NULL;
}
switch((int)w->lumps[i].type)
{
case TYPE_QPIC:
pic = (qpic_t *)Mem_Alloc( fs_mempool, w->lumps[i].disksize );
size = FS_Read(w->file, pic, w->lumps[i].size );
buf = (byte *)((qpic_t *)pic);
break;
case TYPE_QFONT:
fnt = (qfont_t *)Mem_Alloc( fs_mempool, w->lumps[i].disksize );
size = FS_Read(w->file, fnt, w->lumps[i].disksize ); // some gfx.wad requires this
buf = (byte *)((qfont_t *)fnt);
break;
case TYPE_Q1MIP:
if(!com_stricmp( w->lumps[i].name, "conchars" ))
{
// great hack from id software
FS_Seek(w->file, w->lumps[i].filepos - w->lumps[i].size, SEEK_SET);
}
lmp = (lmp_t *)Mem_Alloc( fs_mempool, w->lumps[i].disksize );
size = FS_Read(w->file, lmp, w->lumps[i].size );
buf = (byte *)((lmp_t *)lmp);
case TYPE_HLMIP:
tex = (mip_t *)Mem_Alloc( fs_mempool, w->lumps[i].disksize );
size = FS_Read(w->file, tex, w->lumps[i].size );
buf = (byte *)((mip_t *)tex);
break;
}
buf = (byte *)Mem_Alloc( fs_mempool, w->lumps[i].disksize );
size = FS_Read(w->file, buf, w->lumps[i].disksize );
if( size < w->lumps[i].disksize )
MsgDev(D_WARN, "FS_OpenWad3File: lump %s is corrupt\n", texname );
{
MsgDev(D_WARN, "FS_OpenWadFile: lump %s is corrupt\n", texname );
return NULL;
}
if(filesizeptr) *filesizeptr = w->lumps[i].disksize;
return buf;
}
@ -2377,27 +2361,28 @@ byte *FS_LoadFile (const char *path, fs_offset_t *filesizeptr )
FS_Read (file, buf, filesize);
FS_Close (file);
}
else if(!com_stricmp("wad3", ext ))
else if(!com_stricmp("mip", ext ))
{
// probably it's half-life texture
buf = FS_OpenWad3File( path, &filesize, TYPE_HLMIP );
// mip-texture form quake1 or half-life
buf = FS_OpenWadFile( path, &filesize, TYPE_MIPTEX );
if(!buf) buf = FS_OpenWadFile( path, &filesize, TYPE_MIPTEX2 );
}
else if(!com_stricmp("lmp", ext ))
{
// probably it's quake1 texture
buf = FS_OpenWad3File( path, &filesize, TYPE_Q1MIP );
// qpic from quake1 or half-life
buf = FS_OpenWadFile( path, &filesize, TYPE_QPIC );
}
else if(!com_stricmp("qpic", ext ))
else if(!com_stricmp("fnt", ext ))
{
// probably it's gfx image (q1 or hl)
buf = FS_OpenWad3File( path, &filesize, TYPE_QPIC );
// half-life qfont lump
buf = FS_OpenWadFile( path, &filesize, TYPE_QFONT );
}
else if(!com_stricmp("qfnt", ext ))
else if(!com_stricmp("pal", ext ))
{
// probably it's image from wad-file
buf = FS_OpenWad3File( path, &filesize, TYPE_QFONT );
// quake1 palette lump
buf = FS_OpenWadFile( path, &filesize, TYPE_QPAL );
}
if(filesizeptr) *filesizeptr = filesize;
return buf;
}

View File

@ -98,9 +98,6 @@ extern uint image_ptr; // common moveable pointer
// image lib utilites
extern uint *d_currentpal;
void Image_GetQ1Palette( void );
void Image_GetQ2Palette( void );
void Image_GetPalettePCX( byte *pal );
bool Image_Copy8bitRGBA(const byte *in, byte *out, int pixels);
void Image_RoundDimensions(int *scaled_width, int *scaled_height);
byte *Image_Resample(uint *in, int inwidth, int inheight, int outwidth, int outheight, int in_type);

View File

@ -60,13 +60,13 @@ bool Image_ValidSize( char *name )
{
if(image_width > 4096 || image_height > 4096 || image_width <= 0 || image_height <= 0)
{
MsgWarn( "Image_ValidSize: (%s) image size out of range [%dx%d]\n", name, image_width, image_height );
MsgWarn( "Image_ValidSize: (%s) dimensions out of range [%dx%d]\n", name, image_width, image_height );
return false;
}
return true;
}
void Image_GetPalette( byte *pal, uint *d_table )
void Image_SetPalette( byte *pal, uint *d_table )
{
int i;
byte rgba[4];
@ -117,39 +117,39 @@ void Image_GetPalette( byte *pal, uint *d_table )
}
}
void Image_GetD1Palette( void )
void Image_GetPaletteD1( void )
{
d_rendermode = LUMP_NORMAL;
if(!d1palette_init)
{
Image_GetPalette( palette_d1, d_8toD1table );
Image_SetPalette( palette_d1, d_8toD1table );
d_8toD1table[255] = 247; // 247 is transparent
d1palette_init = true;
}
d_currentpal = d_8toD1table;
}
void Image_GetQ1Palette( void )
void Image_GetPaletteQ1( void )
{
d_rendermode = LUMP_NORMAL;
if(!q1palette_init)
{
Image_GetPalette( palette_q1, d_8toQ1table );
Image_SetPalette( palette_q1, d_8toQ1table );
d_8toQ1table[255] = 0; // 255 is transparent
q1palette_init = true;
}
d_currentpal = d_8toQ1table;
}
void Image_GetQ2Palette( void )
void Image_GetPaletteQ2( void )
{
d_rendermode = LUMP_NORMAL;
if(!q2palette_init)
{
Image_GetPalette( palette_q2, d_8toQ2table );
Image_SetPalette( palette_q2, d_8toQ2table );
d_8toQ2table[255] &= LittleLong(0xffffff);
q2palette_init = true;
}
@ -162,39 +162,38 @@ void Image_GetPalettePCX( byte *pal )
if(pal)
{
Image_GetPalette( pal, d_8to24table );
Image_SetPalette( pal, d_8to24table );
d_8to24table[255] &= LittleLong(0xffffff);
d_currentpal = d_8to24table;
}
else Image_GetQ2Palette();
else Image_GetPaletteQ2();
}
void Image_GetPaletteWAD( byte *pal, int rendermode )
void Image_GetPaletteLMP( byte *pal, int rendermode )
{
d_rendermode = rendermode;
if( pal )
{
Image_GetPalette( pal, d_8to24table );
Image_SetPalette( pal, d_8to24table );
d_8to24table[255] &= LittleLong(0xffffff);
d_currentpal = d_8to24table;
}
else if(rendermode == LUMP_QFONT)
{
// quake1 base palette and font palette have some diferences
Image_GetPalette( palette_q1, d_8to24table );
Image_SetPalette( palette_q1, d_8to24table );
d_8to24table[0] = 0;
d_currentpal = d_8to24table;
}
else Image_GetQ1Palette();
else Image_GetPaletteQ1(); // default quake palette
}
/*
============
Image_Copy8bitRGBA
NOTE: must call Image_GetQ2Palette or Image_GetQ1Palette
before used
NOTE: must call Image_GetPaletteXXX before used
============
*/
bool Image_Copy8bitRGBA(const byte *in, byte *out, int pixels)
@ -206,6 +205,11 @@ bool Image_Copy8bitRGBA(const byte *in, byte *out, int pixels)
MsgDev(D_ERROR,"Image_Copy8bitRGBA: no palette set\n");
return false;
}
if(!in)
{
MsgDev(D_ERROR,"Image_Copy8bitRGBA: no input image\n");
return false;
}
while (pixels >= 8)
{
@ -237,7 +241,7 @@ bool Image_Copy8bitRGBA(const byte *in, byte *out, int pixels)
in += 2;
iout += 2;
}
if (pixels & 1)
if (pixels & 1) // last byte
iout[0] = d_currentpal[in[0]];
return true;
@ -346,211 +350,24 @@ bool Image_Processing( const char *name, rgbdata_t **pix )
return false;
}
/*
==============
LoadWAL
==============
*/
bool LoadWAL( char *name, char *buffer, int filesize )
{
wal_t wal;
int pixels, ofs[4], mipsize;// FIXME, adding four mips ?
int i, flags, value, contents; // wal additional parms
if (filesize < (int)sizeof(wal))
{
MsgWarn("LoadWAL: file (%s) have invalid size\n", name );
return false;
}
Mem_Copy(&wal, buffer, sizeof(wal));
flags = LittleLong(wal.flags);
value = LittleLong(wal.value);
contents = LittleLong(wal.contents);
image_width = LittleLong(wal.width);
image_height = LittleLong(wal.height);
for(i = 0; i < 4; i++) ofs[i] = LittleLong(wal.offsets[i]);
if(!Image_ValidSize( name )) return false;
pixels = image_width * image_height;
mipsize = (int)sizeof(wal) + ofs[0] + pixels;
if( pixels > 256 && filesize < mipsize )
{
// note: wal's with dimensions < 32 have invalid sizes.
MsgWarn("LoadWAL: file (%s) have invalid size\n", name );
return false;
}
image_num_layers = 1;
image_type = PF_RGBA_32;
Image_GetQ2Palette(); // hardcoded
return FS_AddMipmapToPack( buffer + ofs[0], image_width, image_height );
}
/*
============
LoadLMP
LoadPAL
============
*/
bool LoadLMP( char *name, char *buffer, int filesize )
bool LoadPAL( char *name, char *buffer, int filesize )
{
lmp_t lmp;
byte *fin, *pal;
int i, pixels;
int rendermode;
if (filesize < (int)sizeof(lmp))
if( filesize != 768 )
{
MsgWarn("LoadLMP: file (%s) have invalid size\n", name );
MsgWarn("LoadPAL: file (%s) have invalid size\n", name );
return false;
}
fin = buffer;
// great hack from id software
if(!com_stricmp( name, "conchars" ))
{
image_width = image_height = 128;
pixels = image_width * image_height;
image_flags |= IMAGE_HAS_ALPHA;
rendermode = LUMP_QFONT;
}
else
{
Mem_Copy(&lmp, fin, sizeof(lmp));
image_width = LittleLong(lmp.width);
image_height = LittleLong(lmp.height);
fin += sizeof(lmp);
pixels = image_width * image_height;
if (filesize < (int)sizeof(lmp) + pixels)
{
MsgWarn("LoadLMP: file (%s) have invalid size %d\n", name, filesize );
return false;
}
rendermode = LUMP_NORMAL;
}
if(!Image_ValidSize( name )) return false;
image_size = pixels * 4;
image_num_mips = 1;
image_rgba = (byte *)Mem_Alloc(Sys.imagepool, image_size );
image_num_layers = 1;
image_type = PF_RGBA_32;
// try to find transparent pixels
for(i = 0; i < pixels; i++)
{
if(fin[i] != 255) continue;
image_flags |= IMAGE_HAS_ALPHA;
rendermode = LUMP_TRANSPARENT;
break; // found
}
// half-life 1.0.0.1 lmp version with palette
if( filesize == (int)sizeof(lmp) + pixels + sizeof(short) + 768)
{
int numcolors;
pal = fin + pixels;
numcolors = BuffLittleShort( pal ), pal += 2;
if( numcolors != 256 ) pal = NULL; // corrupted lump ?
}
else pal = NULL;
Image_GetPaletteWAD( pal, rendermode );
Image_Copy8bitRGBA( fin, image_rgba, pixels );
// not a real image, just palette lump
Image_GetPaletteLMP( buffer, LUMP_NORMAL );
return true;
}
/*
============
LoadMIP
============
*/
bool LoadMIP( char *name, char *buffer, int filesize )
{
mip_t mip;
int i, ofs[4], mipsize;
if (filesize < (int)sizeof(mip))
{
MsgWarn("LoadMIP: file (%s) have invalid size\n", name );
return false;
}
Mem_Copy(&mip, buffer, sizeof(mip));
image_width = LittleLong(mip.width);
image_height = LittleLong(mip.height);
for(i = 0; i < 4; i++) ofs[i] = LittleLong(mip.offsets[i]);
if(!Image_ValidSize( name )) return false;
mipsize = image_width * image_height;
if (filesize < (int)sizeof(mip) + mipsize)
{
MsgWarn("LoadMIP: file (%s) have invalid size\n", name );
return false;
}
image_num_layers = 1;
image_type = PF_RGBA_32;
Image_GetQ1Palette();// hardcoded
return FS_AddMipmapToPack( buffer + ofs[0], image_width, image_height );
}
/*
============
LoadPIC
============
*/
bool LoadPIC( char *name, char *buffer, int filesize )
{
qpic_t pic;
byte *pal, *fin;
int numcolors;
int pixels;
if(filesize < (int)sizeof(pic))
{
MsgWarn("LoadPIC: file (%s) have invalid size\n", name );
return false;
}
Mem_Copy(&pic, buffer, sizeof(pic));
image_width = LittleShort(pic.width);
image_height = LittleShort(pic.height);
if(!Image_ValidSize( name )) return false;
pixels = image_width * image_height;
fin = buffer + sizeof(pic) - 4;
image_num_layers = 1;
image_type = PF_RGBA_32;
// half-life qlmpy version with palette
if( filesize == (int)sizeof(pic) - 2 + pixels + sizeof(short) + 768)
{
pal = fin + pixels;
numcolors = BuffLittleShort(pal);
if(numcolors != 256)
{
MsgWarn("LoadPIC: file (%s) have invalid palette size %d\n", name, numcolors );
return false;
}
pal += 2; // skip colorsize
}
else pal = NULL; // quake1 pic
if(fin[0] == 255) image_flags |= IMAGE_HAS_ALPHA;
Image_GetPaletteWAD( pal, LUMP_NORMAL );
return FS_AddMipmapToPack( fin, image_width, image_height );
}
bool LoadTEST( char *name, char *buffer, int filesize )
{
return false;
}
/*
============
LoadFNT
@ -586,50 +403,159 @@ bool LoadFNT( char *name, char *buffer, int filesize )
if( fullsize != filesize )
{
// probably it's "creditsfont" or "conchars"
MsgWarn("LoadFNT: (%s) it's not a qfont_t structure\n", name );
return LoadTEST( name, buffer, 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;
}
// setup font dimensions
image_width = font.width * QCHAR_WIDTH;
image_height = font.height;
image_num_layers = 1;
image_type = PF_RGBA_32;
if(!Image_ValidSize( name )) return false;
fin = buffer + sizeof(font) - 4;
pixels = ( image_width * image_height );
fin = buffer + sizeof(font) - 4, pal = fin + pixels;
numcolors = BuffLittleShort( pal ), pal += 2;
pal = fin + pixels;
numcolors = BuffLittleShort( pal ), pal += sizeof(short);
image_flags |= IMAGE_HAS_ALPHA; // fonts always have transparency
if(numcolors != 768)
if( numcolors == 768 )
{
// newstyle font
Image_GetPaletteLMP( pal, LUMP_QFONT );
}
else if( numcolors == 256 )
{
// oldstyle font
Image_GetPaletteLMP( pal, LUMP_TRANSPARENT );
}
else
{
MsgWarn("LoadFNT: file (%s) have invalid palette size %d\n", name, numcolors );
return false;
}
// FIXME: convert this to quake-style conchars ?
Image_GetPaletteWAD( pal, LUMP_QFONT );
return FS_AddMipmapToPack( fin, image_width, image_height );
}
/*
==============
LoadWAL
==============
*/
bool LoadWAL( char *name, char *buffer, int filesize )
{
wal_t wal;
int pixels, ofs[4], mipsize;
int i, flags, value, contents; // wal additional parms
if (filesize < (int)sizeof(wal))
{
MsgWarn("LoadWAL: file (%s) have invalid size\n", name );
return false;
}
Mem_Copy(&wal, buffer, sizeof(wal));
flags = LittleLong(wal.flags);
value = LittleLong(wal.value);
contents = LittleLong(wal.contents);
image_width = LittleLong(wal.width);
image_height = LittleLong(wal.height);
for(i = 0; i < 4; i++) ofs[i] = LittleLong(wal.offsets[i]);
if(!Image_ValidSize( name )) return false;
pixels = image_width * image_height;
mipsize = (int)sizeof(wal) + ofs[0] + pixels;
if( pixels > 256 && filesize < mipsize )
{
// note: wal's with dimensions < 32 have invalid sizes.
MsgWarn("LoadWAL: file (%s) have invalid size\n", name );
return false;
}
image_num_layers = 1;
image_type = PF_RGBA_32;
Image_GetPaletteQ2(); // hardcoded
return FS_AddMipmapToPack( buffer + ofs[0], image_width, image_height );
}
/*
============
LoadWAD
LoadLMP
============
*/
bool LoadWAD( char *name, char *buffer, int filesize )
bool LoadLMP( char *name, char *buffer, int filesize )
{
lmp_t lmp;
byte *fin, *pal;
int pixels;
if (filesize < (int)sizeof(lmp))
{
MsgWarn("LoadLMP: file (%s) have invalid size\n", name );
return false;
}
fin = buffer;
Mem_Copy(&lmp, fin, sizeof(lmp));
image_width = LittleLong(lmp.width);
image_height = LittleLong(lmp.height);
fin += sizeof(lmp);
pixels = image_width * image_height;
if (filesize < (int)sizeof(lmp) + pixels)
{
MsgWarn("LoadLMP: file (%s) have invalid size %d\n", name, filesize );
return false;
}
if(!Image_ValidSize( name )) return false;
image_size = pixels * 4;
image_num_mips = 1;
image_rgba = (byte *)Mem_Alloc(Sys.imagepool, image_size );
image_num_layers = 1;
image_type = PF_RGBA_32;
// half-life 1.0.0.1 lmp version with palette
if( filesize > (int)sizeof(lmp) + pixels )
{
int numcolors;
pal = fin + pixels;
numcolors = BuffLittleShort( pal );
if( numcolors != 256 ) pal = NULL; // corrupted lump ?
else pal += sizeof(short);
}
else pal = NULL;
if(fin[0] == 255) image_flags |= IMAGE_HAS_ALPHA;
Image_GetPaletteLMP( pal, LUMP_NORMAL );
Image_Copy8bitRGBA( fin, image_rgba, pixels );
return true;
}
/*
============
LoadMIP
============
*/
bool LoadMIP( char *name, char *buffer, int filesize )
{
mip_t mip;
byte *pal;
byte *fin, *pal;
int ofs[4], rendermode;
int i, numcolors;
int i, pixels, numcolors;
if (filesize < (int)sizeof(mip))
{
MsgWarn("LoadWAD_3: file (%s) have invalid size\n", name );
MsgWarn("LoadMIP: file (%s) have invalid size\n", name );
return false;
}
@ -637,39 +563,61 @@ bool LoadWAD( char *name, char *buffer, int filesize )
image_width = LittleLong(mip.width);
image_height = LittleLong(mip.height);
for(i = 0; i < 4; i++) ofs[i] = LittleLong(mip.offsets[i]);
if(!Image_ValidSize( name )) return false;
pal = buffer + mip.offsets[0] + (((image_width * image_height) * 85)>>6);
numcolors = BuffLittleShort( pal ), pal += 2; // skip colorsize
if(numcolors != 256)
{
MsgWarn("LoadWAD_3: file (%s) have invalid palette size %d\n", name, numcolors );
return false;
}
pixels = image_width * image_height;
image_num_layers = 1;
image_type = PF_RGBA_32; // always exctracted to 32-bit buffer
image_type = PF_RGBA_32;
// detect rendermode
if( name[0] == '{' )
if(!com_stricmp( name, "conchars" ))
{
// note: i trying determine transparent miptex by last color in palette
// e.g. valve used in their textures blue color (0,0,255)
// other cases for red (255,0,0) ang green (0,255,0) colors,
// otherwise - it will use decal palette with ugly results. ughgrrr..
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else if(pal[255*3+0] == 0 && pal[255*3+1] == 255 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else if(pal[255*3+0] == 255 && pal[255*3+1] == 0 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else rendermode = LUMP_DECAL;
// greatest hack from id software
image_width = image_height = 128;
image_flags |= IMAGE_HAS_ALPHA;
rendermode = LUMP_QFONT;
pal = NULL; // clear palette
fin = buffer;
}
else rendermode = LUMP_NORMAL;
Image_GetPaletteWAD( pal, rendermode );
return FS_AddMipmapToPack( buffer + mip.offsets[0], image_width, image_height );
else if(filesize >= (int)sizeof(mip) + ((pixels * 85)>>6) + sizeof(short) + 768)
{
// half-life 1.0.0.1 mip version with palette
fin = buffer + mip.offsets[0];
pal = buffer + mip.offsets[0] + (((image_width * image_height) * 85)>>6);
numcolors = BuffLittleShort( pal );
if(numcolors != 256) pal = NULL; // corrupted mip ?
else pal += sizeof(short); // skip colorsize
// detect rendermode
if( name[0] == '{' )
{
// note: i trying determine transparent miptex by last color in palette
// e.g. valve used in their textures blue color (0,0,255)
// other cases for red (255,0,0) ang green (0,255,0) colors,
// otherwise - it will use decal palette with ugly results. ughgrrr..
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else if(pal[255*3+0] == 0 && pal[255*3+1] == 255 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else if(pal[255*3+0] == 255 && pal[255*3+1] == 0 && pal[255*3+2] == 0 && pal[255*3+3] == 0)
rendermode = LUMP_TRANSPARENT;
else rendermode = LUMP_DECAL;
image_flags |= IMAGE_HAS_ALPHA;
}
else rendermode = LUMP_NORMAL;
}
else if(filesize >= (int)sizeof(mip) + ((pixels * 85)>>6))
{
// quake1 1.01 mip version without palette
pal = NULL; // clear palette
rendermode = LUMP_NORMAL;
fin = buffer + mip.offsets[0];
}
else
{
MsgWarn("LoadMIP: lump (%s) is corrupted\n", name );
return false;
}
if(!Image_ValidSize( name )) return false;
Image_GetPaletteLMP( pal, rendermode );
return FS_AddMipmapToPack( fin, image_width, image_height );
}
/*
@ -1889,23 +1837,21 @@ loadformat_t load_formats[] =
{"textures/%s%s.%s", "dds", LoadDDS},
{"textures/%s%s.%s", "tga", LoadTGA},
{"textures/%s%s.%s", "jpg", LoadJPG},
{"textures/%s%s.%s", "wad3",LoadWAD},
{"textures/%s%s.%s", "qpic",LoadPIC},
{"textures/%s%s.%s", "pcx", LoadPCX},
{"textures/%s%s.%s", "wal", LoadWAL},
{"textures/%s%s.%s", "lmp", LoadLMP},
{"textures/%s%s.%s", "mip", LoadMIP},
{"textures/%s%s.%s", "qfnt",LoadFNT},
{"textures/%s%s.%s", "wal", LoadWAL},
{"textures/%s%s.%s", "pcx", LoadPCX},
{"textures/%s%s.%s", "lmp", LoadLMP},
{"textures/%s%s.%s", "fnt", LoadFNT},
{"textures/%s%s.%s", "pal", LoadPAL},
{"%s%s.%s", "dds", LoadDDS},
{"%s%s.%s", "tga", LoadTGA},
{"%s%s.%s", "jpg", LoadJPG},
{"%s%s.%s", "wad3",LoadWAD},
{"%s%s.%s", "qpic",LoadPIC},
{"%s%s.%s", "pcx", LoadPCX},
{"%s%s.%s", "wal", LoadWAL},
{"%s%s.%s", "lmp", LoadLMP},
{"%s%s.%s", "mip", LoadMIP},
{"%s%s.%s", "qfnt",LoadFNT},
{"%s%s.%s", "wal", LoadWAL},
{"%s%s.%s", "pcx", LoadPCX},
{"%s%s.%s", "lmp", LoadLMP},
{"%s%s.%s", "fnt", LoadFNT},
{"%s%s.%s", "pal", LoadPAL},
{NULL, NULL}
};
@ -2089,12 +2035,12 @@ rgbdata_t *FS_LoadImage(const char *filename, char *buffer, int buffsize )
// this name will be used only for tell user about problems
FS_FileBase( loadname, texname );
if( format->loadfunc(texname, buffer, buffsize ))
return ImagePack();// loaded
return ImagePack(); // loaded
}
}
}
MsgDev(D_WARN, "couldn't load %s\n", texname );
MsgDev(D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", texname );
return NULL;
}
@ -2140,10 +2086,14 @@ bool SaveTGA( const char *filename, byte *data, int width, int height, bool alph
const byte *bufend, *in;
byte *buffer, *out;
const char *comment = "Generated by Xash ImageLib\0";
char mergedname[MAX_SYSPATH];
if(alpha) outsize = width * height * 4 + 18 + com_strlen(comment);
else outsize = width * height * 3 + 18 + com_strlen(comment);
com_strncpy(mergedname, filename, MAX_SYSPATH );
if(mergedname[0] == '*') mergedname[0] = '!'; // quake1 issues
buffer = (byte *)Malloc( outsize );
memset (buffer, 0, 18);
@ -2199,8 +2149,8 @@ bool SaveTGA( const char *filename, byte *data, int width, int height, bool alph
}
}
MsgDev(D_NOTE, "Writing %s[%d]\n", filename, alpha ? 32 : 24 );
FS_WriteFile (filename, buffer, outsize );
MsgDev(D_NOTE, "Writing %s[%d]\n", mergedname, alpha ? 32 : 24 );
FS_WriteFile( mergedname, buffer, outsize );
Mem_Free( buffer );
return true;

2252
launch/common/imglib.c.old Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1577,9 +1577,10 @@ typedef struct mip_s
#define IDWAD3HEADER (('3'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD3" half-life wads
#define WAD3_NAMELEN 16
#define TYPE_QPIC 66 // quake1 and hl pic (qpic_t)
#define TYPE_HLMIP 67 // half-life textures (mip_t) TYP_SOUND for Quake1, but never used for it
#define TYPE_Q1MIP 68 // quake1 textures (mip_t)
#define TYPE_QPAL 64
#define TYPE_QPIC 66 // quake1 and hl pic (lmp_t)
#define TYPE_MIPTEX2 67 // half-life (mip_t) previous TYP_SOUND but never used in quake1
#define TYPE_MIPTEX 68 // quake1 (mip_t)
#define TYPE_QFONT 70 // half-life font (qfont_t)
#define QCHAR_WIDTH 16
@ -1588,11 +1589,12 @@ typedef struct mip_s
typedef struct
{
int ident; // should be WAD3
int ident; // should be IWAD or WAD2 or WAD3
int numlumps;
int infotableofs;
} dwadinfo_t;
// quake1 and half-life lump header
typedef struct
{
int filepos;
@ -1602,15 +1604,9 @@ typedef struct
char compression; // probably not used
char pad1;
char pad2;
char name[WAD3_NAMELEN]; // must be null terminated
char name[16]; // must be null terminated
} dlumpinfo_t;
typedef struct
{
int width, height;
byte data[4]; // variably sized
} qpic_t;
typedef struct
{
short startoffset;