Reactor yesterdays work

This commit is contained in:
Yamagi Burmeister 2012-03-12 08:11:22 +00:00
parent 1d8109cbbc
commit 9edf27f103
7 changed files with 76 additions and 85 deletions

View file

@ -41,13 +41,6 @@ CC := gcc
# ----------
# Options
# Enables .jpg texture support
JPEG := 1
# ----------
# Base CFLAGS.
#
# -O2 are enough optimizations.
@ -175,12 +168,7 @@ build/refresher/%.o: %.c
${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(INCLUDE) -o $@ $<
release/ref_gl.so : CFLAGS += -fPIC
release/ref_gl.so : LDFLAGS += -shared
ifdef JPEG
release/ref_gl.so : CFLAGS += -DWITH_JPEG
release/ref_gl.so : LDFLAGS += -ljpeg
endif
release/ref_gl.so : LDFLAGS += -shared -ljpeg
# ----------

View file

@ -24,8 +24,6 @@
* =======================================================================
*/
#ifdef WITH_JPEG
#include "../header/local.h"
#include <jpeglib.h>
@ -55,7 +53,7 @@ void jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
cinfo->src->bytes_in_buffer -= (size_t) num_bytes;
}
void jpeg_mem_src (j_decompress_ptr cinfo, byte *mem, int len)
void jpeg_mem_src (j_decompress_ptr cinfo, unsigned char *mem, unsigned long len)
{
cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(struct jpeg_source_mgr));
cinfo->src->init_source = jpg_null;
@ -72,10 +70,9 @@ void jpeg_mem_src (j_decompress_ptr cinfo, byte *mem, int len)
LoadJPG
==============
*/
image_t *
LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
void
LoadJPG (char *origname, byte **pic, int *width, int *height)
{
byte *pic = NULL;
struct jpeg_decompress_struct cinfo;
char filename[256];
struct jpeg_error_mgr jerr;
@ -83,35 +80,37 @@ LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
byte *rawdata, *rgbadata, *scanline, *p, *q;
unsigned int rawsize, i;
len = strlen( oldname );
/* Add the extension */
len = strlen( origname );
if ( strcmp( oldname + len - 4, ".jpg" ) )
if ( strcmp( origname + len - 4, ".jpg" ) )
{
strncpy(filename, oldname, 256);
strncpy(filename, origname, 256);
strncat(filename, ".jpg", 255);
}
else
{
strncpy(filename, oldname, 256);
strncpy(filename, origname, 256);
}
*pic = NULL;
// Load JPEG file into memory
rawsize = ri.FS_LoadFile(filename, (void **)&rawdata);
if (!rawdata)
return NULL;
return;
if (rawsize < 10 || rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
{
ri.Con_Printf (PRINT_ALL, "Invalid JPEG header: %s\n", filename);
ri.FS_FreeFile(rawdata);
return NULL;
return;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, rawdata, rawsize);
jpeg_mem_src(&cinfo, (unsigned char *) rawdata, (unsigned long) rawsize);
jpeg_read_header(&cinfo, true);
jpeg_start_decompress(&cinfo);
@ -120,7 +119,7 @@ LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
ri.Con_Printf(PRINT_ALL, "Invalid JPEG colour components\n");
jpeg_destroy_decompress(&cinfo);
ri.FS_FreeFile(rawdata);
return NULL;
return;
}
// Allocate Memory for decompressed image
@ -130,7 +129,7 @@ LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
ri.Con_Printf(PRINT_ALL, "Insufficient memory for JPEG buffer\n");
jpeg_destroy_decompress(&cinfo);
ri.FS_FreeFile(rawdata);
return NULL;
return;
}
// Pass sizes to output
@ -145,7 +144,7 @@ LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
free (rgbadata);
jpeg_destroy_decompress (&cinfo);
ri.FS_FreeFile (rawdata);
return NULL;
return;
}
// Read Scanlines, and expand from RGB to RGBA
@ -170,14 +169,6 @@ LoadJPG (char *oldname, int *width, int *height, imagetype_t type)
jpeg_finish_decompress (&cinfo);
jpeg_destroy_decompress (&cinfo);
pic = rgbadata;
if ( !pic )
{
return ( NULL );
}
return R_LoadPic( filename, pic, *width, *height, type, 32 );
*pic = rgbadata;
}
#endif // WITH_JPEG

View file

