[tracker/tracker-0.8] tracker-extract: albumart-quill: Bugfix NB#163155
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.8] tracker-extract: albumart-quill: Bugfix NB#163155
- Date: Thu, 20 May 2010 15:31:29 +0000 (UTC)
commit b3a989c6e7d01da74db988dff44056b943da6e59
Author: Philip Van Hoof <philip codeminded be>
Date: Thu May 20 16:08:56 2010 +0200
tracker-extract: albumart-quill: Bugfix NB#163155
src/tracker-extract/tracker-albumart-quill.cpp | 56 ++++++++++++++++++++---
1 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/src/tracker-extract/tracker-albumart-quill.cpp b/src/tracker-extract/tracker-albumart-quill.cpp
index f8c95a1..c33c09d 100644
--- a/src/tracker-extract/tracker-albumart-quill.cpp
+++ b/src/tracker-extract/tracker-albumart-quill.cpp
@@ -70,27 +70,67 @@ tracker_albumart_file_to_jpeg (const gchar *filename,
return TRUE;
}
+static const gchar*
+convert_content_type_to_qt (const gchar *content_type)
+{
+ guint i;
+ static const gchar *conversions[12][2] = { { "image/jpeg", "jpg" },
+ { "image/png", "png" },
+ { "image/ppm", "ppm" },
+ { "image/xbm", "xbm" },
+ { "image/xpm", "xpm" },
+ { "image/mng", "mng" },
+ { "image/tiff", "tif" },
+ { "image/bmp", "bmp" },
+ { "image/gif", "gif" },
+ { "image/pgm", "pgm" },
+ { "image/svg", "svg" },
+ { NULL, NULL }
+ };
+
+ for (i = 0; conversions[i][0] != NULL; i++)
+ {
+ if (g_strcmp0 (conversions[i][0], content_type) == 0)
+ return conversions[i][1];
+ }
+
+ return NULL;
+}
+
gboolean
tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
size_t len,
const gchar *buffer_mime,
const gchar *target)
{
+ const gchar *qt_format;
+
if (!init) {
QuillImageFilter::registerAll();
init = TRUE;
}
-
+ QImageReader *reader = NULL;
QByteArray array = QByteArray ((const char *) buffer, (int) len);
QBuffer qbuffer(&array);
qbuffer.open(QIODevice::ReadOnly);
- QImageReader reader(&qbuffer);
- QImage image = reader.read();
- QuillImageFilter *filter = QuillImageFilterFactory::createImageFilter("Save");
- filter->setOption(QuillImageFilter::FileFormat, QVariant(QString("jpeg")));
- filter->setOption(QuillImageFilter::FileName, QVariant(QString(target)));
- filter->apply(image);
- delete filter;
+ qt_format = convert_content_type_to_qt (buffer_mime);
+ if (qt_format != NULL) {
+ reader = new QImageReader::QImageReader (&qbuffer, QByteArray(qt_format));
+ } else {
+ QByteArray format = QImageReader::imageFormat(&qbuffer);
+ if (!format.isEmpty ())
+ reader = new QImageReader::QImageReader (&qbuffer, format);
+ }
+ if (reader != NULL) {
+ QImage image = reader->read();
+ QuillImageFilter *filter = QuillImageFilterFactory::createImageFilter("Save");
+ filter->setOption(QuillImageFilter::FileFormat, QVariant(QString("jpeg")));
+ filter->setOption(QuillImageFilter::FileName, QVariant(QString(target)));
+ filter->apply(image);
+ delete reader;
+ delete filter;
+ }
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]