From 93288904ccebdfbfcd0c6fa5c1e903890085d4f1 Mon Sep 17 00:00:00 2001
From: Kevin Mihelich <kevin@archlinuxarm.org>
Date: Sat, 25 Jul 2020 16:32:21 +0000
Subject: [PATCH] community/freeimage to 3.18.0-6

---
 community/freeimage/PKGBUILD                  | 10 ++--
 .../freeimage/freeimage-libraw-0.20.patch     | 50 +++++++++++++++++++
 2 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 community/freeimage/freeimage-libraw-0.20.patch

diff --git a/community/freeimage/PKGBUILD b/community/freeimage/PKGBUILD
index b12caaddb..6f60ca0f1 100644
--- a/community/freeimage/PKGBUILD
+++ b/community/freeimage/PKGBUILD
@@ -9,7 +9,7 @@
 
 pkgname=freeimage
 pkgver=3.18.0
-pkgrel=5
+pkgrel=6
 pkgdesc="Library project for developers who would like to support popular graphics image formats"
 arch=('x86_64')
 license=('GPL' 'custom:FIPL')
@@ -17,9 +17,11 @@ url="http://freeimage.sourceforge.net/"
 depends=('libjpeg-turbo' 'openexr' 'openjpeg2' 'libwebp' 'libraw' 'jxrlib')
 makedepends=('mesa' 'glu')
 source=("https://downloads.sourceforge.net/project/freeimage/Source%20Distribution/${pkgver}/FreeImage${pkgver//./}.zip"
-        freeimage-unbundle.patch)
+        freeimage-unbundle.patch
+        freeimage-libraw-0.20.patch)
 sha512sums=('9d9cc7e2d57552c3115e277aeb036e0455204d389026b17a3f513da5be1fd595421655488bb1ec2f76faebed66049119ca55e26e2a6d37024b3fb7ef36ad4818'
-            '605fd28aaaf3b0ad225d04dd7de5e34d825bb7aa4b1f3a3b4219657c51b2f1507512916e95ba1a731ca5fc8b704f03b83371ab9ad066d74fd49feee735cf13b5')
+            '605fd28aaaf3b0ad225d04dd7de5e34d825bb7aa4b1f3a3b4219657c51b2f1507512916e95ba1a731ca5fc8b704f03b83371ab9ad066d74fd49feee735cf13b5'
+            '5709e4c5baac3505bf2f2498082fbf6b8614e631fec69fc629036c8d033fbe21434a198e9ae24d577dd65928fd31a0d95c584ea4349d74134f7859d4e57b8397')
 
 prepare() {
   cd FreeImage
@@ -30,6 +32,8 @@ prepare() {
   # can't be built due to private headers
   > Source/FreeImage/PluginG3.cpp
   > Source/FreeImageToolkit/JPEGTransform.cpp
+
+  patch -p1 -i ../freeimage-libraw-0.20.patch # Fix build with libraw 0.20
 }
 
 build() {
diff --git a/community/freeimage/freeimage-libraw-0.20.patch b/community/freeimage/freeimage-libraw-0.20.patch
new file mode 100644
index 000000000..b921dca1e
--- /dev/null
+++ b/community/freeimage/freeimage-libraw-0.20.patch
@@ -0,0 +1,50 @@
+--- FreeImage/Source/FreeImage/PluginRAW.cpp.orig	2020-07-23 17:27:57.937848902 +0000
++++ FreeImage/Source/FreeImage/PluginRAW.cpp	2020-07-23 17:28:59.482079468 +0000
+@@ -63,17 +63,14 @@
+ 	}
+ 
+     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,13 +80,11 @@
+ 
+     int get_char() { 
+ 		int c = 0;
+-		if(substream) return substream->get_char();
+ 		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))
+@@ -104,7 +99,6 @@
+ 		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 +121,6 @@
+ 	}
+ 
+ 	int eof() { 
+-		if(substream) return substream->eof();
+         return (_io->tell_proc(_handle) >= _eof);
+     }
+