From b74feb49ab8bc91026f5b29ff2f499884a206df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Fri, 22 Nov 2013 18:36:58 +0100 Subject: [PATCH] GrayscaleSSTV: use PIL for grayscale conversion --- pysstv/grayscale.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pysstv/grayscale.py b/pysstv/grayscale.py index 7377f74..a044981 100644 --- a/pysstv/grayscale.py +++ b/pysstv/grayscale.py @@ -5,6 +5,8 @@ from sstv import SSTV, byte_to_freq class GrayscaleSSTV(SSTV): + def on_init(self): + self.pixels = self.image.convert('LA').load() def gen_image_tuples(self): for line in xrange(self.HEIGHT): @@ -15,11 +17,10 @@ class GrayscaleSSTV(SSTV): def encode_line(self, line): msec_pixel = self.SCAN / self.WIDTH - image = self.image.load() - pixlen = len(image[0, line]) + image = self.pixels for col in xrange(self.WIDTH): pixel = image[col, line] - freq_pixel = byte_to_freq(sum(pixel) / pixlen) + freq_pixel = byte_to_freq(pixel[0]) yield freq_pixel, msec_pixel