mirror of https://github.com/odrling/Aegisub
Made sup exporter encode subtitles (untested!), but it still can't generate a .sup file.
Originally committed to SVN as r1804.
This commit is contained in:
parent
37c6828621
commit
f8441e703c
|
@ -114,9 +114,10 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
|
||||||
// Get the image
|
// Get the image
|
||||||
AegiVideoFrame dst;
|
AegiVideoFrame dst;
|
||||||
dst.CopyFrom(srcFrame);
|
dst.CopyFrom(srcFrame);
|
||||||
|
double time = (current->Start.GetMS()/1000.0 + current->End.GetMS()/1000.0)/2.0;
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
{
|
{
|
||||||
provider->DrawSubtitles(dst,current->Start.GetMS()/1000.0);
|
provider->DrawSubtitles(dst,time);
|
||||||
}
|
}
|
||||||
wxImage img = dst.GetImage();
|
wxImage img = dst.GetImage();
|
||||||
dst.Clear();
|
dst.Clear();
|
||||||
|
@ -146,7 +147,7 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
if (r > 127 && g < 20) {
|
if (r > 127 && g < 20) {
|
||||||
r = 255;
|
r = 200;
|
||||||
g = 0;
|
g = 0;
|
||||||
b = 0;
|
b = 0;
|
||||||
}
|
}
|
||||||
|
@ -191,15 +192,88 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector<SubPicture> &pics) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get subpicture
|
|
||||||
wxImage subPic = img.GetSubImage(wxRect(startX,startY,endX-startX+1,endY-startY+1));
|
|
||||||
|
|
||||||
// Save image
|
// Save image
|
||||||
if (startX > endX) endX = startX;
|
if (startX > endX) endX = startX;
|
||||||
if (startY > endY) endY = startY;
|
if (startY > endY) endY = startY;
|
||||||
pics[i].img = subPic;
|
int sw = endX-startX+1;
|
||||||
|
int sh = endY-startY+1;
|
||||||
pics[i].x = startX;
|
pics[i].x = startX;
|
||||||
pics[i].y = startY;
|
pics[i].y = startY;
|
||||||
|
pics[i].w = sw;
|
||||||
|
pics[i].h = sh;
|
||||||
|
|
||||||
|
// RLE to memory
|
||||||
|
for (int j=0;j<2;j++) {
|
||||||
|
int curCol = -1;
|
||||||
|
int col;
|
||||||
|
int temp;
|
||||||
|
int len = 0;
|
||||||
|
dataRead = data + ((startY+j)*w+startX)*3;
|
||||||
|
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) {
|
||||||
|
if (len) groups.push_back(RLEGroup(curCol,len,false));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Advance
|
||||||
|
dataRead += (2*w-sw)*3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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++) {
|
||||||
|
int nibbles;
|
||||||
|
if (groups[m].eol) nibbles = 4;
|
||||||
|
else nibbles = groups[m].len >> 2;
|
||||||
|
nibble[0] = groups[m].col | ((groups[m].len & 0x3) << 2);
|
||||||
|
nibble[1] = (groups[m].len & 0x3C) >> 2;
|
||||||
|
nibble[2] = (groups[m].len & 0xC0) >> 6;
|
||||||
|
for (int n=0;n<nibbles;n++) {
|
||||||
|
if (!off) {
|
||||||
|
last = nibble[nibbles-n-1] << 4;
|
||||||
|
data.push_back(last);
|
||||||
|
}
|
||||||
|
else data.back() = data.back() | last;
|
||||||
|
off = !off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.resize(data.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
|
@ -214,7 +288,4 @@ void DVDSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
|
||||||
// Get subpictures
|
// Get subpictures
|
||||||
std::vector<SubPicture> pics;
|
std::vector<SubPicture> pics;
|
||||||
GetSubPictureList(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));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,20 @@
|
||||||
#include "subtitle_format.h"
|
#include "subtitle_format.h"
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
//////////////////
|
||||||
// Helper class
|
// Helper classes
|
||||||
struct SubPicture {
|
struct SubPicture {
|
||||||
wxImage img;
|
//wxImage img;
|
||||||
|
std::vector<unsigned char> data[2];
|
||||||
int x,y;
|
int x,y;
|
||||||
|
int w,h;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RLEGroup {
|
||||||
|
int col;
|
||||||
|
int len;
|
||||||
|
bool eol;
|
||||||
|
RLEGroup(int _col,int _len,bool _eol) { col = _col; len = _len; eol = _eol; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue