X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Flistimporter.cpp;h=02680f02f8cf561eff2d3691b3640f58493c0c58;hb=756c0d29ac1742f231e6615f9a577e574e35a4af;hp=b138d660c5cb62954eedb2c8cddcee6b4b6a76c8;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/listimporter.cpp b/synfig-core/trunk/src/synfig/listimporter.cpp index b138d66..02680f0 100644 --- a/synfig-core/trunk/src/synfig/listimporter.cpp +++ b/synfig-core/trunk/src/synfig/listimporter.cpp @@ -1,20 +1,22 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file listimporter.cpp ** \brief Template File ** -** $Id: listimporter.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** 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. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** 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 */ /* ========================================================================= */ @@ -38,7 +40,7 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -58,11 +60,67 @@ ListImporter::ListImporter(const String &filename) if(!stream) { - sinfg::error("Unable to open "+filename); + synfig::error("Unable to open "+filename); return; } String line; - String prefix=etl::dirname(filename)+ETL_DIRECTORY_SEPERATOR; + String prefix=etl::dirname(filename)+ETL_DIRECTORY_SEPARATOR; + getline(stream,line); // read first line and check whether it is a Papagayo lip sync file + + if (line == "MohoSwitch1") // it is a Papagayo lipsync file + { + String phoneme, prevphoneme, prevext, ext(".jpg"); // default image format + int frame, prevframe = -1; // it means that the previous phoneme is not known + + while(!stream.eof()) + { + getline(stream,line); + + if(line.find(String("FPS ")) == 0) + { + float f = atof(String(line.begin()+4,line.end()).c_str()); + if (f) fps = f; + continue; + } + + if (line == "bmp" || + line == "gif" || + line == "jpg" || + line == "png" || + line == "ppm" || + line == "tiff" ) + { + ext = String(".") + line; + continue; + } + + size_t pos = line.find(String(" ")); // find space position. The format is "frame phoneme-name". + if(pos != String::npos) + { + frame = atoi(String(line.begin(),line.begin()+pos).c_str()); + phoneme = String(line.begin()+pos+1, line.end()); + + if (prevframe != -1) + while (prevframe < frame) + { + filename_list.push_back(prefix + prevphoneme + prevext); + synfig::info("frame %d, phoneme = %s, path = '%s'", prevframe, prevphoneme.c_str(), (prefix + prevphoneme + prevext).c_str()); + prevframe++; + } + + prevext = ext; + prevframe = frame; + prevphoneme = phoneme; + } + } + + filename_list.push_back(prefix + prevphoneme + prevext); // do it one more time for the last phoneme + synfig::info("finally, frame %d, phoneme = %s, path = '%s'", prevframe, prevphoneme.c_str(), (prefix + prevphoneme + prevext).c_str()); + + return; + } + + stream.seekg(ios_base::beg); while(!stream.eof()) { getline(stream,line); @@ -72,7 +130,7 @@ ListImporter::ListImporter(const String &filename) if(line.find(String("FPS "))==0) { fps=atof(String(line.begin()+4,line.end()).c_str()); - //sinfg::warning("FPS=%f",fps); + //synfig::warning("FPS=%f",fps); if(!fps) fps=15; continue; @@ -94,69 +152,52 @@ ListImporter::~ListImporter() bool ListImporter::get_frame(Surface &surface,Time time, ProgressCallback *cb) { -// DEBUGPOINT(); - int frame=static_cast(time*fps); -// DEBUGPOINT(); - + int frame=round_to_int(time*fps); + if(!filename_list.size()) { if(cb)cb->error(_("No images in list")); - else sinfg::error(_("No images in list")); + else synfig::error(_("No images in list")); return false; } - -// DEBUGPOINT(); + if(frame<0)frame=0; if(frame>=(signed)filename_list.size())frame=filename_list.size()-1; - -// DEBUGPOINT(); + // See if that frame is cached - std::list >::iterator iter; + std::list >::iterator iter; for(iter=frame_cache.begin();iter!=frame_cache.end();++iter) { - if(iter->first==frame) + if(iter->first==filename_list[frame]) { -// DEBUGPOINT(); surface.mirror(iter->second); return static_cast(surface); } } - + Importer::Handle importer(Importer::open(filename_list[frame])); - -// DEBUGPOINT(); if(!importer) { if(cb)cb->error(_("Unable to open ")+filename_list[frame]); - else sinfg::error(_("Unable to open ")+filename_list[frame]); + else synfig::error(_("Unable to open ")+filename_list[frame]); return false; } - -// DEBUGPOINT(); if(!importer->get_frame(surface,0,cb)) { if(cb)cb->error(_("Unable to get frame from ")+filename_list[frame]); - else sinfg::error(_("Unable to get frame from ")+filename_list[frame]); + else synfig::error(_("Unable to get frame from ")+filename_list[frame]); return false; } - -// DEBUGPOINT(); if(frame_cache.size()>=LIST_IMPORTER_CACHE_SIZE) frame_cache.pop_front(); -// DEBUGPOINT(); - - frame_cache.push_back(std::pair(frame,surface)); - -// DEBUGPOINT(); + frame_cache.push_back(std::pair(filename_list[frame],surface)); surface.mirror(frame_cache.back().second); -// DEBUGPOINT(); - return static_cast(surface); }