diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c index 361b2eba..7ea327e7 100644 --- a/src/refresh/files/pcx.c +++ b/src/refresh/files/pcx.c @@ -142,3 +142,24 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height ) ri.FS_FreeFile( pcx ); } + +qboolean +GetPCXInfo (char *filename, int *width, int *height) +{ + pcx_t *pcx; + byte *raw; + + ri.FS_LoadFile (filename, (void **)&raw); + if (!raw) + return false; + + pcx = (pcx_t *)raw; + + *width = pcx->xmax + 1; + *height = pcx->ymax + 1; + + ri.FS_FreeFile (raw); + + return true; +} + diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index 1ba6d8f8..472a8aef 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -319,6 +319,7 @@ 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 ); +qboolean GetPCXInfo ( char *filename, int *width, int *height ); image_t *R_LoadPic ( char *name, byte *pic, int width, int realwidth, int height, int realheight, 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 d145650f..1e3977a9 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -1069,14 +1069,55 @@ R_FindImage ( char *name, imagetype_t type ) if ( !strcmp( name + len - 4, ".pcx" ) ) { - LoadPCX( name, &pic, &palette, &width, &height ); - - if ( !pic ) + if (gl_retexturing->value) { - return ( NULL ); - } + GetPCXInfo( name, &realwidth, &realheight ); - image = R_LoadPic( name, pic, width, 0, height, 0, type, 8 ); + /* Try to load a TGA */ + LoadTGA( namewe, &pic, &width, &height ); + + if ( !pic ) + { + /* JPEG if no TGA available */ + LoadJPG( namewe, &pic, &width, &height); + } + else + { + /* Upload TGA */ + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); + } + + if( !pic ) + { + /* PCX if no JPEG available (exists always) */ + LoadPCX( name, &pic, &palette, &width, &height ); + + if ( !pic ) + { + /* No texture found */ + return ( NULL ); + } + + /* Upload the PCX */ + image = R_LoadPic( name, pic, width, 0, height, 0, type, 8 ); + } + else + { + /* Upload JPEG */ + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); + } + } + else + { + LoadPCX( name, &pic, &palette, &width, &height ); + + if ( !pic ) + { + return ( NULL ); + } + + image = R_LoadPic( name, pic, width, 0, height, 0, type, 8 ); + } } else if ( !strcmp( name + len - 4, ".wal" ) ) {