GrayscaleSSTV: use PIL for grayscale conversion

This commit is contained in:
András Veres-Szentkirályi 2013-11-22 18:36:58 +01:00
parent bd3b84cfb6
commit b74feb49ab

View file

@ -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