mirror of https://github.com/odrling/Aegisub
PNG decoding should hopefully be working now, will know after I finish the avisynth filter
Originally committed to SVN as r275.
This commit is contained in:
parent
065056157c
commit
edec701f82
|
@ -124,6 +124,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
|
||||||
progress->SetProgress(0,toDraw);
|
progress->SetProgress(0,toDraw);
|
||||||
|
|
||||||
// Render all frames that were detected to contain subtitles
|
// Render all frames that were detected to contain subtitles
|
||||||
|
int lastFrameDrawn = 0;
|
||||||
int drawn = 0;
|
int drawn = 0;
|
||||||
for (int framen=0;framen<totalFrames;framen++) {
|
for (int framen=0;framen<totalFrames;framen++) {
|
||||||
// Canceled?
|
// Canceled?
|
||||||
|
@ -148,6 +149,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
|
||||||
// Get wxImage
|
// Get wxImage
|
||||||
wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y,&maxalpha);
|
wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y,&maxalpha);
|
||||||
if (!bmp.Ok()) continue;
|
if (!bmp.Ok()) continue;
|
||||||
|
lastFrameDrawn = framen;
|
||||||
|
|
||||||
// Get the list of rectangles
|
// Get the list of rectangles
|
||||||
std::vector<wxRect> rects;
|
std::vector<wxRect> rects;
|
||||||
|
@ -172,6 +174,10 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) {
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
file.Save((const char*)filename.mb_str(wxConvLocal));
|
file.Save((const char*)filename.mb_str(wxConvLocal));
|
||||||
|
|
||||||
|
// Test file
|
||||||
|
PRSVideoFrame testFrame;
|
||||||
|
file.DrawFrame(lastFrameDrawn,&testFrame);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,26 @@ void PNGWrapper::Read(PRSVideoFrame *frame) {
|
||||||
// Set data reading
|
// Set data reading
|
||||||
png_set_read_fn(png_ptr,this,memory_read_data);
|
png_set_read_fn(png_ptr,this,memory_read_data);
|
||||||
|
|
||||||
// Set row pointers
|
|
||||||
png_bytepp row_pointers = (png_bytep *) png_malloc(png_ptr, frame->h*sizeof(png_bytep));
|
|
||||||
for (int i=0; i<frame->h; i++) row_pointers[i] = (png_bytep) (frame->data[0] + frame->w*i);
|
|
||||||
png_set_rows(png_ptr, info_ptr, row_pointers);
|
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
||||||
|
png_bytepp row_pointers = png_get_rows(png_ptr, info_ptr);
|
||||||
|
|
||||||
|
// Get image size
|
||||||
|
int w = png_get_image_width(png_ptr,info_ptr);
|
||||||
|
int h = png_get_image_height(png_ptr,info_ptr);
|
||||||
|
|
||||||
|
// Allocate frame data
|
||||||
|
int bpp = 4;
|
||||||
|
frame->ownData = true;
|
||||||
|
frame->data[0] = new char[w*h*bpp];
|
||||||
|
frame->w = w;
|
||||||
|
frame->h = h;
|
||||||
|
frame->pitch = w;
|
||||||
|
frame->colorSpace = ColorSpace_RGB32;
|
||||||
|
|
||||||
|
// Copy data to frame
|
||||||
|
char *dst = frame->data[0];
|
||||||
|
for (int i=0;i<h;i++) memcpy(dst+i*w*bpp,row_pointers[i],w*bpp);
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
||||||
|
@ -126,5 +139,5 @@ void PNGWrapper::memory_read_data(png_structp png_ptr, png_bytep dstData, png_si
|
||||||
|
|
||||||
void PNGWrapper::ReadData(png_bytep dstData, png_size_t length) {
|
void PNGWrapper::ReadData(png_bytep dstData, png_size_t length) {
|
||||||
memcpy(dstData,((char*)data)+pos,length);
|
memcpy(dstData,((char*)data)+pos,length);
|
||||||
pos++;
|
pos += (int) length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,11 +270,16 @@ void PRSFile::DrawFrame(int n,PRSVideoFrame *frame) {
|
||||||
// Finds which display blocks are at a position
|
// Finds which display blocks are at a position
|
||||||
void PRSFile::GetDisplayBlocksAtFrame(int n,std::vector<PRSDisplay*> &blocks) {
|
void PRSFile::GetDisplayBlocksAtFrame(int n,std::vector<PRSDisplay*> &blocks) {
|
||||||
// Find all blocks that match
|
// Find all blocks that match
|
||||||
|
unsigned int fn = n;
|
||||||
std::list<PRSEntry*>::iterator cur;
|
std::list<PRSEntry*>::iterator cur;
|
||||||
PRSDisplay *display;
|
PRSDisplay *display;
|
||||||
for (cur=entryList.begin();cur!=entryList.end();cur++) {
|
for (cur=entryList.begin();cur!=entryList.end();cur++) {
|
||||||
display = PRSEntry::GetDisplay(*cur);
|
display = PRSEntry::GetDisplay(*cur);
|
||||||
if (display) blocks.push_back(display);
|
if (display) {
|
||||||
|
if (display->startFrame <= fn && display->endFrame >= fn) {
|
||||||
|
blocks.push_back(display);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort them by layer
|
// Sort them by layer
|
||||||
|
|
|
@ -128,14 +128,6 @@ PRSVideoFrame *PRSImage::GetDecodedFrame() {
|
||||||
// Create frame
|
// Create frame
|
||||||
PRSVideoFrame *frame = new PRSVideoFrame;
|
PRSVideoFrame *frame = new PRSVideoFrame;
|
||||||
|
|
||||||
// Allocate frame data
|
|
||||||
frame->ownData = true;
|
|
||||||
frame->data[0] = new char[w*h];
|
|
||||||
frame->w = w;
|
|
||||||
frame->h = h;
|
|
||||||
frame->pitch = w;
|
|
||||||
frame->colorSpace = ColorSpace_RGB32;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PNGWrapper png;
|
PNGWrapper png;
|
||||||
png.SetData(data);
|
png.SetData(data);
|
||||||
|
|
Loading…
Reference in New Issue