#1199 Fixing exiv2 -dC image-path to delete ICC profile.

v0.27.3
Robin Mills 9 years ago
parent a1d2a54807
commit 043c039d25

@ -239,6 +239,11 @@ namespace Exiv2 {
the actual image until the writeMetadata() method is called. the actual image until the writeMetadata() method is called.
*/ */
virtual void clearIccProfile(); 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 @brief return iccProfile
@ -433,11 +438,11 @@ namespace Exiv2 {
//@} //@}
void setTypeSupported( void setTypeSupported(
int imageType, int imageType,
uint16_t supportedMetadata uint16_t supportedMetadata
) { ) {
imageType_ = imageType; imageType_ = imageType;
supportedMetadata_ = supportedMetadata; supportedMetadata_ = supportedMetadata;
} }
int imageType() const { return imageType_; } int imageType() const { return imageType_; }

@ -949,6 +949,9 @@ namespace Action {
if (0 == rc && Params::instance().target_ & Params::ctXmp) { if (0 == rc && Params::instance().target_ & Params::ctXmp) {
rc = eraseXmpData(image.get()); rc = eraseXmpData(image.get());
} }
if (0 == rc && Params::instance().target_ & Params::ctIccProfile) {
rc = eraseIccProfile(image.get());
}
if (0 == rc && Params::instance().target_ & Params::ctIptcRaw) { if (0 == rc && Params::instance().target_ & Params::ctIptcRaw) {
rc = printStructure(std::cout,Exiv2::kpsIptcErase); rc = printStructure(std::cout,Exiv2::kpsIptcErase);
} }
@ -1032,6 +1035,14 @@ namespace Action {
image->clearXmpPacket(); image->clearXmpPacket();
return 0; 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 Erase::AutoPtr Erase::clone() const
{ {

@ -274,6 +274,10 @@ namespace Action {
@brief Erase XMP packet from the file. @brief Erase XMP packet from the file.
*/ */
int eraseXmpData(Exiv2::Image* image) const; 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) @brief Print image Structure information (used by ctIptcRaw/kpsIptcErase)
*/ */

@ -131,7 +131,7 @@ namespace Exiv2 {
bool has_exif = false; bool has_exif = false;
bool has_vp8x = false; bool has_vp8x = false;
bool has_alpha = false; bool has_alpha = false;
bool has_icc = false; bool has_icc = iccProfileDefined();
int width = 0; int width = 0;
int height = 0; int height = 0;
@ -140,10 +140,6 @@ namespace Exiv2 {
std::string xmpData; std::string xmpData;
Blob blob; Blob blob;
if (iccProfile_.size_ > 0) {
has_icc = true;
}
if (exifData_.count() > 0) { if (exifData_.count() > 0) {
ExifParser::encode(blob, littleEndian, exifData_); ExifParser::encode(blob, littleEndian, exifData_);
if (blob.size() > 0) { if (blob.size() > 0) {
@ -174,7 +170,7 @@ namespace Exiv2 {
/* Chunk with color profile. */ /* Chunk with color profile. */
if (equalsWebPTag(chunkId, "ICCP") && !has_alpha) { if (equalsWebPTag(chunkId, "ICCP") && !has_alpha) {
has_icc = true; has_icc &= true;
} }
/* Chunk with information about features /* Chunk with information about features
@ -299,6 +295,7 @@ namespace Exiv2 {
DataBuf payload(size); DataBuf payload(size);
io_->read(payload.pData_, size); io_->read(payload.pData_, size);
has_icc = iccProfileDefined();
if (equalsWebPTag(chunkId, "VP8X")) { if (equalsWebPTag(chunkId, "VP8X")) {
if (has_icc){ if (has_icc){
@ -325,14 +322,8 @@ namespace Exiv2 {
throw Error(21); throw Error(21);
if (outIo.write(payload.pData_, payload.size_) != payload.size_) if (outIo.write(payload.pData_, payload.size_) != payload.size_)
throw Error(21); throw Error(21);
} else if (equalsWebPTag(chunkId, "ICCP") && has_icc) { } else if (equalsWebPTag(chunkId, "ICCP")) {
ul2Data(size_buff, iccProfile_.size_, littleEndian); // Skip and add new data afterwards
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, "EXIF")) { } else if (equalsWebPTag(chunkId, "EXIF")) {
// Skip and add new data afterwards // Skip and add new data afterwards
} else if (equalsWebPTag(chunkId, "XMP ")) { } else if (equalsWebPTag(chunkId, "XMP ")) {
@ -397,6 +388,15 @@ namespace Exiv2 {
throw Error(21); 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<long>(iccProfile_.size_) != (long)iccProfile_.size_)) {
throw Error(21);
}
}
// Fix File Size Payload Data // Fix File Size Payload Data
outIo.seek(0, BasicIo::beg); outIo.seek(0, BasicIo::beg);

Loading…
Cancel
Save