07 Aug 2008

This commit is contained in:
g-cont 2008-08-07 00:00:00 +04:00 committed by Alibek Omarov
parent 2c618c1ebc
commit d408dca09f
146 changed files with 3970 additions and 6535 deletions

View File

@ -17,32 +17,23 @@ baserc\
viewer\
physic\
render\
imglib\
ripper\
vprogs\
vsound\
common\
common\bsplib
common\roqlib
common\ripper
engine\
engine\client\
engine\server\
engine\common\
launch\
launch\qcc\
launch\xwad\
launch\xash\
launch\bsplib\
launch\common\
launch\lmpdec\
launch\mdldec\
launch\mipdec\
launch\qccdec\
launch\qcclib\
launch\roqlib\
launch\snddec\
launch\sprdec\
launch\sprite\
launch\studio\
launch\viewer\
launch\wadlib\
launch\credits\
launch\install\
launch\extragen\
launch\uninstall\

16
baserc/baserc.plg Normal file
View File

@ -0,0 +1,16 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: baserc - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
baserc.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -17,101 +17,50 @@ CalcTextureReflectivity
*/
void CalcTextureReflectivity( void )
{
int j, i, texels;
vec3_t color;
float r, scale;
int j, i;
rgbdata_t *pic;
shader_t *si;
rgbdata_t *tex;
// allways set index 0 even if no textures
texture_reflectivity[0][0] = 0.5;
texture_reflectivity[0][1] = 0.5;
texture_reflectivity[0][2] = 0.5;
for (i = 0; i < numtexinfo; i++)
for( i = 0; i < numtexinfo; i++ )
{
// see if an earlier texinfo allready got the value
for (j = 0; j < i; j++)
{
if( texinfo[i].texid == texinfo[j].texid )
{
VectorCopy (texture_reflectivity[j], texture_reflectivity[i]);
VectorCopy( texture_reflectivity[j], texture_reflectivity[i] );
break;
}
}
if(j != i) continue;
if( j != i ) continue;
color[0] = color[1] = color[2] = 0;
// loading tga, jpg or png texture
tex = Image->LoadImage(GetStringFromTable( texinfo[i].texid ), NULL, 0);
if( tex )
{
texels = tex->width * tex->height;
switch(tex->type)
{
case PF_DXT1:
case PF_DXT3:
case PF_DXT5:
if(!Image->DecompressDXTC( &tex )) break;
// intentional falltrough
case PF_RGBA_32:
case PF_ABGR_64:
for (j = 0; j < texels; j++, tex->buffer += 4)
{
color[0] += tex->buffer[0];
color[1] += tex->buffer[1];
color[2] += tex->buffer[2];
}
break;
case PF_RGB_24:
for (j = 0; j < texels; j++, tex->buffer += 3)
{
color[0] += tex->buffer[0];
color[1] += tex->buffer[1];
color[2] += tex->buffer[2];
}
break;
default:
MsgDev( D_WARN, "Can't calculate reflectivity for %s\n", GetStringFromTable( texinfo[i].texid ));
break;
}
}
else MsgDev( D_ERROR, "Couldn't load %s\n", GetStringFromTable( texinfo[i].texid ));
pic = FS_LoadImage(GetStringFromTable( texinfo[i].texid ), NULL, 0 );
Image_GetColor( pic );
// try also get direct values from shader
if(si = FindShader( GetStringFromTable(texinfo[i].texid)))
{
if(!VectorIsNull(si->color))
if(!VectorIsNull( si->color ))
{
TransformRGB(si->color, texture_reflectivity[i]);
TransformRGB( si->color, texture_reflectivity[i] );
texinfo[i].value = si->intensity;
continue;
}
}
if(texels == 0 || VectorIsNull(color))
if( !pic || VectorIsNull( pic->color ))
{
//no texture, no shader...
// no texture, no shader...
VectorSet(texture_reflectivity[i], 0.5, 0.5, 0.5 );
continue;
}
for (j = 0; j < 3; j++)
{
r = color[j]/texels/255.0;
texture_reflectivity[i][j] = r;
}
// scale the reflectivity up, because the textures are
// so dim
scale = ColorNormalize (texture_reflectivity[i], texture_reflectivity[i]);
if( scale < 0.5 )
{
scale *= 2;
VectorScale(texture_reflectivity[i], scale, texture_reflectivity[i]);
}
VectorCopy( pic->color, texture_reflectivity[i] );
texinfo[i].value = pic->bump_scale;
FS_FreeImage( pic ); // don't forget free image
}
}

View File

@ -23,13 +23,13 @@ int FindMiptex( char *name )
if( nummiptex == MAX_MAP_TEXTURES ) Sys_Break("MAX_MAP_TEXTURES limit exceeds\n");
// register texture
strcpy (textureref[i].texname, name );
tex = Image->LoadImage( textureref[i].texname, NULL, 0 );
com.strcpy (textureref[i].texname, name );
tex = FS_LoadImage( textureref[i].texname, NULL, 0 );
if( tex )
{
textureref[i].size[0] = tex->width;
textureref[i].size[1] = tex->height;
Image->FreeImage( tex );
FS_FreeImage( tex );
}
else textureref[i].size[0] = textureref[i].size[1] = -1; // technically an error

View File

@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PLATFORM_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "../public" /I "./bsplib/" /I "./roqlib" /I "./common" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "../public" /I "./bsplib/" /I "./ripper" /I "./common" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
@ -79,7 +79,7 @@ SOURCE="$(InputPath)"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PLATFORM_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /I "./" /I "../public" /I "./bsplib/" /I "./roqlib" /I "./common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /I "./" /I "../public" /I "./bsplib/" /I "./ripper" /I "./common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
@ -173,30 +173,6 @@ SOURCE=.\bsplib\qvis3.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_encoder.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_main.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_vq1.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_vq2.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_vq4.c
# End Source File
# Begin Source File
SOURCE=.\roqlib\roq_yuv.c
# End Source File
# Begin Source File
SOURCE=.\bsplib\shaders.c
# End Source File
# Begin Source File
@ -261,10 +237,6 @@ SOURCE=.\platform.h
# End Source File
# Begin Source File
SOURCE=.\roqlib\roqlib.h
# End Source File
# Begin Source File
SOURCE=.\utils.h
# End Source File
# End Group

16
common/common.plg Normal file
View File

