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.
This commit is contained in:
Tobias Frost 2014-11-01 17:59:25 +01:00
parent a8d9c2b489
commit 6bfedbfeb9
4 changed files with 122 additions and 74 deletions

View file

@ -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()

View file

@ -36,7 +36,7 @@ extern idCVar s_noSound;
#define JPEG_INTERNALS
//extern "C" {
#include "../libs/jpeg-6/jpeglib.h"
#include <jpeglib.h>
//}
#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;

View file

@ -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 <jpeglib.h>
#include <jerror.h>
// 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 );

View file

@ -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 <jpeglib.h>
/*
========================