diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/advtime.c | 6 | ||||
-rw-r--r-- | src/util.c | 8 | ||||
-rw-r--r-- | src/util.h | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/advtime.c b/src/advtime.c index e4cd9a9..402da31 100644 --- a/src/advtime.c +++ b/src/advtime.c @@ -113,8 +113,10 @@ main(int argc, char **argv) if (diff > 40.0) { snprintf(filename, BUFSIZ, "img/%04i.pgm", i); frame_mix(frame_a, frame_b); - pgm_save(frame_a->data, frame_a->stride, frame_a->width, - frame_a->height, filename); + if (pgm_save(frame_a->data, frame_a->stride, + frame_a->width, frame_a->height, + filename) < 0) + exit(EXIT_FAILURE); } printf("\n"); @@ -3,17 +3,21 @@ #include "video_decode.h" #include "util.h" -void +int pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) { FILE *f; int i; f = fopen(filename, "w"); + if (f == NULL) + return -1; fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255); - for(i=0; i < ysize; i++) + for(i = 0; i < ysize; i++) fwrite(buf + i * wrap, 1, xsize, f); fclose(f); + + return 0; } void @@ -1,7 +1,7 @@ #ifndef _UTIL_H_ #define _UTIL_H_ -void +int pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename); /* Store half of frame_a and half of frame_b in frame_a */ |