moved freq-related functions to sstv module

This commit is contained in:
András Veres-Szentkirályi 2013-05-23 16:22:30 +02:00
parent b43cf13511
commit 3644c050ae
3 changed files with 11 additions and 9 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from __future__ import division
from sstv import FREQ_BLACK, FREQ_RANGE
from sstv import byte_to_freq, FREQ_BLACK
from grayscale import GrayscaleSSTV
class ColorSSTV(GrayscaleSSTV):
@ -16,8 +16,7 @@ class ColorSSTV(GrayscaleSSTV):
yield item
for col in xrange(self.WIDTH):
pixel = image.getpixel((col, line))
value = pixel[index]
freq_pixel = FREQ_BLACK + FREQ_RANGE * value / 255
freq_pixel = byte_to_freq(pixel[index])
yield freq_pixel, msec_pixel
def before_channel(self, index):

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from __future__ import division
from sstv import FREQ_BLACK, FREQ_RANGE, FREQ_SYNC, SSTV
from sstv import SSTV, byte_to_freq
class GrayscaleSSTV(SSTV):
def gen_freq_bits(self):
@ -13,16 +13,12 @@ class GrayscaleSSTV(SSTV):
for item in self.encode_line(line):
yield item
def horizontal_sync(self):
yield FREQ_SYNC, self.SYNC
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
freq_pixel = byte_to_freq(sum(pixel) / len(pixel))
yield freq_pixel, msec_pixel

View file

@ -83,6 +83,13 @@ class SSTV(object):
yield parity_freq, MSEC_VIS_BIT
yield FREQ_SYNC, MSEC_VIS_BIT # stop bit
def horizontal_sync(self):
yield FREQ_SYNC, self.SYNC
def byte_to_freq(value):
return FREQ_BLACK + FREQ_RANGE * value / 255
if __name__ == '__main__':
from PIL import Image