C++ Interface, create and append to gif file

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
srwilton
Posts: 1
Joined: 2016-05-04T12:47:41-07:00
Authentication code: 1151

C++ Interface, create and append to gif file

Post by srwilton »

I'm a new imagemagick user, and currently in the process of converting a lot of my matlab code base into c++ for speed reasons. One of the tasks I need to complete is writing gif animations from RGB data, frame-by-frame, by appending the latest data to an existing file.

In matlab, this could be done with a line like this:
imwrite(imageData, colormap, filename, 'gif', 'WriteMode', 'append');

Looking at the ImageMagick++ documentation, it appears that animated files are expected to be written as one cumulative write using the STL interface.
...The STL interface must be used to operate on image sequences or images (e.g. of format GIF, TIFF, MIFF, Postscript, & MNG) which are comprized of multiple image frames...
Instead of storing multiple images inside of a container, is it possible to use a single Image object to keep track of the latest pixel data, and use the some Image:: method(s) to first create a .gif file with some animation properties and then later append new data to the existing .gif file with the same Image object?

The reason I'm doing this is because my animations are ambiguously long, depending on the raw data file being used to generate the animations. Sometimes animations can have >10000 frames, and I would prefer to offload data to disk instead of accumulating data in a container of Image variables. Since there aren't many pixels that actually change frame-to-frame and the color depth is limited, I expect the raw pixel data size in memory to be much larger than the resultant gif file.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: C++ Interface, create and append to gif file

Post by snibgo »

I don't use C++ or STL (I use C with MagickCore), but I expect the principles are the same.

When IM reads a GIF file, it creates a list (or "collection") of images, one image per frame. You can then add as many images as you want to the end of the list, and save the result as a GIF file.

GIF files are often compressed so each image contains only the differences from the previous frame. You probably want to uncompress the list after reading it, and re-compress before saving it.

At the command line, uncompressing is "-layers coalesce". Compressing is "-layers optimize". See http://www.imagemagick.org/script/comma ... php#layers
snibgo's IM pages: im.snibgo.com
Post Reply