diff options
Diffstat (limited to 'src/plugins/old/thumbnailgtk_extractor.c')
-rw-r--r-- | src/plugins/old/thumbnailgtk_extractor.c | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/src/plugins/old/thumbnailgtk_extractor.c b/src/plugins/old/thumbnailgtk_extractor.c new file mode 100644 index 0000000..51e3ea4 --- /dev/null +++ b/src/plugins/old/thumbnailgtk_extractor.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2005, 2009 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file thumbnailextractor.c | ||
23 | * @author Christian Grothoff | ||
24 | * @brief this extractor produces a binary (!) encoded | ||
25 | * thumbnail of images (using gdk pixbuf). The bottom | ||
26 | * of the file includes a decoder method that can be used | ||
27 | * to reproduce the 128x128 PNG thumbnails. | ||
28 | */ | ||
29 | |||
30 | #include "platform.h" | ||
31 | #include "extractor.h" | ||
32 | #include <glib.h> | ||
33 | #include <gdk-pixbuf/gdk-pixbuf.h> | ||
34 | |||
35 | #define THUMBSIZE 128 | ||
36 | |||
37 | /* using libgobject, needs init! */ | ||
38 | void __attribute__ ((constructor)) ole_gobject_init () | ||
39 | { | ||
40 | g_type_init (); | ||
41 | } | ||
42 | |||
43 | |||
44 | const char * | ||
45 | EXTRACTOR_thumbnailgtk_options () | ||
46 | { | ||
47 | /* | ||
48 | Since the Gnome developers think that being unable to | ||
49 | unload plugins is an 'acceptable' limitation, we | ||
50 | require out-of-process execution for plugins depending | ||
51 | on libgsf and other glib-based plugins. | ||
52 | See also https://bugzilla.gnome.org/show_bug.cgi?id=374940 | ||
53 | */ | ||
54 | return "oop-only"; | ||
55 | } | ||
56 | |||
57 | |||
58 | int | ||
59 | EXTRACTOR_thumbnailgtk_extract (const char *data, | ||
60 | size_t size, | ||
61 | EXTRACTOR_MetaDataProcessor proc, | ||
62 | void *proc_cls, | ||
63 | const char *options) | ||
64 | { | ||
65 | GdkPixbufLoader *loader; | ||
66 | GdkPixbuf *in; | ||
67 | GdkPixbuf *out; | ||
68 | size_t length; | ||
69 | char *thumb; | ||
70 | unsigned long width; | ||
71 | unsigned long height; | ||
72 | char format[64]; | ||
73 | int ret; | ||
74 | |||
75 | loader = gdk_pixbuf_loader_new (); | ||
76 | gdk_pixbuf_loader_write (loader, | ||
77 | (const unsigned char*) data, | ||
78 | size, NULL); | ||
79 | in = gdk_pixbuf_loader_get_pixbuf (loader); | ||
80 | gdk_pixbuf_loader_close (loader, NULL); | ||
81 | if (in == NULL) | ||
82 | { | ||
83 | g_object_unref (loader); | ||
84 | return 0; | ||
85 | } | ||
86 | g_object_ref (in); | ||
87 | g_object_unref (loader); | ||
88 | height = gdk_pixbuf_get_height (in); | ||
89 | width = gdk_pixbuf_get_width (in); | ||
90 | snprintf (format, | ||
91 | sizeof(format), | ||
92 | "%ux%u", | ||
93 | (unsigned int) width, | ||
94 | (unsigned int) height); | ||
95 | if (0 != proc (proc_cls, | ||
96 | "thumbnailgtk", | ||
97 | EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, | ||
98 | EXTRACTOR_METAFORMAT_UTF8, | ||
99 | "text/plain", | ||
100 | format, | ||
101 | strlen (format) + 1)) | ||
102 | { | ||
103 | g_object_unref (in); | ||
104 | return 1; | ||
105 | } | ||
106 | if ((height <= THUMBSIZE) && (width <= THUMBSIZE)) | ||
107 | { | ||
108 | g_object_unref (in); | ||
109 | return 0; | ||
110 | } | ||
111 | if (height > THUMBSIZE) | ||
112 | { | ||
113 | width = width * THUMBSIZE / height; | ||
114 | height = THUMBSIZE; | ||
115 | } | ||
116 | if (width > THUMBSIZE) | ||
117 | { | ||
118 | height = height * THUMBSIZE / width; | ||
119 | width = THUMBSIZE; | ||
120 | } | ||
121 | if ( (height == 0) || (width == 0) ) | ||
122 | { | ||
123 | g_object_unref (in); | ||
124 | return 0; | ||
125 | } | ||
126 | out = gdk_pixbuf_scale_simple (in, width, height, GDK_INTERP_BILINEAR); | ||
127 | g_object_unref (in); | ||
128 | thumb = NULL; | ||
129 | length = 0; | ||
130 | if (out == NULL) | ||
131 | return 0; | ||
132 | if (!gdk_pixbuf_save_to_buffer (out, &thumb, &length, "png", NULL, | ||
133 | "compression", "9", NULL)) | ||
134 | { | ||
135 | g_object_unref (out); | ||
136 | return 0; | ||
137 | } | ||
138 | g_object_unref (out); | ||
139 | if (thumb == NULL) | ||
140 | return 0; | ||
141 | ret = proc (proc_cls, | ||
142 | "thumbnailgtk", | ||
143 | EXTRACTOR_METATYPE_THUMBNAIL, | ||
144 | EXTRACTOR_METAFORMAT_BINARY, | ||
145 | "image/png", | ||
146 | thumb, length); | ||
147 | free (thumb); | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | int | ||
152 | EXTRACTOR_thumbnail_extract (const char *data, | ||
153 | size_t size, | ||
154 | EXTRACTOR_MetaDataProcessor proc, | ||
155 | void *proc_cls, | ||
156 | const char *options) | ||
157 | { | ||
158 | return EXTRACTOR_thumbnailgtk_extract (data, size, proc, proc_cls, options); | ||
159 | } | ||
160 | |||
161 | |||
162 | /* end of thumbnailgtk_extractor.c */ | ||