Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created September 25, 2022 00:19
Show Gist options
  • Save TheSkorm/28a643b4b6dcd6f8d41c98c585f77bb8 to your computer and use it in GitHub Desktop.
Save TheSkorm/28a643b4b6dcd6f8d41c98c585f77bb8 to your computer and use it in GitHub Desktop.
Realtime SSTV hack
import struct
from PIL import Image, ImageOps
import io
import requests
sstv = open("/tmp/myfifo", "rb")
def send_to_server(bytes_send):
url = "http://file.foxden:5000"
payload={'font':'DejaVuSansMono.ttf'}
files=[
('image',('Untitled.png',bytes_send,'image/png'))
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
skip = False
while 1:
#read header for length
header = sstv.read(2)
length = struct.unpack("H", header)[0]
print(length)
length_bytes = length * 3
#read pixel data
pixel_data = sstv.read(length_bytes)
#skip every second line hack
if skip == False:
skip = True
else:
skip = False
continue
img = Image.frombytes("RGB", (length, 1), pixel_data)
img = ImageOps.mirror(img)
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img_byte_arr.seek(0)
send_to_server(img_byte_arr)
print("line")
diff --git a/video.c b/video.c
index 389751f..ba21c66 100644
--- a/video.c
+++ b/video.c
@@ -37,7 +37,10 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
double ChanStart[4] = {0}, ChanLen[4] = {0};
guchar Image[800][616][3] = {{{0}}};
guchar Channel = 0, WinIdx = 0;
-
+ char * myfifo = "/tmp/myfifo";
+ int fd;
+ mkfifo(myfifo, 0666);
+ fd = open(myfifo, O_WRONLY);
typedef struct {
int X;
int Y;
@@ -426,6 +429,7 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
// Calculate and draw pixels to pixbuf on line change
if (x == ModeSpec[Mode].ImgWidth - 1 || PixelGrid[PixelIdx].Last) {
+ write(fd, &ModeSpec[Mode].ImgWidth, sizeof(ModeSpec[Mode].ImgWidth));
for (tx = 0; tx < ModeSpec[Mode].ImgWidth; tx++) {
p = pixels + y * rowstride + tx * 3;
@@ -454,6 +458,10 @@ gboolean GetVideo(guchar Mode, double Rate, int Skip, gboolean Redraw) {
p[0] = p[1] = p[2] = Image[tx][y][0];
break;
}
+
+ // write to fifo with image buffer
+
+ write(fd, p, 3);
}
if (!Redraw || y % 5 == 0 || PixelGrid[PixelIdx].Last) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment