diff --git a/Makefile b/Makefile index f969650..f5a8ea1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CFLAGS = -DUP=0 -DDN=1 -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -ffast-math -LDFLAGS = -lm -lasound +CFLAGS = -g -DUP=0 -DDN=1 -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -ffast-math $(shell sdl-config --cflags) +LDFLAGS = -lm -lasound $(shell sdl-config --libs) all: encode decode debug @@ -35,9 +35,9 @@ fun: all clean: rm -f encode decode debug *.o {8000,11025,16000,40000,44100,48000}.{ppm,wav,dat} -encode: encode.o mmap_file.o pcm.o wav.o alsa.o yuv.o img.o ppm.o +encode: encode.o mmap_file.o pcm.o wav.o alsa.o yuv.o img.o ppm.o sdl.o -decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o yuv.o img.o ppm.o +decode: decode.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o yuv.o img.o ppm.o sdl.o -debug: debug.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o yuv.o img.o ppm.o +debug: debug.o mmap_file.o pcm.o wav.o alsa.o window.o ddc.o delay.o yuv.o img.o ppm.o sdl.o diff --git a/img.c b/img.c index 0507dd8..3b67054 100644 --- a/img.c +++ b/img.c @@ -9,6 +9,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include #include "img.h" #include "ppm.h" +#include "sdl.h" void close_img(img_t *img) { @@ -27,6 +28,8 @@ int open_img_write(img_t **p, char *name, int width, int height) { if (strstr(name, ".ppm") == (name + (strlen(name) - strlen(".ppm")))) return open_ppm_write(p, name, width, height); + if (strstr(name, "sdl:") == name) + return open_sdl_write(p, name, width, height); return 0; } diff --git a/sdl.c b/sdl.c new file mode 100644 index 0000000..6f44f9a --- /dev/null +++ b/sdl.c @@ -0,0 +1,82 @@ +/* +robot36 - encode and decode images using SSTV in Robot 36 mode +Written in 2011 by +To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. +You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . +*/ + +#include +#include +#include +#include +#include +#include "img.h" + +typedef struct { + void (*close)(img_t *); + uint8_t *pixel; + int width; + int height; + SDL_Surface *screen; + SDL_Thread *thread; + int quit; +} sdl_t; + +int update_sdl(void *data) +{ + sdl_t *sdl = (sdl_t *)data; + while (!sdl->quit) { + SDL_Flip(sdl->screen); + SDL_Delay(100); + } + return 0; +} + +void close_sdl(img_t *img) +{ + sdl_t *sdl = (sdl_t *)img; + sdl->quit = 1; + SDL_WaitThread(sdl->thread, 0); + SDL_Quit(); +} + +int open_sdl_write(img_t **p, char *name, int width, int height) +{ + sdl_t *sdl = (sdl_t *)malloc(sizeof(sdl_t)); + sdl->close = close_sdl; + + atexit(SDL_Quit); + SDL_Init(SDL_INIT_VIDEO); + sdl->screen = SDL_SetVideoMode(width, height, 24, SDL_SWSURFACE); + if (!sdl->screen) { + fprintf(stderr, "couldnt open %s window %dx%d@24\n", name, width, height); + SDL_Quit(); + free(sdl); + return 0; + } + if (sdl->screen->format->BytesPerPixel != 3 || sdl->screen->w != width || sdl->screen->h != height) { + fprintf(stderr, "requested %dx%d@24 but got %s window %dx%d@24\n", width, height, name, sdl->screen->w, sdl->screen->h); + SDL_Quit(); + free(sdl); + return 0; + } + SDL_WM_SetCaption("robot36", "robot36"); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + sdl->pixel = sdl->screen->pixels; + memset(sdl->pixel, 0, width * height * 3); + + sdl->quit = 0; + sdl->thread = SDL_CreateThread(update_sdl, sdl); + if (!sdl->thread) { + fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError()); + SDL_Quit(); + free(sdl); + return 0; + } + + *p = (img_t *)sdl; + + return 1; +} + diff --git a/sdl.h b/sdl.h new file mode 100644 index 0000000..a99fbfa --- /dev/null +++ b/sdl.h @@ -0,0 +1,13 @@ +/* +robot36 - encode and decode images using SSTV in Robot 36 mode +Written in 2011 by +To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. +You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . +*/ + + +#ifndef SDL_H +#define SDL_H +#include "img.h" +int open_sdl_write(img_t **, char *, int, int); +#endif