[Digikam-devel] extragear/graphics/digikam/libs/dimg
Gilles Caulier
caulier.gilles at free.fr
Mon Jun 19 20:46:19 BST 2006
SVN commit 553041 by cgilles:
digikam from trunk : DImg::ImageLoader : If no embedded ICC profile is available in RAW, JPEG, PNG, and TIFF, well try to use Exif metadata :
- 1/ check "Exif.Image.InterColorProfile" exif tag witch can contains an ICC color-space profile.
- 2/ if this tags is empty, check "Exif.Photo.ColorSpace" witch can indicate if the image have already converted in a color space : sRGB or AdobeRGB.
In this case, use the right ICC color-space profile file available with digiKam.
this way will prevent to re-convert again an image to a color-space if there is no ICC embedded profile available.
CCMAIL: digikam-devel at kde.org, fj.cruz at supercable.es
M +49 -0 dimgloader.cpp
M +2 -0 dimgloader.h
M +5 -0 loaders/jpegloader.cpp
M +5 -1 loaders/pngloader.cpp
M +2 -0 loaders/rawloader.cpp
M +5 -0 loaders/tiffloader.cpp
--- trunk/extragear/graphics/digikam/libs/dimg/dimgloader.cpp #553040:553041
@@ -19,6 +19,11 @@
*
* ============================================================ */
+// KDE includes.
+
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
// Local includes.
#include "dimgprivate.h"
@@ -135,4 +140,48 @@
metaDataToFile.applyChanges();
}
+bool DImgLoader::checkExifWorkingColorSpace()
+{
+ DMetadata metaData;
+ metaData.setExif(m_image->getExif());
+
+ // Check if Exif data contains an ICC color profile.
+ QByteArray profile = metaData.getExifTagData("Exif.Image.InterColorProfile");
+ if (!profile.isNull())
+ {
+ kdDebug() << "Found an ICC profile in Exif metadata" << endl;
+ m_image->setICCProfil(profile);
+ return true;
+ }
+
+ // Else check the Exif color-space tag and use a default profiles available in digiKam.
+ KGlobal::dirs()->addResourceType("profiles", KGlobal::dirs()->kde_default("data") + "digikam/profiles");
+
+ switch(metaData.getImageColorWorkSpace())
+ {
+ case DMetadata::WORKSPACE_SRGB:
+ {
+ QString directory = KGlobal::dirs()->findResourceDir("profiles", "srgb.icm");
+ m_image->getICCProfilFromFile(directory + "srgb.icm");
+ kdDebug() << "Exif color-space tag is sRGB. Using default sRGB ICC profile." << endl;
+ return true;
+ break;
+ }
+
+ case DMetadata::WORKSPACE_ADOBERGB:
+ {
+ QString directory = KGlobal::dirs()->findResourceDir("profiles", "adobergb.icm");
+ m_image->getICCProfilFromFile(directory + "adobergb.icm");
+ kdDebug() << "Exif color-space tag is AdobeRGB. Using default AdobeRGB ICC profile." << endl;
+ return true;
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return false;
+}
+
} // NameSpace Digikam
--- trunk/extragear/graphics/digikam/libs/dimg/dimgloader.h #553040:553041
@@ -78,6 +78,8 @@
virtual void readMetadata(const QString& filePath, DImg::FORMAT ff);
virtual void saveMetadata(const QString& filePath);
virtual int granularity(DImgLoaderObserver *observer, int total, float progressSlice = 1.0);
+
+ bool checkExifWorkingColorSpace();
protected:
--- trunk/extragear/graphics/digikam/libs/dimg/loaders/jpegloader.cpp #553040:553041
@@ -404,6 +404,11 @@
metaData.insert(DImg::ICC, profile_rawdata);
free (profile_data);
}
+ else
+ {
+ // If ICC profile is null, check Exif metadata.
+ checkExifWorkingColorSpace();
+ }
// -------------------------------------------------------------------
--- trunk/extragear/graphics/digikam/libs/dimg/loaders/pngloader.cpp #553040:553041
@@ -360,7 +360,6 @@
}
png_read_rows(png_ptr, lines+y, NULL, 1);
-
}
}
@@ -407,6 +406,11 @@
memcpy(profile_rawdata.data(), profile_data, profile_size);
metaData.insert(DImg::ICC, profile_rawdata);
}
+ else
+ {
+ // If ICC profile is null, check Exif metadata.
+ checkExifWorkingColorSpace();
+ }
// -------------------------------------------------------------------
// Get embbeded text data.
--- trunk/extragear/graphics/digikam/libs/dimg/loaders/rawloader.cpp #553040:553041
@@ -81,6 +81,8 @@
bool RAWLoader::load(const QString& filePath, DImgLoaderObserver *observer)
{
readMetadata(filePath, DImg::RAW);
+ checkExifWorkingColorSpace();
+
return ( loadFromDcraw(filePath, observer) );
}
--- trunk/extragear/graphics/digikam/libs/dimg/loaders/tiffloader.cpp #553040:553041
@@ -163,6 +163,11 @@
memcpy(profile_rawdata.data(), profile_data, profile_size);
metaData.insert(DImg::ICC, profile_rawdata);
}
+ else
+ {
+ // If ICC profile is null, check Exif metadata.
+ checkExifWorkingColorSpace();
+ }
// -------------------------------------------------------------------
// Get image data.
More information about the Digikam-devel
mailing list