From ccf45a3b6e90aa42f49fdb5c7a7b3a83ef4dfbbb Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 11 Mar 2012 15:43:27 +0000 Subject: [PATCH 01/15] Create a branch for retexturing support From 441c988b31c3e865c7467b8f721d6c2af81892a4 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 11 Mar 2012 16:50:57 +0000 Subject: [PATCH 02/15] - Add JPEG support - Refactor call to LoadTGA so it returns image_t * directly --- Makefile | 13 +++ src/refresh/files/jpeg.c | 168 +++++++++++++++++++++++++++++++++++++++ src/refresh/files/tga.c | 18 +++-- src/refresh/r_image.c | 18 ++--- 4 files changed, 202 insertions(+), 15 deletions(-) create mode 100644 src/refresh/files/jpeg.c diff --git a/Makefile b/Makefile index 225bb19c..27a4a92e 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,13 @@ CC := gcc # ---------- +# Options + +# Enables .jpg texture support +JPEG := 1 + +# ---------- + # Base CFLAGS. # # -O2 are enough optimizations. @@ -169,6 +176,11 @@ build/refresher/%.o: %.c 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 # ---------- @@ -376,6 +388,7 @@ OPENGL_OBJS_ = \ src/refresh/files/pcx.o \ src/refresh/files/sp2.o \ src/refresh/files/tga.o \ + src/refresh/files/jpeg.o \ src/refresh/files/wal.o \ src/sdl/input.o \ src/sdl/refresh.o \ diff --git a/src/refresh/files/jpeg.c b/src/refresh/files/jpeg.c new file mode 100644 index 00000000..a073fdfb --- /dev/null +++ b/src/refresh/files/jpeg.c @@ -0,0 +1,168 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * The JPEG image format + * + * ======================================================================= + */ + +#ifdef WITH_JPEG + +#include "../header/local.h" +#include + +/* +================================================================= + +JPEG LOADING +NiceAss: Code from Q2Ice + +================================================================= +*/ + +void jpg_null(j_decompress_ptr cinfo) +{ +} + +boolean jpg_fill_input_buffer(j_decompress_ptr cinfo) +{ + ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); + return 1; +} + +void jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) +{ + + cinfo->src->next_input_byte += (size_t) num_bytes; + cinfo->src->bytes_in_buffer -= (size_t) num_bytes; +} + +void jpeg_mem_src (j_decompress_ptr cinfo, byte *mem, int 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; + cinfo->src->fill_input_buffer = jpg_fill_input_buffer; + cinfo->src->skip_input_data = jpg_skip_input_data; + cinfo->src->resync_to_restart = jpeg_resync_to_restart; + cinfo->src->term_source = jpg_null; + cinfo->src->bytes_in_buffer = len; + cinfo->src->next_input_byte = mem; +} + +/* +============== +LoadJPG +============== +*/ +image_t * +LoadJPG (char *filename, int *width, int *height, imagetype_t type) +{ + byte *pic = NULL; + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + byte *rawdata, *rgbadata, *scanline, *p, *q; + unsigned int rawsize, i; + + // Load JPEG file into memory + rawsize = ri.FS_LoadFile(filename, (void **)&rawdata); + + if (!rawdata) + return NULL; + + 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; + } + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_mem_src(&cinfo, rawdata, rawsize); + jpeg_read_header(&cinfo, true); + jpeg_start_decompress(&cinfo); + + if(cinfo.output_components != 3 && cinfo.output_components != 4) + { + ri.Con_Printf(PRINT_ALL, "Invalid JPEG colour components\n"); + jpeg_destroy_decompress(&cinfo); + ri.FS_FreeFile(rawdata); + return NULL; + } + + // Allocate Memory for decompressed image + rgbadata = malloc(cinfo.output_width * cinfo.output_height * 4); + if(!rgbadata) + { + ri.Con_Printf(PRINT_ALL, "Insufficient memory for JPEG buffer\n"); + jpeg_destroy_decompress(&cinfo); + ri.FS_FreeFile(rawdata); + return NULL; + } + + // Pass sizes to output + *width = cinfo.output_width; + *height = cinfo.output_height; + + // Allocate Scanline buffer + scanline = malloc (cinfo.output_width * 3); + if (!scanline) + { + ri.Con_Printf (PRINT_ALL, "Insufficient memory for JPEG scanline buffer\n"); + free (rgbadata); + jpeg_destroy_decompress (&cinfo); + ri.FS_FreeFile (rawdata); + return NULL; + } + + // Read Scanlines, and expand from RGB to RGBA + q = rgbadata; + while (cinfo.output_scanline < cinfo.output_height) + { + p = scanline; + jpeg_read_scanlines(&cinfo, &scanline, 1); + + for (i = 0; i < cinfo.output_width; i++) + { + q[0] = p[0]; + q[1] = p[1]; + q[2] = p[2]; + q[3] = 255; + p += 3; + q += 4; + } + } + + free (scanline); + jpeg_finish_decompress (&cinfo); + jpeg_destroy_decompress (&cinfo); + + pic = rgbadata; + + if ( !pic ) + { + return ( NULL ); + } + + return R_LoadPic( filename, pic, *width, *height, type, 32 ); +} + +#endif // WITH_JPEG diff --git a/src/refresh/files/tga.c b/src/refresh/files/tga.c index b74b756a..a2371496 100644 --- a/src/refresh/files/tga.c +++ b/src/refresh/files/tga.c @@ -35,9 +35,10 @@ typedef struct _TargaHeader unsigned char pixel_size, attributes; } TargaHeader; -void -LoadTGA ( char *name, byte **pic, int *width, int *height ) +image_t * +LoadTGA ( char *name, int *width, int *height, imagetype_t type ) { + byte *pic = NULL; int columns, rows, numPixels; byte *pixbuf; int row, column; @@ -48,15 +49,13 @@ LoadTGA ( char *name, byte **pic, int *width, int *height ) byte *targa_rgba; byte tmp [ 2 ]; - *pic = NULL; - /* load the file */ length = ri.FS_LoadFile( name, (void **) &buffer ); if ( !buffer ) { ri.Con_Printf( PRINT_DEVELOPER, "Bad tga file %s\n", name ); - return; + return NULL; } buf_p = buffer; @@ -112,7 +111,7 @@ LoadTGA ( char *name, byte **pic, int *width, int *height ) } targa_rgba = malloc( numPixels * 4 ); - *pic = targa_rgba; + pic = targa_rgba; if ( targa_header.id_length != 0 ) { @@ -271,5 +270,12 @@ LoadTGA ( char *name, byte **pic, int *width, int *height ) } ri.FS_FreeFile( buffer ); + + if ( !pic ) + { + return ( NULL ); + } + + return R_LoadPic( name, pic, *width, *height, type, 32 ); } diff --git a/src/refresh/r_image.c b/src/refresh/r_image.c index e6feea19..ae3d2987 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -52,7 +52,10 @@ int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST; int gl_filter_max = GL_LINEAR; image_t *LoadWal ( char *name ); -void LoadTGA ( char *name, byte **pic, int *width, int *height ); +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 @@ -1066,14 +1069,11 @@ R_FindImage ( char *name, imagetype_t type ) } else if ( !strcmp( name + len - 4, ".tga" ) ) { - LoadTGA( name, &pic, &width, &height ); - - if ( !pic ) - { - return ( NULL ); - } - - image = R_LoadPic( name, pic, width, height, type, 32 ); + return LoadTGA( name, &width, &height, type ); + } + else if ( !strcmp( name + len - 4, ".jpg" ) ) + { + return LoadJPG( name, &width, &height, type ); } else { From 1d8109cbbca40a602e95a8cd65d7c4206233aa7c Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 11 Mar 2012 19:01:49 +0000 Subject: [PATCH 03/15] 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" ) ) { From 9edf27f1031dea033df12ca127125f28e5191c8a Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 08:11:22 +0000 Subject: [PATCH 04/15] Reactor yesterdays work --- Makefile | 14 +---------- src/refresh/files/jpeg.c | 41 ++++++++++++------------------ src/refresh/files/pcx.c | 11 ++++---- src/refresh/files/tga.c | 28 +++++++-------------- src/refresh/files/wal.c | 11 ++++---- src/refresh/header/local.h | 5 +++- src/refresh/r_image.c | 51 +++++++++++++++++++++++++------------- 7 files changed, 76 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 27a4a92e..b4647039 100644 --- a/Makefile +++ b/Makefile @@ -41,13 +41,6 @@ CC := gcc # ---------- -# Options - -# Enables .jpg texture support -JPEG := 1 - -# ---------- - # Base CFLAGS. # # -O2 are enough optimizations. @@ -175,13 +168,8 @@ build/refresher/%.o: %.c ${Q}$(CC) -c $(CFLAGS) $(SDLCFLAGS) $(INCLUDE) -o $@ $< release/ref_gl.so : CFLAGS += -fPIC -release/ref_gl.so : LDFLAGS += -shared +release/ref_gl.so : LDFLAGS += -shared -ljpeg -ifdef JPEG -release/ref_gl.so : CFLAGS += -DWITH_JPEG -release/ref_gl.so : LDFLAGS += -ljpeg -endif - # ---------- # The baseq2 game diff --git a/src/refresh/files/jpeg.c b/src/refresh/files/jpeg.c index a42cd165..126154d1 100644 --- a/src/refresh/files/jpeg.c +++ b/src/refresh/files/jpeg.c @@ -24,8 +24,6 @@ * ======================================================================= */ -#ifdef WITH_JPEG - #include "../header/local.h" #include @@ -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 diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c index d1c0dea5..361b2eba 100644 --- a/src/refresh/files/pcx.c +++ b/src/refresh/files/pcx.c @@ -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; diff --git a/src/refresh/files/tga.c b/src/refresh/files/tga.c index a4f7fdb1..c317aac1 100644 --- a/src/refresh/files/tga.c +++ b/src/refresh/files/tga.c @@ -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 ); } diff --git a/src/refresh/files/wal.c b/src/refresh/files/wal.c index 0ba6def1..57551d66 100644 --- a/src/refresh/files/wal.c +++ b/src/refresh/files/wal.c @@ -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 ); diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index df484f98..5338b32f 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -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 ); diff --git a/src/refresh/r_image.c b/src/refresh/r_image.c index 8985049a..a1797659 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -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 @@ -1026,11 +1021,13 @@ 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 { From 43fcc8eb99fa134eebf690501e64fd31ff932444 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 08:53:22 +0000 Subject: [PATCH 05/15] Scale the replacement textures to the size of the original texture --- src/refresh/files/wal.c | 2 +- src/refresh/header/local.h | 2 +- src/refresh/r_image.c | 26 ++++++++++++++++++++------ src/refresh/r_misc.c | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/refresh/files/wal.c b/src/refresh/files/wal.c index 57551d66..7378b0de 100644 --- a/src/refresh/files/wal.c +++ b/src/refresh/files/wal.c @@ -34,7 +34,7 @@ LoadWal ( char *origname ) height = LittleLong( mt->height ); ofs = LittleLong( mt->offsets [ 0 ] ); - image = R_LoadPic( name, (byte *) mt + ofs, width, height, it_wall, 8 ); + image = R_LoadPic( name, (byte *) mt + ofs, width, 0, height, 0, it_wall, 8 ); ri.FS_FreeFile( (void *) mt ); diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index 5338b32f..d43641e9 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -317,7 +317,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 ); -image_t *R_LoadPic ( char *name, byte *pic, int width, int height, imagetype_t type, int bits ); +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 ); void R_ImageList_f ( void ); diff --git a/src/refresh/r_image.c b/src/refresh/r_image.c index a1797659..6718ddba 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -895,7 +895,7 @@ R_Upload8 ( byte *data, int width, int height, qboolean mipmap, qboolean is_sky * This is also used as an entry point for the generated r_notexture */ image_t * -R_LoadPic ( char *name, byte *pic, int width, int height, imagetype_t type, int bits ) +R_LoadPic ( char *name, byte *pic, int width, int realwidth, int height, int realheight, imagetype_t type, int bits ) { image_t *image; int i; @@ -994,6 +994,20 @@ R_LoadPic ( char *name, byte *pic, int width, int height, imagetype_t type, int image->upload_width = upload_width; /* after power of 2 and scales */ image->upload_height = upload_height; image->paletted = uploaded_paletted; + + if ( realwidth && realheight ) + { + if ( ( realwidth <= image->width ) && ( realheight <= image->height ) ) + { + image->width = realwidth; + image->height = realheight; + } + else + { + ri.Con_Printf( PRINT_DEVELOPER, "Warning, image '%s' has hi-res replacement smaller than the original! (%d x %d) < (%d x %d)\n", name, image->width, image->height, realwidth, realheight ); + } + } + image->sl = 0; image->sh = 1; image->tl = 0; @@ -1062,7 +1076,7 @@ R_FindImage ( char *name, imagetype_t type ) return ( NULL ); } - image = R_LoadPic( name, pic, width, height, type, 8 ); + image = R_LoadPic( name, pic, width, 0, height, 0, type, 8 ); } else if ( !strcmp( name + len - 4, ".wal" ) ) { @@ -1080,7 +1094,7 @@ R_FindImage ( char *name, imagetype_t type ) else { /* Upload TGA */ - image = R_LoadPic( name, pic, width, height, type, 32 ); + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); } if( !pic ) @@ -1091,7 +1105,7 @@ R_FindImage ( char *name, imagetype_t type ) else { /* Upload JPEG */ - image = R_LoadPic( name, pic, width, height, type, 32 ); + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); } if ( !image ) @@ -1103,12 +1117,12 @@ R_FindImage ( char *name, imagetype_t type ) else if ( !strcmp( name + len - 4, ".tga" ) ) { LoadTGA( name, &pic, &width, &height ); - image = R_LoadPic( name, pic, width, height, type, 32 ); + image = R_LoadPic( name, pic, width, realwidth, height, realwidth, type, 32 ); } else if ( !strcmp( name + len - 4, ".jpg" ) ) { LoadJPG( name, &pic, &width, &height ); - image = R_LoadPic( name, pic, width, height, type, 32 ); + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); } else { diff --git a/src/refresh/r_misc.c b/src/refresh/r_misc.c index c13ad1bd..e49a16c0 100644 --- a/src/refresh/r_misc.c +++ b/src/refresh/r_misc.c @@ -64,7 +64,7 @@ R_InitParticleTexture ( void ) } } - r_particletexture = R_LoadPic( "***particle***", (byte *) data, 8, 8, it_sprite, 32 ); + r_particletexture = R_LoadPic( "***particle***", (byte *) data, 8, 0, 8, 0, it_sprite, 32 ); /* also use this for bad textures, but without alpha */ for ( x = 0; x < 8; x++ ) @@ -78,7 +78,7 @@ R_InitParticleTexture ( void ) } } - r_notexture = R_LoadPic( "***r_notexture***", (byte *) data, 8, 8, it_wall, 32 ); + r_notexture = R_LoadPic( "***r_notexture***", (byte *) data, 8, 0, 8, 0, it_wall, 32 ); } void From 7db2d76833e477f55801b878e463c5315124b98c Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:16:59 +0000 Subject: [PATCH 06/15] Import the Quake III Arena TGA loader and replace out implementation with it. The Q3A is about ~40% faster and supports more types of TGA files, including bottom to top encoded images. --- src/refresh/files/tga.c | 355 ++++++++++++++++++++++++++++------------ 1 file changed, 251 insertions(+), 104 deletions(-) diff --git a/src/refresh/files/tga.c b/src/refresh/files/tga.c index c317aac1..16198d5e 100644 --- a/src/refresh/files/tga.c +++ b/src/refresh/files/tga.c @@ -22,9 +22,9 @@ * The Targa image format * * ======================================================================= - */ + */ -#include "../header/local.h" +#include "../header/local.h" typedef struct _TargaHeader { @@ -36,116 +36,138 @@ typedef struct _TargaHeader } TargaHeader; void -LoadTGA ( char *origname, byte **pic, int *width, int *height ) +LoadTGA(char *origname, byte **pic, int *width, int *height) { - int columns, rows, numPixels; - byte *pixbuf; - int row, column; - byte *buf_p; - byte *buffer; - int length; - int len; + unsigned rows, numPixels; + byte *pixbuf; + int row, column, columns; + byte *buf_p; + byte *buffer; TargaHeader targa_header; - byte *targa_rgba; - byte tmp [ 2 ]; + byte *targa_rgba; + int length; + int pixel_size; char name[256]; + int len; /* Add the extension */ - len = strlen( origname ); + len = strlen(origname); - if ( strcmp( origname + len - 4, ".tga" ) ) + if (strcmp(origname + len - 4, ".tga")) { - strncpy( name, origname, 256 ); + strncpy(name, origname, 256); strncat(name, ".tga", 255); } else { - strncpy( name, origname, 256 ); + strncpy(name, origname, 256); } + *pic = NULL; /* load the file */ - length = ri.FS_LoadFile( name, (void **) &buffer ); + length = ri.FS_LoadFile(name, (void **)&buffer); - if ( !buffer ) + if (!buffer) { - ri.Con_Printf( PRINT_DEVELOPER, "Bad tga file %s\n", name ); return; } + if (length < 18) + { + ri.Sys_Error(ERR_DROP, "LoadTGA: %s has an invalid file size", name); + } + buf_p = buffer; - targa_header.id_length = *buf_p++; - targa_header.colormap_type = *buf_p++; - targa_header.image_type = *buf_p++; + targa_header.id_length = buf_p[0]; + targa_header.colormap_type = buf_p[1]; + targa_header.image_type = buf_p[2]; - tmp [ 0 ] = buf_p [ 0 ]; - tmp [ 1 ] = buf_p [ 1 ]; - targa_header.colormap_index = LittleShort( *( (short *) tmp ) ); - buf_p += 2; - tmp [ 0 ] = buf_p [ 0 ]; - tmp [ 1 ] = buf_p [ 1 ]; - targa_header.colormap_length = LittleShort( *( (short *) tmp ) ); - buf_p += 2; - targa_header.colormap_size = *buf_p++; - targa_header.x_origin = LittleShort( *( (short *) buf_p ) ); - buf_p += 2; - targa_header.y_origin = LittleShort( *( (short *) buf_p ) ); - buf_p += 2; - targa_header.width = LittleShort( *( (short *) buf_p ) ); - buf_p += 2; - targa_header.height = LittleShort( *( (short *) buf_p ) ); - buf_p += 2; - targa_header.pixel_size = *buf_p++; - targa_header.attributes = *buf_p++; + memcpy(&targa_header.colormap_index, &buf_p[3], 2); + memcpy(&targa_header.colormap_length, &buf_p[5], 2); + targa_header.colormap_size = buf_p[7]; + memcpy(&targa_header.x_origin, &buf_p[8], 2); + memcpy(&targa_header.y_origin, &buf_p[10], 2); + memcpy(&targa_header.width, &buf_p[12], 2); + memcpy(&targa_header.height, &buf_p[14], 2); + targa_header.pixel_size = buf_p[16]; + targa_header.attributes = buf_p[17]; - if ( ( targa_header.image_type != 2 ) && - ( targa_header.image_type != 10 ) ) + targa_header.colormap_index = LittleShort(targa_header.colormap_index); + targa_header.colormap_length = LittleShort(targa_header.colormap_length); + targa_header.x_origin = LittleShort(targa_header.x_origin); + targa_header.y_origin = LittleShort(targa_header.y_origin); + targa_header.width = LittleShort(targa_header.width); + targa_header.height = LittleShort(targa_header.height); + + buf_p += 18; + + if ((targa_header.image_type != 2) && + (targa_header.image_type != 10) && + (targa_header.image_type != 3)) { - ri.Sys_Error( ERR_DROP, "LoadTGA: Only type 2 and 10 targa RGB images supported\n" ); + ri.Sys_Error( ERR_DROP, "LoadTGA (%s): Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported", name); } - if ( ( targa_header.colormap_type != 0 ) || - ( ( targa_header.pixel_size != 32 ) && ( targa_header.pixel_size != 24 ) ) ) + if (targa_header.colormap_type != 0) { - ri.Sys_Error( ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n" ); + ri.Sys_Error(ERR_DROP, "LoadTGA (%s): colormaps not supported", name); + } + + if (((targa_header.pixel_size != 32) && (targa_header.pixel_size != 24)) && (targa_header.image_type != 3)) + { + ri.Sys_Error( ERR_DROP, "LoadTGA (%s): Only 32 or 24 bit images supported (no colormaps)", name); } columns = targa_header.width; rows = targa_header.height; - numPixels = columns * rows; + numPixels = columns * rows * 4; - if ( width ) + if (width) { *width = columns; } - if ( height ) + if (height) { *height = rows; } - targa_rgba = malloc( numPixels * 4 ); + if (!columns || !rows || (numPixels > 0x7FFFFFFF) || (numPixels / columns / 4 != rows)) + { + ri.Sys_Error(ERR_DROP, "LoadTGA (%s): Invalid image size", name); + } + + targa_rgba = malloc(numPixels); *pic = targa_rgba; - if ( targa_header.id_length != 0 ) + if (targa_header.id_length != 0) { buf_p += targa_header.id_length; /* skip TARGA image comment */ } - if ( targa_header.image_type == 2 ) /* Uncompressed, RGB images */ + pixel_size = targa_header.pixel_size; + + if ((targa_header.image_type == 2) || (targa_header.image_type == 3)) { - for ( row = rows - 1; row >= 0; row-- ) + /* Uncompressed RGB or gray scale image */ + switch (pixel_size) { - pixbuf = targa_rgba + row * columns * 4; + case 24: - for ( column = 0; column < columns; column++ ) - { - unsigned char red, green, blue, alphabyte; - - switch ( targa_header.pixel_size ) + if (buf_p - buffer + (3 * columns * rows) > length) { - case 24: + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + + for (row = rows - 1; row >= 0; row--) + { + pixbuf = targa_rgba + row * columns * 4; + + for (column = 0; column < columns; column++) + { + unsigned char red, green, blue; blue = *buf_p++; green = *buf_p++; @@ -154,8 +176,26 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) *pixbuf++ = green; *pixbuf++ = blue; *pixbuf++ = 255; - break; - case 32: + } + } + + break; + + case 32: + + if (buf_p - buffer + (4 * columns * rows) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + + for (row = rows - 1; row >= 0; row--) + { + pixbuf = targa_rgba + row * columns * 4; + + for (column = 0; column < columns; column++) + { + unsigned char red, green, blue, alphabyte; + blue = *buf_p++; green = *buf_p++; red = *buf_p++; @@ -164,49 +204,93 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) *pixbuf++ = green; *pixbuf++ = blue; *pixbuf++ = alphabyte; - break; + } } - } + + break; + + case 8: + + if (buf_p - buffer + (1 * columns * rows) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + + for (row = rows - 1; row >= 0; row--) + { + pixbuf = targa_rgba + row * columns * 4; + + for (column = 0; column < columns; column++) + { + unsigned char red, green, blue; + + blue = *buf_p++; + green = blue; + red = blue; + *pixbuf++ = red; + *pixbuf++ = green; + *pixbuf++ = blue; + *pixbuf++ = 255; + } + } + + break; } } - else if ( targa_header.image_type == 10 ) /* Runlength encoded RGB images */ + else if (targa_header.image_type == 10) { - unsigned char red, green, blue, alphabyte, packetHeader, packetSize, j; + /* Runlength encoded RGB images */ + byte red, green, blue, alphabyte, packetHeader; + unsigned packetSize, j; - for ( row = rows - 1; row >= 0; row-- ) + red = 0; + green = 0; + blue = 0; + alphabyte = 0xff; + + for (row = rows - 1; row >= 0; row--) { pixbuf = targa_rgba + row * columns * 4; - for ( column = 0; column < columns; ) + for (column = 0; column < columns; ) { packetHeader = *buf_p++; - packetSize = 1 + ( packetHeader & 0x7f ); + packetSize = 1 + (packetHeader & 0x7f); - if ( packetHeader & 0x80 ) /* run-length packet */ + if (packetHeader & 0x80) { - switch ( targa_header.pixel_size ) + /* run-length packet */ + switch (pixel_size) { case 24: + + if (buf_p - buffer + (3) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + blue = *buf_p++; green = *buf_p++; red = *buf_p++; alphabyte = 255; break; case 32: + + if (buf_p - buffer + (4) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + blue = *buf_p++; green = *buf_p++; red = *buf_p++; alphabyte = *buf_p++; break; default: - blue = 0; - green = 0; - red = 0; - alphabyte = 0; break; } - for ( j = 0; j < packetSize; j++ ) + for (j = 0; j < packetSize; j++) { *pixbuf++ = red; *pixbuf++ = green; @@ -214,12 +298,12 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) *pixbuf++ = alphabyte; column++; - /* run spans across rows */ - if ( column == columns ) + if (column == columns) { + /* run spans across rows */ column = 0; - if ( row > 0 ) + if (row > 0) { row--; } @@ -232,13 +316,20 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) } } } - else /* non run-length packet */ + else { - for ( j = 0; j < packetSize; j++ ) + /* non run-length packet */ + switch (pixel_size) { - switch ( targa_header.pixel_size ) - { - case 24: + case 24: + + if (buf_p - buffer + (3 * packetSize) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + + for (j = 0; j < packetSize; j++) + { blue = *buf_p++; green = *buf_p++; red = *buf_p++; @@ -246,8 +337,38 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) *pixbuf++ = green; *pixbuf++ = blue; *pixbuf++ = 255; - break; - case 32: + + column++; + + if (column == columns) + { + /* pixel packet run spans across rows */ + column = 0; + + if (row > 0) + { + row--; + } + else + { + goto breakOut; + } + + pixbuf = targa_rgba + row * columns * 4; + } + } + + break; + + case 32: + + if (buf_p - buffer + (4 * packetSize) > length) + { + ri.Sys_Error( ERR_DROP, "LoadTGA: (%s): Pointer passed end of file - corrupt TGA file", name); + } + + for (j = 0; j < packetSize; j++) + { blue = *buf_p++; green = *buf_p++; red = *buf_p++; @@ -256,26 +377,31 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) *pixbuf++ = green; *pixbuf++ = blue; *pixbuf++ = alphabyte; - break; - } - column++; + column++; - if ( column == columns ) /* pixel packet run spans across rows */ - { - column = 0; + if (column == columns) + { + /* pixel packet run spans across rows */ + column = 0; - if ( row > 0 ) - { - row--; - } - else - { - goto breakOut; + if (row > 0) + { + row--; + } + else + { + goto breakOut; + } + + pixbuf = targa_rgba + row * columns * 4; + } } - pixbuf = targa_rgba + row * columns * 4; - } + break; + + default: + break; } } } @@ -284,6 +410,27 @@ LoadTGA ( char *origname, byte **pic, int *width, int *height ) } } - ri.FS_FreeFile( buffer ); -} + if (targa_header.attributes & 0x20) + { + byte *temp; + temp = malloc(numPixels); + + if (!temp) + { + ri.Sys_Error(ERR_FATAL, "LoadTGA: not enough memory"); + } + + ri.Con_Printf(PRINT_DEVELOPER, "LoadTGA: Bottom-to-top TGA file (slow): %s\n", name); + memcpy(temp, targa_rgba, numPixels); + + for (row = 0; row < rows; row++) + { + memcpy(targa_rgba + (row * columns * 4), temp + (rows - row - 1) * columns * 4, columns * 4); + } + + free(temp); + } + + ri.FS_FreeFile(buffer); +} From 1cc06e284122fb05fe1282c405e66df4291313e6 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:21:19 +0000 Subject: [PATCH 07/15] Reformat the JPEG loader --- src/refresh/files/jpeg.c | 138 +++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 72 deletions(-) diff --git a/src/refresh/files/jpeg.c b/src/refresh/files/jpeg.c index 126154d1..0d4803d5 100644 --- a/src/refresh/files/jpeg.c +++ b/src/refresh/files/jpeg.c @@ -27,63 +27,52 @@ #include "../header/local.h" #include -/* -================================================================= - -JPEG LOADING -NiceAss: Code from Q2Ice - -================================================================= -*/ - -void jpg_null(j_decompress_ptr cinfo) -{ -} - -boolean jpg_fill_input_buffer(j_decompress_ptr cinfo) -{ - ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); - return 1; -} - -void jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) -{ - - cinfo->src->next_input_byte += (size_t) num_bytes; - cinfo->src->bytes_in_buffer -= (size_t) num_bytes; -} - -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; - cinfo->src->fill_input_buffer = jpg_fill_input_buffer; - cinfo->src->skip_input_data = jpg_skip_input_data; - cinfo->src->resync_to_restart = jpeg_resync_to_restart; - cinfo->src->term_source = jpg_null; - cinfo->src->bytes_in_buffer = len; - cinfo->src->next_input_byte = mem; -} - -/* -============== -LoadJPG -============== -*/ void -LoadJPG (char *origname, byte **pic, int *width, int *height) +jpg_null(j_decompress_ptr cinfo) { - 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; +} + +boolean +jpg_fill_input_buffer(j_decompress_ptr cinfo) +{ + ri.Con_Printf(PRINT_ALL, "Premature end of JPEG data\n"); + return 1; +} + +void +jpg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) +{ + cinfo->src->next_input_byte += (size_t)num_bytes; + cinfo->src->bytes_in_buffer -= (size_t)num_bytes; +} + +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; + cinfo->src->fill_input_buffer = jpg_fill_input_buffer; + cinfo->src->skip_input_data = jpg_skip_input_data; + cinfo->src->resync_to_restart = jpeg_resync_to_restart; + cinfo->src->term_source = jpg_null; + cinfo->src->bytes_in_buffer = len; + cinfo->src->next_input_byte = mem; +} + +void +LoadJPG(char *origname, byte **pic, int *width, int *height) +{ + 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; /* Add the extension */ - len = strlen( origname ); + len = strlen(origname); - if ( strcmp( origname + len - 4, ".jpg" ) ) + if (strcmp(origname + len - 4, ".jpg")) { strncpy(filename, origname, 256); strncat(filename, ".jpg", 255); @@ -95,26 +84,28 @@ LoadJPG (char *origname, byte **pic, int *width, int *height) *pic = NULL; - // Load JPEG file into memory + /* Load JPEG file into memory */ rawsize = ri.FS_LoadFile(filename, (void **)&rawdata); if (!rawdata) - 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); + 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; } cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); - jpeg_mem_src(&cinfo, (unsigned char *) rawdata, (unsigned long) rawsize); + jpeg_mem_src(&cinfo, (unsigned char *)rawdata, (unsigned long)rawsize); jpeg_read_header(&cinfo, true); jpeg_start_decompress(&cinfo); - if(cinfo.output_components != 3 && cinfo.output_components != 4) + if ((cinfo.output_components != 3) && (cinfo.output_components != 4)) { ri.Con_Printf(PRINT_ALL, "Invalid JPEG colour components\n"); jpeg_destroy_decompress(&cinfo); @@ -122,9 +113,10 @@ LoadJPG (char *origname, byte **pic, int *width, int *height) return; } - // Allocate Memory for decompressed image + /* Allocate Memory for decompressed image */ rgbadata = malloc(cinfo.output_width * cinfo.output_height * 4); - if(!rgbadata) + + if (!rgbadata) { ri.Con_Printf(PRINT_ALL, "Insufficient memory for JPEG buffer\n"); jpeg_destroy_decompress(&cinfo); @@ -132,23 +124,25 @@ LoadJPG (char *origname, byte **pic, int *width, int *height) return; } - // Pass sizes to output + /* Pass sizes to output */ *width = cinfo.output_width; *height = cinfo.output_height; - // Allocate Scanline buffer - scanline = malloc (cinfo.output_width * 3); + /* Allocate Scanline buffer */ + scanline = malloc(cinfo.output_width * 3); + if (!scanline) { - ri.Con_Printf (PRINT_ALL, "Insufficient memory for JPEG scanline buffer\n"); - free (rgbadata); - jpeg_destroy_decompress (&cinfo); - ri.FS_FreeFile (rawdata); + ri.Con_Printf(PRINT_ALL, "Insufficient memory for JPEG scanline buffer\n"); + free(rgbadata); + jpeg_destroy_decompress(&cinfo); + ri.FS_FreeFile(rawdata); return; } - // Read Scanlines, and expand from RGB to RGBA + /* Read Scanlines, and expand from RGB to RGBA */ q = rgbadata; + while (cinfo.output_scanline < cinfo.output_height) { p = scanline; @@ -165,9 +159,9 @@ LoadJPG (char *origname, byte **pic, int *width, int *height) } } - free (scanline); - jpeg_finish_decompress (&cinfo); - jpeg_destroy_decompress (&cinfo); + free(scanline); + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); *pic = rgbadata; } From 48a0d6a50d26ab4035b045fd4b576aeca42b1669 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:23:44 +0000 Subject: [PATCH 08/15] - Reformat wal.c - Add a file header to wal.c --- src/refresh/files/wal.c | 69 ++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/src/refresh/files/wal.c b/src/refresh/files/wal.c index 7378b0de..77de5a90 100644 --- a/src/refresh/files/wal.c +++ b/src/refresh/files/wal.c @@ -1,18 +1,44 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * The Wal image format + * + * ======================================================================= + */ + #include "../header/local.h" image_t * -LoadWal ( char *origname ) +LoadWal(char *origname) { - miptex_t *mt; + miptex_t *mt; int width, height, ofs; - image_t *image; + image_t *image; int len; char name[256]; /* Add the extension */ - len = strlen( origname ); + len = strlen(origname); - if ( strcmp( origname + len - 4, ".wal" ) ) + if (strcmp(origname + len - 4, ".wal")) { strncpy(name, origname, 256); strncat(name, ".wal", 255); @@ -22,40 +48,41 @@ LoadWal ( char *origname ) strncpy(name, origname, 256); } - ri.FS_LoadFile( name, (void **) &mt ); + ri.FS_LoadFile(name, (void **)&mt); - if ( !mt ) + if (!mt) { - ri.Con_Printf( PRINT_ALL, "LoadWall: can't load %s\n", name ); - return ( r_notexture ); + ri.Con_Printf(PRINT_ALL, "LoadWall: can't load %s\n", name); + return r_notexture; } - width = LittleLong( mt->width ); - height = LittleLong( mt->height ); - ofs = LittleLong( mt->offsets [ 0 ] ); + width = LittleLong(mt->width); + height = LittleLong(mt->height); + ofs = LittleLong(mt->offsets[0]); - image = R_LoadPic( name, (byte *) mt + ofs, width, 0, height, 0, it_wall, 8 ); + image = R_LoadPic(name, (byte *)mt + ofs, width, 0, height, 0, it_wall, 8); - ri.FS_FreeFile( (void *) mt ); + ri.FS_FreeFile((void *)mt); - return ( image ); + return image; } -qboolean GetWalInfo (char *name, int *width, int *height) +qboolean +GetWalInfo(char *name, int *width, int *height) { - miptex_t *mt; + miptex_t *mt; - ri.FS_LoadFile (name, (void **)&mt); + ri.FS_LoadFile(name, (void **)&mt); if (!mt) { return false; } - *width = LittleLong (mt->width); - *height = LittleLong (mt->height); + *width = LittleLong(mt->width); + *height = LittleLong(mt->height); - ri.FS_FreeFile ((void *)mt); + ri.FS_FreeFile((void *)mt); return true; } From d0133509e12d455d5c611de508b4f5751e7384e2 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:31:33 +0000 Subject: [PATCH 09/15] Provide the gl_retexturing CVAR to switch retexturing off. Default is "1", retexturing enabled. --- src/refresh/header/local.h | 2 ++ src/refresh/r_image.c | 67 +++++++++++++++++++++++--------------- src/refresh/r_main.c | 4 +++ 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index d43641e9..1ba6d8f8 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -200,6 +200,8 @@ extern cvar_t *gl_mode; extern cvar_t *gl_customwidth; extern cvar_t *gl_customheight; +extern cvar_t *gl_retexturing; + extern cvar_t *gl_log; extern cvar_t *gl_lightmap; extern cvar_t *gl_shadows; diff --git a/src/refresh/r_image.c b/src/refresh/r_image.c index 6718ddba..d145650f 100644 --- a/src/refresh/r_image.c +++ b/src/refresh/r_image.c @@ -1080,38 +1080,51 @@ R_FindImage ( char *name, imagetype_t type ) } else if ( !strcmp( name + len - 4, ".wal" ) ) { - /* Get size of the original texture */ - GetWalInfo(name, &realwidth, &realheight); - - /* Try to load a TGA */ - LoadTGA( namewe, &pic, &width, &height ); - - if( !pic ) + if (gl_retexturing->value) { - /* JPEG if no TGA available */ - LoadJPG( namewe, &pic, &width, &height ); + /* Get size of the original texture */ + GetWalInfo(name, &realwidth, &realheight); + + /* 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 ) + { + /* WAL of no JPEG available (exists always) */ + image = LoadWal( namewe ); + } + else + { + /* Upload JPEG */ + image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); + } + + if ( !image ) + { + /* No texture found */ + return ( NULL ); + } } else { - /* Upload TGA */ - image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); - } + image = LoadWal( name ); - if( !pic ) - { - /* WAL of no JPEG available (exists always) */ - image = LoadWal( namewe ); - } - else - { - /* Upload JPEG */ - image = R_LoadPic( name, pic, width, realwidth, height, realheight, type, 32 ); - } - - if ( !image ) - { - /* No texture found */ - return ( NULL ); + if ( !image ) + { + /* No texture found */ + return ( NULL ); + } } } else if ( !strcmp( name + len - 4, ".tga" ) ) diff --git a/src/refresh/r_main.c b/src/refresh/r_main.c index ff0995fa..c6105b22 100644 --- a/src/refresh/r_main.c +++ b/src/refresh/r_main.c @@ -134,6 +134,8 @@ cvar_t *gl_mode; cvar_t *gl_customwidth; cvar_t *gl_customheight; +cvar_t *gl_retexturing; + cvar_t *gl_dynamic; cvar_t *gl_modulate; cvar_t *gl_nobind; @@ -1010,6 +1012,8 @@ R_Register ( void ) gl_customwidth = ri.Cvar_Get( "gl_customwidth", "1024", CVAR_ARCHIVE ); gl_customheight = ri.Cvar_Get( "gl_customheight", "768", CVAR_ARCHIVE ); + gl_retexturing = ri.Cvar_Get( "gl_retexturing", "1", CVAR_ARCHIVE ); + ri.Cmd_AddCommand( "imagelist", R_ImageList_f ); ri.Cmd_AddCommand( "screenshot", R_ScreenShot ); ri.Cmd_AddCommand( "modellist", Mod_Modellist_f ); From 57b06a8bcfba64c102f3118affceb1b33bbf210d Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:54:04 +0000 Subject: [PATCH 10/15] Implement retexturing for PCX files --- src/refresh/files/pcx.c | 21 +++++++++++++++ src/refresh/header/local.h | 1 + src/refresh/r_image.c | 53 +++++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 6 deletions(-) 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" ) ) { From 643cb93e5f3abdc9b91936b46932d9e850a539e6 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 09:56:27 +0000 Subject: [PATCH 11/15] Reformat pcx.c --- src/refresh/files/pcx.c | 92 ++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c index 7ea327e7..5998e886 100644 --- a/src/refresh/files/pcx.c +++ b/src/refresh/files/pcx.c @@ -22,26 +22,26 @@ * The PCX file format * * ======================================================================= - */ + */ #include "../header/local.h" void -LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height ) +LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height) { - byte *raw; - pcx_t *pcx; + byte *raw; + pcx_t *pcx; int x, y; int len; int filelen; int dataByte, runLength; - byte *out, *pix; + byte *out, *pix; char filename[256]; /* Add the extension */ - filelen = strlen( origname ); + filelen = strlen(origname); - if ( strcmp( origname + filelen - 4, ".pcx" ) ) + if (strcmp(origname + filelen - 4, ".pcx")) { strncpy(filename, origname, 256); strncat(filename, ".pcx", 255); @@ -55,68 +55,63 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height ) *palette = NULL; /* load the file */ - len = ri.FS_LoadFile( filename, (void **) &raw ); + len = ri.FS_LoadFile(filename, (void **)&raw); - if ( !raw ) + if (!raw) { - ri.Con_Printf( PRINT_DEVELOPER, "Bad pcx file %s\n", filename ); + ri.Con_Printf(PRINT_DEVELOPER, "Bad pcx file %s\n", filename); return; } /* parse the PCX file */ - pcx = (pcx_t *) raw; + pcx = (pcx_t *)raw; - pcx->xmin = LittleShort( pcx->xmin ); - pcx->ymin = LittleShort( pcx->ymin ); - pcx->xmax = LittleShort( pcx->xmax ); - pcx->ymax = LittleShort( pcx->ymax ); - 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 ); + pcx->xmin = LittleShort(pcx->xmin); + pcx->ymin = LittleShort(pcx->ymin); + pcx->xmax = LittleShort(pcx->xmax); + pcx->ymax = LittleShort(pcx->ymax); + 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); raw = &pcx->data; - if ( ( pcx->manufacturer != 0x0a ) || - ( pcx->version != 5 ) || - ( pcx->encoding != 1 ) || - ( pcx->bits_per_pixel != 8 ) || - ( pcx->xmax >= 640 ) || - ( pcx->ymax >= 480 ) ) + if ((pcx->manufacturer != 0x0a) || (pcx->version != 5) || (pcx->encoding != 1) || (pcx->bits_per_pixel != 8) || (pcx->xmax >= 640) || (pcx->ymax >= 480)) { - ri.Con_Printf( PRINT_ALL, "Bad pcx file %s\n", filename ); + ri.Con_Printf(PRINT_ALL, "Bad pcx file %s\n", filename); return; } - out = malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) ); + out = malloc((pcx->ymax + 1) * (pcx->xmax + 1)); *pic = out; pix = out; - if ( palette ) + if (palette) { - *palette = malloc( 768 ); - memcpy( *palette, (byte *) pcx + len - 768, 768 ); + *palette = malloc(768); + memcpy(*palette, (byte *)pcx + len - 768, 768); } - if ( width ) + if (width) { *width = pcx->xmax + 1; } - if ( height ) + if (height) { *height = pcx->ymax + 1; } - for ( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 ) + for (y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1) { - for ( x = 0; x <= pcx->xmax; ) + for (x = 0; x <= pcx->xmax; ) { dataByte = *raw++; - if ( ( dataByte & 0xC0 ) == 0xC0 ) + if ((dataByte & 0xC0) == 0xC0) { runLength = dataByte & 0x3F; dataByte = *raw++; @@ -126,39 +121,42 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height ) runLength = 1; } - while ( runLength-- > 0 ) + while (runLength-- > 0) { - pix [ x++ ] = dataByte; + pix[x++] = dataByte; } } } - if ( raw - (byte *) pcx > len ) + if (raw - (byte *)pcx > len) { - ri.Con_Printf( PRINT_DEVELOPER, "PCX file %s was malformed", filename ); - free( *pic ); + ri.Con_Printf(PRINT_DEVELOPER, "PCX file %s was malformed", filename); + free(*pic); *pic = NULL; } - ri.FS_FreeFile( pcx ); -} + ri.FS_FreeFile(pcx); +} qboolean -GetPCXInfo (char *filename, int *width, int *height) +GetPCXInfo(char *filename, int *width, int *height) { - pcx_t *pcx; - byte *raw; + pcx_t *pcx; + byte *raw; + + ri.FS_LoadFile(filename, (void **)&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); + ri.FS_FreeFile(raw); return true; } From bb9126ae431068830e9bfb5030da6ecba77c9592 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 10:00:07 +0000 Subject: [PATCH 12/15] Convert GetPCXInfo and GetWalInfo into void functions --- src/refresh/files/pcx.c | 6 +++--- src/refresh/files/wal.c | 7 ++++--- src/refresh/header/local.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c index 5998e886..f8df92af 100644 --- a/src/refresh/files/pcx.c +++ b/src/refresh/files/pcx.c @@ -138,7 +138,7 @@ LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height) ri.FS_FreeFile(pcx); } -qboolean +void GetPCXInfo(char *filename, int *width, int *height) { pcx_t *pcx; @@ -148,7 +148,7 @@ GetPCXInfo(char *filename, int *width, int *height) if (!raw) { - return false; + return; } pcx = (pcx_t *)raw; @@ -158,6 +158,6 @@ GetPCXInfo(char *filename, int *width, int *height) ri.FS_FreeFile(raw); - return true; + return; } diff --git a/src/refresh/files/wal.c b/src/refresh/files/wal.c index 77de5a90..657acec8 100644 --- a/src/refresh/files/wal.c +++ b/src/refresh/files/wal.c @@ -67,7 +67,7 @@ LoadWal(char *origname) return image; } -qboolean +void GetWalInfo(char *name, int *width, int *height) { miptex_t *mt; @@ -76,13 +76,14 @@ GetWalInfo(char *name, int *width, int *height) if (!mt) { - return false; + return; } *width = LittleLong(mt->width); *height = LittleLong(mt->height); ri.FS_FreeFile((void *)mt); - return true; + + return; } diff --git a/src/refresh/header/local.h b/src/refresh/header/local.h index 472a8aef..e29fedcb 100644 --- a/src/refresh/header/local.h +++ b/src/refresh/header/local.h @@ -318,8 +318,8 @@ void LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *heig 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 ); +void GetWalInfo ( char *name, int *width, int *height ); +void 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 ); From 9339d89bdf2500aa5ef465d52bebdc747c727554 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 10:15:22 +0000 Subject: [PATCH 13/15] Provide backward compatiblity with libjpeg v6 --- src/refresh/files/jpeg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/refresh/files/jpeg.c b/src/refresh/files/jpeg.c index 0d4803d5..fe66b176 100644 --- a/src/refresh/files/jpeg.c +++ b/src/refresh/files/jpeg.c @@ -26,6 +26,9 @@ #include "../header/local.h" #include +#include + +void jpeg_memory_src(j_decompress_ptr cinfo, unsigned char *inbuffer, unsigned long insize); void jpg_null(j_decompress_ptr cinfo) From b53e53fb32a2ffe5a500d713ceeca93dfa7c44d3 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 10:25:23 +0000 Subject: [PATCH 14/15] Document the retexturing pack --- README | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README b/README index 9ea037bd..adf9c050 100644 --- a/README +++ b/README @@ -279,6 +279,18 @@ the most common questions are answered. by your video card and set the desired value "gl_anisotropic". The value must be a power of 4, in most cases 2, 4, 8 or 16. +- Yamagi Quake II has support for the high resolution retexturing pack, + created by the community. Installation is easy: + 1. Download q2_textures.zip and models.zip from + http://www-personal.umich.edu/~jimw/q2/ + 2. Extract both files into the baseq2/ directory of your Quake II + installation, so that the new directories baseq2/textures/ and + baseq2/models/ are created. + The retexturing pack is used by default if it's installed. It can + be switched of at any time by setting "gl_retexturing" to "1" and + execute "vid_restart" after it. + + 3.2 Input --------- Quake II had a rather simple input system, even back then in 1997. It From d46cfa56f7d994f48612a58f6197949494790672 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 12 Mar 2012 10:26:55 +0000 Subject: [PATCH 15/15] Add the retexturing pack to the changelog --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b9db8936..71ec9c6c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,11 @@ -Quake II 4.03 to 4.04 +Quake II 4.03 to 4.10 - Change the behavior of hotkey menus to fix some strange bugs and memory leaks in the menu system. - Add the "gl_farsee" cvar. When set to "1" Quake II renders maps up to 4096x4096 units instead of being limited to 2300x2300. The default is "0". (by Richard Allen) +- Add support for the high resolution retexturing pack. Quake II 4.02 to 4.03 - Fix wrong function call in the Quake II file system.