2008-01-21 04:58:14 +01:00
|
|
|
// Copyright (c) 2008, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2008-01-21 04:58:14 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file subtitle_format_dvd.cpp
|
|
|
|
/// @brief Writing of DVD-compatible sub-pictures
|
|
|
|
/// @ingroup subtitle_io vobsub
|
|
|
|
///
|
2008-01-21 04:58:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-21 04:58:14 +01:00
|
|
|
#include "subtitle_format_dvd.h"
|
|
|
|
#include "video_provider_dummy.h"
|
2008-03-07 22:00:20 +01:00
|
|
|
#include "subtitles_provider_manager.h"
|
2008-01-21 04:58:14 +01:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2008-03-20 22:48:47 +01:00
|
|
|
#undef _OPENMP
|
2008-01-21 06:46:52 +01:00
|
|
|
#ifdef _OPENMP
|
|
|
|
#include <omp.h>
|
|
|
|
#endif
|
2008-01-21 21:35:31 +01:00
|
|
|
#include <wx/file.h>
|
2008-01-21 04:58:14 +01:00
|
|
|
|
2008-03-20 22:48:47 +01:00
|
|
|
//#undef MAX_PATH
|
|
|
|
//#include <tessdll.h>
|
|
|
|
//
|
|
|
|
//#pragma comment(lib, "tessdll.lib")
|
|
|
|
|
2008-01-21 04:58:14 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Format name
|
|
|
|
/// @return
|
|
|
|
///
|
2008-01-21 04:58:14 +01:00
|
|
|
wxString DVDSubtitleFormat::GetName() {
|
|
|
|
return _T("DVD Subpictures");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Extensions
|
|
|
|
/// @return
|
|
|
|
///
|
2008-01-21 04:58:14 +01:00
|
|
|
wxArrayString DVDSubtitleFormat::GetWriteWildcards() {
|
|
|
|
wxArrayString results;
|
|
|
|
results.Add(_T("sup"));
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Can write
|
|
|
|
/// @param filename
|
|
|
|
/// @return
|
|
|
|
///
|
2008-01-21 04:58:14 +01:00
|
|
|
bool DVDSubtitleFormat::CanWriteFile(wxString filename) {
|
|
|
|
return (filename.Lower().EndsWith(_T(".sup")));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Get subpicture list
|
|
|
|
/// @param pics
|
|
|
|
///
|
2008-01-21 06:46:52 +01:00
|
|
|
void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
|
2008-01-21 04:58:14 +01:00
|
|
|
// Create video frame
|
|
|
|
int w = 720;
|
|
|
|
int h = 480;
|
|
|
|
VideoProvider *video = new DummyVideoProvider(10,1,w,h,wxColour(255,0,0),false);
|
2009-07-20 05:50:25 +02:00
|
|
|
AegiVideoFrame srcFrame = video->GetFrame(0);
|
2008-01-21 04:58:14 +01:00
|
|
|
delete video;
|
|
|
|
|
2008-01-21 06:46:52 +01:00
|
|
|
// Count and index lines
|
2008-01-21 04:58:14 +01:00
|
|
|
using std::list;
|
2008-01-21 06:46:52 +01:00
|
|
|
int count = 0;
|
|
|
|
std::vector<AssDialogue*> diags;
|
2008-01-21 04:58:14 +01:00
|
|
|
for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) {
|
|
|
|
AssDialogue *current = AssEntry::GetAsDialogue(*cur);
|
|
|
|
if (current) {
|
2008-01-21 06:46:52 +01:00
|
|
|
diags.push_back(current);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pics.resize(count);
|
|
|
|
|
|
|
|
SubtitlesProvider *provider = NULL;
|
2008-03-07 03:32:29 +01:00
|
|
|
provider = SubtitlesProviderFactoryManager::GetProvider();
|
2008-01-21 06:46:52 +01:00
|
|
|
provider->LoadSubtitles(GetAssFile());
|
2008-03-20 22:48:47 +01:00
|
|
|
//TessDllAPI tess;
|
2008-01-21 06:46:52 +01:00
|
|
|
|
|
|
|
// Write lines
|
2008-03-20 22:48:47 +01:00
|
|
|
int i=0;
|
2008-03-13 19:55:09 +01:00
|
|
|
#ifdef _OPENMP
|
2008-01-21 06:46:52 +01:00
|
|
|
#pragma omp parallel for shared(diags,pics,provider) private(i)
|
2008-03-13 19:55:09 +01:00
|
|
|
#endif
|
2008-01-21 06:46:52 +01:00
|
|
|
for (i=0;i<count;i++) {
|
|
|
|
// Dialogue
|
|
|
|
AssDialogue *current = diags[i];
|
|
|
|
|
|
|
|
// Get the image
|
|
|
|
AegiVideoFrame dst;
|
|
|
|
dst.CopyFrom(srcFrame);
|
2008-01-21 07:52:01 +01:00
|
|
|
double time = (current->Start.GetMS()/1000.0 + current->End.GetMS()/1000.0)/2.0;
|
2008-03-13 19:55:09 +01:00
|
|
|
#ifdef _OPENMP
|
2008-01-21 06:46:52 +01:00
|
|
|
#pragma omp critical
|
2008-03-13 19:55:09 +01:00
|
|
|
#endif
|
2008-01-21 06:46:52 +01:00
|
|
|
{
|
2008-01-21 07:52:01 +01:00
|
|
|
provider->DrawSubtitles(dst,time);
|
2008-01-21 06:46:52 +01:00
|
|
|
}
|
|
|
|
wxImage img = dst.GetImage();
|
2008-03-20 22:48:47 +01:00
|
|
|
img.SaveFile(_T("test.bmp"));
|
2008-01-21 06:46:52 +01:00
|
|
|
dst.Clear();
|
|
|
|
|
2008-03-20 22:48:47 +01:00
|
|
|
// Tesseract test
|
|
|
|
/*
|
|
|
|
tess.BeginPageUpright(img.GetWidth(),img.GetHeight(),img.GetData(),24);
|
|
|
|
ETEXT_DESC *output = tess.Recognize_all_Words();
|
|
|
|
wxString blah;
|
|
|
|
int j;
|
|
|
|
for (int cur = 0; cur < output->count; cur = j) {
|
|
|
|
const EANYCODE_CHAR* ch = &output->text[cur];
|
|
|
|
unsigned char unistr[8];
|
|
|
|
|
|
|
|
for (int b = 0; b < ch->blanks; ++b) blah += _T(" ");
|
|
|
|
|
|
|
|
for (j = cur; j < output->count; j++) {
|
|
|
|
const EANYCODE_CHAR* unich = &output->text[j];
|
|
|
|
|
|
|
|
if (ch->left != unich->left || ch->right != unich->right ||
|
|
|
|
ch->top != unich->top || ch->bottom != unich->bottom)
|
|
|
|
break;
|
|
|
|
unistr[j - cur] = static_cast<unsigned char>(unich->char_code);
|
|
|
|
}
|
|
|
|
unistr[j - cur] = '\0';
|
|
|
|
blah += wxString((char*)unistr,wxConvUTF8);
|
|
|
|
if (ch->formatting & 64) blah += _T("\n");
|
|
|
|
}
|
|
|
|
wxLogMessage(blah);
|
|
|
|
*/
|
|
|
|
|
2008-01-21 06:46:52 +01:00
|
|
|
// Perform colour reduction on image
|
|
|
|
unsigned char r,g,b;
|
|
|
|
unsigned char *data = img.GetData();
|
|
|
|
const unsigned char *dataRead = data;
|
|
|
|
unsigned char *dataWrite = data;
|
|
|
|
int startY = 0;
|
|
|
|
int endY = 0;
|
|
|
|
int startX = w;
|
|
|
|
int endX = 0;
|
|
|
|
|
|
|
|
// For each line
|
|
|
|
for (int y=h;--y>=0;) {
|
|
|
|
bool hasData = false;
|
|
|
|
int lineStartX = 0;
|
2008-03-13 19:55:09 +01:00
|
|
|
int lineEndX = 0;
|
2008-01-21 06:46:52 +01:00
|
|
|
|
|
|
|
// Scan line
|
|
|
|
for (int x=w;--x>=0;) {
|
|
|
|
// Read
|
|
|
|
r = *(dataRead++);
|
|
|
|
g = *(dataRead++);
|
|
|
|
b = *(dataRead++);
|
|
|
|
|
|
|
|
// Background
|
|
|
|
if (r > 127 && g < 20) {
|
2008-01-21 07:52:01 +01:00
|
|
|
r = 200;
|
2008-01-21 06:46:52 +01:00
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text
|
|
|
|
else {
|
|
|
|
// Mark coordinates
|
|
|
|
hasData = true;
|
|
|
|
if (lineStartX == 0) lineStartX = w-x-1;
|
|
|
|
lineEndX = w-x-1;
|
|
|
|
|
|
|
|
// Set colour
|
|
|
|
if (r > 170 && g > 170) {
|
2008-01-21 04:58:14 +01:00
|
|
|
r = 255;
|
2008-01-21 06:46:52 +01:00
|
|
|
g = 255;
|
|
|
|
b = 255;
|
|
|
|
}
|
|
|
|
else if (r > 85 && g > 85) {
|
|
|
|
r = 127;
|
|
|
|
g = 127;
|
|
|
|
b = 127;
|
2008-01-21 04:58:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-01-21 06:46:52 +01:00
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
2008-01-21 04:58:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 06:46:52 +01:00
|
|
|
// Write
|
|
|
|
*(dataWrite++) = r;
|
|
|
|
*(dataWrite++) = g;
|
|
|
|
*(dataWrite++) = b;
|
2008-01-21 04:58:14 +01:00
|
|
|
}
|
|
|
|
|
2008-01-21 06:46:52 +01:00
|
|
|
// Mark as last found so far
|
|
|
|
if (hasData) {
|
|
|
|
if (startY == 0) startY = h-y-1;
|
|
|
|
endY = h-y-1;
|
|
|
|
if (lineStartX < startX) startX = lineStartX;
|
|
|
|
if (lineEndX > endX) endX = lineEndX;
|
|
|
|
}
|
2008-01-21 04:58:14 +01:00
|
|
|
}
|
2008-01-21 06:46:52 +01:00
|
|
|
|
2008-01-21 21:35:31 +01:00
|
|
|
// Save image data
|
2008-01-21 06:46:52 +01:00
|
|
|
if (startX > endX) endX = startX;
|
|
|
|
if (startY > endY) endY = startY;
|
2008-01-21 07:52:01 +01:00
|
|
|
int sw = endX-startX+1;
|
|
|
|
int sh = endY-startY+1;
|
2008-01-21 06:46:52 +01:00
|
|
|
pics[i].x = startX;
|
|
|
|
pics[i].y = startY;
|
2008-01-21 07:52:01 +01:00
|
|
|
pics[i].w = sw;
|
|
|
|
pics[i].h = sh;
|
2008-01-21 21:35:31 +01:00
|
|
|
pics[i].start = current->Start.GetMS();
|
|
|
|
pics[i].end = current->End.GetMS();
|
2008-01-21 07:52:01 +01:00
|
|
|
|
|
|
|
// RLE to memory
|
|
|
|
for (int j=0;j<2;j++) {
|
|
|
|
int curCol = -1;
|
|
|
|
int col;
|
|
|
|
int temp;
|
|
|
|
int len = 0;
|
2008-01-21 21:35:31 +01:00
|
|
|
//wxImage subPic = img.GetSubImage(wxRect(startX,startY,sw,sh));
|
2008-01-21 07:52:01 +01:00
|
|
|
dataRead = data + ((startY+j)*w+startX)*3;
|
2008-01-21 21:35:31 +01:00
|
|
|
//dataRead = subPic.GetData();
|
2008-01-21 07:52:01 +01:00
|
|
|
std::vector<RLEGroup> groups;
|
|
|
|
groups.reserve(1024);
|
|
|
|
|
|
|
|
// Read this scanline
|
|
|
|
for (int y=startY+j;y<=endY;y+=2) {
|
|
|
|
for (int x=startX;x<=endX;x++) {
|
|
|
|
// Read current pixel colour
|
|
|
|
temp = *dataRead;
|
|
|
|
if (temp == 200) col = 0;
|
|
|
|
else if (temp == 255) col = 1;
|
|
|
|
else if (temp == 0) col = 2;
|
|
|
|
else col = 3;
|
|
|
|
|
|
|
|
// See if it matches
|
|
|
|
if (col == curCol) {
|
|
|
|
len++;
|
|
|
|
if (len == 255) {
|
2008-01-21 21:35:31 +01:00
|
|
|
groups.push_back(RLEGroup(curCol,len,false));
|
2008-01-21 07:52:01 +01:00
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (len) groups.push_back(RLEGroup(curCol,len,false));
|
|
|
|
len = 1;
|
|
|
|
curCol = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
dataRead += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush
|
|
|
|
if (len) groups.push_back(RLEGroup(curCol,0,true));
|
|
|
|
else {
|
|
|
|
groups.back().len = 0;
|
|
|
|
groups.back().eol = true;
|
|
|
|
}
|
2008-01-21 22:14:47 +01:00
|
|
|
curCol = -1;
|
|
|
|
len = 0;
|
2008-01-21 07:52:01 +01:00
|
|
|
|
|
|
|
// Advance
|
|
|
|
dataRead += (2*w-sw)*3;
|
2008-01-21 22:25:06 +01:00
|
|
|
//dataRead += sw*3;
|
2008-01-21 07:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode into subpicture format
|
|
|
|
int nibble[4];
|
|
|
|
nibble[3] = 0;
|
|
|
|
bool off = false;
|
|
|
|
std::vector<unsigned char> &data = pics[i].data[j];
|
|
|
|
unsigned char last = 0;
|
|
|
|
for (size_t m=0;m<groups.size();m++) {
|
2008-01-21 21:35:31 +01:00
|
|
|
unsigned char len = groups[m].len;
|
2008-01-21 07:52:01 +01:00
|
|
|
int nibbles;
|
2008-01-21 21:35:31 +01:00
|
|
|
|
|
|
|
// End of line, write b000000cc
|
2008-01-21 07:52:01 +01:00
|
|
|
if (groups[m].eol) nibbles = 4;
|
2008-01-21 22:25:06 +01:00
|
|
|
|
|
|
|
// Get proper nibble count
|
2008-01-21 21:35:31 +01:00
|
|
|
else {
|
|
|
|
if (len < 4) nibbles = 1;
|
|
|
|
else if (len < 16) nibbles = 2;
|
|
|
|
else if (len < 64) nibbles = 3;
|
|
|
|
else nibbles = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write nibbles
|
|
|
|
nibble[0] = groups[m].col | ((len & 0x3) << 2);
|
|
|
|
nibble[1] = (len & 0x3C) >> 2;
|
|
|
|
nibble[2] = (len & 0xC0) >> 6;
|
|
|
|
for (int n=nibbles;--n>=0;) {
|
|
|
|
wxASSERT(nibble[n] >= 0 && nibble[n] < 16);
|
|
|
|
wxASSERT(n >= 0 && n < 4);
|
2008-01-21 07:52:01 +01:00
|
|
|
if (!off) {
|
2008-01-21 21:35:31 +01:00
|
|
|
last = nibble[n] << 4;
|
2008-01-21 07:52:01 +01:00
|
|
|
data.push_back(last);
|
|
|
|
}
|
2008-01-21 21:35:31 +01:00
|
|
|
else data.back() = nibble[n] | last;
|
2008-01-21 07:52:01 +01:00
|
|
|
off = !off;
|
2008-01-21 22:25:06 +01:00
|
|
|
|
|
|
|
// Check if just wrote end of line
|
|
|
|
if (len == 0 && n == 0) {
|
|
|
|
last = 0;
|
|
|
|
off = false;
|
|
|
|
}
|
2008-01-21 07:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
data.resize(data.size());
|
|
|
|
}
|
2008-01-21 04:58:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
delete provider;
|
|
|
|
srcFrame.Clear();
|
|
|
|
}
|
2008-01-21 06:46:52 +01:00
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Actually write them
|
|
|
|
/// @param filename
|
|
|
|
/// @param encoding
|
|
|
|
///
|
2008-01-21 06:46:52 +01:00
|
|
|
void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
|
2008-01-21 21:35:31 +01:00
|
|
|
// Prepare subtitles
|
|
|
|
CreateCopy();
|
|
|
|
SortLines();
|
2008-07-18 17:39:34 +02:00
|
|
|
StripComments();
|
|
|
|
RecombineOverlaps();
|
|
|
|
MergeIdentical();
|
2008-01-21 21:35:31 +01:00
|
|
|
|
2008-01-21 06:46:52 +01:00
|
|
|
// Get subpictures
|
|
|
|
std::vector<SubPicture> pics;
|
|
|
|
GetSubPictureList(pics);
|
2008-01-21 21:35:31 +01:00
|
|
|
|
|
|
|
// Open file for writing
|
|
|
|
wxFile fp(filename,wxFile::write);
|
|
|
|
if (!fp.IsOpened()) throw _T("Could not open file for writing.");
|
|
|
|
|
|
|
|
// Write each subpicture
|
|
|
|
size_t pos = 0;
|
|
|
|
for (size_t i=0;i<pics.size();i++) {
|
|
|
|
// Write sup packet data
|
|
|
|
pos += fp.Write("SP",2);
|
|
|
|
wxUint32 temp = wxUINT32_SWAP_ON_BE(pics[i].start * 90);
|
|
|
|
pos += fp.Write(&temp,4);
|
|
|
|
temp = 0;
|
|
|
|
pos += fp.Write(&temp,4);
|
|
|
|
|
|
|
|
// Calculate lengths
|
|
|
|
size_t controlLen = 30;
|
2008-01-21 22:14:47 +01:00
|
|
|
size_t packetLen = 4 + pics[i].data[0].size() + pics[i].data[1].size() + controlLen;
|
2008-01-21 21:35:31 +01:00
|
|
|
size_t packetStart = pos;
|
|
|
|
|
|
|
|
// Write position of the next packet and control
|
|
|
|
unsigned short temp2;
|
|
|
|
temp2 = wxUINT16_SWAP_ON_LE(packetLen);
|
|
|
|
pos += fp.Write(&temp2,2);
|
|
|
|
temp2 = wxUINT16_SWAP_ON_LE(packetLen-controlLen);
|
|
|
|
pos += fp.Write(&temp2,2);
|
|
|
|
|
|
|
|
// Write RLE data
|
|
|
|
size_t line0pos = pos - packetStart;
|
|
|
|
pos += fp.Write(&pics[i].data[0][0],pics[i].data[0].size());
|
|
|
|
size_t line1pos = pos - packetStart;
|
|
|
|
pos += fp.Write(&pics[i].data[1][0],pics[i].data[1].size());
|
|
|
|
|
|
|
|
// Control group data
|
2008-03-20 22:48:47 +01:00
|
|
|
size_t comm2add = packetLen - 6;
|
2008-01-21 21:35:31 +01:00
|
|
|
unsigned char comm2_b1 = (comm2add & 0xFF00) >> 8;
|
|
|
|
unsigned char comm2_b2 = comm2add & 0xFF;
|
|
|
|
unsigned char pix0_b1 = (line0pos & 0xFF00) >> 8;
|
|
|
|
unsigned char pix0_b2 = line0pos & 0xFF;
|
|
|
|
unsigned char pix1_b1 = (line1pos & 0xFF00) >> 8;
|
|
|
|
unsigned char pix1_b2 = line1pos & 0xFF;
|
2008-01-21 22:14:47 +01:00
|
|
|
int delay = (pics[i].end - pics[i].start)*90/1024;
|
2008-01-21 21:35:31 +01:00
|
|
|
unsigned char delay_b1 = (delay & 0xFF00) >> 8;
|
|
|
|
unsigned char delay_b2 = delay & 0xFF;
|
|
|
|
int sx = pics[i].x;
|
|
|
|
int sy = pics[i].y;
|
2008-03-18 06:24:21 +01:00
|
|
|
int ex = pics[i].w + sx - 1;
|
|
|
|
int ey = pics[i].h + sy - 1;
|
2008-01-21 21:35:31 +01:00
|
|
|
unsigned char dispx_b1 = (sx & 0xFF0) >> 4;
|
|
|
|
unsigned char dispx_b2 = ((sx & 0x0F) << 4) | ((ex & 0xF00) >> 8);
|
2008-01-21 22:14:47 +01:00
|
|
|
unsigned char dispx_b3 = (ex & 0xFF);
|
2008-01-21 21:35:31 +01:00
|
|
|
unsigned char dispy_b1 = (sy & 0xFF0) >> 4;
|
|
|
|
unsigned char dispy_b2 = ((sy & 0x0F) << 4) | ((ey & 0xF00) >> 8);
|
2008-01-21 22:14:47 +01:00
|
|
|
unsigned char dispy_b3 = (ey & 0xFF);
|
2008-01-21 21:35:31 +01:00
|
|
|
|
|
|
|
// Write control group
|
|
|
|
unsigned char control[] = {
|
|
|
|
0x00, 0x00, // Delay
|
|
|
|
comm2_b1, comm2_b2, // Next command
|
2008-03-20 22:48:47 +01:00
|
|
|
0x01, // Start display
|
|
|
|
0x03, 0x82, 0x30, // Set colours
|
|
|
|
0x04, 0xFF, 0xF0, // Alpha blend
|
2008-01-21 21:35:31 +01:00
|
|
|
0x05, dispx_b1, dispx_b2, dispx_b3, dispy_b1, dispy_b2, dispy_b3, // Display area
|
|
|
|
0x06, pix0_b1, pix0_b2, pix1_b1, pix1_b2, // Pixel pointers
|
|
|
|
0xFF, // End block 1
|
|
|
|
delay_b1, delay_b2, // Delay
|
|
|
|
comm2_b1, comm2_b2, // This command
|
|
|
|
0x02, // Stop display
|
|
|
|
0xFF // End
|
|
|
|
};
|
|
|
|
pos += fp.Write(control,controlLen);
|
|
|
|
}
|
2008-01-21 06:46:52 +01:00
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|