Page 1 of 1

Magick++ - Reading GIF Animation and accessing frames offset

Posted: 2009-09-17T13:49:24-07:00
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

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

Posted: 2009-09-17T16:40:13-07:00
by magick
You want page() which includes the virtual canvas offsets.

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

Posted: 2009-09-18T05:33:33-07:00
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.