]> git.aero2k.de Git - sirius.git/commitdiff
Replace thresholding with dithering
authorJoe Rickerby <joerick@mac.com>
Wed, 10 Jan 2018 14:56:44 +0000 (14:56 +0000)
committerJoe Rickerby <joerick@mac.com>
Wed, 10 Jan 2018 14:56:44 +0000 (14:56 +0000)
sirius/coding/image_encoding.py

index 436871ed9ea6905ea1ca1c4ed3fb8d3a417f22ee..261df6c8f698ec11304fcbf0da4f5eb44e5feaac 100644 (file)
@@ -61,9 +61,8 @@ def crop_384(im):
     return im.crop((0, 0, 384, min(h, 10000)))
 
 
-def threshold(im):
-    thresholded = ''.join(pixel_to_bw(x) for x in im.convert('RGBA').getdata())
-    return Image.fromstring('L', im.size, thresholded)
+def convert_to_1bit(im):
+    return im.convert('1')
 
 
 def rle_from_bw(bw_image):
@@ -132,6 +131,10 @@ def html_to_png(html):
 def default_pipeline(html):
     """Encode HTML into an RLE image."""
     data = html_to_png(html)
-    image = Image.open(data)
+    return png_pipeline(data)
+
+
+def png_pipeline(png_data):
+    image = Image.open(png_data)
     image = crop_384(image)
-    return threshold(image)
+    return convert_to_1bit(image)