kopia lustrzana https://github.com/dnet/pySSTV
Porównaj commity
10 Commity
65241a6b71
...
bc74dc98d6
Autor | SHA1 | Data |
---|---|---|
András Veres-Szentkirályi | bc74dc98d6 | |
Rehtt | b22e81e65f | |
András Veres-Szentkirályi | c454aa3a4b | |
András Veres-Szentkirályi | 0855fc6a0c | |
András Veres-Szentkirályi | 75b0cd46e3 | |
András Veres-Szentkirályi | cb00cf20ad | |
András Veres-Szentkirályi | 5d3d6a2584 | |
András Veres-Szentkirályi | 456040aa6b | |
András Veres-Szentkirályi | ab0560b71e | |
dependabot[bot] | f4b4ca7b19 |
|
@ -0,0 +1,40 @@
|
|||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
||||
|
||||
name: Python package
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install flake8 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pytest
|
11
README.md
11
README.md
|
@ -1,8 +1,6 @@
|
|||
SSTV generator in pure Python
|
||||
=============================
|
||||
|
||||
[![Build Status](https://travis-ci.org/dnet/pySSTV.svg?branch=master)](https://travis-ci.org/dnet/pySSTV)
|
||||
|
||||
PySSTV generates SSTV modulated WAV files from any image that PIL can open
|
||||
(PNG, JPEG, GIF, and many others). These WAV files then can be played by any
|
||||
audio player connected to a shortwave radio for example.
|
||||
|
@ -36,6 +34,13 @@ Command line usage
|
|||
--vox add VOX tones at the beginning
|
||||
--fskid FSKID add FSKID at the end
|
||||
--chan CHAN number of channels (default: mono)
|
||||
--resize resize the image to the correct size
|
||||
--keep-aspect-ratio keep the original aspect ratio when resizing
|
||||
(and cut off excess pixels)
|
||||
--keep-aspect keep the original aspect ratio when resizing
|
||||
(not cut off excess pixels)
|
||||
--resample which resampling filter to use for resizing
|
||||
(see Pillow documentation)
|
||||
|
||||
Python interface
|
||||
----------------
|
||||
|
@ -76,4 +81,4 @@ Dependencies
|
|||
------------
|
||||
|
||||
- Python 3.5 or later
|
||||
- Python Imaging Library (Debian/Ubuntu package: `python-imaging`)
|
||||
- Python Imaging Library (Debian/Ubuntu package: `python3-pil`)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
|
@ -34,6 +34,8 @@ def main():
|
|||
help='resize the image to the correct size')
|
||||
parser.add_argument('--keep-aspect-ratio', dest='keep_aspect_ratio', action='store_true',
|
||||
help='keep the original aspect ratio when resizing (and cut off excess pixels)')
|
||||
parser.add_argument('--keep-aspect', dest='keep_aspect', action='store_true',
|
||||
help='keep the original aspect ratio when resizing (not cut off excess pixels)')
|
||||
parser.add_argument('--resample', dest='resample', default='lanczos',
|
||||
choices=('nearest', 'bicubic', 'lanczos'),
|
||||
help='which resampling filter to use for resizing (see Pillow documentation)')
|
||||
|
@ -42,14 +44,17 @@ def main():
|
|||
mode = module_map[args.mode]
|
||||
if args.resize and any(i != m for i, m in zip(image.size, (mode.WIDTH, mode.HEIGHT))):
|
||||
resample = getattr(Image, args.resample.upper())
|
||||
if args.keep_aspect_ratio:
|
||||
if args.keep_aspect_ratio or args.keep_aspect:
|
||||
orig_ratio = image.width / image.height
|
||||
mode_ratio = mode.WIDTH / mode.HEIGHT
|
||||
crop = orig_ratio != mode_ratio
|
||||
else:
|
||||
crop = False
|
||||
if crop:
|
||||
if orig_ratio < mode_ratio:
|
||||
t = orig_ratio < mode_ratio
|
||||
if args.keep_aspect:
|
||||
t = orig_ratio > mode_ratio
|
||||
if t:
|
||||
w = mode.WIDTH
|
||||
h = int(w / orig_ratio)
|
||||
else:
|
||||
|
@ -59,6 +64,14 @@ def main():
|
|||
w = mode.WIDTH
|
||||
h = mode.HEIGHT
|
||||
image = image.resize((w, h), resample)
|
||||
if args.keep_aspect:
|
||||
newbg = Image.new('RGB', (mode.WIDTH, mode.HEIGHT))
|
||||
if t:
|
||||
newbg.paste(image, (0, int((mode.HEIGHT/2)-(h/2))))
|
||||
else:
|
||||
newbg.paste(image, (int((mode.WIDTH/2)-(w/2)), 0))
|
||||
image = newbg.copy()
|
||||
crop = False
|
||||
if crop:
|
||||
x = (image.width - mode.WIDTH) / 2
|
||||
y = (image.height - mode.HEIGHT) / 2
|
||||
|
|
|
@ -69,10 +69,10 @@ def main(sstv_class=None):
|
|||
n += 1
|
||||
del lut
|
||||
m_start, m_len = gen_matches(same_as, history, n)
|
||||
for i in xrange(same_as[m_start]):
|
||||
for i in range(same_as[m_start]):
|
||||
yield history[i][0]
|
||||
yield 'for (int row = 0; row < width * {0}; row += width) {{'.format(sstv.HEIGHT)
|
||||
for i in xrange(same_as[m_start], same_as[m_start] + m_len - 1):
|
||||
for i in range(same_as[m_start], same_as[m_start] + m_len - 1):
|
||||
yield ' ' + history[i][1]
|
||||
yield '}'
|
||||
yield '}}\n\n#define FREQ_COUNT {0}'.format(n)
|
||||
|
@ -83,7 +83,7 @@ def gen_matches(same_as, history, n):
|
|||
cur_start = None
|
||||
cur_len = None
|
||||
cur_end = None
|
||||
for i in xrange(n):
|
||||
for i in range(n):
|
||||
if cur_start is None:
|
||||
tmp = same_as.get(i)
|
||||
if tmp is not None:
|
||||
|
@ -114,22 +114,22 @@ def test(img_file):
|
|||
import struct
|
||||
exe = './codegen-test-executable'
|
||||
if not path.exists('stb_image.h'):
|
||||
from urllib import urlretrieve
|
||||
from urllib.request import urlretrieve
|
||||
urlretrieve('https://raw.githubusercontent.com/nothings/stb/master/stb_image.h', 'stb_image.h')
|
||||
try:
|
||||
for sstv_class in supported:
|
||||
print 'Testing', sstv_class
|
||||
print('Testing', sstv_class)
|
||||
gcc = Popen(['gcc', '-xc', '-lm', '-o', exe, '-'], stdin=PIPE)
|
||||
start = datetime.now()
|
||||
with open(path.join(path.dirname(__file__), 'codeman.c')) as cm:
|
||||
c_src = cm.read().replace('#include "codegen.c"', '\n'.join(main(sstv_class)))
|
||||
gcc.communicate(c_src)
|
||||
gen_elapsed = datetime.now() - start
|
||||
print ' - gengcc took', gen_elapsed
|
||||
print(' - gengcc took', gen_elapsed)
|
||||
start = datetime.now()
|
||||
gen = check_output([exe, img_file])
|
||||
native_elapsed = datetime.now() - start
|
||||
print ' - native took', native_elapsed
|
||||
print(' - native took', native_elapsed)
|
||||
img = Image.open(img_file)
|
||||
sstv = sstv_class(img, 44100, 16)
|
||||
start = datetime.now()
|
||||
|
@ -138,20 +138,20 @@ def test(img_file):
|
|||
assert gen[n * 8:(n + 1) * 8] == struct.pack('ff', freq, msec)
|
||||
except AssertionError:
|
||||
mode_name = sstv_class.__name__
|
||||
with file('/tmp/{0}-c.bin'.format(mode_name), 'wb') as f:
|
||||
with open('/tmp/{0}-c.bin'.format(mode_name), 'wb') as f:
|
||||
f.write(gen)
|
||||
with file('/tmp/{0}-py.bin'.format(mode_name), 'wb') as f:
|
||||
with open('/tmp/{0}-py.bin'.format(mode_name), 'wb') as f:
|
||||
for n, (freq, msec) in enumerate(sstv.gen_freq_bits()):
|
||||
f.write(struct.pack('ff', freq, msec))
|
||||
with file('/tmp/{0}.c'.format(mode_name), 'w') as f:
|
||||
with open('/tmp/{0}.c'.format(mode_name), 'w') as f:
|
||||
f.write(c_src)
|
||||
print (" ! Outputs are different, they've been saved to "
|
||||
print((" ! Outputs are different, they've been saved to "
|
||||
"/tmp/{0}-{{c,py}}.bin, along with the C source code "
|
||||
"in /tmp/{0}.c").format(mode_name)
|
||||
"in /tmp/{0}.c").format(mode_name))
|
||||
python_elapsed = datetime.now() - start
|
||||
print ' - python took', python_elapsed
|
||||
print ' - speedup:', python_elapsed.total_seconds() / native_elapsed.total_seconds()
|
||||
print 'OK'
|
||||
print(' - python took', python_elapsed)
|
||||
print(' - speedup:', python_elapsed.total_seconds() / native_elapsed.total_seconds())
|
||||
print('OK')
|
||||
finally:
|
||||
try:
|
||||
remove(exe)
|
||||
|
@ -164,4 +164,4 @@ if __name__ == '__main__':
|
|||
if len(argv) > 2 and argv[1] == 'test':
|
||||
test(argv[2])
|
||||
else:
|
||||
print '\n'.join(main())
|
||||
print('\n'.join(main()))
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
from gimpfu import register, main, pdb, PF_BOOL, PF_STRING, PF_RADIO, CLIP_TO_IMAGE
|
||||
from PIL import Image, ImageTk
|
||||
from Tkinter import Tk, Canvas, Button, Checkbutton, IntVar, Frame, LEFT, NW
|
||||
from tkinter import Tk, Canvas, Button, Checkbutton, IntVar, Frame, LEFT, NW
|
||||
from pysstv import __main__ as pysstv_main
|
||||
from pysstv.examples.pyaudio_sstv import PyAudioSSTV
|
||||
from pysstv.sstv import SSTV
|
||||
from itertools import repeat
|
||||
from threading import Thread
|
||||
from Queue import Queue, Empty
|
||||
from queue import Queue, Empty
|
||||
from time import sleep
|
||||
import gimp, os
|
||||
|
||||
|
@ -118,12 +118,12 @@ class ProgressCanvas(Canvas):
|
|||
self.height_ratio = 1
|
||||
width, height = image.size
|
||||
pixels = image.load()
|
||||
RED, GREEN, BLUE = range(3)
|
||||
RED, GREEN, BLUE = list(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:
|
||||
|
@ -237,7 +237,7 @@ register(
|
|||
"*",
|
||||
[
|
||||
(PF_RADIO, "mode", "SSTV mode", "MartinM1",
|
||||
tuple((n, n) for n in sorted(MODULE_MAP.iterkeys()))),
|
||||
tuple((n, n) for n in sorted(MODULE_MAP.keys()))),
|
||||
(PF_BOOL, "vox", "Include VOX tones", True),
|
||||
(PF_STRING, "fskid", "FSK ID", ""),
|
||||
(PF_RADIO, "ptt_port", "PTT port", None,
|
||||
|
|
|
@ -5,7 +5,7 @@ Demonstrates playing the generated samples directly using PyAudio
|
|||
Tested on PyAudio 0.2.7 http://people.csail.mit.edu/hubert/pyaudio/
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
|
||||
from pysstv.sstv import SSTV
|
||||
from time import sleep
|
||||
from itertools import islice
|
||||
|
|
|
@ -8,9 +8,9 @@ simply copying/linking images to the directory or suing an SSTV
|
|||
receiver such as slowrx or QSSTV.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from pyinotify import WatchManager, Notifier, ProcessEvent, IN_CREATE
|
||||
from pyaudio_sstv import PyAudioSSTV
|
||||
from .pyaudio_sstv import PyAudioSSTV
|
||||
from pysstv.color import MartinM1, MartinM2, ScottieS1, ScottieS2
|
||||
from pysstv.grayscale import Robot8BW, Robot24BW
|
||||
from PIL import Image
|
||||
|
@ -44,13 +44,13 @@ class EventHandler(ProcessEvent):
|
|||
|
||||
def get_module_for_filename(filename):
|
||||
basename, _ = path.splitext(path.basename(filename))
|
||||
for mode, module in MODE_MAP.iteritems():
|
||||
for mode, module in MODE_MAP.items():
|
||||
if mode in basename:
|
||||
return module
|
||||
|
||||
def get_module_for_image(image):
|
||||
size = image.size
|
||||
for mode in MODE_MAP.itervalues():
|
||||
for mode in MODE_MAP.values():
|
||||
if all(i >= m for i, m in zip(size, (mode.WIDTH, mode.HEIGHT))):
|
||||
return mode
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
Pillow==9.0.0
|
||||
Pillow==10.0.1
|
||||
mock==1.0.1
|
||||
nose==1.3.0
|
||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='PySSTV',
|
||||
version='0.5.4',
|
||||
version='0.5.6',
|
||||
description='Python classes for generating Slow-scan Television transmissions',
|
||||
author=u'András Veres-Szentkirályi',
|
||||
author_email='vsza@vsza.hu',
|
||||
|
|
Ładowanie…
Reference in New Issue