Better PRS progress bar, added a function to do glyph separation optimization (which doesn't work yet)

Originally committed to SVN as r270.
This commit is contained in:
Rodrigo Braz Monteiro 2006-03-31 23:12:03 +00:00
parent f6b9862ea3
commit 578d7c72a1
2 changed files with 33 additions and 6 deletions

View File

@ -106,26 +106,32 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
// Get range
std::vector<int> frames = GetFrameRanges();
int totalFrames = frames.size();
int toDraw = 0;
for (int i=0;i<totalFrames;i++) {
if (frames[i] == 2) toDraw++;
}
// Set variables
int totalFrames = frames.size();
id = 0;
lastDisplay = NULL;
optimizer = 0; // 0 = none, 1 = optipng, 2 = pngout
// Progress
DialogProgress *progress = new DialogProgress(NULL,_("Exporting PRS"),NULL,_("Writing file"),0,totalFrames);
DialogProgress *progress = new DialogProgress(NULL,_("Exporting PRS"),NULL,_("Writing file"),0,toDraw);
progress->Show();
progress->SetProgress(0,totalFrames);
progress->SetProgress(0,toDraw);
// Render all frames that were detected to contain subtitles
int drawn = 0;
for (int framen=0;framen<totalFrames;framen++) {
// Is this frame supposed to be rendered?
if (frames[framen] == 0) continue;
// Update progress
progress->SetProgress(framen,totalFrames);
progress->SetProgress(drawn,toDraw);
progress->SetText(wxString::Format(_T("Writing PRS file. Line: %i/%i"),framen,totalFrames));
drawn++;
// Read the frame image
PVideoFrame frame1 = clip1->GetFrame(framen,env1);
@ -139,8 +145,21 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y,&maxalpha);
if (!bmp.Ok()) continue;
// Add image to file
InsertFrame(file,framen,frames,bmp,x,y,maxalpha);
// Get the list of rectangles
std::vector<wxRect> rects;
GetSubPictureRectangles(bmp,rects);
// Add each sub-image to file
int nrects = rects.size();
for (int i=0;i<nrects;i++) {
// Pick either full image or subimage, as appropriate
wxImage curImage;
if (rects[i].x == 0 && rects[i].y == 0 && rects[i].width == bmp.GetWidth() && rects[i].height == bmp.GetHeight()) curImage = bmp;
else curImage = SubImageWithAlpha(bmp,rects[i]);
// Insert the image
InsertFrame(file,framen,frames,curImage,x,y,maxalpha);
}
}
// Destroy progress bar
@ -282,6 +301,13 @@ void PRSSubtitleFormat::InsertFrame(PRSFile &file,int &framen,std::vector<int> &
}
///////////////////////////////////
// Get rectangles of useful glyphs
void PRSSubtitleFormat::GetSubPictureRectangles(wxImage image,std::vector<wxRect> &rects) {
rects.push_back(wxRect(0,0,image.GetWidth(),image.GetHeight()));
}
////////////////////
// Get frame ranges
std::vector<int> PRSSubtitleFormat::GetFrameRanges() {

View File

@ -61,6 +61,7 @@ private:
void InsertFrame(PRSFile &file,int &framen,std::vector<int> &frames,wxImage &bmp,int x,int y,int maxalpha);
wxImage SubImageWithAlpha(wxImage src,const wxRect &area);
wxImage CalculateAlpha(const unsigned char* frame1, const unsigned char* frame2, int w, int h, int pitch, int *x=NULL, int *y=NULL, int *maxalpha=NULL);
void GetSubPictureRectangles(wxImage image,std::vector<wxRect> &rects);
std::vector<int> GetFrameRanges();
public: