summaryrefslogtreecommitdiffstats
path: root/libkdcraw-4.10.0-libjpeg-turbo.patch
blob: 7cd277795244f00d2210dafd190485a6772d758d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
diff -Nur libkdcraw-4.10.0/libraw/CMakeLists.txt libkdcraw-4.10.0-libjpeg-turbo/libraw/CMakeLists.txt
--- libkdcraw-4.10.0/libraw/CMakeLists.txt	2013-01-23 23:00:43.000000000 +0100
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/CMakeLists.txt	2013-03-09 23:58:25.000000000 +0100
@@ -88,29 +88,26 @@
 
 FIND_PACKAGE(JPEG)
 IF(JPEG_FOUND)
-    # check version of libjpeg
-    # inspired from digikam/CMakeLists.txt
-    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")
-    SET(_jpeglib_version_source_file ${CMAKE_BINARY_DIR}/CMakeTmp/cmake_jpeglib_version_check.cpp)
-    FILE(WRITE "${_jpeglib_version_source_file}" "${_jpeglib_version_source}")
-    SET(_jpeglib_version_include_dirs "-DINCLUDE_DIRECTORIES:STRING=${JPEG_INCLUDE_DIR}")
+    INCLUDE(CheckSymbolExists)
 
-    TRY_COMPILE(_jpeglib_version_compile_result ${CMAKE_BINARY_DIR} ${_jpeglib_version_source_file}
-                CMAKE_FLAGS "${_jpeglib_version_include_dirs}"
-                COMPILE_OUTPUT_VARIABLE _jpeglib_version_compile_output_var
-               )
-    IF(_jpeglib_version_compile_result)
-        MESSAGE(STATUS "Identified libjpeg version less than 80 (too low)")
-        SET(JPEG_FOUND FALSE)
-    ENDIF()
+    # check for the jpeg_mem_src function
+    SET(OLD_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
+    LIST(APPEND CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIR}")
+    SET(OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+    LIST(APPEND CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARY}")
+    CHECK_SYMBOL_EXISTS(jpeg_mem_src "stddef.h;stdio.h;jpeglib.h" HAVE_JPEG_MEM_SRC)
+    SET(CMAKE_REQUIRED_INCLUDES "${OLD_CMAKE_REQUIRED_INCLUDES}")
+    SET(CMAKE_REQUIRED_LIBRARIES "${OLD_CMAKE_REQUIRED_LIBRARIES}")
 ENDIF(JPEG_FOUND)
 
-MACRO_LOG_FEATURE(JPEG_FOUND "libjpeg" "JPEG image format support" "http://www.ijg.org" FALSE "80" "needed for the LibRaw DNG lossy codec")
+MACRO_LOG_FEATURE(JPEG_FOUND "libjpeg" "JPEG image format support" "http://www.ijg.org" FALSE "" "needed for the LibRaw DNG lossy codec")
 
 # Flag to use libjpeg with LibRaw DNG lossy codec
 IF(JPEG_FOUND)
     ADD_DEFINITIONS(-DUSE_JPEG)
-    ADD_DEFINITIONS(-DUSE_JPEG8)
+    IF(HAVE_JPEG_MEM_SRC)
+        ADD_DEFINITIONS(-DUSE_JPEG8)
+    ENDIF(HAVE_JPEG_MEM_SRC)
     INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
 ENDIF()
 
diff -Nur libkdcraw-4.10.0/libraw/RawSpeed/DngDecoderSlices.cpp libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/DngDecoderSlices.cpp
--- libkdcraw-4.10.0/libraw/RawSpeed/DngDecoderSlices.cpp	2013-01-23 23:00:43.000000000 +0100
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/DngDecoderSlices.cpp	2013-03-09 23:48:29.000000000 +0100
@@ -88,7 +88,7 @@
 
 }
 
-#if JPEG_LIB_VERSION < 80
+#ifndef USE_JPEG8
 /* Read JPEG image from a memory segment */
 
 static void init_source (j_decompress_ptr cinfo) {}
diff -Nur libkdcraw-4.10.0/libraw/RawSpeed/rawspeed.jpeg-version.patch libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/rawspeed.jpeg-version.patch
--- libkdcraw-4.10.0/libraw/RawSpeed/rawspeed.jpeg-version.patch	1970-01-01 01:00:00.000000000 +0100
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/RawSpeed/rawspeed.jpeg-version.patch	2013-03-09 23:48:29.000000000 +0100
@@ -0,0 +1,13 @@
+diff --git a/RawSpeed/DngDecoderSlices.cpp b/RawSpeed/DngDecoderSlices.cpp
+index 28a137e..617b4b3 100644
+--- a/RawSpeed/DngDecoderSlices.cpp
++++ b/RawSpeed/DngDecoderSlices.cpp
+@@ -88,7 +88,7 @@ void DngDecoderSlices::startDecoding() {
+ 
+ }
+ 
+-#if JPEG_LIB_VERSION < 80
++#ifndef USE_JPEG8
+ /* Read JPEG image from a memory segment */
+ 
+ static void init_source (j_decompress_ptr cinfo) {}
diff -Nur libkdcraw-4.10.0/libraw/src/libraw_datastream.cpp libkdcraw-4.10.0-libjpeg-turbo/libraw/src/libraw_datastream.cpp
--- libkdcraw-4.10.0/libraw/src/libraw_datastream.cpp	2013-01-23 23:00:44.000000000 +0100
+++ libkdcraw-4.10.0-libjpeg-turbo/libraw/src/libraw_datastream.cpp	2013-03-10 00:22:15.000000000 +0100
@@ -443,9 +443,52 @@
 #endif
 }
 
