commit d502541f439f605f5531f403bd8ce90acbc13608
parent d80e1f3f5f806fba69056e5efc1ba99fe9096f9e
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 15 Dec 2009 20:45:08 +0000
thumbnailgtk
Diffstat:
7 files changed, 171 insertions(+), 209 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -560,7 +560,6 @@ src/plugins/ole2/Makefile
src/plugins/oo/Makefile
src/plugins/printable/Makefile
src/plugins/hash/Makefile
-src/plugins/thumbnail/Makefile
src/plugins/thumbnailffmpeg/Makefile
src/test/Makefile
])
diff --git a/src/include/extractor.h b/src/include/extractor.h
@@ -240,10 +240,10 @@ enum EXTRACTOR_MetaType
EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE = 113,
+ EXTRACTOR_METATYPE_THUMBNAIL = 114,
/* fixme: used up to here! */
- EXTRACTOR_METATYPE_THUMBNAIL_DATA = 70,
EXTRACTOR_METATYPE_RESOLUTION = 57,
EXTRACTOR_METATYPE_SCALE = 108,
diff --git a/src/main/extractor_metatypes.c b/src/main/extractor_metatypes.c
@@ -287,6 +287,17 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
creator and the software producer? PDF and DVI
both have this distinction (i.e., Writer vs.
OpenOffice) */
+ { gettext_noop ("thumbnail"),
+ gettext_noop ("smaller version of the image for previewing") },
+ /* 115 */
+ { gettext_noop (""),
+ gettext_noop ("") },
+ { gettext_noop (""),
+ gettext_noop ("") },
+ { gettext_noop (""),
+ gettext_noop ("") },
+ { gettext_noop (""),
+ gettext_noop ("") },
{ gettext_noop (""),
gettext_noop ("") },
#if 0
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
@@ -16,7 +16,7 @@ if WITH_GSF
oledir=ole2
endif
if HAVE_GTK
-thumbgtk=thumbnail
+ thumbgtk=libextractor_thumbnailgtk.la
endif
endif
@@ -93,7 +93,8 @@ plugin_LTLIBRARIES = \
libextractor_it.la \
libextractor_mime.la \
$(pdf) \
- $(rpm)
+ $(rpm) \
+ $(thumbgtk)
libextractor_applefile_la_SOURCES = \
applefile_extractor.c
@@ -166,6 +167,14 @@ libextractor_rpm_la_LDFLAGS = \
libextractor_rpm_la_LIBADD = \
-lrpm
+libextractor_thumbnailgtk_la_CFLAGS = \
+ $(GLIB_CFLAGS) $(GTK_CFLAGS)
+libextractor_thumbnailgtk_la_LIBADD = \
+ $(LIBADD) -lgobject-2.0 @GTK_LIBS@
+libextractor_thumbnailgtk_la_LDFLAGS = \
+ $(PLUGINFLAGS)
+libextractor_thumbnailgtk_la_SOURCES = \
+ thumbnailgtk_extractor.c
diff --git a/src/plugins/thumbnail/Makefile.am b/src/plugins/thumbnail/Makefile.am
@@ -1,16 +0,0 @@
-include ../Makefile-plugins.am
-
-plugin_LTLIBRARIES = \
- libextractor_thumbnailgtk.la
-
-AM_CFLAGS = $(GLIB_CFLAGS) $(GTK_CFLAGS)
-
-libextractor_thumbnailgtk_la_CFLAGS = \
- $(GLIB_CFLAGS) $(GTK_CFLAGS)
-libextractor_thumbnailgtk_la_LIBADD = \
- $(LIBADD) -lgobject-2.0 -lgthread-2.0 @GTK_LIBS@ \
- $(top_builddir)/src/main/libextractor.la
-libextractor_thumbnailgtk_la_LDFLAGS = \
- $(PLUGINFLAGS) $(retaincommand)
-libextractor_thumbnailgtk_la_SOURCES = \
- thumbnailextractor.c
diff --git a/src/plugins/thumbnail/thumbnailextractor.c b/src/plugins/thumbnail/thumbnailextractor.c
@@ -1,189 +0,0 @@
-/*
- This file is part of libextractor.
- (C) 2005 Vidyut Samanta and Christian Grothoff
-
- libextractor is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- libextractor is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with libextractor; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file thumbnailextractor.c
- * @author Christian Grothoff
- * @brief this extractor produces a binary (!) encoded
- * thumbnail of images (using gdk pixbuf). The bottom
- * of the file includes a decoder method that can be used
- * to reproduce the 128x128 PNG thumbnails.
- */
-
-#include "platform.h"
-#include "extractor.h"
-#include <glib.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#define THUMBSIZE 128
-
-
-/* using libgobject, needs init! */
-void __attribute__ ((constructor)) ole_gobject_init ()
-{
- g_type_init ();
- if (! g_thread_supported () )
- g_thread_init (NULL);
-}
-
-
-static EXTRACTOR_KeywordList *
-addKeyword (EXTRACTOR_KeywordType type,
- char *keyword, EXTRACTOR_KeywordList * next)
-{
- EXTRACTOR_KeywordList *result;
-
- if (keyword == NULL)
- return next;
- result = malloc (sizeof (EXTRACTOR_KeywordList));
- result->next = next;
- result->keyword = keyword;
- result->keywordType = type;
- return result;
-}
-
-
-/* which mime-types maybe subjected to
- the thumbnail extractor (ImageMagick
- crashes and/or prints errors for bad
- formats, so we need to be rather
- conservative here) */
-static char *whitelist[] = {
- "image/jpeg",
- "image/gif",
- "image/miff",
- "image/mng",
- "image/png",
- "image/tiff",
- "image/x-bmp",
- "image/x-mng",
- "image/x-png",
- "image/x-xpm",
- "image/xcf",
- NULL,
-};
-
-struct EXTRACTOR_Keywords *
-libextractor_thumbnailgtk_extract (const char *filename,
- const unsigned char *data,
- size_t size,
- struct EXTRACTOR_Keywords *prev)
-{
- GdkPixbufLoader *loader;
- GdkPixbuf *in;
- GdkPixbuf *out;
- size_t length;
- char *thumb;
- unsigned long width;
- unsigned long height;
- char *binary;
- const char *mime;
- int j;
- char *format;
-
- /* if the mime-type of the file is not whitelisted
- do not run the thumbnail extactor! */
- mime = EXTRACTOR_extractLast (EXTRACTOR_MIMETYPE, prev);
- if (mime == NULL)
- return prev;
- j = 0;
- while (whitelist[j] != NULL)
- {
- if (0 == strcmp (whitelist[j], mime))
- break;
- j++;
- }
- if (whitelist[j] == NULL)
- return prev;
-
- loader = gdk_pixbuf_loader_new ();
- gdk_pixbuf_loader_write (loader, data, size, NULL);
- in = gdk_pixbuf_loader_get_pixbuf (loader);
- gdk_pixbuf_loader_close (loader, NULL);
- if (in == NULL)
- {
- g_object_unref (loader);
- return prev;
- }
- g_object_ref (in);
- g_object_unref (loader);
- height = gdk_pixbuf_get_height (in);
- width = gdk_pixbuf_get_width (in);
- format = malloc (64);
- snprintf (format, 64, "%ux%u", (unsigned int) width, (unsigned int) height);
- prev = addKeyword (EXTRACTOR_SIZE, format, prev);
- if (height == 0)
- height = 1;
- if (width == 0)
- width = 1;
- if ((height <= THUMBSIZE) && (width <= THUMBSIZE))
- {
- g_object_unref (in);
- return prev;
- }
- if (height > THUMBSIZE)
- {
- width = width * THUMBSIZE / height;
- height = THUMBSIZE;
- }
- if (width > THUMBSIZE)
- {
- height = height * THUMBSIZE / width;
- width = THUMBSIZE;
- }
- if ( (height == 0) || (width == 0) )
- {
- g_object_unref (in);
- return prev;
- }
- out = gdk_pixbuf_scale_simple (in, width, height, GDK_INTERP_BILINEAR);
- g_object_unref (in);
- thumb = NULL;
- length = 0;
- if (out == NULL)
- return prev;
- if (!gdk_pixbuf_save_to_buffer (out, &thumb, &length, "png", NULL,
- "compression", "9", NULL))
- {
- g_object_unref (out);
- return prev;
- }
- g_object_unref (out);
- if (thumb == NULL)
- return prev;
-
- binary = EXTRACTOR_binaryEncode ((const unsigned char *) thumb, length);
- free (thumb);
- if (binary == NULL)
- return prev;
- return addKeyword (EXTRACTOR_THUMBNAIL_DATA, binary, prev);
-}
-
-struct EXTRACTOR_Keywords *
-libextractor_thumbnail_extract (const char *filename,
- const unsigned char *data,
- size_t size,
- struct EXTRACTOR_Keywords *prev,
- const char *options)
-{
- return libextractor_thumbnailgtk_extract (filename, data, size, prev);
-}
-
-/* end of thumbnailextractor.c */
diff --git a/src/plugins/thumbnailgtk_extractor.c b/src/plugins/thumbnailgtk_extractor.c
@@ -0,0 +1,148 @@
+/*
+ This file is part of libextractor.
+ (C) 2005, 2009 Vidyut Samanta and Christian Grothoff
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file thumbnailextractor.c
+ * @author Christian Grothoff
+ * @brief this extractor produces a binary (!) encoded
+ * thumbnail of images (using gdk pixbuf). The bottom
+ * of the file includes a decoder method that can be used
+ * to reproduce the 128x128 PNG thumbnails.
+ */
+
+#include "platform.h"
+#include "extractor.h"
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#define THUMBSIZE 128
+
+/* using libgobject, needs init! */
+void __attribute__ ((constructor)) ole_gobject_init ()
+{
+ g_type_init ();
+}
+
+
+int
+EXTRACTOR_thumbnailgtk_extract (const char *data,
+ size_t size,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls,
+ const char *options)
+{
+ GdkPixbufLoader *loader;
+ GdkPixbuf *in;
+ GdkPixbuf *out;
+ size_t length;
+ char *thumb;
+ unsigned long width;
+ unsigned long height;
+ char format[64];
+ int ret;
+
+ loader = gdk_pixbuf_loader_new ();
+ gdk_pixbuf_loader_write (loader,
+ (const unsigned char*) data,
+ size, NULL);
+ in = gdk_pixbuf_loader_get_pixbuf (loader);
+ gdk_pixbuf_loader_close (loader, NULL);
+ if (in == NULL)
+ {
+ g_object_unref (loader);
+ return 0;
+ }
+ g_object_ref (in);
+ g_object_unref (loader);
+ height = gdk_pixbuf_get_height (in);
+ width = gdk_pixbuf_get_width (in);
+ snprintf (format,
+ sizeof(format),
+ "%ux%u",
+ (unsigned int) width,
+ (unsigned int) height);
+ if (0 != proc (proc_cls,
+ "thumbnailgtk",
+ EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ format,
+ strlen (format) + 1))
+ {
+ g_object_unref (in);
+ return 1;
+ }
+ if ((height <= THUMBSIZE) && (width <= THUMBSIZE))
+ {
+ g_object_unref (in);
+ return 0;
+ }
+ if (height > THUMBSIZE)
+ {
+ width = width * THUMBSIZE / height;
+ height = THUMBSIZE;
+ }
+ if (width > THUMBSIZE)
+ {
+ height = height * THUMBSIZE / width;
+ width = THUMBSIZE;
+ }
+ if ( (height == 0) || (width == 0) )
+ {
+ g_object_unref (in);
+ return 0;
+ }
+ out = gdk_pixbuf_scale_simple (in, width, height, GDK_INTERP_BILINEAR);
+ g_object_unref (in);
+ thumb = NULL;
+ length = 0;
+ if (out == NULL)
+ return 0;
+ if (!gdk_pixbuf_save_to_buffer (out, &thumb, &length, "png", NULL,
+ "compression", "9", NULL))
+ {
+ g_object_unref (out);
+ return 0;
+ }
+ g_object_unref (out);
+ if (thumb == NULL)
+ return 0;
+ ret = proc (proc_cls,
+ "thumbnailgtk",
+ EXTRACTOR_METATYPE_THUMBNAIL,
+ EXTRACTOR_METAFORMAT_BINARY,
+ "image/png",
+ thumb, length);
+ free (thumb);
+ return ret;
+}
+
+int
+EXTRACTOR_thumbnail_extract (const char *data,
+ size_t size,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls,
+ const char *options)
+{
+ return EXTRACTOR_thumbnailgtk_extract (data, size, proc, proc_cls, options);
+}
+
+
+/* end of thumbnailgtk_extractor.c */