0

I use Magick++ to process images, the codes below throw a warning:"Magick: iCCP: known incorrect sRGB profile () reported by coders/png.c:1105 (PNGWarningHandler)"

......
string img;
//assign image to this string(img)
std::list<Image> m_images;
......
Blob src_blob(image.data(), image.length());
readImages(&m_images, src_blob);//in this function throw a warning exception
if (!m_images.empty()) {
    Image image = *(m_images.begin());
}
......

But if I construct Image like this:

Blob src_blob(image.data(), image.length());
Image image(src_blob);

the codes will work and no throw exception

the identify of this image:

$identify case1.png
case1.png PNG 800x800 800x800+0+0 8-bit sRGB 807280B 0.000u 0:00.004

(I have to use readImages because I may process gif image)

yoyo
  • 31
  • 5
  • 1
    It is a warning issued by libpng library that apparently gets translated into exception in ImageMagick code. More about the underlying issue [here](https://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile). One way to get rid of the sRGB profile in the image is to open and "save as" in some image editor. Alternatively, look for some way to set 'quiet' mode in ImageMagick and suppress the warning. – Congenital Optimist Oct 16 '19 at 09:55
  • 1
    The third argument to `readImages` is for `Magick::ReadOptions`. Set `Magick::ReadOptions.quiet(true)` to suppress this warning. – emcconville Oct 16 '19 at 17:06

1 Answers1

1

Try the following...

std::list<Image> m_images;
// ...
ReadOptions opts;
opts.quiet(true);
Blob src_blob(image.data(), image.length());
readImages(&m_images, src_blob, opts);

Setting ReadOptions.quiet to true will suppress any warnings during decoding.

// From `Magick::throwException` method.
if ((quiet_) && (severity < MagickCore::ErrorException))
{
  delete nestedException;
  return;
}

But if I construct Image like this:

Blob src_blob(image.data(), image.length());
Image image(src_blob);

the codes will work and no throw exception

This is because the constructor-helper method sets quiet temporarily as a convenience.

// From Image.cpp
Magick::Image::Image(const Blob &blob_)
  : _imgRef(new ImageRef)
{
  try
  {
    // Initialize, Allocate and Read images
    quiet(true);
    read(blob_);
    quiet(false);
  }
  catch (const Error&)
  {
    // Release resources
    delete _imgRef;
    throw;
  }
}
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Thank you for your answering, I have try to set ReadOptions.quiet to true, but I found that the version of Magick++ in my company's third-party lib is so old that has no ReadOptions definition, and I have no privilege to update the lib.To solve this problem, I construct an Image object and push it back to list when readImages throw a warning. – yoyo Oct 17 '19 at 02:18
  • By the way, I am confused if it's safe to ignore this warning? – yoyo Oct 17 '19 at 02:26
  • 1
    The warning is safe to ignore. Libpng is just being more strict about incorrect iCCP profiles. The act of opening & resaving them (wiht latest libpng versions) will correct the issue. – emcconville Oct 17 '19 at 12:40
  • btw again, I set ReadOptions.quiet to true, can I assert that if **readImages** not throw Error exception, the elements in m_images are safe to operate(including all the public member function of class Image)? – yoyo Oct 18 '19 at 11:31