From 6bfedbfeb98172d3309ac76d448a6ca030ea010c Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Sat, 1 Nov 2014 17:59:25 +0100 Subject: [PATCH] Use system's libjpeg when -DUSE_SYSTEM_LIBJPEG is used note, that it is expected that this libjpeg is newer, therefore some files needs to be patched to compile. This patch is used for Debian -- Debian uses libjpeg-turbo, but I assume that it will also compile against a recent libjpeg. --- neo/CMakeLists.txt | 150 ++++++++++++++++++++--------------- neo/renderer/Cinematic.cpp | 30 +++++-- neo/renderer/Image_files.cpp | 14 ++-- neo/swf/SWF_Image.cpp | 2 +- 4 files changed, 122 insertions(+), 74 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 4781eaba..3df5791a 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -27,6 +27,9 @@ option(USE_SYSTEM_ZLIB option(USE_SYSTEM_LIBPNG "Use the system libpng instead of the bundled one" OFF) +option(USE_SYSTEM_LIBJPEG + "Use the system libjpeg instead of the bundled one" OFF) + if(UNIX) set(OPENAL TRUE) endif() @@ -209,6 +212,20 @@ else (PNG_FOUND) set(PNG_LIBRARY "" ) endif (PNG_FOUND) + +if(USE_SYSTEM_LIBJPEG) +find_package(JPEG REQUIRED) +endif(USE_SYSTEM_LIBJPEG) + +if (JPEG_FOUND) + include_directories(${JPEG_INCLUDE_DIRS}) + set(JPEG_LIBRARY ${JPEG_LIBRARIES}) + add_definitions(-DUSE_NEWER_JPEG) +else (JPEG_FOUND) + include_directories("libs/jpeg-6") + set(JPEG_LIBRARY "" ) +endif (JPEG_FOUND) + add_subdirectory(idlib) file(GLOB AAS_INCLUDES aas/*.h) @@ -342,69 +359,74 @@ file(GLOB RENDERER_OPENGL_SOURCES renderer/OpenGL/*.cpp) file(GLOB IRRXML_INCLUDES libs/irrxml/src/*.h) file(GLOB IRRXML_SOURCES libs/irrxml/src/*.cpp) - -set(JPEG_INCLUDES - libs/jpeg-6/jchuff.h - libs/jpeg-6/jconfig.h - libs/jpeg-6/jdct.h - libs/jpeg-6/jdhuff.h - libs/jpeg-6/jerror.h - libs/jpeg-6/jinclude.h - libs/jpeg-6/jmemsys.h - libs/jpeg-6/jmorecfg.h - libs/jpeg-6/jpegint.h - libs/jpeg-6/jpeglib.h - libs/jpeg-6/jversion.h) - -set(JPEG_SOURCES - libs/jpeg-6/jcapimin.cpp - libs/jpeg-6/jcapistd.cpp - libs/jpeg-6/jccoefct.cpp - libs/jpeg-6/jccolor.cpp - libs/jpeg-6/jcdctmgr.cpp - libs/jpeg-6/jchuff.cpp - libs/jpeg-6/jcinit.cpp - libs/jpeg-6/jcmainct.cpp - libs/jpeg-6/jcmarker.cpp - libs/jpeg-6/jcmaster.cpp - libs/jpeg-6/jcomapi.cpp - libs/jpeg-6/jcparam.cpp - libs/jpeg-6/jcphuff.cpp - libs/jpeg-6/jcprepct.cpp - libs/jpeg-6/jcsample.cpp - libs/jpeg-6/jctrans.cpp - libs/jpeg-6/jdapimin.cpp - libs/jpeg-6/jdapistd.cpp - libs/jpeg-6/jdatadst.cpp - libs/jpeg-6/jdatasrc.cpp - libs/jpeg-6/jdcoefct.cpp - libs/jpeg-6/jdcolor.cpp - libs/jpeg-6/jddctmgr.cpp - libs/jpeg-6/jdhuff.cpp - libs/jpeg-6/jdinput.cpp - libs/jpeg-6/jdmainct.cpp - libs/jpeg-6/jdmarker.cpp - libs/jpeg-6/jdmaster.cpp - libs/jpeg-6/jdmerge.cpp - libs/jpeg-6/jdphuff.cpp - libs/jpeg-6/jdpostct.cpp - libs/jpeg-6/jdsample.cpp - libs/jpeg-6/jdtrans.cpp - libs/jpeg-6/jerror.cpp - libs/jpeg-6/jfdctflt.cpp - libs/jpeg-6/jfdctfst.cpp - libs/jpeg-6/jfdctint.cpp - libs/jpeg-6/jidctflt.cpp - libs/jpeg-6/jidctfst.cpp - libs/jpeg-6/jidctint.cpp - libs/jpeg-6/jidctred.cpp - #libs/jpeg-6/jload.cpp - libs/jpeg-6/jmemmgr.cpp - libs/jpeg-6/jmemnobs.cpp - #libs/jpeg-6/jpegtran.cpp - libs/jpeg-6/jquant1.cpp - libs/jpeg-6/jquant2.cpp - libs/jpeg-6/jutils.cpp) + +if (NOT JPEG_FOUND) + set(JPEG_INCLUDES + libs/jpeg-6/jchuff.h + libs/jpeg-6/jconfig.h + libs/jpeg-6/jdct.h + libs/jpeg-6/jdhuff.h + libs/jpeg-6/jerror.h + libs/jpeg-6/jinclude.h + libs/jpeg-6/jmemsys.h + libs/jpeg-6/jmorecfg.h + libs/jpeg-6/jpegint.h + libs/jpeg-6/jpeglib.h + libs/jpeg-6/jversion.h) + + set(JPEG_SOURCES + libs/jpeg-6/jcapimin.cpp + libs/jpeg-6/jcapistd.cpp + libs/jpeg-6/jccoefct.cpp + libs/jpeg-6/jccolor.cpp + libs/jpeg-6/jcdctmgr.cpp + libs/jpeg-6/jchuff.cpp + libs/jpeg-6/jcinit.cpp + libs/jpeg-6/jcmainct.cpp + libs/jpeg-6/jcmarker.cpp + libs/jpeg-6/jcmaster.cpp + libs/jpeg-6/jcomapi.cpp + libs/jpeg-6/jcparam.cpp + libs/jpeg-6/jcphuff.cpp + libs/jpeg-6/jcprepct.cpp + libs/jpeg-6/jcsample.cpp + libs/jpeg-6/jctrans.cpp + libs/jpeg-6/jdapimin.cpp + libs/jpeg-6/jdapistd.cpp + libs/jpeg-6/jdatadst.cpp + libs/jpeg-6/jdatasrc.cpp + libs/jpeg-6/jdcoefct.cpp + libs/jpeg-6/jdcolor.cpp + libs/jpeg-6/jddctmgr.cpp + libs/jpeg-6/jdhuff.cpp + libs/jpeg-6/jdinput.cpp + libs/jpeg-6/jdmainct.cpp + libs/jpeg-6/jdmarker.cpp + libs/jpeg-6/jdmaster.cpp + libs/jpeg-6/jdmerge.cpp + libs/jpeg-6/jdphuff.cpp + libs/jpeg-6/jdpostct.cpp + libs/jpeg-6/jdsample.cpp + libs/jpeg-6/jdtrans.cpp + libs/jpeg-6/jerror.cpp + libs/jpeg-6/jfdctflt.cpp + libs/jpeg-6/jfdctfst.cpp + libs/jpeg-6/jfdctint.cpp + libs/jpeg-6/jidctflt.cpp + libs/jpeg-6/jidctfst.cpp + libs/jpeg-6/jidctint.cpp + libs/jpeg-6/jidctred.cpp + #libs/jpeg-6/jload.cpp + libs/jpeg-6/jmemmgr.cpp + libs/jpeg-6/jmemnobs.cpp + #libs/jpeg-6/jpegtran.cpp + libs/jpeg-6/jquant1.cpp + libs/jpeg-6/jquant2.cpp + libs/jpeg-6/jutils.cpp) +else (NOT JPEG_FOUND) + set(JPEG_INCLUDES "") + set(JPEG_SOURCES "") +endif (NOT JPEG_FOUND) if (NOT PNG_FOUND) file(GLOB PNG_INCLUDES libs/png/*.h) @@ -1355,6 +1377,7 @@ if(MSVC) ${FFmpeg_LIBRARIES} ${ZLIB_LIBRARY} ${PNG_LIBRARY} + ${JPEG_LIBRARY} ) #CMAKE_BINARY_DIR @@ -1518,6 +1541,7 @@ else() ${FFMPEG_LIBRARIES} ${ZLIB_LIBRARY} ${PNG_LIBRARY} + ${JPEG_LIBRARY} ) endif() diff --git a/neo/renderer/Cinematic.cpp b/neo/renderer/Cinematic.cpp index 71f618a4..02567cb1 100644 --- a/neo/renderer/Cinematic.cpp +++ b/neo/renderer/Cinematic.cpp @@ -36,7 +36,7 @@ extern idCVar s_noSound; #define JPEG_INTERNALS //extern "C" { -#include "../libs/jpeg-6/jpeglib.h" +#include //} #include "tr_local.h" @@ -2046,8 +2046,12 @@ struct jpeg_error_mgr jerr; * the front of the buffer rather than discarding it. */ - -METHODDEF boolean fill_input_buffer( j_decompress_ptr cinfo ) +#ifdef USE_NEWER_JPEG +METHODDEF(boolean) +#else +METHODDEF boolean +#endif +fill_input_buffer( j_decompress_ptr cinfo ) { my_src_ptr src = ( my_src_ptr ) cinfo->src; int nbytes; @@ -2078,8 +2082,12 @@ METHODDEF boolean fill_input_buffer( j_decompress_ptr cinfo ) * before any data is actually read. */ - -METHODDEF void init_source( j_decompress_ptr cinfo ) +#ifdef USE_NEWER_JPEG +METHODDEF(void) +#else +METHODDEF void +#endif +init_source( j_decompress_ptr cinfo ) { my_src_ptr src = ( my_src_ptr ) cinfo->src; @@ -2102,7 +2110,11 @@ METHODDEF void init_source( j_decompress_ptr cinfo ) * buffer is the application writer's problem. */ +#ifdef USE_NEWER_JPEG +METHODDEF(void) +#else METHODDEF void +#endif skip_input_data( j_decompress_ptr cinfo, long num_bytes ) { my_src_ptr src = ( my_src_ptr ) cinfo->src; @@ -2138,14 +2150,22 @@ skip_input_data( j_decompress_ptr cinfo, long num_bytes ) * for error exit. */ +#ifdef USE_NEWER_JPEG +METHODDEF(void) +#else METHODDEF void +#endif term_source( j_decompress_ptr cinfo ) { cinfo = cinfo; /* no work necessary here */ } +#ifdef USE_NEWER_JPEG +GLOBAL(void) +#else GLOBAL void +#endif jpeg_memory_src( j_decompress_ptr cinfo, byte* infile, int size ) { my_src_ptr src; diff --git a/neo/renderer/Image_files.cpp b/neo/renderer/Image_files.cpp index 9b6641ca..9392860b 100644 --- a/neo/renderer/Image_files.cpp +++ b/neo/renderer/Image_files.cpp @@ -49,7 +49,8 @@ void R_LoadImage( const char *name, byte **pic, int *width, int *height, bool ma * You may also wish to include "jerror.h". */ -#include "../libs/jpeg-6/jpeglib.h" +#include +#include // hooks from jpeg lib to our system @@ -453,7 +454,8 @@ static void LoadJPG( const char* filename, unsigned char** pic, int* width, int* unsigned char* out; byte* fbuffer; byte* bbuf; - + int len; + /* 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. * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that @@ -467,7 +469,6 @@ static void LoadJPG( const char* filename, unsigned char** pic, int* width, int* *pic = NULL; // until proven otherwise } { - int len; idFile* f; f = fileSystem->OpenFileRead( filename ); @@ -505,8 +506,11 @@ static void LoadJPG( const char* filename, unsigned char** pic, int* width, int* /* Step 2: specify data source (eg, a file) */ - jpeg_stdio_src( &cinfo, fbuffer ); - +#ifdef USE_NEWER_JPEG + jpeg_mem_src( &cinfo, fbuffer, len ); +#else + jpeg_stdio_src( &cinfo, fbuffer ); +#endif /* Step 3: read file parameters with jpeg_read_header() */ jpeg_read_header( &cinfo, true ); diff --git a/neo/swf/SWF_Image.cpp b/neo/swf/SWF_Image.cpp index 1ad593ca..267e7722 100644 --- a/neo/swf/SWF_Image.cpp +++ b/neo/swf/SWF_Image.cpp @@ -29,7 +29,7 @@ If you have questions concerning this license or the applicable additional terms #include "precompiled.h" #include "../renderer/Image.h" //#include "../../renderer/ImageTools/ImageProcess.h" -#include "../libs/jpeg-6/jpeglib.h" +#include /* ========================