@ -0,0 +1,16 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: common - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
common.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -7,11 +7,8 @@
#include "utils.h"
#include "bsplib.h"
#include "mdllib.h"
#include "roqlib.h"
dll_info_t imglib_dll = { "imglib.dll", NULL, "CreateAPI", NULL, NULL, true, sizeof(imglib_exp_t) };
dll_info_t vprogs_dll = { "vprogs.dll", NULL, "CreateAPI", NULL, NULL, true, sizeof(vprogs_exp_t) };
imglib_exp_t *Image;
vprogs_exp_t *PRVM;
stdlib_api_t com;
byte *basepool;
@ -31,7 +28,7 @@ void InitPlatform ( int argc, char **argv )
{
byte bspflags = 0, qccflags = 0, roqflags = 0;
char source[64], gamedir[64];
launch_t CreateImglib, CreateVprogs;
launch_t CreateVprogs;
basepool = Mem_AllocPool( "Temp" );
@ -40,13 +37,9 @@ void InitPlatform ( int argc, char **argv )
com_argv = argv;
app_name = g_Instance;
Sys_LoadLibrary( &imglib_dll ); // load imagelib
CreateImglib = (void *)imglib_dll.main;
Image = CreateImglib( &com, NULL ); // second interface not allowed
switch( app_name )
{
case COMP_BSPLIB:
case HOST_BSPLIB:
if(!FS_GetParmFromCmdLine("-game", gamedir ))
com.strncpy(gamedir, Cvar_VariableString( "fs_defaultdir" ), sizeof(gamedir));
if(!FS_GetParmFromCmdLine("+map", source ))
@ -58,7 +51,7 @@ void InitPlatform ( int argc, char **argv )
PrepareBSPModel( gamedir, source, bspflags );
break;
case COMP_QCCLIB:
case HOST_QCCLIB:
Sys_LoadLibrary( &vprogs_dll ); // load qcclib
CreateVprogs = (void *)vprogs_dll.main;
PRVM = CreateVprogs( &com, NULL ); // second interface not allowed
@ -73,21 +66,18 @@ void InitPlatform ( int argc, char **argv )
start = Sys_DoubleTime();
PRVM->PrepareDAT( gamedir, source );
break;
case COMP_ROQLIB:
case COMP_SPRITE:
case COMP_STUDIO:
case COMP_WADLIB:
case HOST_SPRITE:
case HOST_STUDIO:
case HOST_WADLIB:
FS_InitRootDir(".");
start = Sys_DoubleTime();
break;
case HOST_OFFLINE:
break;
}
Image->Init(); // initialize image support
}
void RunPlatform ( void )
void RunPlatform( void )
{
search_t *search;
bool (*CompileMod)( byte *mempool, const char *name, byte parms ) = NULL;
@ -100,36 +90,31 @@ void RunPlatform ( void )
switch(app_name)
{
case COMP_SPRITE:
case HOST_SPRITE:
CompileMod = CompileSpriteModel;
com.strcpy(typemod, "sprites" );
com.strcpy(searchmask[0], "*.qc" );
break;
case COMP_STUDIO:
case HOST_STUDIO:
CompileMod = CompileStudioModel;
com.strcpy(typemod, "models" );
com.strcpy(searchmask[0], "*.qc" );
break;
case COMP_BSPLIB:
case HOST_BSPLIB:
com.strcpy(typemod, "maps" );
com.strcpy(searchmask[0], "*.map" );
CompileBSPModel();
break;
case COMP_WADLIB:
case HOST_WADLIB:
CompileMod = CompileWad3Archive;
com.strcpy(typemod, "wads" );
com.strcpy(searchmask[0], "*.qc" );
break;
case COMP_QCCLIB:
case HOST_QCCLIB:
com.strcpy(typemod, "progs" );
com.strcpy(searchmask[0], "*.src" );
PRVM->CompileDAT();
break;
case COMP_ROQLIB:
CompileMod = CompileROQVideo;
com.strcpy(typemod, "videos" );
com.strcpy(searchmask[0], "*.qc" );
break;
case HOST_OFFLINE:
com.strcpy(typemod, "things" );
com.strcpy(searchmask[0], "*.*" );
@ -137,8 +122,8 @@ void RunPlatform ( void )
}
if(!CompileMod) goto elapced_time; // jump to shutdown
zonepool = Mem_AllocPool("compiler");
if(!FS_GetParmFromCmdLine("-file", filename ))
zonepool = Mem_AllocPool( "compiler" );
if(!FS_GetParmFromCmdLine( "-file", filename ))
{
// search by mask
for( i = 0; i < 8; i++)
@ -174,15 +159,12 @@ elapced_time:
void FreePlatform ( void )
{
if( app_name == COMP_QCCLIB )
if( app_name == HOST_QCCLIB )
{
PRVM->Free();
Sys_FreeLibrary( &vprogs_dll ); // free qcclib
}
Image->Free();
Sys_FreeLibrary( &imglib_dll ); // free imagelib
Mem_Check(); // check for leaks
Mem_FreePool( &basepool );
Mem_FreePool( &zonepool );

File diff suppressed because it is too large Load Diff

View File

@ -1,604 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_main.c - ROQ video maker
//=======================================================================
#include "roqlib.h"
#include "byteorder.h"
#include "mathlib.h"
uint keyBits = 0;
uint motionBits = 0;
uint keyPerc = 600;
uint motionPerc = 200;
uint keyRate = 120;
uint frameRate = 30;
bool neverCache = false;
bool forceRegen = false;
file_t *roqFile = NULL;
file_t *muxFile = NULL;
file_t *cbFile = NULL;
rgbdata_t *frame = NULL;
uint nextKeyframe = 0;
uint iTotalFrames = 0;
dword addedData = 0;
char movieoutname[MAX_SYSPATH];
char tempoutname[MAX_SYSPATH];
char codebookname[MAX_SYSPATH];
char soundname[MAX_SYSPATH];
search_t *frames;
byte *buffer;
#define SAMPLES_PER_FRAME 735 // 22050/30
#define MAX_SAMPLES (SAMPLES_PER_FRAME * 8)
void FPUTC( char buf, file_t *f)
{
addedData++;
FS_Write(f, &buf, 1);
}
#define MAX_DPCM 16129 // 127*127
byte dpcmValues[MAX_DPCM];
short channel1[MAX_SAMPLES*2];
short channel2[MAX_SAMPLES*2];
short temp[MAX_SAMPLES*4];
short previousValues[2];
byte stepIndex[2];
void CopyBytes(dword len)
{
byte bytes[1024];
while(len > 1024)
{
FS_Read(roqFile, bytes, 1024 );
FS_Write(muxFile, bytes, 1024);
len -= 1024;
}
FS_Read(roqFile, bytes, len );
FS_Write(muxFile, bytes, len);
}
short CopyChunk(void)
{
word id;
dword size;
byte buffer[8];
// Read the chunk header
if(!FS_Read(roqFile, buffer, 8 ))
return 0;
// Parse info
id = BuffLittleShort( buffer );
size = BuffLittleLong( &buffer[2] );
// don't copy audio chunks
if(id == 0x1020 || id == 0x1021)
{
FS_Seek(roqFile, size, SEEK_CUR);
return id;
}
// copy the chunk header back out
FS_Write(muxFile, buffer, 8 );
// copy the rest
CopyBytes(size);
return id;
}
void dpcmInit(void)
{
word i;
short diff;
short diff2;
word baseline;
word projection;
word projectionIndex;
projectionIndex = 0;
baseline = 0;
projection = 1;
// Create a table of quick DPCM values
for(i = 0; i < MAX_DPCM; i++)
{
// check the difference of the last projection
// and (possibly) the next projection
diff = i - baseline;
diff2 = i - projection;
if(diff < 0) diff = -diff;
if(diff2 < 0) diff2 = -diff2;
// move the DPCM index up a notch if it's closer
if(diff2 < diff)
{
projectionIndex++;
baseline = projection;
projection = (projectionIndex+1)*(projectionIndex+1);
}
dpcmValues[i] = (byte)projectionIndex;
}
previousValues[0] = 0;
previousValues[1] = 0;
}
short EncodeDPCM( int previous, int current)
{
byte signMask;
int output;
int diff;
diff = current - previous;
if(diff < 0)
{
signMask = 128;
diff = -diff;
}
else signMask = 0;
if(diff >= MAX_DPCM)
output = 127;
else output = dpcmValues[diff];
diff = output*output;
if(signMask) diff = -diff;
if(previous + diff < -32768 || previous + diff > 32767)
output--; // Tone down to prevent overflow
diff = output*output;
if(signMask) diff = -diff;
FPUTC(output | signMask, muxFile);
return previous + diff;
}
void EncodeStereo(unsigned long samples)
{
dword doubleSamples = samples * 2;
dword i;
FPUTC(0x21, muxFile); // stereo audio
FPUTC(0x10, muxFile);
FPUTC(doubleSamples & 255, muxFile);
FPUTC((doubleSamples>>8) & 255, muxFile);
FPUTC((doubleSamples>>16) & 255, muxFile);
FPUTC((doubleSamples>>24) & 255, muxFile);
previousValues[0] &= 0xFF00;
previousValues[1] &= 0xFF00;
FPUTC((previousValues[1] >> 8), muxFile);
FPUTC((previousValues[0] >> 8), muxFile);
// Encode samples
for(i = 0; i < samples; i++)
{
previousValues[0] = EncodeDPCM(previousValues[0], channel1[i]);
previousValues[1] = EncodeDPCM(previousValues[1], channel2[i]);
}
}
void EncodeMono(dword samples)
{
dword i;
FPUTC(0x20, muxFile); // mono audio
FPUTC(0x10, muxFile);
FPUTC(samples & 255, muxFile);
FPUTC((samples>>8) & 255, muxFile);
FPUTC((samples>>16) & 255, muxFile);
FPUTC((samples>>24) & 255, muxFile);
FPUTC(previousValues[0] & 255, muxFile);
FPUTC((previousValues[0] >> 8) & 255, muxFile);
// encode samples
for(i = 0; i < samples; i++)
previousValues[0] = EncodeDPCM(previousValues[0], channel1[i]);
}
byte *ROQ_MakeUprightRGB( const char *name, rgbdata_t *frame )
{
byte *in, *out;
int bpp;
switch(frame->type)
{
case PF_RGB_24:
case PF_RGB_24_FLIP:
case PF_RGBA_32:
bpp = PFDesc[frame->type].bpp;
break;
default:
Sys_Break("Frame %s have unsupported image type %s\n", name, PFDesc[frame->type].name );
break;
}
// flip image at 180 degrees
for (in = frame->buffer, out = buffer; in < frame->buffer + frame->width * frame->height * bpp; in += bpp)
{
*out++ = in[0];
*out++ = in[1];
*out++ = in[2];
}
return buffer;
}
void ROQ_Blit(byte *source, byte *dest, dword scanWidth, dword sourceSkip, dword destSkip, dword rows)
{
while(rows)
{
Mem_Copy(dest, source, scanWidth);
source += sourceSkip;
dest += destSkip;
rows--;
}
}
int ROQ_ReadCodebook( byte *buffer )
{
if(forceRegen) return 0;
return FS_Read(cbFile, buffer, CB_FRAME_SIZE );
}
void ROQ_SaveCodebook( byte *buffer )
{
if(neverCache) return;
FS_Write(cbFile, buffer, CB_FRAME_SIZE );
}
static roq_compressor_t *ROQ_CreateCompressor(void)
{
comp = RQalloc(sizeof(roq_compressor_t));
comp->framesSinceKeyframe = 0;
comp->preferences[ROQENC_PREF_KEYFRAME] = 1;
comp->preferences[ROQENC_PREF_WIDTH] = 0;
comp->preferences[ROQENC_PREF_HEIGHT] = 0;
comp->preferences[ROQENC_PREF_REFINEMENT_PASSES] = 1;
comp->preferences[ROQENC_PREF_CULL_THRESHOLD] = 64;
comp->initialized = 0;
return comp;
}
void ROQ_DestroyCompressor(roq_compressor_t *comp)
{
long i;
Mem_Free(comp->devLUT2);
Mem_Free(comp->devLUT4);
Mem_Free(comp->devLUT8);
Mem_Free(comp->devMotion4);
Mem_Free(comp->devMotion8);
Mem_Free(comp->devSkip4);
for(i = 0; i < 3; i++)
Mem_Free(comp->frames[i].rgb);
Mem_Free(comp->listSort);
Mem_Free(comp->lut2);
Mem_Free(comp->lut4);
Mem_Free(comp->lut8);
Mem_Free(comp->motionVectors4);
Mem_Free(comp->motionVectors8);
Mem_Free(comp->pList);
Mem_Free(comp->preWrite);
Mem_Free(comp->recon);
Mem_Free(comp->optimizedOut4);
Mem_Free(comp);
}
static void ROQ_SetPreference(roq_compressor_t *comp, short num, dword pref)
{
if(num >= ROQENC_PREF_COUNT) return;
comp->preferences[num] = pref;
}
static void ROQ_WriteHeader(file_t *file)
{
roq_t hdr;
hdr.ident = IDQMOVIEHEADER;
hdr.flags = (short)0xffff;
hdr.flags2 = (short)0xffff;
hdr.fps = frameRate;
FS_Write(file, &hdr, sizeof(roq_t));
}
// Doubles the size of one RGB source longo the destination
void ROQ_DoubleSize(byte *source, byte *dest, dword dim)
{
dword x,y;
dword skip;
skip = dim * 6;
for(y = 0; y < dim; y++)
{
for(x = 0; x < dim; x++)
{
Mem_Copy(dest, source, 3);
Mem_Copy(dest+3, source, 3);
Mem_Copy(dest+skip, source, 3);
Mem_Copy(dest+skip+3, source, 3);
dest += 6;
source += 3;
}
dest += skip;
}
}
/*
===============
Cmd_Sound
syntax: "$sound soundname"
===============
*/
void Cmd_Sound( void )
{
com.strcpy( soundname, Com_GetToken (false));
FS_DefaultExtension( soundname, ".wav" );
}
/*
===============
Cmd_FpsMovie
syntax: "$framerate value"
===============
*/
void Cmd_FpsMovie( void )
{
int fps = com.atoi(Com_GetToken(false));
frameRate = bound(12, fps, 36 );
}
/*
==============
Cmd_Videoname
syntax: "$videoname outname"
==============
*/
void Cmd_Videoname (void)
{
com.strcpy( movieoutname, Com_GetToken (false));
FS_DefaultExtension( movieoutname, ".roq" );
}
/*
==============
Cmd_FrameMask
syntax: "$framemask "shot*.tga""
==============
*/
void Cmd_FrameMask( void )
{
frames = FS_Search(Com_GetToken(false), true );
}
/*
==============
Cmd_Quality
syntax: "$quality "keyword""
==============
*/
void Cmd_Quality( void )
{
Com_GetToken(false);
if(Com_MatchToken("high"))
{
motionPerc = 550;
}
else if(Com_MatchToken("normal"))
{
motionPerc = 350;
}
else if(Com_MatchToken("low"))
{
motionPerc = 200;
}
else motionPerc = 350;
}
/*
==============
Cmd_MovieUnknown
syntax: "blabla"
==============
*/
void Cmd_MovieUnknown( void )
{
MsgDev( D_WARN, "Cmd_MovieUnknown: bad command %s\n", com_token);
while(Com_TryToken());
}
void ResetMovieInfo( void )
{
// set default sprite parms
FS_FileBase(gs_filename, movieoutname ); // kill path and ext
FS_DefaultExtension( movieoutname, ".roq" ); //set new ext
motionBits = 0;
keyPerc = 600;
motionPerc = 200;
keyRate = 120;
frameRate = 30;
keyBits = nextKeyframe = 0;
neverCache = forceRegen = 0;
iTotalFrames = 0;
addedData = 0;
if(roqFile) FS_Close(roqFile);
if(muxFile) FS_Close(muxFile);
if(cbFile) FS_Close(cbFile);
if(frame) RFree( frame );
if(frames) RFree( frames );
roqFile = cbFile = muxFile = NULL;
frame = NULL;
frames = NULL;
}
/*
===============
ParseScript
===============
*/
bool ROQ_ParseMovieScript (void)
{
ResetMovieInfo();
while (1)
{
if(!Com_GetToken (true))break;
if (Com_MatchToken( "$videoname" )) Cmd_Videoname();
else if (Com_MatchToken( "$fps" )) Cmd_FpsMovie();
else if (Com_MatchToken( "$framemask" )) Cmd_FrameMask();
else if (Com_MatchToken( "$sound" )) Cmd_Sound();
else if (Com_MatchToken( "$quality")) Cmd_Quality();
else if (!Com_ValidScript( QC_ROQLIB )) return false;
else Cmd_MovieUnknown();
}
return true;
}
void ROQ_ProcessFrame( int num )
{
frame = Image->LoadImage( frames->filenames[num], NULL, 0 );
if(!frame || !frame->buffer) return; // technically an error
Image->ResampleImage( frames->filenames[num], &frame, 512, 256, true ); // resample if needed
if(!nextKeyframe)
{
ROQ_SetPreference(comp, ROQENC_PREF_KEYFRAME, 1);
ROQ_SetPreference(comp, ROQENC_PREF_GOAL_SIZE_BITS, keyBits);
nextKeyframe = keyRate;
}
else ROQ_SetPreference(comp, ROQENC_PREF_GOAL_SIZE_BITS, motionBits);
nextKeyframe--;
if(!ROQ_CompressRGB(comp, roqFile, ROQ_MakeUprightRGB( frames->filenames[num], frame )))
{
MsgDev( D_ERROR, "ROQ_CompressRGB: frame encode failed\n");
return;
}
Sys_GetEvent(); // update console output
if( frame ) Image->FreeImage( frame );
iTotalFrames++;
}
void ROQ_ProcessVideo( void )
{
roq_compressor_t *comp;
uint i = 0;
if(!frames) frames = FS_Search("frame?", true );
if(!frames) Sys_Break("RoqLib: movie frames not found\n");
roqFile = FS_Open( movieoutname, "wb" );
com.strcpy(codebookname, movieoutname );
FS_StripExtension( codebookname );
FS_DefaultExtension( codebookname, ".cb" );
if(!forceRegen)
{
cbFile = FS_Open( codebookname, "rb");
if(!cbFile) forceRegen = true;
else neverCache = true;
}
if(forceRegen && !neverCache)
{
cbFile = FS_Open( codebookname, "wb");
if(!cbFile) Sys_Break("ROQ_ProcessVideo: could not open %s\n", codebookname );
}
frame = Image->LoadImage( frames->filenames[i], NULL, 0 );
if(!frame) Sys_Break("frame not loaded\n");
Image->ResampleImage( frames->filenames[i], &frame, 512, 256, true ); // resample first frame
// allocate transform buffer
buffer = RQalloc( frame->width * frame->height * 3);
if(!keyBits) keyBits = (frame->width * frame->height * (3*8)) * keyPerc / 10000;
if(!motionBits) motionBits = (frame->width * frame->height * (3*8)) * motionPerc / 10000;
// write the RoQ header
comp = ROQ_CreateCompressor();
ROQ_SetPreference(comp, ROQENC_PREF_WIDTH, frame->width );
ROQ_SetPreference(comp, ROQENC_PREF_HEIGHT, frame->height );
ROQ_WriteHeader( roqFile );
Msg ("Compress Video...\n");
RunThreadsOnIndividual(frames->numfilenames, true, ROQ_ProcessFrame );
Msg("Total Frames compressed: %i\n", iTotalFrames );
// close file
ROQ_DestroyCompressor(comp);
RFree( buffer );
RFree( frames );
if(roqFile) FS_Close( roqFile );
if(!forceRegen && !neverCache) FS_Close( cbFile );
}
void ROQ_ProcessAudio( void )
{
return;
if(!com.strlen(soundname)) return;
com.strcpy( tempoutname, movieoutname );
FS_StripExtension( tempoutname );
FS_DefaultExtension( tempoutname, ".mux" );
roqFile = FS_Open( movieoutname, "rb" );
muxFile = FS_Open( tempoutname, "wb");
}
bool CompileCurrentMovie( const char *name )
{
bool load = false;
if( name ) com.strcpy( gs_filename, name );
FS_DefaultExtension( gs_filename, ".qc" );
load = Com_LoadScript( gs_filename, NULL, 0 );
if(load)
{
if(!ROQ_ParseMovieScript())
return false;
ROQ_ProcessVideo();
ROQ_ProcessAudio();
return true;
}
Msg("%s not found\n", gs_filename );
return false;
}
bool CompileROQVideo( byte *mempool, const char *name, byte parms )
{
if(mempool) roqpool = mempool;
else
{
Msg("RoqLib: can't allocate memory pool.\nAbort compilation\n");
return false;
}
return CompileCurrentMovie( name );
}

View File

@ -1,156 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_vq.h - adaptive GLA variant 3: heiarchial VQ
//=======================================================================
static void GLA_ITERATE(GLA_UNIT *input, uint inputCount, GLA_UNIT *book, uint bookSize, uint *mapping, uint *hits, uint *diameters, uint *diamvectors)
{
uint i, j;
uint misses;
uint diff;
uint bestDiff;
uint bestMatch;
long lhits[256];
double totalDeviation=0.0;
// remap the diameter list
for(i = 0; i < bookSize; i++) diameters[i] = diamvectors[i] = hits[i] = 0;
// first map each input to the closest codebook entry
for(i = 0; i < inputCount; i++)
{
bestDiff = GLA_DIFFERENCE(input + i, book);
bestMatch = 0;
for(j = 1; j < bookSize; j++)
{
diff = GLA_DIFFERENCE(input + i, book + j);
if(diff < bestDiff)
{
bestDiff = diff;
bestMatch = j;
if(!diff) break;
}
}
totalDeviation += (double)bestDiff / (double)inputCount;
// mark this the most deviant if needed
if(bestDiff > diameters[bestMatch])
{
diameters[bestMatch] = bestDiff;
diamvectors[bestMatch] = i;
}
hits[bestMatch]++;
// assign this entry to the centroid
mapping[i] = bestMatch;
}
misses = 0;
for(i = 0; i < bookSize; i++) lhits[i] = 0;
for(i = 0; i < inputCount; i++) lhits[mapping[i]]++;
for(i = 0; i < bookSize; i++) if(!lhits[i]) misses++;
MsgDev(D_NOTE, "%i misses ", misses);
GLA_CENTROID(input, inputCount, book, bookSize, mapping);
}
GLA_FUNCTION_SCOPE long GLA_FUNCTION(GLA_UNIT *input, uint inputCount, uint goalCells, uint *resultCount, GLA_UNIT **resultElements)
{
GLA_UNIT *output=GLA_NULL;
GLA_UNIT *output2=GLA_NULL;
uint *diameters;
uint *diamVectors;
uint *hits;
GLA_UNIT *tempOutput;
uint *mapping = GLA_NULL;
uint i,j,splitTotal;
uint bestDiff;
uint bestMatch;
uint step;
uint cellGoal;
mapping = RQalloc(inputCount * sizeof(unsigned int));
output = RQalloc(goalCells * sizeof(GLA_UNIT));
output2 = RQalloc(goalCells * sizeof(GLA_UNIT));
diameters = RQalloc(goalCells * sizeof(unsigned int));
diamVectors = RQalloc(goalCells * sizeof(unsigned int));
hits = RQalloc(goalCells * sizeof(unsigned int));
if(!mapping || !output || !output2 || !diameters || !diamVectors || !hits)
{
if(mapping) Mem_Free(mapping);
if(output) Mem_Free(output);
if(output2) Mem_Free(output2);
if(diameters) Mem_Free(diameters);
if(diamVectors) Mem_Free(diamVectors);
if(hits) Mem_Free(hits);
return 0;
}
step = 0;
// Map all input units to the same cell to create
// a centroid for the entire input set
for(i = 0; i < inputCount; i++) mapping[i] = 0;
GLA_CENTROID(input, inputCount, output, 1, mapping);
for(cellGoal = 1; cellGoal < goalCells; cellGoal *= 2)
{
MsgDev(D_NOTE, "Building codebook size %i...\n", cellGoal*2);
// split each cell into 2 new cells, then perturb them.
// copy the original in so it can be perturbed as well if needed
for(i = 0; i < cellGoal; i++)
{
GLA_COPY(output + i, output2 + (i*2));
GLA_PERTURB(output2 + (i*2), output2 + (i*2+1), step);
}
// swap output buffers
tempOutput = output2;
output2 = output;
output = tempOutput;
// run GLA passes on the new output
for(i = 0; i < GLA2_MAX_PASSES; i++)
GLA_ITERATE(input, inputCount, output, cellGoal*2, mapping, hits, diameters, diamVectors);
MsgDev(D_NOTE, "Done\n", 0);
step++;
}
// split high-diameter cells to minimize waste
splitTotal = 0;
for(i = 0; i < cellGoal; i++)
{
if(hits[i] == 0)
{
// This cell is dead. Replace it with the highest-diameter input
bestDiff = diameters[0];
bestMatch = 0;
for(j = 0; j < cellGoal; j++)
{
if(diameters[j] > bestDiff && diameters[j] != 0)
{
bestDiff = diameters[j];
bestMatch = j;
}
}
// if no split could be made, ignore...
if(bestDiff == 0) break;
splitTotal++;
diameters[bestMatch] = 0;
GLA_COPY(input + diamVectors[bestMatch], output + i);
}
}
MsgDev(D_NOTE, "%i splits made.\n", splitTotal);
Mem_Free(diameters);
Mem_Free(diamVectors);
Mem_Free(hits);
Mem_Free(output2);
Mem_Free(mapping);
*resultCount = cellGoal;
*resultElements = output;
return 1;
}

View File

@ -1,218 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_vq1.c - vq codebook base1
//=======================================================================
#include "roqlib.h"
// vector quantization routines. RoQ uses 4:2:0 and 2:1:0 YCbCr blocks for codebooks,
// so I use the same thing, but only because it's about twice as fast as doing RGB
// with very slight quality loss.
yuvBlock4_t yuvCodebook4[256];
yuvBlock2_t yuvCodebook2[256];
yuvDiskBlock4_t yuvDisk4[256]; // Indexed 4x4
static byte codebookBuffer[2560];
static byte ROQ_IndexCodebook2( yuvBlock2_t *block )
{
long i;
uint diff;
uint highestDiff=9999999;
byte choice=0;
// Find the closest match
for(i = 0; i < 256; i++)
{
diff = YUVDifference2(block, yuvCodebook2+i);
if(diff < highestDiff)
{
highestDiff = diff;
choice = (byte)i;
}
}
return choice;
}
static void ROQ_IndexCodebook4( void )
{
long i,j;
for(i = 0; i < 256; i++)
{
for(j = 0; j < 4; j++)
yuvDisk4[i].indexes[j] = ROQ_IndexCodebook2(yuvCodebook4[i].block + j);
}
}
long ROQ_MakeCodebooks(void)
{
yuvBlock2_t *inputs2;
yuvBlock2_t *results2;
yuvBlock4_t *inputs4;
yuvBlock4_t *results4;
uint resultCount;
dword x,y,n = 0;
dword mx, my;
byte temp[4*4*3];
// 2x2 codebook
inputs2 = RQalloc(sizeof(yuvBlock2_t) * vidWidth * vidHeight / 4);
for(y = 0; y < vidHeight; y += 2)
{
my = (y*vidWidth) / 16;
for(x = 0; x < vidWidth; x += 2)
{
mx = x / 4;
// check optimization
if(optimizedOut4[mx+my]) continue;
ROQ_Blit(rgbFrame0 + (x + (y*vidWidth))*3, temp, 2*3, vidScanWidth, 2*3, 2);
RGB2toYUV2(temp, inputs2[n].yuv);
n++;
}
}
stats.vectorsProvided4 = vidWidth*vidHeight / 16;
stats.vectorsQuantized4 = n;
if(!n) n = 1; // don't feed the generator bad input
// make it
if(!YUVGenerateCodebooks2(inputs2, n, 256, &resultCount, &results2))
{
Mem_Free(inputs2);
return 0;
}
// save and release the results
Mem_Copy(yuvCodebook2, results2, sizeof(yuvBlock2_t) * resultCount);
Mem_Free(results2);
Mem_Free(inputs2);
// 4x4 codebook
inputs4 = RQalloc(sizeof(yuvBlock4_t) * vidWidth * vidHeight / 16);
for(y = 0, n = 0; y < vidHeight; y += 4)
{
my = (y*vidWidth) / 16;
for(x = 0; x < vidWidth; x += 4)
{
mx = x / 4;
if(optimizedOut4[mx+my]) continue;
ROQ_Blit(rgbFrame0 + (x + (y*vidWidth))*3, temp, 2*3, vidScanWidth, 2*3, 2);
RGB2toYUV2(temp, inputs4[n].block[0].yuv);
ROQ_Blit(rgbFrame0 + ((x+2) + (y*vidWidth))*3, temp, 2*3, vidScanWidth, 2*3, 2);
RGB2toYUV2(temp, inputs4[n].block[1].yuv);
ROQ_Blit(rgbFrame0 + (x + ((y+2)*vidWidth))*3, temp, 2*3, vidScanWidth, 2*3, 2);
RGB2toYUV2(temp, inputs4[n].block[2].yuv);
ROQ_Blit(rgbFrame0 + ((x+2) + ((y+2)*vidWidth))*3, temp, 2*3, vidScanWidth, 2*3, 2);
RGB2toYUV2(temp, inputs4[n].block[3].yuv);
n++;
}
}
if(!n) n = 1; // don't feed the generator bad input
// make it
if(!YUVGenerateCodebooks4(inputs4, n, 256, &resultCount, &results4))
{
Mem_Free(inputs4);
return 0;
}
// save and release the results
Mem_Copy(yuvCodebook4, results4, sizeof(yuvBlock4_t) * resultCount);
Mem_Free(results4);
Mem_Free(inputs4);
// index the 4x4 codebook (RoQ requires this)
ROQ_IndexCodebook4();
return 1;
}
void GenerateCodebookDebugs(void)
{
long x,y,n = 0;
for(y = 0; y < 16; y++)
{
for(x = 0; x < 16; x++)
{
// copy a 2x2
ROQ_Blit(codebook2[n].rgb, stats.codebookResults2 + (x*2*3) + (y*2*(2*16*3)), 2*3, 2*3, 16*2*3, 2);
ROQ_Blit(codebook4[n].rgb, stats.codebookResults4 + (x*4*3) + (y*4*(4*16*3)), 4*3, 4*3, 16*4*3, 4);
n++;
}
}
}
static byte codebookBuffer[CB_FRAME_SIZE];
int ReadCodebookCache( void )
{
uint i, j, n = 0;
if(!ROQ_ReadCodebook(codebookBuffer))
return 0;
// Parse the codebook data
for(i = 0; i < 256; i++)
for(j = 0; j < 6; j++)
yuvCodebook2[i].yuv[j] = codebookBuffer[n++];
for(i = 0; i < 256; i++)
for(j = 0; j < 4; j++)
yuvDisk4[i].indexes[j] = codebookBuffer[n++];
return 1;
}
void WriteCodebookCache(void)
{
uint i, j, n = 0;
for(i = 0; i < 256; i++)
for(j = 0; j < 6; j++)
codebookBuffer[n++] = yuvCodebook2[i].yuv[j];
for(i = 0; i < 256; i++)
for(j = 0; j < 4; j++)
codebookBuffer[n++] = yuvDisk4[i].indexes[j];
ROQ_SaveCodebook(codebookBuffer);
}
long ROQ_GetCodebooks( void )
{
long i;
bool dontWrite;
if(!ReadCodebookCache())
{
// generate codebooks for this frame
if(!ROQ_MakeCodebooks()) return 0;
dontWrite = false;
}
else
{
stats.vectorsProvided4 = vidWidth*vidHeight / 16;
stats.vectorsQuantized4 = stats.vectorsProvided4;
dontWrite = true;
}
// decode the 2x2 codebook
for(i = 0; i < 256; i++) YUV2toRGB2(yuvCodebook2[i].yuv, codebook2[i].rgb);
// copy the 2x2 codebook to the 4x4 codebook using the indices
for(i = 0; i < 256; i++)
{
ROQ_Blit(codebook2[yuvDisk4[i].indexes[0]].rgb, codebook4[i].rgb, 2*3, 2*3, 4*3, 2);
ROQ_Blit(codebook2[yuvDisk4[i].indexes[1]].rgb, codebook4[i].rgb+6, 2*3, 2*3, 4*3, 2);
ROQ_Blit(codebook2[yuvDisk4[i].indexes[2]].rgb, codebook4[i].rgb+24, 2*3, 2*3, 4*3, 2);
ROQ_Blit(codebook2[yuvDisk4[i].indexes[3]].rgb, codebook4[i].rgb+24+6, 2*3, 2*3, 4*3, 2);
}
// create 8x8 codebooks by oversizing the 4x4 entries
for(i = 0; i < 256; i++) ROQ_DoubleSize(codebook4[i].rgb, codebook8[i].rgb, 4);
GenerateCodebookDebugs();
if(!dontWrite) WriteCodebookCache();
return 1;
}

View File

@ -1,97 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_vq2.c - vq codebook base2
//=======================================================================
#include "roqlib.h"
static void YUVCentroid2(yuvBlock2_t *inputs, uint count, yuvBlock2_t *out, uint cbSize, uint *map)
{
uint numEntries;
uint totals[6];
uint i, j, k;
byte *yuv;
// for each entry in the codebook...
for(i = 0; i < cbSize; i++)
{
// initialize the average
totals[0] = totals[1] = totals[2] = totals[3] = totals[4] = totals[5] = 0;
numEntries = 0;
for(j = 0; j < count; j++)
{
// if an input element is mapped to this entry...
if(map[j] == i)
{
// increase the number of entries
numEntries++;
// and add the values to the total
yuv = inputs[j].yuv;
for(k = 0; k < 6; k++) totals[k] += yuv[k];
}
}
// average the results to create a final component
if(numEntries)
{
yuv = out[i].yuv;
for(k = 0; k < 6; k++) yuv[k] = (byte)(totals[k] / numEntries);
}
}
}
uint YUVDifference2(yuvBlock2_t *a, yuvBlock2_t *b)
{
byte *yuv1, *yuv2;
yuv1 = a->yuv;
yuv2 = b->yuv;
return QUICKDIFF(yuv1[0],yuv2[0]) + QUICKDIFF(yuv1[1],yuv2[1]) + QUICKDIFF(yuv1[2],yuv2[2]) + QUICKDIFF(yuv1[3],yuv2[3]) + (QUICKDIFF(yuv1[4],yuv2[4]) << 2) + (QUICKDIFF(yuv1[5],yuv2[5]) << 2);
}
void YUVPerturb2(yuvBlock2_t *a, yuvBlock2_t *b, uint step)
{
long i, res, diff = 0;
static uint lastStep = 999;
static long rmax;
if(lastStep != step)
{
lastStep = step;
rmax = 1;
for(i = 0; i < PERTURBATION_BASE_POWER - (int)step; i++) rmax <<= 1;
}
if(rmax < 2) rmax = 2;
for(i = 0; i < 6; i++)
{
if(rmax) diff = rmax;
else diff = 0;
res = a->yuv[i] + diff;
if(res < 0) res = 0;
if(res > 255) res = 255;
b->yuv[i] = (byte)res;
res = a->yuv[i] - diff;
if(res < 0) res = 0;
if(res > 255) res = 255;
a->yuv[i] = (byte)res;
if(i == 4) rmax /= 2;
}
}
#define GLA_FUNCTION_SCOPE
#define GLA_UNIT yuvBlock2_t
#define GLA_NULL NULL
#define GLA_DIFFERENCE YUVDifference2
#define GLA_CENTROID YUVCentroid2
#define GLA_PRINTF(a,b) Msg( a, b )
#define GLA_COPY(in,out) Mem_Copy((out), (in), sizeof(yuvBlock2_t))
#define GLA_PERTURB YUVPerturb2
#define GLA2_MAX_PASSES refinementPasses
#define GLA_FUNCTION YUVGenerateCodebooks2
// YUVGenerateCodebooks2 is DYNAMICALLY CREATED using the following include
#include "roq_vq.h"

View File

@ -1,76 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_vq4.c - vq codebook base4
//=======================================================================
#include "roqlib.h"
void YUVPerturb4(yuvBlock4_t *in, yuvBlock4_t *out, uint step)
{
YUVPerturb2(in->block, out->block, step);
YUVPerturb2(in->block + 1, out->block + 1, step);
YUVPerturb2(in->block + 2, out->block + 2, step);
YUVPerturb2(in->block + 3, out->block + 3, step);
}
uint YUVDifference4(yuvBlock4_t *in, yuvBlock4_t *out)
{
return YUVDifference2(in->block, out->block) + YUVDifference2(in->block + 1, out->block + 1) + YUVDifference2(in->block + 2, out->block + 2) + YUVDifference2(in->block + 3, out->block + 3);
}
void YUVCentroid4(yuvBlock4_t *blocks, uint count, yuvBlock4_t *out, uint cbSize, uint *map)
{
uint numEntries;
uint totals[24];
uint j, i, k, l, n;
byte *yuv;
// for each entry in the codebook...
for(i = 0; i < cbSize; i++)
{
// initialize the average
for(j = 0; j < 24; j++) totals[j] = 0;
numEntries = 0;
for(j = 0; j < count; j++)
{
// if an input element is mapped to this entry...
if(map[j] == i)
{
// increase the number of entries
numEntries++;
// and add the values to the total
for(k = 0, n = 0; k < 4; k++)
{
yuv = blocks[j].block[k].yuv;
for(l = 0; l < 6; l++) totals[n++] += yuv[l];
}
}
}
// average the results to create a final component
if(numEntries)
{
for(k = 0, n = 0; k < 4; k++)
{
yuv = out[i].block[k].yuv;
for(l = 0; l < 6; l++) yuv[l] = (byte)(totals[n++] / numEntries);
}
}
}
}
#define GLA_FUNCTION_SCOPE
#define GLA_UNIT yuvBlock4_t
#define GLA_NULL NULL
#define GLA_DIFFERENCE YUVDifference4
#define GLA_CENTROID YUVCentroid4
#define GLA_PRINTF(a, b) Msg( a, b )
#define GLA_COPY(in,out) Mem_Copy((out), (in), sizeof(yuvBlock4_t))
#define GLA_PERTURB YUVPerturb4
#define GLA2_MAX_PASSES refinementPasses
#define GLA_FUNCTION YUVGenerateCodebooks4
// YUVGenerateCodebooks4 is DYNAMICALLY CREATED using the following include
#include "roq_vq.h"

View File

@ -1,89 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roq_yuv.c - ROQ yuv convertor
//=======================================================================
#include "roqlib.h"
// CCIR 601-1 YCbCr colorspace.
// acceleration tables
static short r2y[256];
static short r2cb[256];
static short r2cr[256];
static short g2y[256];
static short g2cb[256];
static short g2cr[256];
static short b2y[256];
static short b2cb[256];
static short b2cr[256];
static short cb2g[256];
static short cb2b[256];
static short cr2r[256];
static short cr2g[256];
void ROQ_InitYUV(void)
{
static bool initialized = false;
long i;
if(initialized) return;
initialized = true;
for(i = 0; i < 256; i++)
{
// set up encode tables
r2y[i] = (short)((i * 19595)>>16); // 0.299
r2cb[i] = (short)((i * (-11056))>>16); // -0.1687
r2cr[i] = (short)(i>>1); // 0.5
g2y[i] = (short)((i * 38470)>>16); // 0.587
g2cb[i] = (short)((i * (-21712))>>16); // -0.3313
g2cr[i] = (short)((i * (-27440))>>16); // -0.4187
b2y[i] = (short)((i * 7471)>>16); // 0.114
b2cb[i] = (short)(i>>1); // 0.5
b2cr[i] = (short)((i * (-5328))>>16); // -0.0813
cb2g[i] = (short)(( (i-128)*(-22554))>>16); // -0.34414
cb2b[i] = (short)(( (i-128)*112853)>>16); // 1.722
cr2r[i] = (short)(( (i-128)*91881)>>16); // 1.402
cr2g[i] = (short)(( (i-128)*(-46802))>>16); // -0.71414
}
}
void ROQ_RGBtoYUV(byte r, byte g, byte b, byte *yp, byte *up, byte *vp)
{
short y, cb, cr;
y = r2y[r] + g2y[g] + b2y[b];
y = (y < 0) ? 0 : ((y > 255) ? 255 : y);
cb = r2cb[r] + g2cb[g] + b2cb[b] + 128;
cb = (cb < 0) ? 0 : ((cb > 255) ? 255 : cb);
cr = r2cr[r] + g2cr[g] + b2cr[b] + 128;
cr = (cr < 0) ? 0 : ((cr > 255) ? 255 : cr);
*yp = (byte)y;
*up = (byte)cb;
*vp = (byte)cr;
}
void ROQ_YUVtoRGB(byte y, byte u, byte v, byte *rp, byte *gp, byte *bp)
{
short r, g, b;
r = y + cr2r[v];
r = (r < 0) ? 0 : ((r > 255) ? 255 : r);
g = y + cb2g[u] + cr2g[v];
g = (g < 0) ? 0 : ((g > 255) ? 255 : g);
b = y + cb2b[u];
b = (b < 0) ? 0 : ((b > 255) ? 255 : b);
*rp = (byte)r;
*gp = (byte)g;
*bp = (byte)b;
}

View File

@ -1,156 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// roqlib.h - roq video maker
//=======================================================================
#ifndef ROQLIB_H
#define ROQLIB_H
#include "platform.h"
#include "utils.h"
/*
========================================================================
ROQ FILES
The .roq file are vector-compressed movies
========================================================================
*/
#define IDQMOVIEHEADER 0x1084 // little-endian "„"
typedef struct roq_s
{
word ident;
short flags;
short flags2;
word fps;
} roq_t;
typedef struct { byte *rgb; } videoFrame_t;
typedef struct { long x,y; } motionVector_t;
typedef struct { byte yuv[6]; } yuvBlock2_t;
typedef struct { byte indexes[4]; } yuvDiskBlock4_t;
typedef struct { yuvBlock2_t block[4]; } yuvBlock4_t;
typedef struct { byte rgb[8*8*3]; } rgbBlock8_t;
typedef struct { byte rgb[4*4*3]; } rgbBlock4_t;
typedef struct { byte rgb[2*2*3]; } rgbBlock2_t;
enum
{
ROQENC_PREF_KEYFRAME,
ROQENC_PREF_WIDTH,
ROQENC_PREF_HEIGHT,
ROQENC_PREF_GOAL_SIZE_BITS,
ROQENC_PREF_REFINEMENT_PASSES,
ROQENC_PREF_CULL_THRESHOLD,
ROQENC_PREF_COUNT,
};
typedef struct roq_stats_s
{
byte codebookResults4[256*4*4*3];
byte codebookResults2[256*2*2*3];
uint vectorsProvided4;
uint vectorsQuantized4;
long bytesConsumed;
long bytesMax;
byte *reconstructResult;
} roq_stats_t;
typedef struct possibilityList_s
{
double bestDownscaleRate;
long mse[259];
long currentMSE;
dword currentSize;
word currentChoice;
word bestDownscaleChoice;
byte downscalePossible;
} possibilityList_t;
typedef struct roq_compressor_s
{
long initialized;
long wroteInfo;
long frameNum; // hack to fix RoQ bug
dword preferences[ROQENC_PREF_COUNT];
videoFrame_t frames[3];
videoFrame_t *frameCycle[3];
// local data
uint *devLUT8;
uint *devLUT4;
uint *devLUT2;
uint *devMotion8;
uint *devMotion4;
uint *devSkip4; // Skip8 can be calculated from this
motionVector_t *motionVectors8;
motionVector_t *motionVectors4;
byte *lut8;
byte *lut4;
byte *lut2;
byte *recon; // frame reconstruction after compression
byte *preWrite;
possibilityList_t *pList;
uint *listSort;
long *optimizedOut4;
long framesSinceKeyframe;
} roq_compressor_t;
extern roq_compressor_t *comp;
extern dword vidWidth;
extern dword vidHeight;
extern dword vidScanWidth;
extern byte *rgbFrame0;
extern byte *rgbFrame1;
extern byte *rgbFrame2;
extern uint refinementPasses;
extern rgbBlock8_t codebook8[256];
extern rgbBlock4_t codebook4[256];
extern rgbBlock2_t codebook2[256];
extern uint quickDiff[256*256];
extern yuvBlock2_t yuvCodebook2[256];
extern yuvDiskBlock4_t yuvDisk4[256];
extern long *optimizedOut4;
extern roq_stats_t stats;
#define CB_FRAME_SIZE 2560
#define QUICKDIFF(a,b) quickDiff[((a)<<8)+(b)]
#define PERTURBATION_BASE_POWER 6
void ROQ_InitQuickdiff(void);
long ROQ_GetCodebooks(void);
void ROQ_GenerateBlocks(void);
int ROQ_ReadCodebook( byte *buffer );
void ROQ_SaveCodebook( byte *buffer );
void ROQ_InitYUV(void);
void YUV2toRGB2(byte *yuv, byte *rgb);
void RGB2toYUV2(byte *rgb, byte *yuv);
void YUVPerturb2(yuvBlock2_t *a, yuvBlock2_t *b, uint step);
uint YUVDifference2(yuvBlock2_t *a, yuvBlock2_t *b);
long YUVGenerateCodebooks4(yuvBlock4_t *input, uint inputCount, uint goalCells, uint *resultCount, yuvBlock4_t **resultElements);
long YUVGenerateCodebooks2(yuvBlock2_t *input, uint inputCount, uint goalCells, uint *resultCount, yuvBlock2_t **resultElements);
void ROQ_RGBtoYUV(byte r, byte g, byte b, byte *yp, byte *up, byte *vp);
void ROQ_YUVtoRGB(byte y, byte u, byte v, byte *rp, byte *gp, byte *bp);
dword ROQ_CompressRGB( roq_compressor_t *compressor, void *file, byte *rgb);
#define CHUNKMARK_INFO 0x1001
#define CHUNKMARK_CODEBOOK 0x1002
#define CHUNKMARK_VIDEO 0x1011
#define CHUNKMARK_AUDIO_MONO 0x1020
#define CHUNKMARK_AUDIO_STEREO 0x1021
extern byte *roqpool;
#define RQalloc( size ) Mem_Alloc(roqpool, size )
#define RFree(x) if(x) Mem_Free(x)
// utils
void ROQ_Blit(byte *source, byte *dest, dword scanWidth, dword sourceSkip, dword destSkip, dword rows);
void ROQ_DoubleSize(byte *source, byte *dest, dword dim);
#endif//ROQLIB_H

View File

@ -97,7 +97,6 @@ void Profile_Time( void ); // total profile time
#define Profile_Results( name ) _Profile_Results( #name )
extern stdlib_api_t com;
extern imglib_exp_t *Image;
extern vprogs_exp_t *PRVM;
#define Sys_Error com.error

View File

@ -34,17 +34,16 @@ int Lump_GetFileType( const char *name, byte *buf )
if(!buf) return TYPE_NONE;
// otherwise get file type by extension
if(!com.stricmp( ext, "tga" )) return TYPE_GFXPIC;
else if(!com.stricmp( ext, "dds" )) return TYPE_GFXPIC; // directdraw mip
else if(!com.stricmp( ext, "mip" ))
{
if(wadheader == IDWAD3HEADER)
return TYPE_MIPTEX2; // half-life texture
return TYPE_MIPTEX; // quake1 texture
}
if(!com.stricmp( ext, "mip" )) return TYPE_MIPTEX2; // half-life texture
else if(!com.stricmp( ext, "lmp" )) return TYPE_QPIC; // hud pics
else if(!com.stricmp( ext, "pal" )) return TYPE_QPAL; // palette
else if(!com.stricmp( ext, "txt" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "aur" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "lst" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "qc" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "qh" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "c" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "h" )) return TYPE_SCRIPT; // text file
else if(!com.stricmp( ext, "dat" )) return TYPE_VPROGS; // qc progs
else if(!com.stricmp( ext, "raw" )) return TYPE_RAW; // raw data
@ -85,14 +84,14 @@ void Wad3_AddLump( const char *name, bool compress )
}
FS_FileBase( name, lumpname );
if(strlen(lumpname) > WAD3_NAMELEN)
if(com.strlen(lumpname) > WAD3_NAMELEN)
{
MsgDev( D_ERROR, "Wad3_AddLump: %s have too long name, max %d symbols\n", lumpname, WAD3_NAMELEN );
return;
}
// create wad file
if(!handle) Wad3_NewWad();
if( !handle ) Wad3_NewWad();
info = &wadlumps[numlumps];
com.strncpy( info->name, lumpname, WAD3_NAMELEN );
@ -128,32 +127,6 @@ void Cmd_WadName( void )
FS_DefaultExtension( wadoutname, ".wad" );
}
void Cmd_WadType( void )
{
Com_GetToken( false );
if(Com_MatchToken( "Quake1") || Com_MatchToken( "Q1"))
{
wadheader = IDWAD2HEADER;
allow_compression = false;
}
else if(Com_MatchToken( "Half-Life") || Com_MatchToken( "Hl1"))
{
wadheader = IDWAD3HEADER;
allow_compression = false;
}
else if(Com_MatchToken( "Xash3D"))
{
wadheader = IDWAD4HEADER;
allow_compression = true;
}
else
{
wadheader = IDWAD3HEADER; // default
allow_compression = false;
}
}
void Cmd_AddLump( void )
{
char filename[MAX_SYSPATH];
@ -225,8 +198,8 @@ void ResetWADInfo( void )
memset (&wadheader, 0, sizeof(wadheader));
wadheader = IDWAD3HEADER;
allow_compression = true;
compress_lumps = false;
allow_compression = false;
numlumps = 0;
handle = NULL;
}
@ -245,7 +218,6 @@ bool ParseWADfileScript( void )
if(!Com_GetToken (true))break;
if (Com_MatchToken( "$wadname" )) Cmd_WadName();
else if (Com_MatchToken( "$wadtype" )) Cmd_WadType();
else if (Com_MatchToken( "$compression" )) Cmd_WadCompress();
else if (Com_MatchToken( "$addlump" )) Cmd_AddLump();
else if (Com_MatchToken( "$addlumps" )) Cmd_AddLumps();

View File

@ -20,9 +20,6 @@ if errorlevel 1 set BUILD_ERROR=1
%MSDEV% common/common.dsp %CONFIG%"common - Win32 Debug" %build_target%
if errorlevel 1 set BUILD_ERROR=1
%MSDEV% imglib/imglib.dsp %CONFIG%"imglib - Win32 Debug" %build_target%
if errorlevel 1 set BUILD_ERROR=1
%MSDEV% ripper/ripper.dsp %CONFIG%"ripper - Win32 Debug" %build_target%
if errorlevel 1 set BUILD_ERROR=1
@ -64,7 +61,6 @@ if exist baserc\baserc.plg del /f /q baserc\baserc.plg
if exist engine\engine.plg del /f /q engine\engine.plg
if exist launch\launch.plg del /f /q launch\launch.plg
if exist common\common.plg del /f /q common\common.plg
if exist imglib\imglib.plg del /f /q imglib\imglib.plg
if exist ripper\ripper.plg del /f /q ripper\ripper.plg
if exist physic\physic.plg del /f /q physic\physic.plg
if exist render\render.plg del /f /q render\render.plg

16
engine/engine.plg Normal file
View File

@ -0,0 +1,16 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: engine - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
engine.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@ -1,56 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// imagelib.h - image processing library
//=======================================================================
#ifndef IMAGELIB_H
#define IMAGELIB_H
#include <windows.h>
#include "basetypes.h"
#include "ref_dllapi.h"
#define IMAGE_MAXWIDTH 4096
#define IMAGE_MAXHEIGHT 4096
extern stdlib_api_t com;
extern byte *zonepool;
extern int app_name;
#define Sys_Error com.error
extern cvar_t *img_resample_lerp;
extern int image_width, image_height;
extern byte image_num_layers; // num layers in
extern byte image_num_mips; // build mipmaps
extern uint image_type; // main type switcher
extern uint image_flags; // additional image flags
extern byte image_bits_count; // bits per RGBA
extern size_t image_size; // image rgba size
extern byte *image_rgba; // image pointer (see image_type for details)
extern byte *image_palette; // palette pointer
bool Image_AddMipmapToPack( const byte *in, int width, int height );
void Image_RoundDimensions( int *scaled_width, int *scaled_height );
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int intype );
bool Image_Resample( const char *name, rgbdata_t **image, int width, int height, bool free_baseimage );
void Image_FreeImage( rgbdata_t *pack );
void Image_Save( const char *filename, rgbdata_t *pix );
rgbdata_t *Image_Load(const char *filename, const byte *buffer, size_t buffsize );
//
// formats
//
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize );
bool Image_SaveMIP( const char *name, rgbdata_t *pix, int saveformat );
bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize );
bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat );
bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize );
bool Image_SaveDDS( const char *name, rgbdata_t *pix, int saveformat );
//
// img_utils.c
//
bool Image_ValidSize( const char *name );
bool Image_DecompressDXTC( rgbdata_t **image ); // compilers version of decompressor
bool Image_DecompressARGB( rgbdata_t **image );
#endif//IMAGELIB_H

