1 /* === S I N F G =========================================================== */
2 /*! \file listimporter.cpp
3 ** \brief Template File
5 ** $Id: listimporter.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "listimporter.h"
37 /* === U S I N G =========================================================== */
41 using namespace sinfg;
43 /* === M A C R O S ========================================================= */
45 #define LIST_IMPORTER_CACHE_SIZE 20
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ListImporter::ListImporter(const String &filename)
57 ifstream stream(filename.c_str());
61 sinfg::error("Unable to open "+filename);
65 String prefix=etl::dirname(filename)+ETL_DIRECTORY_SEPERATOR;
71 // If we have a framerate, then use it
72 if(line.find(String("FPS "))==0)
74 fps=atof(String(line.begin()+4,line.end()).c_str());
75 //sinfg::warning("FPS=%f",fps);
80 filename_list.push_back(prefix+line);
85 ListImporter::create(const char *filename)
87 return new ListImporter(filename);
90 ListImporter::~ListImporter()
95 ListImporter::get_frame(Surface &surface,Time time, ProgressCallback *cb)
98 int frame=static_cast<int>(time*fps);
101 if(!filename_list.size())
103 if(cb)cb->error(_("No images in list"));
104 else sinfg::error(_("No images in list"));
110 if(frame>=(signed)filename_list.size())frame=filename_list.size()-1;
113 // See if that frame is cached
114 std::list<std::pair<int,Surface> >::iterator iter;
115 for(iter=frame_cache.begin();iter!=frame_cache.end();++iter)
117 if(iter->first==frame)
120 surface.mirror(iter->second);
121 return static_cast<bool>(surface);
125 Importer::Handle importer(Importer::open(filename_list[frame]));
131 if(cb)cb->error(_("Unable to open ")+filename_list[frame]);
132 else sinfg::error(_("Unable to open ")+filename_list[frame]);
138 if(!importer->get_frame(surface,0,cb))
140 if(cb)cb->error(_("Unable to get frame from ")+filename_list[frame]);
141 else sinfg::error(_("Unable to get frame from ")+filename_list[frame]);
147 if(frame_cache.size()>=LIST_IMPORTER_CACHE_SIZE)
148 frame_cache.pop_front();
152 frame_cache.push_back(std::pair<int,Surface>(frame,surface));
156 surface.mirror(frame_cache.back().second);
160 return static_cast<bool>(surface);
164 ListImporter::is_animated()