From 21383519c29c4af658498e75d029538797dffff8 Mon Sep 17 00:00:00 2001 From: xy Date: Mon, 2 Jul 2012 22:11:40 +0800 Subject: [PATCH] Minor fix on MemSubpic.[PART 3] --- src/subpic/MemSubPic.cpp | 166 +++++++++++++++++++++++------------------------ src/subpic/MemSubPic.h | 3 + 2 files changed, 84 insertions(+), 85 deletions(-) diff --git a/src/subpic/MemSubPic.cpp b/src/subpic/MemSubPic.cpp index c2b718b..770ec1f 100644 --- a/src/subpic/MemSubPic.cpp +++ b/src/subpic/MemSubPic.cpp @@ -1133,96 +1133,25 @@ HRESULT CMemSubPic::AlphaBltAnv12_P010( const RECT* pSrc, const RECT* pDst, SubP int w = rs.Width(), h = rs.Height(); bool bottom_down = rd.top > rd.bottom; - BYTE* d = reinterpret_cast(dst.bits) + dst.pitch*rd.top + rd.left*2; - if(bottom_down) - { - d = reinterpret_cast(dst.bits) + dst.pitch*(rd.top-1) + rd.left*2; - dst.pitch = -dst.pitch; - } - - //dst.pitch = abs(dst.pitch); - int h2 = h/2; - if(!dst.pitchUV) + BYTE* d = NULL; + BYTE* dUV = NULL; + if(!bottom_down) { - dst.pitchUV = abs(dst.pitch); + d = reinterpret_cast(dst.bits) + dst.pitch*rd.top + rd.left*2; + dUV = reinterpret_cast(dst.bits) + dst.pitch*dst.h + dst.pitch*rd.top/2 + rd.left*2; } - dst.bitsU = reinterpret_cast(dst.bits) + abs(dst.pitch)*dst.h; - BYTE* ddUV = dst.bitsU + dst.pitchUV*rd.top/2 + rd.left*2; - if(bottom_down) + else { - ddUV = dst.bitsU + dst.pitchUV*(rd.top/2-1) + rd.left*2; - dst.pitchUV = -dst.pitchUV; + d = reinterpret_cast(dst.bits) + dst.pitch*(rd.top-1) + rd.left*2; + dUV = reinterpret_cast(dst.bits) + dst.pitch*dst.h + dst.pitch*(rd.top/2-1) + rd.left*2; + dst.pitch = -dst.pitch; } + ASSERT(dst.pitchUV==0 || dst.pitchUV==abs(dst.pitch)); - BYTE* src_origin= reinterpret_cast(src.bits) + src.pitch*rs.top + rs.left; - BYTE *s = src_origin; - - // equivalent: - // if( (reinterpret_cast(s2)&15)==0 && (reinterpret_cast(sa)&15)==0 - // && (reinterpret_cast(d2)&15)==0 ) - if( ((reinterpret_cast(s) | static_cast(src.pitch) | - reinterpret_cast(d) | static_cast(dst.pitch) ) & 15 )==0 ) - { - for(int i=0; i(d2); s2 < s2end; s2++, sa++, d3++) - { - if(sa[0] < 0xff) - { - d2[0] = ((d2[0]*sa[0])>>8) + (s2[0]<<8); - } - } - } - } - else //fix me: only a workaround for non-mod-16 size video - { - for(int i=0; i(d); - for(; s2 < s2end; s2+=1, sa+=1, d2+=1) - { - if(sa[0] < 0xff) - { - d2[0] = ((d2[0]*sa[0])>>8) + (s2[0]<<8); - } - } - } - } - - d = ddUV; - BYTE* sa = src_origin; - BYTE* s_uv = src_origin + src.pitch*src.h*2;//UV - if( ((reinterpret_cast(sa) | static_cast(src.pitch) | - reinterpret_cast(d) | static_cast(dst.pitch) ) & 15 )==0 ) - { - for(int j = 0; j < h2; j++, s_uv += src.pitch, sa += src.pitch*2, d += dst.pitchUV) - { - hleft_vmid_mix_uv_p010_sse2(d, w, s_uv, sa, src.pitch); - } - } - else - { - for(int j = 0; j < h2; j++, s_uv += src.pitch, sa += src.pitch*2, d += dst.pitchUV) - { - hleft_vmid_mix_uv_p010_c(d, w, s_uv, sa, src.pitch); - } - } - __asm emms; - return S_OK; + const BYTE* sa = reinterpret_cast(src.bits) + src.pitch*rs.top + rs.left; + const BYTE* sy = sa + src.pitch*src.h; + const BYTE* s_uv = sy + src.pitch*src.h;//UV + return AlphaBltAnv12_P010(sa, sy, s_uv, src.pitch, d, dUV, dst.pitch, w, h); } HRESULT CMemSubPic::AlphaBltAnv12_Nv12( const RECT* pSrc, const RECT* pDst, SubPicDesc* pTarget ) @@ -1306,6 +1235,73 @@ STDMETHODIMP CMemSubPic::SetDirtyRectEx(CAtlList* dirtyRectList ) // static // +HRESULT CMemSubPic::AlphaBltAnv12_P010( const BYTE* src_a, const BYTE* src_y, const BYTE* src_uv, int src_pitch, + BYTE* dst_y, BYTE* dst_uv, int dst_pitch, int w, int h ) +{ + const BYTE* sa = src_a; + if( ((reinterpret_cast(src_a) | reinterpret_cast(src_y) | static_cast(src_pitch) | + reinterpret_cast(dst_y) | static_cast(dst_pitch) ) & 15 )==0 ) + { + for(int i=0; i(d2); s2 < s2end; s2++, sa2++, d3++) + { + if(sa2[0] < 0xff) + { + d2[0] = ((d2[0]*sa2[0])>>8) + (s2[0]<<8); + } + } + } + } + else //fix me: only a workaround for non-mod-16 size video + { + for(int i=0; i(dst_y); + for(; s2 < s2end; s2+=1, sa2+=1, d2+=1) + { + if(sa2[0] < 0xff) + { + d2[0] = ((d2[0]*sa2[0])>>8) + (s2[0]<<8); + } + } + } + } + //UV + int h2 = h/2; + BYTE* d = dst_uv; + if( ((reinterpret_cast(src_a) | reinterpret_cast(src_uv) | static_cast(src_pitch) | + reinterpret_cast(dst_uv) | static_cast(dst_pitch) ) & 15 )==0 ) + { + for(int j = 0; j < h2; j++, src_uv += src_pitch, src_a += src_pitch*2, d += dst_pitch) + { + hleft_vmid_mix_uv_p010_sse2(d, w, src_uv, src_a, src_pitch); + } + } + else + { + for(int j = 0; j < h2; j++, src_uv += src_pitch, src_a += src_pitch*2, d += dst_pitch) + { + hleft_vmid_mix_uv_p010_c(d, w, src_uv, src_a, src_pitch); + } + } + __asm emms; + return S_OK; +} + HRESULT CMemSubPic::AlphaBltAnv12_Nv12( const BYTE* src_a, const BYTE* src_y, const BYTE* src_uv, int src_pitch, BYTE* dst_y, BYTE* dst_uv, int dst_pitch, int w, int h ) { diff --git a/src/subpic/MemSubPic.h b/src/subpic/MemSubPic.h index 7b0df7c..efcd8e2 100644 --- a/src/subpic/MemSubPic.h +++ b/src/subpic/MemSubPic.h @@ -65,6 +65,9 @@ public: STDMETHODIMP Unlock(CAtlList* dirtyRectList); STDMETHODIMP SetDirtyRectEx(CAtlList* dirtyRectList); public: + static HRESULT AlphaBltAnv12_P010(const BYTE* src_a, const BYTE* src_y, const BYTE* src_uv, int src_pitch, + BYTE* dst_y, BYTE* dst_uv, int dst_pitch, + int w, int h); static HRESULT AlphaBltAnv12_Nv12(const BYTE* src_a, const BYTE* src_y, const BYTE* src_uv, int src_pitch, BYTE* dst_y, BYTE* dst_uv, int dst_pitch, int w, int h); -- 2.11.4.GIT