blob: a6a13d6f31ff67ad0ab8ee3aac7bd339740416c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <assert.h>
#include <gif_lib.h>
#include "meh.h"
struct gif_t{
struct image img;
FILE *f;
GifFileType *gif;
};
static struct image *gif_open(FILE *f){
struct gif_t *g;
GifFileType *gif;
lseek(fileno(f), 0L, SEEK_SET);
if(!(gif = DGifOpenFileHandle(fileno(f)))){
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;
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;
}
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
};
|