kopia lustrzana https://github.com/dnet/pySSTV
replaced color line encoding with numpy array
rodzic
09df062547
commit
ae67b1d960
|
@ -1,27 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import division
|
||||
from pysstv.sstv import byte_to_freq, FREQ_BLACK, FREQ_WHITE, FREQ_VIS_START
|
||||
from pysstv.sstv import byte_to_freq, FREQ_BLACK, FREQ_WHITE, FREQ_RANGE, FREQ_VIS_START
|
||||
from pysstv.grayscale import GrayscaleSSTV
|
||||
from itertools import chain
|
||||
import numpy
|
||||
|
||||
|
||||
RED, GREEN, BLUE = range(3)
|
||||
|
||||
class ColorSSTV(GrayscaleSSTV):
|
||||
def on_init(self):
|
||||
self.pixels = self.image.load()
|
||||
self.array = (numpy.array(self.image) * (FREQ_RANGE / 255) + FREQ_BLACK) * (numpy.pi * 2)
|
||||
|
||||
def encode_line(self, line):
|
||||
msec_pixel = self.SCAN / self.WIDTH
|
||||
image = self.pixels
|
||||
for index in self.COLOR_SEQ:
|
||||
for item in self.before_channel(index):
|
||||
yield item
|
||||
for col in xrange(self.WIDTH):
|
||||
pixel = image[col, line]
|
||||
freq_pixel = byte_to_freq(pixel[index])
|
||||
yield freq_pixel, msec_pixel
|
||||
yield self.array[line,:self.WIDTH,index], msec_pixel
|
||||
for item in self.after_channel(index):
|
||||
yield item
|
||||
|
||||
|
|
|
@ -81,14 +81,18 @@ class SSTV(object):
|
|||
samples = 0
|
||||
factor = 2 * pi / self.samples_per_sec
|
||||
sample = 0
|
||||
for freq, msec in self.gen_freq_bits():
|
||||
samples += spms * msec
|
||||
tx = int(samples)
|
||||
freq_factor = freq * factor
|
||||
for sample in xrange(tx):
|
||||
yield sin(sample * freq_factor + offset)
|
||||
offset += (sample + 1) * freq_factor
|
||||
samples -= tx
|
||||
for freqs, msec in self.gen_freq_bits():
|
||||
if hasattr(freqs, '__iter__'):
|
||||
freqs /= self.samples_per_sec
|
||||
else:
|
||||
freqs = [freqs * factor]
|
||||
for freq_factor in imap(float, freqs):
|
||||
samples += spms * msec
|
||||
tx = int(samples)
|
||||
for sample in xrange(tx):
|
||||
yield sin(sample * freq_factor + offset)
|
||||
offset += (sample + 1) * freq_factor
|
||||
samples -= tx
|
||||
|
||||
def gen_freq_bits(self):
|
||||
"""generates tuples (freq, msec) that describe a sine wave segment
|
||||
|
|
Ładowanie…
Reference in New Issue