aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-01-30 20:11:59 +0100
committerjaseg <jaseg@jaseg.net>2014-01-30 20:11:59 +0100
commit5a77d3a0e0a24c2c637aec0195919a13d42ac769 (patch)
tree80e40cad3eef9ddb1cdb79676f83c2ec99f3e832
parentdd677c6fa77d2bc10b1640172263eb0ba5325c6c (diff)
downloadmatelight-5a77d3a0e0a24c2c637aec0195919a13d42ac769.tar.gz
matelight-5a77d3a0e0a24c2c637aec0195919a13d42ac769.tar.bz2
matelight-5a77d3a0e0a24c2c637aec0195919a13d42ac769.zip
GIF reading fixes
-rw-r--r--host/gif.c12
-rw-r--r--host/main.c8
2 files changed, 14 insertions, 6 deletions
diff --git a/host/gif.c b/host/gif.c
index ac77bd8..c62a5e2 100644
--- a/host/gif.c
+++ b/host/gif.c
@@ -14,7 +14,8 @@ int gif_buffer_input (GifFileType *gif, GifByteType *dest, int n){
readBuffer_t *rb = gif->UserData;
if(rb->index+n > rb->length)
n = rb->length - rb->index;
- memcpy(dest, rb->data, n);
+ memcpy(dest, rb->data + rb->index, n);
+ rb->index += n;
return n;
}
@@ -38,6 +39,7 @@ void color_fill(color_t *dest, color_t src, size_t size){
}
gifAnimationState_t *gif_read(uint8_t *buf, size_t buflength){
+ color_t *fb = 0;
gifAnimationState_t *st = malloc(sizeof(gifAnimationState_t));
if(!st){
fprintf(stderr, "Failed to allocate %lu bytes\n", sizeof(*st));
@@ -48,6 +50,12 @@ gifAnimationState_t *gif_read(uint8_t *buf, size_t buflength){
int err = 0;
GifFileType *gif = DGifOpen(&readBuf, gif_buffer_input, &err);
if(err){
+ fprintf(stderr, "Could not open GIF: %s\n", GifErrorString(err));
+ goto error;
+ }
+
+ err = DGifSlurp(gif);
+ if(err){
fprintf(stderr, "Could not read GIF data: %s\n", GifErrorString(err));
goto error;
}
@@ -57,7 +65,7 @@ gifAnimationState_t *gif_read(uint8_t *buf, size_t buflength){
fprintf(stderr, "Invalid 0*0px gif\n");
goto error;
}
- color_t *fb = calloc(framesize, sizeof(color_t));
+ fb = calloc(framesize, sizeof(color_t));
if(!fb){
fprintf(stderr, "Failed to allocate framebuffer for GIF (%lu bytes)\n", framesize*sizeof(color_t));
goto error;
diff --git a/host/main.c b/host/main.c
index a8c5231..aa782aa 100644
--- a/host/main.c
+++ b/host/main.c
@@ -390,7 +390,7 @@ int main(int argc, char **argv){
fprintf(stderr, "Error opening gif file from argument (\"%s\"): Cannot allocate %lu bytes.\n", argv[1], newsize);
goto error;
}
- read += fread(buf+size, 1, newsize, f);
+ read += fread(buf+size, 1, READ_INC, f);
size = newsize;
}while(read == size);
fb = framebuffer_render_gif(buf, read, &gifstate, &delay);
@@ -401,13 +401,13 @@ int main(int argc, char **argv){
}
for(;;){ /* Never gonna give you up, never gonna let you down! */
- printf("\033[2J");
-
if(!fb){
- fprintf(stderr, "Error rendering text.\n");
+ fprintf(stderr, "Error rendering.\n");
goto error;
}
+ printf("\033[2J");
+
console_render_buffer(fb);
printf("\n");
usleep(delay*1000);