From 6efeb90a0efabb42c0fc21088c23ef0c76d80fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Thu, 15 Sep 2022 10:48:47 +0200 Subject: [PATCH 1/2] Initialize a non-empty PNG ICC profile name --- include/exiv2/pngimage.hpp | 2 +- src/pngimage.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/exiv2/pngimage.hpp b/include/exiv2/pngimage.hpp index 3c1a2609f1..efcb1cc338 100644 --- a/include/exiv2/pngimage.hpp +++ b/include/exiv2/pngimage.hpp @@ -79,7 +79,7 @@ class EXIV2API PngImage : public Image { void doWriteMetadata(BasicIo& outIo); //@} - std::string profileName_; + std::string profileName_{"ICC Profile"}; }; // class PngImage diff --git a/src/pngimage.cpp b/src/pngimage.cpp index f9a6bbd8ab..6879f9735a 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -447,13 +447,16 @@ void PngImage::readMetadata() { enforce(iccOffset < 80 && iccOffset < chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata); } while (chunkData.read_uint8(iccOffset++) != 0x00); - profileName_ = std::string(chunkData.c_str(), iccOffset - 1); + // Don't fail on empty ICC profile name, but also don't overwrite the default + std::string profileName = std::string(chunkData.c_str(), iccOffset - 1); + if (profileName.size() > 0) + profileName_ = profileName; ++iccOffset; // +1 = 'compressed' flag enforce(iccOffset <= chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata); zlibToDataBuf(chunkData.c_data(iccOffset), static_cast(chunkLength - iccOffset), iccProfile_); #ifdef EXIV2_DEBUG_MESSAGES - std::cout << "Exiv2::PngImage::readMetadata: profile name: " << profileName_ << std::endl; + std::cout << "Exiv2::PngImage::readMetadata: profile name: " << profileName << std::endl; std::cout << "Exiv2::PngImage::readMetadata: iccProfile.size_ (uncompressed) : " << iccProfile_.size() << std::endl; #endif From e7cefa3dc42a77075a46ffab9eb638c41f1bc147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Mon, 19 Sep 2022 12:26:03 +0200 Subject: [PATCH 2/2] API for setting profile name for PNGs --- include/exiv2/image.hpp | 2 +- include/exiv2/pngimage.hpp | 16 +++++++++++++++- src/pngimage.cpp | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index bb4e46986b..cb5bd6937f 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -192,7 +192,7 @@ class EXIV2API Image { */ virtual void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true); /*! - @brief Erase iccProfile. the profile is not removed from + @brief Erase iccProfile. The profile is not removed from the actual image until the writeMetadata() method is called. */ virtual void clearIccProfile(); diff --git a/include/exiv2/pngimage.hpp b/include/exiv2/pngimage.hpp index efcb1cc338..6471e3f87d 100644 --- a/include/exiv2/pngimage.hpp +++ b/include/exiv2/pngimage.hpp @@ -53,6 +53,20 @@ class EXIV2API PngImage : public Image { @warning This function is not thread safe and intended for exiv2 -pS for debugging. */ void printStructure(std::ostream& out, PrintStructureOption option, size_t depth) override; + /*! + @brief Set the image iccProfile. The new profile is not written + to the image until the writeMetadata() method is called. + @param iccProfile DataBuf containing profile (binary) + @param bTestValid - tests that iccProfile contains credible data + @param profileName Name for referring to the profile + */ + void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true, + const std::string& profileName = std::string("ICC profile")); + /*! + @brief Erase iccProfile. The profile is not removed from + the actual image until the writeMetadata() method is called. + */ + void clearIccProfile() override; //@} //! @name Accessors @@ -79,7 +93,7 @@ class EXIV2API PngImage : public Image { void doWriteMetadata(BasicIo& outIo); //@} - std::string profileName_{"ICC Profile"}; + std::string profileName_{"ICC profile"}; }; // class PngImage diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 6879f9735a..7c32909a1e 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -373,6 +373,16 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, si } } +void PngImage::setIccProfile(DataBuf&& iccProfile, bool bTestValid, const std::string& profileName) { + profileName_ = profileName; + Image::setIccProfile(std::move(iccProfile), bTestValid); +} + +void PngImage::clearIccProfile() { + profileName_ = std::string("ICC profile"); + Image::clearIccProfile(); +} + void readChunk(DataBuf& buffer, BasicIo& io) { #ifdef EXIV2_DEBUG_MESSAGES std::cout << "Exiv2::PngImage::readMetadata: Position: " << io.tell() << std::endl;