Re: Creating a new image loader
Aurélien Gâteau <[email protected]>
| Newsgroups | gmane.comp.kde.gwenview |
|---|---|
| Message-ID | <[email protected]> |
On Monday 06 August 2007 23:04:06 Aurélien Gâteau wrote: > On Friday 03 August 2007 09:17:38 Ruben Lopez wrote: > > Hello Aurélien, > > > > Could you test the last code with gwenview? Any hint on what else to > > change in the plugin to help it work? > > > > Thanks! > > So sorry about that :-( > Looking at it right now. Done! Looking at the code from KMimeType::findByContent(), I realized it does not care about the "Header" entries of *.kimgio files. Attached patch should fix the problem. Tell me if it works for you. Aurélien ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Gwenview-general mailing list Gwenview-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/gwenview-general
imageloader_kimageio.diff
(text/x-diff, 1.8 KB)
Index: gvcore/imageloader.cpp
===================================================================
--- gvcore/imageloader.cpp (révision 671034)
+++ gvcore/imageloader.cpp (copie de travail)
@@ -29,6 +29,7 @@
// KDE
#include <kapplication.h>
+#include <kimageio.h>
#include <kmimetype.h>
// Local
@@ -437,6 +438,16 @@
}
}
+// There is no way in KImageIO to get the mimeType from the image format.
+// This function assumes KImageIO::types and KImageIO::mimeTypes return items
+// in the same order (which they do, according to the source code).
+static QString mimeTypeFromFormat(const char* format) {
+ QStringList formats = KImageIO::types(KImageIO::Reading);
+ QStringList mimeTypes = KImageIO::mimeTypes(KImageIO::Reading);
+ int pos = formats.findIndex(QString::fromAscii(format));
+ Q_ASSERT(pos != -1);
+ return mimeTypes[pos];
+}
void ImageLoader::slotDataReceived(KIO::Job* job, const QByteArray& chunk) {
LOG2("size: " << chunk.size());
@@ -448,9 +459,18 @@
if (oldSize==0) {
// Try to determine the data type
- KMimeType::Ptr ptr = KMimeType::findByContent(d->mRawData);
- d->mMimeType = ptr->name();
- d->mURLKind = MimeTypeUtils::mimeTypeKind(d->mMimeType);
+ QBuffer buffer(d->mRawData);
+ buffer.open(IO_ReadOnly);
+ const char* format = QImageIO::imageFormat(&buffer);
+ if (format) {
+ // This is a raster image, get the mime type now
+ d->mURLKind = MimeTypeUtils::KIND_RASTER_IMAGE;
+ d->mMimeType = mimeTypeFromFormat(format);
+ } else {
+ KMimeType::Ptr ptr = KMimeType::findByContent(d->mRawData);
+ d->mMimeType = ptr->name();
+ d->mURLKind = MimeTypeUtils::mimeTypeKind(d->mMimeType);
+ }
if (d->mURLKind!=MimeTypeUtils::KIND_RASTER_IMAGE) {
Q_ASSERT(!d->mDecoderTimer.isActive());
job->kill(true /* quietly */);