From 5b74fb816edc1e0ef620d32c20c0bceabca3ee0d Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 1 Apr 2006 00:16:52 +0000 Subject: [PATCH] Sub-image splitting for PRS implemented Originally committed to SVN as r271. --- core/subtitle_format_prs.cpp | 60 ++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/core/subtitle_format_prs.cpp b/core/subtitle_format_prs.cpp index 683f2bcc2..a821ceae9 100644 --- a/core/subtitle_format_prs.cpp +++ b/core/subtitle_format_prs.cpp @@ -118,13 +118,17 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) { optimizer = 0; // 0 = none, 1 = optipng, 2 = pngout // Progress - DialogProgress *progress = new DialogProgress(NULL,_("Exporting PRS"),NULL,_("Writing file"),0,toDraw); + bool canceled = false; + DialogProgress *progress = new DialogProgress(NULL,_("Exporting PRS"),&canceled,_("Writing file"),0,toDraw); progress->Show(); progress->SetProgress(0,toDraw); // Render all frames that were detected to contain subtitles int drawn = 0; for (int framen=0;framenDestroy(); + if (!canceled) progress->Destroy(); + else return; // Save file file.Save((const char*)filename.mb_str(wxConvLocal)); @@ -304,7 +309,56 @@ void PRSSubtitleFormat::InsertFrame(PRSFile &file,int &framen,std::vector & /////////////////////////////////// // Get rectangles of useful glyphs void PRSSubtitleFormat::GetSubPictureRectangles(wxImage image,std::vector &rects) { - rects.push_back(wxRect(0,0,image.GetWidth(),image.GetHeight())); + // Boundaries + int w = image.GetWidth(); + int h = image.GetHeight(); + int startx = 0; + int starty = 0; + int endx = w-1; + int endy = h-1; + + // Variables + bool hasSubImage = false; + bool isBlankRow = true; + const unsigned char *data = image.GetAlpha(); + const unsigned char *src = data; + unsigned char a; + + // For each row + for (int y=0;y<=h;y++) { + if (y < h) { + // Reset row data + isBlankRow = true; + if (!hasSubImage) { + startx = w; + endx = -1; + } + + // Check row + for (int x=0;x endx) endx = x; + } + } + + // Set sub image status + if (!isBlankRow && !hasSubImage) { + starty = y; + hasSubImage = true; + } + } + + // If the processed row is totally blank and there is a subimage, separate them + if ((isBlankRow && hasSubImage) || y == h) { + // Insert rectangle + endy = y-1; + rects.push_back(wxRect(startx,starty,endx-startx+1,endy-starty+1)); + hasSubImage = false; + } + } }