From cc5527e2d07e7164bb07776355d7491197e40b6e Mon Sep 17 00:00:00 2001 From: dooglus Date: Sat, 27 Oct 2007 20:04:51 +0000 Subject: [PATCH] Added new module 'mod_magickpp' for rendering multiple images to a single file using Magick++. git-svn-id: http://svn.voria.com/code@988 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/config/configure.ac | 33 +++++ synfig-core/trunk/src/modules/Makefile.am | 4 +- .../trunk/src/modules/mod_magickpp/Makefile.am | 16 +++ .../trunk/src/modules/mod_magickpp/main.cpp | 54 ++++++++ .../src/modules/mod_magickpp/mod_magickpp.nsh | 11 ++ .../src/modules/mod_magickpp/trgt_magickpp.cpp | 153 +++++++++++++++++++++ .../trunk/src/modules/mod_magickpp/trgt_magickpp.h | 70 ++++++++++ .../src/modules/mod_magickpp/unmod_magickpp.nsh | 5 + .../trunk/src/modules/synfig_modules.cfg.in | 1 + 9 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/Makefile.am create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/main.cpp create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/mod_magickpp.nsh create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.cpp create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.h create mode 100644 synfig-core/trunk/src/modules/mod_magickpp/unmod_magickpp.nsh diff --git a/synfig-core/trunk/config/configure.ac b/synfig-core/trunk/config/configure.ac index 8c5d1f8..6e39207 100644 --- a/synfig-core/trunk/config/configure.ac +++ b/synfig-core/trunk/config/configure.ac @@ -153,6 +153,37 @@ if test $with_imagemagick = "no" ; then { +AC_ARG_WITH(magickpp,[ + --without-magickpp Disable support for Magick++],[ +],[ + with_magickpp="yes" +]) +if test $with_magickpp = "yes" ; then { + AC_CHECK_HEADER([Magick++.h],[ + MAGICKPP_LIBS="-lMagick++" + AC_DEFINE(HAVE_MAGICKPP,[], [ Define if Magick++ library is available ] ) + AC_SUBST(MAGICKPP_LIBS) + AM_CONDITIONAL(HAVE_LIBMAGICKPP,true) + AC_CHECK_LIB(Magick++,OptimizeImageTransparency,[ + AC_DEFINE(HAVE_MAGICK_OPTIMIZE,[], [ Define if Magick++ defines OptimizeImageTransparency() ] ) + AM_CONDITIONAL(HAVE_MAGICK_OPTIMIZE,true) + ],[ + AC_MSG_RESULT([ *** OptimizeImageTransparency() not available - need ImageMagick 6.3 or newer ]) + AM_CONDITIONAL(HAVE_MAGICK_OPTIMIZE,false) + ]) + ],[ + with_magickpp="no" + AC_MSG_RESULT([ *** Magick++ Output target disabled]) + TARGET_MAGICKPP="no" + AM_CONDITIONAL(HAVE_LIBMAGICKPP,false) + ]) +} else { + AM_CONDITIONAL(HAVE_LIBMAGICKPP,false) +} ; fi + + + + AC_ARG_WITH(ffmpeg,[ --without-ffmpeg Disable support for FFMPEG],[ ],[ @@ -551,6 +582,7 @@ src/modules/mod_gradient/Makefile src/modules/mod_imagemagick/Makefile src/modules/mod_jpeg/Makefile src/modules/mod_libavcodec/Makefile +src/modules/mod_magickpp/Makefile src/modules/mod_mng/Makefile src/modules/mod_noise/Makefile src/modules/mod_openexr/Makefile @@ -594,6 +626,7 @@ fontconfig -----------------------> $with_fontconfig libavcodec -----------------------> $with_libavcodec vImage ---------------------------> $with_vimage ImageMagick ----------------------> $with_imagemagick +Magick++ -------------------------> $with_magickpp FFMPEG ---------------------------> $with_ffmpeg libdv ----------------------------> $with_libdv OpenEXR --------------------------> $with_openexr diff --git a/synfig-core/trunk/src/modules/Makefile.am b/synfig-core/trunk/src/modules/Makefile.am index 5afc758..e190521 100644 --- a/synfig-core/trunk/src/modules/Makefile.am +++ b/synfig-core/trunk/src/modules/Makefile.am @@ -3,7 +3,7 @@ synfiglibdir=@SYNFIGLIB_DIR@ MAINTAINERCLEANFILES=Makefile.in -SUBDIRS=mod_particle mod_filter mod_yuv420p mod_gif mod_gradient mod_geometry mod_noise mod_libavcodec mod_jpeg mod_openexr mod_bmp mod_ppm mod_png mod_dv mod_imagemagick mod_ffmpeg lyr_freetype lyr_std mod_mng -EXTRA_DIST=untemplate.nsh template.nsh example/simplecircle.h example/simplecircle.cpp example/filledrect.h example/main.cpp example/Makefile.am example/filledrect.cpp example/metaballs.cpp example/metaballs.h mod_mng/trgt_mng.h mod_mng/unmod_mng.nsh mod_mng/main.cpp mod_mng/Makefile.am mod_mng/mod_mng.nsh mod_mng/trgt_mng.cpp mptr_mplayer/main.cpp mptr_mplayer/mptr_mplayer.h mptr_mplayer/Makefile.am mptr_mplayer/mptr_mplayer.cpp +SUBDIRS=mod_particle mod_filter mod_yuv420p mod_gif mod_gradient mod_geometry mod_noise mod_libavcodec mod_jpeg mod_openexr mod_bmp mod_ppm mod_png mod_dv mod_imagemagick mod_ffmpeg lyr_freetype lyr_std mod_mng mod_magickpp +EXTRA_DIST=untemplate.nsh template.nsh example/simplecircle.h example/simplecircle.cpp example/filledrect.h example/main.cpp example/Makefile.am example/filledrect.cpp example/metaballs.cpp example/metaballs.h mod_mng/trgt_mng.h mod_mng/unmod_mng.nsh mod_mng/main.cpp mod_mng/Makefile.am mod_mng/mod_mng.nsh mod_mng/trgt_mng.cpp mptr_mplayer/main.cpp mptr_mplayer/mptr_mplayer.h mptr_mplayer/Makefile.am mptr_mplayer/mptr_mplayer.cpp mod_magickpp/trgt_magickpp.h mod_magickpp/unmod_magickpp.nsh mod_magickpp/main.cpp mod_magickpp/Makefile.am mod_magickpp/mod_magickpp.nsh mod_magickpp/trgt_magickpp.cpp sysconf_DATA = synfig_modules.cfg diff --git a/synfig-core/trunk/src/modules/mod_magickpp/Makefile.am b/synfig-core/trunk/src/modules/mod_magickpp/Makefile.am new file mode 100644 index 0000000..b665f1f --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/Makefile.am @@ -0,0 +1,16 @@ +# $Id$ + +MAINTAINERCLEANFILES=Makefile.in +INCLUDES = -I$(top_srcdir)/src + +moduledir=@MODULE_DIR@ + +if HAVE_LIBMAGICKPP +module_LTLIBRARIES = libmod_magickpp.la +libmod_magickpp_la_SOURCES = main.cpp trgt_magickpp.cpp trgt_magickpp.h +libmod_magickpp_la_LDFLAGS = -module @MAGICKPP_LIBS@ -no-undefined +libmod_magickpp_la_CXXFLAGS = @SYNFIG_CFLAGS@ +libmod_magickpp_la_LIBADD = -L../../synfig -lsynfig @SYNFIG_LIBS@ +else +endif +EXTRA_DIST= mod_magickpp.nsh unmod_magickpp.nsh diff --git a/synfig-core/trunk/src/modules/mod_magickpp/main.cpp b/synfig-core/trunk/src/modules/mod_magickpp/main.cpp new file mode 100644 index 0000000..7233ab6 --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/main.cpp @@ -0,0 +1,54 @@ +/* === S Y N F I G ========================================================= */ +/*! \file mod_magickpp/main.cpp +** \brief Magick++ plugin +** +** $Id$ +** +** \legal +** Copyright 2007 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#define SYNFIG_MODULE + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "trgt_magickpp.h" +#endif + +/* === E N T R Y P O I N T ================================================= */ + +MODULE_DESC_BEGIN(mod_magickpp) + MODULE_NAME("Magick++ Module (libMagick++)") + MODULE_DESCRIPTION("Provides an animated GIF target") + MODULE_AUTHOR("Chris Moore") + MODULE_VERSION("1.0") + MODULE_COPYRIGHT(SYNFIG_COPYRIGHT) +MODULE_DESC_END + +MODULE_INVENTORY_BEGIN(mod_magickpp) + BEGIN_TARGETS + TARGET(magickpp_trgt) + END_TARGETS +MODULE_INVENTORY_END diff --git a/synfig-core/trunk/src/modules/mod_magickpp/mod_magickpp.nsh b/synfig-core/trunk/src/modules/mod_magickpp/mod_magickpp.nsh new file mode 100644 index 0000000..f186a91 --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/mod_magickpp.nsh @@ -0,0 +1,11 @@ +Section "mod_magickpp" Sec_mod_magickpp + SetOutPath "$INSTDIR\lib\synfig\modules" + File /oname=mod_magickpp.dll "src\modules\mod_magickpp\.libs\libmod_magickpp-0.dll" + FileOpen $0 $INSTDIR\etc\synfig_modules.cfg a + FileSeek $0 0 END + FileWrite $0 "mod_magickpp" + FileWriteByte $0 "13" + FileWriteByte $0 "10" + FileClose $0 +SectionEnd + diff --git a/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.cpp b/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.cpp new file mode 100644 index 0000000..68ce3df --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.cpp @@ -0,0 +1,153 @@ +/* === S Y N F I G ========================================================= */ +/*! \file trgt_magickpp.cpp +** \brief Magick++ Target Module +** +** $Id$ +** +** \legal +** Copyright 2007 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#define SYNFIG_TARGET + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "trgt_magickpp.h" + +#endif + +/* === M A C R O S ========================================================= */ + +using namespace synfig; +using namespace std; +using namespace etl; + +/* === G L O B A L S ======================================================= */ + +SYNFIG_TARGET_INIT(magickpp_trgt); +SYNFIG_TARGET_SET_NAME(magickpp_trgt,"magick++"); +SYNFIG_TARGET_SET_EXT(magickpp_trgt,"gif"); +SYNFIG_TARGET_SET_VERSION(magickpp_trgt,"0.1"); +SYNFIG_TARGET_SET_CVS_ID(magickpp_trgt,"$Id$"); + +/* === M E T H O D S ======================================================= */ + +magickpp_trgt::~magickpp_trgt() +{ + MagickLib::ExceptionInfo exceptionInfo; + MagickLib::GetExceptionInfo(&exceptionInfo); + + // check whether this file format supports multiple-image files + Magick::Image image(*(images.begin())); + image.fileName(filename); + SetImageInfo(image.imageInfo(),Magick::MagickTrue,&exceptionInfo); + + // the file type is now in image.imageInfo()->magick and + // image.adjoin() tells us whether we can write to a single file + if (image.adjoin()) + { + unsigned int delay = round_to_int(100.0 / desc.get_frame_rate()); + for_each(images.begin(), images.end(), Magick::animationDelayImage(delay)); + + // if we can write multiple images to a single file, optimize + // the images (only write the pixels that change from frame to + // frame +#ifdef HAVE_MAGICK_OPTIMIZE + linkImages(images.begin(), images.end()); + OptimizeImageTransparency(images.begin()->image(),&exceptionInfo); + unlinkImages(images.begin(), images.end()); +#else + // linkImages(images.begin(), images.end()); + // MagickLib::Image* new_images = DeconstructImages(images.begin()->image(),&exceptionInfo); + // unlinkImages(images.begin(), images.end()); + // images.clear(); + // insertImages(&images, new_images); +#endif + } + else + // if we can't write multiple images to a file of this type, + // include '%04d' in the filename, so the files will be numbered + // with a fixed width, '0'-padded number + filename = (filename_sans_extension(filename) + ".%04d" + filename_extension(filename)); + + Magick::writeImages(images.begin(), images.end(), filename); + + if (buffer != NULL) delete [] buffer; + if (color_buffer != NULL) delete [] color_buffer; +} + +bool +magickpp_trgt::set_rend_desc(RendDesc *given_desc) +{ + desc = *given_desc; + return true; +} + +bool +magickpp_trgt::init() +{ + width = desc.get_w(); + height = desc.get_h(); + + buffer = new unsigned char[4*width*height]; + if (buffer == NULL) + return false; + + color_buffer = new Color[width]; + if (color_buffer == NULL) + { + delete [] buffer; + return false; + } + + return true; +} + +void +magickpp_trgt::end_frame() +{ + Magick::Image image(width, height, "RGBA", Magick::CharPixel, buffer); + images.push_back(image); +} + +bool +magickpp_trgt::start_frame(synfig::ProgressCallback *callback) +{ + row = 0; + return true; +} + +Color* +magickpp_trgt::start_scanline(int scanline) +{ + return color_buffer; +} + +bool +magickpp_trgt::end_scanline() +{ + convert_color_format(buffer + row++ * width*4, color_buffer, width, PF_RGB|PF_A, gamma()); + return true; +} diff --git a/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.h b/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.h new file mode 100644 index 0000000..e14dea2 --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/trgt_magickpp.h @@ -0,0 +1,70 @@ +/*! ======================================================================== +** Synfig +** +** Copyright (c) 2007 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_TRGT_MAGICKPP_H +#define __SYNFIG_TRGT_MAGICKPP_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include + +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +class magickpp_trgt : public synfig::Target_Scanline +{ + SYNFIG_TARGET_MODULE_EXT + +private: + + int width, height, row; + + synfig::String filename; + unsigned char *buffer; + synfig::Color *color_buffer; + std::vector images; + +public: + + magickpp_trgt(const char *filename) : filename(filename) { } + virtual ~magickpp_trgt(); + + virtual bool set_rend_desc(synfig::RendDesc *desc); + virtual bool init(); + + virtual bool start_frame(synfig::ProgressCallback *cb); + virtual void end_frame(); + + virtual synfig::Color* start_scanline(int scanline); + virtual bool end_scanline(); +}; + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/trunk/src/modules/mod_magickpp/unmod_magickpp.nsh b/synfig-core/trunk/src/modules/mod_magickpp/unmod_magickpp.nsh new file mode 100644 index 0000000..b4001cf --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_magickpp/unmod_magickpp.nsh @@ -0,0 +1,5 @@ +Section "un.mod_magicpp" + Delete "$INSTDIR\lib\synfig\modules\mod_magicpp.dll" + RMDir "$INSTDIR" +SectionEnd + diff --git a/synfig-core/trunk/src/modules/synfig_modules.cfg.in b/synfig-core/trunk/src/modules/synfig_modules.cfg.in index 003d4d4..002c6d0 100644 --- a/synfig-core/trunk/src/modules/synfig_modules.cfg.in +++ b/synfig-core/trunk/src/modules/synfig_modules.cfg.in @@ -17,3 +17,4 @@ mod_openexr mod_jpeg mod_libavcodec mod_yuv420p +mod_magickpp -- 2.7.4