Magick++ - Reading GIF Animation and accessing frames offset

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
simoes

Magick++ - Reading GIF Animation and accessing frames offset

Post by simoes »

Hi for all

I have a study purpose project made of C++ with OpenGL.

My simple texture reading system is using Magick++;

I can thankfully say that it works for almost types I've tried to load.

The problem is that I cannot access the offset of x and y of each frame for an optimized version of gif animation.

I'm using a test like this:

Code: Select all

std::list<Magick::Image> images;
readImages( &images, "/database/obj/gif_test.gif" );

std::list<Magick::Image>::iterator it, end;
it = images.begin();
end = images.end();

while( it != end )
{
      cout << it->geometry().xOff() << endl;
    	++it;
}
The problem is when geometry() is called. It seems that no geometry is being created when i load my gif.
I have searched for other possibilities to find offsets but i could only find it under Geometry class.

Could you help me with a hint or link to a possible solution.

I've already lost a time searching an answer on google and here but I couldn't find dedicated information regarding Magick++.

Best Regards
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ - Reading GIF Animation and accessing frames offset

Post by magick »

You want page() which includes the virtual canvas offsets.
simoes

Re: Magick++ - Reading GIF Animation and accessing frames offset

Post by simoes »

Hi Admin.

Before looking your post today I've got a worst way to solve the problem since i didn't know the canvas:

Code: Select all

    class Position
    {
        double x, y, z;
        set( double _x, double _y, double _z = 0.0 )
        {
              x = _x; y = _y; z = _z;
        }
    };

    Position offset;
    for( unsigned int j = 0; j < image.rows(); ++j )
    {
    	for( unsigned int i = 0; i < image.columns(); ++i )
    	{
    		Magick::Color color = image.pixelColor( i, j );

    		if( color.alpha() < 1.0 )
    		{
    			alpha = true;
    			offset.set( -(int)i, 0 );
    		}
    	}
    	if( alpha )
    		break;
    }
and as you've posted (much better, safer and faster):

Code: Select all

Position offset;
offset.set(  image.page().xOff(), 0 );
In both cases I'm not setting y because it makes my gif to "jump".

I don't know if this is a rule to every gif animation but i've discarded yOff() from page() and it has worked equally on the same way.

Thanks for the fast reply.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 8 guests