View File

@ -1,117 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// imagelib.h - image processing library
//=======================================================================
#ifndef IMG_FORMATS_H
#define IMG_FORMATS_H
#include <limits.h>
/*
========================================================================
.TGA image format (Truevision Targa)
========================================================================
*/
typedef struct tga_s
{
byte id_length;
byte colormap_type;
byte image_type;
word colormap_index;
word colormap_length;
byte colormap_size;
word x_origin;
word y_origin;
word width;
word height;
byte pixel_size;
byte attributes;
} tga_t;
/*
========================================================================
.DDS image format
========================================================================
*/
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
// various four-cc types
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
#define DDS_CAPS 0x00000001L
#define DDS_HEIGHT 0x00000002L
#define DDS_WIDTH 0x00000004L
#define DDS_RGB 0x00000040L
#define DDS_PIXELFORMAT 0x00001000L
#define DDS_LUMINANCE 0x00020000L
#define DDS_ALPHAPIXELS 0x00000001L
#define DDS_ALPHA 0x00000002L
#define DDS_FOURCC 0x00000004L
#define DDS_PITCH 0x00000008L
#define DDS_COMPLEX 0x00000008L
#define DDS_CUBEMAP 0x00000200L
#define DDS_TEXTURE 0x00001000L
#define DDS_MIPMAPCOUNT 0x00020000L
#define DDS_LINEARSIZE 0x00080000L
#define DDS_VOLUME 0x00200000L
#define DDS_MIPMAP 0x00400000L
#define DDS_DEPTH 0x00800000L
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
typedef struct dds_pf_s
{
uint dwSize;
uint dwFlags;
uint dwFourCC;
uint dwRGBBitCount;
uint dwRBitMask;
uint dwGBitMask;
uint dwBBitMask;
uint dwABitMask;
} dds_pixf_t;
// DDCAPS2
typedef struct dds_caps_s
{
uint dwCaps1;
uint dwCaps2;
uint dwCaps3;
uint dwCaps4;
} dds_caps_t;
typedef struct dds_s
{
uint dwIdent; // must matched with DDSHEADER
uint dwSize;
uint dwFlags; // determines what fields are valid
uint dwHeight;
uint dwWidth;
uint dwLinearSize; // Formless late-allocated optimized surface size
uint dwDepth; // depth if a volume texture
uint dwMipMapCount; // number of mip-map levels requested
uint dwAlphaBitDepth; // depth of alpha buffer requested
float fReflectivity[3]; // average reflectivity value
float fBumpScale; // bumpmapping scale factor
uint dwReserved1[6]; // reserved for future expansions
dds_pixf_t dsPixelFormat;
dds_caps_t dsCaps;
uint dwTextureStage;
} dds_t;
#endif//IMG_FORMATS_H

View File

@ -1,299 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_load.c - load various image formats
//=======================================================================
#include "imagelib.h"
#include "img_formats.h"
// global image variables
int image_width, image_height;
byte image_num_layers = 1; // num layers in
byte image_num_mips = 0; // build mipmaps
uint image_type; // main type switcher
uint image_flags; // additional image flags
byte image_bits_count; // bits per RGBA
size_t image_size; // image rgba size
uint image_ptr;
byte *image_palette; // palette pointer
byte *image_rgba; // image pointer (see image_type for details)
// cubemap variables
int cubemap_width, cubemap_height;
int cubemap_num_sides; // how mach sides is loaded
byte *image_cubemap; // cubemap pack
uint cubemap_image_type; // shared image type
const char *suf[6] = { "ft", "bk", "rt", "lf", "up", "dn" };
typedef struct loadformat_s
{
char *formatstring;
char *ext;
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
} loadformat_t;
loadformat_t load_formats[] =
{
{"textures/%s%s.%s", "dds", Image_LoadDDS},
{"textures/%s%s.%s", "tga", Image_LoadTGA},
{"%s%s.%s", "dds", Image_LoadDDS},
{"%s%s.%s", "tga", Image_LoadTGA},
{NULL, NULL}
};
rgbdata_t *ImagePack( void )
{
rgbdata_t *pack = Mem_Alloc( zonepool, sizeof(rgbdata_t));
if( image_cubemap && cubemap_num_sides != 6 )
{
// this neved be happens, just in case
MsgDev( D_NOTE, "ImagePack: inconsistent cubemap pack %d\n", cubemap_num_sides );
Image_FreeImage( pack );
return NULL;
}
if( image_cubemap )
{
image_flags |= IMAGE_CUBEMAP;
pack->buffer = image_cubemap;
pack->width = cubemap_width;
pack->height = cubemap_height;
pack->type = cubemap_image_type;
pack->size = image_size * cubemap_num_sides;
}
else
{
pack->buffer = image_rgba;
pack->width = image_width;
pack->height = image_height;
pack->type = image_type;
pack->size = image_size;
}
pack->numLayers = image_num_layers;
pack->numMips = image_num_mips;
pack->bitsCount = image_bits_count;
pack->flags = image_flags;
pack->palette = image_palette;
return pack;
}
bool FS_AddImageToPack( const char *name )
{
byte *resampled;
// first image have suffix "ft" and set average size for all cubemap sides!
if(!image_cubemap)
{
cubemap_width = image_width;
cubemap_height = image_height;
cubemap_image_type = image_type;
}
image_size = cubemap_width * cubemap_height * 4; // keep constant size, render.dll expecting it
// mixing dds format with any existing ?
if(image_type != cubemap_image_type) return false;
// resampling image if needed
resampled = Image_ResampleInternal((uint *)image_rgba, image_width, image_height, cubemap_width, cubemap_height, cubemap_image_type );
if(!resampled) return false; // try to reasmple dxt?
if( resampled != image_rgba ) Mem_Move( zonepool, &image_rgba, resampled, image_size ); // update buffer
image_cubemap = Mem_Realloc( zonepool, image_cubemap, image_ptr + image_size );
Mem_Copy(image_cubemap + image_ptr, image_rgba, image_size );
Mem_Free( image_rgba ); // memmove aren't help us
image_ptr += image_size; // move to next
cubemap_num_sides++; // sides counter
return true;
}
/*
================
FS_LoadImage
loading and unpack to rgba any known image
================
*/
rgbdata_t *Image_Load(const char *filename, const byte *buffer, size_t buffsize )
{
loadformat_t *format;
const char *ext = FS_FileExtension( filename );
char path[128], loadname[128], texname[128];
bool anyformat = !com.stricmp(ext, "") ? true : false;
int i, filesize = 0;
byte *f;
#if 0 // don't try to be very clever
if(!buffer || !buffsize) buffer = (char *)florr1_2_jpg, buffsize = sizeof(florr1_2_jpg);
#endif
com.strncpy( loadname, filename, sizeof(loadname)-1);
FS_StripExtension( loadname ); //remove extension if needed
// developer warning
if(!anyformat) MsgDev(D_NOTE, "Note: %s will be loading only with ext .%s\n", loadname, ext );
// now try all the formats in the selected list
for (format = load_formats; format->formatstring; format++)
{
if( anyformat || !com.stricmp(ext, format->ext ))
{
com.sprintf (path, format->formatstring, loadname, "", format->ext );
f = FS_LoadFile( path, &filesize );
if(f && filesize > 0)
{
// this name will be used only for tell user about problems
FS_FileBase( path, texname );
if( format->loadfunc(texname, f, filesize ))
{
Mem_Free(f); // release buffer
return ImagePack(); // loaded
}
}
}
}
// maybe it skybox or cubemap ?
for( i = 0; i < 6; i++ )
{
for( format = load_formats; format->formatstring; format++ )
{
if( anyformat || !com.stricmp(ext, format->ext ))
{
com.sprintf (path, format->formatstring, loadname, suf[i], format->ext );
f = FS_LoadFile( path, &filesize );
if(f && filesize > 0)
{
// this name will be used only for tell user about problems
FS_FileBase( path, texname );
if( format->loadfunc(texname, f, filesize ))
{
if(FS_AddImageToPack(va("%s%s.%s", loadname, suf[i], format->ext)))
break; // loaded
}
Mem_Free(f);
}
}
}
if( cubemap_num_sides != i + 1 ) // check side
{
// first side not found, probably it's not cubemap
// it contain info about image_type and dimensions, don't generate black cubemaps
if(!image_cubemap) break;
MsgDev(D_ERROR, "FS_LoadImage: couldn't load (%s%s.%s), create black image\n",loadname,suf[i],ext );
// Mem_Alloc already filled memblock with 0x00, no need to do it again
image_cubemap = Mem_Realloc( zonepool, image_cubemap, image_ptr + image_size );
image_ptr += image_size; // move to next
cubemap_num_sides++; // merge counter
}
}
if(image_cubemap) return ImagePack(); // now it's cubemap pack
// try to load image from const buffer (e.g. const byte blank_frame )
com.strncpy( texname, filename, sizeof(texname) - 1);
for (format = load_formats; format->formatstring; format++)
{
if(anyformat || !com.stricmp(ext, format->ext ))
{
if(buffer && buffsize > 0)
{
// this name will be used only for tell user about problems
FS_FileBase( loadname, texname );
if( format->loadfunc(texname, buffer, buffsize ))
return ImagePack(); // loaded
}
}
}
MsgDev(D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", texname );
return NULL;
}
typedef struct saveformat_s
{
const char *formatstring;
const char *ext;
bool (*savefunc)( const char *name, rgbdata_t *pix, int saveformat );
} saveformat_t;
saveformat_t save_formats[] =
{
{"%s%s.%s", "tga", Image_SaveTGA},
{"%s%s.%s", "dds", Image_SaveDDS},
{NULL, NULL}
};
/*
================
Image_Save
writes image as any known format
================
*/
void Image_Save( const char *filename, rgbdata_t *pix )
{
saveformat_t *format;
const char *ext = FS_FileExtension( filename );
char path[128], savename[128];
bool anyformat = !com.stricmp(ext, "") ? true : false;
int filesize = 0;
byte *data;
bool has_alpha = false;
if(!pix || !pix->buffer) return;
if(pix->flags & IMAGE_HAS_ALPHA) has_alpha = true;
data = pix->buffer;
com.strncpy( savename, filename, sizeof(savename) - 1);
FS_StripExtension( savename ); // remove extension if needed
// developer warning
if(!anyformat) MsgDev(D_NOTE, "Note: %s will be saving only with ext .%s\n", savename, ext );
// now try all the formats in the selected list
for (format = save_formats; format->formatstring; format++)
{
if( anyformat || !com.stricmp( ext, format->ext ))
{
com.sprintf( path, format->formatstring, savename, "", format->ext );
if( format->savefunc( path, pix, pix->hint ))
break; // saved
}
}
}
/*
================
Image_FreeImage
free RGBA buffer
================
*/
void Image_FreeImage( rgbdata_t *pack )
{
if( pack )
{
if( pack->buffer ) Mem_Free( pack->buffer );
if( pack->palette ) Mem_Free( pack->palette );
Mem_Free( pack );
}
// reset global variables
image_width = image_height = 0;
cubemap_width = cubemap_height = 0;
image_bits_count = image_flags = 0;
cubemap_num_sides = 0;
image_num_layers = 1;
image_num_mips = 0;
image_type = PF_UNKNOWN;
image_palette = NULL;
image_rgba = NULL;
image_cubemap = NULL;
image_ptr = 0;
image_size = 0;
}

View File

@ -1,47 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_main.c - image processing library
//=======================================================================
#include "imagelib.h"
stdlib_api_t com;
byte *zonepool;
int app_name = 0;
cvar_t *img_resample_lerp;
void ImageLib_Init ( void )
{
// init pools
zonepool = Mem_AllocPool( "ImageLib Pool" );
app_name = g_Instance;
img_resample_lerp = Cvar_Get( "img_lerping", "1", CVAR_SYSTEMINFO, "lerping images after resample" );
}
void ImageLib_Free ( void )
{
Mem_Check(); // check for leaks
Mem_FreePool( &zonepool );
}
imglib_exp_t DLLEXPORT *CreateAPI( stdlib_api_t *input, void *unused )
{
static imglib_exp_t Com;
com = *input;
// generic functions
Com.api_size = sizeof(imglib_exp_t);
Com.Init = ImageLib_Init;
Com.Free = ImageLib_Free;
Com.LoadImage = Image_Load;
Com.SaveImage = Image_Save;
Com.DecompressDXTC = Image_DecompressDXTC;
Com.DecompressARGB = Image_DecompressARGB;
Com.ResampleImage = Image_Resample;
Com.FreeImage = Image_FreeImage;
return &Com;
}

View File

@ -1,100 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_mip.c - hl1 q1 image mips
//=======================================================================
#include "imagelib.h"
#include "byteorder.h"
#include "img_formats.h"
/*
=============
Image_LoadMIP
=============
*/
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize )
{
dmip_t mip;
byte *fin, *pal;
int ofs[4], rendermode;
int i, k, l, pixels, numcolors;
if( filesize < (int)sizeof(mip))
{
MsgDev( D_ERROR, "Image_LoadMIP: file (%s) have invalid size\n", name );
return false;
}
memset( &pic, 0, sizeof(pic));
Mem_Copy(&mip, buffer, sizeof(mip));
pic.width = LittleLong(mip.width);
pic.height = LittleLong(mip.height);
for(i = 0; i < 4; i++) ofs[i] = LittleLong(mip.offsets[i]);
pixels = pic.width * pic.height;
pic.numLayers = 1;
pic.type = PF_RGBA_32;
if(!com.stricmp( savedname, "gfx/conchars" ))
{
// greatest hack from id software
pic.width = pic.height = 128;
pic.flags |= IMAGE_HAS_ALPHA;
rendermode = LUMP_QFONT;
pixels = pic.width * pic.height;
pal = NULL; // clear palette
fin = buffer;
com.snprintf( filepath, MAX_STRING, "%s/gfx/%s.tga", gs_gamedir, savedname );
}
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] + (((pic.width * pic.height) * 85)>>6);
numcolors = BuffLittleShort( pal );
if(numcolors != 256) pal = NULL; // corrupted mip ?
else pal += sizeof(short); // skip colorsize
// detect rendermode
if( com.strchr( savedname, '{' ))
{
// qlumpy used this color for transparent textures, otherwise it's decals
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255)
rendermode = LUMP_TRANSPARENT;
else rendermode = LUMP_DECAL;
pic.flags |= IMAGE_HAS_ALPHA;
}
else rendermode = LUMP_NORMAL;
com.snprintf( filepath, MAX_STRING, "%s/textures/%s.tga", gs_gamedir, savedname );
}
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];
com.snprintf( filepath, MAX_STRING, "%s/textures/%s.tga", gs_gamedir, savedname );
}
else
{
MsgDev( D_ERROR, "LoadMIP: lump (%s) is corrupted\n", savedname );
return false;
}
if(!Lump_ValidSize( savedname, &pic, 640, 640 )) return false;
pic.size = pixels * 4;
pic.buffer = (byte *)Mem_Alloc(zonepool, pic.size );
Conv_GetPaletteLMP( pal, rendermode );
Conv_Copy8bitRGBA( fin, pic.buffer, pixels );
Image->SaveImage( filepath, &pic ); // save converted image
Conv_CreateShader( name, &pic, "mip", NULL, 0, 0 );
Mem_Free( pic.buffer ); // release buffer
Msg("%s.mip\n", savedname ); // echo to console about current texture
return true;
}
bool Image_SaveMIP( const char *name, rgbdata_t *pix, int saveformat )
{
return false;
}

View File

@ -1,471 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_resample.c - resample 24 or 32-bit buffer
//=======================================================================
#include "imagelib.h"
#define LERPBYTE(i) r = resamplerow1[i];out[i] = (byte)((((resamplerow2[i] - r) * lerp)>>16) + r)
void Image_RoundDimensions( int *scaled_width, int *scaled_height )
{
int width, height;
for( width = 1; width < *scaled_width; width <<= 1 );
for( height = 1; height < *scaled_height; height <<= 1 );
*scaled_width = bound( 1, width, IMAGE_MAXWIDTH );
*scaled_height = bound( 1, height, IMAGE_MAXHEIGHT );
}
static void Image_Resample32LerpLine (const byte *in, byte *out, int inwidth, int outwidth)
{
int j, xi, oldx = 0, f, fstep, endx, lerp;
fstep = (int)(inwidth * 65536.0f/outwidth);
endx = (inwidth-1);
for( j = 0, f = 0; j < outwidth; j++, f += fstep )
{
xi = f>>16;
if( xi != oldx )
{
in += (xi - oldx) * 4;
oldx = xi;
}
if( xi < endx )
{
lerp = f & 0xFFFF;
*out++ = (byte)((((in[4] - in[0]) * lerp)>>16) + in[0]);
*out++ = (byte)((((in[5] - in[1]) * lerp)>>16) + in[1]);
*out++ = (byte)((((in[6] - in[2]) * lerp)>>16) + in[2]);
*out++ = (byte)((((in[7] - in[3]) * lerp)>>16) + in[3]);
}
else // last pixel of the line has no pixel to lerp to
{
*out++ = in[0];
*out++ = in[1];
*out++ = in[2];
*out++ = in[3];
}
}
}
static void Image_Resample24LerpLine( const byte *in, byte *out, int inwidth, int outwidth )
{
int j, xi, oldx = 0, f, fstep, endx, lerp;
fstep = (int)(inwidth * 65536.0f/outwidth);
endx = (inwidth-1);
for( j = 0, f = 0; j < outwidth; j++, f += fstep )
{
xi = f>>16;
if( xi != oldx )
{
in += (xi - oldx) * 3;
oldx = xi;
}
if( xi < endx )
{
lerp = f & 0xFFFF;
*out++ = (byte)((((in[3] - in[0]) * lerp)>>16) + in[0]);
*out++ = (byte)((((in[4] - in[1]) * lerp)>>16) + in[1]);
*out++ = (byte)((((in[5] - in[2]) * lerp)>>16) + in[2]);
}
else // last pixel of the line has no pixel to lerp to
{
*out++ = in[0];
*out++ = in[1];
*out++ = in[2];
}
}
}
void Image_Resample32Lerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
{
int i, j, r, yi, oldy = 0, f, fstep, lerp, endy = (inheight - 1);
int inwidth4 = inwidth * 4;
int outwidth4 = outwidth * 4;
const byte *inrow;
byte *out;
byte *resamplerow1;
byte *resamplerow2;
out = (byte *)outdata;
fstep = (int)(inheight * 65536.0f/outheight);
resamplerow1 = (byte *)Mem_Alloc( zonepool, outwidth * 4 * 2);
resamplerow2 = resamplerow1 + outwidth * 4;
inrow = (const byte *)indata;
Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample32LerpLine( inrow + inwidth4, resamplerow2, inwidth, outwidth );
for( i = 0, f = 0; i < outheight; i++, f += fstep )
{
yi = f>>16;
if( yi < endy )
{
lerp = f & 0xFFFF;
if( yi != oldy )
{
inrow = (byte *)indata + inwidth4 * yi;
if (yi == oldy+1) Mem_Copy( resamplerow1, resamplerow2, outwidth4 );
else Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample32LerpLine( inrow + inwidth4, resamplerow2, inwidth, outwidth );
oldy = yi;
}
j = outwidth - 4;
while( j >= 0 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
LERPBYTE( 8);
LERPBYTE( 9);
LERPBYTE(10);
LERPBYTE(11);
LERPBYTE(12);
LERPBYTE(13);
LERPBYTE(14);
LERPBYTE(15);
out += 16;
resamplerow1 += 16;
resamplerow2 += 16;
j -= 4;
}
if( j & 2 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
out += 8;
resamplerow1 += 8;
resamplerow2 += 8;
}
if( j & 1 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
out += 4;
resamplerow1 += 4;
resamplerow2 += 4;
}
resamplerow1 -= outwidth4;
resamplerow2 -= outwidth4;
}
else
{
if( yi != oldy )
{
inrow = (byte *)indata + inwidth4*yi;
if( yi == oldy + 1 ) Mem_Copy( resamplerow1, resamplerow2, outwidth4 );
else Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth);
oldy = yi;
}
Mem_Copy( out, resamplerow1, outwidth4 );
}
}
Mem_Free( resamplerow1 );
resamplerow1 = NULL;
resamplerow2 = NULL;
}
void Image_Resample32Nolerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j;
uint frac, fracstep;
int *inrow, *out = (int *)outdata; // relies on int being 4 bytes
fracstep = inwidth * 0x10000/outwidth;
for( i = 0; i < outheight; i++)
{
inrow = (int *)indata + inwidth * (i * inheight/outheight);
frac = fracstep>>1;
j = outwidth - 4;
while( j >= 0 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out[1] = inrow[frac >> 16];frac += fracstep;
out[2] = inrow[frac >> 16];frac += fracstep;
out[3] = inrow[frac >> 16];frac += fracstep;
out += 4;
j -= 4;
}
if( j & 2 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out[1] = inrow[frac >> 16];frac += fracstep;
out += 2;
}
if( j & 1 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out += 1;
}
}
}
void Image_Resample24Lerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight - 1);
int inwidth3 = inwidth * 3;
int outwidth3 = outwidth * 3;
const byte *inrow;
byte *out = (byte *)outdata;
byte *resamplerow1;
byte *resamplerow2;
fstep = (int)(inheight * 65536.0f / outheight);
resamplerow1 = (byte *)Mem_Alloc(zonepool, outwidth * 3 * 2);
resamplerow2 = resamplerow1 + outwidth*3;
inrow = (const byte *)indata;
oldy = 0;
Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample24LerpLine( inrow + inwidth3, resamplerow2, inwidth, outwidth );
for( i = 0, f = 0; i < outheight; i++, f += fstep )
{
yi = f>>16;
if( yi < endy )
{
lerp = f & 0xFFFF;
if( yi != oldy )
{
inrow = (byte *)indata + inwidth3 * yi;
if( yi == oldy + 1) Mem_Copy( resamplerow1, resamplerow2, outwidth3 );
else Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample24LerpLine( inrow + inwidth3, resamplerow2, inwidth, outwidth );
oldy = yi;
}
j = outwidth - 4;
while( j >= 0 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
LERPBYTE( 8);
LERPBYTE( 9);
LERPBYTE(10);
LERPBYTE(11);
out += 12;
resamplerow1 += 12;
resamplerow2 += 12;
j -= 4;
}
if( j & 2 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
out += 6;
resamplerow1 += 6;
resamplerow2 += 6;
}
if( j & 1 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
out += 3;
resamplerow1 += 3;
resamplerow2 += 3;
}
resamplerow1 -= outwidth3;
resamplerow2 -= outwidth3;
}
else
{
if( yi != oldy )
{
inrow = (byte *)indata + inwidth3*yi;
if( yi == oldy + 1) Mem_Copy( resamplerow1, resamplerow2, outwidth3 );
else Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
oldy = yi;
}
Mem_Copy( out, resamplerow1, outwidth3 );
}
}
Mem_Free( resamplerow1 );
resamplerow1 = NULL;
resamplerow2 = NULL;
}
void Image_Resample24Nolerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j, f, inwidth3 = inwidth * 3;
uint frac, fracstep;
byte *inrow, *out = (byte *)outdata;
fracstep = inwidth * 0x10000/outwidth;
for( i = 0; i < outheight; i++)
{
inrow = (byte *)indata + inwidth3 * (i * inheight/outheight);
frac = fracstep>>1;
j = outwidth - 4;
while( j >= 0 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
j -= 4;
}
if( j & 2 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
out += 2;
}
if( j & 1 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
out += 1;
}
}
}
/*
================
Image_Resample
================
*/
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int type )
{
bool quality = img_resample_lerp->integer;
byte *outdata;
// nothing to resample ?
if (inwidth == outwidth && inheight == outheight)
return (byte *)indata;
// malloc new buffer
switch( type )
{
case PF_RGB_24:
case PF_RGB_24_FLIP:
outdata = (byte *)Mem_Alloc( zonepool, outwidth * outheight * 3 );
if( quality ) Image_Resample24Lerp( indata, inwidth, inheight, outdata, outwidth, outheight );
else Image_Resample24Nolerp( indata, inwidth, inheight, outdata, outwidth, outheight );
break;
case PF_RGBA_32:
outdata = (byte *)Mem_Alloc( zonepool, outwidth * outheight * 4 );
if( quality ) Image_Resample32Lerp( indata, inwidth, inheight, outdata, outwidth, outheight );
else Image_Resample32Nolerp( indata, inwidth, inheight, outdata, outwidth, outheight );
break;
default:
MsgDev( D_WARN, "Image_Resample: unsupported format %s\n", PFDesc[type].name );
return (byte *)indata;
}
return (byte *)outdata;
}
bool Image_Resample( const char *name, rgbdata_t **image, int width, int height, bool free_baseimage )
{
int w, h, pixel;
rgbdata_t *pix = *image;
byte *out;
// check for buffers
if(!pix || !pix->buffer) return false;
w = pix->width;
h = pix->height;
if( width && height )
{
// custom size
w = bound(4, width, IMAGE_MAXWIDTH ); // maxwidth 4096
h = bound(4, height, IMAGE_MAXHEIGHT); // maxheight 4096
}
else Image_RoundDimensions( &w, &h ); // auto detect new size
out = Image_ResampleInternal((uint *)pix->buffer, pix->width, pix->height, w, h, pix->type );
if( out != pix->buffer )
{
switch( pix->type )
{
case PF_RGBA_32:
pixel = 4;
break;
case PF_RGB_24:
case PF_RGB_24_FLIP:
pixel = 3;
break;
default:
pixel = 4;
}
// if image was resampled
MsgDev(D_NOTE, "Resampling %s from[%d x %d] to [%d x %d]\n", name, pix->width, pix->height, w, h );
if( free_baseimage ) Mem_Free( pix->buffer ); // free original image buffer
// change image params
pix->buffer = out;
pix->width = w, pix->height = h;
pix->size = w * h * pixel;
*image = pix;
return true;
}
return false;
}

View File

@ -1,19 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_utils.c - misc common utils
//=======================================================================
#include "imagelib.h"
//=======================================================================
// IMGLIB COMMON TOOLS
//=======================================================================
bool Image_ValidSize( const char *name )
{
if( image_width > IMAGE_MAXWIDTH || image_height > IMAGE_MAXHEIGHT || image_width <= 0 || image_height <= 0 )
{
MsgDev( D_WARN, "Image_ValidSize: (%s) dimensions out of range [%dx%d]\n",name, image_width, image_height );
return false;
}
return true;
}

View File

