[Digikam-devel] extragear/graphics/digikam/libs/dimg

Gilles Caulier caulier.gilles at free.fr
Mon Apr 17 21:19:08 BST 2006


SVN commit 530854 by cgilles:

digikam from trunk : DImg API to detect image file formatn we parse file extension in first, and in second, we parse file header.

This way is mandatory because some TIFF files are detected like RAW files by dcraw::parse method. 

Please, update svn and give me a feedback (:=)))...
 
CCMAIL:  digikam-devel at kde.org, frank at birnstiel.org, dudasg at freemail.hu

 M  +22 -2     dimg.cpp  


--- trunk/extragear/graphics/digikam/libs/dimg/dimg.cpp #530853:530854
@@ -34,6 +34,7 @@
 // Qt includes.
 
 #include <qfile.h>
+#include <qfileinfo.h>
 #include <qmap.h>
 
 // KDE includes.
@@ -96,7 +97,6 @@
     allocateData();
 }
 
-
 DImg::~DImg()
 {
     if (m_priv->deref())
@@ -284,7 +284,6 @@
 
 bool DImg::load(const QString& filePath, DImgLoaderObserver *observer,
                 RawDecodingSettings rawDecodingSettings)
-
 {
     FORMAT format = fileFormat(filePath);
 
@@ -430,6 +429,27 @@
     if ( filePath == QString::null )
         return NONE;
 
+    // In first we trying to check the file extension. This is mandatory because
+    // some tiff files are detected like RAW files by dcraw::parse method.
+
+    QFileInfo fileInfo(filePath);
+    if (!fileInfo.exists())
+    {
+        kdDebug() << k_funcinfo << "Failed to open file" << endl;
+        return NONE;
+    }
+    
+    QString ext = fileInfo.extension().upper();
+
+    if (ext == QString("JPEG") || ext == QString("JPG"))
+        return JPEG;
+    else if (ext == QString("PNG"))
+        return PNG;
+    else if (ext == QString("TIFF") || ext == QString("TIF"))
+        return TIFF;
+
+    // In second, we trying to parse file header.
+
     FILE* f = fopen(QFile::encodeName(filePath), "rb");
     
     if (!f)



More information about the Digikam-devel mailing list