diff --git a/color.py b/color.py index 24fdb16..3acc8d6 100644 --- a/color.py +++ b/color.py @@ -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): diff --git a/grayscale.py b/grayscale.py index 3ca0aa4..10422a3 100644 --- a/grayscale.py +++ b/grayscale.py @@ -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 diff --git a/sstv.py b/sstv.py index 1d3c491..b84bc32 100644 --- a/sstv.py +++ b/sstv.py @@ -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