aboutsummaryrefslogtreecommitdiffstats
path: root/src/gif.c
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-16 16:15:54 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-16 16:15:54 -0700
commit0e03461ca2c584cacda2647b68d2eb8b0c34c216 (patch)
treec1253a7951df53678e16dd981ac4cc0940703932 /src/gif.c
parentd1ea7c8e8f53dd1885ca2c8b951089cdbee3f180 (diff)
downloadmirror-meh-0e03461ca2c584cacda2647b68d2eb8b0c34c216.tar.gz
mirror-meh-0e03461ca2c584cacda2647b68d2eb8b0c34c216.tar.bz2
mirror-meh-0e03461ca2c584cacda2647b68d2eb8b0c34c216.zip
changed all formats to use struct image
Diffstat (limited to 'src/gif.c')
-rw-r--r--src/gif.c77
1 files changed, 53 insertions, 24 deletions
diff --git a/src/gif.c b/src/gif.c
index 93a4517..a6a13d6 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1,6 +1,9 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
#include <assert.h>
@@ -8,38 +11,64 @@
#include "meh.h"
+struct gif_t{
+ struct image img;
+ FILE *f;
+ GifFileType *gif;
+};
-unsigned char *loadgif(FILE *f, int *bufwidth, int *bufheight){
+static struct image *gif_open(FILE *f){
+ struct gif_t *g;
GifFileType *gif;
- SavedImage *img;
- GifColorType *colormap;
- unsigned char *buf;
+ lseek(fileno(f), 0L, SEEK_SET);
if(!(gif = DGifOpenFileHandle(fileno(f)))){
return NULL;
}
- if(DGifSlurp(gif) == GIF_ERROR){
- return NULL;
- }
- img = &gif->SavedImages[0];
- *bufwidth = img->ImageDesc.Width;
- *bufheight = img->ImageDesc.Height;
- buf = malloc(img->ImageDesc.Width * img->ImageDesc.Height * 3);
-
- if(img->ImageDesc.ColorMap)
- colormap = img->ImageDesc.ColorMap->Colors;
- else if(gif->SColorMap)
- colormap = gif->SColorMap->Colors;
- else
- return NULL;
+ g = malloc(sizeof(struct gif_t));
+ g->f = f;
+ g->gif = gif;
+ g->img.width = gif->SWidth;
+ g->img.height = gif->SHeight;
+
+ return (struct image *)g;
+}
+
+static int gif_read(struct image *img){
int i, j = 0;
- for(i = 0; i < img->ImageDesc.Width * img->ImageDesc.Height; i++){
- unsigned char idx = img->RasterBits[i];
- buf[j++] = colormap[idx].Red;
- buf[j++] = colormap[idx].Green;
- buf[j++] = colormap[idx].Blue;
+ struct gif_t *g = (struct gif_t *)img;
+ GifColorType *colormap;
+ SavedImage *s;
+
+ if(DGifSlurp(g->gif) == GIF_ERROR){
+ PrintGifError();
+ return 1;
+ }
+
+ s = &g->gif->SavedImages[0];
+
+ if(s->ImageDesc.ColorMap)
+ colormap = s->ImageDesc.ColorMap->Colors;
+ else if(g->gif->SColorMap)
+ colormap = g->gif->SColorMap->Colors;
+ else{
+ PrintGifError();
+ return 1;
}
- return buf;
+
+ for(i = 0; i < img->width * img->height; i++){
+ unsigned char idx = s->RasterBits[i];
+ img->buf[j++] = colormap[idx].Red;
+ img->buf[j++] = colormap[idx].Green;
+ img->buf[j++] = colormap[idx].Blue;
+ }
+
+ return 0;
}
+struct imageformat giflib = {
+ gif_open,
+ gif_read
+};
+