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/debug.c b/debug.c index f4200b7..abea7b0 100644 --- a/debug.c +++ b/debug.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) const int width = (0.150 + 3.0 * sync_porch_len) * drate + 20; const int height = 256; - img_t *img; + img_t *img = 0; int hor_ticks = 0; int y_pixel_x = 0; diff --git a/decode.c b/decode.c index 24bc9c3..dec3a6d 100644 --- a/decode.c +++ b/decode.c @@ -359,7 +359,7 @@ int main(int argc, char **argv) short *buff = (short *)malloc(sizeof(short) * channels * factor_M); - img_t *img; + img_t *img = 0; for (int out = factor_L;; out++) { if (out >= factor_L) { 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..a41fcf2 --- /dev/null +++ b/sdl.c @@ -0,0 +1,60 @@ +/* +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_t; + +void close_sdl(img_t *img) +{ + sdl_t *sdl = (sdl_t *)img; + (void)sdl; + 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); + + *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