SVN commit 540279 by cgilles:
digikam from trunk : - New DMetadata method to set Exif thumbnail. - New DMetadata method to set Exif Image dimensions. - CameraGUI : Exif auto rotate update Exif image dimensions and Thumbnail during download. - ImageEditor : update Exif image dimensions and Thumbnail during save picture operation. CCMAIL: [hidden email] M +26 -3 libs/dmetadata/dmetadata.cpp M +1 -0 libs/dmetadata/dmetadata.h M +17 -1 libs/jpegutils/exifrotate.cpp M +10 -3 utilities/imageeditor/canvas/dimginterface.cpp --- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.cpp #540278:540279 @@ -34,6 +34,7 @@ // KDE includes. #include <kdebug.h> +#include <ktempfile.h> // Exiv2 includes. @@ -319,14 +320,14 @@ { if (fixOrientation) { - Exiv2::ExifKey key("Exif.Image.Orientation"); + Exiv2::ExifKey key("Exif.Thumbnail.Orientation"); Exiv2::ExifData exifData(d->exifMetadata); Exiv2::ExifData::iterator it = exifData.findKey(key); if (it != exifData.end()) { QWMatrix matrix; long orientation = it->toLong(); - kdDebug() << " Exif Orientation: " << orientation << endl; + kdDebug() << " Exif Thumbnail Orientation: " << orientation << endl; switch (orientation) { @@ -374,7 +375,7 @@ } catch( Exiv2::Error &e ) { - kdDebug() << "Cannot parse Exif Thumbnail using Exiv2 (" + kdDebug() << "Cannot get Exif Thumbnail using Exiv2 (" << QString::fromLocal8Bit(e.what().c_str()) << ")" << endl; } @@ -382,6 +383,28 @@ return thumbnail; } +bool DMetadata::setExifThumbnail(const QImage& thumb) +{ + try + { + KTempFile thumbFile(QString::null, "DigikamDMetadataThumb"); + thumbFile.setAutoDelete(true); + thumb.save(thumbFile.name(), "JPEG"); + + const std::string &fileName( (const char*)(QFile::encodeName(thumbFile.name())) ); + d->exifMetadata.setJpegThumbnail( fileName ); + return true; + } + catch( Exiv2::Error &e ) + { + kdDebug() << "Cannot set Exif Thumbnail using Exiv2 (" + << QString::fromLocal8Bit(e.what().c_str()) + << ")" << endl; + } + + return false; +} + QSize DMetadata::getImageDimensions() { if (d->exifMetadata.empty()) --- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.h #540278:540279 @@ -95,6 +95,7 @@ int getImageRating() const; QStringList getImageKeywords() const; + bool setExifThumbnail(const QImage& thumb); bool setImageDimensions(const QSize& size); bool setImageOrientation(ImageOrientation orientation); bool setImageDateTime(const QDateTime& dateTime); --- trunk/extragear/graphics/digikam/libs/jpegutils/exifrotate.cpp #540278:540279 @@ -44,6 +44,7 @@ #include <qcstring.h> #include <qfile.h> #include <qfileinfo.h> +#include <qimage.h> // KDE includes. @@ -214,12 +215,27 @@ fclose(input_file); fclose(output_file); - // reset the orientation of the temp file to normal + // -- Metadata operations ------------------------------------------------------ + + // Reset the Exif orientation tag of the temp image to normal kdDebug() << "ExifRotate: set Orientation tag to normal: " << file << endl; exifData.load(temp); exifData.setImageOrientation(DMetadata::ORIENTATION_NORMAL); + + // Get the new image dimension of the temp image. Using a dummy QImage objet here + // has a sense because the Exif dimension informations can be missing from original image. + // Get new dimensions with QImage will always work... + QImage img(temp); + exifData.setImageDimensions(img.size()); + + // Update the thumbnail. + QImage thumb = img.scale(160, 120, QImage::ScaleMin); + exifData.setExifThumbnail(thumb); + + // We update all new metadata now... exifData.applyChanges(); + // ----------------------------------------------------------------------------- // set the file modification time of the temp file to that // of the original file struct stat st; --- trunk/extragear/graphics/digikam/utilities/imageeditor/canvas/dimginterface.cpp #540278:540279 @@ -542,6 +542,14 @@ d->image.setAttribute("compress", iofileSettings->TIFFCompression); d->savingFilename = fileName; + + // update Exif thumbnail. + DMetadata meta; + meta.setExif(d->image.getExif()); + QImage thumb = d->image.smoothScale(160, 120, QSize::ScaleMin).copyQImage(); + meta.setExifThumbnail(thumb); + d->image.setExif(meta.getExif()); + d->thread->save(d->image, fileName, mimeType); } @@ -551,9 +559,7 @@ return; if (!success) - { kdWarning() << "error saving image '" << QFile::encodeName(filePath).data() << endl; - } emit signalImageSaved(filePath, success); emit signalUndoStateChanged(d->undoMan->anyMoreUndo(), d->undoMan->anyMoreRedo(), !d->undoMan->isAtOrigin()); @@ -588,9 +594,10 @@ { DMetadata meta; meta.setExif(d->image.getExif()); + + // Update Exif Image dimensions. meta.setImageDimensions(d->image.size()); d->image.setExif(meta.getExif()); - // TODO: Update Exif Thumbnail here ! emit signalModified(); emit signalUndoStateChanged(d->undoMan->anyMoreUndo(), d->undoMan->anyMoreRedo(), !d->undoMan->isAtOrigin()); _______________________________________________ Digikam-devel mailing list [hidden email] https://mail.kde.org/mailman/listinfo/digikam-devel |
Free forum by Nabble | Edit this page |