+ // make a completely new image list
+ // this is required because:
+ // RemoveDuplicateLayers wants a linked list of images, and removes some of them
+ // when it removes an image, it invalidates it using DeleteImageFromList, but we still have it in our container
+ // when we destroy our container, the image is re-freed, failing an assertion
+
+ synfig::info("copying image list");
+ MagickLib::Image *image_list = copy_image_list(images);
+
+ synfig::info("clearing old image list");
+ images.clear();
+
+ if (!getenv("SYNFIG_DISABLE_REMOVE_DUPS"))
+ {
+ synfig::info("removing duplicate frames");
+ try
+ {
+ RemoveDuplicateLayers(&image_list, &exceptionInfo);
+ }
+ catch(Magick::Warning warning) {
+ synfig::warning("exception '%s'", warning.what());
+ }
+ }
+
+ if (!getenv("SYNFIG_DISABLE_OPTIMIZE"))
+ {
+ synfig::info("optimizing layers");
+ try
+ {
+ image_list = OptimizeImageLayers(image_list,&exceptionInfo);
+ }
+ catch(Magick::Warning warning) {
+ synfig::warning("exception '%s'", warning.what());
+ }
+ }
+
+ if (!getenv("SYNFIG_DISABLE_OPTIMIZE_TRANS"))
+ {
+ synfig::info("optimizing layer transparency");
+ try
+ {
+ OptimizeImageTransparency(image_list,&exceptionInfo);
+ }
+ catch(Magick::Warning warning) {
+ synfig::warning("exception '%s'", warning.what());
+ }
+ }
+
+ synfig::info("recreating image list");
+ insertImages(&images, image_list);