diff -up /dev/null quake3-1.34-rc4/code/renderer/jpeg_memsrc.c --- /dev/null 2007-09-24 08:32:51.587004947 +0200 +++ quake3-1.34-rc4/code/renderer/jpeg_memsrc.c 2007-09-26 14:11:49.000000000 +0200 @@ -0,0 +1,163 @@ +/* +* memsrc.c +* +* Copyright (C) 1994-1996, Thomas G. Lane. +* This file is part of the Independent JPEG Group's software. +* For conditions of distribution and use, see the accompanying README file. +* +* This file contains decompression data source routines for the case of +* reading JPEG data from a memory buffer that is preloaded with the entire +* JPEG file. This would not seem especially useful at first sight, but +* a number of people have asked for it. +* This is really just a stripped-down version of jdatasrc.c. Comparison +* of this code with jdatasrc.c may be helpful in seeing how to make +* custom source managers for other purposes. +*/ + +/* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#include +#include +#include + + +/* Expanded data source object for memory input */ + +typedef struct { +struct jpeg_source_mgr pub; /* public fields */ + +JOCTET eoi_buffer[2]; /* a place to put a dummy EOI */ +} my_source_mgr; + +typedef my_source_mgr * my_src_ptr; + + +/* +* Initialize source --- called by jpeg_read_header +* before any data is actually read. +*/ + +METHODDEF(void) +init_source (j_decompress_ptr cinfo) +{ +/* No work, since jpeg_memory_src set up the buffer pointer and count. +* Indeed, if we want to read multiple JPEG images from one buffer, +* this *must* not do anything to the pointer. +*/ +} + + +/* +* Fill the input buffer --- called whenever buffer is emptied. +* +* In this application, this routine should never be called; if it is called, +* the decompressor has overrun the end of the input buffer, implying we +* supplied an incomplete or corrupt JPEG datastream. A simple error exit +* might be the most appropriate response. +* +* But what we choose to do in this code is to supply dummy EOI markers +* in order to force the decompressor to finish processing and supply +* some sort of output image, no matter how corrupted. +*/ + +METHODDEF(boolean) +fill_input_buffer (j_decompress_ptr cinfo) +{ +my_src_ptr src = (my_src_ptr) cinfo->src; + +WARNMS(cinfo, JWRN_JPEG_EOF); + +/* Create a fake EOI marker */ +src->eoi_buffer[0] = (JOCTET) 0xFF; +src->eoi_buffer[1] = (JOCTET) JPEG_EOI; +src->pub.next_input_byte = src->eoi_buffer; +src->pub.bytes_in_buffer = 2; + +return TRUE; +} + + +/* +* Skip data --- used to skip over a potentially large amount of +* uninteresting data (such as an APPn marker). +* +* If we overrun the end of the buffer, we let fill_input_buffer deal with +* it. An extremely large skip could cause some time-wasting here, but +* it really isn't supposed to happen ... and the decompressor will never +* skip more than 64K anyway. +*/ + +METHODDEF(void) +skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ +my_src_ptr src = (my_src_ptr) cinfo->src; + +if (num_bytes > 0) { +while (num_bytes > (long) src->pub.bytes_in_buffer) { +num_bytes -= (long) src->pub.bytes_in_buffer; +(void) fill_input_buffer(cinfo); +/* note we assume that fill_input_buffer will never return FALSE, +* so suspension need not be handled. +*/ +} +src->pub.next_input_byte += (size_t) num_bytes; +src->pub.bytes_in_buffer -= (size_t) num_bytes; +} +} + + +/* +* An additional method that can be provided by data source modules is the +* resync_to_restart method for error recovery in the presence of RST markers. +* For the moment, this source module just uses the default resync method +* provided by the JPEG library. That method assumes that no backtracking +* is possible. +*/ + + +/* +* Terminate source --- called by jpeg_finish_decompress +* after all data has been read. Often a no-op. +* +* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding +* application must deal with any cleanup that should happen even +* for error exit. +*/ + +METHODDEF(void) +term_source (j_decompress_ptr cinfo) +{ +/* no work necessary here */ +} + + +/* +* Prepare for input from a memory buffer. +*/ + +GLOBAL(void) +jpeg_memory_src (j_decompress_ptr cinfo, const JOCTET * buffer, size_t bufsize) +{ +my_src_ptr src; + +/* The source object is made permanent so that a series of JPEG images +* can be read from a single buffer by calling jpeg_memory_src +* only before the first one. +* This makes it unsafe to use this manager and a different source +* manager serially with the same JPEG object. Caveat programmer. +*/ +if (cinfo->src == NULL) { /* first time for this JPEG object? */ +cinfo->src = (struct jpeg_source_mgr *) +(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, +sizeof(my_source_mgr)); +} + +src = (my_src_ptr) cinfo->src; +src->pub.init_source = init_source; +src->pub.fill_input_buffer = fill_input_buffer; +src->pub.skip_input_data = skip_input_data; +src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ +src->pub.term_source = term_source; + +src->pub.next_input_byte = buffer; +src->pub.bytes_in_buffer = bufsize; +} diff -up quake3-1.34-rc4/code/renderer/tr_image.c.syslibs quake3-1.34-rc4/code/renderer/tr_image.c --- quake3-1.34-rc4/code/renderer/tr_image.c.syslibs 2007-09-25 19:37:48.000000000 +0200 +++ quake3-1.34-rc4/code/renderer/tr_image.c 2007-09-26 14:11:49.000000000 +0200 @@ -30,9 +30,13 @@ Foundation, Inc., 51 Franklin St, Fifth * You may also wish to include "jerror.h". */ +#ifdef USE_SYSTEM_JPEG +#include +#include "jpeg_memsrc.h" +#else #define JPEG_INTERNALS #include "../jpeg-6/jpeglib.h" - +#endif static void LoadBMP( const char *name, byte **pic, int *width, int *height ); static void LoadTGA( const char *name, byte **pic, int *width, int *height ); @@ -1405,6 +1409,11 @@ static void LoadJPG( const char *filenam unsigned char *out; byte *fbuffer; byte *buf; + size_t bufsize; +#ifdef USE_SYSTEM_JPEG + int i,j; + byte *inptr, *outptr; +#endif /* In this example we want to open the input file before doing anything else, * so that the setjmp() error recovery below can assume the file is open. @@ -1412,7 +1421,7 @@ static void LoadJPG( const char *filenam * requires it in order to read binary files. */ - ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); + bufsize = ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); if (!fbuffer) { return; } @@ -1430,8 +1439,11 @@ static void LoadJPG( const char *filenam jpeg_create_decompress(&cinfo); /* Step 2: specify data source (eg, a file) */ - +#ifdef USE_SYSTEM_JPEG + jpeg_memory_src(&cinfo, fbuffer, bufsize); +#else /* ???????? */ jpeg_stdio_src(&cinfo, fbuffer); +#endif /* Step 3: read file parameters with jpeg_read_header() */ @@ -1474,7 +1486,7 @@ static void LoadJPG( const char *filenam } memcount = pixelcount * 4; - row_stride = cinfo.output_width * cinfo.output_components; + row_stride = cinfo.output_width * 4; out = ri.Malloc(memcount); @@ -1495,6 +1507,21 @@ static void LoadJPG( const char *filenam buf = ((out+(row_stride*cinfo.output_scanline))); buffer = &buf; (void) jpeg_read_scanlines(&cinfo, buffer, 1); +#ifdef USE_SYSTEM_JPEG + /* we have RGB data, we need to expand this out to ARGB */ + inptr = buf + cinfo.output_width * 3 - 1; + outptr = buf + row_stride - 1; + + for (i = 0; i < cinfo.output_width; i++) { + /* endian dependent? maybe for big endian this must be done after the + color/pixel copy? */ + *outptr-- = 255; + for (j = 0; j < 3; j++) { + JOCTET color = *inptr--; + *outptr-- = color; + } + } +#endif } buf = out; @@ -1614,6 +1641,8 @@ boolean empty_output_buffer (j_compress_ } +#ifndef USE_SYSTEM_JPEG + /* * Compression initialization. * Before calling this, all parameters and a data destination must be set up. @@ -1705,6 +1734,8 @@ jpeg_write_scanlines (j_compress_ptr cin return row_ctr; } +#endif + /* * Terminate destination --- called by jpeg_finish_compress * after all data has been written. Usually needs to flush buffer. diff -up /dev/null quake3-1.34-rc4/code/renderer/jpeg_memsrc.h --- /dev/null 2007-09-24 08:32:51.587004947 +0200 +++ quake3-1.34-rc4/code/renderer/jpeg_memsrc.h 2007-09-26 14:11:49.000000000 +0200 @@ -0,0 +1,5 @@ +#include +#include + +void jpeg_memory_src (j_decompress_ptr cinfo, const JOCTET * buffer, + size_t bufsize); diff -up quake3-1.34-rc4/code/jpeg-6/jmemnobs.c.syslibs quake3-1.34-rc4/code/jpeg-6/jmemnobs.c --- quake3-1.34-rc4/code/jpeg-6/jmemnobs.c.syslibs 2007-09-26 16:17:27.000000000 +0200 +++ quake3-1.34-rc4/code/jpeg-6/jmemnobs.c 2007-09-26 16:26:01.000000000 +0200 @@ -15,10 +15,23 @@ * Note that the max_memory_to_use option is ignored by this implementation. */ +#ifdef USE_SYSTEM_JPEG +#include +#include +#include + +#undef GLOBAL +#define GLOBAL +#define FAR + +typedef void * backing_store_ptr; + +#else #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" #include "jmemsys.h" /* import the system-dependent declarations */ +#endif #include "../renderer/tr_local.h" @@ -83,7 +96,13 @@ GLOBAL void jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { +#ifdef USE_SYSTEM_JPEG + fprintf(stderr, + "jmemnobs.c: jpeg_open_backing_store() call, this should never happen!\n"); + exit(1); +#else ERREXIT(cinfo, JERR_NO_BACKING_STORE); +#endif } diff -up quake3-1.34-rc4/Makefile.syslibs quake3-1.34-rc4/Makefile --- quake3-1.34-rc4/Makefile.syslibs 2007-09-25 19:37:57.000000000 +0200 +++ quake3-1.34-rc4/Makefile 2007-09-26 16:15:46.000000000 +0200 @@ -96,6 +96,10 @@ ifndef USE_OPENAL USE_OPENAL=1 endif +ifndef USE_SYSTEM_JPEG +USE_SYSTEM_JPEG=1 +endif + ifndef USE_OPENAL_DLOPEN USE_OPENAL_DLOPEN=0 endif @@ -180,7 +184,7 @@ ifeq ($(PLATFORM),linux) endif endif - BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes -pipe + BASE_CFLAGS = ifeq ($(USE_OPENAL),1) BASE_CFLAGS += -DUSE_OPENAL=1 @@ -200,6 +204,10 @@ ifeq ($(PLATFORM),linux) BASE_CFLAGS += -DUSE_CODEC_VORBIS=1 endif + ifeq ($(USE_SYSTEM_JPEG),1) + BASE_CFLAGS += -DUSE_SYSTEM_JPEG=1 + endif + ifeq ($(USE_SDL),1) BASE_CFLAGS += -DUSE_SDL_VIDEO=1 -DUSE_SDL_SOUND=1 $(shell sdl-config --cflags) else @@ -265,6 +273,10 @@ ifeq ($(PLATFORM),linux) CLIENT_LDFLAGS += -lvorbisfile -lvorbis -logg endif + ifeq ($(USE_SYSTEM_JPEG),1) + CLIENT_LDFLAGS += -ljpeg + endif + ifeq ($(ARCH),i386) # linux32 make ... BASE_CFLAGS += -m32 @@ -970,40 +982,7 @@ Q3OBJ = \ $(B)/client/l_script.o \ $(B)/client/l_struct.o \ \ - $(B)/client/jcapimin.o \ - $(B)/client/jchuff.o \ - $(B)/client/jcinit.o \ - $(B)/client/jccoefct.o \ - $(B)/client/jccolor.o \ - $(B)/client/jfdctflt.o \ - $(B)/client/jcdctmgr.o \ - $(B)/client/jcphuff.o \ - $(B)/client/jcmainct.o \ - $(B)/client/jcmarker.o \ - $(B)/client/jcmaster.o \ - $(B)/client/jcomapi.o \ - $(B)/client/jcparam.o \ - $(B)/client/jcprepct.o \ - $(B)/client/jcsample.o \ - $(B)/client/jdapimin.o \ - $(B)/client/jdapistd.o \ - $(B)/client/jdatasrc.o \ - $(B)/client/jdcoefct.o \ - $(B)/client/jdcolor.o \ - $(B)/client/jddctmgr.o \ - $(B)/client/jdhuff.o \ - $(B)/client/jdinput.o \ - $(B)/client/jdmainct.o \ - $(B)/client/jdmarker.o \ - $(B)/client/jdmaster.o \ - $(B)/client/jdpostct.o \ - $(B)/client/jdsample.o \ - $(B)/client/jdtrans.o \ - $(B)/client/jerror.o \ - $(B)/client/jidctflt.o \ - $(B)/client/jmemmgr.o \ $(B)/client/jmemnobs.o \ - $(B)/client/jutils.o \ \ $(B)/client/tr_animation.o \ $(B)/client/tr_backend.o \ @@ -1027,7 +1006,46 @@ Q3OBJ = \ $(B)/client/tr_shadows.o \ $(B)/client/tr_sky.o \ $(B)/client/tr_surface.o \ - $(B)/client/tr_world.o \ + $(B)/client/tr_world.o + +ifneq ($(USE_SYSTEM_JPEG),1) + Q3OBJ += \ + $(B)/client/jcapimin.o \ + $(B)/client/jchuff.o \ + $(B)/client/jcinit.o \ + $(B)/client/jccoefct.o \ + $(B)/client/jccolor.o \ + $(B)/client/jfdctflt.o \ + $(B)/client/jcdctmgr.o \ + $(B)/client/jcphuff.o \ + $(B)/client/jcmainct.o \ + $(B)/client/jcmarker.o \ + $(B)/client/jcmaster.o \ + $(B)/client/jcomapi.o \ + $(B)/client/jcparam.o \ + $(B)/client/jcprepct.o \ + $(B)/client/jcsample.o \ + $(B)/client/jdapimin.o \ + $(B)/client/jdapistd.o \ + $(B)/client/jdatasrc.o \ + $(B)/client/jdcoefct.o \ + $(B)/client/jdcolor.o \ + $(B)/client/jddctmgr.o \ + $(B)/client/jdhuff.o \ + $(B)/client/jdinput.o \ + $(B)/client/jdmainct.o \ + $(B)/client/jdmarker.o \ + $(B)/client/jdmaster.o \ + $(B)/client/jdpostct.o \ + $(B)/client/jdsample.o \ + $(B)/client/jdtrans.o \ + $(B)/client/jerror.o \ + $(B)/client/jidctflt.o \ + $(B)/client/jmemmgr.o \ + $(B)/client/jutils.o +else +Q3OBJ += $(B)/client/jpeg_memsrc.o +endif ifeq ($(ARCH),i386) Q3OBJ += \