Hi!
I've noticed recently that when building synfig-studio and some of the
images are re-rendered, the png-spritesheet target is selected over the
default png when the render command doesn't specify a target and it is
deduced from the file extension.
Meanwhile fixing that bug I've found that there are to books at target.cpp:
synfig::Target::Book* synfig::Target::book_;
synfig::Target::ExtBook* synfig::Target::ext_book_;
which are retrieved by two convenient functions:
static Book& book();
static ExtBook& ext_book();
where:
struct BookEntry
{
Factory factory;
String filename; ///< Output filename including path
TargetParam target_param; ///< Target module parameters
};
//! Book of types of targets indexed by the name of the Target.
typedef std::map<String,BookEntry> Book;
//! Book of types of targets indexed by the file extension
typedef std::map<String,String> ExtBook;
For each module, those books are filled with the proper values with the
following macros:
#define TARGET(x) \
synfig::Target::book()[synfig::String(x::name__)].factory = \
reinterpret_cast<synfig::Target::Factory> (x::create); \
synfig::Target::book()[synfig::String(x::name__)].filename = \
synfig::String(x::ext__); \
synfig::Target::book()[synfig::String(x::name__)].target_param = \
synfig::TargetParam();
\
synfig::Target::ext_book()[synfig::String(x::ext__)]=x::name__;
#define TARGET_EXT(x,y)
synfig::Target::ext_book()[synfig::String(y)]=x::name__;
Notice that although BookEntry:filename is defined as a path, it is filed
with the default extension for that target.
Also notice, that in both macros (TARGET and TARGET_EXT) the ext_book is
modified in both, so since ext_book is a map and there is only one key
occurrence for each key, if both macros are called with the same key, only
the one that is called the last time is used.
That was the reason because when the png_spritesheet target was added the
"default" target for a png extension is png-spritesheet, because its macro
was called the last one.
To fix the bug I've added a call to the TARGET_EXT macro setting the png
target for png extension as default. See commit:
https://github.com/synfig/synfig/commit/fded60762beab430517302ba441957fc7c2014e4
But this is not the only occurrence of this overwriting. Each time a module
is loaded it overwrites the default target for a given extension when the
extension is repeated. The order of overwriting is given by this list:
synfig-core\src\modules\synfig_modules.cfg
which contents is:
mod_example
mod_gif
mod_imagemagick
mod_magickpp
mod_mng
lyr_std
mod_noise
mod_filter
mod_ffmpeg
mod_bmp
mod_dv
mod_png
mod_ppm
mod_openexr
mod_jpeg
mod_libavcodec
mod_yuv420p
mod_svg
Coments:
1) We are lucky that mod_png is loaded later than mod_magickpp because on
contrary, the default target for png extension would be magickpp. Same
happen with jpg extension and others.
2) What the hell is lyr_std doing there? if the layers should be loaded,
why aren't listed the other modules of layers as well?
3) Should we put a warning somewhere to avoid to alter that list to be sure
that the overwriting is made in the proper order?
4) Would it be better to eliminate the overwriting completely so the
modules doesn't fight one against other to be the default for a given
extension?
5) Shouldn't the command line interface somehow explain which is the
default target for a given filename extension?
I think that at last a review of those macros and modules/ targets has to
be done. Any help or comments will be appreciated.
Cheers!
--
Carlos
http://synfig.org
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl