Skip to content

Instantly share code, notes, and snippets.

@coldtobi
Last active August 29, 2015 14:07
Show Gist options
  • Save coldtobi/7700133f5f2a3e240d82 to your computer and use it in GitHub Desktop.
Save coldtobi/7700133f5f2a3e240d82 to your computer and use it in GitHub Desktop.
Description: Use system/packaged libjpeg
Author: Tobias Frost <tobi@debian.org>
Forwarded: no
Last-Update: 2014-10-18
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/neo/CMakeLists.txt
+++ b/neo/CMakeLists.txt
@@ -202,6 +202,22 @@
set(PNG_LIBRARY "" )
endif (PNG_FOUND)
+# coldtobi: use system libjpeg if available (same logic as for the zlib)
+# contrary to the above, this is marked REQUIRED because the library in the
+# doom sources is too old and code needs patching
+# however, if the library is updated in the doom source one can remove the
+# required (and patch the directory name if required)
+# Debian has -- at the point of this writing libjpeg-dev provided by
+# libjpeg-turbo.
+find_package(JPEG REQUIRED)
+if (JPEG_FOUND)
+ include_directories(${JPEG_INCLUDE_DIRS})
+ set(JPEG_LIBRARY ${JPEG_LIBRARIES})
+else (JPEG_FOUND)
+ include_directories("libs/jpeg-6")
+ set(JPEG_LIBRARY "" )
+endif (JPEG_FOUND)
+
add_subdirectory(idlib)
file(GLOB AAS_INCLUDES aas/*.h)
@@ -335,69 +351,74 @@
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)
@@ -1349,6 +1370,7 @@
${FFmpeg_LIBRARIES}
${ZLIB_LIBRARY}
${PNG_LIBRARY}
+ ${JPEG_LIBRARY}
)
#CMAKE_BINARY_DIR
@@ -1512,6 +1534,7 @@
${FFMPEG_LIBRARIES}
${ZLIB_LIBRARY}
${PNG_LIBRARY}
+ ${JPEG_LIBRARY}
)
endif()
--- a/neo/renderer/Image_files.cpp
+++ b/neo/renderer/Image_files.cpp
@@ -49,7 +49,8 @@
* 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 @@
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 @@
*pic = NULL; // until proven otherwise
}
{
- int len;
idFile* f;
f = fileSystem->OpenFileRead( filename );
@@ -505,7 +506,7 @@
/* Step 2: specify data source (eg, a file) */
- jpeg_stdio_src( &cinfo, fbuffer );
+ jpeg_mem_src( &cinfo, fbuffer, len );
/* Step 3: read file parameters with jpeg_read_header() */
--- a/neo/swf/SWF_Image.cpp
+++ b/neo/swf/SWF_Image.cpp
@@ -29,7 +29,7 @@
#include "precompiled.h"
#include "../renderer/Image.h"
//#include "../../renderer/ImageTools/ImageProcess.h"
-#include "../libs/jpeg-6/jpeglib.h"
+#include <jpeglib.h>
/*
========================
--- a/neo/renderer/Cinematic.cpp
+++ b/neo/renderer/Cinematic.cpp
@@ -36,7 +36,7 @@
#define JPEG_INTERNALS
//extern "C" {
-#include "../libs/jpeg-6/jpeglib.h"
+#include <jpeglib.h>
//}
#include "tr_local.h"
@@ -2047,7 +2047,7 @@
*/
-METHODDEF boolean fill_input_buffer( j_decompress_ptr cinfo )
+METHODDEF(boolean) fill_input_buffer( j_decompress_ptr cinfo )
{
my_src_ptr src = ( my_src_ptr ) cinfo->src;
int nbytes;
@@ -2079,7 +2079,7 @@
*/
-METHODDEF void init_source( j_decompress_ptr cinfo )
+METHODDEF(void) init_source( j_decompress_ptr cinfo )
{
my_src_ptr src = ( my_src_ptr ) cinfo->src;
@@ -2102,7 +2102,7 @@
* buffer is the application writer's problem.
*/
-METHODDEF void
+METHODDEF(void)
skip_input_data( j_decompress_ptr cinfo, long num_bytes )
{
my_src_ptr src = ( my_src_ptr ) cinfo->src;
@@ -2138,14 +2138,14 @@
* for error exit.
*/
-METHODDEF void
+METHODDEF(void)
term_source( j_decompress_ptr cinfo )
{
cinfo = cinfo;
/* no work necessary here */
}
-GLOBAL void
+GLOBAL (void)
jpeg_memory_src( j_decompress_ptr cinfo, byte* infile, int size )
{
my_src_ptr src;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment