Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ bool readImage(const char* path, Options& /* options */) {
bool bResult = false;

try {
Image::UniquePtr image = ImageFactory::open(path);
if (image.get()) {
if (auto image = ImageFactory::open(path)) {
image->readMetadata();
ExifData& exifData = image->exifData();
bResult = !exifData.empty();
Expand Down Expand Up @@ -848,8 +847,7 @@ int main(int argc, const char* argv[]) {
try {
time_t t = readImageTime(path, &stamp);
Position* pPos = searchTimeDict(gTimeDict, t, Position::deltaMax_);
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(path);
if (image.get()) {
if (auto image = Exiv2::ImageFactory::open(path)) {
image->readMetadata();
Exiv2::ExifData& exifData = image->exifData();
if (pPos) {
Expand Down
2 changes: 1 addition & 1 deletion src/cr2header_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DataBuf Cr2Header::write() const {
return buf;
} // Cr2Header::write

bool Cr2Header::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* /*pPrimaryGroups*/) const {
bool Cr2Header::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& /*pPrimaryGroups*/) const {
// CR2 image tags are all IFD2 and IFD3 tags
if (group == IfdId::ifd2Id || group == IfdId::ifd3Id)
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/cr2header_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Cr2Header : public TiffHeaderBase {
//! @name Accessors
//@{
[[nodiscard]] DataBuf write() const override;
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const override;
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const override;
//@}

//! Return the address of offset2 from the start of the header
Expand Down
25 changes: 9 additions & 16 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,16 @@ const CrwSubDir CrwMap::crwSubDir_[] = {
CiffComponent::CiffComponent(uint16_t tag, uint16_t dir) : dir_(dir), tag_(tag) {
}

CiffDirectory::~CiffDirectory() {
for (auto&& component : components_) {
delete component;
}
}

CiffComponent* CiffComponent::add(UniquePtr component) {
const CiffComponent::UniquePtr& CiffComponent::add(UniquePtr component) {
return doAdd(std::move(component));
}

CiffComponent* CiffEntry::doAdd(UniquePtr /*component*/) {
const CiffComponent::UniquePtr& CiffEntry::doAdd(UniquePtr /*component*/) {
throw Error(ErrorCode::kerFunctionNotSupported, "CiffEntry::add");
} // CiffEntry::doAdd

CiffComponent* CiffDirectory::doAdd(UniquePtr component) {
components_.push_back(component.release());
const CiffComponent::UniquePtr& CiffDirectory::doAdd(UniquePtr component) {
components_.push_back(std::move(component));
return components_.back();
} // CiffDirectory::doAdd

Expand Down Expand Up @@ -517,20 +511,20 @@ void CiffHeader::add(uint16_t crwTagId, uint16_t crwDir, DataBuf&& buf) {
if (!pRootDir_) {
pRootDir_ = std::make_unique<CiffDirectory>();
}
if (auto child = pRootDir_->add(crwDirs, crwTagId)) {
if (const auto& child = pRootDir_->add(crwDirs, crwTagId)) {
child->setValue(std::move(buf));
}
} // CiffHeader::add

CiffComponent* CiffComponent::add(CrwDirs& crwDirs, uint16_t crwTagId) {
const CiffComponent::UniquePtr& CiffComponent::add(CrwDirs& crwDirs, uint16_t crwTagId) {
return doAdd(crwDirs, crwTagId);
} // CiffComponent::add

CiffComponent* CiffComponent::doAdd(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {
return nullptr;
const CiffComponent::UniquePtr& CiffComponent::doAdd(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {
throw Error(ErrorCode::kerFunctionNotSupported, "CiffEntry::doAdd");
} // CiffComponent::doAdd

CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
const CiffComponent::UniquePtr& CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
/*
add()
if stack not empty
Expand Down Expand Up @@ -602,7 +596,6 @@ void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId) {
// Find the tag
auto it = std::find_if(components_.begin(), components_.end(), [=](const auto& c) { return c->tag() == crwTagId; });
if (it != components_.end()) {
delete *it;
components_.erase(it);
}
}
Expand Down
27 changes: 8 additions & 19 deletions src/crwimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ class CiffComponent {
//! CiffComponent auto_ptr type
using UniquePtr = std::unique_ptr<CiffComponent>;
//! Container type to hold all metadata
using Components = std::vector<CiffComponent*>;
using Components = std::vector<UniquePtr>;

//! @name Creators
//@{
//! Default constructor
CiffComponent() = default;
//! Constructor taking a tag and directory
CiffComponent(uint16_t tag, uint16_t dir);
CiffComponent(const CiffComponent&) = delete;
CiffComponent& operator=(const CiffComponent&) = delete;
//! Virtual destructor.
virtual ~CiffComponent() = default;
//@}
Expand All @@ -73,7 +71,7 @@ class CiffComponent {
// Default assignment operator is fine

//! Add a component to the composition
CiffComponent* add(UniquePtr component);
const UniquePtr& add(UniquePtr component);
/*!
@brief Add \em crwTagId to the parse tree, if it doesn't exist
yet. \em crwDirs contains the path of subdirectories, starting
Expand All @@ -87,7 +85,7 @@ class CiffComponent {

@return A pointer to the newly added component.
*/
CiffComponent* add(CrwDirs& crwDirs, uint16_t crwTagId);
const UniquePtr& add(CrwDirs& crwDirs, uint16_t crwTagId);
/*!
@brief Remove \em crwTagId from the parse tree, if it exists yet. \em
crwDirs contains the path of subdirectories, starting with the
Expand Down Expand Up @@ -231,9 +229,9 @@ class CiffComponent {
//! @name Manipulators
//@{
//! Implements add()
virtual CiffComponent* doAdd(UniquePtr component) = 0;
virtual const UniquePtr& doAdd(UniquePtr component) = 0;
//! Implements add(). The default implementation does nothing.
virtual CiffComponent* doAdd(CrwDirs& crwDirs, uint16_t crwTagId);
virtual const UniquePtr& doAdd(CrwDirs& crwDirs, uint16_t crwTagId);
//! Implements remove(). The default implementation does nothing.
virtual void doRemove(CrwDirs& crwDirs, uint16_t crwTagId);
//! Implements read(). The default implementation reads a directory entry.
Expand Down Expand Up @@ -291,7 +289,7 @@ class CiffEntry : public CiffComponent {
//@{
using CiffComponent::doAdd;
// See base class comment
CiffComponent* doAdd(UniquePtr component) override;
const UniquePtr& doAdd(UniquePtr component) override;
/*!
@brief Implements write(). Writes only the value data of the entry,
using writeValueData().
Expand All @@ -312,15 +310,6 @@ class CiffDirectory : public CiffComponent {
using CiffComponent::CiffComponent;

public:
//! @name Creators
//@{
//! Virtual destructor
~CiffDirectory() override;
//@}

CiffDirectory(const CiffDirectory&) = delete;
CiffDirectory& operator=(const CiffDirectory&) = delete;

//! @name Manipulators
//@{
// Default assignment operator is fine
Expand All @@ -339,9 +328,9 @@ class CiffDirectory : public CiffComponent {
//! @name Manipulators
//@{
// See base class comment
CiffComponent* doAdd(UniquePtr component) override;
const UniquePtr& doAdd(UniquePtr component) override;
// See base class comment
CiffComponent* doAdd(CrwDirs& crwDirs, uint16_t crwTagId) override;
const UniquePtr& doAdd(CrwDirs& crwDirs, uint16_t crwTagId) override;
// See base class comment
void doRemove(CrwDirs& crwDirs, uint16_t crwTagId) override;
/*!
Expand Down
16 changes: 8 additions & 8 deletions src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size
auto primaryGroups = findPrimaryGroups(parsedTree);
if (parsedTree) {
// Attempt to update existing TIFF components based on metadata entries
TiffEncoder encoder(exifData, iptcData, xmpData, parsedTree.get(), false, &primaryGroups, pHeader, findEncoderFct);
TiffEncoder encoder(exifData, iptcData, xmpData, parsedTree.get(), false, primaryGroups, pHeader, findEncoderFct);
parsedTree->accept(encoder);
if (!encoder.dirty())
writeMethod = wmNonIntrusive;
Expand All @@ -2070,11 +2070,11 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size
auto createdTree = TiffCreator::create(root, IfdId::ifdIdNotSet);
if (parsedTree) {
// Copy image tags from the original image to the composite
TiffCopier copier(createdTree.get(), root, pHeader, &primaryGroups);
TiffCopier copier(createdTree.get(), root, pHeader, primaryGroups);
parsedTree->accept(copier);
}
// Add entries from metadata to composite
TiffEncoder encoder(exifData, iptcData, xmpData, createdTree.get(), !parsedTree, &primaryGroups, pHeader,
TiffEncoder encoder(exifData, iptcData, xmpData, createdTree.get(), !parsedTree, primaryGroups, pHeader,
findEncoderFct);
encoder.add(createdTree.get(), parsedTree.get(), root);
// Write binary representation from the composite tree
Expand Down Expand Up @@ -2228,7 +2228,7 @@ uint16_t TiffHeaderBase::tag() const {
return tag_;
}

bool TiffHeaderBase::isImageTag(uint16_t /*tag*/, IfdId /*group*/, const PrimaryGroups* /*primaryGroups*/) const {
bool TiffHeaderBase::isImageTag(uint16_t /*tag*/, IfdId /*group*/, const PrimaryGroups& /*primaryGroups*/) const {
return false;
}

Expand Down Expand Up @@ -2327,7 +2327,7 @@ TiffHeader::TiffHeader(ByteOrder byteOrder, uint32_t offset, bool hasImageTags)
TiffHeaderBase(42, 8, byteOrder, offset), hasImageTags_(hasImageTags) {
}

bool TiffHeader::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const {
bool TiffHeader::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const {
if (!hasImageTags_) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "No image tags in this image\n";
Expand All @@ -2338,16 +2338,16 @@ bool TiffHeader::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPri
ExifKey key(tag, groupName(group));
#endif
// If there are primary groups and none matches group, we're done
if (pPrimaryGroups && !pPrimaryGroups->empty() &&
std::find(pPrimaryGroups->begin(), pPrimaryGroups->end(), group) == pPrimaryGroups->end()) {
if (!pPrimaryGroups.empty() &&
std::find(pPrimaryGroups.begin(), pPrimaryGroups.end(), group) == pPrimaryGroups.end()) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Not an image tag: " << key << " (1)\n";
#endif
return false;
}
// All tags of marked primary groups other than IFD0 are considered
// image tags. That should take care of NEFs until we know better.
if (pPrimaryGroups && !pPrimaryGroups->empty() && group != IfdId::ifd0Id) {
if (!pPrimaryGroups.empty() && group != IfdId::ifd0Id) {
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(tag, groupName(group));
std::cerr << "Image tag: " << key << " (2)\n";
Expand Down
4 changes: 2 additions & 2 deletions src/tiffimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class TiffHeaderBase {

@return The default implementation returns \c false.
*/
virtual bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const;
virtual bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const;
//@}

private:
Expand All @@ -120,7 +120,7 @@ class TiffHeader : public TiffHeaderBase {
//@}
//@{
//! @name Accessors
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* pPrimaryGroups) const override;
bool isImageTag(uint16_t tag, IfdId group, const PrimaryGroups& pPrimaryGroups) const override;
//@}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void TiffFinder::visitBinaryElement(TiffBinaryElement* object) {
}

TiffCopier::TiffCopier(TiffComponent* pRoot, uint32_t root, const TiffHeaderBase* pHeader,
const PrimaryGroups* pPrimaryGroups) :
const PrimaryGroups& pPrimaryGroups) :
pRoot_(pRoot), root_(root), pHeader_(pHeader), pPrimaryGroups_(pPrimaryGroups) {
}

Expand Down Expand Up @@ -440,7 +440,7 @@ void TiffDecoder::visitBinaryElement(TiffBinaryElement* object) {
}

TiffEncoder::TiffEncoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, TiffComponent* pRoot,
const bool isNewImage, const PrimaryGroups* pPrimaryGroups, const TiffHeaderBase* pHeader,
const bool isNewImage, const PrimaryGroups& pPrimaryGroups, const TiffHeaderBase* pHeader,
FindEncoderFct findEncoderFct) :
exifData_(exifData),
iptcData_(iptcData),
Expand Down
8 changes: 4 additions & 4 deletions src/tiffvisitor_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class TiffCopier : public TiffVisitor {
@param pHeader Pointer to the TIFF header of the source image.
@param pPrimaryGroups Pointer to the list of primary groups.
*/
TiffCopier(TiffComponent* pRoot, uint32_t root, const TiffHeaderBase* pHeader, const PrimaryGroups* pPrimaryGroups);
TiffCopier(TiffComponent* pRoot, uint32_t root, const TiffHeaderBase* pHeader, const PrimaryGroups& pPrimaryGroups);
TiffCopier(const TiffCopier&) = delete;
TiffCopier& operator=(const TiffCopier&) = delete;
//! Virtual destructor
Expand Down Expand Up @@ -241,7 +241,7 @@ class TiffCopier : public TiffVisitor {
TiffComponent* pRoot_;
uint32_t root_;
const TiffHeaderBase* pHeader_;
const PrimaryGroups* pPrimaryGroups_;
PrimaryGroups pPrimaryGroups_;
}; // class TiffCopier

/*!
Expand Down Expand Up @@ -352,7 +352,7 @@ class TiffEncoder : public TiffVisitor {
find special encoders.
*/
TiffEncoder(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, TiffComponent* pRoot, bool isNewImage,
const PrimaryGroups* pPrimaryGroups, const TiffHeaderBase* pHeader, FindEncoderFct findEncoderFct);
const PrimaryGroups& pPrimaryGroups, const TiffHeaderBase* pHeader, FindEncoderFct findEncoderFct);
TiffEncoder(const TiffEncoder&) = delete;
TiffEncoder& operator=(const TiffEncoder&) = delete;
//! Virtual destructor
Expand Down Expand Up @@ -517,7 +517,7 @@ class TiffEncoder : public TiffVisitor {
const TiffHeaderBase* pHeader_; //!< TIFF image header
TiffComponent* pRoot_; //!< Root element of the composite
bool isNewImage_; //!< True if the TIFF image is created from scratch
const PrimaryGroups* pPrimaryGroups_; //!< List of primary image groups
PrimaryGroups pPrimaryGroups_; //!< List of primary image groups
TiffComponent* pSourceTree_{nullptr}; //!< Parsed source tree for reference
ByteOrder byteOrder_; //!< Byteorder for encoding
ByteOrder origByteOrder_; //!< Byteorder as set in the c'tor
Expand Down
Loading