Update libkexiv2 to version 0.1.9

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libkexiv2@1232460 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
parent f83c303ef5
commit 84d52ca133

@ -1,13 +1,13 @@
METASOURCES = AUTO
KDE_CXXFLAGS = $(USE_EXCEPTIONS)
INCLUDES= $(all_includes)
INCLUDES= $(EXIV2_CFLAGS) $(all_includes)
lib_LTLIBRARIES = libkexiv2.la
libkexiv2_la_SOURCES = kexiv2.cpp
libkexiv2_la_SOURCES = kexiv2.cpp kexiv2private.cpp
libkexiv2_version_info = 4:0:1
libkexiv2_version_info = 5:0:0
libkexiv2_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -version-info $(libkexiv2_version_info) -no-undefined
libkexiv2_la_LIBADD = $(EXIV2_LIBS) $(LIB_KDECORE) $(LIB_QT)

File diff suppressed because it is too large Load Diff

@ -6,8 +6,8 @@
* Date : 2006-09-15
* Description : Exiv2 library interface for KDE
*
* Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2007 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* Exiv2: http://www.exiv2.org
* Exif : http://www.exif.org/Exif2-2.PDF
@ -17,7 +17,7 @@
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -28,10 +28,6 @@
#ifndef KEXIV2_H
#define KEXIV2_H
// C++ includes.
#include <string>
// QT includes.
#include <qcstring.h>
@ -44,15 +40,6 @@
#include "libkexiv2_export.h"
namespace Exiv2
{
class DataBuf;
class Exifdatum;
class ExifData;
class IptcData;
class Error;
}
namespace KExiv2Iface
{
@ -63,7 +50,8 @@ class LIBKEXIV2_EXPORT KExiv2
public:
/** The image color workspace values given by Exif metadata. */
/** The image color workspace values given by Exif metadata.
*/
enum ImageColorWorkSpace
{
WORKSPACE_UNSPECIFIED = 0,
@ -72,7 +60,8 @@ public:
WORKSPACE_UNCALIBRATED = 65535
};
/** The image orientation values given by Exif metadata. */
/** The image orientation values given by Exif metadata.
*/
enum ImageOrientation
{
ORIENTATION_UNSPECIFIED = 0,
@ -87,143 +76,192 @@ public:
};
/** A map used by decodeExifMetadata() decodeIptcMetadata() methods
to store Tags Key and Tags Value. */
to store Tags Key and Tags Value.
*/
typedef QMap<QString, QString> MetaDataMap;
public:
/** Standard constructor. */
/** Standard constructor.
*/
KExiv2();
/** Contructor to Load Metadata from image file. */
/** Contructor to Load Metadata from image file.
*/
KExiv2(const QString& filePath);
/** Standard destructor */
/** Standard destructor
*/
virtual ~KExiv2();
/** Return a string version of Exiv2 release in format "major.minor.patch" */
/** Return true if library can writte metadata to typeMime file format.
*/
static bool supportMetadataWritting(const QString& typeMime);
/** Return a string version of Exiv2 release in format "major.minor.patch"
*/
static QString Exiv2Version();
/** Return a string version of libkexiv2 release */
/** Return a string version of libkexiv2 release
*/
static QString version();
/** Generic method to print the Exiv2 C++ Exception error message from 'e'.
'msg' string is printed just before like debug header.
*/
static void printExiv2ExceptionError(const QString& msg, Exiv2::Error& e);
//-- Metadata manipulation methods ----------------------------------------------
/** Clear the Comments metadata container in memory. */
/** Clear the Comments metadata container in memory.
*/
bool clearComments();
/** Clear the Exif metadata container in memory. */
/** Clear the Exif metadata container in memory.
*/
bool clearExif();
/** Clear the Iptc metadata container in memory. */
/** Clear the Iptc metadata container in memory.
*/
bool clearIptc();
/** Return the file path open with the current instance of interface. */
/** Return the file path open with the current instance of interface.
*/
QString getFilePath() const;
/** Return a Qt byte array copy of Comments container get from current image.
Comments are JFIF section of JPEG images. Look Exiv2 API for more information.
Return a null Qt byte array if there is no Comments metadata in memory. */
Return a null Qt byte array if there is no Comments metadata in memory.
*/
QByteArray getComments() const;
/** Return a Qt string object of Comments from current image decoded using
the 'detectEncodingAndDecode()' method. Return a null string if there is no
Comments metadata available. */
Comments metadata available.
*/
QString getCommentsDecoded() const;
/** Return a Qt byte array copy of Exif container get from current image.
Return a null Qt byte array if there is no Exif metadata in memory. */
Return a null Qt byte array if there is no Exif metadata in memory.
*/
QByteArray getExif() const;
/** Return a Qt byte array copy of Iptc container get from current image.
Set true 'addIrbHeader' parameter to add an Irb header to IPTC metadata.
Return a null Qt byte array if there is no Iptc metadata in memory. */
Return a null Qt byte array if there is no Iptc metadata in memory.
*/
QByteArray getIptc(bool addIrbHeader=false) const;
/** Set the Comments data using a Qt byte array. Return true if Comments metadata
have been changed in memory. */
have been changed in memory.
*/
bool setComments(const QByteArray& data);
/** Set the Exif data using a Qt byte array. Return true if Exif metadata
have been changed in memory. */
have been changed in memory.
*/
bool setExif(const QByteArray& data);
/** Set the Iptc data using a Qt byte array. Return true if Iptc metadata
have been changed in memory. */
have been changed in memory.
*/
bool setIptc(const QByteArray& data);
//-- File access methods ----------------------------------------------
/** Load all metadata (EXIF, IPTC and JFIF Comments) from a byte array.
Return true if metadata have been loaded successfully from image data.
*/
bool load(const QByteArray& imgData);
/** Load all metadata (EXIF, IPTC and JFIF Comments) from a picture (JPEG, RAW, TIFF, PNG,
DNG, etc...). Return true if metadata have been loaded successfully from file. */
DNG, etc...). Return true if metadata have been loaded successfully from file.
*/
virtual bool load(const QString& filePath);
/** Save all metadata to a file. This one can be different than original picture to perform
transfert operation Return true if metadata have been saved into file. */
transfert operation Return true if metadata have been saved into file.
*/
bool save(const QString& filePath);
/** The same than save() method, but it apply on current image. Return true if metadata
have been saved into file. */
have been saved into file.
*/
bool applyChanges();
/** return true is the file metadata cannot be written by Exiv2. */
/** return true is the file metadata cannot be written by Exiv2.
*/
static bool isReadOnly(const QString& filePath);
/** Return 'true' if Comments can be written in file.
*/
static bool canWriteComment(const QString& filePath);
/** Return 'true' if Exif can be written in file.
*/
static bool canWriteExif(const QString& filePath);
/** Return 'true' if Iptc can be written in file.
*/
static bool canWriteIptc(const QString& filePath);
//-- Metadata Image Information manipulation methods ----------------
/** Set Program name and program version in Exif and Iptc Metadata. Return true if information
have been changed in metadata. */
have been changed in metadata.
*/
bool setImageProgramId(const QString& program, const QString& version);
/** Return the size of image in pixels using Exif tags. Return a null dimmension if size cannot
be found. */
be found.
*/
QSize getImageDimensions() const;
/** Set the size of image in pixels in Exif tags. Return true if size have been changed
in metadata. */
in metadata.
*/
bool setImageDimensions(const QSize& size, bool setProgramName=true);
/** Return a QImage copy of Exif thumbnail image. Return a null image if thumbnail cannot
be found. The 'fixOrientation' parameter will rotate automatically the thumbnail if Exif
orientation tags information are attached with thumbnail. */
orientation tags information are attached with thumbnail.
*/
QImage getExifThumbnail(bool fixOrientation) const;
/** Set the Exif Thumbnail image. The thumbnail image must have the right dimensions before.
Look Exif specification for details. Return true if thumbnail have been changed in metadata. */
Look Exif specification for details. Return true if thumbnail have been changed in metadata.
*/
bool setExifThumbnail(const QImage& thumb, bool setProgramName=true);
/** Return the image orientation set in Exif metadata. The makernotes of image are also parsed to
get this information. See ImageOrientation values for details. */
get this information. See ImageOrientation values for details.
*/
KExiv2::ImageOrientation getImageOrientation() const;
/** Set the Exif orientation tag of image. See ImageOrientation values for details
Return true if orientation have been changed in metadata. */
Return true if orientation have been changed in metadata.
*/
bool setImageOrientation(ImageOrientation orientation, bool setProgramName=true);
/** Return the image color-space set in Exif metadata. The makernotes of image are also parsed to
get this information. See ImageColorWorkSpace values for details. */
get this information. See ImageColorWorkSpace values for details.
*/
KExiv2::ImageColorWorkSpace getImageColorWorkSpace() const;
/** Set the Exif color-space tag of image. See ImageColorWorkSpace values for details
Return true if work-space have been changed in metadata. */
Return true if work-space have been changed in metadata.
*/
bool setImageColorWorkSpace(ImageColorWorkSpace workspace, bool setProgramName=true);
/** Return the time stamp of image. Exif information are check in first, IPTC in second
if image don't have Exif information. If no time stamp is found, a null date is returned. */
if image don't have Exif information. If no time stamp is found, a null date is returned.
*/
QDateTime getImageDateTime() const;
/** Set the Exif and Iptc time stamp. If 'setDateTimeDigitized' parameter is true, the 'Digitalized'
time stamp is set, else only 'Created' time stamp is set. */
time stamp is set, else only 'Created' time stamp is set.
*/
bool setImageDateTime(const QDateTime& dateTime, bool setDateTimeDigitized = false,
bool setProgramName=true);
/** Return a QImage copy of Iptc preview image. Return a null image if preview cannot
be found. */
be found.
*/
bool getImagePreview(QImage& preview) const;
/** Set the Iptc preview image. The thumbnail image must have the right size before (64Kb max
@ -240,7 +278,8 @@ public:
/** Set Iptc keywords using a list of strings defined by 'newKeywords' parameter. Use 'getImageKeywords()'
method to set 'oldKeywords' parameter with existing keywords from image. The method will compare
all new keywords with all old keywords to prevent duplicate entries in image. Return true if keywords
have been changed in metadata. */
have been changed in metadata.
*/
bool setImageKeywords(const QStringList& oldKeywords, const QStringList& newKeywords,
bool setProgramName=true);
@ -250,109 +289,135 @@ public:
/** Set Iptc subjects using a list of strings defined by 'newSubjects' parameter. Use 'getImageSubjects()'
method to set 'oldSubjects' parameter with existing subjects from image. The method will compare
all new subjects with all old subjects to prevent duplicate entries in image. Return true if subjects
have been changed in metadata. */
have been changed in metadata.
*/
bool setImageSubjects(const QStringList& oldSubjects, const QStringList& newSubjects,
bool setProgramName=true);
/** Return a strings list of Iptc sub-categories from image. Return an empty list if no sub-category
are set. */
are set.
*/
QStringList getImageSubCategories() const;
/** Set Iptc sub-categories using a list of strings defined by 'newSubCategories' parameter. Use
'getImageSubCategories()' method to set 'oldSubCategories' parameter with existing sub-categories
from image. The method will compare all new sub-categories with all old sub-categories to prevent
duplicate entries in image. Return true if sub-categories have been changed in metadata. */
duplicate entries in image. Return true if sub-categories have been changed in metadata.
*/
bool setImageSubCategories(const QStringList& oldSubCategories, const QStringList& newSubCategories,
bool setProgramName=true);
/** Return a QString copy of Exif user comments. Return a null string if user comments cannot
be found. */
be found.
*/
QString getExifComment() const;
/** Set the Exif user comments from image. Look Exif specification for more details about this tag.
Return true if Exif user comments have been changed in metadata. */
Return true if Exif user comments have been changed in metadata.
*/
bool setExifComment(const QString& comment, bool setProgramName=true);
/** Get all GPS location information set in image. Return true if all information can be found. */
/** Get all GPS location information set in image. Return true if all information can be found.
*/
bool getGPSInfo(double& altitude, double& latitude, double& longitude) const;
/** Set all GPS location information into image. Return true if all information have been
changed in metadata. */
changed in metadata.
*/
bool setGPSInfo(double altitude, double latitude, double longitude, bool setProgramName=true);
/** Remove all Exif tags relevant of GPS location information. Return true if all tags have been
removed successfully in metadata. */
removed successfully in metadata.
*/
bool removeGPSInfo(bool setProgramName=true);
//-- Metadata Tags manipulation methods ----------------------------------------
/** Get an Exif tags content like a string. If 'escapeCR' parameter is true, the CR characters
will be removed. If Exif tag cannot be found a null string is returned. */
will be removed. If Exif tag cannot be found a null string is returned.
*/
QString getExifTagString(const char *exifTagName, bool escapeCR=true) const;
/** Set an Exif tag content using a string. Return true if tag is set successfully. */
/** Set an Exif tag content using a string. Return true if tag is set successfully.
*/
bool setExifTagString(const char *exifTagName, const QString& value, bool setProgramName=true);
/** Get an Exif tags content like a long value. Return true if Exif tag be found. */
/** Get an Exif tags content like a long value. Return true if Exif tag be found.
*/
bool getExifTagLong(const char* exifTagName, long &val) const;
/** Set an Exif tag content using a long value. Return true if tag is set successfully. */
/** Set an Exif tag content using a long value. Return true if tag is set successfully.
*/
bool setExifTagLong(const char *exifTagName, long val, bool setProgramName=true);
/** Get the 'component' index of an Exif tags content like a rational value.
'num' and 'den' are the numerator and the denominator of the rational value.
Return true if Exif tag be found. */
Return true if Exif tag be found.
*/
bool getExifTagRational(const char *exifTagName, long int &num, long int &den, int component=0) const;
/** Set an Exif tags content using a rational value.
'num' and 'den' are the numerator and the denominator of the rational value.
Return true if tag is set successfully. */
Return true if tag is set successfully.
*/
bool setExifTagRational(const char *exifTagName, long int num, long int den, bool setProgramName=true);
/** Get an Exif tags content like a bytes array. Return an empty bytes array if Exif
tag cannot be found. */
tag cannot be found.
*/
QByteArray getExifTagData(const char *exifTagName) const;
/** Set an Exif tag content using a bytes array. Return true if tag is set successfully. */
/** Set an Exif tag content using a bytes array. Return true if tag is set successfully.
*/
bool setExifTagData(const char *exifTagName, const QByteArray& data, bool setProgramName=true);
/** Get an Iptc tags content like a string. If 'escapeCR' parameter is true, the CR characters
will be removed. If Iptc tag cannot be found a null string is returned. */
will be removed. If Iptc tag cannot be found a null string is returned.
*/
QString getIptcTagString(const char* iptcTagName, bool escapeCR=true) const;
/** Set an Iptc tag content using a string. Return true if tag is set successfully. */
/** Set an Iptc tag content using a string. Return true if tag is set successfully.
*/
bool setIptcTagString(const char *iptcTagName, const QString& value, bool setProgramName=true);
/** Get an Iptc tags content like a bytes array. Return an empty bytes array if Iptc
tag cannot be found. */
tag cannot be found.
*/
QByteArray getIptcTagData(const char *iptcTagName) const;
/** Set an Iptc tag content using a bytes array. Return true if tag is set successfully. */
/** Set an Iptc tag content using a bytes array. Return true if tag is set successfully.
*/
bool setIptcTagData(const char *iptcTagName, const QByteArray& data, bool setProgramName=true);
/** Remove the Exif tag 'exifTagName' from Exif metadata. Return true if tag is
removed successfully. */
removed successfully.
*/
bool removeExifTag(const char *exifTagName, bool setProgramName=true);
/** Remove the Iptc tag 'iptcTagName' from Iptc metadata. Return true if tag is
removed successfully. */
/** Remove the all instance of Iptc tags 'iptcTagName' from Iptc metadata. Return true if all
tags have been removed successfully.
*/
bool removeIptcTag(const char *iptcTagName, bool setProgramName=true);
/** Return the Exif Tag title or a null string. */
static QString getExifTagTitle(const char *exifTagName);
/** Return the Exif Tag title or a null string.
*/
QString getExifTagTitle(const char *exifTagName);
/** Return the Exif Tag description or a null string. */
static QString getExifTagDescription(const char *exifTagName);
/** Return the Exif Tag description or a null string.
*/
QString getExifTagDescription(const char *exifTagName);
/** Return the Iptc Tag title or a null string. */
static QString getIptcTagTitle(const char *iptcTagName);
/** Return the Iptc Tag title or a null string.
*/
QString getIptcTagTitle(const char *iptcTagName);
/** Return the Iptc Tag description or a null string. */
static QString getIptcTagDescription(const char *iptcTagName);
/** Return the Iptc Tag description or a null string.
*/
QString getIptcTagDescription(const char *iptcTagName);
/** Return a map of Exif tags name/value found in metadata sorted by
Exif keys given by 'exifKeysFilter'.
'exifKeysFilter' is a QStringList of Exif keys.
For example, if you use the string list given below:
@ -367,12 +432,12 @@ public:
if 'inverSelection' is false.
- not include "Iop", or "Thumbnail", or "Image", or "Photo" in the Exif tag keys
if 'inverSelection' is true.
*/
*/
KExiv2::MetaDataMap getExifTagsDataList(const QStringList &exifKeysFilter, bool invertSelection=false);
/** Return a map of Iptc tags name/value found in metadata sorted by
Iptc keys given by 'iptcKeysFilter'.
'iptcKeysFilter' is a QStringList of Iptc keys.
For example, if you use the string list given below:
@ -385,28 +450,23 @@ public:
if 'inverSelection' is false.
- not include "Envelope", or "Application2" in the Iptc tag keys
if 'inverSelection' is true.
*/
*/
KExiv2::MetaDataMap getIptcTagsDataList(const QStringList &iptcKeysFilter, bool invertSelection=false);
//-- Advanced methods to convert and decode data -------------------------
/** This method convert 'number' like a rational value, returned in 'numerator' and
'denominator' parameters. Set the precision using 'rounding' parameter. */
'denominator' parameters. Set the precision using 'rounding' parameter.
*/
static void convertToRational(double number, long int* numerator,
long int* denominator, int rounding);
/** Wrapper method to convert a Comments content to a QString. */
static QString convertCommentValue(const Exiv2::Exifdatum &comment);
/** Charset autodetection to convert a string to a QString. */
static QString detectEncodingAndDecode(const std::string &value);
protected:
/** Re-implemente this method to set automatically the Program Name and Program Version
information in Exif and Iptc metadata if 'on' argument is true. This method is called by all methods witch
change tags in metadata. By default this method do nothing and return true.
In digiKam this method is re-implementated like this:
if (on)
@ -415,37 +475,15 @@ protected:
QString software("digiKam");
return setImageProgramId(software, version);
}
return true;
*/
*/
virtual bool setProgramId(bool on=true);
private:
/** Return a reference to Exif metadata object in memory. */
Exiv2::ExifData& exifMetaData();
/** Return a reference to Iptc metadata object in memory. */
Exiv2::IptcData& iptcMetaData();
/** Set the Exif data using an Exiv2 byte array. Return true if Exif metadata
have been changed in memory. */
bool setExif(Exiv2::DataBuf const data);
/** Set the Iptc data using an Exiv2 byte array. Return true if Iptc metadata
have been changed in memory. */
bool setIptc(Exiv2::DataBuf const data);
/** Return a reference to comments string object in memory. */
std::string& commentsMetaData();
/** Return a standard C++ string copy of Comments container get from current image.
Return a null standard string if there is no Comments metadata in memory. */
std::string getCommentsString() const;
private:
/** Internal class to store private members. Used to improve binary compatibility */
/** Internal class to store private members. Used to improve binary compatibility
*/
KExiv2Priv *d;
};

