From b944328f2b2ada09340c7226f0f4eac681262f39 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Fri, 5 Sep 2014 23:37:15 +0200 Subject: [PATCH] add patch to fix freeimage uint16 and big endian loading --- debian/patches/freeimage-fix.patch | 77 ++++++++++++++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 78 insertions(+) create mode 100644 debian/patches/freeimage-fix.patch diff --git a/debian/patches/freeimage-fix.patch b/debian/patches/freeimage-fix.patch new file mode 100644 index 00000000..bc5846c2 --- /dev/null +++ b/debian/patches/freeimage-fix.patch @@ -0,0 +1,77 @@ +Author: Stefan van der Walt +Description: freeimage: Correctly handle saving uint16 images and fix big endian + +Origin: 2b1dde20 051c54c577b3 84f3835106aaeb +Applied-Upstream: 0.11 +--- a/skimage/io/_plugins/freeimage_plugin.py ++++ b/skimage/io/_plugins/freeimage_plugin.py +@@ -493,7 +493,6 @@ def _array_from_bitmap(bitmap): + # swizzle the color components and flip the scanlines to go from + # FreeImage's BGR[A] and upside-down internal memory format to something + # more normal +- + def n(arr): + return arr[..., ::-1].T + if len(shape) == 3 and _FI.FreeImage_IsLittleEndian() and \ +@@ -637,17 +636,28 @@ def _array_to_bitmap(array): + raise RuntimeError('Could not allocate image for storage') + try: + def n(arr): # normalise to freeimage's in-memory format +- return arr.T[:, ::-1] ++ return arr.T[..., ::-1] ++ + wrapped_array = _wrap_bitmap_bits_in_array(bitmap, w_shape, dtype) + # swizzle the color components and flip the scanlines to go to + # FreeImage's BGR[A] and upside-down internal memory format +- if len(shape) == 3 and _FI.FreeImage_IsLittleEndian() and \ +- dtype.type == numpy.uint8: +- wrapped_array[0] = n(array[:, :, 2]) +- wrapped_array[1] = n(array[:, :, 1]) +- wrapped_array[2] = n(array[:, :, 0]) ++ if len(shape) == 3 and _FI.FreeImage_IsLittleEndian(): ++ R = array[:, :, 0] ++ G = array[:, :, 1] ++ B = array[:, :, 2] ++ ++ if dtype.type == numpy.uint8: ++ wrapped_array[0] = n(B) ++ wrapped_array[1] = n(G) ++ wrapped_array[2] = n(R) ++ elif dtype.type == numpy.uint16: ++ wrapped_array[0] = n(R) ++ wrapped_array[1] = n(G) ++ wrapped_array[2] = n(B) ++ + if shape[2] == 4: +- wrapped_array[3] = n(array[:, :, 3]) ++ A = array[:, :, 3] ++ wrapped_array[3] = n(A) + else: + wrapped_array[:] = n(array) + if len(shape) == 2 and dtype.type == numpy.uint8: +diff --git a/skimage/io/tests/test_freeimage.py b/skimage/io/tests/test_freeimage.py +index 32e01bd..308f1ee 100644 +--- a/skimage/io/tests/test_freeimage.py ++++ b/skimage/io/tests/test_freeimage.py +@@ -74,15 +74,15 @@ class TestSave: + f.close() + sio.imsave(fname, x) + y = sio.imread(fname) +- assert_array_equal(x, y) ++ assert_array_equal(y, x) + + @skipif(not FI_available) + def test_imsave_roundtrip(self): + for shape, dtype, format in [ + [(10, 10), (np.uint8, np.uint16), ('tif', 'png')], + [(10, 10), (np.float32,), ('tif',)], +- [(10, 10, 3), (np.uint8,), ('png',)], +- [(10, 10, 4), (np.uint8,), ('png',)] ++ [(10, 10, 3), (np.uint8, np.uint16), ('png',)], ++ [(10, 10, 4), (np.uint8, np.uint16), ('png',)] + ]: + tests = [(d, f) for d in dtype for f in format] + for d, f in tests: +-- +1.9.1 + diff --git a/debian/patches/series b/debian/patches/series index 37fc429f..0e42339f 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -2,3 +2,4 @@ search-html.patch fix-doc-links.patch doc-privacy.patch slicing-error.patch +freeimage-fix.patch