From 1e72c8221210bbc24fd34d5cab75818193f2d962 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 10 Jan 2014 12:34:25 +0100 Subject: Working on gif handling. Not working yet. libgif does not yet read all parts of the file --- host/gif.c | 11 +++++++--- host/gif.h | 4 ++-- host/main.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------------- host/main.h | 4 ++++ 4 files changed, 68 insertions(+), 20 deletions(-) (limited to 'host') diff --git a/host/gif.c b/host/gif.c index 6474269..ac77bd8 100644 --- a/host/gif.c +++ b/host/gif.c @@ -37,7 +37,7 @@ void color_fill(color_t *dest, color_t src, size_t size){ memcpy(dest+i, dest, (size-i)*sizeof(color_t)); } -gifAnimationState_t *gif_read(uint8_t *buf, unsigned int buflength){ +gifAnimationState_t *gif_read(uint8_t *buf, size_t buflength){ gifAnimationState_t *st = malloc(sizeof(gifAnimationState_t)); if(!st){ fprintf(stderr, "Failed to allocate %lu bytes\n", sizeof(*st)); @@ -59,7 +59,7 @@ gifAnimationState_t *gif_read(uint8_t *buf, unsigned int buflength){ } color_t *fb = calloc(framesize, sizeof(color_t)); if(!fb){ - fprintf(stderr, "Failed to allocate framebuffer for GIF (%d bytes)\n", gif->SWidth*gif->SHeight); + fprintf(stderr, "Failed to allocate framebuffer for GIF (%lu bytes)\n", framesize*sizeof(color_t)); goto error; } if(gif->SColorMap){ /* Initially fill framebuffer with background color */ @@ -73,6 +73,11 @@ gifAnimationState_t *gif_read(uint8_t *buf, unsigned int buflength){ st->gif = gif; st->idx = 0; + st->frame = malloc(sizeof(framebuffer_t)); + if(!st->frame){ + fprintf(stderr, "Failed to allocate %lu bytes\n", sizeof(framebuffer_t)); + goto error; + } st->frame->data = fb; st->frame->w = gif->SWidth; st->frame->h = gif->SHeight; @@ -93,7 +98,7 @@ void gifAnimationState_free(gifAnimationState_t *st){ * state ⇜ internal state, initialize as NULL * delay ⇜ is filled with this frame's delay value in milliseconds (if it is not NULL). -1 means "No delay given". * Small note: I mean, rendering a GIF in python is not quite trivial, either (about 20loc). But come on, this is just ridiculous. */ -framebuffer_t *gif_render(uint8_t *buf, unsigned int buflength, gifAnimationState_t **state, int *delay){ +framebuffer_t *framebuffer_render_gif(uint8_t *buf, size_t buflength, gifAnimationState_t **state, int *delay){ gifAnimationState_t *st; if(*state == NULL){ /* On first invocation, parse gif and store it in the state struct */ diff --git a/host/gif.h b/host/gif.h index 8ff4981..fde10b4 100644 --- a/host/gif.h +++ b/host/gif.h @@ -6,8 +6,8 @@ typedef struct _gifAnimationState gifAnimationState_t; -gifAnimationState_t *gif_read(uint8_t *buf, unsigned int buflength); -framebuffer_t* gif_render(uint8_t *buf, unsigned int buflength, gifAnimationState_t **state, int *delay); +gifAnimationState_t *gif_read(uint8_t *buf, size_t buflength); +framebuffer_t* framebuffer_render_gif(uint8_t *buf, size_t buflength, gifAnimationState_t **state, int *delay); void gifAnimationState_free(gifAnimationState_t *st); #endif//__GIF_H__ diff --git a/host/main.c b/host/main.c index 29e56f9..07a99dd 100644 --- a/host/main.c +++ b/host/main.c @@ -1,7 +1,8 @@ #include "main.h" -#include "font.h" #include "color.h" +#include "font.h" +#include "gif.h" #include #include #include @@ -345,34 +346,72 @@ void console_render_buffer(framebuffer_t *fb){ } int main(int argc, char **argv){ - if(argc < 2){ - fprintf(stderr, "No input text given\n"); + if(argc != 2){ + fprintf(stderr, "No or too much input text given\n"); return 1; } - FILE *f = fopen("unifont.bdf", "r"); - if(!f){ + FILE *fontfile = fopen("unifont.bdf", "r"); + if(!fontfile){ fprintf(stderr, "Error opening font file: %s\n", strerror(errno)); return 1; } glyph_t* glyph_table[BLP_SIZE]; - if(read_bdf(f, glyph_table, BLP_SIZE)){ + if(read_bdf(fontfile, glyph_table, BLP_SIZE)){ fprintf(stderr, "Error reading font file.\n"); return 1; } + fclose(fontfile); - for(;;){ - printf("\033[2J"); - for(unsigned int i=1; i