PNG: always strip the existing iCCP chunk

main
Miloš Komarčević 3 years ago
parent 7ebf2a184e
commit c2fbff291e

@ -193,7 +193,6 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
const auto exifKey = upper("Raw profile type exif"); const auto exifKey = upper("Raw profile type exif");
const auto app1Key = upper("Raw profile type APP1"); const auto app1Key = upper("Raw profile type APP1");
const auto iptcKey = upper("Raw profile type iptc"); const auto iptcKey = upper("Raw profile type iptc");
const auto iccKey = upper("icc");
const auto softKey = upper("Software"); const auto softKey = upper("Software");
const auto commKey = upper("Comment"); const auto commKey = upper("Comment");
const auto descKey = upper("Description"); const auto descKey = upper("Description");
@ -272,13 +271,12 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
// for XMP, ICC etc: read and format data // for XMP, ICC etc: read and format data
const auto dataStringU = upper(dataString); const auto dataStringU = upper(dataString);
bool bXMP = option == kpsXMP && findi(dataStringU, xmpKey) == 0; bool bXMP = option == kpsXMP && findi(dataStringU, xmpKey) == 0;
bool bICC = option == kpsIccProfile && findi(dataStringU, iccKey) == 0;
bool bExif = option == kpsRecursive && (findi(dataStringU, exifKey) == 0 || findi(dataStringU, app1Key) == 0); bool bExif = option == kpsRecursive && (findi(dataStringU, exifKey) == 0 || findi(dataStringU, app1Key) == 0);
bool bIptc = option == kpsRecursive && findi(dataStringU, iptcKey) == 0; bool bIptc = option == kpsRecursive && findi(dataStringU, iptcKey) == 0;
bool bSoft = option == kpsRecursive && findi(dataStringU, softKey) == 0; bool bSoft = option == kpsRecursive && findi(dataStringU, softKey) == 0;
bool bComm = option == kpsRecursive && findi(dataStringU, commKey) == 0; bool bComm = option == kpsRecursive && findi(dataStringU, commKey) == 0;
bool bDesc = option == kpsRecursive && findi(dataStringU, descKey) == 0; bool bDesc = option == kpsRecursive && findi(dataStringU, descKey) == 0;
bool bDump = bXMP || bICC || bExif || bIptc || bSoft || bComm || bDesc || eXIf; bool bDump = bXMP || bExif || bIptc || bSoft || bComm || bDesc || iCCP || eXIf;
if (bDump) { if (bDump) {
DataBuf dataBuf; DataBuf dataBuf;
@ -346,7 +344,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
bLF = true; bLF = true;
} }
if (bICC || bComm) { if ((iCCP && option == kpsIccProfile) || bComm) {
out.write(dataBuf.c_str(), dataBuf.size()); out.write(dataBuf.c_str(), dataBuf.size());
bLF = bComm; bLF = bComm;
} }
@ -356,6 +354,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in
out.write(decoded.c_str(), decoded.size()); out.write(decoded.c_str(), decoded.size());
bLF = true; bLF = true;
} }
if (eXIf && option == kpsRecursive) { if (eXIf && option == kpsRecursive) {
// create memio object with the data, then print the structure // create memio object with the data, then print the structure
MemIo p(data.c_data(), dataOffset); MemIo p(data.c_data(), dataOffset);
@ -546,9 +545,14 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
throw Error(ErrorCode::kerImageWriteFailed); throw Error(ErrorCode::kerImageWriteFailed);
return; return;
} }
if (!strcmp(szChunk, "eXIf")) { if (!strcmp(szChunk, "eXIf") || !strcmp(szChunk, "iCCP")) {
; // do nothing Exif metadata is written following IHDR // do nothing (strip): Exif metadata is written following IHDR
; // as zTXt chunk with signature Raw profile type exif__ // as zTXt chunk with signature "Raw profile type exif",
// together with the ICC profile as a fresh iCCP chunk
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: strip " << szChunk << " chunk (length: " << dataOffset << ")"
<< std::endl;
#endif
} else if (!strcmp(szChunk, "IHDR")) { } else if (!strcmp(szChunk, "IHDR")) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n"; std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n";
@ -636,13 +640,11 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
throw Error(ErrorCode::kerImageWriteFailed); throw Error(ErrorCode::kerImageWriteFailed);
} }
} }
} else if (!strcmp(szChunk, "tEXt") || !strcmp(szChunk, "zTXt") || !strcmp(szChunk, "iTXt") || } else if (!strcmp(szChunk, "tEXt") || !strcmp(szChunk, "zTXt") || !strcmp(szChunk, "iTXt")) {
!strcmp(szChunk, "iCCP")) {
DataBuf key = PngChunk::keyTXTChunk(chunkBuf, true); DataBuf key = PngChunk::keyTXTChunk(chunkBuf, true);
if (!key.empty() && (compare("Raw profile type exif", key) || compare("Raw profile type APP1", key) || if (!key.empty() && (compare("Raw profile type exif", key) || compare("Raw profile type APP1", key) ||
compare("Raw profile type iptc", key) || compare("Raw profile type xmp", key) || compare("Raw profile type iptc", key) || compare("Raw profile type xmp", key) ||
compare("XML:com.adobe.xmp", key) || compare("icc", key) || // see test/data/imagemagick.png compare("XML:com.adobe.xmp", key) || compare("Description", key))) {
compare("ICC", key) || compare("Description", key))) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: strip " << szChunk << " chunk (length: " << dataOffset << ")" std::cout << "Exiv2::PngImage::doWriteMetadata: strip " << szChunk << " chunk (length: " << dataOffset << ")"
<< std::endl; << std::endl;

Loading…
Cancel
Save