From 1d8109cbbca40a602e95a8cd65d7c4206233aa7c Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 11 Mar 2012 19:01:49 +0000 Subject: [PATCH] Work in progress version of the retexterung support. The next step is to alter r_LoadPic, so that it accepts realwidth and realheight as additional arguments and uses them to manipualte image after uploading it into the vram. --- src/refresh/files/jpeg.c | 17 ++++++++++++++++- src/refresh/files/pcx.c | 16 +++++++++++++++- src/refresh/files/tga.c | 20 +++++++++++++++++++- src/refresh/files/wal.c | 36 ++++++++++++++++++++++++++++++++++-- src/refresh/header/local.h | 1 + src/refresh/r_image.c | 20 +++++++++++++++++++- 6 files changed, 104 insertions(+), 6 deletions(-) diff --git a/src/refresh/files/jpeg.c b/src/refresh/files/jpeg.c index a073fdfb..a42cd165 100644 --- a/src/refresh/files/jpeg.c +++ b/src/refresh/files/jpeg.c @@ -73,14 +73,29 @@ LoadJPG ============== */ image_t * -LoadJPG (char *filename, int *width, int *height, imagetype_t type) +LoadJPG (char *oldname, int *width, int *height, imagetype_t type) { byte *pic = NULL; struct jpeg_decompress_struct cinfo; + char filename[256]; struct jpeg_error_mgr jerr; + int len; byte *rawdata, *rgbadata, *scanline, *p, *q; unsigned int rawsize, i; + len = strlen( oldname ); + + if ( strcmp( oldname + len - 4, ".jpg" ) ) + { + strncpy(filename, oldname, 256); + strncat(filename, ".jpg", 255); + } + else + { + strncpy(filename, oldname, 256); + } + + // Load JPEG file into memory rawsize = ri.FS_LoadFile(filename, (void **)&rawdata); diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c index f52834f6..d1c0dea5 100644 --- a/src/refresh/files/pcx.c +++ b/src/refresh/files/pcx.c @@ -27,14 +27,28 @@ #include "../header/local.h" void -LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *height ) +LoadPCX ( char *oldname, byte **pic, byte **palette, int *width, int *height ) { byte *raw; pcx_t *pcx; int x, y; int len; + int filelen; int dataByte, runLength; byte *out, *pix; + char filename[256]; + + filelen = strlen( oldname ); + + if ( strcmp( oldname + filelen - 4, ".pcx" ) ) + { + strncpy(filename, oldname, 256); + strncat(filename, ".pcx", 255); + } + else + { + strncpy(filename, oldname, 256); + } *pic = NULL; *palette = NULL; diff --git a/src/refresh/files/tga.c b/src/refresh/files/tga.c index a2371496..a4f7fdb1 100644 --- a/src/refresh/files/tga.c +++ b/src/refresh/files/tga.c @@ -36,7 +36,7 @@ typedef struct _TargaHeader } TargaHeader; image_t * -LoadTGA ( char *name, int *width, int *height, imagetype_t type ) +LoadTGA ( char *oldname, int *width, int *height, imagetype_t type ) { byte *pic = NULL; int columns, rows, numPixels; @@ -45,9 +45,24 @@ LoadTGA ( char *name, int *width, int *height, imagetype_t type ) byte *buf_p; byte *buffer; int length; + int len; TargaHeader targa_header; byte *targa_rgba; byte tmp [ 2 ]; + char name[256]; + + len = strlen( oldname ); + + if ( strcmp( oldname + len - 4, ".tga" ) ) + { + strncpy( name, oldname, 256 ); + strncat(name, ".tga", 255); + } + else + { + strncpy( name, oldname, 256 ); + } + /* load the file */ length = ri.FS_LoadFile( name, (void **) &buffer ); @@ -100,6 +115,8 @@ LoadTGA ( char *name, int *width, int *height, imagetype_t type ) rows = targa_header.height; numPixels = columns * rows; + // FIXME Custommaps + if ( width ) { *width = columns; @@ -110,6 +127,7 @@ LoadTGA ( char *name, int *width, int *height, imagetype_t type ) *height = rows; } + targa_rgba = malloc( numPixels * 4 ); pic = targa_rgba; diff --git a/src/refresh/files/wal.c b/src/refresh/files/wal.c index 0db23893..0ba6def1 100644 --- a/src/refresh/files/wal.c +++ b/src/refresh/files/wal.c @@ -1,11 +1,25 @@ #include "../header/local.h" image_t * -LoadWal ( char *name ) +LoadWal ( char *oldname ) { miptex_t *mt; int width, height, ofs; image_t *image; + int len; + char name[256]; + + len = strlen( oldname ); + + if ( strcmp( oldname + len - 4, ".wal" ) ) + { + strncpy(name, oldname, 256); + strncat(name, ".wal", 255); + } + else + { + strncpy(name, oldname, 256); + } ri.FS_LoadFile( name, (void **) &mt ); @@ -24,5 +38,23 @@ LoadWal ( char *name ) ri.FS_FreeFile( (void *) mt ); return ( image ); -} +} + +qboolean GetWalInfo (char *name, int *width, int *height) +{ + miptex_t *mt; + + ri.FS_LoadFile (name, (void **)&mt); + + if (!mt) + { + return false; + } + + *width = LittleLong (mt->width); + *height = LittleLong (mt->height); + + ri.FS_FreeFile ((void *)mt); + return true; +} diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index dba0bb21..df484f98 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -313,6 +313,7 @@ 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 *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 ); diff --git a/src/refresh/r_image.c b/src/refresh/r_image.c index ae3d2987..8985049a 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -1018,13 +1018,17 @@ R_FindImage ( char *name, imagetype_t type ) int i, len; byte *pic, *palette; int width, height; + int realwidth, realheight; char *ptr; + char namewe[256]; if ( !name ) { return ( NULL ); } + memset(namewe, 0, 256); + len = strlen( name ); if ( len < 5 ) @@ -1065,7 +1069,21 @@ R_FindImage ( char *name, imagetype_t type ) } else if ( !strcmp( name + len - 4, ".wal" ) ) { - image = LoadWal( name ); + /* Remove the extension */ + memcpy(namewe, name, len - 4); + + GetWalInfo(name, &realwidth, &realheight); + image = LoadTGA( namewe, &width, &height, type ); + + if( image == NULL ) + { + image = LoadJPG( namewe, &width, &height, type ); + } + + if( image == NULL) + { + image = LoadWal( namewe ); + } } else if ( !strcmp( name + len - 4, ".tga" ) ) {