[Pkg-mozext-commits] [adblock-plus] 05/41: Issue 1883 - Convert mode P to LA to work around a PIL bug when extracting the alpha channel

David Prévot taffit at moszumanska.debian.org
Wed Mar 18 18:21:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 74bc60cf104e4f260a496bcf2f0d2453cc478a4e
Author: Sebastian Noack <sebastian at adblockplus.org>
Date:   Tue Jan 27 15:03:57 2015 +0100

    Issue 1883 - Convert mode P to LA to work around a PIL bug when extracting the alpha channel
---
 imageConversion.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/imageConversion.py b/imageConversion.py
index 44746a7..87e9fec 100644
--- a/imageConversion.py
+++ b/imageConversion.py
@@ -19,14 +19,14 @@ def get_alpha(image):
   if image.mode in ('RGBA', 'LA'):
     return image.split()[image.getbands().index('A')]
 
-  if image.mode == 'P':
-    transparency = image.info.get('transparency')
-
-    if transparency is not None:
-      table = [255] * 256
-      table[transparency] = 0
-
-      return image.point(table, 'L')
+  # In order to generate an alpha channel for images using a palette, we
+  # convert the image to grayscale+alpha. Initially, we created an alpha
+  # channel by replacing opaque pixels with a high mark and transparent
+  # pixels with a low mark. However, it turned out that you can't rely on the
+  # value of Image.info['transparency'] since in some cases it might be an
+  # unparsed string instead an int indicating the value of transparent pixels.
+  if image.mode == 'P' and 'transparency' in image.info:
+    return image.convert('LA').split()[1]
 
 def load_image(path):
   image = Image.open(path)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list