Page 1 of 1

Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-03-30T07:53:21-07:00
by bzr
Not a big problem, just a bit puzzled by the interface of the Image::read function in Magick++
The following works ok:

Code: Select all

Magick::Image image;
image.read("file.tiff[3]");
But what I really would want was a function taking the frame number (3 in the example above) as a separate integer argument, which would allow usage like:

Code: Select all

int level;
// Determine what level to use...
image.read("file.tiff", level);
This to avoid having to cast integers to strings. But as far as I can see there is no way to do this, or is there?

Re: Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-03-30T09:03:28-07:00
by magick
Try setting Magick::Options::subImage(3) and Magick::Options::subRange(1) before read() and see if that does what you want. If not, we'll take a closer look at the problem.

Re: Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-03-31T02:44:45-07:00
by bzr
Thanks for the suggestion, however this:

Code: Select all

Magick::Image image;
image.subImage(3);
image.subRange(1);
image.read("file.tiff");
only gives me the first frame...

Re: Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-05-13T04:42:49-07:00
by kunjbhai
image.subImage(3);
image.subRange(1);

I was also trying to use the above methods to get the first scene from a mpg (http://cid-7572e6fdaea4368b.skydrive.li ... ic/vid.mpg) while using blob but it does not work like ("file.mpg[0]")
I used the following code:

Code: Select all

int main(int argc,char * argv)
{
	InitializeMagick(argv);
	std::string path("C:\\Tests\\vid.mpg");

/** Passing [0] in the file name itself **/
	Image *image1=new Image();
	image1->read(path+"[0]");
	image1->write("C:\\Tests\\SceneInName.jpeg");
	delete(image1);
	cout<<"Copying from image done.";

/** Asking to retrieve only first frame by using subRange **/
	ifstream fl(path.c_str(), ios::in | IOS_IN_BINARY );
	fl.seekg(0, ios::end );
	size_t blobLen = fl.tellg();
	unsigned char* blobData = new unsigned char[blobLen];
	char* c=reinterpret_cast<char *>(blobData);
	fl.seekg(0,ios::beg);
	fl.read(c, blobLen);
	fl.close();

	// Construct Magick++ Blob
	Blob blob(static_cast<const unsigned char*>(blobData), blobLen);
	delete [] blobData;

	image1=new Magick::Image();
	image1->subImage(3);
	image1->subRange(1);
		
	image1->magick("MPG");
		
	image1->read( blob);
	image1->write("C:\\Tests\\SceneInSubRange.jpeg");
	delete(image1);
	cout<<"Copying from Bytes done.";
}
Though I only get the first scene by both methods but that happens even if I don't use [0] OR subImage() and subRange() methods at all.

But in first case (path+"[0]") the time taken is way less than during subImage(),subRange() methods which suggests that they are not doing the same thing.

How can we get the same effect as (path+"[0]") for the case where we want to read image from inside a file, from an offset other than zero, (i.e. in case of blobs)?

Re: Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-05-23T04:09:21-07:00
by caramel1982
Can anyone please answer the question of kunjbhai. We closely have the same problem.
Thanks in advance.

Simulation pret immobilier

Re: Magick++ - reading specific frame of multi-page TIFF

Posted: 2009-05-23T05:53:35-07:00
by magick
Problem reports require time to investigate. A patch for the problem is in ImageMagick 6.5.2-8 Beta available here: ftp://ftp.imagemagick.org/pub/ImageMagick/beta. We should have an official release within a week or two.