gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3036 - in Extractor: . src/plugins


From: durner
Subject: [GNUnet-SVN] r3036 - in Extractor: . src/plugins
Date: Sat, 24 Jun 2006 09:35:06 -0700 (PDT)

Author: durner
Date: 2006-06-24 09:34:56 -0700 (Sat, 24 Jun 2006)
New Revision: 3036

Added:
   Extractor/src/plugins/thumbnailextractorqt.cc
Modified:
   Extractor/AUTHORS
   Extractor/configure.ac
   Extractor/src/plugins/Makefile.am
Log:
thumbnail extractor based on Qt

Modified: Extractor/AUTHORS
===================================================================
--- Extractor/AUTHORS   2006-06-24 16:29:19 UTC (rev 3035)
+++ Extractor/AUTHORS   2006-06-24 16:34:56 UTC (rev 3036)
@@ -29,6 +29,7 @@
 hash          - core team using GNU coreutils/textutils and GPL'ed RMD160 code.
 translit      - Nils Durner <address@hidden>
 thumbnail     - core team using GTK
+thumbnailqt   - Nils Durner <address@hidden>
 exiv2         - Andreas Huggel <address@hidden>
 language      - Roberto Cappuccio <address@hidden> (from libkat)
 word          - Ariya Hidayat <address@hidden> and Sacha Fuentes 
<address@hidden>

Modified: Extractor/configure.ac
===================================================================
--- Extractor/configure.ac      2006-06-24 16:29:19 UTC (rev 3035)
+++ Extractor/configure.ac      2006-06-24 16:34:56 UTC (rev 3036)
@@ -252,8 +252,80 @@
  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
 AC_MSG_CHECKING([whether to enable printable extractors])
 AC_ARG_ENABLE(printable,

Modified: Extractor/src/plugins/Makefile.am
===================================================================
--- Extractor/src/plugins/Makefile.am   2006-06-24 16:29:19 UTC (rev 3035)
+++ Extractor/src/plugins/Makefile.am   2006-06-24 16:34:56 UTC (rev 3036)
@@ -9,6 +9,14 @@
 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 @@
   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_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)
+

Added: Extractor/src/plugins/thumbnailextractorqt.cc
===================================================================
--- Extractor/src/plugins/thumbnailextractorqt.cc       2006-06-24 16:29:19 UTC 
(rev 3035)
+++ Extractor/src/plugins/thumbnailextractorqt.cc       2006-06-24 16:34:56 UTC 
(rev 3036)
@@ -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 */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]