1 /* === S Y N F I G ========================================================= */
2 /*! \file listimporter.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "listimporter.h"
38 /* === U S I N G =========================================================== */
42 using namespace synfig;
44 /* === M A C R O S ========================================================= */
46 #define LIST_IMPORTER_CACHE_SIZE 20
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ListImporter::ListImporter(const String &filename)
58 ifstream stream(filename.c_str());
62 synfig::error("Unable to open "+filename);
66 String prefix=etl::dirname(filename)+ETL_DIRECTORY_SEPARATOR;
72 // If we have a framerate, then use it
73 if(line.find(String("FPS "))==0)
75 fps=atof(String(line.begin()+4,line.end()).c_str());
76 //synfig::warning("FPS=%f",fps);
81 filename_list.push_back(prefix+line);
86 ListImporter::create(const char *filename)
88 return new ListImporter(filename);
91 ListImporter::~ListImporter()
96 ListImporter::get_frame(Surface &surface,Time time, ProgressCallback *cb)
99 int frame=static_cast<int>(time*fps);
102 if(!filename_list.size())
104 if(cb)cb->error(_("No images in list"));
105 else synfig::error(_("No images in list"));
111 if(frame>=(signed)filename_list.size())frame=filename_list.size()-1;
114 // See if that frame is cached
115 std::list<std::pair<int,Surface> >::iterator iter;
116 for(iter=frame_cache.begin();iter!=frame_cache.end();++iter)
118 if(iter->first==frame)
121 surface.mirror(iter->second);
122 return static_cast<bool>(surface);
126 Importer::Handle importer(Importer::open(filename_list[frame]));
132 if(cb)cb->error(_("Unable to open ")+filename_list[frame]);
133 else synfig::error(_("Unable to open ")+filename_list[frame]);
139 if(!importer->get_frame(surface,0,cb))
141 if(cb)cb->error(_("Unable to get frame from ")+filename_list[frame]);
142 else synfig::error(_("Unable to get frame from ")+filename_list[frame]);
148 if(frame_cache.size()>=LIST_IMPORTER_CACHE_SIZE)
149 frame_cache.pop_front();
153 frame_cache.push_back(std::pair<int,Surface>(frame,surface));
157 surface.mirror(frame_cache.back().second);
161 return static_cast<bool>(surface);
165 ListImporter::is_animated()