@ -0,0 +1,226 @@
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.kipi-plugins.org
*
* Date : 2007-09-03
* Description : Exiv2 library interface for KDE
*
* Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* NOTE: Do not use kdDebug() in this implementation because
* it will be multithreaded. Use qDebug() instead.
* See B.K.O #133026 for details.
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
// Local includes.
#include "kexiv2private.h"
namespace KExiv2Iface
{
KExiv2Priv::KExiv2Priv()
{
imageComments = std::string();
}
KExiv2Priv::~KExiv2Priv()
{
#ifdef _XMP_SUPPORT_
// Fix memory leak if Exiv2 support XMP.
Exiv2::XmpParser::terminate();
#endif // _XMP_SUPPORT_
}
bool KExiv2Priv::setExif(Exiv2::DataBuf const data)
{
try
{
if (data.size_ != 0)
{
#if (EXIV2_TEST_VERSION(0,17,91))
Exiv2::ExifParser::decode(exifMetadata, data.pData_, data.size_);
return (!exifMetadata.empty());
#else
if (exifMetadata.load(data.pData_, data.size_) != 0)
return false;
else
return true;
#endif
}
}
catch( Exiv2::Error &e )
{
if (!filePath.isEmpty())
qDebug ("From file %s", filePath.ascii());
printExiv2ExceptionError("Cannot set Exif data using Exiv2 ", e);
}
return false;
}
bool KExiv2Priv::setIptc(Exiv2::DataBuf const data)
{
try
{
if (data.size_ != 0)
{
#if (EXIV2_TEST_VERSION(0,17,91))
Exiv2::IptcParser::decode(iptcMetadata, data.pData_, data.size_);
return (!iptcMetadata.empty());
#else
if (iptcMetadata.load(data.pData_, data.size_) != 0)
return false;
else
return true;
#endif
}
}
catch( Exiv2::Error &e )
{
if (!filePath.isEmpty())
qDebug ("From file %s", filePath.ascii());
printExiv2ExceptionError("Cannot set Iptc data using Exiv2 ", e);
}
return false;
}
void KExiv2Priv::printExiv2ExceptionError(const QString& msg, Exiv2::Error& e)
{
std::string s(e.what());
qDebug("%s (Error #%i: %s)", msg.ascii(), e.code(), s.c_str());
}
QString KExiv2Priv::convertCommentValue(const Exiv2::Exifdatum &exifDatum)
{
try
{
std::string comment;
std::string charset;
#if (EXIV2_TEST_VERSION(0,11,0))
comment = exifDatum.toString();
#else
// workaround for bug in TIFF parser: CommentValue is loaded as DataValue
const Exiv2::Value &value = exifDatum.value();
Exiv2::byte *data = new Exiv2::byte[value.size()];
value.copy(data, Exiv2::invalidByteOrder);
Exiv2::CommentValue commentValue;
// this read method is hidden in CommentValue
static_cast<Exiv2::Value &>(commentValue).read(data, value.size(), Exiv2::invalidByteOrder);
comment = commentValue.toString();
delete [] data;
#endif
// libexiv2 will prepend "charset=\"SomeCharset\" " if charset is specified
// Before conversion to QString, we must know the charset, so we stay with std::string for a while
if (comment.length() > 8 && comment.substr(0, 8) == "charset=")
{
// the prepended charset specification is followed by a blank
std::string::size_type pos = comment.find_first_of(' ');
if (pos != std::string::npos)
{
// extract string between the = and the blank
charset = comment.substr(8, pos-8);
// get the rest of the string after the charset specification
comment = comment.substr(pos+1);
}
}
if (charset == "\"Unicode\"")
{
// QString expects a null-terminated UCS-2 string.
// Is it already null terminated? In any case, add termination "\0\0" for safety.
comment.resize(comment.length() + 2, '\0');
return QString::fromUcs2((unsigned short *)comment.data());
}
else if (charset == "\"Jis\"")
{
QTextCodec *codec = QTextCodec::codecForName("JIS7");
return codec->toUnicode(comment.c_str());
}
else if (charset == "\"Ascii\"")
{
return QString::fromLatin1(comment.c_str());
}
else
{
return detectEncodingAndDecode(comment);
}
}
catch( Exiv2::Error &e )
{
printExiv2ExceptionError("Cannot convert Comment using Exiv2 ", e);
}
return QString();
}
QString KExiv2Priv::detectEncodingAndDecode(const std::string &value)
{
// For charset autodetection, we could use sophisticated code
// (Mozilla chardet, KHTML's autodetection, QTextCodec::codecForContent),
// but that is probably too much.
// We check for UTF8, Local encoding and ASCII.
if (value.empty())
return QString();
#if KDE_IS_VERSION(3,2,0)
if (KStringHandler::isUtf8(value.c_str()))
{
return QString::fromUtf8(value.c_str());
}
#else
// anyone who is still running KDE 3.0 or 3.1 is missing so many features
// that he will have to accept this missing feature.
return QString::fromUtf8(value.c_str());
#endif
// Utf8 has a pretty unique byte pattern.
// Thats not true for ASCII, it is not possible
// to reliably autodetect different ISO-8859 charsets.
// We try if QTextCodec can decide here, otherwise we use Latin1.
// Or use local8Bit as default?
// load QTextCodecs
QTextCodec *latin1Codec = QTextCodec::codecForName("iso8859-1");
//QTextCodec *utf8Codec = QTextCodec::codecForName("utf8");
QTextCodec *localCodec = QTextCodec::codecForLocale();
// make heuristic match
int latin1Score = latin1Codec->heuristicContentMatch(value.c_str(), value.length());
int localScore = localCodec->heuristicContentMatch(value.c_str(), value.length());
// convert string:
// Use whatever has the larger score, local or ASCII
if (localScore >= 0 && localScore >= latin1Score)
{
// workaround for bug #134999:
// The QLatin15Codec may crash if strlen < value.length()
int length = value.length();
if (localCodec->name() == QString::fromLatin1("ISO 8859-15"))
length = strlen(value.c_str());
return localCodec->toUnicode(value.c_str(), length);
}
else
return QString::fromLatin1(value.c_str());
}
} // NameSpace KExiv2Iface

