diff options
Diffstat (limited to 'src/plugins/gif_extractor.c')
-rw-r--r-- | src/plugins/gif_extractor.c | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/src/plugins/gif_extractor.c b/src/plugins/gif_extractor.c index 8ee5807..405eebe 100644 --- a/src/plugins/gif_extractor.c +++ b/src/plugins/gif_extractor.c | |||
@@ -37,16 +37,16 @@ | |||
37 | */ | 37 | */ |
38 | static int | 38 | static int |
39 | gif_read_func (GifFileType *ft, | 39 | gif_read_func (GifFileType *ft, |
40 | GifByteType *bt, | 40 | GifByteType *bt, |
41 | int arg) | 41 | int arg) |
42 | { | 42 | { |
43 | struct EXTRACTOR_ExtractContext *ec = ft->UserData; | 43 | struct EXTRACTOR_ExtractContext *ec = ft->UserData; |
44 | void *data; | 44 | void *data; |
45 | ssize_t ret; | 45 | ssize_t ret; |
46 | 46 | ||
47 | ret = ec->read (ec->cls, | 47 | ret = ec->read (ec->cls, |
48 | &data, | 48 | &data, |
49 | arg); | 49 | arg); |
50 | if (-1 == ret) | 50 | if (-1 == ret) |
51 | return -1; | 51 | return -1; |
52 | memcpy (bt, data, ret); | 52 | memcpy (bt, data, ret); |
@@ -75,7 +75,7 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec) | |||
75 | 75 | ||
76 | gif_error = 0; | 76 | gif_error = 0; |
77 | gif_file = DGifOpen (ec, &gif_read_func, &gif_error); | 77 | gif_file = DGifOpen (ec, &gif_read_func, &gif_error); |
78 | if (gif_file == NULL || gif_error != 0) | 78 | if ((gif_file == NULL) || (gif_error != 0)) |
79 | { | 79 | { |
80 | if (gif_file != NULL) | 80 | if (gif_file != NULL) |
81 | #if GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 | 81 | #if GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 |
@@ -88,57 +88,58 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec) | |||
88 | #endif | 88 | #endif |
89 | if (0 != | 89 | if (0 != |
90 | ec->proc (ec->cls, | 90 | ec->proc (ec->cls, |
91 | "gif", | 91 | "gif", |
92 | EXTRACTOR_METATYPE_MIMETYPE, | 92 | EXTRACTOR_METATYPE_MIMETYPE, |
93 | EXTRACTOR_METAFORMAT_UTF8, | 93 | EXTRACTOR_METAFORMAT_UTF8, |
94 | "text/plain", | 94 | "text/plain", |
95 | "image/gif", | 95 | "image/gif", |
96 | strlen ("image/gif") + 1)) | 96 | strlen ("image/gif") + 1)) |
97 | return; | 97 | return; |
98 | snprintf (dims, | 98 | snprintf (dims, |
99 | sizeof (dims), | 99 | sizeof (dims), |
100 | "%dx%d", | 100 | "%dx%d", |
101 | gif_file->SHeight, | 101 | gif_file->SHeight, |
102 | gif_file->SWidth); | 102 | gif_file->SWidth); |
103 | if (0 != | 103 | if (0 != |
104 | ec->proc (ec->cls, | 104 | ec->proc (ec->cls, |
105 | "gif", | 105 | "gif", |
106 | EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, | 106 | EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, |
107 | EXTRACTOR_METAFORMAT_UTF8, | 107 | EXTRACTOR_METAFORMAT_UTF8, |
108 | "text/plain", | 108 | "text/plain", |
109 | dims, | 109 | dims, |
110 | strlen (dims) + 1)) | 110 | strlen (dims) + 1)) |
111 | return; | 111 | return; |
112 | while (1) | 112 | while (1) |
113 | { | ||
114 | if (GIF_OK != | ||
115 | DGifGetRecordType (gif_file, | ||
116 | &gif_type)) | ||
117 | break; | ||
118 | if (UNDEFINED_RECORD_TYPE == gif_type) | ||
119 | break; | ||
120 | if (EXTENSION_RECORD_TYPE != gif_type) | ||
121 | continue; | ||
122 | if (GIF_OK != | ||
123 | DGifGetExtension (gif_file, &et, &ext)) | ||
124 | continue; | ||
125 | if (NULL == ext) | ||
126 | continue; | ||
127 | if (COMMENT_EXT_FUNC_CODE == et) | ||
113 | { | 128 | { |
114 | if (GIF_OK != | 129 | ec->proc (ec->cls, |
115 | DGifGetRecordType (gif_file, | 130 | "gif", |
116 | &gif_type)) | 131 | EXTRACTOR_METATYPE_COMMENT, |
117 | break; | 132 | EXTRACTOR_METAFORMAT_C_STRING, |
118 | if (UNDEFINED_RECORD_TYPE == gif_type) | 133 | "text/plain", |
119 | break; | 134 | (char*) &ext[1], |
120 | if (EXTENSION_RECORD_TYPE != gif_type) | 135 | (uint8_t) ext[0]); |
121 | continue; | 136 | break; |
122 | if (GIF_OK != | ||
123 | DGifGetExtension (gif_file, &et, &ext)) | ||
124 | continue; | ||
125 | if (NULL == ext) | ||
126 | continue; | ||
127 | if (COMMENT_EXT_FUNC_CODE == et) | ||
128 | { | ||
129 | ec->proc (ec->cls, | ||
130 | "gif", | ||
131 | EXTRACTOR_METATYPE_COMMENT, | ||
132 | EXTRACTOR_METAFORMAT_C_STRING, | ||
133 | "text/plain", | ||
134 | (char*) &ext[1], | ||
135 | (uint8_t) ext[0]); | ||
136 | break; | ||
137 | } | ||
138 | while ( (GIF_ERROR != | ||
139 | DGifGetExtensionNext(gif_file, &ext)) && | ||
140 | (NULL != ext) ) ; /* keep going */ | ||
141 | } | 137 | } |
138 | while ( (GIF_ERROR != | ||
139 | DGifGetExtensionNext (gif_file, &ext)) && | ||
140 | (NULL != ext) ) | ||
141 | ; /* keep going */ | ||
142 | } | ||
142 | #if defined (GIF_LIB_VERSION) || GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 | 143 | #if defined (GIF_LIB_VERSION) || GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 |
143 | DGifCloseFile (gif_file); | 144 | DGifCloseFile (gif_file); |
144 | #else | 145 | #else |
@@ -146,4 +147,5 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec) | |||
146 | #endif | 147 | #endif |
147 | } | 148 | } |
148 | 149 | ||
150 | |||
149 | /* end of gif_extractor.c */ | 151 | /* end of gif_extractor.c */ |