--- Makefile +++ Makefile @@ -91,6 +91,10 @@ USE_OPENAL=1 endif +ifndef USE_SYSTEM_JPEG +USE_SYSTEM_JPEG=1 +endif + ifndef USE_OPENAL_DLOPEN USE_OPENAL_DLOPEN=0 endif @@ -193,6 +197,10 @@ endif endif + ifeq ($(USE_SYSTEM_JPEG),1) + BASE_CFLAGS += -DUSE_SYSTEM_JPEG=1 + endif + ifeq ($(USE_CURL),1) BASE_CFLAGS += -DUSE_CURL=1 ifeq ($(USE_CURL_DLOPEN),1) @@ -269,6 +277,10 @@ CLIENT_LDFLAGS += -lvorbisfile -lvorbis -logg endif + ifeq ($(USE_SYSTEM_JPEG),1) + CLIENT_LDFLAGS += -ljpeg + endif + ifeq ($(ARCH),x86) # linux32 make ... BASE_CFLAGS += -m32 @@ -928,6 +940,33 @@ $(B)/client/vm.o \ $(B)/client/vm_interpreted.o \ \ + $(B)/client/tr_animation.o \ + $(B)/client/tr_backend.o \ + $(B)/client/tr_bloom.o \ + $(B)/client/tr_bsp.o \ + $(B)/client/tr_cmds.o \ + $(B)/client/tr_curve.o \ + $(B)/client/tr_flares.o \ + $(B)/client/tr_font.o \ + $(B)/client/tr_image.o \ + $(B)/client/tr_init.o \ + $(B)/client/tr_light.o \ + $(B)/client/tr_main.o \ + $(B)/client/tr_marks.o \ + $(B)/client/tr_mesh.o \ + $(B)/client/tr_model.o \ + $(B)/client/tr_noise.o \ + $(B)/client/tr_scene.o \ + $(B)/client/tr_shade.o \ + $(B)/client/tr_shade_calc.o \ + $(B)/client/tr_shader.o \ + $(B)/client/tr_shadows.o \ + $(B)/client/tr_sky.o \ + $(B)/client/tr_surface.o \ + $(B)/client/tr_world.o \ + +ifneq ($(USE_SYSTEM_JPEG),1) + Q3OBJ += \ $(B)/client/jcapimin.o \ $(B)/client/jchuff.o \ $(B)/client/jcinit.o \ @@ -961,32 +1000,10 @@ $(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_bloom.o \ - $(B)/client/tr_bsp.o \ - $(B)/client/tr_cmds.o \ - $(B)/client/tr_curve.o \ - $(B)/client/tr_flares.o \ - $(B)/client/tr_font.o \ - $(B)/client/tr_image.o \ - $(B)/client/tr_init.o \ - $(B)/client/tr_light.o \ - $(B)/client/tr_main.o \ - $(B)/client/tr_marks.o \ - $(B)/client/tr_mesh.o \ - $(B)/client/tr_model.o \ - $(B)/client/tr_noise.o \ - $(B)/client/tr_scene.o \ - $(B)/client/tr_shade.o \ - $(B)/client/tr_shade_calc.o \ - $(B)/client/tr_shader.o \ - $(B)/client/tr_shadows.o \ - $(B)/client/tr_sky.o \ - $(B)/client/tr_surface.o \ - $(B)/client/tr_world.o \ + $(B)/client/jutils.o +else + Q3OBJ += $(B)/client/jpeg_memsrc.o +endif ifeq ($(ARCH),x86) Q3OBJ += \ @@ -1284,8 +1301,12 @@ $(B)/client/%.o: $(BLIBDIR)/%.c $(DO_BOT_CC) +ifneq ($(USE_SYSTEM_JPEG),1) $(B)/client/%.o: $(JPDIR)/%.c $(DO_CC) +else +$(B)/client/jmemnobs.o : $(JPDIR)/jmemnobs.c; $(DO_CC) $(GL_CFLAGS) $(MINGW_CFLAGS) +endif $(B)/client/%.o: $(RDIR)/%.c $(DO_CC) --- src/jpeg-6/jmemnobs.c +++ src/jpeg-6/jmemnobs.c @@ -16,11 +16,23 @@ */ #include "../renderer/tr_local.h" +#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 /* * Memory allocation and ri.Freeing are controlled by the regular library @@ -83,7 +95,13 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { - ERREXIT(cinfo, JERR_NO_BACKING_STORE); +#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 } --- src/renderer/tr_image.c +++ src/renderer/tr_image.c @@ -31,8 +31,13 @@ * 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 #include "../qcommon/puff.h" @@ -1409,6 +1414,12 @@ 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. @@ -1416,7 +1427,7 @@ * 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; } @@ -1434,8 +1445,11 @@ 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() */ @@ -1478,7 +1492,7 @@ } memcount = pixelcount * 4; - row_stride = cinfo.output_width * cinfo.output_components; + row_stride = cinfo.output_width * 4; out = ri.Malloc(memcount); @@ -1499,6 +1513,21 @@ 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; @@ -1617,6 +1646,7 @@ return TRUE; } +#ifndef USE_SYSTEM_JPEG /* * Compression initialization. @@ -1709,6 +1739,8 @@ return row_ctr; } +#endif + /* * Terminate destination --- called by jpeg_finish_compress * after all data has been written. Usually needs to flush buffer.