summaryrefslogtreecommitdiffstats
path: root/graphics-libs
diff options
context:
space:
mode:
authorIsmael Luceno2021-09-07 18:48:41 +0200
committerIsmael Luceno2021-09-07 19:08:35 +0200
commit40182960b0912f9c668d926bad03594733ce4352 (patch)
tree815e21d8a304c6ef0f5674ce226d69334675ddbb /graphics-libs
parent5eb21754547de4648d97d2c3f4343edcf2d5e934 (diff)
freeimage 3.18.0 + build fixes
Diffstat (limited to 'graphics-libs')
-rwxr-xr-xgraphics-libs/freeimage/BUILD8
-rwxr-xr-xgraphics-libs/freeimage/DEPENDS1
-rwxr-xr-xgraphics-libs/freeimage/DETAILS8
-rw-r--r--graphics-libs/freeimage/Fix-CVE-2015-0852.patch127
-rw-r--r--graphics-libs/freeimage/Fix-CVE-2016-5684.patch33
-rw-r--r--graphics-libs/freeimage/HISTORY17
-rwxr-xr-xgraphics-libs/freeimage/PRE_BUILD39
-rw-r--r--graphics-libs/freeimage/patches/0001-Disable-vendored-dependencies.patch396
-rw-r--r--graphics-libs/freeimage/patches/0002-Use-system-dependencies.patch189
-rw-r--r--graphics-libs/freeimage/patches/0003-Fix-macro-redefinition-for-64-bit-integer-types.patch27
-rw-r--r--graphics-libs/freeimage/patches/0004-Fix-compatibility-with-system-libpng.patch102
-rw-r--r--graphics-libs/freeimage/patches/0006-Disable-testing-of-JPEG-transform.patch45
-rw-r--r--graphics-libs/freeimage/patches/0007-Disable-testing-of-JXR-MemIO.patch27
-rw-r--r--graphics-libs/freeimage/patches/0010-CVE-2019-12211-13.patch164
-rw-r--r--graphics-libs/freeimage/patches/0011-Fix_compilation_external-static.patch18
-rw-r--r--graphics-libs/freeimage/patches/0012-Fix-libraw-compilation.patch76
-rw-r--r--graphics-libs/freeimage/patches/0013-Update-OpenEXR-API.patch37
17 files changed, 1127 insertions, 187 deletions
diff --git a/graphics-libs/freeimage/BUILD b/graphics-libs/freeimage/BUILD
index a05aac3293..9ec48a0ba5 100755
--- a/graphics-libs/freeimage/BUILD
+++ b/graphics-libs/freeimage/BUILD
@@ -1,7 +1,3 @@
-if [[ "${SMGL_COMPAT_ARCHS[1]}" == "x86_64" || "${SMGL_COMPAT_ARCHS[1]}" == "em64t" ]]; then
- sed -i 's:COMPILERFLAGS = :&-fPIC -DPIC :' $SOURCE_DIRECTORY/Makefile.fip
-fi &&
-
-cd $SOURCE_DIRECTORY &&
-CXXFLAGS+=" -fpermissive -Wno-narrowing" make &&
+CFLAGS+=' -fPIC' CXXFLAGS+=' -fPIC' &&
+make &&
make -f Makefile.fip
diff --git a/graphics-libs/freeimage/DEPENDS b/graphics-libs/freeimage/DEPENDS
index d37b379572..e423ea632a 100755
--- a/graphics-libs/freeimage/DEPENDS
+++ b/graphics-libs/freeimage/DEPENDS
@@ -2,6 +2,7 @@ depends -sub CXX gcc &&
depends tiff &&
depends ilmbase &&
depends JPEG &&
+depends jxrlib &&
depends libpng &&
depends libmng &&
depends libraw &&
diff --git a/graphics-libs/freeimage/DETAILS b/graphics-libs/freeimage/DETAILS
index 82181cc259..bd247c11ef 100755
--- a/graphics-libs/freeimage/DETAILS
+++ b/graphics-libs/freeimage/DETAILS
@@ -1,9 +1,9 @@
SPELL=freeimage
SPELLX=FreeImage
- VERSION=3170
- SECURITY_PATCH=1
- SOURCE_HASH=sha512:703c2626c0bcfe73eb40d720f45745208ca9650a7730759680a2b38ad3f6c719a43008477032bc70b76a95761f7d4b6f901b961359d36b54ace906dd78fb391b
- SOURCE=$SPELLX$VERSION.zip
+ VERSION=3.18.0
+ SECURITY_PATCH=2
+ SOURCE_HASH=sha512:9d9cc7e2d57552c3115e277aeb036e0455204d389026b17a3f513da5be1fd595421655488bb1ec2f76faebed66049119ca55e26e2a6d37024b3fb7ef36ad4818
+ SOURCE=$SPELLX${VERSION//.}.zip
SOURCE_DIRECTORY=$BUILD_DIRECTORY/$SPELLX
SOURCE_URL[0]=http://downloads.sourceforge.net/sourceforge/$SPELL/$SOURCE
WEB_SITE=http://$SPELL.SourceForge.net
diff --git a/graphics-libs/freeimage/Fix-CVE-2015-0852.patch b/graphics-libs/freeimage/Fix-CVE-2015-0852.patch
deleted file mode 100644
index f114bf8141..0000000000
--- a/graphics-libs/freeimage/Fix-CVE-2015-0852.patch
+++ /dev/null
@@ -1,127 +0,0 @@
-From: Debian QA Group <packages@qa.debian.org>
-Date: Fri, 6 Nov 2015 13:51:20 +0000
-Subject: Fix CVE-2015-0852
-
-CVE-2015-0852: multiple integer underflows in PluginPCX.cpp.
----
- Source/FreeImage/PluginPCX.cpp | 76 +++++++++++++++++++++++++++---------------
- 1 file changed, 50 insertions(+), 26 deletions(-)
-
-diff --git a/Source/FreeImage/PluginPCX.cpp b/Source/FreeImage/PluginPCX.cpp
-index cd75629..dcd9d61 100644
---- a/Source/FreeImage/PluginPCX.cpp
-+++ b/Source/FreeImage/PluginPCX.cpp
-@@ -347,12 +347,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
-
- try {
- // check PCX identifier
--
-- long start_pos = io->tell_proc(handle);
-- BOOL validated = pcx_validate(io, handle);
-- io->seek_proc(handle, start_pos, SEEK_SET);
-- if(!validated) {
-- throw FI_MSG_ERROR_MAGIC_NUMBER;
-+ // (note: should have been already validated using FreeImage_GetFileType but check again)
-+ {
-+ long start_pos = io->tell_proc(handle);
-+ BOOL validated = pcx_validate(io, handle);
-+ io->seek_proc(handle, start_pos, SEEK_SET);
-+ if(!validated) {
-+ throw FI_MSG_ERROR_MAGIC_NUMBER;
-+ }
- }
-
- // process the header
-@@ -366,20 +368,38 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
- SwapHeader(&header);
- #endif
-
-- // allocate a new DIB
-+ // process the window
-+ const WORD *window = header.window; // left, upper, right,lower pixel coord.
-+ const int left = window[0];
-+ const int top = window[1];
-+ const int right = window[2];
-+ const int bottom = window[3];
-+
-+ // check image size
-+ if((left >= right) || (top >= bottom)) {
-+ throw FI_MSG_ERROR_PARSING;
-+ }
-
-- unsigned width = header.window[2] - header.window[0] + 1;
-- unsigned height = header.window[3] - header.window[1] + 1;
-- unsigned bitcount = header.bpp * header.planes;
-+ const unsigned width = right - left + 1;
-+ const unsigned height = bottom - top + 1;
-+ const unsigned bitcount = header.bpp * header.planes;
-
-- if (bitcount == 24) {
-- dib = FreeImage_AllocateHeader(header_only, width, height, bitcount, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
-- } else {
-- dib = FreeImage_AllocateHeader(header_only, width, height, bitcount);
-+ // allocate a new DIB
-+ switch(bitcount) {
-+ case 1:
-+ case 4:
-+ case 8:
-+ dib = FreeImage_AllocateHeader(header_only, width, height, bitcount);
-+ break;
-+ case 24:
-+ dib = FreeImage_AllocateHeader(header_only, width, height, bitcount, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
-+ break;
-+ default:
-+ throw FI_MSG_ERROR_DIB_MEMORY;
-+ break;
- }
-
- // if the dib couldn't be allocated, throw an error
--
- if (!dib) {
- throw FI_MSG_ERROR_DIB_MEMORY;
- }
-@@ -426,19 +446,23 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
-
- if (palette_id == 0x0C) {
- BYTE *cmap = (BYTE*)malloc(768 * sizeof(BYTE));
-- io->read_proc(cmap, 768, 1, handle);
-
-- pal = FreeImage_GetPalette(dib);
-- BYTE *pColormap = &cmap[0];
-+ if(cmap) {
-+ io->read_proc(cmap, 768, 1, handle);
-
-- for(int i = 0; i < 256; i++) {
-- pal[i].rgbRed = pColormap[0];
-- pal[i].rgbGreen = pColormap[1];
-- pal[i].rgbBlue = pColormap[2];
-- pColormap += 3;
-+ pal = FreeImage_GetPalette(dib);
-+ BYTE *pColormap = &cmap[0];
-+
-+ for(int i = 0; i < 256; i++) {
-+ pal[i].rgbRed = pColormap[0];
-+ pal[i].rgbGreen = pColormap[1];
-+ pal[i].rgbBlue = pColormap[2];
-+ pColormap += 3;
-+ }
-+
-+ free(cmap);
- }
-
-- free(cmap);
- }
-
- // wrong palette ID, perhaps a gray scale is needed ?
-@@ -466,9 +490,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
- // calculate the line length for the PCX and the DIB
-
- // length of raster line in bytes
-- unsigned linelength = header.bytes_per_line * header.planes;
-+ const unsigned linelength = header.bytes_per_line * header.planes;
- // length of DIB line (rounded to DWORD) in bytes
-- unsigned pitch = FreeImage_GetPitch(dib);
-+ const unsigned pitch = FreeImage_GetPitch(dib);
-
- // run-length encoding ?
-
diff --git a/graphics-libs/freeimage/Fix-CVE-2016-5684.patch b/graphics-libs/freeimage/Fix-CVE-2016-5684.patch
deleted file mode 100644
index 9e260bea82..0000000000
--- a/graphics-libs/freeimage/Fix-CVE-2016-5684.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From: Debian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
-Date: Mon, 10 Oct 2016 08:22:44 +0100
-Subject: CVE-2016-5684
-
----
- Source/FreeImage/PluginXPM.cpp | 7 ++++++-
- 1 file changed, 6 insertions(+), 1 deletion(-)
-
-diff --git a/Source/FreeImage/PluginXPM.cpp b/Source/FreeImage/PluginXPM.cpp
-index a698321..cc7bd07 100644
---- a/Source/FreeImage/PluginXPM.cpp
-+++ b/Source/FreeImage/PluginXPM.cpp
-@@ -181,6 +181,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
- }
- free(str);
-
-+ // check info string
-+ if((width <= 0) || (height <= 0) || (colors <= 0) || (cpp <= 0)) {
-+ throw "Improperly formed info string";
-+ }
-+
- if (colors > 256) {
- dib = FreeImage_AllocateHeader(header_only, width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
- } else {
-@@ -193,7 +198,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
- FILE_RGBA rgba;
-
- str = ReadString(io, handle);
-- if(!str)
-+ if(!str || (strlen(str) < (size_t)cpp))
- throw "Error reading color strings";
-
- std::string chrs(str,cpp); //create a string for the color chars using the first cpp chars
diff --git a/graphics-libs/freeimage/HISTORY b/graphics-libs/freeimage/HISTORY
index 1bb62b7bc6..bbb542dd4a 100644
--- a/graphics-libs/freeimage/HISTORY
+++ b/graphics-libs/freeimage/HISTORY
@@ -1,3 +1,20 @@
+2021-09-07 Ismael Luceno <ismael@sourcemage.org>
+ * DETAILS: updated spell to 3.18.0
+ * DEPENDS: added jxrlib
+ * PRE_BUILD: unbundled dependencies
+ * PRE_BUILD, patches/0001-Disable-vendored-dependencies.patch,
+ patches/0002-Use-system-dependencies.patch,
+ patches/0003-Fix-macro-redefinition-for-64-bit-integer-types.patch,
+ patches/0004-Fix-compatibility-with-system-libpng.patch,
+ patches/0006-Disable-testing-of-JPEG-transform.patch,
+ patches/0007-Disable-testing-of-JXR-MemIO.patch,
+ patches/0009-Enable-substitution-of-pkg-config.patch,
+ patches/0010-CVE-2019-12211-13.patch,
+ patches/0011-Fix_compilation_external-static.patch,
+ patches/0012-Fix-libraw-compilation.patch: imported patches from Debian
+ * Fix-CVE-2016-5684.patch: removed, no longer needed
+ * Fix-CVE-2015-0852.patch: removed, no longer needed
+
2019-07-08 Eric Sandall <sandalle@sourcemage.org>
* Set 64-bit for EM64T as well.
Sorcery devel (from git), glibc, gcc, or updated smgl-archspecs changed
diff --git a/graphics-libs/freeimage/PRE_BUILD b/graphics-libs/freeimage/PRE_BUILD
index 91b9340a33..624744f0d3 100755
--- a/graphics-libs/freeimage/PRE_BUILD
+++ b/graphics-libs/freeimage/PRE_BUILD
@@ -1,18 +1,23 @@
default_pre_build &&
-cd "${SOURCE_DIRECTORY}/Source" &&
-rm -rf LibPNG LibMNG LibOpenJPEG ZLib OpenEXR LibRawLite LibTIFF4 LibJPEG &&
-cd "${SOURCE_DIRECTORY}" &&
-sed -i 's/\r$//m' Makefile.{gnu,fip,srcs} fipMakefile.srcs */*.h */*/*.cpp &&
-sed -i \
- -e "/LibJPEG/d" \
- -e "/LibPNG/d" \
- -e "/LibTIFF/d" \
- -e "/Source\/ZLib/d" \
- -e "/LibOpenJPEG/d" \
- -e "/OpenEXR/d" \
- -e "/LibRawLite/d" \
- -e "/LibMNG/d" \
- Makefile.srcs fipMakefile.srcs &&
-
-patch -p1 < "$SPELL_DIRECTORY/Fix-CVE-2015-0852.patch" &&
-patch -p1 < "$SPELL_DIRECTORY/Fix-CVE-2016-5684.patch"
+cd "$SOURCE_DIRECTORY" &&
+# Remove bundled libraries
+rm -rf \
+ Source/LibJPEG \
+ Source/LibMNG \
+ Source/LibOpenJPEG \
+ Source/LibPNG \
+ Source/LibRawLite \
+ Source/LibTIFF4 \
+ Source/LibWebP \
+ Source/OpenEXR \
+ Source/ZLib &&
+sed -E -i '
+ /^SRCS =/ {
+ s@ ([.]/)?Source/(OpenEXR|Z?Lib)[^ ]*@@g
+ s@ [.]/Source/FreeImageToolkit/JPEGTransform[.]cpp@@
+ }
+ /^INCLUDE =/ {
+ s@ -I([.]/)?Source/(OpenEXR|Z?Lib)[^ ]*@@g
+ }
+' {,fip}Makefile.srcs &&
+apply_patch_dir patches
diff --git a/graphics-libs/freeimage/patches/0001-Disable-vendored-dependencies.patch b/graphics-libs/freeimage/patches/0001-Disable-vendored-dependencies.patch
new file mode 100644
index 0000000000..15c69c3761
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0001-Disable-vendored-dependencies.patch
@@ -0,0 +1,396 @@
+From: Ghislain Antony Vaillant <ghisvail@gmail.com>
+Date: Tue, 3 Nov 2015 14:39:33 +0000
+Subject: Disable vendored dependencies
+
+This commit disables usage of the embedded dependencies for building
+FreeImage and FreeImagePlus. Functionalities which could not use the
+packaged dependencies are delibarately disabled for security reasons.
+
+This patch is based on Fedora's FreeImage-3.17.0_unbundle patch.
+
+Origin: Debian, Fedora
+[ismael@iodev.co.uk: Adapted for Source Mage]
+---
+ Source/FreeImage.h | 8 +++++++-
+ Source/FreeImage/J2KHelper.cpp | 2 +-
+ Source/FreeImage/PluginEXR.cpp | 20 ++++++++++----------
+ Source/FreeImage/PluginG3.cpp | 6 +++---
+ Source/FreeImage/PluginJ2K.cpp | 2 +-
+ Source/FreeImage/PluginJP2.cpp | 2 +-
+ Source/FreeImage/PluginJPEG.cpp | 6 +++---
+ Source/FreeImage/PluginJXR.cpp | 2 +-
+ Source/FreeImage/PluginPNG.cpp | 4 ++--
+ Source/FreeImage/PluginRAW.cpp | 2 +-
+ Source/FreeImage/PluginTIFF.cpp | 4 ++--
+ Source/FreeImage/PluginWebP.cpp | 6 +++---
+ Source/FreeImage/ZLibInterface.cpp | 5 ++---
+ Source/Metadata/XTIFF.cpp | 7 ++++++-
+ 14 files changed, 43 insertions(+), 33 deletions(-)
+
+--- a/Source/FreeImage.h
++++ b/Source/FreeImage.h
+@@ -473,6 +473,8 @@ FI_ENUM(FREE_IMAGE_DITHER) {
+ FID_BAYER16x16 = 6 //! Bayer ordered dispersed dot dithering (order 4 dithering matrix)
+ };
+
++/* Disable JPEGTransform functions; they require the vendored copy of libjpeg */
++#if 0
+ /** Lossless JPEG transformations
+ Constants used in FreeImage_JPEGTransform
+ */
+@@ -486,6 +488,7 @@ FI_ENUM(FREE_IMAGE_JPEG_OPERATION) {
+ FIJPEG_OP_ROTATE_180 = 6, //! 180-degree rotation
+ FIJPEG_OP_ROTATE_270 = 7 //! 270-degree clockwise (or 90 ccw)
+ };
++#endif
+
+ /** Tone mapping operators.
+ Constants used in FreeImage_ToneMapping.
+@@ -1088,6 +1092,8 @@ DLL_API const char* DLL_CALLCONV FreeIma
+ // JPEG lossless transformation routines
+ // --------------------------------------------------------------------------
+
++/* Disable JPEGTransform functions; they require the vendored copy of libjpeg */
++#if 0
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransform(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(TRUE));
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(TRUE));
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCrop(const char *src_file, const char *dst_file, int left, int top, int right, int bottom);
+@@ -1097,6 +1102,7 @@ DLL_API BOOL DLL_CALLCONV FreeImage_JPEG
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombined(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombinedU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
+ DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombinedFromMemory(FIMEMORY* src_stream, FIMEMORY* dst_stream, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
++#endif
+
+
+ // --------------------------------------------------------------------------
+--- a/Source/FreeImage/J2KHelper.cpp
++++ b/Source/FreeImage/J2KHelper.cpp
+@@ -21,7 +21,7 @@
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+-#include "../LibOpenJPEG/openjpeg.h"
++#include <openjpeg.h>
+ #include "J2KHelper.h"
+
+ // --------------------------------------------------------------------------
+--- a/Source/FreeImage/PluginEXR.cpp
++++ b/Source/FreeImage/PluginEXR.cpp
+@@ -28,16 +28,16 @@
+ #pragma warning (disable : 4800) // ImfVersion.h - 'const int' : forcing value to bool 'true' or 'false' (performance warning)
+ #endif
+
+-#include "../OpenEXR/IlmImf/ImfIO.h"
+-#include "../OpenEXR/Iex/Iex.h"
+-#include "../OpenEXR/IlmImf/ImfOutputFile.h"
+-#include "../OpenEXR/IlmImf/ImfInputFile.h"
+-#include "../OpenEXR/IlmImf/ImfRgbaFile.h"
+-#include "../OpenEXR/IlmImf/ImfChannelList.h"
+-#include "../OpenEXR/IlmImf/ImfRgba.h"
+-#include "../OpenEXR/IlmImf/ImfArray.h"
+-#include "../OpenEXR/IlmImf/ImfPreviewImage.h"
+-#include "../OpenEXR/Half/half.h"
++#include <OpenEXR/ImfIO.h>
++#include <OpenEXR/Iex.h>
++#include <OpenEXR/ImfOutputFile.h>
++#include <OpenEXR/ImfInputFile.h>
++#include <OpenEXR/ImfRgbaFile.h>
++#include <OpenEXR/ImfChannelList.h>
++#include <OpenEXR/ImfRgba.h>
++#include <OpenEXR/ImfArray.h>
++#include <OpenEXR/ImfPreviewImage.h>
++#include <Imath/half.h>
+
+
+ // ==========================================================
+--- a/Source/FreeImage/PluginG3.cpp
++++ b/Source/FreeImage/PluginG3.cpp
+@@ -20,7 +20,6 @@
+ // Use at your own risk!
+ // ==========================================================
+
+-#include "../LibTIFF4/tiffiop.h"
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+@@ -31,6 +29,7 @@
+
+ static int s_format_id;
+
++#if 0
+ // ==========================================================
+ // Constant/Macro declarations
+ // ==========================================================
+@@ -192,6 +191,7 @@ copyFaxFile(FreeImageIO *io, fi_handle h
+
+ return (row);
+ }
++#endif
+
+
+ // ==========================================================
+@@ -229,6 +231,7 @@ SupportsExportDepth(int depth) {
+
+ // ----------------------------------------------------------
+
++#if 0
+ static FIBITMAP * DLL_CALLCONV
+ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
+ TIFF *faxTIFF = NULL;
+@@ -406,6 +406,7 @@ Load(FreeImageIO *io, fi_handle handle,
+ return dib;
+
+ }
++#endif
+
+ // ==========================================================
+ // Init
+@@ -423,7 +424,7 @@ InitG3(Plugin *plugin, int format_id) {
+ plugin->close_proc = NULL;
+ plugin->pagecount_proc = NULL;
+ plugin->pagecapability_proc = NULL;
+- plugin->load_proc = Load;
++ plugin->load_proc = NULL;
+ plugin->save_proc = NULL;
+ plugin->validate_proc = NULL;
+ plugin->mime_proc = MimeType;
+--- a/Source/FreeImage/PluginJ2K.cpp
++++ b/Source/FreeImage/PluginJ2K.cpp
+@@ -21,7 +21,7 @@
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+-#include "../LibOpenJPEG/openjpeg.h"
++#include <openjpeg.h>
+ #include "J2KHelper.h"
+
+ // ==========================================================
+--- a/Source/FreeImage/PluginJP2.cpp
++++ b/Source/FreeImage/PluginJP2.cpp
+@@ -21,7 +21,7 @@
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+-#include "../LibOpenJPEG/openjpeg.h"
++#include <openjpeg.h>
+ #include "J2KHelper.h"
+
+ // ==========================================================
+--- a/Source/FreeImage/PluginJPEG.cpp
++++ b/Source/FreeImage/PluginJPEG.cpp
+@@ -35,9 +35,9 @@ extern "C" {
+ #undef FAR
+ #include <setjmp.h>
+
+-#include "../LibJPEG/jinclude.h"
+-#include "../LibJPEG/jpeglib.h"
+-#include "../LibJPEG/jerror.h"
++#include <stdio.h>
++#include <jpeglib.h>
++#include <jerror.h>
+ }
+
+ #include "FreeImage.h"
+--- a/Source/FreeImage/PluginJXR.cpp
++++ b/Source/FreeImage/PluginJXR.cpp
+@@ -23,7 +23,7 @@
+ #include "Utilities.h"
+ #include "../Metadata/FreeImageTag.h"
+
+-#include "../LibJXR/jxrgluelib/JXRGlue.h"
++#include <JXRGlue.h>
+
+ // ==========================================================
+ // Plugin Interface
+--- a/Source/FreeImage/PluginPNG.cpp
++++ b/Source/FreeImage/PluginPNG.cpp
+@@ -40,8 +40,8 @@
+
+ // ----------------------------------------------------------
+
+-#include "../ZLib/zlib.h"
+-#include "../LibPNG/png.h"
++#include <zlib.h>
++#include <png.h>
+
+ // ----------------------------------------------------------
+
+--- a/Source/FreeImage/PluginRAW.cpp
++++ b/Source/FreeImage/PluginRAW.cpp
+@@ -19,7 +19,7 @@
+ // Use at your own risk!
+ // ==========================================================
+
+-#include "../LibRawLite/libraw/libraw.h"
++#include <libraw/libraw.h>
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+--- a/Source/FreeImage/ZLibInterface.cpp
++++ b/Source/FreeImage/ZLibInterface.cpp
+@@ -19,10 +19,9 @@
+ // Use at your own risk!
+ // ==========================================================
+
+-#include "../ZLib/zlib.h"
++#include <zlib.h>
+ #include "FreeImage.h"
+ #include "Utilities.h"
+-#include "../ZLib/zutil.h" /* must be the last header because of error C3163 in VS2008 (_vsnprintf defined in stdio.h) */
+
+ /**
+ Compresses a source buffer into a target buffer, using the ZLib library.
+@@ -115,7 +114,7 @@ FreeImage_ZLibGZip(BYTE *target, DWORD t
+ return 0;
+ case Z_OK: {
+ // patch header, setup crc and length (stolen from mod_trace_output)
+- BYTE *p = target + 8; *p++ = 2; *p = OS_CODE; // xflags, os_code
++ BYTE *p = target + 8; *p++ = 2; *p = 3; // xflags, os_code (unix)
+ crc = crc32(crc, source, source_size);
+ memcpy(target + 4 + dest_len, &crc, 4);
+ memcpy(target + 8 + dest_len, &source_size, 4);
+--- a/Source/Metadata/XTIFF.cpp
++++ b/Source/Metadata/XTIFF.cpp
+@@ -29,13 +29,17 @@
+ #pragma warning (disable : 4786) // identifier was truncated to 'number' characters
+ #endif
+
+-#include "../LibTIFF4/tiffiop.h"
++#include <tiffio.h>
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+ #include "FreeImageTag.h"
+ #include "FIRational.h"
+
++extern "C" {
++ int _TIFFDataSize(TIFFDataType type);
++}
++
+ // ----------------------------------------------------------
+ // Extended TIFF Directory GEO Tag Support
+ // ----------------------------------------------------------
+@@ -224,6 +229,33 @@ tiff_write_geotiff_profile(TIFF *tif, FI
+ // TIFF EXIF tag reading & writing
+ // ----------------------------------------------------------
+
++static uint32 exif_tag_ids[] = {
++ EXIFTAG_EXPOSURETIME, EXIFTAG_FNUMBER, EXIFTAG_EXPOSUREPROGRAM,
++ EXIFTAG_SPECTRALSENSITIVITY, EXIFTAG_ISOSPEEDRATINGS, EXIFTAG_OECF,
++ EXIFTAG_EXIFVERSION, EXIFTAG_DATETIMEORIGINAL, EXIFTAG_DATETIMEDIGITIZED,
++ EXIFTAG_COMPONENTSCONFIGURATION, EXIFTAG_COMPRESSEDBITSPERPIXEL,
++ EXIFTAG_SHUTTERSPEEDVALUE, EXIFTAG_APERTUREVALUE,
++ EXIFTAG_BRIGHTNESSVALUE, EXIFTAG_EXPOSUREBIASVALUE,
++ EXIFTAG_MAXAPERTUREVALUE, EXIFTAG_SUBJECTDISTANCE, EXIFTAG_METERINGMODE,
++ EXIFTAG_LIGHTSOURCE, EXIFTAG_FLASH, EXIFTAG_FOCALLENGTH,
++ EXIFTAG_SUBJECTAREA, EXIFTAG_MAKERNOTE, EXIFTAG_USERCOMMENT,
++ EXIFTAG_SUBSECTIME, EXIFTAG_SUBSECTIMEORIGINAL,
++ EXIFTAG_SUBSECTIMEDIGITIZED, EXIFTAG_FLASHPIXVERSION, EXIFTAG_COLORSPACE,
++ EXIFTAG_PIXELXDIMENSION, EXIFTAG_PIXELYDIMENSION,
++ EXIFTAG_RELATEDSOUNDFILE, EXIFTAG_FLASHENERGY,
++ EXIFTAG_SPATIALFREQUENCYRESPONSE, EXIFTAG_FOCALPLANEXRESOLUTION,
++ EXIFTAG_FOCALPLANEYRESOLUTION, EXIFTAG_FOCALPLANERESOLUTIONUNIT,
++ EXIFTAG_SUBJECTLOCATION, EXIFTAG_EXPOSUREINDEX, EXIFTAG_SENSINGMETHOD,
++ EXIFTAG_FILESOURCE, EXIFTAG_SCENETYPE, EXIFTAG_CFAPATTERN,
++ EXIFTAG_CUSTOMRENDERED, EXIFTAG_EXPOSUREMODE, EXIFTAG_WHITEBALANCE,
++ EXIFTAG_DIGITALZOOMRATIO, EXIFTAG_FOCALLENGTHIN35MMFILM,
++ EXIFTAG_SCENECAPTURETYPE, EXIFTAG_GAINCONTROL, EXIFTAG_CONTRAST,
++ EXIFTAG_SATURATION, EXIFTAG_SHARPNESS, EXIFTAG_DEVICESETTINGDESCRIPTION,
++ EXIFTAG_SUBJECTDISTANCERANGE, EXIFTAG_GAINCONTROL, EXIFTAG_GAINCONTROL,
++ EXIFTAG_IMAGEUNIQUEID
++};
++static int nExifTags = sizeof(exif_tag_ids) / sizeof(exif_tag_ids[0]);
++
+ /**
+ Read a single Exif tag
+
+@@ -575,43 +607,10 @@ tiff_read_exif_tags(TIFF *tif, TagLib::M
+
+ // loop over all Core Directory Tags
+ // ### uses private data, but there is no other way
++ // -> Fedora: Best we can do without private headers is to hard-code a list of known EXIF tags and read those
+ if(md_model == TagLib::EXIF_MAIN) {
+- const TIFFDirectory *td = &tif->tif_dir;
+-
+- uint32 lastTag = 0; //<- used to prevent reading some tags twice (as stored in tif_fieldinfo)
+-
+- for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) {
+- const TIFFField *fld = tif->tif_fields[fi];
+-
+- const uint32 tag_id = TIFFFieldTag(fld);
+-
+- if(tag_id == lastTag) {
+- continue;
+- }
+-
+- // test if tag value is set
+- // (lifted directly from LibTiff _TIFFWriteDirectory)
+-
+- if( fld->field_bit == FIELD_CUSTOM ) {
+- int is_set = FALSE;
+-
+- for(int ci = 0; ci < td->td_customValueCount; ci++ ) {
+- is_set |= (td->td_customValues[ci].info == fld);
+- }
+-
+- if( !is_set ) {
+- continue;
+- }
+-
+- } else if(!TIFFFieldSet(tif, fld->field_bit)) {
+- continue;
+- }
+-
+- // process *all* other tags (some will be ignored)
+-
+- tiff_read_exif_tag(tif, tag_id, dib, md_model);
+-
+- lastTag = tag_id;
++ for (int i = 0; i < nExifTags; ++i) {
++ tiff_read_exif_tag(tif, exif_tag_ids[i], dib, md_model);
+ }
+
+ }
+@@ -723,10 +722,9 @@ tiff_write_exif_tags(TIFF *tif, TagLib::
+
+ TagLib& tag_lib = TagLib::instance();
+
+- for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) {
+- const TIFFField *fld = tif->tif_fields[fi];
+-
+- const uint32 tag_id = TIFFFieldTag(fld);
++ for (int fi = 0, nfi = nExifTags; nfi > 0; nfi--, fi++) {
++ const uint32 tag_id = exif_tag_ids[fi];
++ const TIFFField *fld = TIFFFieldWithTag(tif, tag_id);
+
+ if(skip_write_field(tif, tag_id)) {
+ // skip tags that are already handled by the LibTIFF writing process
+--- a/Source/FreeImage/PluginTIFF.cpp
++++ b/Source/FreeImage/PluginTIFF.cpp
+@@ -37,9 +37,9 @@
+
+ #include "FreeImage.h"
+ #include "Utilities.h"
+-#include "../LibTIFF4/tiffiop.h"
++#include <tiffio.h>
+ #include "../Metadata/FreeImageTag.h"
+-#include "../OpenEXR/Half/half.h"
++#include "Imath/half.h"
+
+ #include "FreeImageIO.h"
+ #include "PSDParser.h"
+--- a/Source/FreeImage/PluginWebP.cpp
++++ b/Source/FreeImage/PluginWebP.cpp
+@@ -24,9 +24,9 @@
+
+ #include "../Metadata/FreeImageTag.h"
+
+-#include "../LibWebP/src/webp/decode.h"
+-#include "../LibWebP/src/webp/encode.h"
+-#include "../LibWebP/src/webp/mux.h"
++#include "webp/decode.h"
++#include "webp/encode.h"
++#include "webp/mux.h"
+
+ // ==========================================================
+ // Plugin Interface
diff --git a/graphics-libs/freeimage/patches/0002-Use-system-dependencies.patch b/graphics-libs/freeimage/patches/0002-Use-system-dependencies.patch
new file mode 100644
index 0000000000..59a0547dec
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0002-Use-system-dependencies.patch
@@ -0,0 +1,189 @@
+From: Ghislain Antony Vaillant <ghisvail@gmail.com>
+Date: Thu, 5 Nov 2015 22:47:13 +0000
+Subject: Use system dependencies.
+
+This commit patches the build system to use the packaged dependencies
+for building FreeImage and FreeImagePlus. This patch also modifies some
+targets in the corresponding Makefiles to help with the package build process.
+
+Origin: Debian
+[ismael@iodev.co.uk: Merged with PKG_CONFIG var patch]
+---
+ Makefile.fip | 45 +++++++++++++++++----------------------------
+ Makefile.gnu | 41 ++++++++++++++++++++---------------------
+ 2 files changed, 37 insertions(+), 49 deletions(-)
+
+diff --git a/Makefile.fip b/Makefile.fip
+index b59c419..98733cf 100644
+--- a/Makefile.fip
++++ b/Makefile.fip
+@@ -11,27 +11,17 @@ INSTALLDIR ?= $(DESTDIR)/usr/lib
+ # Converts cr/lf to just lf
+ DOS2UNIX = dos2unix
+
+-LIBRARIES = -lstdc++
++PKG_CONFIG ?= pkg-config
++LIBRARIES = -lstdc++ -ljxrglue $(shell ${PKG_CONFIG} --libs libjpeg libopenjp2 libpng libraw libtiff-4 libwebpmux OpenEXR zlib) -lm
+
+ MODULES = $(SRCS:.c=.o)
+ MODULES := $(MODULES:.cpp=.o)
+-CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden
+-# OpenJPEG
+-CFLAGS += -DOPJ_STATIC
+-# LibRaw
+-CFLAGS += -DNO_LCMS
+-# LibJXR
+-CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
+-CFLAGS += $(INCLUDE)
+-CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
+-# LibJXR
+-CXXFLAGS += -D__ANSI__
+-CXXFLAGS += $(INCLUDE)
+-
+-ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64)
+- CFLAGS += -fPIC
+- CXXFLAGS += -fPIC
+-endif
++CFLAGS ?= -O3 -fPIC
++override CFLAGS += -fexceptions -fvisibility=hidden
++override CFLAGS += $(INCLUDE) -IDist
++CXXFLAGS ?= -O3 -fPIC
++override CXXFLAGS += -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
++override CXXFLAGS += $(INCLUDE) -IDist
+
+ TARGET = freeimageplus
+ STATICLIB = lib$(TARGET).a
+@@ -48,31 +37,31 @@ all: dist
+
+ dist: FreeImage
+ mkdir -p Dist
+- cp *.a Dist/
+- cp *.so Dist/
+- cp Source/FreeImage.h Dist/
+- cp Wrapper/FreeImagePlus/FreeImagePlus.h Dist/
++ cp $(STATICLIB) Dist/
++ cp $(SHAREDLIB) Dist/
++ cp $(HEADERFIP) Dist/
++ ln -sf $(SHAREDLIB) Dist/$(VERLIBNAME)
++ ln -sf $(VERLIBNAME) Dist/$(LIBNAME)
+
+ dos2unix:
+- @$(DOS2UNIX) $(SRCS)
++ @$(DOS2UNIX) $(SRCS) $(HEADERFIP)
+
+ FreeImage: $(STATICLIB) $(SHAREDLIB)
+
+ .c.o:
+- $(CC) $(CFLAGS) -c $< -o $@
++ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+ .cpp.o:
+- $(CXX) $(CXXFLAGS) -c $< -o $@
++ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
+
+ $(STATICLIB): $(MODULES)
+ $(AR) r $@ $(MODULES)
+
+ $(SHAREDLIB): $(MODULES)
+- $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
++ $(CC) -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
+
+ install:
+ install -d $(INCDIR) $(INSTALLDIR)
+- install -m 644 -o root -g root $(HEADER) $(INCDIR)
+ install -m 644 -o root -g root $(HEADERFIP) $(INCDIR)
+ install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR)
+ install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR)
+@@ -80,5 +69,5 @@ install:
+ ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME)
+
+ clean:
+- rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
++ rm -f Dist/lib$(TARGET)* Dist/FreeImagePlus.h $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
+
+diff --git a/Makefile.gnu b/Makefile.gnu
+index 92f6358..4e61efa 100644
+--- a/Makefile.gnu
++++ b/Makefile.gnu
+@@ -11,27 +11,25 @@ INSTALLDIR ?= $(DESTDIR)/usr/lib
+ # Converts cr/lf to just lf
+ DOS2UNIX = dos2unix
+
+-LIBRARIES = -lstdc++
++PKG_CONFIG ?= pkg-config
++LIBRARIES := -lstdc++ -ljxrglue $(shell ${PKG_CONFIG} --libs libjpeg libopenjp2 libpng libraw libtiff-4 libwebpmux OpenEXR zlib) -lm
+
+ MODULES = $(SRCS:.c=.o)
+ MODULES := $(MODULES:.cpp=.o)
+-CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden
++CFLAGS ?= -O3 -fPIC
++override CFLAGS += -fexceptions -fvisibility=hidden
+ # OpenJPEG
+-CFLAGS += -DOPJ_STATIC
++override CFLAGS += -DOPJ_STATIC
+ # LibRaw
+-CFLAGS += -DNO_LCMS
++override CFLAGS += -DNO_LCMS
+ # LibJXR
+-CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
+-CFLAGS += $(INCLUDE)
+-CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
++override CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
++override CFLAGS += $(INCLUDE) -I/usr/include/jxrlib $(shell ${PKG_CONFIG} --cflags libjpeg libopenjp2 libpng libraw libtiff-4 libwebpmux OpenEXR zlib)
++CXXFLAGS ?= -O3 -fPIC
++override CXXFLAGS += -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
+ # LibJXR
+-CXXFLAGS += -D__ANSI__
+-CXXFLAGS += $(INCLUDE)
+-
+-ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64)
+- CFLAGS += -fPIC
+- CXXFLAGS += -fPIC
+-endif
++override CXXFLAGS += -D__ANSI__
++override CXXFLAGS += $(INCLUDE) -I/usr/include/jxrlib $(shell ${PKG_CONFIG} --cflags libjpeg libopenjp2 libpng libraw libtiff-4 libwebpmux OpenEXR zlib)
+
+ TARGET = freeimage
+ STATICLIB = lib$(TARGET).a
+@@ -48,9 +45,11 @@ all: dist
+
+ dist: FreeImage
+ mkdir -p Dist
+- cp *.a Dist/
+- cp *.so Dist/
+- cp Source/FreeImage.h Dist/
++ cp $(STATICLIB) Dist/
++ cp $(SHAREDLIB) Dist/
++ cp $(HEADER) Dist/
++ ln -sf $(SHAREDLIB) Dist/$(VERLIBNAME)
++ ln -sf $(VERLIBNAME) Dist/$(LIBNAME)
+
+ dos2unix:
+ @$(DOS2UNIX) $(SRCS) $(INCLS)
+@@ -58,16 +57,16 @@ dos2unix:
+ FreeImage: $(STATICLIB) $(SHAREDLIB)
+
+ .c.o:
+- $(CC) $(CFLAGS) -c $< -o $@
++ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
+
+ .cpp.o:
+- $(CXX) $(CXXFLAGS) -c $< -o $@
++ $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
+
+ $(STATICLIB): $(MODULES)
+ $(AR) r $@ $(MODULES)
+
+ $(SHAREDLIB): $(MODULES)
+- $(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
++ $(CC) -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
+
+ install:
+ install -d $(INCDIR) $(INSTALLDIR)
+@@ -79,5 +78,5 @@ install:
+ # ldconfig
+
+ clean:
+- rm -f core Dist/*.* u2dtmp* $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
++ rm -f Dist/lib$(TARGET)* Dist/FreeImage.h $(MODULES) $(STATICLIB) $(SHAREDLIB) $(LIBNAME)
+
diff --git a/graphics-libs/freeimage/patches/0003-Fix-macro-redefinition-for-64-bit-integer-types.patch b/graphics-libs/freeimage/patches/0003-Fix-macro-redefinition-for-64-bit-integer-types.patch
new file mode 100644
index 0000000000..d4011ad92f
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0003-Fix-macro-redefinition-for-64-bit-integer-types.patch
@@ -0,0 +1,27 @@
+From: Debian QA Group <packages@qa.debian.org>
+Date: Fri, 6 Nov 2015 13:51:20 +0000
+Subject: Fix macro redefinition for 64-bit integer types.
+
+Both FreeImage and LibRAW defines INT64 and UINT64 aliases in their respective
+public headers via macros. This commit guards against macro redefinitions for
+these types inside the FreeImage.h public header.
+
+Origin: Debian
+
+---
+ Source/FreeImage.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- FreeImage.orig/Source/FreeImage.h
++++ FreeImage/Source/FreeImage.h
+@@ -155,8 +155,10 @@ typedef uint8_t BYTE;
+ typedef uint16_t WORD;
+ typedef uint32_t DWORD;
+ typedef int32_t LONG;
++#ifndef _LIBRAW_TYPES_H
+ typedef int64_t INT64;
+ typedef uint64_t UINT64;
++#endif
+ #else
+ // MS is not C99 ISO compliant
+ typedef long BOOL;
diff --git a/graphics-libs/freeimage/patches/0004-Fix-compatibility-with-system-libpng.patch b/graphics-libs/freeimage/patches/0004-Fix-compatibility-with-system-libpng.patch
new file mode 100644
index 0000000000..74426a2a87
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0004-Fix-compatibility-with-system-libpng.patch
@@ -0,0 +1,102 @@
+From: Ghislain Antony Vaillant <ghisvail@gmail.com>
+Date: Tue, 3 Nov 2015 15:20:45 +0000
+Subject: Fix compatibility with system libpng.
+
+[Ghislain Antony Vaillant]
+The PNG plugin of FreeImage makes use of optional features of libpng, which
+are not enabled in Debian. This commit adds the necessary guards for FreeImage
+to compile and run without these features.
+
+[Tobias Frost]
+Fix FTBFS with libpng 1.6.
+
+Origin: Debian
+
+---
+ Source/FreeImage/PluginPNG.cpp | 35 ++++++++++++++++++++++++++++-------
+ 1 file changed, 28 insertions(+), 7 deletions(-)
+
+Index: FreeImage/Source/FreeImage/PluginPNG.cpp
+===================================================================
+--- FreeImage.orig/Source/FreeImage/PluginPNG.cpp
++++ FreeImage/Source/FreeImage/PluginPNG.cpp
+@@ -115,9 +115,11 @@ ReadMetadata(png_structp png_ptr, png_in
+ // create a tag
+ tag = FreeImage_CreateTag();
+ if(!tag) return FALSE;
+-
++#ifdef PNG_iTXt_SUPPORTED
+ DWORD tag_length = (DWORD) MAX(text_ptr[i].text_length, text_ptr[i].itxt_length);
+-
++#else
++ DWORD tag_length = text_ptr[i].text_length;
++#endif
+ FreeImage_SetTagLength(tag, tag_length);
+ FreeImage_SetTagCount(tag, tag_length);
+ FreeImage_SetTagType(tag, FIDT_ASCII);
+@@ -185,14 +187,19 @@ WriteMetadata(png_structp png_ptr, png_i
+ if(mdhandle) {
+ do {
+ memset(&text_metadata, 0, sizeof(png_text));
++#ifdef PNG_iTXt_SUPPORTED
+ text_metadata.compression = 1; // iTXt, none
++#else
++ text_metadata.compression = -1;
++#endif
+ text_metadata.key = (char*)FreeImage_GetTagKey(tag); // keyword, 1-79 character description of "text"
+ text_metadata.text = (char*)FreeImage_GetTagValue(tag); // comment, may be an empty string (ie "")
+ text_metadata.text_length = FreeImage_GetTagLength(tag);// length of the text string
++#ifdef PNG_iTXt_SUPPORTED
+ text_metadata.itxt_length = FreeImage_GetTagLength(tag);// length of the itxt string
+ text_metadata.lang = 0; // language code, 0-79 characters or a NULL pointer
+ text_metadata.lang_key = 0; // keyword translated UTF-8 string, 0 or more chars or a NULL pointer
+-
++#endif
+ // set the tag
+ png_set_text(png_ptr, info_ptr, &text_metadata, 1);
+
+@@ -211,10 +218,11 @@ WriteMetadata(png_structp png_ptr, png_i
+ text_metadata.key = (char*)g_png_xmp_keyword; // keyword, 1-79 character description of "text"
+ text_metadata.text = (char*)FreeImage_GetTagValue(tag); // comment, may be an empty string (ie "")
+ text_metadata.text_length = FreeImage_GetTagLength(tag);// length of the text string
++#ifdef PNG_iTXt_SUPPORTED
+ text_metadata.itxt_length = FreeImage_GetTagLength(tag);// length of the itxt string
+ text_metadata.lang = 0; // language code, 0-79 characters or a NULL pointer
+ text_metadata.lang_key = 0; // keyword translated UTF-8 string, 0 or more chars or a NULL pointer
+-
++#endif
+ // set the tag
+ png_set_text(png_ptr, info_ptr, &text_metadata, 1);
+ bResult &= TRUE;
+@@ -707,11 +715,19 @@ Load(FreeImageIO *io, fi_handle handle,
+
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_iCCP)) {
+ png_charp profile_name = NULL;
+- png_bytep profile_data = NULL;
++#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
++ png_bytepp profile_data = NULL;
++#else
++ png_charp profile_data = NULL;
++#endif
+ png_uint_32 profile_length = 0;
+ int compression_type;
+
++#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
++ png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, profile_data, &profile_length);
++#else
+ png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &profile_data, &profile_length);
++#endif
+
+ // copy ICC profile data (must be done after FreeImage_AllocateHeader)
+
+@@ -746,8 +762,9 @@ Load(FreeImageIO *io, fi_handle handle,
+ for (png_uint_32 k = 0; k < height; k++) {
+ row_pointers[height - 1 - k] = FreeImage_GetScanLine(dib, k);
+ }
+-
++#ifdef PNG_BENIGN_ERRORS_SUPPORTED
+ png_set_benign_errors(png_ptr, 1);
++#endif
+ png_read_image(png_ptr, row_pointers);
+
+ // check if the bitmap contains transparency, if so enable it in the header
diff --git a/graphics-libs/freeimage/patches/0006-Disable-testing-of-JPEG-transform.patch b/graphics-libs/freeimage/patches/0006-Disable-testing-of-JPEG-transform.patch
new file mode 100644
index 0000000000..c34c63a56a
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0006-Disable-testing-of-JPEG-transform.patch
@@ -0,0 +1,45 @@
+From: Ghislain Antony Vaillant <ghisvail@gmail.com>
+Date: Tue, 3 Nov 2015 18:15:18 +0000
+Subject: Disable testing of JPEG transform.
+
+Reason: the JPEG transform features are disabled from the Debian build as a
+result of the stripping of the vendored dependencies.
+
+Origin: Debian
+
+---
+ TestAPI/testJPEG.cpp | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+Index: FreeImage/TestAPI/testJPEG.cpp
+===================================================================
+--- FreeImage.orig/TestAPI/testJPEG.cpp
++++ FreeImage/TestAPI/testJPEG.cpp
+@@ -25,6 +25,7 @@
+ // Local test functions
+ // ----------------------------------------------------------
+
++#if 0
+ void testJPEGTransform(const char *src_file) {
+ BOOL bResult;
+ BOOL perfect;
+@@ -193,11 +194,13 @@ void testJPEGSameFile(const char *src_fi
+ bResult = FreeImage_JPEGTransform("test.jpg", "test.jpg", FIJPEG_OP_ROTATE_270, perfect);
+ assert(bResult);
+ }
++#endif
+
+ // Main test function
+ // ----------------------------------------------------------
+
+ void testJPEG() {
++#if 0
+ const char *src_file = "exif.jpg";
+
+ printf("testJPEG (should throw exceptions) ...\n");
+@@ -213,4 +216,5 @@ void testJPEG() {
+
+ // using the same file for src & dst is allowed
+ testJPEGSameFile(src_file);
++#endif
+ }
diff --git a/graphics-libs/freeimage/patches/0007-Disable-testing-of-JXR-MemIO.patch b/graphics-libs/freeimage/patches/0007-Disable-testing-of-JXR-MemIO.patch
new file mode 100644
index 0000000000..a8cf0cc68e
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0007-Disable-testing-of-JXR-MemIO.patch
@@ -0,0 +1,27 @@
+From: Ghislain Antony Vaillant <ghisvail@gmail.com>
+Date: Thu, 5 Nov 2015 23:47:23 +0000
+Subject: Disable testing of JXR MemIO.
+
+Reason: The JXR MemIO test raises an assertion error, whose origin is unknown
+and needs to be assessed with upstream. Meanwhile the failing test should be
+temporarily disabled.
+
+Origin: Debian
+
+---
+ TestAPI/MainTestSuite.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+Index: FreeImage/TestAPI/MainTestSuite.cpp
+===================================================================
+--- FreeImage.orig/TestAPI/MainTestSuite.cpp
++++ FreeImage/TestAPI/MainTestSuite.cpp
+@@ -76,7 +76,7 @@ int main(int argc, char *argv[]) {
+
+ // test memory IO
+ testMemIO("sample.png");
+- testMemIO("exif.jxr");
++ //testMemIO("exif.jxr");
+
+ // test multipage functions
+ testMultiPage("sample.png");
diff --git a/graphics-libs/freeimage/patches/0010-CVE-2019-12211-13.patch b/graphics-libs/freeimage/patches/0010-CVE-2019-12211-13.patch
new file mode 100644
index 0000000000..11f075c8d1
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0010-CVE-2019-12211-13.patch
@@ -0,0 +1,164 @@
+Origin: Debian
+
+Index: freeimage/Source/FreeImage/PluginTIFF.cpp
+===================================================================
+--- freeimage.orig/Source/FreeImage/PluginTIFF.cpp
++++ freeimage/Source/FreeImage/PluginTIFF.cpp
+@@ -122,9 +122,14 @@ static void ReadThumbnail(FreeImageIO *i
+ static int s_format_id;
+
+ typedef struct {
++ //! FreeImage IO functions
+ FreeImageIO *io;
++ //! FreeImage handle
+ fi_handle handle;
++ //! LibTIFF handle
+ TIFF *tif;
++ //! Count the number of thumbnails already read (used to avoid recursion on loading)
++ unsigned thumbnailCount;
+ } fi_TIFFIO;
+
+ // ----------------------------------------------------------
+@@ -184,10 +189,8 @@ Open a TIFF file descriptor for reading
+ */
+ TIFF *
+ TIFFFdOpen(thandle_t handle, const char *name, const char *mode) {
+- TIFF *tif;
+-
+ // Open the file; the callback will set everything up
+- tif = TIFFClientOpen(name, mode, handle,
++ TIFF *tif = TIFFClientOpen(name, mode, handle,
+ _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc,
+ _tiffSizeProc, _tiffMapProc, _tiffUnmapProc);
+
+@@ -460,9 +463,9 @@ CreateImageType(BOOL header_only, FREE_I
+ }
+
+ }
+- else {
++ else if (bpp <= 32) {
+
+- dib = FreeImage_AllocateHeader(header_only, width, height, MIN(bpp, 32), FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
++ dib = FreeImage_AllocateHeader(header_only, width, height, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ }
+
+
+@@ -1053,6 +1056,7 @@ Open(FreeImageIO *io, fi_handle handle,
+ if(!fio) return NULL;
+ fio->io = io;
+ fio->handle = handle;
++ fio->thumbnailCount = 0;
+
+ if (read) {
+ fio->tif = TIFFFdOpen((thandle_t)fio, "", "r");
+@@ -1108,6 +1112,27 @@ check for uncommon bitspersample values
+ */
+ static BOOL
+ IsValidBitsPerSample(uint16 photometric, uint16 bitspersample, uint16 samplesperpixel) {
++ // get the pixel depth in bits
++ const uint16 pixel_depth = bitspersample * samplesperpixel;
++
++ // check for a supported pixel depth
++ switch (pixel_depth) {
++ case 1:
++ case 4:
++ case 8:
++ case 16:
++ case 24:
++ case 32:
++ case 48:
++ case 64:
++ case 96:
++ case 128:
++ // OK, go on
++ break;
++ default:
++ // unsupported pixel depth
++ return FALSE;
++ }
+
+ switch(bitspersample) {
+ case 1:
+@@ -1148,6 +1173,8 @@ IsValidBitsPerSample(uint16 photometric,
+ default:
+ return FALSE;
+ }
++
++ return FALSE;
+ }
+
+ static TIFFLoadMethod
+@@ -1237,16 +1264,32 @@ Read embedded thumbnail
+ static void
+ ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMAP *dib) {
+ FIBITMAP* thumbnail = NULL;
++
++ fi_TIFFIO *fio = (fi_TIFFIO*)data;
++
++ /*
++ Thumbnail loading can cause recursions because of the way
++ functions TIFFLastDirectory and TIFFSetSubDirectory are working.
++ We use here a hack to count the number of times the ReadThumbnail function was called.
++ We only allow one call, check for this
++ */
++ if (fio->thumbnailCount > 0) {
++ return;
++ }
++ else {
++ // update the thumbnail count (used to avoid recursion)
++ fio->thumbnailCount++;
++ }
+
+ // read exif thumbnail (IFD 1) ...
+
+- /*
+- // this code can cause unwanted recursion causing an overflow, it is thus disabled until we have a better solution
+- // do we really need to read a thumbnail from the Exif segment ? knowing that TIFF store the thumbnail in the subIFD ...
+- //
+ toff_t exif_offset = 0;
+ if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) {
+
++ // this code can cause unwanted recursion causing an overflow,
++ // because of the way TIFFLastDirectory work => this is checked
++ // using
++
+ if(!TIFFLastDirectory(tiff)) {
+ // save current position
+ const long tell_pos = io->tell_proc(handle);
+@@ -1264,7 +1307,6 @@ ReadThumbnail(FreeImageIO *io, fi_handle
+ TIFFSetDirectory(tiff, cur_dir);
+ }
+ }
+- */
+
+ // ... or read the first subIFD
+
+@@ -1281,6 +1323,10 @@ ReadThumbnail(FreeImageIO *io, fi_handle
+ const long tell_pos = io->tell_proc(handle);
+ const uint16 cur_dir = TIFFCurrentDirectory(tiff);
+
++ // this code can cause unwanted recursion
++ // causing an overflow, because of the way
++ // TIFFSetSubDirectory work
++
+ if(TIFFSetSubDirectory(tiff, subIFD_offsets[0])) {
+ // load the thumbnail
+ int page = -1;
+@@ -2041,7 +2087,7 @@ Load(FreeImageIO *io, fi_handle handle,
+ }
+
+ // calculate src line and dst pitch
+- int dst_pitch = FreeImage_GetPitch(dib);
++ unsigned dst_pitch = FreeImage_GetPitch(dib);
+ uint32 tileRowSize = (uint32)TIFFTileRowSize(tif);
+ uint32 imageRowSize = (uint32)TIFFScanlineSize(tif);
+
+@@ -2071,7 +2117,7 @@ Load(FreeImageIO *io, fi_handle handle,
+ BYTE *src_bits = tileBuffer;
+ BYTE *dst_bits = bits + rowSize;
+ for(int k = 0; k < nrows; k++) {
+- memcpy(dst_bits, src_bits, src_line);
++ memcpy(dst_bits, src_bits, MIN(dst_pitch, src_line));
+ src_bits += tileRowSize;
+ dst_bits -= dst_pitch;
+ }
diff --git a/graphics-libs/freeimage/patches/0011-Fix_compilation_external-static.patch b/graphics-libs/freeimage/patches/0011-Fix_compilation_external-static.patch
new file mode 100644
index 0000000000..ec59b8f776
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0011-Fix_compilation_external-static.patch
@@ -0,0 +1,18 @@
+Description: Fix compilation due to external-static mismatch
+Author: Anton Gladky <gladk@debian.org>
+Bug-Debian: https://bugs.debian.org/964653
+Last-Update: 2020-07-15
+
+Origin: Debian
+
+--- freeimage-3.18.0+ds2.orig/Source/FreeImage/PluginJPEG.cpp
++++ freeimage-3.18.0+ds2/Source/FreeImage/PluginJPEG.cpp
+@@ -502,7 +502,7 @@ marker_is_icc(jpeg_saved_marker_ptr mark
+ NOTE: if the file contains invalid ICC APP2 markers, we just silently
+ return FALSE. You might want to issue an error message instead.
+ */
+-static BOOL
++BOOL
+ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr, unsigned *icc_data_len) {
+ jpeg_saved_marker_ptr marker;
+ int num_markers = 0;
diff --git a/graphics-libs/freeimage/patches/0012-Fix-libraw-compilation.patch b/graphics-libs/freeimage/patches/0012-Fix-libraw-compilation.patch
new file mode 100644
index 0000000000..f3aaca12e5
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0012-Fix-libraw-compilation.patch
@@ -0,0 +1,76 @@
+Description: Fix FTBFS against libraw 0.20.0
+Origin: https://sourceforge.net/p/freeimage/svn/1842/
+Acked-By: Anton Gladky <gladk@debian.org>
+Bug-Debian: https://bugs.debian.org/968637
+Last-update: 2020-08-27
+
+Index: freeimage/Source/FreeImage/PluginRAW.cpp
+===================================================================
+--- freeimage.orig/Source/FreeImage/PluginRAW.cpp
++++ freeimage/Source/FreeImage/PluginRAW.cpp
+@@ -59,21 +59,18 @@ public:
+ }
+
+ int valid() {
+- return (_io && _handle);
++ return (_io && _handle) ? 1 : 0;
+ }
+
+ int read(void *buffer, size_t size, size_t count) {
+- if(substream) return substream->read(buffer, size, count);
+ return _io->read_proc(buffer, (unsigned)size, (unsigned)count, _handle);
+ }
+
+ int seek(INT64 offset, int origin) {
+- if(substream) return substream->seek(offset, origin);
+ return _io->seek_proc(_handle, (long)offset, origin);
+ }
+
+ INT64 tell() {
+- if(substream) return substream->tell();
+ return _io->tell_proc(_handle);
+ }
+
+@@ -83,19 +80,21 @@ public:
+
+ int get_char() {
+ int c = 0;
+- if(substream) return substream->get_char();
+- if(!_io->read_proc(&c, 1, 1, _handle)) return -1;
++ if (!_io->read_proc(&c, 1, 1, _handle)) {
++ return -1;
++ }
+ return c;
+ }
+
+ char* gets(char *buffer, int length) {
+- if (substream) return substream->gets(buffer, length);
+ memset(buffer, 0, length);
+ for(int i = 0; i < length; i++) {
+- if(!_io->read_proc(&buffer[i], 1, 1, _handle))
++ if (!_io->read_proc(&buffer[i], 1, 1, _handle)) {
+ return NULL;
+- if(buffer[i] == 0x0A)
++ }
++ if (buffer[i] == 0x0A) {
+ break;
++ }
+ }
+ return buffer;
+ }
+@@ -104,7 +103,6 @@ public:
+ std::string buffer;
+ char element = 0;
+ bool bDone = false;
+- if(substream) return substream->scanf_one(fmt,val);
+ do {
+ if(_io->read_proc(&element, 1, 1, _handle) == 1) {
+ switch(element) {
+@@ -127,7 +125,6 @@ public:
+ }
+
+ int eof() {
+- if(substream) return substream->eof();
+ return (_io->tell_proc(_handle) >= _eof);
+ }
+
diff --git a/graphics-libs/freeimage/patches/0013-Update-OpenEXR-API.patch b/graphics-libs/freeimage/patches/0013-Update-OpenEXR-API.patch
new file mode 100644
index 0000000000..5437f6be41
--- /dev/null
+++ b/graphics-libs/freeimage/patches/0013-Update-OpenEXR-API.patch
@@ -0,0 +1,37 @@
+From: Ismael Luceno <ismael@iodev.co.uk>
+Subject: Update OpenEXR API
+
+diff --git a/Source/FreeImage/PluginEXR.cpp b/Source/FreeImage/PluginEXR.cpp
+index a70739cc0e67..decc3a01ae10 100644
+--- a/Source/FreeImage/PluginEXR.cpp
++++ b/Source/FreeImage/PluginEXR.cpp
+@@ -66,12 +66,12 @@ public:
+ return ((unsigned)n != _io->read_proc(c, 1, n, _handle));
+ }
+
+- virtual Imath::Int64 tellg() {
++ virtual uint64_t tellg() {
+ return _io->tell_proc(_handle);
+ }
+
+- virtual void seekg(Imath::Int64 pos) {
+- _io->seek_proc(_handle, (unsigned)pos, SEEK_SET);
++ virtual void seekg(uint64_t pos) {
++ _io->seek_proc(_handle, pos, SEEK_SET);
+ }
+
+ virtual void clear() {
+@@ -100,11 +100,11 @@ public:
+ }
+ }
+
+- virtual Imath::Int64 tellp() {
++ virtual uint64_t tellp() {
+ return _io->tell_proc(_handle);
+ }
+
+- virtual void seekp(Imath::Int64 pos) {
++ virtual void seekp(uint64_t pos) {
+ _io->seek_proc(_handle, (unsigned)pos, SEEK_SET);
+ }
+ };