blob: fab3371f0f51d1eb165ae27837af82b8d09e91a0 [file] [log] [blame]
Patrick Williamsddad1a12017-02-23 20:36:32 -06001 src/tracker-extract/tracker-extract-gif.c | 36 +++++++++++++++++++++++++++++
2 1 file changed, 36 insertions(+)
3--- a/src/tracker-extract/tracker-extract-gif.c
4+++ a/src/tracker-extract/tracker-extract-gif.c
5@@ -75,6 +75,39 @@
6 return (GIF_OK);
7 }
8
9+#if GIFLIB_MAJOR >= 5
10+static inline void
11+gif_error (const gchar *action, int err)
12+{
13+ const char *str = GifErrorString (err);
14+ if (str != NULL) {
15+ g_message ("%s, error: '%s'", action, str);
16+ } else {
17+ g_message ("%s, undefined error %d", action, err);
18+ }
19+}
20+#else /* GIFLIB_MAJOR >= 5 */
21+static inline void print_gif_error()
22+{
23+#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4)
24+ const char *str = GifErrorString ();
25+ if (str != NULL) {
26+ g_message ("GIF, error: '%s'", str);
27+ } else {
28+ g_message ("GIF, undefined error");
29+ }
30+#else
31+ PrintGifError();
32+#endif
33+}
34+#endif /* GIFLIB_MAJOR >= 5 */
35+
36+/* giflib 5.1 changed the API of DGifCloseFile to take two arguments */
37+#if !defined(GIFLIB_MAJOR) || \
38+ !(GIFLIB_MAJOR > 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1))
39+#define DGifCloseFile(a, b) DGifCloseFile(a)
40+#endif
41+
42 static void
43 read_metadata (TrackerSparqlBuilder *preupdate,
44 TrackerSparqlBuilder *metadata,
45@@ -100,14 +133,22 @@
46 ExtBlock extBlock;
47
48 if (DGifGetRecordType(gifFile, &RecordType) == GIF_ERROR) {
49- PrintGifError();
50+#if GIFLIB_MAJOR < 5
51+ print_gif_error ();
52+#else /* GIFLIB_MAJOR < 5 */
53+ gif_error ("Could not read next GIF record type", gifFile->Error);
54+#endif /* GIFLIB_MAJOR < 5 */
55 return;
56 }
57
58 switch (RecordType) {
59 case IMAGE_DESC_RECORD_TYPE:
60 if (DGifGetImageDesc(gifFile) == GIF_ERROR) {
61- PrintGifError();
62+#if GIFLIB_MAJOR < 5
63+ print_gif_error();
64+#else /* GIFLIB_MAJOR < 5 */
65+ gif_error ("Could not get GIF record information", gifFile->Error);
66+#endif /* GIFLIB_MAJOR < 5 */
67 return;
68 }
69
70@@ -117,7 +158,11 @@
71 framedata = g_malloc (framewidth*frameheight);
72
73 if (DGifGetLine(gifFile, framedata, framewidth*frameheight)==GIF_ERROR) {
74- PrintGifError();
75+#if GIFLIB_MAJOR < 5
76+ print_gif_error();
77+#else /* GIFLIB_MAJOR < 5 */
78+ gif_error ("Could not load a block of GIF pixes", gifFile->Error);
79+#endif /* GIFLIB_MAJOR < 5 */
80 return;
81 }
82
83@@ -593,6 +638,9 @@
84 gchar *filename, *uri;
85 GFile *file;
86 int fd;
87+#if GIFLIB_MAJOR >= 5
88+ int err;
89+#endif
90
91 preupdate = tracker_extract_info_get_preupdate_builder (info);
92 metadata = tracker_extract_info_get_metadata_builder (info);
93@@ -617,8 +665,14 @@
94 return FALSE;
95 }
96
97+#if GIFLIB_MAJOR < 5
98 if ((gifFile = DGifOpenFileHandle (fd)) == NULL) {
99- PrintGifError ();
100+ print_gif_error ();
101+#else /* GIFLIB_MAJOR < 5 */
102+ if ((gifFile = DGifOpenFileHandle (fd, &err)) == NULL) {
103+ gif_error ("Could not open GIF file with handle", err);
104+#endif /* GIFLIB_MAJOR < 5 */
105+ g_free (filename);
106 close (fd);
107 return FALSE;
108 }
109@@ -637,10 +691,15 @@
110 g_string_free (where, TRUE);
111
112 g_free (uri);
113-
114+#if GIFLIB_MAJOR < 5
115 if (DGifCloseFile (gifFile) != GIF_OK) {
116- PrintGifError ();
117+ print_gif_error ();
118+ }
119+#else /* GIFLIB_MAJOR < 5 */
120+ if (DGifCloseFile (gifFile, NULL) != GIF_OK) {
121+ gif_error ("Could not close GIF file", gifFile->Error);
122 }
123+#endif /* GIFLIB_MAJOR < 5 */
124
125 return TRUE;
126 }