From 3ad0f7fa213b575b8df6c3ff65b2d57ef02ca0ee Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Wed, 10 Jan 2018 14:56:44 +0000 Subject: [PATCH] Replace thresholding with dithering --- sirius/coding/image_encoding.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sirius/coding/image_encoding.py b/sirius/coding/image_encoding.py index 436871e..261df6c 100644 --- a/sirius/coding/image_encoding.py +++ b/sirius/coding/image_encoding.py @@ -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) -- 2.47.3