kopia lustrzana https://github.com/dnet/pySSTV
replaced Python 2 iter calls with Python 3 ones
rodzic
09df062547
commit
c432be2447
|
@ -18,7 +18,7 @@ class ColorSSTV(GrayscaleSSTV):
|
|||
for index in self.COLOR_SEQ:
|
||||
for item in self.before_channel(index):
|
||||
yield item
|
||||
for col in xrange(self.WIDTH):
|
||||
for col in range(self.WIDTH):
|
||||
pixel = image[col, line]
|
||||
freq_pixel = byte_to_freq(pixel[index])
|
||||
yield freq_pixel, msec_pixel
|
||||
|
@ -92,7 +92,7 @@ class Robot36(ColorSSTV):
|
|||
self.yuv = self.image.convert('YCbCr').load()
|
||||
|
||||
def encode_line(self, line):
|
||||
pixels = [self.yuv[col, line] for col in xrange(self.WIDTH)]
|
||||
pixels = [self.yuv[col, line] for col in range(self.WIDTH)]
|
||||
channel = (line % 2) + 1
|
||||
y_pixel_time = self.Y_SCAN / self.WIDTH
|
||||
uv_pixel_time = self.C_SCAN / self.WIDTH
|
||||
|
|
|
@ -120,10 +120,10 @@ class ProgressCanvas(Canvas):
|
|||
pixels = image.load()
|
||||
RED, GREEN, BLUE = range(3)
|
||||
self.colors = ['#{0:02x}{1:02x}{2:02x}'.format(
|
||||
contrast(sum(pixels[x, y][RED] for x in xrange(width)) / width),
|
||||
contrast(sum(pixels[x, y][GREEN] for x in xrange(width)) / width),
|
||||
contrast(sum(pixels[x, y][BLUE] for x in xrange(width)) / width))
|
||||
for y in xrange(height)]
|
||||
contrast(sum(pixels[x, y][RED] for x in range(width)) / width),
|
||||
contrast(sum(pixels[x, y][GREEN] for x in range(width)) / width),
|
||||
contrast(sum(pixels[x, y][BLUE] for x in range(width)) / width))
|
||||
for y in range(height)]
|
||||
if height / float(width) > 1.5:
|
||||
width *= 2
|
||||
elif width < 200:
|
||||
|
|
|
@ -9,7 +9,7 @@ class GrayscaleSSTV(SSTV):
|
|||
self.pixels = self.image.convert('LA').load()
|
||||
|
||||
def gen_image_tuples(self):
|
||||
for line in xrange(self.HEIGHT):
|
||||
for line in range(self.HEIGHT):
|
||||
for item in self.horizontal_sync():
|
||||
yield item
|
||||
for item in self.encode_line(line):
|
||||
|
@ -18,7 +18,7 @@ class GrayscaleSSTV(SSTV):
|
|||
def encode_line(self, line):
|
||||
msec_pixel = self.SCAN / self.WIDTH
|
||||
image = self.pixels
|
||||
for col in xrange(self.WIDTH):
|
||||
for col in range(self.WIDTH):
|
||||
pixel = image[col, line]
|
||||
freq_pixel = byte_to_freq(pixel[0])
|
||||
yield freq_pixel, msec_pixel
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import division, with_statement
|
|||
from math import sin, pi
|
||||
from random import random
|
||||
from contextlib import closing
|
||||
from itertools import imap, izip, cycle, chain
|
||||
from itertools import cycle, chain
|
||||
from array import array
|
||||
import wave
|
||||
|
||||
|
@ -46,7 +46,7 @@ class SSTV(object):
|
|||
data = array(fmt, self.gen_samples())
|
||||
if self.nchannels != 1:
|
||||
data = array(fmt, chain.from_iterable(
|
||||
izip(*([data] * self.nchannels))))
|
||||
zip(*([data] * self.nchannels))))
|
||||
with closing(wave.open(filename, 'wb')) as wav:
|
||||
wav.setnchannels(self.nchannels)
|
||||
wav.setsampwidth(self.bits // 8)
|
||||
|
@ -64,8 +64,8 @@ class SSTV(object):
|
|||
amp = max_value // 2
|
||||
lowest = -amp
|
||||
highest = amp - 1
|
||||
alias_cycle = cycle((alias * (random() - 0.5) for _ in xrange(1024)))
|
||||
for value, alias_item in izip(self.gen_values(), alias_cycle):
|
||||
alias_cycle = cycle((alias * (random() - 0.5) for _ in range(1024)))
|
||||
for value, alias_item in zip(self.gen_values(), alias_cycle):
|
||||
sample = int(value * amp + alias_item)
|
||||
yield (lowest if sample <= lowest else
|
||||
sample if sample <= highest else highest)
|
||||
|
@ -85,7 +85,7 @@ class SSTV(object):
|
|||
samples += spms * msec
|
||||
tx = int(samples)
|
||||
freq_factor = freq * factor
|
||||
for sample in xrange(tx):
|
||||
for sample in range(tx):
|
||||
yield sin(sample * freq_factor + offset)
|
||||
offset += (sample + 1) * freq_factor
|
||||
samples -= tx
|
||||
|
@ -104,7 +104,7 @@ class SSTV(object):
|
|||
yield FREQ_SYNC, MSEC_VIS_BIT # start bit
|
||||
vis = self.VIS_CODE
|
||||
num_ones = 0
|
||||
for _ in xrange(7):
|
||||
for _ in range(7):
|
||||
bit = vis & 1
|
||||
vis >>= 1
|
||||
num_ones += bit
|
||||
|
@ -115,8 +115,8 @@ class SSTV(object):
|
|||
yield FREQ_SYNC, MSEC_VIS_BIT # stop bit
|
||||
for freq_tuple in self.gen_image_tuples():
|
||||
yield freq_tuple
|
||||
for fskid_byte in imap(ord, self.fskid_payload):
|
||||
for _ in xrange(6):
|
||||
for fskid_byte in map(ord, self.fskid_payload):
|
||||
for _ in range(6):
|
||||
bit = fskid_byte & 1
|
||||
fskid_byte >>= 1
|
||||
bit_freq = FREQ_FSKID_BIT1 if bit == 1 else FREQ_FSKID_BIT0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import unittest
|
||||
from itertools import islice, izip
|
||||
from itertools import islice
|
||||
import pickle
|
||||
import mock
|
||||
from mock import MagicMock
|
||||
|
@ -46,7 +46,7 @@ class TestSSTV(unittest.TestCase):
|
|||
def test_gen_values(self):
|
||||
gen_values = self.s.gen_values()
|
||||
expected = pickle.load(open(get_asset_filename("SSTV_gen_values.p")))
|
||||
for e, g in izip(expected, gen_values):
|
||||
for e, g in zip(expected, gen_values):
|
||||
self.assertAlmostEqual(e, g, delta=0.000000001)
|
||||
|
||||
def test_gen_samples(self):
|
||||
|
@ -59,7 +59,7 @@ class TestSSTV(unittest.TestCase):
|
|||
sstv.random = MagicMock(return_value=0.4) # xkcd:221
|
||||
expected = pickle.load(open(get_asset_filename("SSTV_gen_samples.p")))
|
||||
actual = list(islice(gen_values, 0, 1000))
|
||||
for e, a in izip(expected, actual):
|
||||
for e, a in zip(expected, actual):
|
||||
self.assertAlmostEqual(e, a, delta=1)
|
||||
|
||||
def test_write_wav(self):
|
||||
|
|
Ładowanie…
Reference in New Issue