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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bzr

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

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
bzr

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

Post 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...
kunjbhai

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

Post 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)?
caramel1982

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

Post by caramel1982 »

Can anyone please answer the question of kunjbhai. We closely have the same problem.
Thanks in advance.

Simulation pret immobilier
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
Post Reply