Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize a non-empty PNG ICC profile name #2355

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 15 additions & 1 deletion include/exiv2/pngimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -79,7 +93,7 @@ class EXIV2API PngImage : public Image {
void doWriteMetadata(BasicIo& outIo);
//@}

std::string profileName_;
std::string profileName_{"ICC profile"};

}; // class PngImage

Expand Down
17 changes: 15 additions & 2 deletions src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -447,13 +457,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<uLongf>(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
Expand Down