add patch to fix freeimage uint16 and big endian loading

This commit is contained in:
Julian Taylor
2014-09-05 23:37:15 +02:00
parent 7cdf7da6c0
commit b944328f2b
2 changed files with 78 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
Author: Stefan van der Walt <stefan@sun.ac.za>
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
+1
View File
@@ -2,3 +2,4 @@ search-html.patch
fix-doc-links.patch
doc-privacy.patch
slicing-error.patch
freeimage-fix.patch