mirror of
https://github.com/dnet/pySSTV.git
synced 2026-04-21 06:03:43 +00:00
merge and use GIMP layers directly (fixes gh-3)
This commit is contained in:
parent
cf8eb28ec1
commit
e9db1cf9a0
1 changed files with 31 additions and 27 deletions
|
|
@ -4,8 +4,7 @@
|
||||||
# copy to ~/.gimp-2.8/plug-ins/
|
# copy to ~/.gimp-2.8/plug-ins/
|
||||||
# dependencies: GIMP 2.8, python-imaging-tk
|
# dependencies: GIMP 2.8, python-imaging-tk
|
||||||
|
|
||||||
from gimpfu import register, main, pdb, PF_BOOL, PF_STRING, PF_RADIO
|
from gimpfu import register, main, pdb, PF_BOOL, PF_STRING, PF_RADIO, CLIP_TO_IMAGE
|
||||||
from tempfile import mkstemp
|
|
||||||
from PIL import Image, ImageTk
|
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 import __main__ as pysstv_main
|
||||||
|
|
@ -14,7 +13,7 @@ from pysstv.sstv import SSTV
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue, Empty
|
from Queue import Queue, Empty
|
||||||
import os
|
import gimp
|
||||||
|
|
||||||
MODULE_MAP = pysstv_main.build_module_map()
|
MODULE_MAP = pysstv_main.build_module_map()
|
||||||
|
|
||||||
|
|
@ -134,31 +133,36 @@ class ProgressCanvas(Canvas):
|
||||||
|
|
||||||
def transmit_current_image(image, drawable, mode, vox, fskid):
|
def transmit_current_image(image, drawable, mode, vox, fskid):
|
||||||
sstv = MODULE_MAP[mode]
|
sstv = MODULE_MAP[mode]
|
||||||
png_fn = generate_png_filename()
|
pil_img = match_image_with_sstv_mode(image_gimp_to_pil(image), sstv)
|
||||||
try:
|
root = Tk()
|
||||||
pdb.gimp_file_save(image, drawable, png_fn, png_fn)
|
cu = CanvasUpdater(ProgressCanvas(root, pil_img))
|
||||||
pil_img = match_image_with_sstv_mode(Image.open(png_fn), sstv)
|
cu.start()
|
||||||
root = Tk()
|
tm = Transmitter(init_sstv(sstv, pil_img, vox, fskid), root, cu)
|
||||||
cu = CanvasUpdater(ProgressCanvas(root, pil_img))
|
tm1750 = Transmitter(Sine1750(None, 44100, 16), None, None)
|
||||||
cu.start()
|
buttons = Frame(root)
|
||||||
tm = Transmitter(init_sstv(sstv, pil_img, vox, fskid), root, cu)
|
for text, tram in (('TX', tm), ('1750 Hz', tm1750)):
|
||||||
tm1750 = Transmitter(Sine1750(None, 44100, 16), None, None)
|
Checkbutton(buttons, text=text, indicatoron=False, padx=5, pady=5,
|
||||||
buttons = Frame(root)
|
variable=tram.tx_enabled, command=tram.start_stop_tx).pack(side=LEFT)
|
||||||
for text, tram in (('TX', tm), ('1750 Hz', tm1750)):
|
Button(buttons, text="Close", command=tm.close).pack(side=LEFT)
|
||||||
Checkbutton(buttons, text=text, indicatoron=False, padx=5, pady=5,
|
buttons.pack()
|
||||||
variable=tram.tx_enabled, command=tram.start_stop_tx).pack(side=LEFT)
|
root.mainloop()
|
||||||
Button(buttons, text="Close", command=tm.close).pack(side=LEFT)
|
for obj in (tm, tm1750, cu):
|
||||||
buttons.pack()
|
obj.stop()
|
||||||
root.mainloop()
|
|
||||||
for obj in (tm, tm1750, cu):
|
|
||||||
obj.stop()
|
|
||||||
finally:
|
|
||||||
os.remove(png_fn)
|
|
||||||
|
|
||||||
def generate_png_filename():
|
def image_gimp_to_pil(image):
|
||||||
handle, png_fn = mkstemp(suffix='.png', prefix='pysstv-gimp-')
|
try:
|
||||||
os.fdopen(handle).close()
|
sandbox = image.duplicate()
|
||||||
return png_fn
|
sandbox.merge_visible_layers(CLIP_TO_IMAGE)
|
||||||
|
layer = sandbox.layers[0]
|
||||||
|
if not layer.is_rgb:
|
||||||
|
pdb.gimp_image_convert_rgb(sandbox)
|
||||||
|
if layer.has_alpha:
|
||||||
|
pdb.gimp_layer_flatten(layer)
|
||||||
|
w, h = layer.width, layer.height
|
||||||
|
pixels = layer.get_pixel_rgn(0, 0, w, h)[:, :] # all pixels
|
||||||
|
return Image.frombuffer('RGB', (w, h), pixels, 'raw', 'RGB', 0, 0)
|
||||||
|
finally:
|
||||||
|
gimp.delete(sandbox)
|
||||||
|
|
||||||
def match_image_with_sstv_mode(image, mode):
|
def match_image_with_sstv_mode(image, mode):
|
||||||
mode_size = mode.WIDTH, mode.HEIGHT
|
mode_size = mode.WIDTH, mode.HEIGHT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue