readImages and for_each(..., Magick::densityImage(...))

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
michalm

readImages and for_each(..., Magick::densityImage(...))

Post by michalm »

The code below is supposed to read a PDF file and write a PNG file for every page. Since 72x72 dpi is too unreadable, I'm using densityImage("300x300"). It looks like the value of the Image property does get changed, but since it happens after the PDF data has been copied (using readImages) into the Image objects, it no longer applies to them.

Code: Select all

#include <cassert>
#include <list>
#include <Magick++.h>

int main()
{
    std::list<Magick::Image> imageList; 
    readImages( &imageList, "jet.pdf" );
    assert(imageList.begin()->density() == Magick::Geometry(72,72));
    for_each(imageList.begin(), imageList.end(), Magick::densityImage("300x300")); // sets the property value correctly to 300x300 dpi
    assert(imageList.begin()->density() == Magick::Geometry(300,300));
    writeImages(imageList.begin(), imageList.end(), "jet%02d.png");  // but the image is written as if it was read 72x72 dpi
    return 0;
}
for_each works well for all the properties except for density, because it's too late for it to be changed.

What I'm trying to achieve is a multi-page version of the following routine, which works perfectly:

Code: Select all

        Magick::Image image;
        image.density("100");
        image.read("jet.pdf");
        image.write("jet.png");
One solution would be add an optional Geometry parameter to readImages(...) function, which would allow Magick++ to set density after the Image object is created, but before it's fed with data from PDF.
michalm

Re: readImages and for_each(..., Magick::densityImage(...))

Post by michalm »

Looking at STL.h file in Magick++ and at the definition of readImages function I've found something like this.

Code: Select all

  
  // Read images into existing container (appending to container)
  // FIXME: need a way to specify options like size, depth, and density.
  template <class Container>
  void readImages( Container *sequence_,
       const std::string &imageSpec_ ) {
    MagickCore::ImageInfo *imageInfo = MagickCore::CloneImageInfo(0);
    imageSpec_.copy( imageInfo->filename, MaxTextExtent-1 );
    imageInfo->filename[ imageSpec_.length() ] = 0;
    MagickCore::ExceptionInfo exceptionInfo;
    MagickCore::GetExceptionInfo( &exceptionInfo );
    MagickCore::Image* images =  MagickCore::ReadImage( imageInfo, &exceptionInfo );
    MagickCore::DestroyImageInfo(imageInfo);
    insertImages( sequence_, images);
    throwException( exceptionInfo );
    (void) MagickCore::DestroyExceptionInfo( &exceptionInfo );
  }
A FIXME. So it looks like this really is a know bug. Is there any way there to work it around?
michalm

Re: readImages and for_each(..., Magick::densityImage(...))

Post by michalm »

Is there any plan for getting rid of the FIXME in the code? It really is a bug.
Post Reply