libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 3547de13279c3b80d5555a24e60c633c54469d86
parent 434c43f32a7ccff6d551cd4d7cb005d8bd2a42f5
Author: Nils Durner <durner@gnunet.org>
Date:   Sat, 24 Jun 2006 16:34:56 +0000

thumbnail extractor based on Qt

Diffstat:
MAUTHORS | 1+
Mconfigure.ac | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/plugins/Makefile.am | 16++++++++++++++++
Asrc/plugins/thumbnailextractorqt.cc | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 287 insertions(+), 0 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -29,6 +29,7 @@ id3v2 - core team with Milan <milan@skoid.org> hash - core team using GNU coreutils/textutils and GPL'ed RMD160 code. translit - Nils Durner <durner@gnunet.org> thumbnail - core team using GTK +thumbnailqt - Nils Durner <durner@gnunet.org> exiv2 - Andreas Huggel <ahuggel@gmx.net> language - Roberto Cappuccio <roberto.cappuccio@gmail.com> (from libkat) word - Ariya Hidayat <ariya@kde.org> and Sacha Fuentes <mandelman@iname.com> diff --git a/configure.ac b/configure.ac @@ -252,6 +252,78 @@ else AM_CONDITIONAL(HAVE_GTK,false) fi +# check for Qt 4 +qt=0 +AC_LANG_PUSH([C++]) +AC_MSG_CHECKING(for Qt) +AC_ARG_WITH(qt, + [ --with-qt=PFX Base of Qt installation], + [AC_MSG_RESULT([$with_qt]) + case $with_qt in + no) + ;; + yes) + AC_CHECK_HEADERS(qpixmap.h, + AC_CHECK_LIB([QtGui4], [_ZN7QPixmap12defaultDepthEv], + qt=1)) + ;; + *) + LDFLAGS="-L$with_qt/lib $LDFLAGS" + CPPFLAGS="-I$with_qt/include -I$with_qt/include/Qt $CPPFLAGS" + AC_CHECK_HEADERS(qpixmap.h, + AC_CHECK_LIB([QtGui4], [_ZN7QPixmap12defaultDepthEv], + EXT_LIB_PATH="-L$with_qt/lib $EXT_LIB_PATH" + qt=1)) + ;; + esac + ], + [AC_MSG_RESULT([--with-qt not specified]) + AC_CHECK_HEADERS(qpixmap.h, + AC_CHECK_LIB([QtGui4], [_ZN7QPixmap12defaultDepthEv], + qt=1))]) + +if test x$qt != x0 +then + AC_DEFINE(HAVE_QT, 1, [We have Qt]) +fi +AM_CONDITIONAL(HAVE_QT, test x$qt != x0) + +# check for Qt SVG module +AC_MSG_CHECKING(for Qt SVG) +AC_ARG_WITH(qt, + [ --with-qt=PFX Base of Qt installation], + [AC_MSG_RESULT([$with_qt]) + case $with_qt in + no) + ;; + yes) + AC_CHECK_HEADERS(qsvgrenderer.h, + AC_CHECK_LIB([QtSvg4], [_ZN10QSvgWidgetD0Ev], + qt_svg=1)) + ;; + *) + LDFLAGS="-L$with_qt/lib $LDFLAGS" + CPPFLAGS="-I$with_qt/include -I$with_qt/include/Qt $CPPFLAGS" + AC_CHECK_HEADERS(qsvgrenderer.h, + AC_CHECK_LIB([QtSvg4], [_ZN10QSvgWidgetD0Ev], + EXT_LIB_PATH="-L$with_qt/lib $EXT_LIB_PATH" + qt_svg=1)) + ;; + esac + ], + [AC_MSG_RESULT([--with-qt not specified]) + AC_CHECK_HEADERS(qsvgrenderer.h, + AC_CHECK_LIB([QtSvg4], [_ZN10QSvgWidgetD0Ev], + qt_svg=1))]) + +if test x$qt_svg != x0 +then + AC_DEFINE(HAVE_QT_SVG, 1, [We have Qt SVG]) +fi +AM_CONDITIONAL(HAVE_QT_SVG, test x$qt_svg != x0) + + +AC_LANG_POP([C++]) printable=1 diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -9,6 +9,14 @@ thumbdir=thumbnail endif endif +if HAVE_QT + thumbqt=libextractor_thumbnailqt.la +endif + +if HAVE_QT_SVG + svgflags = -lQtSvg4 +endif + if HAVE_PRINTABLE printdir=printable endif @@ -72,6 +80,7 @@ plugin_LTLIBRARIES = $(pdfplugin) \ libextractor_split.la \ libextractor_tar.la \ libextractor_tiff.la \ + $(thumbqt) \ libextractor_translit.la \ libextractor_wav.la \ libextractor_zip.la @@ -290,3 +299,10 @@ libextractor_translit_la_SOURCES = \ libextractor_translit_la_LDFLAGS = \ $(PLUGINFLAGS) $(retaincommand) +libextractor_thumbnailqt_la_SOURCES = \ + thumbnailextractorqt.cc +libextractor_thumbnailqt_la_LIBADD = \ + $(top_builddir)/src/main/libextractor.la +libextractor_thumbnailqt_la_LDFLAGS = \ + $(PLUGINFLAGS) $(retaincommand) -lQtCore4 -lQtGui4 $(svgflags) + diff --git a/src/plugins/thumbnailextractorqt.cc b/src/plugins/thumbnailextractorqt.cc @@ -0,0 +1,198 @@ +/* + This file is part of libextractor. + (C) 2006 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 thumbnailextractorqt.cc + * @author Nils Durner + * @brief this extractor produces a binary (!) encoded + * thumbnail of images (using Qt). + */ + +#include "platform.h" +#include "extractor.h" +#include <qpixmap.h> +#include <qbytearray.h> +#include <qbuffer.h> +#include <qapplication.h> + +#ifdef HAVE_QT_SVG + #include <qsvgrenderer.h> + #include <qpainter.h> +#endif + +#define THUMBSIZE 128 + +extern "C" +{ + +QApplication *app; +char *argv; + +void __attribute__ ((constructor)) thumnailextractorqt_init(void) +{ + int argc = 0; + + argv = strdup(""); + app = new QApplication(argc, &argv); +} + +void __attribute__ ((destructor)) my_fini(void) +{ + delete app; + free(argv); +} + +static EXTRACTOR_KeywordList * addKeyword(EXTRACTOR_KeywordType type, + char * keyword, + EXTRACTOR_KeywordList * next) { + EXTRACTOR_KeywordList * result; + + if (keyword == NULL) + return next; + result = (EXTRACTOR_KeywordList *) 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/x-bmp", + "image/gif", + "image/jpeg", + "image/png", + "image/x-png", + "image/x-portable-bitmap", + "image/x-portable-graymap", + "image/x-portable-pixmap", + "image/x-xbitmap", + "image/x-xpixmap" + "image/x-xpm", +#ifdef HAVE_QT_SVG + "image/svg+xml", +#endif + NULL +}; + +struct EXTRACTOR_Keywords * libextractor_thumbnailqt_extract(const char * filename, + const unsigned char * data, + size_t size, + struct EXTRACTOR_Keywords * prev) { + QPixmap img; + QByteArray bytes; + QBuffer buffer; + 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; + +#ifdef HAVE_QT_SVG + if (strcmp(mime, "image/svg+xml") == 0) + { + /* Render SVG image */ + QSvgRenderer svg; + QSize size; + + if (! svg.load(QByteArray((const char *) data))) + return prev; + + size = svg.defaultSize(); + img = QPixmap(size); + + QPainter painter(&img); + painter.setViewport(0, 0, size.width(), size.height()); + painter.eraseRect(0, 0, size.width(), size.height()); + + svg.render(&painter); + } + else +#endif + /* Load image */ + img.loadFromData(data, size); + + height = img.height(); + width = img.width(); + format = (char *) 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 = width * THUMBSIZE / height; + height = THUMBSIZE; + } + if (width > THUMBSIZE) { + height = height * THUMBSIZE / width; + width = THUMBSIZE; + } + + img = img.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); + buffer.setBuffer(&bytes); + buffer.open(QIODevice::WriteOnly); + img.save(&buffer, "PNG"); + + binary + = EXTRACTOR_binaryEncode((const unsigned char*) bytes.data(), + bytes.length()); + + if (binary == NULL) + return prev; + + return addKeyword(EXTRACTOR_THUMBNAIL_DATA, + binary, + prev); +} + +} // extern "C" + +/* end of thumbnailextractorqt.cc */