From cf38bf30d7b48fa0f244c3245c72fc8868cfe1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Wed, 29 Jun 2022 17:53:41 +0200 Subject: [PATCH] PNG: always strip the existing iCCP chunk --- src/pngimage.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pngimage.cpp b/src/pngimage.cpp index a241554936..f29e8f2f1b 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -278,7 +278,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in bool bSoft = option == kpsRecursive && findi(dataStringU, softKey) == 0; bool bComm = option == kpsRecursive && findi(dataStringU, commKey) == 0; bool bDesc = option == kpsRecursive && findi(dataStringU, descKey) == 0; - bool bDump = bXMP || bICC || bExif || bIptc || bSoft || bComm || bDesc || eXIf; + bool bDump = bXMP || bICC || bExif || bIptc || bSoft || bComm || bDesc || iCCP || eXIf; if (bDump) { DataBuf dataBuf; @@ -546,9 +546,14 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { throw Error(ErrorCode::kerImageWriteFailed); return; } - if (!strcmp(szChunk, "eXIf")) { - ; // do nothing Exif metadata is written following IHDR - ; // as zTXt chunk with signature Raw profile type exif__ + if (!strcmp(szChunk, "eXIf") || !strcmp(szChunk, "iCCP")) { + // do nothing (strip): Exif metadata is written following IHDR + // 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")) { #ifdef EXIV2_DEBUG_MESSAGES std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n"; @@ -636,8 +641,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { throw Error(ErrorCode::kerImageWriteFailed); } } - } else if (!strcmp(szChunk, "tEXt") || !strcmp(szChunk, "zTXt") || !strcmp(szChunk, "iTXt") || - !strcmp(szChunk, "iCCP")) { + } else if (!strcmp(szChunk, "tEXt") || !strcmp(szChunk, "zTXt") || !strcmp(szChunk, "iTXt") ||) { DataBuf key = PngChunk::keyTXTChunk(chunkBuf, true); 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) ||