[Digikam-devel] extragear/graphics/digikam/libs/dmetadata
Gilles Caulier
caulier.gilles at free.fr
Wed Jun 21 12:06:23 BST 2006
SVN commit 553520 by cgilles:
digikam from trunk : DMetadata : new method to set IPTC preview image. We will use it to store a JPEG image preview used by digiKam preview tool to render the image to the screen.
In a first time storing IPTC preview wwill be done by Image editor. Later we can do it during Camera download on the fly.
CCMAIL: digikam-devel at kde.org
M +50 -8 dmetadata.cpp
M +2 -1 dmetadata.h
--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.cpp #553519:553520
@@ -161,7 +161,8 @@
{
try
{
- d->exifMetadata.load((const Exiv2::byte*)data.data(), data.size());
+ if (!data.isEmpty())
+ d->exifMetadata.load((const Exiv2::byte*)data.data(), data.size());
}
catch( Exiv2::Error &e )
{
@@ -175,7 +176,8 @@
{
try
{
- d->exifMetadata.load(data.pData_, data.size_);
+ if (data.size_ != 0)
+ d->exifMetadata.load(data.pData_, data.size_);
}
catch( Exiv2::Error &e )
{
@@ -189,7 +191,8 @@
{
try
{
- d->iptcMetadata.load((const Exiv2::byte*)data.data(), data.size());
+ if (!data.isEmpty())
+ d->iptcMetadata.load((const Exiv2::byte*)data.data(), data.size());
}
catch( Exiv2::Error &e )
{
@@ -203,7 +206,8 @@
{
try
{
- d->iptcMetadata.load(data.pData_, data.size_);
+ if (data.size_ != 0)
+ d->iptcMetadata.load(data.pData_, data.size_);
}
catch( Exiv2::Error &e )
{
@@ -1537,15 +1541,15 @@
return QByteArray();
}
-bool DMetadata::getImagePreview(QImage& image)
+bool DMetadata::getImagePreview(QImage& preview)
{
try
{
- // Minolta camera preview extraction.
- if (image.loadFromData(getExifTagData("Exif.Minolta.Thumbnail")) )
+ // In first we trying to get from Iptc preview tag.
+ if (preview.loadFromData(getIptcTagData("Iptc.Application2.Preview")) )
return true;
- // TODO : Added here other makernotes preview extraction
+ // TODO : Added here Makernotes preview extraction when Exiv2 will be fixed for that.
}
catch( Exiv2::Error &e )
{
@@ -1557,4 +1561,42 @@
return false;
}
+bool DMetadata::setImagePreview(const QImage& preview)
+{
+ try
+ {
+ KTempFile previewFile(QString::null, "DigikamDMetadataPreview");
+ previewFile.setAutoDelete(true);
+ // Very compressed preview to limit IPTC size
+ preview.save(previewFile.name(), "JPEG", 50);
+
+ QFile file(previewFile.name());
+ if ( !file.open(IO_ReadOnly) )
+ return false;
+
+ QByteArray data(file.size());
+ QDataStream stream( &file );
+ stream.readRawBytes(data.data(), data.size());
+ file.close();
+
+ Exiv2::DataValue val;
+ val.read((Exiv2::byte *)data.data(), data.size());
+ d->iptcMetadata["Iptc.Application2.Preview"] = val;
+
+ // See http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf Appendix A for details.
+ d->iptcMetadata["Iptc.Application2.PreviewFormat"] = 11; // JPEG
+ d->iptcMetadata["Iptc.Application2.PreviewVersion"] = 1;
+
+ return true;
+ }
+ catch( Exiv2::Error &e )
+ {
+ kdDebug() << "Cannot get image preview using Exiv2 ("
+ << QString::fromLocal8Bit(e.what().c_str())
+ << ")" << endl;
+ }
+
+ return false;
+}
+
} // NameSpace Digikam
--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.h #553519:553520
@@ -105,7 +105,7 @@
QByteArray getIptcTagData(const char *iptcTagName) const;
ImageColorWorkSpace getImageColorWorkSpace();
- bool getImagePreview(QImage& image);
+ bool getImagePreview(QImage& preview);
QSize getImageDimensions();
ImageOrientation getImageOrientation();
QDateTime getImageDateTime() const;
@@ -116,6 +116,7 @@
bool setExifTagString(const char *exifTagName, const QString& value);
bool setExifThumbnail(const QImage& thumb);
bool setImageColorWorkSpace(ImageColorWorkSpace workspace);
+ bool setImagePreview(const QImage& preview);
bool setImageDimensions(const QSize& size);
bool setImageOrientation(ImageOrientation orientation);
bool setImageDateTime(const QDateTime& dateTime, bool setDateTimeDigitized = false);
More information about the Digikam-devel
mailing list