Merge pull request #1790 from WarrenWeckesser/imread-indexed-png-alpha

FIX: imread w/PIL plugin no longer drops indexed PNG alpha channel
This commit is contained in:
Josh Warner
2015-12-15 19:57:23 -07:00
5 changed files with 27 additions and 5 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ numpy>=1.6.1
scipy>=0.9.0
six>=1.4
networkx>=1.8
pillow>=1.7.8
pillow>=2.1.0
dask[array]>=0.5.0
Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

+4 -1
View File
@@ -85,7 +85,10 @@ def pil_to_ndarray(im, dtype=None, img_num=None):
if grayscale:
frame = im.convert('L')
else:
frame = im.convert('RGB')
if im.format == 'PNG' and 'transparency' in im.info:
frame = im.convert('RGBA')
else:
frame = im.convert('RGB')
elif im.mode == '1':
frame = im.convert('L')
+22
View File
@@ -84,6 +84,28 @@ def test_imread_palette():
assert img.ndim == 3
def test_imread_index_png_with_alpha():
# The file `foo3x5x4indexed.png` was created with this array
# (3x5 is (height)x(width)):
data = np.array([[[127, 0, 255, 255],
[127, 0, 255, 255],
[127, 0, 255, 255],
[127, 0, 255, 255],
[127, 0, 255, 255]],
[[192, 192, 255, 0],
[192, 192, 255, 0],
[0, 0, 255, 0],
[0, 0, 255, 0],
[0, 0, 255, 0]],
[[0, 31, 255, 255],
[0, 31, 255, 255],
[0, 31, 255, 255],
[0, 31, 255, 255],
[0, 31, 255, 255]]], dtype=np.uint8)
img = imread(os.path.join(data_dir, 'foo3x5x4indexed.png'))
assert_array_equal(img, data)
def test_palette_is_gray():
gray = Image.open(os.path.join(data_dir, 'palette_gray.png'))
assert _palette_is_grayscale(gray)
-3
View File
@@ -40,9 +40,6 @@ fi
# test minimum requirements on 2.7
if [[ $TRAVIS_PYTHON_VERSION == 2.7* ]]; then
sed -i 's/>=/==/g' requirements.txt
# PIL instead of Pillow
sed -i 's/pillow.*/pil==1.1.7/g' requirements.txt
WHEELBINARIES=${WHEELBINARIES/pillow/pil}
fi
# create new empty venv