Made sup exporter multi-threaded with OpenMP. <3

Originally committed to SVN as r1803.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-21 05:46:52 +00:00
parent 849921c7c5
commit 37c6828621
2 changed files with 124 additions and 77 deletions

View File

@ -44,6 +44,9 @@
#include "subtitles_provider.h" #include "subtitles_provider.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#ifdef _OPENMP
#include <omp.h>
#endif
/////////////// ///////////////
@ -70,35 +73,51 @@ bool DVDSubtitleFormat::CanWriteFile(wxString filename) {
/////////////////////// ///////////////////////
// Actually write them // Get subpicture list
void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) { void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
// Create video frame // Create video frame
int w = 720; int w = 720;
int h = 480; int h = 480;
VideoProvider *video = new DummyVideoProvider(10,1,w,h,wxColour(255,0,0),false); VideoProvider *video = new DummyVideoProvider(10,1,w,h,wxColour(255,0,0),false);
AegiVideoFrame srcFrame; AegiVideoFrame srcFrame = video->GetFrame(0);
srcFrame.CopyFrom(video->GetFrame(0));
delete video; delete video;
// Subtitles
SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider();
// Prepare subtitles // Prepare subtitles
CreateCopy(); CreateCopy();
SortLines(); SortLines();
//Merge(true,true,true); //Merge(true,true,true);
provider->LoadSubtitles(GetAssFile());
// Write lines // Count and index lines
using std::list; using std::list;
int i = 0; int count = 0;
std::vector<AssDialogue*> diags;
for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) { for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) {
AssDialogue *current = AssEntry::GetAsDialogue(*cur); AssDialogue *current = AssEntry::GetAsDialogue(*cur);
if (current) { if (current) {
diags.push_back(current);
count++;
}
}
pics.resize(count);
SubtitlesProvider *provider = NULL;
provider = SubtitlesProviderFactory::GetProvider();
provider->LoadSubtitles(GetAssFile());
// Write lines
int i;
#pragma omp parallel for shared(diags,pics,provider) private(i)
for (i=0;i<count;i++) {
// Dialogue
AssDialogue *current = diags[i];
// Get the image // Get the image
AegiVideoFrame dst; AegiVideoFrame dst;
dst.CopyFrom(srcFrame); dst.CopyFrom(srcFrame);
#pragma omp critical
{
provider->DrawSubtitles(dst,current->Start.GetMS()/1000.0); provider->DrawSubtitles(dst,current->Start.GetMS()/1000.0);
}
wxImage img = dst.GetImage(); wxImage img = dst.GetImage();
dst.Clear(); dst.Clear();
@ -108,7 +127,7 @@ void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
const unsigned char *dataRead = data; const unsigned char *dataRead = data;
unsigned char *dataWrite = data; unsigned char *dataWrite = data;
int startY = 0; int startY = 0;
int endY; int endY = 0;
int startX = w; int startX = w;
int endX = 0; int endX = 0;
@ -172,13 +191,30 @@ void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
} }
} }
// Get subpicture
wxImage subPic = img.GetSubImage(wxRect(startX,startY,endX-startX+1,endY-startY+1));
// Save image // Save image
img.GetSubImage(wxRect(startX,startY,endX-startX+1,endY-startY+1)).SaveFile(filename + wxString::Format(_T("%03i.png"),i)); if (startX > endX) endX = startX;
i++; if (startY > endY) endY = startY;
} pics[i].img = subPic;
pics[i].x = startX;
pics[i].y = startY;
} }
// Clean up // Clean up
delete provider; delete provider;
srcFrame.Clear(); srcFrame.Clear();
} }
///////////////////////
// Actually write them
void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
// Get subpictures
std::vector<SubPicture> pics;
GetSubPictureList(pics);
// Dump as PNG
//for (size_t i=0;i<pics.size();i++) pics[i].img.SaveFile(filename + wxString::Format(_T("_%03i.png"),i));
}

View File

@ -42,9 +42,20 @@
#include "subtitle_format.h" #include "subtitle_format.h"
////////////////
// Helper class
struct SubPicture {
wxImage img;
int x,y;
};
////////////////////////// //////////////////////////
// DVD subpictures writer // DVD subpictures writer
class DVDSubtitleFormat : public SubtitleFormat { class DVDSubtitleFormat : public SubtitleFormat {
private:
void GetSubPictureList(std::vector<SubPicture> &pics);
public: public:
wxString GetName(); wxString GetName();
wxArrayString GetWriteWildcards(); wxArrayString GetWriteWildcards();