@ -27,7 +27,7 @@
#include "../header/local.h"
void
LoadPCX ( char *oldname, byte **pic, byte **palette, int *width, int *height )
LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height )
{
byte *raw;
pcx_t *pcx;
@ -38,16 +38,17 @@ LoadPCX ( char *oldname, byte **pic, byte **palette, int *width, int *height )
byte *out, *pix;
char filename[256];
filelen = strlen( oldname );
/* Add the extension */
filelen = strlen( origname );
if ( strcmp( oldname + filelen - 4, ".pcx" ) )
if ( strcmp( origname + filelen - 4, ".pcx" ) )
{
strncpy(filename, oldname, 256);
strncpy(filename, origname, 256);
strncat(filename, ".pcx", 255);
}
else
{
strncpy(filename, oldname, 256);
strncpy(filename, origname, 256);
}
*pic = NULL;

View file

@ -35,10 +35,9 @@ typedef struct _TargaHeader
unsigned char pixel_size, attributes;
} TargaHeader;
image_t *
LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
void
LoadTGA ( char *origname, byte **pic, int *width, int *height )
{
byte *pic = NULL;
int columns, rows, numPixels;
byte *pixbuf;
int row, column;
@ -51,16 +50,17 @@ LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
byte tmp [ 2 ];
char name[256];
len = strlen( oldname );
/* Add the extension */
len = strlen( origname );
if ( strcmp( oldname + len - 4, ".tga" ) )
if ( strcmp( origname + len - 4, ".tga" ) )
{
strncpy( name, oldname, 256 );
strncpy( name, origname, 256 );
strncat(name, ".tga", 255);
}
else
{
strncpy( name, oldname, 256 );
strncpy( name, origname, 256 );
}
@ -70,7 +70,7 @@ LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
if ( !buffer )
{
ri.Con_Printf( PRINT_DEVELOPER, "Bad tga file %s\n", name );
return NULL;
return;
}
buf_p = buffer;
@ -115,8 +115,6 @@ LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
rows = targa_header.height;
numPixels = columns * rows;
// FIXME Custommaps
if ( width )
{
*width = columns;
@ -127,9 +125,8 @@ LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
*height = rows;
}
targa_rgba = malloc( numPixels * 4 );
pic = targa_rgba;
*pic = targa_rgba;
if ( targa_header.id_length != 0 )
{
@ -288,12 +285,5 @@ LoadTGA ( char *oldname, int *width, int *height, imagetype_t type )
}
ri.FS_FreeFile( buffer );
if ( !pic )
{
return ( NULL );
}
return R_LoadPic( name, pic, *width, *height, type, 32 );
}

View file

@ -1,7 +1,7 @@
#include "../header/local.h"
image_t *
LoadWal ( char *oldname )
LoadWal ( char *origname )
{
miptex_t *mt;
int width, height, ofs;
@ -9,16 +9,17 @@ LoadWal ( char *oldname )
int len;
char name[256];
len = strlen( oldname );
/* Add the extension */
len = strlen( origname );
if ( strcmp( oldname + len - 4, ".wal" ) )
if ( strcmp( origname + len - 4, ".wal" ) )
{
strncpy(name, oldname, 256);
strncpy(name, origname, 256);
strncat(name, ".wal", 255);
}
else
{
strncpy(name, oldname, 256);
strncpy(name, origname, 256);
}
ri.FS_LoadFile( name, (void **) &mt );

View file

@ -313,7 +313,10 @@ void R_ResampleTexture ( unsigned *in, int inwidth, int inheight, unsigned *out,
struct image_s *R_RegisterSkin ( char *name );
void LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *height );
qboolean GetWalInfo (char *name, int *width, int *height);
image_t *LoadWal ( char *name );
void LoadJPG ( char *origname, byte **pic, int *width, int *height );
void LoadTGA ( char *origname, byte **pic, int *width, int *height );
qboolean GetWalInfo ( char *name, int *width, int *height );
image_t *R_LoadPic ( char *name, byte *pic, int width, int height, imagetype_t type, int bits );
image_t *R_FindImage ( char *name, imagetype_t type );
void R_TextureMode ( char *string );

View file

@ -51,11 +51,6 @@ int gl_tex_alpha_format = 4;
int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
int gl_filter_max = GL_LINEAR;
image_t *LoadWal ( char *name );
image_t *LoadTGA ( char *name, int *width, int *height, imagetype_t type );
#ifdef WITH_JPEG
image_t *LoadJPG (char *filename, int *width, int *height, imagetype_t type);
#endif
int Draw_GetPalette ( void );
typedef struct
@ -1027,10 +1022,12 @@ R_FindImage ( char *name, imagetype_t type )
return ( NULL );
}
memset(namewe, 0, 256);
len = strlen( name );
/* Remove the extension */
memset(namewe, 0, 256);
memcpy(namewe, name, len - 4);
if ( len < 5 )
{
return ( NULL );
@ -1069,29 +1066,49 @@ R_FindImage ( char *name, imagetype_t type )
}
else if ( !strcmp( name + len - 4, ".wal" ) )
{
/* Remove the extension */
memcpy(namewe, name, len - 4);
/* Get size of the original texture */
GetWalInfo(name, &realwidth, &realheight);
image = LoadTGA( namewe, &width, &height, type );
if( image == NULL )
/* Try to load a TGA */
LoadTGA( namewe, &pic, &width, &height );
if( !pic )
{
image = LoadJPG( namewe, &width, &height, type );
/* JPEG if no TGA available */
LoadJPG( namewe, &pic, &width, &height );
}
else
{
/* Upload TGA */
image = R_LoadPic( name, pic, width, height, type, 32 );
}
if( image == NULL)
if( !pic )
{
/* WAL of no JPEG available (exists always) */
image = LoadWal( namewe );
}
else
{
/* Upload JPEG */
image = R_LoadPic( name, pic, width, height, type, 32 );
}
if ( !image )
{
/* No texture found */
return ( NULL );
}
}
else if ( !strcmp( name + len - 4, ".tga" ) )
{
return LoadTGA( name, &width, &height, type );
LoadTGA( name, &pic, &width, &height );
image = R_LoadPic( name, pic, width, height, type, 32 );
}
else if ( !strcmp( name + len - 4, ".jpg" ) )
{
return LoadJPG( name, &width, &height, type );
LoadJPG( name, &pic, &width, &height );
image = R_LoadPic( name, pic, width, height, type, 32 );
}
else
{