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
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import division
|
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 pysstv.grayscale import GrayscaleSSTV
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
import numpy
|
||||||
|
|
||||||
|
|
||||||
RED, GREEN, BLUE = range(3)
|
RED, GREEN, BLUE = range(3)
|
||||||
|
|
||||||
class ColorSSTV(GrayscaleSSTV):
|
class ColorSSTV(GrayscaleSSTV):
|
||||||
def on_init(self):
|
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):
|
def encode_line(self, line):
|
||||||
msec_pixel = self.SCAN / self.WIDTH
|
msec_pixel = self.SCAN / self.WIDTH
|
||||||
image = self.pixels
|
|
||||||
for index in self.COLOR_SEQ:
|
for index in self.COLOR_SEQ:
|
||||||
for item in self.before_channel(index):
|
for item in self.before_channel(index):
|
||||||
yield item
|
yield item
|
||||||
for col in xrange(self.WIDTH):
|
yield self.array[line,:self.WIDTH,index], msec_pixel
|
||||||
pixel = image[col, line]
|
|
||||||
freq_pixel = byte_to_freq(pixel[index])
|
|
||||||
yield freq_pixel, msec_pixel
|
|
||||||
for item in self.after_channel(index):
|
for item in self.after_channel(index):
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,14 @@ class SSTV(object):
|
||||||
samples = 0
|
samples = 0
|
||||||
factor = 2 * pi / self.samples_per_sec
|
factor = 2 * pi / self.samples_per_sec
|
||||||
sample = 0
|
sample = 0
|
||||||
for freq, msec in self.gen_freq_bits():
|
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
|
samples += spms * msec
|
||||||
tx = int(samples)
|
tx = int(samples)
|
||||||
freq_factor = freq * factor
|
|
||||||
for sample in xrange(tx):
|
for sample in xrange(tx):
|
||||||
yield sin(sample * freq_factor + offset)
|
yield sin(sample * freq_factor + offset)
|
||||||
offset += (sample + 1) * freq_factor
|
offset += (sample + 1) * freq_factor
|
||||||
|
|
Ładowanie…
Reference in New Issue