From 370512917cd16b4048015eed342731292dbc0880 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 29 Jan 2007 05:47:29 +0000 Subject: [PATCH] Applied Pomyk's patch and fixed YV12 DirectShow Originally committed to SVN as r905. --- aegisub/subs_edit_box.cpp | 3 ++- aegisub/video_context.cpp | 10 ++++++++-- aegisub/video_frame.h | 2 +- aegisub/video_provider_avs.cpp | 3 +++ aegisub/video_provider_dshow.cpp | 13 +++++++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/aegisub/subs_edit_box.cpp b/aegisub/subs_edit_box.cpp index 27fcea6e1..2483149ed 100644 --- a/aegisub/subs_edit_box.cpp +++ b/aegisub/subs_edit_box.cpp @@ -884,7 +884,7 @@ int SubsEditBox::BlockAtPos(int pos) { int max = text.Length()-1; // Find block number at pos - for (int i=0;i<=pos;i++) { + for (int i=0;i<=pos && i<=max;i++) { if (i > 0 && text[i] == _T('{')) n++; if (text[i] == _T('}') && i != max && i != pos && i != pos -1 && (i+1 == max || text[i+1] != _T('{'))) n++; } @@ -1267,3 +1267,4 @@ void SubsEditBox::OnButtonStrikeout(wxCommandEvent &event) { SetOverride(_T("\\s")); } + diff --git a/aegisub/video_context.cpp b/aegisub/video_context.cpp index a157509e1..8bce8de3d 100644 --- a/aegisub/video_context.cpp +++ b/aegisub/video_context.cpp @@ -479,9 +479,15 @@ GLuint VideoContext::GetFrameAsTexture(int n) { // UV planes for YV12 if (frame.format == FORMAT_YV12) { - glTexSubImage2D(GL_TEXTURE_2D,0,0,frame.h,frame.w/2,frame.h/2,format,GL_UNSIGNED_BYTE,frame.data[1]); + int u = 1; + int v = 2; + if (frame.invertChannels) { + u = 2; + v = 1; + } + glTexSubImage2D(GL_TEXTURE_2D,0,0,frame.h,frame.w/2,frame.h/2,format,GL_UNSIGNED_BYTE,frame.data[u]); if (glGetError() != 0) throw _T("Error uploading U plane."); - glTexSubImage2D(GL_TEXTURE_2D,0,frame.w/2,frame.h,frame.w/2,frame.h/2,format,GL_UNSIGNED_BYTE,frame.data[2]); + glTexSubImage2D(GL_TEXTURE_2D,0,frame.w/2,frame.h,frame.w/2,frame.h/2,format,GL_UNSIGNED_BYTE,frame.data[v]); if (glGetError() != 0) throw _T("Error uploadinv V plane."); } diff --git a/aegisub/video_frame.h b/aegisub/video_frame.h index d5f96df78..aa4460434 100644 --- a/aegisub/video_frame.h +++ b/aegisub/video_frame.h @@ -61,7 +61,7 @@ public: unsigned int pitch[4]; // Pitch, that is, the number of bytes used by each row. bool flipped; // First row is actually the bottom one - bool invertChannels; // Invert Red and Blue channels + bool invertChannels; // Invert Red and Blue channels or U and V planes bool cppAlloc; // Allocated with C++'s "new" operator, instead of "malloc" AegiVideoFrame(); diff --git a/aegisub/video_provider_avs.cpp b/aegisub/video_provider_avs.cpp index e880071f1..b275f09df 100644 --- a/aegisub/video_provider_avs.cpp +++ b/aegisub/video_provider_avs.cpp @@ -331,15 +331,18 @@ const AegiVideoFrame AvisynthVideoProvider::DoGetFrame(int _n) { AegiVideoFrame &final = iframe; final.flipped = false; final.cppAlloc = true; + final.invertChannels = false; // Format if (vi.IsRGB32()) { final.format = FORMAT_RGB32; final.flipped = true; + final.invertChannels = true; } else if (vi.IsRGB24()) { final.format = FORMAT_RGB24; final.flipped = true; + final.invertChannels = true; } else if (vi.IsYV12()) final.format = FORMAT_YV12; else if (vi.IsYUY2()) final.format = FORMAT_YUY2; diff --git a/aegisub/video_provider_dshow.cpp b/aegisub/video_provider_dshow.cpp index 2074e10ee..7b4107ae3 100644 --- a/aegisub/video_provider_dshow.cpp +++ b/aegisub/video_provider_dshow.cpp @@ -358,8 +358,8 @@ HRESULT DirectShowVideoProvider::OpenVideo(wxString _filename) { // Set FPS and frame duration if (defd == 0) defd = 417083; - if (fps != 0.0) defd = long long (10000000.0 / fps); - else fps = 10000000.0 / double(defd); + if (fps != 0.0) defd = long long (10000000.0 / fps) + 1; + else fps = 10000000.0 / double(++defd); // Set number of frames last_fnum = 0; @@ -434,8 +434,17 @@ void DirectShowVideoProvider::ReadFrame(long long timestamp, unsigned format, un else if (format == IVS_RGB32) df->frame.format = FORMAT_RGB32; else if (format == IVS_YV12) df->frame.format = FORMAT_YV12; + // Allocate unsigned int datalen = stride*height; df->frame.Allocate(); + + // Prepare data for YV12 + if (format == IVS_YV12) { + datalen = datalen * 3 / 2; + df->frame.invertChannels = true; + } + + // Copy memcpy(df->frame.data[0],src,datalen); } }