-
Notifications
You must be signed in to change notification settings - Fork 3
/
img-dcdr.c
65 lines (59 loc) · 1.37 KB
/
img-dcdr.c
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
#include <stddef.h>
#include <stdlib.h>
#include "global.h"
#include "mime.h"
#include "image_P.h"
typedef struct s_decoder {
struct s_decoder * Next;
MIMETYPE Mime[4];
BOOL (*start)(const char * file, IMGINFO);
} DECODER;
#define DECODER_CHAIN NULL
#include "img_gif.c"
#include "img_jpg.c"
#include "img_png.c"
#include "img_xmp.c"
#include "img_ico.c"
/*----------------------------------------------------------------------------*/
IMGINFO
get_decoder (const char * file)
{
static DECODER * decoder_chain = DECODER_CHAIN;
IMGINFO info = (decoder_chain ? malloc (sizeof (struct s_img_info)) : NULL);
if (info) {
DECODER * decoder = NULL;
DECODER * found = NULL;
MIMETYPE mime = mime_byExtension (file, NULL, NULL);
memset (info, 0, offsetof (struct s_img_info, Pixel));
if (MIME_Major(mime) && MIME_Minor(mime)) {
found = decoder_chain;
while (found) {
MIMETYPE * mptr = found->Mime;
while (*mptr && *mptr != mime) {
mptr++;
}
if (*mptr) {
if ((*found->start)(file, info)) {
decoder = found;
}
break;
}
found = found->Next;
}
}
if (!decoder) {
decoder = decoder_chain;
while (decoder) {
if (decoder != found && (*decoder->start)(file, info)) {
break;
}
decoder = decoder->Next;
}
}
if (!info->_priv_data) {
free (info);
info = NULL;
}
}
return info;
}