@ -1,152 +0,0 @@
# Microsoft Developer Studio Project File - Name="imglib" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=imglib - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "imglib.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "imglib.mak" CFG="imglib - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "imglib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "imglib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "imglib - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\temp\imglib\!release"
# PROP Intermediate_Dir "..\temp\imglib\!release"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PLATFORM_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "./" /I "../public" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /opt:nowin98
# ADD LINK32 msvcrt.lib /nologo /dll /profile /machine:I386 /nodefaultlib:"libc.lib" /opt:nowin98
# Begin Custom Build
TargetDir=\XASH3D\src_main\temp\imglib\!release
InputPath=\XASH3D\src_main\temp\imglib\!release\imglib.dll
SOURCE="$(InputPath)"
"D:\Xash3D\bin\imglib.dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(TargetDir)\imglib.dll "D:\Xash3D\bin\imglib.dll"
# End Custom Build
!ELSEIF "$(CFG)" == "imglib - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\temp\imglib\!debug"
# PROP Intermediate_Dir "..\temp\imglib\!debug"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PLATFORM_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /Gi /GX /ZI /I "./" /I "../public" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 msvcrt.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /pdbtype:sept
# SUBTRACT LINK32 /incremental:no /nodefaultlib
# Begin Custom Build
TargetDir=\XASH3D\src_main\temp\imglib\!debug
InputPath=\XASH3D\src_main\temp\imglib\!debug\imglib.dll
SOURCE="$(InputPath)"
"D:\Xash3D\bin\imglib.dll" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy $(TargetDir)\imglib.dll "D:\Xash3D\bin\imglib.dll"
# End Custom Build
!ENDIF
# Begin Target
# Name "imglib - Win32 Release"
# Name "imglib - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\img_dds.c
# End Source File
# Begin Source File
SOURCE=.\img_loadsave.c
# End Source File
# Begin Source File
SOURCE=.\img_main.c
# End Source File
# Begin Source File
SOURCE=.\img_resample.c
# End Source File
# Begin Source File
SOURCE=.\img_tga.c
# End Source File
# Begin Source File
SOURCE=.\img_utils.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\img_formats.h
# End Source File
# Begin Source File
SOURCE=.\imglib.h
# End Source File
# End Group
# End Target
# End Project

View File

@ -1,103 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2006
// All Rights Reserved
// zip32.h - zlib custom build
//=======================================================================
#ifndef COM_ZLIB_H
#define COM_ZLIB_H
/*
========================================================================
PAK FILES
The .pak files are just a linear collapse of a directory tree
========================================================================
*/
// header
#define IDPACKV1HEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P') // little-endian "PACK"
#define IDPACKV2HEADER (('2'<<24)+('K'<<16)+('A'<<8)+'P') // little-endian "PAK2"
#define IDPACKV3HEADER (('\4'<<24)+('\3'<<16)+('K'<<8)+'P') // little-endian "PK\3\4"
#define IDPK3CDRHEADER (('\2'<<24)+('\1'<<16)+('K'<<8)+'P') // little-endian "PK\1\2"
#define IDPK3ENDHEADER (('\6'<<24)+('\5'<<16)+('K'<<8)+'P') // little-endian "PK\5\6"
#define MAX_FILES_IN_PACK 65536 // pack\pak2
typedef struct
{
int ident;
int dirofs;
int dirlen;
} dpackheader_t;
typedef struct
{
char name[56]; // total 64 bytes
int filepos;
int filelen;
} dpackfile_t;
typedef struct
{
char name[116]; // total 128 bytes
int filepos;
int filelen;
uint attribs; // file attributes
} dpak2file_t;
typedef struct
{
int ident;
word disknum;
word cdir_disknum; // number of the disk with the start of the central directory
word localentries; // number of entries in the central directory on this disk
word nbentries; // total number of entries in the central directory on this disk
uint cdir_size; // size of the central directory
uint cdir_offset; // with respect to the starting disk number
word comment_size;
} dpak3file_t;
#define ZLIB_VERSION "1.2.3"
#define MAX_WBITS 15
// zlib errors
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_SYNC_FLUSH 2
#define Z_FINISH 4
typedef struct z_stream_s
{
byte *next_in; // next input byte
uint avail_in; // number of bytes available at next_in
dword total_in; // total nb of input bytes read so far
byte *next_out; // next output byte should be put there
uint avail_out; // remaining free space at next_out
dword total_out; // total nb of bytes output so far
char *msg; // last error message, NULL if no error
byte *state; // not visible by applications
byte* (*zalloc)(); // used to allocate the internal state
void (*zfree)(); // used to free the internal state
byte* opaque; // private data object passed to zalloc and zfree
int data_type; // best guess about the data type: binary or text
dword adler; // adler32 value of the uncompressed data
dword reserved; // reserved for future use
} z_stream;
// exported functions
extern int inflate(z_stream *strm, int flush);
extern int inflateEnd(z_stream *strm);
extern int inflateInit_(z_stream *strm, const char *version, int stream_size);
extern int inflateInit2_(z_stream *strm, int windowBits, const char *version, int stream_size);
extern int inflateReset(z_stream *strm);
extern int deflate (z_stream *strm, int flush);
extern int deflateEnd (z_stream *strm);
extern int deflateInit_(z_stream *strm, int level, const char *version, int stream_size);
extern int deflateInit2_ (z_stream *strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size);
extern int deflateReset (z_stream *strm);
#define inflateInit(strm) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) deflateInit2_((strm),(level),(method),(windowBits),(memLevel),(strategy), ZLIB_VERSION, sizeof(z_stream))
#endif//COM_ZLIB_H

View File

@ -1,62 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// logging.c - std lib portable utils
//=======================================================================
#include "launch.h"
void Sys_InitLog( void )
{
const char *mode;
if( Sys.app_state == SYS_RESTART )
mode = "a";
else mode = "w";
// create log if needed
if( Sys.log_active && !Sys.con_silentmode )
{
Sys.logfile = FS_Open( Sys.log_path, mode );
if(!Sys.logfile) MsgDev( D_ERROR, "Sys_InitLog: can't create log file %s\n", Sys.log_path );
FS_Print( Sys.logfile, "=======================================================================\n" );
FS_Printf( Sys.logfile, "\t%s started at %s\n", Sys.caption, com_timestamp(TIME_FULL));
FS_Print( Sys.logfile, "=======================================================================\n");
FS_Print( Sys.logfile, Sys.log_buffer ); // write all queued messages
Sys.log_buffer[0] = '\0';
}
}
void Sys_CloseLog( void )
{
string event_name;
// continue logged
switch( Sys.app_state )
{
case SYS_ABORT: com_strncpy( event_name, "aborted by user", MAX_STRING ); break;
case SYS_ERROR: com_strncpy( event_name, "stopped with error", MAX_STRING ); break;
case SYS_RESTART: com_strncpy( event_name, "restarted", MAX_STRING ); break;
default: com_strncpy( event_name, "stopped", MAX_STRING ); break;
}
if( Sys.logfile )
{
FS_Print( Sys.logfile, "\n");
FS_Print( Sys.logfile, "=======================================================================");
FS_Printf( Sys.logfile, "\n\t%s %s at %s\n", Sys.caption, event_name, com_timestamp(TIME_FULL));
FS_Print( Sys.logfile, "=======================================================================\n");
if( Sys.app_state == SYS_RESTART ) FS_Print( Sys.logfile, "\n" ); // just for tabulate
FS_Close( Sys.logfile );
Sys.logfile = NULL;
}
}
void Sys_PrintLog( const char *pMsg )
{
if( !Sys.log_active ) return;
if( !Sys.logfile ) // copy message into queued buffer
com_strncat( Sys.log_buffer, pMsg, LOG_QUEUE_SIZE );
else FS_Print( Sys.logfile, pMsg ); // normal logging
}

View File

@ -1,24 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = credits
OBJS = $(MAINTARGET).obj
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj
$(link) $(OBJS) /out:"credits.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
@copy $(MAINTARGET).exe D:\Xash3D\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘Ş®Ż¨ŕ®˘ ­® ä ©«®˘: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<

View File

@ -4,4 +4,4 @@
#include "../rundll.h"
Run( qccdec );
Run( ripper );

View File

@ -0,0 +1,28 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,8
#define VER_FILEVERSION_STR "0.8"
#define VER_PRODUCTVERSION 0,8
#define VER_PRODUCTVERSION_STR "0.8"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2008"
#define VER_PRODUCTNAME_STR "extragen"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Quake Resource Extractor"
#define VER_ORIGINALFILENAME_STR "extragen.exe"
#define VER_INTERNALNAME_STR "qrip"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

View File

@ -7,14 +7,14 @@
!include <win32.mak>
MAINTARGET = qcclib
MAINTARGET = extragen
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj qcclib.res
$(link) $(OBJS) qcclib.res /out:"qcclib.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
$(MAINTARGET).exe: $(MAINTARGET).obj extragen.res
$(link) $(OBJS) extragen.res /out:"extragen.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@ -24,5 +24,5 @@ clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
qcclib.res : qcclib.rc
$(RC) $(RCFLAGS) /r qcclib.rc
extragen.res : extragen.rc
$(RC) $(RCFLAGS) /r extragen.rc