+#if !defined(NO_JPEG) && !defined(USE_JPEG8)
+/* Read JPEG image from a memory segment
+   (from libraw/RawSpeed/DngDecoderSlices.cpp, LGPLv2+) */
+
+static void init_source (j_decompress_ptr cinfo) {}
+static boolean fill_input_buffer (j_decompress_ptr cinfo)
+{
+  struct jpeg_source_mgr* src = (struct jpeg_source_mgr*) cinfo->src;
+  return !!src->bytes_in_buffer;
+}
+static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
+{
+  struct jpeg_source_mgr* src = (struct jpeg_source_mgr*) cinfo->src;
+
+  if (num_bytes > (int)src->bytes_in_buffer)
+    throw LIBRAW_EXCEPTION_IO_EOF;
+  if (num_bytes > 0) {
+    src->next_input_byte += (size_t) num_bytes;
+    src->bytes_in_buffer -= (size_t) num_bytes;
+  }
+}
+static void term_source (j_decompress_ptr cinfo) {}
+static void jpeg_mem_src (j_decompress_ptr cinfo, unsigned char* buffer, long nbytes)
+{
+  struct jpeg_source_mgr* src;
+
+  if (cinfo->src == NULL) {   /* first time for this JPEG object? */
+    cinfo->src = (struct jpeg_source_mgr *)
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+      sizeof(struct jpeg_source_mgr));
+  }
+
+  src = (struct jpeg_source_mgr*) cinfo->src;
+  src->init_source = init_source;
+  src->fill_input_buffer = fill_input_buffer;
+  src->skip_input_data = skip_input_data;
+  src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
+  src->term_source = term_source;
+  src->bytes_in_buffer = nbytes;
+  src->next_input_byte = (JOCTET*)buffer;
+}
+#endif
+
 int LibRaw_buffer_datastream::jpeg_src(void *jpegdata)
 {
-#if defined(NO_JPEG) || !defined (USE_JPEG8)
+#if defined(NO_JPEG)
   return -1;
 #else
   j_decompress_ptr cinfo = (j_decompress_ptr) jpegdata;