Created
January 23, 2013 21:40
-
-
Save springmeyer/4613861 to your computer and use it in GitHub Desktop.
Fix hang in mapproxy rendering due to PIL quantize deadlock on osx by disabling quantization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mapproxy/image/__init__.py b/mapproxy/image/__init__.py | |
index b5bb73b..0c6c6ac 100644 | |
--- a/mapproxy/image/__init__.py | |
+++ b/mapproxy/image/__init__.py | |
@@ -282,22 +282,6 @@ def img_to_buf(img, image_opts): | |
return buf | |
def quantize(img, colors=256, alpha=False, defaults=None, quantizer=None): | |
- if hasattr(Image, 'FASTOCTREE') and quantizer in (None, 'fastoctree'): | |
- if not alpha: | |
- img = img.convert('RGB') | |
- img = img.quantize(colors, Image.FASTOCTREE) | |
- else: | |
- if alpha and img.mode == 'RGBA': | |
- img.load() # split might fail if image is not loaded | |
- alpha = img.split()[3] | |
- img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors-1) | |
- mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0) | |
- img.paste(255, mask) | |
- if defaults is not None: | |
- defaults['transparency'] = 255 | |
- else: | |
- img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors) | |
- | |
return img | |
diff --git a/mapproxy/platform/image.py b/mapproxy/platform/image.py | |
index ed725ca..f1d5eb3 100644 | |
--- a/mapproxy/platform/image.py | |
+++ b/mapproxy/platform/image.py | |
@@ -50,21 +50,5 @@ def require_alpha_composite_support(): | |
raise ImportError('Pillow required for alpha_composite support') | |
def quantize_pil(img, colors=256, alpha=False, defaults=None): | |
- if hasattr(Image, 'FASTOCTREE'): | |
- if not alpha: | |
- img = img.convert('RGB') | |
- img = img.quantize(colors, Image.FASTOCTREE) | |
- else: | |
- if alpha: | |
- img.load() # split might fail if image is not loaded | |
- alpha = img.split()[3] | |
- img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors-1) | |
- mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0) | |
- img.paste(255, mask) | |
- if defaults is not None: | |
- defaults['transparency'] = 255 | |
- else: | |
- img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=colors) | |
- | |
return img | |
quantize = quantize_pil | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment