1 /* === S Y N F I G ========================================================= */
2 /*! \file trgt_magickpp.cpp
3 ** \brief Magick++ Target Module
8 ** Copyright 2007 Chris Moore
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
37 #include "trgt_magickpp.h"
41 /* === M A C R O S ========================================================= */
43 using namespace synfig;
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_TARGET_INIT(magickpp_trgt);
50 SYNFIG_TARGET_SET_NAME(magickpp_trgt,"magick++");
51 SYNFIG_TARGET_SET_EXT(magickpp_trgt,"gif");
52 SYNFIG_TARGET_SET_VERSION(magickpp_trgt,"0.1");
53 SYNFIG_TARGET_SET_CVS_ID(magickpp_trgt,"$Id$");
55 /* === M E T H O D S ======================================================= */
57 magickpp_trgt::~magickpp_trgt()
59 MagickLib::ExceptionInfo exceptionInfo;
60 MagickLib::GetExceptionInfo(&exceptionInfo);
62 // check whether this file format supports multiple-image files
63 Magick::Image image(*(images.begin()));
64 image.fileName(filename);
65 SetImageInfo(image.imageInfo(),Magick::MagickTrue,&exceptionInfo);
67 // the file type is now in image.imageInfo()->magick and
68 // image.adjoin() tells us whether we can write to a single file
71 unsigned int delay = round_to_int(100.0 / desc.get_frame_rate());
72 for_each(images.begin(), images.end(), Magick::animationDelayImage(delay));
74 // if we can write multiple images to a single file, optimize
75 // the images (only write the pixels that change from frame to
77 #ifdef HAVE_MAGICK_OPTIMIZE
78 linkImages(images.begin(), images.end());
79 OptimizeImageTransparency(images.begin()->image(),&exceptionInfo);
80 unlinkImages(images.begin(), images.end());
82 // linkImages(images.begin(), images.end());
83 // MagickLib::Image* new_images = DeconstructImages(images.begin()->image(),&exceptionInfo);
84 // unlinkImages(images.begin(), images.end());
86 // insertImages(&images, new_images);
90 // if we can't write multiple images to a file of this type,
91 // include '%04d' in the filename, so the files will be numbered
92 // with a fixed width, '0'-padded number
93 filename = (filename_sans_extension(filename) + ".%04d" + filename_extension(filename));
95 Magick::writeImages(images.begin(), images.end(), filename);
97 if (buffer != NULL) delete [] buffer;
98 if (color_buffer != NULL) delete [] color_buffer;
102 magickpp_trgt::set_rend_desc(RendDesc *given_desc)
109 magickpp_trgt::init()
111 width = desc.get_w();
112 height = desc.get_h();
114 buffer = new unsigned char[4*width*height];
118 color_buffer = new Color[width];
119 if (color_buffer == NULL)
129 magickpp_trgt::end_frame()
131 Magick::Image image(width, height, "RGBA", Magick::CharPixel, buffer);
132 images.push_back(image);
136 magickpp_trgt::start_frame(synfig::ProgressCallback *callback)
143 magickpp_trgt::start_scanline(int scanline)
149 magickpp_trgt::end_scanline()
151 convert_color_format(buffer + row++ * width*4, color_buffer, width, PF_RGB|PF_A, gamma());