Index: code/unix/Makefile =================================================================== --- code/unix/Makefile (revision 146) +++ code/unix/Makefile (working copy) @@ -71,7 +71,6 @@ UIDIR=$(MOUNT_DIR)/ui Q3UIDIR=$(MOUNT_DIR)/q3_ui #FTDIR=$(MOUNT_DIR)/ft2 -JPDIR=$(MOUNT_DIR)/jpeg-6 SPLNDIR=$(MOUNT_DIR)/splines # extract version info @@ -160,7 +159,7 @@ SHLIBLDFLAGS=-shared $(LDFLAGS) THREAD_LDFLAGS=-lpthread - LDFLAGS=-ldl -lm + LDFLAGS=-ldl -lm -ljpeg DEBUG_CFLAGS += -DHAVE_EXECINFO_H ifeq ($(BUILD_FREETYPE),1) @@ -551,41 +550,6 @@ $(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 \ $(B)/client/tr_bsp.o \ @@ -806,42 +770,6 @@ $(B)/client/l_script.o : $(BLIBDIR)/l_script.c; $(DO_BOT_CC) $(B)/client/l_struct.o : $(BLIBDIR)/l_struct.c; $(DO_BOT_CC) -$(B)/client/jcapimin.o : $(JPDIR)/jcapimin.c; $(DO_CC) -$(B)/client/jchuff.o : $(JPDIR)/jchuff.c; $(DO_CC) -$(B)/client/jcinit.o : $(JPDIR)/jcinit.c; $(DO_CC) -$(B)/client/jccoefct.o : $(JPDIR)/jccoefct.c; $(DO_CC) -$(B)/client/jccolor.o : $(JPDIR)/jccolor.c; $(DO_CC) -$(B)/client/jfdctflt.o : $(JPDIR)/jfdctflt.c; $(DO_CC) -$(B)/client/jcdctmgr.o : $(JPDIR)/jcdctmgr.c; $(DO_CC) -$(B)/client/jcmainct.o : $(JPDIR)/jcmainct.c; $(DO_CC) -$(B)/client/jcmarker.o : $(JPDIR)/jcmarker.c; $(DO_CC) -$(B)/client/jcmaster.o : $(JPDIR)/jcmaster.c; $(DO_CC) -$(B)/client/jcomapi.o : $(JPDIR)/jcomapi.c; $(DO_CC) -$(B)/client/jcparam.o : $(JPDIR)/jcparam.c; $(DO_CC) -$(B)/client/jcprepct.o : $(JPDIR)/jcprepct.c; $(DO_CC) -$(B)/client/jcsample.o : $(JPDIR)/jcsample.c; $(DO_CC) - -$(B)/client/jdapimin.o : $(JPDIR)/jdapimin.c; $(DO_CC) -$(B)/client/jdapistd.o : $(JPDIR)/jdapistd.c; $(DO_CC) -$(B)/client/jdatasrc.o : $(JPDIR)/jdatasrc.c; $(DO_CC) -$(B)/client/jdcoefct.o : $(JPDIR)/jdcoefct.c; $(DO_CC) -$(B)/client/jdcolor.o : $(JPDIR)/jdcolor.c; $(DO_CC) -$(B)/client/jcphuff.o : $(JPDIR)/jcphuff.c; $(DO_CC) -$(B)/client/jddctmgr.o : $(JPDIR)/jddctmgr.c; $(DO_CC) -$(B)/client/jdhuff.o : $(JPDIR)/jdhuff.c; $(DO_CC) -$(B)/client/jdinput.o : $(JPDIR)/jdinput.c; $(DO_CC) -$(B)/client/jdmainct.o : $(JPDIR)/jdmainct.c; $(DO_CC) -$(B)/client/jdmarker.o : $(JPDIR)/jdmarker.c; $(DO_CC) -$(B)/client/jdmaster.o : $(JPDIR)/jdmaster.c; $(DO_CC) -$(B)/client/jdpostct.o : $(JPDIR)/jdpostct.c; $(DO_CC) -$(B)/client/jdsample.o : $(JPDIR)/jdsample.c; $(DO_CC) -$(B)/client/jdtrans.o : $(JPDIR)/jdtrans.c; $(DO_CC) -$(B)/client/jerror.o : $(JPDIR)/jerror.c; $(DO_CC) $(GL_CFLAGS) $(MINGW_CFLAGS) -$(B)/client/jidctflt.o : $(JPDIR)/jidctflt.c; $(DO_CC) -$(B)/client/jmemmgr.o : $(JPDIR)/jmemmgr.c; $(DO_CC) -$(B)/client/jmemnobs.o : $(JPDIR)/jmemnobs.c; $(DO_CC) $(GL_CFLAGS) $(MINGW_CFLAGS) -$(B)/client/jutils.o : $(JPDIR)/jutils.c; $(DO_CC) - $(B)/client/tr_bsp.o : $(RDIR)/tr_bsp.c; $(DO_CC) $(GL_CFLAGS) $(B)/client/tr_animation.o : $(RDIR)/tr_animation.c; $(DO_CC) $(GL_CFLAGS) $(B)/client/tr_backend.o : $(RDIR)/tr_backend.c; $(DO_CC) $(GL_CFLAGS) Index: code/renderer/tr_image.c =================================================================== --- code/renderer/tr_image.c (revision 146) +++ code/renderer/tr_image.c (working copy) @@ -29,9 +29,9 @@ * (stdio.h is sufficient on ANSI-conforming systems.) * You may also wish to include "jerror.h". */ - #define JPEG_INTERNALS -#include "../jpeg-6/jpeglib.h" +#include +#include static void LoadBMP( const char *name, byte **pic, int *width, int *height ); @@ -1369,7 +1369,168 @@ ri.FS_FreeFile (buffer); } +/* + * 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 "jpeglib.h" +#include "jerror.h" + + +/* 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; +} + static void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height ) { /* This struct contains the JPEG decompression parameters and pointers to * working space (which is allocated as needed by the JPEG library). @@ -1395,6 +1556,7 @@ unsigned char *out; byte *fbuffer; byte *buf; + int buflen; /* size of fbuffer returned from FS_ReadFile */ /* 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. @@ -1402,7 +1564,7 @@ * requires it in order to read binary files. */ - ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); + buflen = ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer); if (!fbuffer) { return; } @@ -1419,10 +1581,9 @@ /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress(&cinfo); - /* Step 2: specify data source (eg, a file) */ + /* Step 2: specify data source (a buffer in memory) */ + jpeg_memory_src(&cinfo, fbuffer, buflen); - jpeg_stdio_src(&cinfo, fbuffer); - /* Step 3: read file parameters with jpeg_read_header() */ (void) jpeg_read_header(&cinfo, TRUE); @@ -1619,7 +1780,7 @@ * wrong thing. */ -GLOBAL void +GLOBAL(void) jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) { if (cinfo->global_state != CSTATE_START) @@ -1658,7 +1819,7 @@ * when using a multiple-scanline buffer. */ -GLOBAL JDIMENSION +GLOBAL(JDIMENSION) jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines) {