Possible bug: Resolution Units

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
albertisi
Posts: 15
Joined: 2014-07-28T12:17:08-07:00
Authentication code: 6789

Possible bug: Resolution Units

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Resolution Units

Post 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));
}
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
albertisi
Posts: 15
Joined: 2014-07-28T12:17:08-07:00
Authentication code: 6789

Re: Possible bug: Resolution Units

Post by albertisi »

Thank you,
i looked at my old posts and re-posted it here.
-Sorry my mistake
Post Reply