@ -0,0 +1,131 @@
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.kipi-plugins.org
*
* Date : 2007-09-03
* Description : Exiv2 library interface for KDE
*
* Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#ifndef KEXIV2_PRIVATE_H
#define KEXIV2_PRIVATE_H
// C++ includes.
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
// Qt includes.
#include <qfile.h>
#include <qsize.h>
#include <qtextcodec.h>
#include <qwmatrix.h>
#include <qfileinfo.h>
// KDE includes.
#include <ktempfile.h>
#include <kstringhandler.h>
#include <kdeversion.h>
// Exiv2 includes.
// The pragmas are required to be able to catch exceptions thrown by libexiv2:
// See http://gcc.gnu.org/wiki/Visibility, the section about c++ exceptions.
// They are needed for all libexiv2 versions that do not care about visibility.
#pragma GCC visibility push(default)
#include <exiv2/error.hpp>
#include <exiv2/image.hpp>
#include <exiv2/jpgimage.hpp>
#include <exiv2/datasets.hpp>
#include <exiv2/tags.hpp>
#include <exiv2/types.hpp>
#include <exiv2/exif.hpp>
#pragma GCC visibility pop
// Check if Exiv2 support XMP
#if (EXIV2_MAJOR_VERSION ==0 && EXIV2_MINOR_VERSION ==15 && EXIV2_PATCH_VERSION >=99) || \
(EXIV2_MAJOR_VERSION ==0 && EXIV2_MINOR_VERSION >15 ) || \
(EXIV2_MAJOR_VERSION >0)
# define _XMP_SUPPORT_ 1
#endif
// Make sure an EXIV2_TEST_VERSION macro exists:
#ifdef EXIV2_VERSION
# ifndef EXIV2_TEST_VERSION
# define EXIV2_TEST_VERSION(major,minor,patch) \
( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) )
# endif
#else
# define EXIV2_TEST_VERSION(major,minor,patch) (false)
#endif
namespace KExiv2Iface
{
class KExiv2Priv
{
public:
KExiv2Priv();
~KExiv2Priv();
/** Set the Exif data using an Exiv2 byte array. Return true if Exif metadata
have been changed in memory.
*/
bool setExif(Exiv2::DataBuf const data);
/** Set the Iptc data using an Exiv2 byte array. Return true if Iptc metadata
have been changed in memory.
*/
bool setIptc(Exiv2::DataBuf const data);
/** Generic method to print the Exiv2 C++ Exception error message from 'e'.
'msg' string is printed just before like debug header.
*/
void printExiv2ExceptionError(const QString& msg, Exiv2::Error& e);
/** Wrapper method to convert a Comments content to a QString.
*/
QString convertCommentValue(const Exiv2::Exifdatum &exifDatum);
/** Charset autodetection to convert a string to a QString.
*/
QString detectEncodingAndDecode(const std::string &value);
public:
QString filePath;
std::string imageComments;
Exiv2::ExifData exifMetadata;
Exiv2::IptcData iptcMetadata;
};
} // NameSpace KExiv2Iface
#endif /* KEXIV2_PRIVATE_H */

@ -6,7 +6,7 @@
* Date : 2007-02-06
* Description : Exiv2 library interface for KDE
*
* Copyright (C) 2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
@ -23,9 +23,9 @@
#ifndef KEXIV2_VERSION_H
#define KEXIV2_VERSION_H
static const char kexiv2_version[] = "0.1.7";
static const char kexiv2_version[] = "0.1.9";
#define KEXIV2_VERSION 0x000107
#define KEXIV2_VERSION 0x000109
#endif // KEXIV2_VERSION_H

Loading…
Cancel
Save