diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 495ab5c7..a2ed2edf 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -239,6 +239,11 @@ namespace Exiv2 { the actual image until the writeMetadata() method is called. */ virtual void clearIccProfile(); + /*! + @brief Erase iccProfile. the profile is not removed from + the actual image until the writeMetadata() method is called. + */ + virtual bool iccProfileDefined() { return iccProfile_.size_?true:false;} /*! @brief return iccProfile @@ -433,11 +438,11 @@ namespace Exiv2 { //@} void setTypeSupported( - int imageType, + int imageType, uint16_t supportedMetadata ) { - imageType_ = imageType; - supportedMetadata_ = supportedMetadata; + imageType_ = imageType; + supportedMetadata_ = supportedMetadata; } int imageType() const { return imageType_; } diff --git a/src/actions.cpp b/src/actions.cpp index 78247f87..24e89447 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -949,6 +949,9 @@ namespace Action { if (0 == rc && Params::instance().target_ & Params::ctXmp) { rc = eraseXmpData(image.get()); } + if (0 == rc && Params::instance().target_ & Params::ctIccProfile) { + rc = eraseIccProfile(image.get()); + } if (0 == rc && Params::instance().target_ & Params::ctIptcRaw) { rc = printStructure(std::cout,Exiv2::kpsIptcErase); } @@ -1032,6 +1035,14 @@ namespace Action { image->clearXmpPacket(); return 0; } + int Erase::eraseIccProfile(Exiv2::Image* image) const + { + if (Params::instance().verbose_ && image->iccProfileDefined() ) { + std::cout << _("Erasing ICC Profile data from the file") << std::endl; + } + image->clearIccProfile(); + return 0; + } Erase::AutoPtr Erase::clone() const { diff --git a/src/actions.hpp b/src/actions.hpp index cfc1d3a2..2e0a82d5 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -274,6 +274,10 @@ namespace Action { @brief Erase XMP packet from the file. */ int eraseXmpData(Exiv2::Image* image) const; + /*! + @brief Erase ICCProfile from the file. + */ + int eraseIccProfile(Exiv2::Image* image) const; /*! @brief Print image Structure information (used by ctIptcRaw/kpsIptcErase) */ diff --git a/src/webpimage.cpp b/src/webpimage.cpp index a55537e4..faa9fe69 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -131,7 +131,7 @@ namespace Exiv2 { bool has_exif = false; bool has_vp8x = false; bool has_alpha = false; - bool has_icc = false; + bool has_icc = iccProfileDefined(); int width = 0; int height = 0; @@ -140,10 +140,6 @@ namespace Exiv2 { std::string xmpData; Blob blob; - if (iccProfile_.size_ > 0) { - has_icc = true; - } - if (exifData_.count() > 0) { ExifParser::encode(blob, littleEndian, exifData_); if (blob.size() > 0) { @@ -174,7 +170,7 @@ namespace Exiv2 { /* Chunk with color profile. */ if (equalsWebPTag(chunkId, "ICCP") && !has_alpha) { - has_icc = true; + has_icc &= true; } /* Chunk with information about features @@ -299,6 +295,7 @@ namespace Exiv2 { DataBuf payload(size); io_->read(payload.pData_, size); + has_icc = iccProfileDefined(); if (equalsWebPTag(chunkId, "VP8X")) { if (has_icc){ @@ -325,14 +322,8 @@ namespace Exiv2 { throw Error(21); if (outIo.write(payload.pData_, payload.size_) != payload.size_) throw Error(21); - } else if (equalsWebPTag(chunkId, "ICCP") && has_icc) { - ul2Data(size_buff, iccProfile_.size_, littleEndian); - if (outIo.write(chunkId.pData_, TAG_SIZE) != TAG_SIZE) - throw Error(21); - if (outIo.write(size_buff, 4) != 4) - throw Error(21); - if (outIo.write(iccProfile_.pData_, iccProfile_.size_) != iccProfile_.size_) - throw Error(21); + } else if (equalsWebPTag(chunkId, "ICCP")) { + // Skip and add new data afterwards } else if (equalsWebPTag(chunkId, "EXIF")) { // Skip and add new data afterwards } else if (equalsWebPTag(chunkId, "XMP ")) { @@ -397,6 +388,15 @@ namespace Exiv2 { throw Error(21); } } + if (has_icc) { + std::string header = "ICCP"; + if (outIo.write((const byte*)header.data(), TAG_SIZE) != TAG_SIZE) throw Error(21); + ul2Data(data, (uint32_t) iccProfile_.size_, littleEndian); + if (outIo.write(data, 4) != 4) throw Error(21); + if (outIo.write((const byte*)iccProfile_.pData_, static_cast(iccProfile_.size_) != (long)iccProfile_.size_)) { + throw Error(21); + } + } // Fix File Size Payload Data outIo.seek(0, BasicIo::beg);