Blame SOURCES/libkdcraw-4.10.0-libjpeg-turbo.patch

56e28e
diff -Nur libkdcraw-4.10.0/libraw/CMakeLists.txt libkdcraw-4.10.0-libjpeg-turbo/libraw/CMakeLists.txt
56e28e
--- libkdcraw-4.10.0/libraw/CMakeLists.txt	2013-01-23 23:00:43.000000000 +0100
56e28e
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/CMakeLists.txt	2013-03-09 23:58:25.000000000 +0100
56e28e
@@ -88,29 +88,26 @@
56e28e
 
56e28e
 FIND_PACKAGE(JPEG)
56e28e
 IF(JPEG_FOUND)
56e28e
-    # check version of libjpeg
56e28e
-    # inspired from digikam/CMakeLists.txt
56e28e
-    SET(_jpeglib_version_source "#include <stddef.h>\n#include<stdio.h>\n#include <jpeglib.h>\n int main()\n {\n #if (JPEG_LIB_VERSION >= 80) \n #error JPEG_LIB_VERSION >= 80 found \n #endif \n }\n")
56e28e
-    SET(_jpeglib_version_source_file ${CMAKE_BINARY_DIR}/CMakeTmp/cmake_jpeglib_version_check.cpp)
56e28e
-    FILE(WRITE "${_jpeglib_version_source_file}" "${_jpeglib_version_source}")
56e28e
-    SET(_jpeglib_version_include_dirs "-DINCLUDE_DIRECTORIES:STRING=${JPEG_INCLUDE_DIR}")
56e28e
+    INCLUDE(CheckSymbolExists)
56e28e
 
56e28e
-    TRY_COMPILE(_jpeglib_version_compile_result ${CMAKE_BINARY_DIR} ${_jpeglib_version_source_file}
56e28e
-                CMAKE_FLAGS "${_jpeglib_version_include_dirs}"
56e28e
-                COMPILE_OUTPUT_VARIABLE _jpeglib_version_compile_output_var
56e28e
-               )
56e28e
-    IF(_jpeglib_version_compile_result)
56e28e
-        MESSAGE(STATUS "Identified libjpeg version less than 80 (too low)")
56e28e
-        SET(JPEG_FOUND FALSE)
56e28e
-    ENDIF()
56e28e
+    # check for the jpeg_mem_src function
56e28e
+    SET(OLD_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
56e28e
+    LIST(APPEND CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIR}")
56e28e
+    SET(OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
56e28e
+    LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARY}")
56e28e
+    CHECK_SYMBOL_EXISTS(jpeg_mem_src "stddef.h;stdio.h;jpeglib.h" HAVE_JPEG_MEM_SRC)
56e28e
+    SET(CMAKE_REQUIRED_INCLUDES "${OLD_CMAKE_REQUIRED_INCLUDES}")
56e28e
+    SET(CMAKE_REQUIRED_LIBRARIES "${OLD_CMAKE_REQUIRED_LIBRARIES}")
56e28e
 ENDIF(JPEG_FOUND)
56e28e
 
56e28e
-MACRO_LOG_FEATURE(JPEG_FOUND "libjpeg" "JPEG image format support" "http://www.ijg.org" FALSE "80" "needed for the LibRaw DNG lossy codec")
56e28e
+MACRO_LOG_FEATURE(JPEG_FOUND "libjpeg" "JPEG image format support" "http://www.ijg.org" FALSE "" "needed for the LibRaw DNG lossy codec")
56e28e
 
56e28e
 # Flag to use libjpeg with LibRaw DNG lossy codec
56e28e
 IF(JPEG_FOUND)
56e28e
     ADD_DEFINITIONS(-DUSE_JPEG)
56e28e
-    ADD_DEFINITIONS(-DUSE_JPEG8)
56e28e
+    IF(HAVE_JPEG_MEM_SRC)
56e28e
+        ADD_DEFINITIONS(-DUSE_JPEG8)
56e28e
+    ENDIF(HAVE_JPEG_MEM_SRC)
56e28e
     INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
56e28e
 ENDIF()
56e28e
 
56e28e
diff -Nur libkdcraw-4.10.0/libraw/RawSpeed/DngDecoderSlices.cpp libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/DngDecoderSlices.cpp
56e28e
--- libkdcraw-4.10.0/libraw/RawSpeed/DngDecoderSlices.cpp	2013-01-23 23:00:43.000000000 +0100
56e28e
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/DngDecoderSlices.cpp	2013-03-09 23:48:29.000000000 +0100
56e28e
@@ -88,7 +88,7 @@
56e28e
 
56e28e
 }
56e28e
 
56e28e
-#if JPEG_LIB_VERSION < 80
56e28e
+#ifndef USE_JPEG8
56e28e
 /* Read JPEG image from a memory segment */