View File

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1042,9 +1042,6 @@ static bool FS_AddWad3File( const char *filename )
case IDWAD3HEADER:
com_strncpy( type, "Half-Life", 16 );
break;
case IDWAD4HEADER:
com_strncpy( type, "Xash3D", 16 );
break;
default:
MsgDev(D_ERROR, "FS_AddWad3File: %s have invalid ident\n", filename );
FS_Close( file );
@ -1146,7 +1143,6 @@ static bool FS_AddWad3File( const char *filename )
break;
case IDWAD2HEADER:
case IDWAD3HEADER:
case IDWAD4HEADER:
if(FS_Read( file, w->lumps, sizeof(dlumpinfo_t)*w->numlumps) != (long)sizeof(dlumpinfo_t)*numlumps)
{
MsgDev(D_ERROR, "FS_AddWad3File: unable to read lump table\n");
@ -1161,7 +1157,7 @@ static bool FS_AddWad3File( const char *filename )
}
// swap everthing
for (i = 0; i < numlumps; i++)
for( i = 0; i < numlumps; i++ )
{
w->lumps[i].filepos = LittleLong(w->lumps[i].filepos);
w->lumps[i].disksize = LittleLong(w->lumps[i].disksize);
@ -1501,7 +1497,7 @@ void FS_Init( void )
Cbuf_Execute(); // apply system cvars immediately
// ignore commandlineoption "-game" for other stuff
if(Sys.app_name == HOST_NORMAL || Sys.app_name == HOST_DEDICATED || Sys.app_name == COMP_BSPLIB)
if( Sys.app_name == HOST_NORMAL || Sys.app_name == HOST_DEDICATED || Sys.app_name == HOST_BSPLIB )
{
stringlistinit(&dirs);
listdirectory(&dirs, "./");
@ -1510,7 +1506,7 @@ void FS_Init( void )
if(!FS_GetParmFromCmdLine("-game", gs_basedir ))
{
if( Sys.app_name == COMP_BSPLIB )
if( Sys.app_name == HOST_BSPLIB )
com_strcpy( gs_basedir, fs_defaultdir->string );
else if(Sys_GetModuleName( gs_basedir, MAX_SYSPATH ));
else com_strcpy( gs_basedir, fs_defaultdir->string ); // default dir
@ -1549,11 +1545,8 @@ void FS_Init( void )
// enable temporary wad support for some tools
switch( Sys.app_name )
{
case COMP_WADLIB:
case RIPP_MIPDEC:
case RIPP_MDLDEC:
case RIPP_LMPDEC:
case RIPP_SNDDEC:
case HOST_WADLIB:
case HOST_RIPPER:
fs_use_wads = true;
break;
default:
@ -1925,12 +1918,15 @@ wadtype_t wad_types[] =
{"mip", TYPE_MIPTEX2}, // hl texture
{"mip", TYPE_MIPTEX }, // quake1 mip
{"raw", TYPE_RAW }, // signed raw data
{"fnt", TYPE_QFONT }, // qfont structure (e.g. fonts.wad in hl1)
{"dat", TYPE_VPROGS }, // QC progs
{"txt", TYPE_SCRIPT }, // txt script file
{"dds", TYPE_GFXPIC }, // any known image
{"tga", TYPE_GFXPIC }, // any known image
{NULL, TYPE_NONE }
{"txt", TYPE_SCRIPT }, // xash script file
{"lst", TYPE_SCRIPT }, // xash script file
{"aur", TYPE_SCRIPT }, // xash aurora file
{"qc", TYPE_SCRIPT }, // xash qc-script file
{"qh", TYPE_SCRIPT }, // xash qc-header file
{"c", TYPE_SCRIPT }, // xash c-source file
{"h", TYPE_SCRIPT }, // xash c-header file
{"dat", TYPE_VPROGS }, // xash progs
{ NULL, TYPE_NONE }
};
/*
@ -1955,7 +1951,7 @@ static byte *FS_OpenWadFile( const char *name, fs_offset_t *filesizeptr, int mat
FS_FileBase( name, basename );
if(filesizeptr) *filesizeptr = 0;
if(com.strlen(basename) > WAD3_NAMELEN )
if(com_strlen(basename) > WAD3_NAMELEN )
{
Msg("FS_OpenWad3File: %s too long name\n", basename );
return NULL;
@ -2025,7 +2021,7 @@ byte *FS_LoadFileFromWAD( const char *path, fs_offset_t *filesizeptr )
byte *f;
// now try all the formats in the selected list
for (type = wad_types; type->ext; type++)
for( type = wad_types; type->ext; type++ )
{
if(anyformat || !com_stricmp( ext, type->ext ))
{
@ -2559,7 +2555,7 @@ byte *FS_LoadFile (const char *path, fs_offset_t *filesizeptr )
const char *ext = FS_FileExtension( path );
file = _FS_Open( path, "rb", true );
if (file)
if( file )
{
filesize = file->real_length;
buf = (byte *)Mem_Alloc( fs_mempool, filesize + 1 );
@ -2985,6 +2981,13 @@ void FS_SaveEnvironmentVariables( char *pPath )
SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_NORMAL, 10, NULL); // system update message
}
void FS_FreeEnvironmentVariables( void )
{
// save new path
REG_SetValue(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\Session Manager\\Environment", "Xash3D", "" );
SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_NORMAL, 10, NULL); // system update message
}
static void FS_BuildPath( char *pPath, char *pOut )
{
// set working directory
@ -3039,15 +3042,15 @@ VIRTUAL FILE SYSTEM - WRITE DATA INTO MEMORY
=============================================================================
*/
vfile_t *VFS_Create(byte *buffer, size_t buffsize)
vfile_t *VFS_Create( const byte *buffer, size_t buffsize)
{
vfile_t *file = (vfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
vfile_t *file = (vfile_t *)Mem_Alloc( fs_mempool, sizeof (*file));
file->length = file->buffsize = buffsize;
file->buff = Mem_Alloc(fs_mempool, (file->buffsize));
file->offset = 0;
file->mode = O_RDONLY;
Mem_Copy(file->buff, buffer, buffsize );
Mem_Copy( file->buff, buffer, buffsize );
return file;
}

466
launch/filesystem.h Normal file
View File

@ -0,0 +1,466 @@
//=======================================================================
// Copyright (C) XashXT Group 2006
// All Rights Reserved
// zip32.h - zlib custom build
//=======================================================================
#ifndef COM_ZLIB_H
#define COM_ZLIB_H
/*
========================================================================
.PCX image format (ZSoft Paintbrush)
========================================================================
*/
typedef struct
{
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
word xmin,ymin,xmax,ymax;
word hres,vres;
byte palette[48];
char reserved;
char color_planes;
word bytes_per_line;
word palette_type;
char filler[58];
} pcx_t;
/*
========================================================================
.WAL image format (Wally textures)
========================================================================
*/
typedef struct wal_s
{
char name[32];
uint width, height;
uint offsets[4]; // four mip maps stored
char animname[32]; // next frame in animation chain
int flags;
int contents;
int value;
} wal_t;
/*
========================================================================
.LMP image format (Quake1 gfx lumps)
========================================================================
*/
typedef struct flat_s
{
short width;
short height;
short desc[2]; // probably not used
} flat_t;
/*
========================================================================
.LMP image format (Quake1 gfx lumps)
========================================================================
*/
typedef struct lmp_s
{
uint width;
uint height;
} lmp_t;
/*
========================================================================
.MIP image format (Quake1 textures)
========================================================================
*/
typedef struct mip_s
{
char name[16];
uint width, height;
uint offsets[4]; // four mip maps stored
} mip_t;
/*
========================================================================
.BMP image format
========================================================================
*/
typedef struct
{
char id[2]; //bmfh.bfType
dword fileSize; //bmfh.bfSize
dword reserved0; //bmfh.bfReserved1 + bmfh.bfReserved2
dword bitmapDataOffset; //bmfh.bfOffBits
dword bitmapHeaderSize; //bmih.biSize
dword width; //bmih.biWidth
dword height; //bmih.biHeight
word planes; //bmih.biPlanes
word bitsPerPixel; //bmih.biBitCount
dword compression; //bmih.biCompression
dword bitmapDataSize; //bmih.biSizeImage
dword hRes; //bmih.biXPelsPerMeter
dword vRes; //bmih.biYPelsPerMeter
dword colors; //bmih.biClrUsed
dword importantColors; //bmih.biClrImportant
byte palette[256][4]; //RGBQUAD palette
} bmp_t;
/*
========================================================================
.TGA image format (Truevision Targa)
========================================================================
*/
typedef struct tga_s
{
byte id_length;
byte colormap_type;
byte image_type;
word colormap_index;
word colormap_length;
byte colormap_size;
word x_origin;
word y_origin;
word width;
word height;
byte pixel_size;
byte attributes;
} tga_t;
/*
========================================================================
.JPG image format
========================================================================
*/
typedef struct huffman_table_s
{
// Huffman coding tables
byte bits[16];
byte hval[256];
byte size[256];
word code[256];
} huffman_table_t;
typedef struct jpg_s
{
// not a real header
file_t *file; // file
byte *buffer; // jpg buffer
int width; // width image
int height; // height image
byte *data; // image
int data_precision; // bit per component
int num_components; // number component
int restart_interval; // restart interval
bool progressive_mode; // progressive format
struct
{
int id; // identifier
int h; // horizontal sampling factor
int v; // vertical sampling factor
int t; // quantization table selector
int td; // DC table selector
int ta; // AC table selector
} component_info[3]; // RGB (alpha not supported)
huffman_table_t hac[4]; // AC table
huffman_table_t hdc[4]; // DC table
int qtable[4][64]; // quantization table
struct
{
int ss,se; // progressive jpeg spectral selection
int ah,al; // progressive jpeg successive approx
} scan;
int dc[3];
int curbit;
byte curbyte;
} jpg_t;
/*
========================================================================
.DDS image format
========================================================================
*/
#define DDSHEADER ((' '<<24)+('S'<<16)+('D'<<8)+'D') // little-endian "DDS "
// various four-cc types
#define TYPE_DXT1 (('1'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT1"
#define TYPE_DXT3 (('3'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT3"
#define TYPE_DXT5 (('5'<<24)+('T'<<16)+('X'<<8)+'D') // little-endian "DXT5"
#define TYPE_$ (('\0'<<24)+('\0'<<16)+('\0'<<8)+'$') // little-endian "$"
#define TYPE_t (('\0'<<24)+('\0'<<16)+('\0'<<8)+'t') // little-endian "t"
#define DDS_CAPS 0x00000001L
#define DDS_HEIGHT 0x00000002L
#define DDS_WIDTH 0x00000004L
#define DDS_RGB 0x00000040L
#define DDS_PIXELFORMAT 0x00001000L
#define DDS_LUMINANCE 0x00020000L
#define DDS_ALPHAPIXELS 0x00000001L
#define DDS_ALPHA 0x00000002L
#define DDS_FOURCC 0x00000004L
#define DDS_PITCH 0x00000008L
#define DDS_COMPLEX 0x00000008L
#define DDS_CUBEMAP 0x00000200L
#define DDS_TEXTURE 0x00001000L
#define DDS_MIPMAPCOUNT 0x00020000L
#define DDS_LINEARSIZE 0x00080000L
#define DDS_VOLUME 0x00200000L
#define DDS_MIPMAP 0x00400000L
#define DDS_DEPTH 0x00800000L
#define DDS_CUBEMAP_POSITIVEX 0x00000400L
#define DDS_CUBEMAP_NEGATIVEX 0x00000800L
#define DDS_CUBEMAP_POSITIVEY 0x00001000L
#define DDS_CUBEMAP_NEGATIVEY 0x00002000L
#define DDS_CUBEMAP_POSITIVEZ 0x00004000L
#define DDS_CUBEMAP_NEGATIVEZ 0x00008000L
typedef struct dds_pf_s
{
uint dwSize;
uint dwFlags;
uint dwFourCC;
uint dwRGBBitCount;
uint dwRBitMask;
uint dwGBitMask;
uint dwBBitMask;
uint dwABitMask;
} dds_pixf_t;
// DDCAPS2
typedef struct dds_caps_s
{
uint dwCaps1;
uint dwCaps2;
uint dwCaps3;
uint dwCaps4;
} dds_caps_t;
typedef struct dds_s
{
uint dwIdent; // must matched with DDSHEADER
uint dwSize;
uint dwFlags; // determines what fields are valid
uint dwHeight;
uint dwWidth;
uint dwLinearSize; // Formless late-allocated optimized surface size
uint dwDepth; // depth if a volume texture
uint dwMipMapCount; // number of mip-map levels requested
uint dwAlphaBitDepth; // depth of alpha buffer requested
float fReflectivity[3]; // average reflectivity value
float fBumpScale; // bumpmapping scale factor
uint dwReserved1[6]; // reserved for future expansions
dds_pixf_t dsPixelFormat;
dds_caps_t dsCaps;
uint dwTextureStage;
} dds_t;
/*
========================================================================
PAK FILES
The .pak files are just a linear collapse of a directory tree
========================================================================
*/
// header
#define IDPACKV1HEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P') // little-endian "PACK"
#define IDPACKV2HEADER (('2'<<24)+('K'<<16)+('A'<<8)+'P') // little-endian "PAK2"
#define IDPACKV3HEADER (('\4'<<24)+('\3'<<16)+('K'<<8)+'P') // little-endian "PK\3\4"
#define IDPK3CDRHEADER (('\2'<<24)+('\1'<<16)+('K'<<8)+'P') // little-endian "PK\1\2"
#define IDPK3ENDHEADER (('\6'<<24)+('\5'<<16)+('K'<<8)+'P') // little-endian "PK\5\6"
#define MAX_FILES_IN_PACK 65536 // pack\pak2
typedef struct
{
int ident;
int dirofs;
int dirlen;
} dpackheader_t;
typedef struct
{
char name[56]; // total 64 bytes
int filepos;
int filelen;
} dpackfile_t;
typedef struct
{
char name[116]; // total 128 bytes
int filepos;
int filelen;
uint attribs; // file attributes
} dpak2file_t;
typedef struct
{
int ident;
word disknum;
word cdir_disknum; // number of the disk with the start of the central directory
word localentries; // number of entries in the central directory on this disk
word nbentries; // total number of entries in the central directory on this disk
uint cdir_size; // size of the central directory
uint cdir_offset; // with respect to the starting disk number
word comment_size;
} dpak3file_t;
#define IDIWADHEADER (('D'<<24)+('A'<<16)+('W'<<8)+'I') // little-endian "IWAD" doom1 game wad
#define IDPWADHEADER (('D'<<24)+('A'<<16)+('W'<<8)+'P') // little-endian "PWAD" doom1 game wad
#define IDWAD2HEADER (('2'<<24)+('D'<<16)+('A'<<8)+'W') // little-endian "WAD2" quake1 gfx.wad
#define TYPE_FLMP 59 // doom1 hud picture (doom1 mapped lump)
#define TYPE_SND 60 // doom1 wav sound (doom1 mapped lump)
#define TYPE_MUS 61 // doom1 music file (doom1 mapped lump)
#define TYPE_SKIN 62 // doom1 sprite model (doom1 mapped lump)
#define TYPE_FLAT 63 // doom1 wall texture (doom1 mapped lump)
// doom1 and doom2 lump header
typedef struct
{
int filepos;
int size;
char name[8]; // null not included
} dlumpfile_t;
#define ZLIB_VERSION "1.2.3"
#define MAX_WBITS 15
// zlib errors
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_SYNC_FLUSH 2
#define Z_FINISH 4
typedef struct z_stream_s
{
byte *next_in; // next input byte
uint avail_in; // number of bytes available at next_in
dword total_in; // total nb of input bytes read so far
byte *next_out; // next output byte should be put there
uint avail_out; // remaining free space at next_out
dword total_out; // total nb of bytes output so far
char *msg; // last error message, NULL if no error
byte *state; // not visible by applications
byte* (*zalloc)(); // used to allocate the internal state
void (*zfree)(); // used to free the internal state
byte* opaque; // private data object passed to zalloc and zfree
int data_type; // best guess about the data type: binary or text
dword adler; // adler32 value of the uncompressed data
dword reserved; // reserved for future use
} z_stream;
// zlib exported functions
extern int inflate(z_stream *strm, int flush);
extern int inflateEnd(z_stream *strm);
extern int inflateInit_(z_stream *strm, const char *version, int stream_size);
extern int inflateInit2_(z_stream *strm, int windowBits, const char *version, int stream_size);
extern int inflateReset(z_stream *strm);
extern int deflate (z_stream *strm, int flush);
extern int deflateEnd (z_stream *strm);
extern int deflateInit_(z_stream *strm, int level, const char *version, int stream_size);
extern int deflateInit2_ (z_stream *strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size);
extern int deflateReset (z_stream *strm);
#define inflateInit(strm) inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit(strm, level) deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) deflateInit2_((strm),(level),(method),(windowBits),(memLevel),(strategy), ZLIB_VERSION, sizeof(z_stream))
// imagelib definitions
#define IMAGE_MAXWIDTH 4096
#define IMAGE_MAXHEIGHT 4096
#define LERPBYTE(i) r = resamplerow1[i];out[i] = (byte)((((resamplerow2[i] - r) * lerp)>>16) + r)
#define LUMP_NORMAL 0
#define LUMP_TRANSPARENT 1
#define LUMP_DECAL 2
#define LUMP_QFONT 3
extern int image_width, image_height;
extern byte image_num_layers; // num layers in
extern byte image_num_mips; // build mipmaps
extern uint image_type; // main type switcher
extern uint image_flags; // additional image flags
extern byte image_bits_count; // bits per RGBA
extern size_t image_size; // image rgba size
extern byte *image_rgba; // image pointer (see image_type for details)
extern byte *image_palette; // palette pointer
extern uint *d_currentpal; // installed version of internal palette
extern cvar_t *img_oldformats;
bool Image_AddMipmapToPack( const byte *in, int width, int height, bool expand );
void Image_RoundDimensions( int *scaled_width, int *scaled_height );
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int intype );
void Image_FreeImage( rgbdata_t *pack );
void Image_Save( const char *filename, rgbdata_t *pix );
rgbdata_t *Image_Load(const char *filename, const byte *buffer, size_t buffsize );
bool Image_Copy8bitRGBA( const byte *in, byte *out, int pixels );
bool FS_AddMipmapToPack( const byte *in, int width, int height, bool expand );
vec_t Image_NormalizeColor( vec3_t in, vec3_t out );
bool Image_DecompressDXTC( rgbdata_t **image );
bool Image_DecompressARGB( rgbdata_t **image );
void Image_GetPaletteLMP( const byte *pal, int rendermode );
void Image_GetPalettePCX( const byte *pal );
void Image_CopyPalette24bit( void );
void Image_CopyPalette32bit( void );
void Image_GetPaletteQ2( void );
void Image_GetPaletteQ1( void );
void Image_GetPaletteD1( void ); // doom 2 on TNT :)
//
// formats load
//
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadBMP( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadJPG( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadPNG( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadPCX( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadLMP( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadWAL( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadFLT( const char *name, const byte *buffer, size_t filesize );
bool Image_LoadPAL( const char *name, const byte *buffer, size_t filesize );
//
// formats save
//
bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat );
bool Image_SaveDDS( const char *name, rgbdata_t *pix, int saveformat );
bool Image_SaveBMP( const char *name, rgbdata_t *pix, int saveformat );
bool Image_SavePNG( const char *name, rgbdata_t *pix, int saveformat );
//
// img_utils.c
//
bool Image_ValidSize( const char *name );
bool Image_DecompressDXTC( rgbdata_t **image ); // compilers version of decompressor
bool Image_DecompressARGB( rgbdata_t **image );
#endif//COM_ZLIB_H

241
launch/img_bmp.c Normal file
View File

@ -0,0 +1,241 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_bmp.c - bmp format load & save
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
/*
=============
Image_LoadBMP
=============
*/
bool Image_LoadBMP( const char *name, const byte *buffer, size_t filesize )
{
byte *buf_p, *pb, *pbBmpBits;
int i, columns, rows;
RGBQUAD rgrgbPalette[256];
dword cbBmpBits;
dword cbPalBytes;
dword biTrueWidth;
bmp_t bhdr;
buf_p = (byte *)buffer;
bhdr.id[0] = *buf_p++;
bhdr.id[1] = *buf_p++; // move pointer
bhdr.fileSize = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.reserved0 = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.bitmapDataOffset = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.bitmapHeaderSize = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.width = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.height = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.planes = LittleShort(*(short *)buf_p); buf_p += 2;
bhdr.bitsPerPixel = LittleShort(*(short *)buf_p); buf_p += 2;
bhdr.compression = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.bitmapDataSize = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.hRes = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.vRes = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.colors = LittleLong(*(long *)buf_p); buf_p += 4;
bhdr.importantColors = LittleLong(*(long *)buf_p); buf_p += 4;
memcpy( bhdr.palette, buf_p, sizeof( bhdr.palette ));
// bogus file header check
if( bhdr.reserved0 != 0 ) return false;
if( memcmp(bhdr.id, "BM", 2 ))
{
MsgDev( D_ERROR, "Image_LoadBMP: only Windows-style BMP files supported (%s)\n", name );
return false;
}
// bogus info header check
if( bhdr.fileSize != filesize )
{
MsgDev( D_ERROR, "Image_LoadBMP: incorrect file size %i should be %i\n", filesize, bhdr.fileSize );
return false;
}
// bogus bit depth? Only 8-bit supported.
if( bhdr.bitsPerPixel != 8 )
{
MsgDev( D_ERROR, "Image_LoadBMP: %d not a 8 bit image\n", bhdr.bitsPerPixel );
return false;
}
// bogus compression? Only non-compressed supported.
if( bhdr.compression != BI_RGB )
{
MsgDev( D_ERROR, "Image_LoadBMP: it's compressed file\n");
return false;
}
image_width = bhdr.width;
image_height = bhdr.height;
if(!Image_ValidSize( name ))
return false;
// figure out how many entires are actually in the table
if( bhdr.colors == 0 )
{
bhdr.colors = 256;
cbPalBytes = (1 << bhdr.bitsPerPixel) * sizeof( RGBQUAD );
}
else cbPalBytes = bhdr.colors * sizeof( RGBQUAD );
Mem_Copy( rgrgbPalette, &bhdr.palette, cbPalBytes ); // read palette (bmih.biClrUsed entries)
// convert to a packed 768 byte palette
image_palette = Mem_Alloc( Sys.imagepool, 768 );
pb = image_palette;
// copy over used entries
for( i = 0; i < (int)bhdr.colors; i++ )
{
*pb++ = rgrgbPalette[i].rgbRed;
*pb++ = rgrgbPalette[i].rgbGreen;
*pb++ = rgrgbPalette[i].rgbBlue;
}
// fill in unused entires will 0, 0, 0
for( i = bhdr.colors; i < 256; i++ )
{
*pb++ = 0;
*pb++ = 0;
*pb++ = 0;
}
// read bitmap bits (remainder of file)
columns = bhdr.width, rows = bhdr.height;
if ( rows < 0 ) rows = -rows;
cbBmpBits = columns * rows;
buf_p += 1024; // move pointer
pb = buf_p;
pbBmpBits = image_rgba = Mem_Alloc( Sys.imagepool, cbBmpBits );
// data is actually stored with the width being rounded up to a multiple of 4
biTrueWidth = (bhdr.width + 3) & ~3;
// reverse the order of the data.
pb += (bhdr.height - 1) * biTrueWidth;
for( i = 0; i < bhdr.height; i++ )
{
// FIXME: replace with Mem_Move
memmove(&pbBmpBits[biTrueWidth * i], pb, biTrueWidth);
pb -= biTrueWidth;
}
pb += biTrueWidth;
image_num_layers = image_num_mips = 1;
image_size = image_width * image_height;
// scan for transparency
for( i = 0; i < image_size; i++ )
{
if( pbBmpBits[i] == 255 )
{
image_flags |= IMAGE_HAS_ALPHA;
break;
}
}
image_type = (image_flags & IMAGE_HAS_ALPHA) ? PF_INDEXED_32 : PF_INDEXED_24;
return true;
}
bool Image_SaveBMP( const char *name, rgbdata_t *pix, int saveformat )
{
file_t *pfile = NULL;
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD rgrgbPalette[256];
dword cbBmpBits;
byte* pbBmpBits;
byte *pb, *pbPal = NULL;
dword cbPalBytes;
dword biTrueWidth;
int i, rc = 0;
// bogus parameter check
if( !pix->palette || !pix->buffer )
return false;
pfile = FS_Open( name, "wb");
if(!pfile) return false;
switch( pix->type )
{
case PF_INDEXED_24:
case PF_INDEXED_32:
break;
default:
MsgDev( D_WARN, "Image_SaveBMP: unsupported image type %s\n", PFDesc[pix->type].name );
return false;
}
// NOTE: alig transparency column will sucessfully removed
// after create sprite or lump image, it's just standard requiriments
biTrueWidth = ((pix->width + 3) & ~3);
cbBmpBits = biTrueWidth * pix->height;
cbPalBytes = 256 * sizeof( RGBQUAD );
// Bogus file header check
bmfh.bfType = MAKEWORD( 'B', 'M' );
bmfh.bfSize = sizeof(bmfh) + sizeof(bmih) + cbBmpBits + cbPalBytes;
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
bmfh.bfOffBits = sizeof(bmfh) + sizeof(bmih) + cbPalBytes;
// write header
FS_Write( pfile, &bmfh, sizeof(bmfh));
// size of structure
bmih.biSize = sizeof(bmih);
bmih.biWidth = biTrueWidth;
bmih.biHeight = pix->height;
bmih.biPlanes = 1;
bmih.biBitCount = 8;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 256;
bmih.biClrImportant = 0;
// Write info header
FS_Write( pfile, &bmih, sizeof(bmih));
pb = pix->palette;
// copy over used entries
for( i = 0; i < (int)bmih.biClrUsed; i++ )
{
rgrgbPalette[i].rgbRed = *pb++;
rgrgbPalette[i].rgbGreen = *pb++;
rgrgbPalette[i].rgbBlue = *pb++;
rgrgbPalette[i].rgbReserved = *pb++;
}
// write palette( bmih.biClrUsed entries )
cbPalBytes = bmih.biClrUsed * sizeof( RGBQUAD );
FS_Write( pfile, rgrgbPalette, cbPalBytes );
pbBmpBits = Mem_Alloc( Sys.imagepool, cbBmpBits );
pb = pix->buffer;
pb += (pix->height - 1) * pix->width;
for( i = 0; i < bmih.biHeight; i++ )
{
// FIXME: replace with Mem_Move
memmove( &pbBmpBits[biTrueWidth * i], pb, pix->width );
pb -= pix->width;
}
// write bitmap bits (remainder of file)
FS_Write( pfile, pbBmpBits, cbBmpBits );
FS_Close( pfile );
MsgDev( D_NOTE, "Writing %s[8]\n", name );
Mem_Free( pbBmpBits );
return true;
}

View File

@ -1,11 +1,11 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// Copyright XashXT Group 2008 ©
// img_dds.c - dds format load & save
//=======================================================================
#include "imagelib.h"
#include "launch.h"
#include "byteorder.h"
#include "img_formats.h"
#include "filesystem.h"
// TODO: tune this ?
#define REDWEIGHT 4
@ -1048,7 +1048,7 @@ bool Image_DecompressDXTC( rgbdata_t **image )
Bpp = PFDesc[pix->type].bpp;
Bps = pix->width * Bpp * PFDesc[pix->type].bpc;
SizeOfPlane = Bps * pix->height;
fout = Mem_Alloc( zonepool, pix->width * pix->height * 4 );
fout = Mem_Alloc( Sys.imagepool, pix->width * pix->height * 4 );
switch( pix->type )
{
@ -1351,7 +1351,7 @@ bool Image_DecompressARGB( rgbdata_t **image )
return false;
}
fout = Mem_Alloc( zonepool, pix->width * pix->height * 4 );
fout = Mem_Alloc( Sys.imagepool, pix->width * pix->height * 4 );
TempBpp = pix->bitsCount / 8;
Image_GetBitsFromMask(r_bitmask, &RedL, &RedR);
@ -1411,7 +1411,7 @@ word *Image_Compress565( rgbdata_t *pix )
uint i, j;
uint Bps, SizeOfPlane, SizeOfData;
Data = (word *)Mem_Alloc( zonepool, pix->width * pix->height * 2 * pix->numLayers );
Data = (word *)Mem_Alloc( Sys.imagepool, pix->width * pix->height * 2 * pix->numLayers );
Bps = pix->width * PFDesc[pix->type].bpp * PFDesc[pix->type].bpc;
SizeOfPlane = Bps * pix->height;
@ -1461,7 +1461,7 @@ byte *Image_Compress88( rgbdata_t *pix )
byte *Data;
uint i, j;
Data = (byte *)Mem_Alloc(zonepool, pix->width * pix->height * 2 * pix->numLayers );
Data = (byte *)Mem_Alloc(Sys.imagepool, pix->width * pix->height * 2 * pix->numLayers );
switch( pix->type )
{
@ -1521,7 +1521,7 @@ size_t Image_CompressDXT( vfile_t *f, int saveformat, rgbdata_t *pix )
byte *in = pix->buffer;
uint line = pix->width * srccomps;
flip = Mem_Alloc( zonepool, pix->size ); // alloc src image size
flip = Mem_Alloc( Sys.imagepool, pix->size ); // alloc src image size
for( y = pix->height - 1; y >= 0; y-- )
for( x = 0; x < pix->width; x++ )
for( c = 0; c < srccomps; c++, in++)
@ -1529,7 +1529,7 @@ size_t Image_CompressDXT( vfile_t *f, int saveformat, rgbdata_t *pix )
pix->buffer = flip;
}
blkaddr = dest = Mem_Alloc( zonepool, dst_size ); // alloc dst image size
blkaddr = dest = Mem_Alloc( Sys.imagepool, dst_size ); // alloc dst image size
switch( saveformat )
{
@ -1668,7 +1668,7 @@ void Image_DXTGetPixelFormat( dds_t *hdr )
if(image_type == PF_ARGB_32 || image_type == PF_LUMINANCE || image_type == PF_LUMINANCE_16 || image_type == PF_LUMINANCE_ALPHA)
{
//store RGBA mask into one block, and get palette pointer
byte *tmp = image_palette = Mem_Alloc( zonepool, sizeof(uint) * 4 );
byte *tmp = image_palette = Mem_Alloc( Sys.imagepool, sizeof(uint) * 4 );
Mem_Copy( tmp, &hdr->dsPixelFormat.dwRBitMask, sizeof(uint)); tmp += 4;
Mem_Copy( tmp, &hdr->dsPixelFormat.dwGBitMask, sizeof(uint)); tmp += 4;
Mem_Copy( tmp, &hdr->dsPixelFormat.dwBBitMask, sizeof(uint)); tmp += 4;
@ -1828,7 +1828,7 @@ bool Image_LoadDDS( const char *name, const byte *buffer, size_t filesize )
if(image_size == 0) return false; // just in case
// dds files will be uncompressed on a render. requires minimal of info for set this
image_rgba = Mem_Alloc( zonepool, image_size );
image_rgba = Mem_Alloc( Sys.imagepool, image_size );
Mem_Copy( image_rgba, fin, image_size );
return true;

502
launch/img_jpg.c Normal file
View File

@ -0,0 +1,502 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_jpg.c - jpg format load & save
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
jpg_t jpg_file; // jpeg read struct
int jpeg_read_byte( void )
{
// read byte
jpg_file.curbyte = *jpg_file.buffer++;
jpg_file.curbit = 0;
return jpg_file.curbyte;
}
int jpeg_read_word( void )
{
// read word
word i = BuffLittleShort( jpg_file.buffer);
i = ((i << 8) & 0xFF00) + ((i >> 8) & 0x00FF);
jpg_file.buffer += 2;
return i;
}
int jpeg_read_bit( void )
{
// read bit
register int i;
if(jpg_file.curbit == 0)
{
jpeg_read_byte();
if(jpg_file.curbyte == 0xFF)
{
while(jpg_file.curbyte == 0xFF) jpeg_read_byte();
if(jpg_file.curbyte >= 0xD0 && jpg_file.curbyte <= 0xD7)
memset(jpg_file.dc, 0, sizeof(int) * 3);
if(jpg_file.curbyte == 0) jpg_file.curbyte = 0xFF;
else jpeg_read_byte();
}
}
i = (jpg_file.curbyte >> (7 - jpg_file.curbit++)) & 0x01;
if(jpg_file.curbit == 8) jpg_file.curbit = 0;
return i;
}
int jpeg_read_bits( int num )
{
// read num bit
register int i, j;
for(i = 0, j = 0; i < num; i++)
{
j <<= 1;
j |= jpeg_read_bit();
}
return j;
}
int jpeg_bit2int( int bit, int i )
{
// convert bit code to int
if((i & (1 << (bit - 1))) > 0) return i;
return -(i ^ ((1 << bit) - 1));
}
int jpeg_huffmancode( huffman_table_t *table )
{
// get Huffman code
register int i,size,code;
for(size = 1, code = 0, i = 0; size < 17; size++)
{
code <<= 1;
code |= jpeg_read_bit();
while(table->size[i] <= size)
{
if(table->code[i] == code)
return table->hval[i];
i++;
}
}
return code;
}
void jpeg_idct( float *data )
{
// aa&n algorithm inverse DCT
float t0, t1, t2, t3, t4, t5, t6, t7;
float t10, t11, t12, t13;
float z5, z10, z11, z12, z13;
float *dataptr;
int i;
dataptr = data;
for(i = 0; i < 8; i++)
{
t0 = dataptr[8 * 0];
t1 = dataptr[8 * 2];
t2 = dataptr[8 * 4];
t3 = dataptr[8 * 6];
t10 = t0 + t2;
t11 = t0 - t2;
t13 = t1 + t3;
t12 = - t13 + (t1 - t3) * 1.414213562;//??
t0 = t10 + t13;
t3 = t10 - t13;
t1 = t11 + t12;
t2 = t11 - t12;
t4 = dataptr[8 * 1];
t5 = dataptr[8 * 3];
t6 = dataptr[8 * 5];
t7 = dataptr[8 * 7];
z13 = t6 + t5;
z10 = t6 - t5;
z11 = t4 + t7;
z12 = t4 - t7;
t7 = z11 + z13;
t11 = (z11 - z13) * 1.414213562;
z5 = (z10 + z12) * 1.847759065;
t10 = - z5 + z12 * 1.082392200;
t12 = z5 - z10 * 2.613125930;
t6 = t12 - t7;
t5 = t11 - t6;
t4 = t10 + t5;
dataptr[8 * 0] = t0 + t7;
dataptr[8 * 7] = t0 - t7;
dataptr[8 * 1] = t1 + t6;
dataptr[8 * 6] = t1 - t6;
dataptr[8 * 2] = t2 + t5;
dataptr[8 * 5] = t2 - t5;
dataptr[8 * 4] = t3 + t4;
dataptr[8 * 3] = t3 - t4;
dataptr++;
}
dataptr = data;
for(i = 0; i < 8; i++)
{
t10 = dataptr[0] + dataptr[4];
t11 = dataptr[0] - dataptr[4];
t13 = dataptr[2] + dataptr[6];
t12 = - t13 + (dataptr[2] - dataptr[6]) * 1.414213562;//??
t0 = t10 + t13;
t3 = t10 - t13;
t1 = t11 + t12;
t2 = t11 - t12;
z13 = dataptr[5] + dataptr[3];
z10 = dataptr[5] - dataptr[3];
z11 = dataptr[1] + dataptr[7];
z12 = dataptr[1] - dataptr[7];
t7 = z11 + z13;
t11 = (z11 - z13) * 1.414213562;
z5 = (z10 + z12) * 1.847759065;
t10 = - z5 + z12 * 1.082392200;
t12 = z5 - z10 * 2.613125930;
t6 = t12 - t7;
t5 = t11 - t6;
t4 = t10 + t5;
dataptr[0] = t0 + t7;
dataptr[7] = t0 - t7;
dataptr[1] = t1 + t6;
dataptr[6] = t1 - t6;
dataptr[2] = t2 + t5;
dataptr[5] = t2 - t5;
dataptr[4] = t3 + t4;
dataptr[3] = t3 - t4;
dataptr += 8;//move ptr
}
}
int jpeg_readmarkers( void )
{
// read jpeg markers
int marker, length, i, j, k, l, m;
huffman_table_t *hptr;
while( 1 )
{
marker = jpeg_read_byte();
if(marker != 0xFF) return 0;
marker = jpeg_read_byte();
if(marker != 0xD8)
{
length = jpeg_read_word();
length -= 2;
switch(marker)
{
case 0xC0: // Baseline
jpg_file.data_precision = jpeg_read_byte();
jpg_file.height = jpeg_read_word();
jpg_file.width = jpeg_read_word();
jpg_file.num_components = jpeg_read_byte();
if(length - 6 != jpg_file.num_components * 3) return 0;
for(i = 0; i < jpg_file.num_components; i++)
{
jpg_file.component_info[i].id = jpeg_read_byte();
j = jpeg_read_byte();
jpg_file.component_info[i].h = (j >> 4) & 0x0F;
jpg_file.component_info[i].v = j & 0x0F;
jpg_file.component_info[i].t = jpeg_read_byte();
}
break;
case 0xC1: // Extended sequetial, Huffman
case 0xC2: // Progressive, Huffman
case 0xC3: // Lossless, Huffman
case 0xC5: // Differential sequential, Huffman
case 0xC6: // Differential progressive, Huffman
case 0xC7: // Differential lossless, Huffman
case 0xC8: // Reserved for JPEG extensions
case 0xC9: // Extended sequential, arithmetic
case 0xCA: // Progressive, arithmetic
case 0xCB: // Lossless, arithmetic
case 0xCD: // Differential sequential, arithmetic
case 0xCE: // Differential progressive, arithmetic
case 0xCF: // Differential lossless, arithmetic
return 0;
case 0xC4: // Huffman table
while(length > 0)
{
k = jpeg_read_byte();
if(k & 0x10) hptr = &jpg_file.hac[k & 0x0F];
else hptr = &jpg_file.hdc[k & 0x0F];
for(i = 0, j = 0; i < 16; i++)
{
hptr->bits[i] = jpeg_read_byte();
j += hptr->bits[i];
}
length -= 17;
for(i = 0; i < j; i++) hptr->hval[i] = jpeg_read_byte();
length -= j;
for(i = 0, k = 0, l = 0; i < 16; i++)
{
for(j = 0; j < hptr->bits[i]; j++, k++)
{
hptr->size[k] = i + 1;
hptr->code[k] = l++;
}
l <<= 1;
}
}
break;
case 0xDB: // Quantization table
while(length > 0)
{
j = jpeg_read_byte();
k = (j >> 4) & 0x0F;
for(i = 0; i < 64; i++)
{
if( k )jpg_file.qtable[j][i] = jpeg_read_word();
else jpg_file.qtable[j][i] = jpeg_read_byte();
}
length -= 65;
if( k )length -= 64;
}
break;
case 0xD9: // End of image (EOI)
return 0;
case 0xDA: // Start of scan (SOS)
j = jpeg_read_byte();
for(i = 0; i < j; i++)
{
k = jpeg_read_byte();
m = jpeg_read_byte();
for(l = 0; l < jpg_file.num_components; l++)
{
if(jpg_file.component_info[l].id == k)
{
jpg_file.component_info[l].td = (m >> 4) & 0x0F;
jpg_file.component_info[l].ta = m & 0x0F;
}
}
}
jpg_file.scan.ss = jpeg_read_byte();
jpg_file.scan.se = jpeg_read_byte();
k = jpeg_read_byte();
jpg_file.scan.ah = (k >> 4) & 0x0F;
jpg_file.scan.al = k & 0x0F;
return 1;
case 0xDD: // Restart interval
jpg_file.restart_interval = jpeg_read_word();
break;
default:
jpg_file.buffer += length; //move ptr
break;
}
}
}
}
void jpeg_decompress( void )
{
// decompress jpeg file (Baseline algorithm)
register int x, y, i, j, k, l, c;
int X, Y, H, V, plane, scaleh[3], scalev[3];
static float vector[64], dct[64];
static const int jpeg_zigzag[64] =
{
0, 1, 5, 6, 14, 15, 27, 28,
2, 4, 7, 13, 16, 26, 29, 42,
3, 8, 12, 17, 25, 30, 41, 43,
9, 11, 18, 24, 31, 40, 44, 53,
10, 19, 23, 32, 39, 45, 52, 54,
20, 22, 33, 38, 46, 51, 55, 60,
21, 34, 37, 47, 50, 56, 59, 61,
35, 36, 48, 49, 57, 58, 62, 63
};
// 1.0, k = 0; cos(k * PI / 16) * sqrt(2), k = 1...7
static const float aanscale[8] =
{
1.0, 1.387039845, 1.306562965, 1.175875602,
1.0, 0.785694958, 0.541196100, 0.275899379
};
scaleh[0] = 1;
scalev[0] = 1;
if(jpg_file.num_components == 3)
{
scaleh[1] = jpg_file.component_info[0].h / jpg_file.component_info[1].h;
scalev[1] = jpg_file.component_info[0].v / jpg_file.component_info[1].v;
scaleh[2] = jpg_file.component_info[0].h / jpg_file.component_info[2].h;
scalev[2] = jpg_file.component_info[0].v / jpg_file.component_info[2].v;
}
memset(jpg_file.dc,0,sizeof(int) * 3);
for(Y = 0; Y < jpg_file.height; Y += jpg_file.component_info[0].v << 3)
{
if(jpg_file.restart_interval > 0) jpg_file.curbit = 0;
for(X = 0; X < jpg_file.width; X += jpg_file.component_info[0].h << 3)
{
for(plane = 0; plane < jpg_file.num_components; plane++)
{
for(V = 0; V < jpg_file.component_info[plane].v; V++)
{
for(H = 0; H < jpg_file.component_info[plane].h; H++)
{
i = jpeg_huffmancode(&jpg_file.hdc[jpg_file.component_info[plane].td]);
i &= 0x0F;
vector[0] = jpg_file.dc[plane] + jpeg_bit2int(i,jpeg_read_bits(i));
jpg_file.dc[plane] = vector[0];
i = 1;
while(i < 64)
{
j = jpeg_huffmancode(&jpg_file.hac[jpg_file.component_info[plane].ta]);
if(j == 0) while(i < 64) vector[i++] = 0;
else
{
k = i + ((j >> 4) & 0x0F);
while(i < k) vector[i++] = 0;
j &= 0x0F;
vector[i++] = jpeg_bit2int(j,jpeg_read_bits(j));
}
}
k = jpg_file.component_info[plane].t;
for(y = 0, i = 0; y < 8; y++)
{
for(x = 0; x < 8; x++, i++)
{
j = jpeg_zigzag[i];
dct[i] = vector[j] * jpg_file.qtable[k][j] * aanscale[x] * aanscale[y];
}
}
jpeg_idct(dct);
for(y = 0; y < 8; y++)
{
for(x = 0; x < 8; x++)
{
c = ((int)dct[(y << 3) + x] >> 3) + 128;
if(c < 0) c = 0;
else if(c > 255) c = 255;
if(scaleh[plane] == 1 && scalev[plane] == 1)
{
i = X + x + (H << 3);
j = Y + y + (V << 3);
if(i < jpg_file.width && j < jpg_file.height)
jpg_file.data[((j * jpg_file.width + i) << 2) + plane] = c;
}
else for(l = 0; l < scalev[plane]; l++)//else for, heh...
{
for(k = 0; k < scaleh[plane]; k++)
{
i = X + (x + (H << 3)) * scaleh[plane] + k;
j = Y + (y + (V << 3)) * scalev[plane] + l;
if(i < jpg_file.width && j < jpg_file.height)
jpg_file.data[((j * jpg_file.width + i) << 2) + plane] = c;
}
}
}
}
}
}
}
}
}
}
void jpeg_ycbcr2rgba( void )
{
int i, Y, Cb, Cr, R, G, B;
// convert YCbCr image to RGBA
for(i = 0; i < jpg_file.width * jpg_file.height << 2; i += 4)
{
Y = jpg_file.data[i];
Cb = jpg_file.data[i + 1] - 128;
Cr = jpg_file.data[i + 2] - 128;
R = Y + 1.40200 * Cr;
G = Y - 0.34414 * Cb - 0.71414 * Cr;
B = Y + 1.77200 * Cb;
// bound colors
if(R < 0) R = 0;
else if(R > 255) R = 255;
if(G < 0) G = 0;
else if(G > 255) G = 255;
if(B < 0) B = 0;
else if(B > 255) B = 255;
jpg_file.data[i + 0] = R;
jpg_file.data[i + 1] = G;
jpg_file.data[i + 2] = B;
jpg_file.data[i + 3] = 0xff;//alpha channel
}
}
void jpeg_gray2rgba( void )
{
int i, j;
// grayscale image to RGBA
for(i = 0; i < jpg_file.width * jpg_file.height << 2; i += 4)
{
j = jpg_file.data[i];
jpg_file.data[i + 0] = j;
jpg_file.data[i + 1] = j;
jpg_file.data[i + 2] = j;
jpg_file.data[i + 3] = 0xff;
}
}
/*
=============
Image_LoadJPG
=============
*/
bool Image_LoadJPG( const char *name, const byte *buffer, size_t filesize )
{
memset(&jpg_file, 0, sizeof(jpg_file));
jpg_file.buffer = (byte *)buffer;
if(!jpeg_readmarkers())
return false; // it's not a jpg file, just skip it
image_width = jpg_file.width;
image_height = jpg_file.height;
image_type = PF_RGBA_32;
if(!Image_ValidSize( name )) return false;
image_size = jpg_file.width * jpg_file.height * 4;
jpg_file.data = Mem_Alloc( Sys.imagepool, image_size );
jpeg_decompress();
if( jpg_file.num_components == 1 ) jpeg_gray2rgba();
if( jpg_file.num_components == 3 ) jpeg_ycbcr2rgba();
image_num_layers = 1;
image_num_mips = 1;
image_rgba = jpg_file.data;
return true;
}

513
launch/img_main.c Normal file
View File

@ -0,0 +1,513 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_load.c - load various image formats
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
#include "mathlib.h"
// global image variables
int image_width, image_height;
byte image_num_layers = 1; // num layers in
byte image_num_mips = 0; // build mipmaps
uint image_type; // main type switcher
uint image_flags; // additional image flags
byte image_bits_count; // bits per RGBA
size_t image_size; // image rgba size
uint image_ptr;
byte *image_palette; // palette pointer
byte *image_rgba; // image pointer (see image_type for details)
// cubemap variables
int cubemap_width, cubemap_height;
int cubemap_num_sides; // how mach sides is loaded
byte *image_cubemap; // cubemap pack
uint base_image_type; // shared image type for all mipmaps or cubemap sides
const char *suf[6] = { "ft", "bk", "rt", "lf", "up", "dn" };
typedef struct loadformat_s
{
char *formatstring;
char *ext;
bool (*loadfunc)( const char *name, const byte *buffer, size_t filesize );
} loadformat_t;
static loadformat_t load_formats0[] =
{
{"textures/%s%s.%s", "dds", Image_LoadDDS},
{"textures/%s%s.%s", "tga", Image_LoadTGA},
{"%s%s.%s", "dds", Image_LoadDDS},
{"%s%s.%s", "tga", Image_LoadTGA},
{NULL, NULL, NULL}
};
static loadformat_t load_formats1[] =
{
{"textures/%s%s.%s", "dds", Image_LoadDDS},
{"textures/%s%s.%s", "tga", Image_LoadTGA},
{"textures/%s%s.%s", "jpg", Image_LoadJPG},
{"textures/%s%s.%s", "png", Image_LoadPNG},
{"textures/%s%s.%s", "mip", Image_LoadMIP},
{"%s%s.%s", "dds", Image_LoadDDS},
{"%s%s.%s", "tga", Image_LoadTGA},
{"%s%s.%s", "jpg", Image_LoadJPG},
{"%s%s.%s", "png", Image_LoadPNG},
{"%s%s.%s", "mip", Image_LoadMIP},
{NULL, NULL, NULL}
};
static loadformat_t load_formats2[] =
{
{"textures/%s%s.%s", "dds", Image_LoadDDS},
{"textures/%s%s.%s", "tga", Image_LoadTGA},
{"textures/%s%s.%s", "jpg", Image_LoadJPG},
{"textures/%s%s.%s", "png", Image_LoadPNG},
{"textures/%s%s.%s", "mip", Image_LoadMIP},
{"textures/%s%s.%s", "bmp", Image_LoadBMP},
{"textures/%s%s.%s", "wal", Image_LoadWAL},
{"textures/%s%s.%s", "pcx", Image_LoadPCX},
{"textures/%s%s.%s", "lmp", Image_LoadLMP},
{"%s%s.%s", "dds", Image_LoadDDS},
{"%s%s.%s", "tga", Image_LoadTGA},
{"%s%s.%s", "jpg", Image_LoadJPG},
{"%s%s.%s", "png", Image_LoadPNG},
{"%s%s.%s", "mip", Image_LoadMIP},
{"%s%s.%s", "bmp", Image_LoadBMP},
{"%s%s.%s", "wal", Image_LoadWAL},
{"%s%s.%s", "pcx", Image_LoadPCX},
{"%s%s.%s", "lmp", Image_LoadLMP},
{NULL, NULL, NULL}
};
static loadformat_t load_formats3[] =
{
{"textures/%s%s.%s", "dds", Image_LoadDDS},
{"textures/%s%s.%s", "tga", Image_LoadTGA},
{"textures/%s%s.%s", "jpg", Image_LoadJPG},
{"textures/%s%s.%s", "png", Image_LoadPNG},
{"textures/%s%s.%s", "mip", Image_LoadMIP},
{"textures/%s%s.%s", "bmp", Image_LoadBMP},
{"textures/%s%s.%s", "wal", Image_LoadWAL},
{"textures/%s%s.%s", "pcx", Image_LoadPCX},
{"textures/%s%s.%s", "lmp", Image_LoadLMP},
{"textures/%s%s.%s", "flt", Image_LoadFLT},
{"textures/%s%s.%s", "pal", Image_LoadPAL},
{"%s%s.%s", "dds", Image_LoadDDS},
{"%s%s.%s", "tga", Image_LoadTGA},
{"%s%s.%s", "jpg", Image_LoadJPG},
{"%s%s.%s", "png", Image_LoadPNG},
{"%s%s.%s", "mip", Image_LoadMIP},
{"%s%s.%s", "bmp", Image_LoadBMP},
{"%s%s.%s", "wal", Image_LoadWAL},
{"%s%s.%s", "pcx", Image_LoadPCX},
{"%s%s.%s", "lmp", Image_LoadLMP},
{"%s%s.%s", "flt", Image_LoadFLT},
{"%s%s.%s", "pal", Image_LoadPAL},
{NULL, NULL, NULL}
};
static loadformat_t load_formats4[] =
{
{"%s%s.%s", "bmp", Image_LoadBMP},
{"%s%s.%s", "pcx", Image_LoadPCX},
{"%s%s.%s", "mip", Image_LoadMIP},
{"%s%s.%s", "wal", Image_LoadWAL},
{"%s%s.%s", "lmp", Image_LoadLMP},
{"%s%s.%s", "flt", Image_LoadFLT},
{NULL, NULL, NULL}
};
rgbdata_t *ImagePack( void )
{
rgbdata_t *pack = Mem_Alloc( Sys.imagepool, sizeof(rgbdata_t));
if( image_cubemap && cubemap_num_sides != 6 )
{
// this neved be happens, just in case
MsgDev( D_NOTE, "ImagePack: inconsistent cubemap pack %d\n", cubemap_num_sides );
FS_FreeImage( pack );
return NULL;
}
if( image_cubemap )
{
image_flags |= IMAGE_CUBEMAP;
pack->buffer = image_cubemap;
pack->width = cubemap_width;
pack->height = cubemap_height;
pack->type = base_image_type;
pack->size = image_size * cubemap_num_sides;
}
else
{
pack->buffer = image_rgba;
pack->width = image_width;
pack->height = image_height;
pack->type = image_type;
pack->size = image_size;
}
pack->numLayers = image_num_layers;
pack->numMips = image_num_mips;
pack->bitsCount = image_bits_count;
pack->flags = image_flags;
pack->palette = image_palette;
return pack;
}
bool FS_AddImageToPack( const char *name )
{
byte *resampled;
// first image have suffix "ft" and set average size for all cubemap sides!
if(!image_cubemap)
{
cubemap_width = image_width;
cubemap_height = image_height;
base_image_type = image_type;
}
image_size = cubemap_width * cubemap_height * 4; // keep constant size, render.dll expecting it
// mixing dds format with any existing ?
if(image_type != base_image_type) return false;
// resampling image if needed
resampled = Image_ResampleInternal((uint *)image_rgba, image_width, image_height, cubemap_width, cubemap_height, base_image_type );
if(!resampled) return false; // try to reasmple dxt?
if( resampled != image_rgba ) Mem_Move( Sys.imagepool, &image_rgba, resampled, image_size ); // update buffer
image_cubemap = Mem_Realloc( Sys.imagepool, image_cubemap, image_ptr + image_size );
Mem_Copy(image_cubemap + image_ptr, image_rgba, image_size );
Mem_Free( image_rgba ); // memmove aren't help us
image_ptr += image_size; // move to next
cubemap_num_sides++; // sides counter
return true;
}
bool FS_AddMipmapToPack( const byte *in, int width, int height, bool expand )
{
int mipsize = width * height;
int outsize = width * height;
// check for inconsistency
if( !base_image_type ) base_image_type = image_type;
// trying to add 8 bit mimpap into 32-bit mippack or somewhat...
if( base_image_type != image_type ) return false;
if( expand ) outsize *= 4;
else Image_CopyPalette32bit();
// reallocate image buffer
image_rgba = Mem_Realloc( Sys.imagepool, image_rgba, image_size + outsize );
if( !expand ) Mem_Copy( image_rgba + image_ptr, in, outsize );
else if( !Image_Copy8bitRGBA( in, image_rgba + image_ptr, mipsize ))
return false; // probably pallette not installed
image_size += outsize;
image_ptr += outsize;
image_num_mips++;
return true;
}
void FS_GetImageColor( rgbdata_t *pic )
{
int j, texels;
byte *pal, *buffer;
vec3_t color = {0,0,0};
float r, scale;
if( !pic )
{
MsgDev( D_ERROR, "FS_GetImageColor: image not loaded\n" );
return;
}
if(!pic->palette && (pic->type == PF_INDEXED_24 || pic->type == PF_INDEXED_32))
{
MsgDev( D_ERROR, "FS_GetImageColor: indexed image doesn't have palette\n" );
VectorClear( pic->color ); // clear previous color, if present
return;
}
texels = pic->width * pic->height;
buffer = pic->buffer;
pal = pic->palette;
switch( pic->type )
{
case PF_DXT1:
case PF_DXT3:
case PF_DXT5:
if(!Image_DecompressDXTC( &pic )) break;
// intentional falltrough
case PF_RGBA_32:
case PF_ABGR_64:
for( j = 0; j < texels; j++, buffer += 4 )
{
color[0] += buffer[0];
color[1] += buffer[1];
color[2] += buffer[2];
}
break;
case PF_RGB_24:
case PF_RGB_24_FLIP:
for( j = 0; j < texels; j++, buffer += 3 )
{
color[0] += buffer[0];
color[1] += buffer[1];
color[2] += buffer[2];
}
break;
case PF_INDEXED_24:
case PF_INDEXED_32:
for( j = 0; j < texels; j++ )
{
color[0] += pal[buffer[j]+0];
color[1] += pal[buffer[j]+1];
color[2] += pal[buffer[j]+2];
}
break;
default:
MsgDev( D_WARN, "FS_GetImageColor: Can't calculate reflectivity\n" );
break;
}
for( j = 0; j < 3; j++ )
{
r = color[j]/texels;
pic->color[j] = r;
}
// scale the reflectivity up, because the textures are so dim
scale = Image_NormalizeColor( pic->color, pic->color );
pic->bump_scale = texels * 255.0 / scale; // basic intensity value
}
/*
================
FS_LoadImage
loading and unpack to rgba any known image
================
*/
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t buffsize )
{
const char *ext = FS_FileExtension( filename );
char path[128], loadname[128], texname[128];
loadformat_t *format, *desired_formats = load_formats0;
bool anyformat = !com_stricmp(ext, "") ? true : false;
int i, filesize = 0;
byte *f;
#if 0 // don't try to be very clever
if( !buffer || !buffsize ) buffer = (char *)florr1_2_jpg, buffsize = sizeof(florr1_2_jpg);
#endif
switch( Sys.app_name )
{
case HOST_NORMAL:
case HOST_BSPLIB:
case HOST_VIEWER:
switch( img_oldformats->integer )
{
case 0: desired_formats = load_formats0; break; // tga, dds
case 1: desired_formats = load_formats1; break; // tga, dds, jpg, png, mip
case 2: desired_formats = load_formats2; break; // tga, dds, jpg, png, mip, bmp, pcx, wal, lmp
case 3: desired_formats = load_formats3; break; // tga, dds, jpg, png, mip, bmp, pcx, wal, lmp, flat, pal
}
break;
case HOST_SPRITE:
case HOST_STUDIO:
case HOST_WADLIB:
desired_formats = load_formats4; // bmp, pcx, mip, wal, lmp, flat
break;
case HOST_RIPPER:
// everything else
desired_formats = load_formats3; // tga, dds, jpg, png, mip, bmp, pcx, wal, lmp, flat, pal
break;
default:
// other instances not needs image support
desired_formats = NULL;
break;
}
// skip any checks, load file from buffer
if(com_stristr( filename, "#internal" ) && buffer && buffsize )
goto load_internal;
com_strncpy( loadname, filename, sizeof(loadname)-1);
FS_StripExtension( loadname ); //remove extension if needed
// developer warning
if(!anyformat) MsgDev(D_NOTE, "Note: %s will be loading only with ext .%s\n", loadname, ext );
// now try all the formats in the selected list
for( format = desired_formats; format->formatstring; format++)
{
if( anyformat || !com_stricmp(ext, format->ext ))
{
com_sprintf( path, format->formatstring, loadname, "", format->ext );
f = FS_LoadFile( path, &filesize );
if(f && filesize > 0)
{
// this name will be used only for tell user about problems
FS_FileBase( path, texname );
if( format->loadfunc(texname, f, filesize ))
{
Mem_Free(f); // release buffer
return ImagePack(); // loaded
}
}
}
}
// maybe it skybox or cubemap ?
for( i = 0; i < 6; i++ )
{
for( format = desired_formats; format->formatstring; format++ )
{
if( anyformat || !com_stricmp(ext, format->ext ))
{
com_sprintf( path, format->formatstring, loadname, suf[i], format->ext );
f = FS_LoadFile( path, &filesize );
if(f && filesize > 0)
{
// this name will be used only for tell user about problems
FS_FileBase( path, texname );
if( format->loadfunc(texname, f, filesize ))
{
if(FS_AddImageToPack(va("%s%s.%s", loadname, suf[i], format->ext)))
break; // loaded
}
Mem_Free(f);
}
}
}
if( cubemap_num_sides != i + 1 ) // check side
{
// first side not found, probably it's not cubemap
// it contain info about image_type and dimensions, don't generate black cubemaps
if(!image_cubemap) break;
MsgDev(D_ERROR, "FS_LoadImage: couldn't load (%s%s.%s), create black image\n",loadname,suf[i],ext );
// Mem_Alloc already filled memblock with 0x00, no need to do it again
image_cubemap = Mem_Realloc( Sys.imagepool, image_cubemap, image_ptr + image_size );
image_ptr += image_size; // move to next
cubemap_num_sides++; // merge counter
}
}
if( image_cubemap ) return ImagePack(); // now it's cubemap pack
load_internal:
// try to load image from const buffer (e.g. const byte blank_frame )
com_strncpy( texname, filename, sizeof(texname) - 1);
for( format = desired_formats; format->formatstring; format++ )
{
if( anyformat || !com_stricmp( ext, format->ext ))
{
if( buffer && buffsize > 0 )
{
// this name will be used only for tell user about problems
FS_FileBase( texname, texname );
if( format->loadfunc( texname, buffer, buffsize ))
return ImagePack(); // loaded
}
}
}
if( !desired_formats ) MsgDev( D_NOTE, "FS_LoadImage: imagelib offline\n" );
else if(!com_stristr( filename, "#internal" ))
MsgDev(D_WARN, "FS_LoadImage: couldn't load \"%s\"\n", texname );
return NULL;
}
typedef struct saveformat_s
{
const char *formatstring;
const char *ext;
bool (*savefunc)( const char *name, rgbdata_t *pix, int saveformat );
} saveformat_t;
saveformat_t save_formats[] =
{
{"%s%s.%s", "tga", Image_SaveTGA},
{"%s%s.%s", "png", Image_SavePNG},
{"%s%s.%s", "dds", Image_SaveDDS},
{"%s%s.%s", "bmp", Image_SaveBMP},
{NULL, NULL}
};
/*
================
Image_Save
writes image as any known format
================
*/
void FS_SaveImage( const char *filename, rgbdata_t *pix )
{
saveformat_t *format;
const char *ext = FS_FileExtension( filename );
char path[128], savename[128];
bool anyformat = !com_stricmp(ext, "") ? true : false;
int filesize = 0;
byte *data;
bool has_alpha = false;
if(!pix || !pix->buffer) return;
if(pix->flags & IMAGE_HAS_ALPHA) has_alpha = true;
data = pix->buffer;
com_strncpy( savename, filename, sizeof(savename) - 1);
FS_StripExtension( savename ); // remove extension if needed
// developer warning
if(!anyformat) MsgDev(D_NOTE, "Note: %s will be saving only with ext .%s\n", savename, ext );
// now try all the formats in the selected list
for (format = save_formats; format->formatstring; format++)
{
if( anyformat || !com_stricmp( ext, format->ext ))
{
com_sprintf( path, format->formatstring, savename, "", format->ext );
if( format->savefunc( path, pix, pix->hint ))
break; // saved
}
}
}
/*
================
Image_FreeImage
free RGBA buffer
================
*/
void FS_FreeImage( rgbdata_t *pack )
{
if( pack )
{
if( pack->buffer ) Mem_Free( pack->buffer );
if( pack->palette ) Mem_Free( pack->palette );
Mem_Free( pack );
}
// reset global variables
image_width = image_height = 0;
cubemap_width = cubemap_height = 0;
image_bits_count = image_flags = 0;
cubemap_num_sides = 0;
image_num_layers = 1;
base_image_type = 0;
image_num_mips = 0;
image_type = PF_UNKNOWN;
image_palette = NULL;
image_rgba = NULL;
image_cubemap = NULL;
image_ptr = 0;
image_size = 0;
}

97
launch/img_pcx.c Normal file
View File

@ -0,0 +1,97 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_pcx.c - pcx format load & save
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
/*
=============
Image_LoadPCX
=============
*/
bool Image_LoadPCX( const char *name, const byte *buffer, size_t filesize )
{
pcx_t pcx;
int s, i, x, y, x2, dataByte;
byte *pix, *pbuf, *palette, *fin, *enddata;
fin = (byte *)buffer;
Mem_Copy(&pcx, fin, sizeof(pcx));
fin += sizeof(pcx);
// probably it's not pcx file
if( pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1 ) return false;
if( filesize < (int)sizeof(pcx) + 768)
{
MsgDev( D_ERROR, "Image_LoadPCX: file (%s) have invalid size\n", name );
return false;
}
pcx.xmax = LittleShort (pcx.xmax);
pcx.xmin = LittleShort (pcx.xmin);
pcx.ymax = LittleShort (pcx.ymax);
pcx.ymin = LittleShort (pcx.ymin);
pcx.hres = LittleShort (pcx.hres);
pcx.vres = LittleShort (pcx.vres);
pcx.bytes_per_line = LittleShort (pcx.bytes_per_line);
pcx.palette_type = LittleShort (pcx.palette_type);
image_width = pcx.xmax + 1 - pcx.xmin;
image_height = pcx.ymax + 1 - pcx.ymin;
if( pcx.bits_per_pixel != 8 || pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1)
{
MsgDev( D_ERROR, "Image_LoadPCX: (%s) have illegal pixel size '%d'\n", name, pcx.bits_per_pixel );
return false;
}
if(!Image_ValidSize( name )) return false;
palette = (byte *)buffer + filesize - 768;
image_num_layers = 1;
image_num_mips = 1;
s = image_width * image_height;
pbuf = (byte *)Mem_Alloc( Sys.imagepool, s );
enddata = palette;
for( y = 0; y < image_height && fin < enddata; y++ )
{
pix = pbuf + y * image_width;
for (x = 0; x < image_width && fin < enddata;)
{
dataByte = *fin++;
if(dataByte >= 0xC0)
{
if (fin >= enddata) break;
x2 = x + (dataByte & 0x3F);
dataByte = *fin++;
if (x2 > image_width) x2 = image_width; // technically an error
while(x < x2) pix[x++] = dataByte;
}
else pix[x++] = dataByte;
}
// the number of bytes per line is always forced to an even number
fin += pcx.bytes_per_line - image_width;
while(x < image_width) pix[x++] = 0;
}
Image_GetPalettePCX( palette );
// check for transparency
for (i = 0; i < s; i++)
{
if( pbuf[i] == 255 )
{
image_flags |= IMAGE_HAS_ALPHA; // found alpha channel
break;
}
}
image_type = (image_flags & IMAGE_HAS_ALPHA) ? PF_INDEXED_32 : PF_INDEXED_24;
FS_AddMipmapToPack( pbuf, image_width, image_height, false );
Mem_Free( pbuf ); // free compressed image
return true;
}

28
launch/img_png.c Normal file
View File

@ -0,0 +1,28 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_png.c - png format load & save
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
/*
=============
Image_LoadPNG
=============
*/
bool Image_LoadPNG( const char *name, const byte *buffer, size_t filesize )
{
return false;
}
/*
=============
Image_SavePNG
=============
*/
bool Image_SavePNG( const char *name, rgbdata_t *pix, int saveformat )
{
return false;
}

View File

@ -3,9 +3,9 @@
// img_tga.c - tga format load & save
//=======================================================================
#include "imagelib.h"
#include "launch.h"
#include "byteorder.h"
#include "img_formats.h"
#include "filesystem.h"
/*
=============
@ -17,8 +17,9 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
int x, y, pix_inc, row_inc;
int red, green, blue, alpha;
int runlen, alphabits;
byte *pixbuf;
byte *p, *pixbuf;
const byte *fin, *enddata;
byte palette[256*4];
tga_t targa_header;
if(filesize < sizeof(tga_t))
@ -57,8 +58,41 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
// the image data)
if( targa_header.colormap_type )
{
MsgDev(D_ERROR, "LoadTGA: (%s) colormap images unsupported (valid is 32 or 24 bit)\n", name );
return false;
if( targa_header.colormap_length > 256 )
{
MsgDev( D_ERROR, "Image_LoadTGA: only up to 256 colormap_length supported\n" );
return false;
}
if( targa_header.colormap_index )
{
MsgDev( D_ERROR, "Image_LoadTGA: colormap_index not supported\n" );
return false;
}
if( targa_header.colormap_size == 24 )
{
for( x = 0; x < targa_header.colormap_length; x++ )
{
palette[x*4+2] = *fin++;
palette[x*4+1] = *fin++;
palette[x*4+0] = *fin++;
palette[x*4+3] = 255;
}
}
else if( targa_header.colormap_size == 32 )
{
for( x = 0; x < targa_header.colormap_length; x++ )
{
palette[x*4+2] = *fin++;
palette[x*4+1] = *fin++;
palette[x*4+0] = *fin++;
palette[x*4+3] = *fin++;
}
}
else
{
Msg("Image_LoadTGA: Only 32 and 24 bit colormap_size supported\n");
return false;
}
}
// check our pixel_size restrictions according to image_type
@ -71,14 +105,31 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
return false;
}
break;
case 3:
// set up a palette to make the loader easier
for( x = 0; x < 256; x++ )
{
palette[x*4+2] = x;
palette[x*4+1] = x;
palette[x*4+0] = x;
palette[x*4+3] = 255;
}
// fall through to colormap case
case 1:
if( targa_header.pixel_size != 8 )
{
MsgDev( D_ERROR, "Image_LoadTGA: only 8bit pixel size for type 1, 3, 9, and 11 images supported\n" );
return false;
}
break;
default:
MsgDev(D_ERROR, "LoadTGA: (%s) is unsupported image type '%i'\n", name, targa_header.image_type );
MsgDev(D_ERROR, "Image_LoadTGA: (%s) is unsupported image type '%i'\n", name, targa_header.image_type );
return false;
}
if( targa_header.attributes & 0x10 )
{
MsgDev( D_WARN, "LoadTGA: (%s): top right and bottom right origin are not supported\n", name );
MsgDev( D_WARN, "Image_LoadTGA: (%s): top right and bottom right origin are not supported\n", name );
return false;
}
@ -92,7 +143,7 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
image_flags |= alphabits ? IMAGE_HAS_ALPHA : 0;
image_size = image_width * image_height * 4;
image_rgba = Mem_Alloc( zonepool, image_size );
image_rgba = Mem_Alloc( Sys.imagepool, image_size );
// If bit 5 of attributes isn't set, the image has been stored from bottom to top
if(!(targa_header.attributes & 0x20))
@ -113,6 +164,22 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
switch( targa_header.image_type )
{
case 1: // colormapped, uncompressed
case 3: // greyscale, uncompressed
if( fin + image_width * image_height * pix_inc > enddata )
break;
for( y = 0; y < image_height; y++, pixbuf += row_inc )
{
for( x = 0; x < image_width; x++ )
{
p = palette + *fin++ * 4;
*pixbuf++ = p[0];
*pixbuf++ = p[1];
*pixbuf++ = p[2];
*pixbuf++ = p[3];
}
}
break;
case 2:
// BGR or BGRA, uncompressed
if(fin + image_width * image_height * pix_inc > enddata)
@ -144,6 +211,55 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
}
}
break;
case 9: // colormapped, RLE
case 11: // greyscale, RLE
for( y = 0; y < image_height; y++, pixbuf += row_inc )
{
for( x = 0; x < image_width; )
{
if( fin >= enddata ) break; // error - truncated file
runlen = *fin++;
if( runlen & 0x80 )
{
// RLE - all pixels the same color
runlen += 1 - 0x80;
if( fin + pix_inc > enddata )
break; // error - truncated file
if( x + runlen > image_width )
break; // error - line exceeds width
p = palette + *fin++ * 4;
red = p[0];
green = p[1];
blue = p[2];
alpha = p[3];
for( ;runlen--; x++ )
{
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = alpha;
}
}
else
{
// uncompressed - all pixels different color
runlen++;
if( fin + pix_inc * runlen > enddata )
break; // error - truncated file
if( x + runlen > image_width )
break; // error - line exceeds width
for( ;runlen--; x++ )
{
p = palette + *fin++ * 4;
*pixbuf++ = p[0];
*pixbuf++ = p[1];
*pixbuf++ = p[2];
*pixbuf++ = p[3];
}
}
}
}
break;
case 10:
// BGR or BGRA, RLE
if( targa_header.pixel_size == 32 && alphabits )
@ -244,7 +360,7 @@ bool Image_LoadTGA( const char *name, const byte *buffer, size_t filesize )
/*
=============
SaveTGA
Image_SaveTGA
=============
*/
bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat )
@ -255,14 +371,14 @@ bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat )
const char *comment = "Generated by Xash ImageLib\0";
if(FS_FileExists(name)) return false; // already existed
if( pix->flags & IMAGE_HAS_ALPHA ) outsize = pix->width * pix->height * 4 + 18 + com.strlen(comment);
else outsize = pix->width * pix->height * 3 + 18 + com.strlen(comment);
if( pix->flags & IMAGE_HAS_ALPHA ) outsize = pix->width * pix->height * 4 + 18 + com_strlen( comment );
else outsize = pix->width * pix->height * 3 + 18 + com_strlen( comment );
buffer = (byte *)Mem_Alloc( zonepool, outsize );
buffer = (byte *)Mem_Alloc( Sys.imagepool, outsize );
memset( buffer, 0, 18 );
// prepare header
buffer[0] = com.strlen(comment); // tga comment length
buffer[0] = com_strlen( comment ); // tga comment length
buffer[2] = 2; // uncompressed type
buffer[12] = (pix->width >> 0) & 0xFF;
buffer[13] = (pix->width >> 8) & 0xFF;
@ -270,8 +386,8 @@ bool Image_SaveTGA( const char *name, rgbdata_t *pix, int saveformat )
buffer[15] = (pix->height >> 8) & 0xFF;
buffer[16] = ( pix->flags & IMAGE_HAS_ALPHA ) ? 32 : 24;
buffer[17] = ( pix->flags & IMAGE_HAS_ALPHA ) ? 8 : 0; // 8 bits of alpha
com.strncpy( buffer + 18, comment, com.strlen(comment));
out = buffer + 18 + com.strlen(comment);
com_strncpy( buffer + 18, comment, com_strlen( comment ));
out = buffer + 18 + com_strlen( comment );
// get image description
switch( pix->type )

835
launch/img_utils.c Normal file
View File

@ -0,0 +1,835 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_utils.c - image common tools
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
#include "mathlib.h"
cvar_t *img_resample_lerp;
cvar_t *img_oldformats;
uint d_8toD1table[256];
uint d_8toQ1table[256];
uint d_8toQ2table[256];
uint d_8to24table[256];
uint *d_currentpal; // 32 bit palette
bool d1palette_init = false;
bool q1palette_init = false;
bool q2palette_init = false;
int d_rendermode = LUMP_NORMAL;
static byte palette_d1[768] =
{
0,0,0,31,23,11,23,15,7,75,75,75,255,255,255,27,27,27,19,19,19,11,11,11,7,7,7,47,55,31,35,43,15,23,31,7,15,23,0,79,
59,43,71,51,35,63,43,27,255,183,183,247,171,171,243,163,163,235,151,151,231,143,143,223,135,135,219,123,123,211,115,
115,203,107,107,199,99,99,191,91,91,187,87,87,179,79,79,175,71,71,167,63,63,163,59,59,155,51,51,151,47,47,143,43,43,
139,35,35,131,31,31,127,27,27,119,23,23,115,19,19,107,15,15,103,11,11,95,7,7,91,7,7,83,7,7,79,0,0,71,0,0,67,0,0,255,
235,223,255,227,211,255,219,199,255,211,187,255,207,179,255,199,167,255,191,155,255,187,147,255,179,131,247,171,123,
239,163,115,231,155,107,223,147,99,215,139,91,207,131,83,203,127,79,191,123,75,179,115,71,171,111,67,163,107,63,155,
99,59,143,95,55,135,87,51,127,83,47,119,79,43,107,71,39,95,67,35,83,63,31,75,55,27,63,47,23,51,43,19,43,35,15,239,
239,239,231,231,231,223,223,223,219,219,219,211,211,211,203,203,203,199,199,199,191,191,191,183,183,183,179,179,179,
171,171,171,167,167,167,159,159,159,151,151,151,147,147,147,139,139,139,131,131,131,127,127,127,119,119,119,111,111,
111,107,107,107,99,99,99,91,91,91,87,87,87,79,79,79,71,71,71,67,67,67,59,59,59,55,55,55,47,47,47,39,39,39,35,35,35,
119,255,111,111,239,103,103,223,95,95,207,87,91,191,79,83,175,71,75,159,63,67,147,55,63,131,47,55,115,43,47,99,35,39,
83,27,31,67,23,23,51,15,19,35,11,11,23,7,191,167,143,183,159,135,175,151,127,167,143,119,159,135,111,155,127,107,147,
123,99,139,115,91,131,107,87,123,99,79,119,95,75,111,87,67,103,83,63,95,75,55,87,67,51,83,63,47,159,131,99,143,119,83,
131,107,75,119,95,63,103,83,51,91,71,43,79,59,35,67,51,27,123,127,99,111,115,87,103,107,79,91,99,71,83,87,59,71,79,51,
63,71,43,55,63,39,255,255,115,235,219,87,215,187,67,195,155,47,175,123,31,155,91,19,135,67,7,115,43,0,255,255,255,255,
219,219,255,187,187,255,155,155,255,123,123,255,95,95,255,63,63,255,31,31,255,0,0,239,0,0,227,0,0,215,0,0,203,0,0,191,
0,0,179,0,0,167,0,0,155,0,0,139,0,0,127,0,0,115,0,0,103,0,0,91,0,0,79,0,0,67,0,0,231,231,255,199,199,255,171,171,255,
143,143,255,115,115,255,83,83,255,55,55,255,27,27,255,0,0,255,0,0,227,0,0,203,0,0,179,0,0,155,0,0,131,0,0,107,0,0,83,
255,255,255,255,235,219,255,215,187,255,199,155,255,179,123,255,163,91,255,143,59,255,127,27,243,115,23,235,111,15,
223,103,15,215,95,11,203,87,7,195,79,0,183,71,0,175,67,0,255,255,255,255,255,215,255,255,179,255,255,143,255,255,107,
255,255,71,255,255,35,255,255,0,167,63,0,159,55,0,147,47,0,135,35,0,79,59,39,67,47,27,55,35,19,47,27,11,0,0,83,0,0,71,
0,0,59,0,0,47,0,0,35,0,0,23,0,0,11,0,255,255,255,159,67,255,231,75,255,123,255,255,0,255,207,0,207,159,0,155,111,0,107,
167,107,107
};
static byte palette_q1[768] =
{
0,0,0,15,15,15,31,31,31,47,47,47,63,63,63,75,75,75,91,91,91,107,107,107,123,123,123,139,139,139,155,155,155,171,
171,171,187,187,187,203,203,203,219,219,219,235,235,235,15,11,7,23,15,11,31,23,11,39,27,15,47,35,19,55,43,23,63,
47,23,75,55,27,83,59,27,91,67,31,99,75,31,107,83,31,115,87,31,123,95,35,131,103,35,143,111,35,11,11,15,19,19,27,
27,27,39,39,39,51,47,47,63,55,55,75,63,63,87,71,71,103,79,79,115,91,91,127,99,99,139,107,107,151,115,115,163,123,
123,175,131,131,187,139,139,203,0,0,0,7,7,0,11,11,0,19,19,0,27,27,0,35,35,0,43,43,7,47,47,7,55,55,7,63,63,7,71,71,
7,75,75,11,83,83,11,91,91,11,99,99,11,107,107,15,7,0,0,15,0,0,23,0,0,31,0,0,39,0,0,47,0,0,55,0,0,63,0,0,71,0,0,79,
0,0,87,0,0,95,0,0,103,0,0,111,0,0,119,0,0,127,0,0,19,19,0,27,27,0,35,35,0,47,43,0,55,47,0,67,55,0,75,59,7,87,67,7,
95,71,7,107,75,11,119,83,15,131,87,19,139,91,19,151,95,27,163,99,31,175,103,35,35,19,7,47,23,11,59,31,15,75,35,19,
87,43,23,99,47,31,115,55,35,127,59,43,143,67,51,159,79,51,175,99,47,191,119,47,207,143,43,223,171,39,239,203,31,255,
243,27,11,7,0,27,19,0,43,35,15,55,43,19,71,51,27,83,55,35,99,63,43,111,71,51,127,83,63,139,95,71,155,107,83,167,123,
95,183,135,107,195,147,123,211,163,139,227,179,151,171,139,163,159,127,151,147,115,135,139,103,123,127,91,111,119,
83,99,107,75,87,95,63,75,87,55,67,75,47,55,67,39,47,55,31,35,43,23,27,35,19,19,23,11,11,15,7,7,187,115,159,175,107,
143,163,95,131,151,87,119,139,79,107,127,75,95,115,67,83,107,59,75,95,51,63,83,43,55,71,35,43,59,31,35,47,23,27,35,
19,19,23,11,11,15,7,7,219,195,187,203,179,167,191,163,155,175,151,139,163,135,123,151,123,111,135,111,95,123,99,83,
107,87,71,95,75,59,83,63,51,67,51,39,55,43,31,39,31,23,27,19,15,15,11,7,111,131,123,103,123,111,95,115,103,87,107,
95,79,99,87,71,91,79,63,83,71,55,75,63,47,67,55,43,59,47,35,51,39,31,43,31,23,35,23,15,27,19,11,19,11,7,11,7,255,
243,27,239,223,23,219,203,19,203,183,15,187,167,15,171,151,11,155,131,7,139,115,7,123,99,7,107,83,0,91,71,0,75,55,
0,59,43,0,43,31,0,27,15,0,11,7,0,0,0,255,11,11,239,19,19,223,27,27,207,35,35,191,43,43,175,47,47,159,47,47,143,47,
47,127,47,47,111,47,47,95,43,43,79,35,35,63,27,27,47,19,19,31,11,11,15,43,0,0,59,0,0,75,7,0,95,7,0,111,15,0,127,23,
7,147,31,7,163,39,11,183,51,15,195,75,27,207,99,43,219,127,59,227,151,79,231,171,95,239,191,119,247,211,139,167,123,
59,183,155,55,199,195,55,231,227,87,127,191,255,171,231,255,215,255,255,103,0,0,139,0,0,179,0,0,215,0,0,255,0,0,255,
243,147,255,247,199,255,255,255,159,91,83
};
static byte palette_q2[768] =
{
0,0,0,15,15,15,31,31,31,47,47,47,63,63,63,75,75,75,91,91,91,107,107,107,123,123,123,139,139,139,155,155,155,171,171,
171,187,187,187,203,203,203,219,219,219,235,235,235,99,75,35,91,67,31,83,63,31,79,59,27,71,55,27,63,47,23,59,43,23,
51,39,19,47,35,19,43,31,19,39,27,15,35,23,15,27,19,11,23,15,11,19,15,7,15,11,7,95,95,111,91,91,103,91,83,95,87,79,91,
83,75,83,79,71,75,71,63,67,63,59,59,59,55,55,51,47,47,47,43,43,39,39,39,35,35,35,27,27,27,23,23,23,19,19,19,143,119,
83,123,99,67,115,91,59,103,79,47,207,151,75,167,123,59,139,103,47,111,83,39,235,159,39,203,139,35,175,119,31,147,99,
27,119,79,23,91,59,15,63,39,11,35,23,7,167,59,43,159,47,35,151,43,27,139,39,19,127,31,15,115,23,11,103,23,7,87,19,0,
75,15,0,67,15,0,59,15,0,51,11,0,43,11,0,35,11,0,27,7,0,19,7,0,123,95,75,115,87,67,107,83,63,103,79,59,95,71,55,87,67,
51,83,63,47,75,55,43,67,51,39,63,47,35,55,39,27,47,35,23,39,27,19,31,23,15,23,15,11,15,11,7,111,59,23,95,55,23,83,47,
23,67,43,23,55,35,19,39,27,15,27,19,11,15,11,7,179,91,79,191,123,111,203,155,147,215,187,183,203,215,223,179,199,211,
159,183,195,135,167,183,115,151,167,91,135,155,71,119,139,47,103,127,23,83,111,19,75,103,15,67,91,11,63,83,7,55,75,7,
47,63,7,39,51,0,31,43,0,23,31,0,15,19,0,7,11,0,0,0,139,87,87,131,79,79,123,71,71,115,67,67,107,59,59,99,51,51,91,47,
47,87,43,43,75,35,35,63,31,31,51,27,27,43,19,19,31,15,15,19,11,11,11,7,7,0,0,0,151,159,123,143,151,115,135,139,107,
127,131,99,119,123,95,115,115,87,107,107,79,99,99,71,91,91,67,79,79,59,67,67,51,55,55,43,47,47,35,35,35,27,23,23,19,
15,15,11,159,75,63,147,67,55,139,59,47,127,55,39,119,47,35,107,43,27,99,35,23,87,31,19,79,27,15,67,23,11,55,19,11,43,
15,7,31,11,7,23,7,0,11,0,0,0,0,0,119,123,207,111,115,195,103,107,183,99,99,167,91,91,155,83,87,143,75,79,127,71,71,
115,63,63,103,55,55,87,47,47,75,39,39,63,35,31,47,27,23,35,19,15,23,11,7,7,155,171,123,143,159,111,135,151,99,123,
139,87,115,131,75,103,119,67,95,111,59,87,103,51,75,91,39,63,79,27,55,67,19,47,59,11,35,47,7,27,35,0,19,23,0,11,15,
0,0,255,0,35,231,15,63,211,27,83,187,39,95,167,47,95,143,51,95,123,51,255,255,255,255,255,211,255,255,167,255,255,
127,255,255,83,255,255,39,255,235,31,255,215,23,255,191,15,255,171,7,255,147,0,239,127,0,227,107,0,211,87,0,199,71,
0,183,59,0,171,43,0,155,31,0,143,23,0,127,15,0,115,7,0,95,0,0,71,0,0,47,0,0,27,0,0,239,0,0,55,55,255,255,0,0,0,0,255,
43,43,35,27,27,23,19,19,15,235,151,127,195,115,83,159,87,51,123,63,27,235,211,199,199,171,155,167,139,119,135,107,87,
159,91,83
};
void Image_Init( void )
{
// init pools
Sys.imagepool = Mem_AllocPool( "ImageLib Pool" );
img_resample_lerp = Cvar_Get( "img_lerping", "1", CVAR_SYSTEMINFO, "lerping images after resample" );
img_oldformats = Cvar_Get( "img_oldformats", "1", CVAR_SYSTEMINFO, "enabels support of old image formats, e.g. doom1 flats, quake1 mips, quake2 wally, etc" );
}
void Image_Shutdown( void )
{
Mem_Check(); // check for leaks
Mem_FreePool( &Sys.imagepool );
}
void Image_RoundDimensions( int *scaled_width, int *scaled_height )
{
int width, height;
for( width = 1; width < *scaled_width; width <<= 1 );
for( height = 1; height < *scaled_height; height <<= 1 );
*scaled_width = bound( 1, width, IMAGE_MAXWIDTH );
*scaled_height = bound( 1, height, IMAGE_MAXHEIGHT );
}
bool Image_ValidSize( const char *name )
{
if( image_width > IMAGE_MAXWIDTH || image_height > IMAGE_MAXHEIGHT || image_width <= 0 || image_height <= 0 )
{
if(!com_stristr( name, "#internal" )) // internal errors are silent
MsgDev(D_WARN, "Image_ValidSize: (%s) dims out of range[%dx%d]\n", name, image_width,image_height );
return false;
}
return true;
}
vec_t Image_NormalizeColor( vec3_t in, vec3_t out )
{
float max, scale;
max = in[0];
if(in[1] > max) max = in[1];
if(in[2] > max) max = in[2];
// ignore green color
if( max == 0 ) return 0;
scale = 255.0f / max;
VectorScale( in, scale, out );
return max;
}
void Image_SetPalette( const byte *pal, uint *d_table )
{
int i;
byte rgba[4];
// setup palette
switch( d_rendermode )
{
case LUMP_DECAL:
for(i = 0; i < 256; i++)
{
rgba[3] = pal[765];
rgba[2] = pal[766];
rgba[1] = pal[767];
rgba[0] = i;
d_table[i] = BuffBigLong( rgba );
}
break;
case LUMP_TRANSPARENT:
for (i = 0; i < 256; i++)
{
rgba[3] = pal[i*3+0];
rgba[2] = pal[i*3+1];
rgba[1] = pal[i*3+2];
rgba[0] = pal[i] == 255 ? pal[i] : 0xFF;
d_table[i] = BuffBigLong( rgba );
}
break;
case LUMP_QFONT:
for (i = 1; i < 256; i++)
{
rgba[3] = pal[i*3+0];
rgba[2] = pal[i*3+1];
rgba[1] = pal[i*3+2];
rgba[0] = 0xFF;
d_table[i] = BuffBigLong( rgba );
}
break;
case LUMP_NORMAL:
for (i = 0; i < 256; i++)
{
rgba[3] = pal[i*3+0];
rgba[2] = pal[i*3+1];
rgba[1] = pal[i*3+2];
rgba[0] = 0xFF;
d_table[i] = BuffBigLong( rgba );
}
break;
}
}
void Image_GetPaletteD1( void )
{
d_rendermode = LUMP_NORMAL;
if(!d1palette_init)
{
Image_SetPalette( palette_d1, d_8toD1table );
d_8toD1table[247] = 0; // 247 is transparent
d1palette_init = true;
}
d_currentpal = d_8toD1table;
}
void Image_GetPaletteQ1( void )
{
d_rendermode = LUMP_NORMAL;
if(!q1palette_init)
{
Image_SetPalette( palette_q1, d_8toQ1table );
d_8toQ1table[255] = 0; // 255 is transparent
q1palette_init = true;
}
d_currentpal = d_8toQ1table;
}
void Image_GetPaletteQ2( void )
{
d_rendermode = LUMP_NORMAL;
if(!q2palette_init)
{
Image_SetPalette( palette_q2, d_8toQ2table );
d_8toQ2table[255] &= LittleLong(0xffffff);
q2palette_init = true;
}
d_currentpal = d_8toQ2table;
}
void Image_GetPalettePCX( const byte *pal )
{
d_rendermode = LUMP_NORMAL;
if( pal )
{
Image_SetPalette( pal, d_8to24table );
d_8to24table[255] &= LittleLong(0xffffff);
d_currentpal = d_8to24table;
}
else Image_GetPaletteQ2();
}
void Image_GetPaletteLMP( const byte *pal, int rendermode )
{
d_rendermode = rendermode;
if( pal )
{
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_SetPalette( palette_q1, d_8to24table );
d_8to24table[0] = 0;
d_currentpal = d_8to24table;
}
else Image_GetPaletteQ1(); // default quake palette
}
void Image_CopyPalette24bit( void )
{
byte *pal32, *pal24;
int i;
if( !d_currentpal )
{
MsgDev(D_ERROR,"Image_Palette24bit: no palette set\n");
return;
}
if( image_palette )
{
MsgDev(D_ERROR,"Image_Palette24bit: palette already set\n");
return;
}
image_palette = Mem_Alloc( Sys.imagepool, 768 );
pal32 = (byte *)((uint *)d_currentpal);
pal24 = image_palette;
for( i = 0; i < 256; i++, pal24 += 3, pal32 += 4 )
{
pal24[0] = pal32[0];
pal24[1] = pal32[1];
pal24[2] = pal32[2];
}
}
void Image_CopyPalette32bit( void )
{
image_palette = Mem_Alloc( Sys.imagepool, 1024 );
Mem_Copy( image_palette, d_currentpal, 1024 );
}
/*
============
Image_Copy8bitRGBA
NOTE: must call Image_GetPaletteXXX before used
============
*/
bool Image_Copy8bitRGBA( const byte *in, byte *out, int pixels )
{
int *iout = (int *)out;
if( !d_currentpal )
{
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 )
{
iout[0] = d_currentpal[in[0]];
iout[1] = d_currentpal[in[1]];
iout[2] = d_currentpal[in[2]];
iout[3] = d_currentpal[in[3]];
iout[4] = d_currentpal[in[4]];
iout[5] = d_currentpal[in[5]];
iout[6] = d_currentpal[in[6]];
iout[7] = d_currentpal[in[7]];
in += 8;
iout += 8;
pixels -= 8;
}
if( pixels & 4 )
{
iout[0] = d_currentpal[in[0]];
iout[1] = d_currentpal[in[1]];
iout[2] = d_currentpal[in[2]];
iout[3] = d_currentpal[in[3]];
in += 4;
iout += 4;
}
if( pixels & 2 )
{
iout[0] = d_currentpal[in[0]];
iout[1] = d_currentpal[in[1]];
in += 2;
iout += 2;
}
if( pixels & 1 ) // last byte
iout[0] = d_currentpal[in[0]];
return true;
}
static void Image_Resample32LerpLine (const byte *in, byte *out, int inwidth, int outwidth)
{
int j, xi, oldx = 0, f, fstep, endx, lerp;
fstep = (int)(inwidth * 65536.0f/outwidth);
endx = (inwidth-1);
for( j = 0, f = 0; j < outwidth; j++, f += fstep )
{
xi = f>>16;
if( xi != oldx )
{
in += (xi - oldx) * 4;
oldx = xi;
}
if( xi < endx )
{
lerp = f & 0xFFFF;
*out++ = (byte)((((in[4] - in[0]) * lerp)>>16) + in[0]);
*out++ = (byte)((((in[5] - in[1]) * lerp)>>16) + in[1]);
*out++ = (byte)((((in[6] - in[2]) * lerp)>>16) + in[2]);
*out++ = (byte)((((in[7] - in[3]) * lerp)>>16) + in[3]);
}
else // last pixel of the line has no pixel to lerp to
{
*out++ = in[0];
*out++ = in[1];
*out++ = in[2];
*out++ = in[3];
}
}
}
static void Image_Resample24LerpLine( const byte *in, byte *out, int inwidth, int outwidth )
{
int j, xi, oldx = 0, f, fstep, endx, lerp;
fstep = (int)(inwidth * 65536.0f/outwidth);
endx = (inwidth-1);
for( j = 0, f = 0; j < outwidth; j++, f += fstep )
{
xi = f>>16;
if( xi != oldx )
{
in += (xi - oldx) * 3;
oldx = xi;
}
if( xi < endx )
{
lerp = f & 0xFFFF;
*out++ = (byte)((((in[3] - in[0]) * lerp)>>16) + in[0]);
*out++ = (byte)((((in[4] - in[1]) * lerp)>>16) + in[1]);
*out++ = (byte)((((in[5] - in[2]) * lerp)>>16) + in[2]);
}
else // last pixel of the line has no pixel to lerp to
{
*out++ = in[0];
*out++ = in[1];
*out++ = in[2];
}
}
}
void Image_Resample32Lerp(const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
{
int i, j, r, yi, oldy = 0, f, fstep, lerp, endy = (inheight - 1);
int inwidth4 = inwidth * 4;
int outwidth4 = outwidth * 4;
const byte *inrow;
byte *out;
byte *resamplerow1;
byte *resamplerow2;
out = (byte *)outdata;
fstep = (int)(inheight * 65536.0f/outheight);
resamplerow1 = (byte *)Mem_Alloc( Sys.imagepool, outwidth * 4 * 2);
resamplerow2 = resamplerow1 + outwidth * 4;
inrow = (const byte *)indata;
Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample32LerpLine( inrow + inwidth4, resamplerow2, inwidth, outwidth );
for( i = 0, f = 0; i < outheight; i++, f += fstep )
{
yi = f>>16;
if( yi < endy )
{
lerp = f & 0xFFFF;
if( yi != oldy )
{
inrow = (byte *)indata + inwidth4 * yi;
if (yi == oldy+1) Mem_Copy( resamplerow1, resamplerow2, outwidth4 );
else Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample32LerpLine( inrow + inwidth4, resamplerow2, inwidth, outwidth );
oldy = yi;
}
j = outwidth - 4;
while( j >= 0 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
LERPBYTE( 8);
LERPBYTE( 9);
LERPBYTE(10);
LERPBYTE(11);
LERPBYTE(12);
LERPBYTE(13);
LERPBYTE(14);
LERPBYTE(15);
out += 16;
resamplerow1 += 16;
resamplerow2 += 16;
j -= 4;
}
if( j & 2 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
out += 8;
resamplerow1 += 8;
resamplerow2 += 8;
}
if( j & 1 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
out += 4;
resamplerow1 += 4;
resamplerow2 += 4;
}
resamplerow1 -= outwidth4;
resamplerow2 -= outwidth4;
}
else
{
if( yi != oldy )
{
inrow = (byte *)indata + inwidth4*yi;
if( yi == oldy + 1 ) Mem_Copy( resamplerow1, resamplerow2, outwidth4 );
else Image_Resample32LerpLine( inrow, resamplerow1, inwidth, outwidth);
oldy = yi;
}
Mem_Copy( out, resamplerow1, outwidth4 );
}
}
Mem_Free( resamplerow1 );
resamplerow1 = NULL;
resamplerow2 = NULL;
}
void Image_Resample32Nolerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j;
uint frac, fracstep;
int *inrow, *out = (int *)outdata; // relies on int being 4 bytes
fracstep = inwidth * 0x10000/outwidth;
for( i = 0; i < outheight; i++)
{
inrow = (int *)indata + inwidth * (i * inheight/outheight);
frac = fracstep>>1;
j = outwidth - 4;
while( j >= 0 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out[1] = inrow[frac >> 16];frac += fracstep;
out[2] = inrow[frac >> 16];frac += fracstep;
out[3] = inrow[frac >> 16];frac += fracstep;
out += 4;
j -= 4;
}
if( j & 2 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out[1] = inrow[frac >> 16];frac += fracstep;
out += 2;
}
if( j & 1 )
{
out[0] = inrow[frac >> 16];frac += fracstep;
out += 1;
}
}
}
void Image_Resample24Lerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight - 1);
int inwidth3 = inwidth * 3;
int outwidth3 = outwidth * 3;
const byte *inrow;
byte *out = (byte *)outdata;
byte *resamplerow1;
byte *resamplerow2;
fstep = (int)(inheight * 65536.0f / outheight);
resamplerow1 = (byte *)Mem_Alloc(Sys.imagepool, outwidth * 3 * 2);
resamplerow2 = resamplerow1 + outwidth*3;
inrow = (const byte *)indata;
oldy = 0;
Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample24LerpLine( inrow + inwidth3, resamplerow2, inwidth, outwidth );
for( i = 0, f = 0; i < outheight; i++, f += fstep )
{
yi = f>>16;
if( yi < endy )
{
lerp = f & 0xFFFF;
if( yi != oldy )
{
inrow = (byte *)indata + inwidth3 * yi;
if( yi == oldy + 1) Mem_Copy( resamplerow1, resamplerow2, outwidth3 );
else Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
Image_Resample24LerpLine( inrow + inwidth3, resamplerow2, inwidth, outwidth );
oldy = yi;
}
j = outwidth - 4;
while( j >= 0 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
LERPBYTE( 6);
LERPBYTE( 7);
LERPBYTE( 8);
LERPBYTE( 9);
LERPBYTE(10);
LERPBYTE(11);
out += 12;
resamplerow1 += 12;
resamplerow2 += 12;
j -= 4;
}
if( j & 2 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
LERPBYTE( 3);
LERPBYTE( 4);
LERPBYTE( 5);
out += 6;
resamplerow1 += 6;
resamplerow2 += 6;
}
if( j & 1 )
{
LERPBYTE( 0);
LERPBYTE( 1);
LERPBYTE( 2);
out += 3;
resamplerow1 += 3;
resamplerow2 += 3;
}
resamplerow1 -= outwidth3;
resamplerow2 -= outwidth3;
}
else
{
if( yi != oldy )
{
inrow = (byte *)indata + inwidth3*yi;
if( yi == oldy + 1) Mem_Copy( resamplerow1, resamplerow2, outwidth3 );
else Image_Resample24LerpLine( inrow, resamplerow1, inwidth, outwidth );
oldy = yi;
}
Mem_Copy( out, resamplerow1, outwidth3 );
}
}
Mem_Free( resamplerow1 );
resamplerow1 = NULL;
resamplerow2 = NULL;
}
void Image_Resample24Nolerp( const void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight )
{
int i, j, f, inwidth3 = inwidth * 3;
uint frac, fracstep;
byte *inrow, *out = (byte *)outdata;
fracstep = inwidth * 0x10000/outwidth;
for( i = 0; i < outheight; i++)
{
inrow = (byte *)indata + inwidth3 * (i * inheight/outheight);
frac = fracstep>>1;
j = outwidth - 4;
while( j >= 0 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
j -= 4;
}
if( j & 2 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
out += 2;
}
if( j & 1 )
{
f = (frac >> 16)*3;
*out++ = inrow[f+0];
*out++ = inrow[f+1];
*out++ = inrow[f+2];
frac += fracstep;
out += 1;
}
}
}
/*
================
Image_Resample
================
*/
byte *Image_ResampleInternal( const void *indata, int inwidth, int inheight, int outwidth, int outheight, int type )
{
bool quality = img_resample_lerp->integer;
byte *outdata;
// nothing to resample ?
if (inwidth == outwidth && inheight == outheight)
return (byte *)indata;
// alloc new buffer
switch( type )
{
case PF_RGB_24:
case PF_RGB_24_FLIP:
outdata = (byte *)Mem_Alloc( Sys.imagepool, outwidth * outheight * 3 );
if( quality ) Image_Resample24Lerp( indata, inwidth, inheight, outdata, outwidth, outheight );
else Image_Resample24Nolerp( indata, inwidth, inheight, outdata, outwidth, outheight );
break;
case PF_RGBA_32:
outdata = (byte *)Mem_Alloc( Sys.imagepool, outwidth * outheight * 4 );
if( quality ) Image_Resample32Lerp( indata, inwidth, inheight, outdata, outwidth, outheight );
else Image_Resample32Nolerp( indata, inwidth, inheight, outdata, outwidth, outheight );
break;
default:
MsgDev( D_WARN, "Image_Resample: unsupported format %s\n", PFDesc[type].name );
return (byte *)indata;
}
return (byte *)outdata;
}
bool Image_Resample( rgbdata_t **image, int width, int height, bool free_baseimage )
{
int w, h, pixel;
rgbdata_t *pix = *image;
byte *out;
// check for buffers
if(!pix || !pix->buffer) return false;
w = pix->width;
h = pix->height;
if( width && height )
{
// custom size
w = bound(4, width, IMAGE_MAXWIDTH ); // maxwidth 4096
h = bound(4, height, IMAGE_MAXHEIGHT); // maxheight 4096
}
else Image_RoundDimensions( &w, &h ); // auto detect new size
out = Image_ResampleInternal((uint *)pix->buffer, pix->width, pix->height, w, h, pix->type );
if( out != pix->buffer )
{
switch( pix->type )
{
case PF_RGBA_32:
pixel = 4;
break;
case PF_RGB_24:
case PF_RGB_24_FLIP:
pixel = 3;
break;
default:
pixel = 4;
}
// if image was resampled
MsgDev(D_NOTE, "Resample image from[%d x %d] to [%d x %d]\n", pix->width, pix->height, w, h );
if( free_baseimage ) Mem_Free( pix->buffer ); // free original image buffer
// change image params
pix->buffer = out;
pix->width = w, pix->height = h;
pix->size = w * h * pixel;
*image = pix;
return true;
}
return false;
}
bool Image_Process( rgbdata_t **pix, int adjust_type, bool free_baseimage )
{
int w, h;
rgbdata_t *pic = *pix;
// check for buffers
if(!pic || !pic->buffer) return false;
w = pic->width;
h = pic->height;
//TODO: implement
return false;
}

274
launch/img_wad.c Normal file
View File

@ -0,0 +1,274 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// img_mip.c - hl1 q1 image mips
//=======================================================================
#include "launch.h"
#include "byteorder.h"
#include "filesystem.h"
/*
============
Image_LoadPAL
============
*/
bool Image_LoadPAL( const char *name, const byte *buffer, size_t filesize )
{
if( filesize != 768 )
{
MsgDev( D_ERROR, "Image_LoadPAL: file (%s) have invalid size\n", name );
return false;
}
image_palette = Mem_Alloc( Sys.imagepool, 768 );
Mem_Copy( image_palette, buffer, 768 );
image_rgba = NULL; // only palette, not real image
image_size = image_width = image_height = 0;
image_num_mips = image_num_layers = 0;
image_flags = IMAGE_ONLY_PALETTE;
return true;
}
/*
==============
Image_LoadWAL
==============
*/
bool Image_LoadWAL( const char *name, const byte *buffer, size_t filesize )
{
wal_t wal;
int pixels, ofs[4], mipsize;
int i, flags, value, contents; // wal additional parms
if( filesize < (int)sizeof(wal))
{
MsgDev( D_ERROR, "Image_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.
MsgDev( D_ERROR, "Image_LoadWAL: file (%s) have invalid size\n", name );
return false;
}
image_num_layers = 1;
image_type = PF_INDEXED_24; // wal's never haven't transparency
Image_GetPaletteQ2(); // hardcoded
return FS_AddMipmapToPack( buffer + ofs[0], image_width, image_height, false );
}
/*
============
Image_LoadFLT
============
*/
bool Image_LoadFLT( const char *name, const byte *buffer, size_t filesize )
{
flat_t flat;
vfile_t *f;
word column_loop, row_loop;
int i, column_offset, pointer_position, first_pos;
byte *Data, post, topdelta, length;
if(filesize < (int)sizeof(flat))
{
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 );
VFS_Read(f, &flat, sizeof(flat));
image_width = LittleShort( flat.width );
image_height = LittleShort( flat.height );
flat.desc[0] = LittleShort( flat.desc[0] );
flat.desc[1] = LittleShort( flat.desc[1] );
if(!Image_ValidSize( name )) return false;
Data = (byte *)Mem_Alloc( Sys.imagepool, image_width * image_height );
memset( Data, 247, image_width * image_height ); // set default transparency
image_num_layers = 1;
for( column_loop = 0; column_loop < image_width; column_loop++ )
{
VFS_Read(f, &column_offset, sizeof(int));
pointer_position = VFS_Tell( f );
VFS_Seek( f, first_pos + column_offset, SEEK_SET );
while( 1 )
{
if(VFS_Read(f, &topdelta, 1) != 1) return false;
if(topdelta == 255) break;
if(VFS_Read(f, &length, 1) != 1) return false;
if(VFS_Read(f, &post, 1) != 1) return false;
for (row_loop = 0; row_loop < length; row_loop++)
{
if(VFS_Read(f, &post, 1) != 1) return false;
if(row_loop + topdelta < image_height)
Data[(row_loop + topdelta) * image_width + column_loop] = post;
}
VFS_Read( f, &post, 1 );
}
VFS_Seek(f, pointer_position, SEEK_SET );
}
VFS_Close( f );
// scan for transparency
for (i = 0; i < image_width * image_height; i++)
{
if( Data[i] == 247 )
{
image_flags |= IMAGE_HAS_ALPHA;
break;
}
}
image_type = (image_flags & IMAGE_HAS_ALPHA) ? PF_INDEXED_32 : PF_INDEXED_24;
Image_GetPaletteD1();
FS_AddMipmapToPack( Data, image_width, image_height, false );
Mem_Free( Data );
return true;
}
/*
============
Image_LoadLMP
============
*/
bool Image_LoadLMP( const char *name, const byte *buffer, size_t filesize )
{
lmp_t lmp;
byte *fin, *pal;
int pixels;
if( filesize < (int)sizeof(lmp))
{
MsgDev( D_ERROR, "Image_LoadLMP: file (%s) have invalid size\n", name );
return false;
}
fin = (byte *)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 )
{
MsgDev( D_ERROR, "Image_LoadLMP: file (%s) have invalid size %d\n", name, filesize );
return false;
}
if(!Image_ValidSize( name )) return false;
image_num_mips = 1;
image_rgba = (byte *)Mem_Alloc(Sys.imagepool, image_width * image_height );
image_num_layers = 1;
// 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_type = (image_flags & IMAGE_HAS_ALPHA) ? PF_INDEXED_32 : PF_INDEXED_24;
return FS_AddMipmapToPack( fin, image_width, image_height, false );
}
/*
=============
Image_LoadMIP
=============
*/
bool Image_LoadMIP( const char *name, const byte *buffer, size_t filesize )
{
mip_t mip;
byte *fin, *pal;
int ofs[4], rendermode;
int i, pixels, numcolors;
if( filesize < (int)sizeof(mip))
{
MsgDev( D_ERROR, "Image_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]);
pixels = image_width * image_height;
image_num_layers = 1;
if(!com_stricmp( name, "conchars" ))
{
// greatest hack from id software
image_width = image_height = 128;
image_flags |= IMAGE_HAS_ALPHA;
rendermode = LUMP_QFONT;
pal = NULL; // clear palette
fin = (byte *)buffer;
}
else if(filesize >= (int)sizeof(mip) + ((pixels * 85)>>6) + sizeof(short) + 768)
{
// half-life 1.0.0.1 mip version with palette
fin = (byte *)buffer + mip.offsets[0];
pal = (byte *)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] == '{' )
{
// qlumpy used this color for transparent textures, otherwise it's decals
if(pal[255*3+0] == 0 && pal[255*3+1] == 0 && pal[255*3+2] == 255)
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
fin = (byte *)buffer + mip.offsets[0];
pal = NULL; // clear palette
rendermode = LUMP_NORMAL;
}
else
{
MsgDev( D_ERROR, "Image_LoadMIP: lump (%s) is corrupted\n", name );
return false;
}
if(!Image_ValidSize( name )) return false;
Image_GetPaletteLMP( pal, rendermode );
image_type = (image_flags & IMAGE_HAS_ALPHA) ? PF_INDEXED_32 : PF_INDEXED_24;
return FS_AddMipmapToPack( fin, image_width, image_height, false );
}

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run32( install );

View File

@ -140,6 +140,42 @@ SOURCE=.\common\filesystem.c
# End Source File
# Begin Source File
SOURCE=.\common\img_bmp.c
# End Source File
# Begin Source File
SOURCE=.\common\img_dds.c
# End Source File
# Begin Source File
SOURCE=.\common\img_jpg.c
# End Source File
# Begin Source File
SOURCE=.\common\img_main.c
# End Source File
# Begin Source File
SOURCE=.\common\img_pcx.c
# End Source File
# Begin Source File
SOURCE=.\common\img_png.c
# End Source File
# Begin Source File
SOURCE=.\common\img_tga.c
# End Source File
# Begin Source File
SOURCE=.\common\img_utils.c
# End Source File
# Begin Source File
SOURCE=.\common\img_wad.c
# End Source File
# Begin Source File
SOURCE=.\common\memlib.c
# End Source File
# Begin Source File
@ -168,6 +204,10 @@ SOURCE=.\common\system.c
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\common\filesystem.h
# End Source File
# Begin Source File
SOURCE=.\launcher.h
# End Source File
# End Group

View File

@ -132,7 +132,6 @@ void Con_RegisterHotkeys( void );
//
void Sys_InitCPU( void );
gameinfo_t Sys_GameInfo( void );
uint Sys_SendKeyEvents( void );
void Sys_ParseCommandLine (LPSTR lpCmdLine);
void Sys_LookupInstance( void );
void Sys_NewInstance( const char *name, const char *fmsg );
@ -293,6 +292,7 @@ void FS_DefaultExtension (char *path, const char *extension );
bool FS_GetParmFromCmdLine( char *parm, char *out );
void FS_ExtractFilePath(const char* const path, char* dest);
void FS_UpdateEnvironmentVariables( void );
void FS_FreeEnvironmentVariables( void );
const char *FS_FileWithoutPath (const char *in);
extern char sys_rootdir[];
extern char *fs_argv[];
@ -301,10 +301,12 @@ extern int fs_argc;
// simply files managment interface
byte *FS_LoadFile (const char *path, fs_offset_t *filesizeptr );
bool FS_WriteFile (const char *filename, const void *data, fs_offset_t len);
rgbdata_t *FS_LoadImage(const char *filename, char *data, int size );
void FS_SaveImage(const char *filename, rgbdata_t *buffer );
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t buffsize );
void FS_SaveImage( const char *filename, rgbdata_t *pix );
void FS_FreeImage( rgbdata_t *pack );
bool Image_Processing( const char *name, rgbdata_t **pix, int width, int height );
void FS_GetImageColor( rgbdata_t *pic );
bool Image_Resample( rgbdata_t **image, int width, int height, bool free_baseimage );
bool Image_Process( rgbdata_t **pix, int adjust_type, bool free_baseimage );
search_t *FS_Search(const char *pattern, int caseinsensitive );
search_t *FS_SearchDirs(const char *pattern, int caseinsensitive );
@ -379,10 +381,10 @@ void Cmd_ExecuteString (const char *text);
void Cmd_ForwardToServer (void);
// virtual files managment
vfile_t *VFS_Create(byte *buffer, size_t buffsize);
vfile_t *VFS_Create( const byte *buffer, size_t buffsize );
vfile_t *VFS_Open(file_t *handle, const char* mode);
fs_offset_t VFS_Write( vfile_t *file, const void *buf, size_t size );
fs_offset_t VFS_Read(vfile_t* file, void* buffer, size_t buffersize);
fs_offset_t VFS_Read( vfile_t* file, void* buffer, size_t buffersize);
int VFS_Print(vfile_t* file, const char *msg);
int VFS_Printf(vfile_t* file, const char* format, ...);
int VFS_Seek( vfile_t *file, fs_offset_t offset, int whence );

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( lmpdec );

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,2
#define VER_FILEVERSION_STR "0.2"
#define VER_PRODUCTVERSION 0,2
#define VER_PRODUCTVERSION_STR "0.2"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "lmpdec"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Lump Decompiler"
#define VER_ORIGINALFILENAME_STR "lmpdec.exe"
#define VER_INTERNALNAME_STR "lmpdec"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( mdldec );

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,2
#define VER_FILEVERSION_STR "0.2"
#define VER_PRODUCTVERSION 0,2
#define VER_PRODUCTVERSION_STR "0.2"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "mdldec"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Model Decompiler"
#define VER_ORIGINALFILENAME_STR "mdldec.exe"
#define VER_INTERNALNAME_STR "mdldec"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -596,7 +596,7 @@ void MemList_f( void )
_mem_printstats();
break;
case 2:
_mem_printlist(com.atoi(Cmd_Argv(1)) * 1024);
_mem_printlist(com_atoi(Cmd_Argv(1)) * 1024);
_mem_printstats();
break;
default:

View File

@ -1,28 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = mipdec
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj mipdec.res
$(link) $(OBJS) mipdec.res /out:"mipdec.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘Ş®Ż¨ŕ®˘ ­® ä ©«®˘: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
mipdec.res : mipdec.rc
$(RC) $(RCFLAGS) /r mipdec.rc

Binary file not shown.

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( mipdec );

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,39
#define VER_FILEVERSION_STR "0.39"
#define VER_PRODUCTVERSION 0,39
#define VER_PRODUCTVERSION_STR "0.39"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "mipdec"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Miptex Decompiler"
#define VER_ORIGINALFILENAME_STR "mipdec.exe"
#define VER_INTERNALNAME_STR "mipdec"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -789,7 +789,7 @@ get token on current or newline
*/
char *SC_GetToken( bool newline )
{
if( Sys.app_name == COMP_BSPLIB )
if( Sys.app_name == HOST_BSPLIB )
{
// don't handle single characters
if(SC_ReadTokenSimple( newline ))

View File

@ -7,14 +7,14 @@
!include <win32.mak>
MAINTARGET = lmpdec
MAINTARGET = qcc
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj lmpdec.res
$(link) $(OBJS) lmpdec.res /out:"lmpdec.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
$(MAINTARGET).exe: $(MAINTARGET).obj qcc.res
$(link) $(OBJS) qcc.res /out:"qcc.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@ -24,5 +24,5 @@ clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
lmpdec.res : lmpdec.rc
$(RC) $(RCFLAGS) /r lmpdec.rc
qcc.res : qcc.rc
$(RC) $(RCFLAGS) /r qcc.rc

View File

@ -2,10 +2,10 @@
#define IDI_ICON1 101
#define VER_FILEVERSION 0,29
#define VER_FILEVERSION_STR "0.29"
#define VER_PRODUCTVERSION 0,29
#define VER_PRODUCTVERSION_STR "0.29"
#define VER_FILEVERSION 0,45
#define VER_FILEVERSION_STR "0.45"
#define VER_PRODUCTVERSION 0,45
#define VER_PRODUCTVERSION_STR "0.45"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
@ -14,13 +14,13 @@
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "QccLib Launcher"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2008"
#define VER_PRODUCTNAME_STR "QuakeC compiler"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "QccLib Launcher"
#define VER_ORIGINALFILENAME_STR "qcclib.exe"
#define VER_FILEDESCRIPTION_STR "QuakeC compiler"
#define VER_ORIGINALFILENAME_STR "qcc.exe"
#define VER_INTERNALNAME_STR "qcclib"
#include <common.ver>

BIN
launch/qcc/tool.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@ -1,28 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = qccdec
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj qccdec.res
$(link) $(OBJS) qccdec.res /out:"qccdec.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘ª®¯¨à®¢ ­® ä ©«®¢: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
qccdec.res : qccdec.rc
$(RC) $(RCFLAGS) /r qccdec.rc

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,2
#define VER_FILEVERSION_STR "0.2"
#define VER_PRODUCTVERSION 0,2
#define VER_PRODUCTVERSION_STR "0.2"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "qccdec"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "QuakeC Decompiler"
#define VER_ORIGINALFILENAME_STR "qccdec.exe"
#define VER_INTERNALNAME_STR "qccdec"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1,28 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = roqlib
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj roqlib.res
$(link) $(OBJS) roqlib.res /out:"roqlib.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘ª®¯¨à®¢ ­® ä ©«®¢: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
roqlib.res : roqlib.rc
$(RC) $(RCFLAGS) /r roqlib.rc

Binary file not shown.

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( roqlib );

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,29
#define VER_FILEVERSION_STR "0.29"
#define VER_PRODUCTVERSION 0,29
#define VER_PRODUCTVERSION_STR "0.29"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "RoqLib Launcher"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "R.O.Q. video convertor"
#define VER_ORIGINALFILENAME_STR "roqlib.exe"
#define VER_INTERNALNAME_STR "roqlib"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1,28 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = snddec
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj snddec.res
$(link) $(OBJS) snddec.res /out:"snddec.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘ª®¯¨à®¢ ­® ä ©«®¢: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
snddec.res : snddec.rc
$(RC) $(RCFLAGS) /r snddec.rc

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( snddec );

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -1,28 +0,0 @@
#=============================
# Makefile to build xash utils
# Author: Unkle Mike <xash.ru>
#
# Please associate .nmake files as NMAKE.EXE "/f" "%1" for build this file
#=============================
!include <win32.mak>
MAINTARGET = sprdec
OBJS = $(MAINTARGET).obj
RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj sprdec.res
$(link) $(OBJS) sprdec.res /out:"sprdec.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘ª®¯¨à®¢ ­® ä ©«®¢: 1.
clean:
.cpp.obj:
$(CC) $(CFLAGS) /c $<
sprdec.res : sprdec.rc
$(RC) $(RCFLAGS) /r sprdec.rc

View File

@ -1,7 +0,0 @@
//=======================================================================
// Copyright (C) XashXT Group 2007
//=======================================================================
#include "../rundll.h"
Run( sprdec );

View File

@ -1,28 +0,0 @@
#include <winver.h>
#define IDI_ICON1 101
#define VER_FILEVERSION 0,2
#define VER_FILEVERSION_STR "0.2"
#define VER_PRODUCTVERSION 0,2
#define VER_PRODUCTVERSION_STR "0.2"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
#define VER_FILEOS VOS__WINDOWS32
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "sprdec"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Sprite Decompiler"
#define VER_ORIGINALFILENAME_STR "sprdec.exe"
#define VER_INTERNALNAME_STR "sprdec"
#include <common.ver>
IDI_ICON1 ICON DISCARDABLE "tool.ico"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -14,8 +14,8 @@ RES = $(MAINTARGET).rc
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj spritegen.res
$(link) $(OBJS) spritegen.res /out:"spritegen.exe" /subsystem:console /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
$(link) $(OBJS) spritegen.res /out:"spritegen.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘Ş®Ż¨ŕ®˘ ­® ä ©«®˘: 1.

Binary file not shown.

View File

@ -4,4 +4,4 @@
#include "../rundll.h"
Run( sprite );
Run32( sprite );

View File

@ -2,10 +2,10 @@
#define IDI_ICON1 101
#define VER_FILEVERSION 0,29
#define VER_FILEVERSION_STR "0.29"
#define VER_PRODUCTVERSION 0,29
#define VER_PRODUCTVERSION_STR "0.29"
#define VER_FILEVERSION 1,0
#define VER_FILEVERSION_STR "1.0"
#define VER_PRODUCTVERSION 1,0
#define VER_PRODUCTVERSION_STR "1.0"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
@ -15,13 +15,13 @@
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_PRODUCTNAME_STR "Spritegen"
#define VER_PRODUCTNAME_STR "spritegen"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Sprite Generator"
#define VER_ORIGINALFILENAME_STR "sprite.exe"
#define VER_INTERNALNAME_STR "sprite"
#define VER_ORIGINALFILENAME_STR "spritegen.exe"
#define VER_INTERNALNAME_STR "spritegen"
#include <common.ver>

View File

@ -15,7 +15,7 @@ default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj studiomdl.res
$(link) $(OBJS) studiomdl.res /out:"studiomdl.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘ª®¯¨à®¢ ­® ä ©«®¢: 1.

Binary file not shown.

View File

@ -2,10 +2,10 @@
#define IDI_ICON1 101
#define VER_FILEVERSION 0,48
#define VER_FILEVERSION_STR "0.48"
#define VER_PRODUCTVERSION 0,48
#define VER_PRODUCTVERSION_STR "0.48"
#define VER_FILEVERSION 0,51
#define VER_FILEVERSION_STR "0.51"
#define VER_PRODUCTVERSION 0,51
#define VER_PRODUCTVERSION_STR "0.51"
#define VER_FILEFLAGSMASK VS_FF_PRERELEASE | VS_FF_PATCHED
#define VER_FILEFLAGS VS_FF_PRERELEASE
@ -14,14 +14,14 @@
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_COMPANYNAME_STR "XashXT Group"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2007"
#define VER_LEGALCOPYRIGHT_STR "XashXT 2008"
#define VER_PRODUCTNAME_STR "studiomdl"
#define VER_ANSICP
#define VER_FILEDESCRIPTION_STR "Studio Model Compiler"
#define VER_ORIGINALFILENAME_STR "studio.exe"
#define VER_INTERNALNAME_STR "studio"
#define VER_ORIGINALFILENAME_STR "studiomdl.exe"
#define VER_INTERNALNAME_STR "studiomdl"
#include <common.ver>

View File

@ -177,6 +177,16 @@ void Sys_GetStdAPI( void )
com.Com_DoubleTime = Sys_DoubleTime; // hi-res timer
com.Com_Milliseconds = Sys_Milliseconds;
// built-in imagelib functions
com.LoadImage = FS_LoadImage; // return 8, 24 or 32 bit buffer with image info
com.GetImageColor = FS_GetImageColor; // returns color of image (bsplib uses)
com.SaveImage = FS_SaveImage; // save image into specified format
com.FreeImage = FS_FreeImage; // free image buffer
// image manipulation
com.ResampleImage = Image_Resample; // resample image
com.ProcessImage = Image_Process; // flip, rotate e.t.c
com.Com_RandomLong = Com_RandomLong;
com.Com_RandomFloat = Com_RandomFloat;
@ -240,6 +250,7 @@ This list will be expnaded in future
void Sys_LookupInstance( void )
{
char szTemp[4096];
bool dedicated = false;
Sys.app_name = HOST_OFFLINE;
// we can specified custom name, from Sys_NewInstance
@ -249,31 +260,90 @@ void Sys_LookupInstance( void )
// determine host type
if( Sys.ModuleName[0] == '#' || Sys.ModuleName[0] == '©' )
{
if( Sys.ModuleName[0] == '#' ) com_strcpy( Sys.progname, "dedicated" );
if( Sys.ModuleName[0] == '©' ) com_strcpy( Sys.progname, "splash" );
if( Sys.ModuleName[0] == '#' ) dedicated = true;
if( Sys.ModuleName[0] == '©' ) com_strcpy( Sys.progname, "credits" );
// cutoff hidden symbols
com_strncpy( szTemp, Sys.ModuleName + 1, MAX_SYSPATH );
com_strncpy( Sys.ModuleName, szTemp, MAX_SYSPATH );
}
// lookup all instances
if(!com_strcmp(Sys.progname, "normal"))
if(!com_strcmp(Sys.progname, "credits"))
{
Sys.app_name = HOST_NORMAL;
Sys.con_readonly = true;
// don't show console as default
if(!Sys.debug) Sys.con_showalways = false;
Sys.app_name = HOST_CREDITS; // easter egg
Sys.linked_dll = NULL; // no need to loading library
Sys.log_active = Sys.developer = Sys.debug = 0; // clear all dbg states
com_strcpy(Sys.caption, "About");
Sys.con_showcredits = true;
}
else if(!com_strcmp(Sys.progname, "uninstall")) // write path into registry
{
Sys.app_name = HOST_UNINSTALL;
Sys.linked_dll = NULL; // no need to loading library
Sys.log_active = Sys.developer = Sys.debug = 0; // clear all dbg states
Sys.con_silentmode = true;
}
else if(!com_strcmp(Sys.progname, "normal"))
{
if( dedicated )
{
Sys.app_name = HOST_DEDICATED;
Sys.con_readonly = false;
}
else
{
Sys.app_name = HOST_NORMAL;
Sys.con_readonly = true;
// don't show console as default
if(!Sys.debug) Sys.con_showalways = false;
}
Sys.linked_dll = &engine_dll; // pointer to engine.dll info
com_sprintf(Sys.log_path, "engine.log", com_timestamp(TIME_NO_SECONDS)); // logs folder
com_strcpy(Sys.caption, va("Xash3D ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "dedicated"))
else if(!com_strcmp(Sys.progname, "bsplib"))
{
Sys.app_name = HOST_DEDICATED;
Sys.con_readonly = false;
Sys.linked_dll = &engine_dll; // pointer to engine.dll info
com_sprintf(Sys.log_path, "engine.log", com_timestamp(TIME_NO_SECONDS)); // logs folder
com_strcpy(Sys.caption, va("Xash3D ver.%g", XASH_VERSION ));
Sys.app_name = HOST_BSPLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_strcpy(Sys.log_path, "bsplib.log" ); // xash3d root directory
com_strcpy(Sys.caption, "Xash3D BSP Compiler");
}
else if(!com_strcmp(Sys.progname, "qcclib"))
{
Sys.app_name = HOST_QCCLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/compile.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D QuakeC Compiler");
}
else if(!com_strcmp(Sys.progname, "sprite"))
{
Sys.app_name = HOST_SPRITE;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/spritegen.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Sprite Compiler");
}
else if(!com_strcmp(Sys.progname, "studio"))
{
Sys.app_name = HOST_STUDIO;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/studiomdl.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Studio Models Compiler");
}
else if(!com_strcmp(Sys.progname, "wadlib"))
{
Sys.app_name = HOST_WADLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/wadlib.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Wad2\\Wad3 maker");
}
else if(!com_strcmp(Sys.progname, "ripper"))
{
Sys.app_name = HOST_RIPPER;
Sys.con_readonly = true;
Sys.log_active = true; // always create log
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/decompile.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Quake Recource Extractor ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "viewer"))
{
@ -285,120 +355,6 @@ void Sys_LookupInstance( void )
com_sprintf(Sys.log_path, "%s/editor.log", sys_rootdir ); // logs folder
com_strcpy(Sys.caption, va("Xash3D Resource Viewer ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "splash"))
{
Sys.app_name = HOST_CREDITS; // easter egg
Sys.linked_dll = NULL; // no need to loading library
Sys.log_active = Sys.developer = Sys.debug = 0; // clear all dbg states
com_strcpy(Sys.caption, "About");
Sys.con_showcredits = true;
}
else if(!com_strcmp(Sys.progname, "install")) // write path into registry
{
Sys.app_name = HOST_INSTALL;
Sys.linked_dll = NULL; // no need to loading library
Sys.log_active = Sys.developer = Sys.debug = 0; //clear all dbg states
Sys.con_silentmode = true;
}
else if(!com_strcmp(Sys.progname, "bsplib"))
{
Sys.app_name = COMP_BSPLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_strcpy(Sys.log_path, "bsplib.log" ); // xash3d root directory
com_strcpy(Sys.caption, "Xash3D BSP Compiler");
}
else if(!com_strcmp(Sys.progname, "qcclib"))
{
Sys.app_name = COMP_QCCLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/compile.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D QuakeC Compiler");
}
else if(!com_strcmp(Sys.progname, "roqlib"))
{
Sys.app_name = COMP_ROQLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/roq.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D ROQ Video Maker");
}
else if(!com_strcmp(Sys.progname, "sprite"))
{
Sys.app_name = COMP_SPRITE;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/spritegen.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Sprite Compiler");
}
else if(!com_strcmp(Sys.progname, "studio"))
{
Sys.app_name = COMP_STUDIO;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/studiomdl.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Studio Models Compiler");
}
else if(!com_strcmp(Sys.progname, "wadlib"))
{
Sys.app_name = COMP_WADLIB;
Sys.linked_dll = &common_dll; // pointer to common.dll info
com_sprintf(Sys.log_path, "%s/wadlib.log", sys_rootdir ); // same as .exe file
com_strcpy(Sys.caption, "Xash3D Wad2\\Wad3 maker");
}
else if(!com_strcmp(Sys.progname, "mipdec"))
{
Sys.app_name = RIPP_MIPDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/textures.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Texture Ripper ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "sprdec"))
{
Sys.app_name = RIPP_SPRDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/sprites.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Sprite Ripper ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "mdldec"))
{
Sys.app_name = RIPP_MDLDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/models.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Model Ripper ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "lmpdec"))
{
Sys.app_name = RIPP_LMPDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/lumps.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Picture Ripper ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "snddec"))
{
Sys.app_name = RIPP_SNDDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/sound.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Sound Ripper ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "bspdec"))
{
Sys.app_name = RIPP_BSPDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/maps.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("Bsp Decompiler ver.%g", XASH_VERSION ));
}
else if(!com_strcmp(Sys.progname, "qccdec"))
{
Sys.app_name = RIPP_QCCDEC;
Sys.con_readonly = true;
Sys.linked_dll = &ripper_dll; // pointer to wdclib.dll info
com_sprintf(Sys.log_path, "%s/source.log", sys_rootdir ); // default
com_strcpy(Sys.caption, va("QuakeC Decompiler ver.%g", XASH_VERSION ));
}
// share instance over all system
GI.instance = Sys.app_name;
}
@ -422,19 +378,12 @@ void Sys_CreateInstance( void )
case HOST_NORMAL:
case HOST_DEDICATED:
case HOST_VIEWER:
case COMP_BSPLIB:
case COMP_QCCLIB:
case COMP_ROQLIB:
case COMP_SPRITE:
case COMP_STUDIO:
case COMP_WADLIB:
case RIPP_MIPDEC:
case RIPP_SPRDEC:
case RIPP_MDLDEC:
case RIPP_LMPDEC:
case RIPP_SNDDEC:
case RIPP_BSPDEC:
case RIPP_QCCDEC:
case HOST_BSPLIB:
case HOST_QCCLIB:
case HOST_SPRITE:
case HOST_STUDIO:
case HOST_WADLIB:
case HOST_RIPPER:
Sys_LoadLibrary( &baserc_dll ); // load baserc
CreateHost = (void *)Sys.linked_dll->main;
Host = CreateHost( &com, NULL ); // second interface not allowed
@ -452,12 +401,12 @@ void Sys_CreateInstance( void )
case HOST_CREDITS:
Sys_Break( show_credits );
break;
case HOST_INSTALL:
// FS_UpdateEnvironmentVariables() is done, quit now
case HOST_UNINSTALL:
FS_FreeEnvironmentVariables();
Sys_Exit();
break;
case HOST_OFFLINE:
Sys_Break("Host offline\n");
Sys_Break( "Host offline\n" );
break;
}
@ -478,19 +427,12 @@ void Sys_CreateInstance( void )
case HOST_VIEWER:
Con_ShowConsole( false );
// intentional falltrough
case COMP_BSPLIB:
case COMP_QCCLIB:
case COMP_ROQLIB:
case COMP_SPRITE:
case COMP_STUDIO:
case COMP_WADLIB:
case RIPP_MIPDEC:
case RIPP_SPRDEC:
case RIPP_MDLDEC:
case RIPP_LMPDEC:
case RIPP_SNDDEC:
case RIPP_BSPDEC:
case RIPP_QCCDEC:
case HOST_BSPLIB:
case HOST_QCCLIB:
case HOST_SPRITE:
case HOST_STUDIO:
case HOST_WADLIB:
case HOST_RIPPER:
// always run stuffcmds for current instances
Cbuf_ExecuteText( EXEC_NOW, "stuffcmds\n" );
break;
@ -500,21 +442,6 @@ void Sys_CreateInstance( void )
Sys.app_state = SYS_FRAME; // system is now active
}
uint Sys_SendKeyEvents( void )
{
MSG msg;
int msg_time;
while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
{
if(!GetMessage (&msg, NULL, 0, 0)) break;
msg_time = msg.time;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.time;
}
/*
==================
Sys_ParseCommandLine
@ -823,7 +750,7 @@ void Sys_WaitForQuit( void )
if(abs((int)GetStdHandle(STD_OUTPUT_HANDLE)) <= 100)
{
Sys_Print("press any key to quit\n");
system("@pause\n"); // wait for quit
system("@pause>nul\n"); // wait for quit
}
}
else
@ -916,6 +843,7 @@ void Sys_Init( void )
Sys.hInstance = (HINSTANCE)GetModuleHandle( NULL ); // get current hInstance first
Sys_GetStdAPI();
Sys.MSG_Init = NULL;
Sys.Init = NullInit;
Sys.Main = NullFunc;
Sys.Free = NullFunc;
@ -961,6 +889,7 @@ void Sys_Init( void )
Cmd_Init();
Cvar_Init();
FS_Init();
Image_Init();
Sys_CreateInstance();
}
@ -973,6 +902,7 @@ void Sys_Shutdown( void )
Sys_FreeLibrary( &baserc_dll );
FS_Shutdown();
Image_Shutdown();
Memory_Shutdown();
Con_DestroyConsole();
}

View File

@ -7,13 +7,13 @@
!include <win32.mak>
MAINTARGET = install
MAINTARGET = uninstall
OBJS = $(MAINTARGET).obj
default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj
$(link) $(OBJS) /out:"install.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
$(link) $(OBJS) /out:"uninstall.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp > nul
@copy $(MAINTARGET).exe D:\Xash3D\bin\$(MAINTARGET).exe
@del $(MAINTARGET).exe

View File

@ -4,4 +4,4 @@
#include "../rundll.h"
Run32( splash );
Run32( uninstall );

View File

@ -16,7 +16,7 @@ default: $(MAINTARGET).exe
$(MAINTARGET).exe: $(MAINTARGET).obj viewer.res
$(link) $(OBJS) viewer.res /out:"viewer.exe" /subsystem:windows /opt:nowin98 /nodefaultlib:"libc.lib"
@del $(MAINTARGET).obj $(MAINTARGET).lib $(MAINTARGET).exp $(MAINTARGET).res > nul
@copy $(MAINTARGET).exe D:\Xash3D\sdk_main\tools\$(MAINTARGET).exe
@copy $(MAINTARGET).exe D:\Xash3D\$(MAINTARGET).exe
@del $(MAINTARGET).exe
@echo ‘Ş®Ż¨ŕ®˘ ­® ä ©«®˘: 1.
clean:

Some files were not shown because too many files have changed in this diff Show More