From 021d6c28b2b8fbd53693ef88714f9144685554c4 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sun, 2 Apr 2006 15:18:38 +0000 Subject: [PATCH] Added an ASCII write mode for PRSFile Originally committed to SVN as r290. --- prs/prs_file.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ prs/prs_file.h | 3 +++ 2 files changed, 58 insertions(+) diff --git a/prs/prs_file.cpp b/prs/prs_file.cpp index 48a84297f..f1cee568e 100644 --- a/prs/prs_file.cpp +++ b/prs/prs_file.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "prs_file.h" #include "prs_entry.h" #include "prs_image.h" @@ -322,3 +323,57 @@ PRSImage *PRSFile::GetImageByID(int id) { return NULL; } + +////////////////////// +// Save as plain-text +void PRSFile::SaveText(std::string path) { + // Open file + std::ofstream file; + file.open(path.c_str(),std::fstream::out); + + // Write version string + file << "PRS-ASCII v1" << std::endl; + + // Write events + std::list::iterator cur; + for (cur=entryList.begin();cur!=entryList.end();cur++) { + PRSImage *img; + PRSDisplay *display; + + // Is image? + img = PRSEntry::GetImage(*cur); + if (img) { + // Get image filename + char idStr[64]; + itoa(img->id,idStr,10); + std::string imgfile = path; + imgfile += ".id."; + imgfile += idStr; + imgfile += ".png"; + + // Copy to disk + FILE *fp = fopen(imgfile.c_str(),"wb"); + if (fp) { + fwrite(img->data,1,img->dataLen,fp); + fclose(fp); + } + + // Write text + file << "IMG: " << img->id << "," << img->imageType << "," << imgfile.c_str() << std::endl; + continue; + } + + // Is display? + display = PRSEntry::GetDisplay(*cur); + if (display) { + // Write text + file << "DSP: " << display->startFrame << "," << display->endFrame << "," << display->start << "," << display->end; + file << display->id << "," << display->x << "," << display->y << "," << display->alpha << "," << display->blend; + file << std::endl; + continue; + } + } + + // Close file + file.close(); +} diff --git a/prs/prs_file.h b/prs/prs_file.h index 5360cbd1a..39cdd885c 100644 --- a/prs/prs_file.h +++ b/prs/prs_file.h @@ -67,6 +67,9 @@ public: void Save(std::string path); void Load(std::string path,bool reset=true); + void SaveText(std::string path); + void LoadText(std::string path,bool reset=true); + void GetDisplayBlocksAtFrame(int n,std::vector &blocks); bool HasDataAtFrame(int n); void DrawFrame(int n,PRSVideoFrame *frame);