56e28e
 
56e28e
 static void init_source (j_decompress_ptr cinfo) {}
56e28e
diff -Nur libkdcraw-4.10.0/libraw/RawSpeed/rawspeed.jpeg-version.patch libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/rawspeed.jpeg-version.patch
56e28e
--- libkdcraw-4.10.0/libraw/RawSpeed/rawspeed.jpeg-version.patch	1970-01-01 01:00:00.000000000 +0100
56e28e
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/rawspeed.jpeg-version.patch	2013-03-09 23:48:29.000000000 +0100
56e28e
@@ -0,0 +1,13 @@
56e28e
+diff --git a/RawSpeed/DngDecoderSlices.cpp b/RawSpeed/DngDecoderSlices.cpp
56e28e
+index 28a137e..617b4b3 100644
56e28e
+--- a/RawSpeed/DngDecoderSlices.cpp
56e28e
++++ b/RawSpeed/DngDecoderSlices.cpp
56e28e
+@@ -88,7 +88,7 @@ void DngDecoderSlices::startDecoding() {
56e28e
+ 
56e28e
+ }
56e28e
+ 
56e28e
+-#if JPEG_LIB_VERSION < 80
56e28e
++#ifndef USE_JPEG8
56e28e
+ /* Read JPEG image from a memory segment */
56e28e
+ 
56e28e
+ static void init_source (j_decompress_ptr cinfo) {}
56e28e
diff -Nur libkdcraw-4.10.0/libraw/src/libraw_datastream.cpp libkdcraw-4.10.0-libjpeg-turbo/libraw/src/libraw_datastream.cpp
56e28e
--- libkdcraw-4.10.0/libraw/src/libraw_datastream.cpp	2013-01-23 23:00:44.000000000 +0100
56e28e
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/src/libraw_datastream.cpp	2013-03-10 00:22:15.000000000 +0100
56e28e
@@ -443,9 +443,52 @@
56e28e
 #endif
56e28e
 }
56e28e
 
56e28e
+#if !defined(NO_JPEG) && !defined(USE_JPEG8)
56e28e
+/* Read JPEG image from a memory segment
56e28e
+   (from libraw/RawSpeed/DngDecoderSlices.cpp, LGPLv2+) */
56e28e
+
56e28e
+static void init_source (j_decompress_ptr cinfo) {}
56e28e
+static boolean fill_input_buffer (j_decompress_ptr cinfo)
56e28e
+{
56e28e
+  struct jpeg_source_mgr* src = (struct jpeg_source_mgr*) cinfo->src;
56e28e
+  return !!src->bytes_in_buffer;
56e28e
+}
56e28e
+static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
56e28e
+{
56e28e
+  struct jpeg_source_mgr* src = (struct jpeg_source_mgr*) cinfo->src;
56e28e
+
56e28e
+  if (num_bytes > (int)src->bytes_in_buffer)
56e28e
+    throw LIBRAW_EXCEPTION_IO_EOF;
56e28e
+  if (num_bytes > 0) {
56e28e
+    src->next_input_byte += (size_t) num_bytes;
56e28e
+    src->bytes_in_buffer -= (size_t) num_bytes;
56e28e
+  }
56e28e
+}
56e28e
+static void term_source (j_decompress_ptr cinfo) {}
56e28e
+static void jpeg_mem_src (j_decompress_ptr cinfo, unsigned char* buffer, long nbytes)
56e28e
+{
56e28e
+  struct jpeg_source_mgr* src;
56e28e
+
56e28e
+  if (cinfo->src == NULL) {   /* first time for this JPEG object? */
56e28e
+    cinfo->src = (struct jpeg_source_mgr *)
56e28e
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
56e28e
+      sizeof(struct jpeg_source_mgr));
56e28e
+  }
56e28e
+
56e28e
+  src = (struct jpeg_source_mgr*) cinfo->src;
56e28e
+  src->init_source = init_source;
56e28e
+  src->fill_input_buffer = fill_input_buffer;
56e28e
+  src->skip_input_data = skip_input_data;
56e28e
+  src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
56e28e
+  src->term_source = term_source;
56e28e
+  src->bytes_in_buffer = nbytes;
56e28e
+  src->next_input_byte = (JOCTET*)buffer;
56e28e
+}
56e28e
+#endif
56e28e
+
56e28e
 int LibRaw_buffer_datastream::jpeg_src(void *jpegdata)
56e28e
 {
56e28e
-#if defined(NO_JPEG) || !defined (USE_JPEG8)
56e28e
+#if defined(NO_JPEG)
56e28e
   return -1;
56e28e
 #else
56e28e
   j_decompress_ptr cinfo = (j_decompress_ptr) jpegdata;