Page 1 of 1

Possible bug: Resolution Units

Posted: 2015-05-06T11:13:59-07:00
by albertisi
I am using Magick C++ API, to read and write PNG format files.

I have an image that i save with resolution and resolution unit like this:

Code: Select all

someImage.density(Geometry(resolution, resolution));
someImage.resolutionUnits(MagickCore::ResolutionType::PixelsPerCentimeterResolution);
someImage.write(imagePath);
Once i read the same image right after, my resolution units are set to unknown (0), why is that? I think that is the bug in magick++.
Read code:

Code: Select all

Image someImage2;
someImage2.read(imagePath);         
int resUnit2 = someImage2.resolutionUnits();
I am saving an image in PNG format. Please let me know if you need more information.
My OS Win 7 64 bit, using ImageMagick source compiled version 6.9.1-2.


Potential proposed fixed is here:

I debugged image magic, and the problem is during the retrieval of resolutionUnits from the image.
After i read the image, i call to return resolution units In Image.cpp this code gets executed

Code: Select all

Magick::ResolutionType Magick::Image::resolutionUnits(void) const
{
  return(constOptions()->resolutionUnits());
}
Unfortunately constOptions() are not set, or updated during the read, so it contains default values for all attributes.
This code should be updated to this:

Code: Select all

Magick::ResolutionType Magick::Image::resolutionUnits(void) const
{
  return(constImage()->units());
}
Image attributes contains all the attributes setup after the read, constOptions doesnt.

Re: Possible bug: Resolution Units

Posted: 2015-05-06T11:55:23-07:00
by dlemstra
We already fixed this in october 2014. Are you sure that you are using the latest source code? This is the current code:

Code: Select all

void Magick::Image::resolutionUnits(
  const Magick::ResolutionType resolutionUnits_)
{
  modifyImage();
  image()->units=resolutionUnits_;
  options()->resolutionUnits(resolutionUnits_);
}

Magick::ResolutionType Magick::Image::resolutionUnits(void) const
{
  return(static_cast<Magick::ResolutionType>(constImage()->units));
}

Re: Possible bug: Resolution Units

Posted: 2015-05-06T11:59:08-07:00
by albertisi
Thank you,
i looked at my old posts and re-posted it here.
-Sorry my mistake