From a9984c6e39d563f66dd1d38134fdf10edd429f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Thu, 23 May 2013 14:46:18 +0200 Subject: [PATCH] added ColorSSTV class, fixed fencepost div --- sstv.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/sstv.py b/sstv.py index 60664cf..20d9125 100644 --- a/sstv.py +++ b/sstv.py @@ -88,14 +88,34 @@ class GrayscaleSSTV(SSTV): def gen_freq_bits(self): for item in SSTV.gen_freq_bits(self): yield item - msec_pixel = self.SCAN / self.WIDTH - image = self.image for line in xrange(self.HEIGHT): yield FREQ_SYNC, self.SYNC - for col in xrange(self.WIDTH): - pixel = image.getpixel((col, line)) - value = sum(pixel) / len(pixel) - freq_pixel = FREQ_BLACK + FREQ_RANGE * value / 256 + for item in self.encode_line(line): + yield item + + def encode_line(self, line): + msec_pixel = self.SCAN / self.WIDTH + image = self.image + for col in xrange(self.WIDTH): + pixel = image.getpixel((col, line)) + value = sum(pixel) / len(pixel) + freq_pixel = FREQ_BLACK + FREQ_RANGE * value / 255 + yield freq_pixel, msec_pixel + + +class ColorSSTV(GrayscaleSSTV): + RED, GREEN, BLUE = range(3) + + def encode_line(self, line): + cs = self.COLOR_SEQ + msec_pixel = self.SCAN / self.WIDTH + image = self.image + for col in xrange(self.WIDTH): + pixel = image.getpixel((col, line)) + print pixel + for index in cs: + value = pixel[index] + freq_pixel = FREQ_BLACK + FREQ_RANGE * value / 255 yield freq_pixel, msec_pixel