From 3aebff8112fb6c5d0cfb381ad9c781fa0a4b097f Mon Sep 17 00:00:00 2001 From: Oneric Date: Sat, 5 Nov 2022 01:30:54 +0100 Subject: [PATCH 1/4] cosmetic: consistenly use CRLF line endings Some source files had mixed CRLF and LF line endings which can be bothersome. To fix this convert all files with at least one preexisting CRLF line ending to full CRLF: find src/ -type f \( -name "*.h" -o -name "*.c" -o -name "*.cpp" \) -execdir \ bash -c 'cmp <(dos2unix < "$1" 2>/dev/null) "$1" 1>/dev/null || unix2dos "$1"' _ '{}' \; To confirm nothing else changed use git diff --ignore-space-change HEAD~ or git diff --ignore-cr-at-eol HEAD~ --- src/dsutil/DSUtil.cpp | 96 +- src/dsutil/DSUtil.h | 4 +- src/dsutil/xy_utils.cpp | 110 +- src/filters/transform/vsfilter/Copy.cpp | 10 +- .../transform/vsfilter/IDirectVobSubXy.h | 2 +- src/filters/transform/vsfilter/csriapi.cpp | 2 +- src/filters/transform/vsfilter/once_logger.h | 8 +- .../transform/vsfilter/timing_logger.h | 18 +- src/filters/transform/vsfilter/xy_logger.cpp | 4 +- src/subpic/DX9SubPic.cpp | 390 +++---- src/subpic/DX9SubPic.h | 100 +- src/subpic/ISimpleSubPic.h | 14 +- src/subpic/ISubPic.h | 106 +- src/subpic/MemSubPic.cpp | 228 ++-- src/subpic/MemSubPic.h | 6 +- src/subpic/PooledSubPic.cpp | 30 +- src/subpic/PooledSubPic.h | 2 +- src/subpic/SimpleSubPicProviderImpl.cpp | 382 +++---- src/subpic/SimpleSubPicProviderImpl.h | 100 +- src/subpic/SimpleSubPicWrapper.cpp | 4 +- src/subpic/SimpleSubPicWrapper.h | 2 +- src/subpic/SimpleSubpicImpl.cpp | 36 +- src/subpic/SimpleSubpicImpl.h | 2 +- src/subpic/SubPicImpl.cpp | 1006 ++++++++--------- src/subpic/SubPicProviderExWrapper.cpp | 20 +- src/subpic/SubPicProviderExWrapper.h | 88 +- src/subpic/SubPicProviderImpl.cpp | 142 +-- src/subpic/SubPicQueueImpl.h | 286 ++--- 28 files changed, 1599 insertions(+), 1599 deletions(-) diff --git a/src/dsutil/DSUtil.cpp b/src/dsutil/DSUtil.cpp index eb7d554d6..f6947a5df 100644 --- a/src/dsutil/DSUtil.cpp +++ b/src/dsutil/DSUtil.cpp @@ -27,7 +27,7 @@ #include "Mpeg2Def.h" #include "vd.h" #include "..\..\..\include\moreuuids.h" -#include +#include #include #include #include @@ -928,53 +928,53 @@ REFERENCE_TIME HMSF2RT(DVD_HMSF_TIMECODE hmsf, double fps) return (REFERENCE_TIME)((((REFERENCE_TIME)hmsf.bHours*60+hmsf.bMinutes)*60+hmsf.bSeconds)*1000+1.0*hmsf.bFrames*1000/fps)*10000; } -void memsetd(void* dst, unsigned int c, size_t nbytes) -{ -#ifndef _WIN64 - if (!(g_cpuid.m_flags & g_cpuid.sse2)) { - __asm { - mov eax, c - mov ecx, nbytes - shr ecx, 2 - mov edi, dst - cld - rep stosd - } - return; - } -#endif - size_t n = nbytes / 4; - size_t o = n - (n % 4); - - __m128i val = _mm_set1_epi32 ( (int)c ); - if (((uintptr_t)dst & 0x0F) == 0) { // 16-byte aligned - for (size_t i = 0; i < o; i+=4) { - _mm_store_si128( (__m128i*)&(((DWORD*)dst)[i]), val ); - } - } else { - for (size_t i = 0; i < o; i+=4) { - _mm_storeu_si128( (__m128i*)&(((DWORD*)dst)[i]), val ); - } - } - - switch(n - o) { - case 3: - ((DWORD*)dst)[o + 2] = c; - case 2: - ((DWORD*)dst)[o + 1] = c; - case 1: - ((DWORD*)dst)[o + 0] = c; - } -} - -void memsetw(void* dst, unsigned short c, size_t nbytes) -{ - memsetd(dst, c << 16 | c, nbytes); - - size_t n = nbytes / 2; - size_t o = (n / 2) * 2; - if ((n - o) == 1) { - ((WORD*)dst)[o] = c; +void memsetd(void* dst, unsigned int c, size_t nbytes) +{ +#ifndef _WIN64 + if (!(g_cpuid.m_flags & g_cpuid.sse2)) { + __asm { + mov eax, c + mov ecx, nbytes + shr ecx, 2 + mov edi, dst + cld + rep stosd + } + return; + } +#endif + size_t n = nbytes / 4; + size_t o = n - (n % 4); + + __m128i val = _mm_set1_epi32 ( (int)c ); + if (((uintptr_t)dst & 0x0F) == 0) { // 16-byte aligned + for (size_t i = 0; i < o; i+=4) { + _mm_store_si128( (__m128i*)&(((DWORD*)dst)[i]), val ); + } + } else { + for (size_t i = 0; i < o; i+=4) { + _mm_storeu_si128( (__m128i*)&(((DWORD*)dst)[i]), val ); + } + } + + switch(n - o) { + case 3: + ((DWORD*)dst)[o + 2] = c; + case 2: + ((DWORD*)dst)[o + 1] = c; + case 1: + ((DWORD*)dst)[o + 0] = c; + } +} + +void memsetw(void* dst, unsigned short c, size_t nbytes) +{ + memsetd(dst, c << 16 | c, nbytes); + + size_t n = nbytes / 2; + size_t o = (n / 2) * 2; + if ((n - o) == 1) { + ((WORD*)dst)[o] = c; } } diff --git a/src/dsutil/DSUtil.h b/src/dsutil/DSUtil.h index d5127c32b..f2f1fdabd 100644 --- a/src/dsutil/DSUtil.h +++ b/src/dsutil/DSUtil.h @@ -67,8 +67,8 @@ extern CString GetDriveLabel(TCHAR drive); extern bool GetKeyFrames(CString fn, CUIntArray& kfs); extern DVD_HMSF_TIMECODE RT2HMSF(REFERENCE_TIME rt, double fps = 0); extern REFERENCE_TIME HMSF2RT(DVD_HMSF_TIMECODE hmsf, double fps = 0); -extern void memsetd(void* dst, unsigned int c, size_t nbytes); -extern void memsetw(void* dst, unsigned short c, size_t nbytes); +extern void memsetd(void* dst, unsigned int c, size_t nbytes); +extern void memsetw(void* dst, unsigned short c, size_t nbytes); extern bool ExtractBIH(const AM_MEDIA_TYPE* pmt, BITMAPINFOHEADER* bih); extern bool ExtractBIH(IMediaSample* pMS, BITMAPINFOHEADER* bih); extern bool ExtractDim(const AM_MEDIA_TYPE* pmt, int& w, int& h, int& arx, int& ary); diff --git a/src/dsutil/xy_utils.cpp b/src/dsutil/xy_utils.cpp index 38d3b7caa..9a3627a5c 100644 --- a/src/dsutil/xy_utils.cpp +++ b/src/dsutil/xy_utils.cpp @@ -1,10 +1,10 @@ -#include "stdafx.h" -#include "xy_utils.h" -#include -#include - -void MergeRects(const CAtlList& input, CAtlList* output) -{ +#include "stdafx.h" +#include "xy_utils.h" +#include +#include + +void MergeRects(const CAtlList& input, CAtlList* output) +{ if(output==NULL || input.GetCount()==0) return; @@ -105,51 +105,51 @@ void MergeRects(const CAtlList& input, CAtlList* output) tempSegments[start].seg_end=rect.right; } } - } - for (int i=count-1;i>0;i--) - { - CAtlList& cur_line = *tempSegments[i].rects; - CRect cur_rect = cur_line.RemoveTail(); - if(tempSegments[i].top == tempSegments[i-1].bottom) - { - CAtlList& upper_line = *tempSegments[i-1].rects; - - POSITION pos = upper_line.GetTailPosition(); - while(pos) - { - CRect& upper_rect = upper_line.GetPrev(pos); - while( upper_rect.rightAddHead(cur_rect); - //if(!cur_line.IsEmpty()) - cur_rect = cur_line.RemoveTail(); - } - if(cur_line.IsEmpty()) - break; - - if(upper_rect.right==cur_rect.right && upper_rect.left==cur_rect.left) - { - upper_rect.bottom = cur_rect.bottom; - //if(!cur_line.IsEmpty()) - cur_rect = cur_line.RemoveTail(); - } - //else if ( upper_rect.right>cur_rect.right || upper_rect.left>cur_rect.left ) - } - } - while(!cur_line.IsEmpty()) - { - output->AddHead(cur_rect); - cur_rect = cur_line.RemoveTail(); - } - } - if(count>0) - { - CAtlList& cur_line = *tempSegments[0].rects; - CRect cur_rect = cur_line.RemoveTail(); - while(!cur_line.IsEmpty()) - { - output->AddHead(cur_rect); - cur_rect = cur_line.RemoveTail(); - } - } -} + } + for (int i=count-1;i>0;i--) + { + CAtlList& cur_line = *tempSegments[i].rects; + CRect cur_rect = cur_line.RemoveTail(); + if(tempSegments[i].top == tempSegments[i-1].bottom) + { + CAtlList& upper_line = *tempSegments[i-1].rects; + + POSITION pos = upper_line.GetTailPosition(); + while(pos) + { + CRect& upper_rect = upper_line.GetPrev(pos); + while( upper_rect.rightAddHead(cur_rect); + //if(!cur_line.IsEmpty()) + cur_rect = cur_line.RemoveTail(); + } + if(cur_line.IsEmpty()) + break; + + if(upper_rect.right==cur_rect.right && upper_rect.left==cur_rect.left) + { + upper_rect.bottom = cur_rect.bottom; + //if(!cur_line.IsEmpty()) + cur_rect = cur_line.RemoveTail(); + } + //else if ( upper_rect.right>cur_rect.right || upper_rect.left>cur_rect.left ) + } + } + while(!cur_line.IsEmpty()) + { + output->AddHead(cur_rect); + cur_rect = cur_line.RemoveTail(); + } + } + if(count>0) + { + CAtlList& cur_line = *tempSegments[0].rects; + CRect cur_rect = cur_line.RemoveTail(); + while(!cur_line.IsEmpty()) + { + output->AddHead(cur_rect); + cur_rect = cur_line.RemoveTail(); + } + } +} diff --git a/src/filters/transform/vsfilter/Copy.cpp b/src/filters/transform/vsfilter/Copy.cpp index a947ce2c6..7efd12945 100644 --- a/src/filters/transform/vsfilter/Copy.cpp +++ b/src/filters/transform/vsfilter/Copy.cpp @@ -306,10 +306,10 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut) _T(" bitmap :%ld/%ld/%ld\t\t")\ _T(" scan line:%ld/%ld/%ld\n")\ _T(" relay key:%ld/%ld/%ld\t\t")\ - _T(" clipper :%ld/%ld/%ld\n")\ - _T("\n")\ + _T(" clipper :%ld/%ld/%ld\n")\ + _T("\n")\ _T(" FW string pool :%ld/%ld/%ld\t\t")\ - _T(" FW bitmap key pool:%ld/%ld/%ld\n")\ + _T(" FW bitmap key pool:%ld/%ld/%ld\n")\ , caches_info->text_info_cache_cur_item_num, caches_info->text_info_cache_hit_count, caches_info->text_info_cache_query_count, caches_info->word_info_cache_cur_item_num, caches_info->word_info_cache_hit_count, caches_info->word_info_cache_query_count, @@ -322,9 +322,9 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut) caches_info->scanline_cache_cur_item_num, caches_info->scanline_cache_hit_count, caches_info->scanline_cache_query_count, caches_info->overlay_key_cache_cur_item_num, caches_info->overlay_key_cache_hit_count, caches_info->overlay_key_cache_query_count, caches_info->clipper_cache_cur_item_num, caches_info->clipper_cache_hit_count, caches_info->clipper_cache_query_count, - + xy_fw_info->xy_fw_string_w.cur_item_num, xy_fw_info->xy_fw_string_w.hit_count, xy_fw_info->xy_fw_string_w.query_count, - xy_fw_info->xy_fw_grouped_draw_items_hash_key.cur_item_num, xy_fw_info->xy_fw_grouped_draw_items_hash_key.hit_count, xy_fw_info->xy_fw_grouped_draw_items_hash_key.query_count + xy_fw_info->xy_fw_grouped_draw_items_hash_key.cur_item_num, xy_fw_info->xy_fw_grouped_draw_items_hash_key.hit_count, xy_fw_info->xy_fw_grouped_draw_items_hash_key.query_count ); msg += tmp; delete []caches_info; diff --git a/src/filters/transform/vsfilter/IDirectVobSubXy.h b/src/filters/transform/vsfilter/IDirectVobSubXy.h index 01c0cbb33..18f2d2047 100644 --- a/src/filters/transform/vsfilter/IDirectVobSubXy.h +++ b/src/filters/transform/vsfilter/IDirectVobSubXy.h @@ -93,7 +93,7 @@ namespace DirectVobSubXyOptions struct XyFlyWeightInfo { CacheInfo xy_fw_string_w; - CacheInfo xy_fw_grouped_draw_items_hash_key; + CacheInfo xy_fw_grouped_draw_items_hash_key; }; enum LayoutSizeOpt { diff --git a/src/filters/transform/vsfilter/csriapi.cpp b/src/filters/transform/vsfilter/csriapi.cpp index 37a6de580..b032db02d 100644 --- a/src/filters/transform/vsfilter/csriapi.cpp +++ b/src/filters/transform/vsfilter/csriapi.cpp @@ -176,4 +176,4 @@ static struct csri_info csri_vsfilter_info = { CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend) { return &csri_vsfilter_info; } CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific) { return &csri_vsfilter; } CSRIAPI csri_rend *csri_renderer_default() { return &csri_vsfilter; } -CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev) { return 0; } \ No newline at end of file +CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev) { return 0; } diff --git a/src/filters/transform/vsfilter/once_logger.h b/src/filters/transform/vsfilter/once_logger.h index 16617fc02..d7f091d80 100644 --- a/src/filters/transform/vsfilter/once_logger.h +++ b/src/filters/transform/vsfilter/once_logger.h @@ -24,7 +24,7 @@ class OnceLogger s_entered[id]++; if(logger.isEnabledFor(TRACE_LOG_LEVEL)) - { + { std::wostringstream buff; buff< -#include +#include #include "DX9SubPic.h" // // CDX9SubPic // -CDX9SubPic::CDX9SubPic(IDirect3DSurface9* pSurface, CDX9SubPicAllocator *pAllocator, bool bExternalRenderer) - : m_pSurface(pSurface), m_pAllocator(pAllocator), m_bExternalRenderer(bExternalRenderer) +CDX9SubPic::CDX9SubPic(IDirect3DSurface9* pSurface, CDX9SubPicAllocator *pAllocator, bool bExternalRenderer) + : m_pSurface(pSurface), m_pAllocator(pAllocator), m_bExternalRenderer(bExternalRenderer) { D3DSURFACE_DESC d3dsd; ZeroMemory(&d3dsd, sizeof(d3dsd)); - if(SUCCEEDED(m_pSurface->GetDesc(&d3dsd))) { + if(SUCCEEDED(m_pSurface->GetDesc(&d3dsd))) { m_maxsize.SetSize(d3dsd.Width, d3dsd.Height); m_rcDirty.SetRect(0, 0, d3dsd.Width, d3dsd.Height); - } -} - -CDX9SubPic::~CDX9SubPic() -{ - { - CAutoLock Lock(&CDX9SubPicAllocator::ms_SurfaceQueueLock); - // Add surface to cache - if (m_pAllocator) { - for (POSITION pos = m_pAllocator->m_AllocatedSurfaces.GetHeadPosition(); pos; ) { - POSITION ThisPos = pos; - CDX9SubPic *pSubPic = m_pAllocator->m_AllocatedSurfaces.GetNext(pos); - if (pSubPic == this) { - m_pAllocator->m_AllocatedSurfaces.RemoveAt(ThisPos); - break; - } - } - m_pAllocator->m_FreeSurfaces.AddTail(m_pSurface); - } } } - +CDX9SubPic::~CDX9SubPic() +{ + { + CAutoLock Lock(&CDX9SubPicAllocator::ms_SurfaceQueueLock); + // Add surface to cache + if (m_pAllocator) { + for (POSITION pos = m_pAllocator->m_AllocatedSurfaces.GetHeadPosition(); pos; ) { + POSITION ThisPos = pos; + CDX9SubPic *pSubPic = m_pAllocator->m_AllocatedSurfaces.GetNext(pos); + if (pSubPic == this) { + m_pAllocator->m_AllocatedSurfaces.RemoveAt(ThisPos); + break; + } + } + m_pAllocator->m_FreeSurfaces.AddTail(m_pSurface); + } + } +} + + // ISubPic STDMETHODIMP_(void*) CDX9SubPic::GetObject() const { CComPtr pTexture; - if(SUCCEEDED(m_pSurface->GetContainer(IID_IDirect3DTexture9, (void**)&pTexture))) { + if(SUCCEEDED(m_pSurface->GetContainer(IID_IDirect3DTexture9, (void**)&pTexture))) { return (void*)(IDirect3DTexture9*)pTexture; - } + } return NULL; } @@ -75,9 +75,9 @@ STDMETHODIMP CDX9SubPic::GetDesc(SubPicDesc& spd) const { D3DSURFACE_DESC d3dsd; ZeroMemory(&d3dsd, sizeof(d3dsd)); - if(FAILED(m_pSurface->GetDesc(&d3dsd))) { + if(FAILED(m_pSurface->GetDesc(&d3dsd))) { return E_FAIL; - } + } spd.type = 0; spd.w = m_size.cx; @@ -95,50 +95,50 @@ STDMETHODIMP CDX9SubPic::GetDesc(SubPicDesc& spd) const STDMETHODIMP CDX9SubPic::CopyTo(ISubPic* pSubPic) { HRESULT hr; - if(FAILED(hr = __super::CopyTo(pSubPic))) { + if(FAILED(hr = __super::CopyTo(pSubPic))) { return hr; - } + } - if(m_rcDirty.IsRectEmpty()) { + if(m_rcDirty.IsRectEmpty()) { return S_FALSE; - } + } CComPtr pD3DDev; - if(!m_pSurface || FAILED(m_pSurface->GetDevice(&pD3DDev)) || !pD3DDev) { + if(!m_pSurface || FAILED(m_pSurface->GetDevice(&pD3DDev)) || !pD3DDev) { return E_FAIL; - } - - IDirect3DTexture9* pSrcTex = (IDirect3DTexture9*)GetObject(); - CComPtr pSrcSurf; - pSrcTex->GetSurfaceLevel(0, &pSrcSurf); - D3DSURFACE_DESC srcDesc; - pSrcSurf->GetDesc(&srcDesc); - - IDirect3DTexture9* pDstTex = (IDirect3DTexture9*)pSubPic->GetObject(); - CComPtr pDstSurf; - pDstTex->GetSurfaceLevel(0, &pDstSurf); - D3DSURFACE_DESC dstDesc; - pDstSurf->GetDesc(&dstDesc); - - RECT r; - SetRect(&r, 0, 0, min(srcDesc.Width, dstDesc.Width), min(srcDesc.Height, dstDesc.Height)); - POINT p = { 0, 0 }; - hr = pD3DDev->UpdateSurface(pSrcSurf, &r, pDstSurf, &p); - // ASSERT (SUCCEEDED (hr)); + } + + IDirect3DTexture9* pSrcTex = (IDirect3DTexture9*)GetObject(); + CComPtr pSrcSurf; + pSrcTex->GetSurfaceLevel(0, &pSrcSurf); + D3DSURFACE_DESC srcDesc; + pSrcSurf->GetDesc(&srcDesc); + + IDirect3DTexture9* pDstTex = (IDirect3DTexture9*)pSubPic->GetObject(); + CComPtr pDstSurf; + pDstTex->GetSurfaceLevel(0, &pDstSurf); + D3DSURFACE_DESC dstDesc; + pDstSurf->GetDesc(&dstDesc); + + RECT r; + SetRect(&r, 0, 0, min(srcDesc.Width, dstDesc.Width), min(srcDesc.Height, dstDesc.Height)); + POINT p = { 0, 0 }; + hr = pD3DDev->UpdateSurface(pSrcSurf, &r, pDstSurf, &p); + // ASSERT (SUCCEEDED (hr)); return SUCCEEDED(hr) ? S_OK : E_FAIL; } STDMETHODIMP CDX9SubPic::ClearDirtyRect(DWORD color) { - if(m_rcDirty.IsRectEmpty()) { + if(m_rcDirty.IsRectEmpty()) { return S_FALSE; - } + } CComPtr pD3DDev; - if(!m_pSurface || FAILED(m_pSurface->GetDevice(&pD3DDev)) || !pD3DDev) { + if(!m_pSurface || FAILED(m_pSurface->GetDevice(&pD3DDev)) || !pD3DDev) { return E_FAIL; - } + } SubPicDesc spd; if(SUCCEEDED(Lock(spd))) { @@ -146,17 +146,17 @@ STDMETHODIMP CDX9SubPic::ClearDirtyRect(DWORD color) BYTE* ptr = (BYTE*)spd.bits + spd.pitch*m_rcDirty.top + (m_rcDirty.left*spd.bpp>>3); - if(spd.bpp == 16) { - while(h-- > 0) { - memsetw(ptr, color, 2 * m_rcDirty.Width()); + if(spd.bpp == 16) { + while(h-- > 0) { + memsetw(ptr, color, 2 * m_rcDirty.Width()); ptr += spd.pitch; } - } else if(spd.bpp == 32) { - while(h-- > 0) { - memsetd(ptr, color, 4 * m_rcDirty.Width()); + } else if(spd.bpp == 32) { + while(h-- > 0) { + memsetd(ptr, color, 4 * m_rcDirty.Width()); ptr += spd.pitch; } - } + } /* DWORD* ptr = (DWORD*)bm.bits; DWORD* end = ptr + bm.h*bm.wBytes/4; @@ -167,8 +167,8 @@ STDMETHODIMP CDX9SubPic::ClearDirtyRect(DWORD color) // HRESULT hr = pD3DDev->ColorFill(m_pSurface, m_rcDirty, color); - m_rcDirty.SetRectEmpty(); - + m_rcDirty.SetRectEmpty(); + return S_OK; } @@ -176,15 +176,15 @@ STDMETHODIMP CDX9SubPic::Lock(SubPicDesc& spd) { D3DSURFACE_DESC d3dsd; ZeroMemory(&d3dsd, sizeof(d3dsd)); - if(FAILED(m_pSurface->GetDesc(&d3dsd))) { + if(FAILED(m_pSurface->GetDesc(&d3dsd))) { return E_FAIL; - } + } D3DLOCKED_RECT LockedRect; ZeroMemory(&LockedRect, sizeof(LockedRect)); - if(FAILED(m_pSurface->LockRect(&LockedRect, NULL, D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK))) { + if(FAILED(m_pSurface->LockRect(&LockedRect, NULL, D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK))) { return E_FAIL; - } + } spd.type = 0; spd.w = m_size.cx; @@ -201,10 +201,10 @@ STDMETHODIMP CDX9SubPic::Lock(SubPicDesc& spd) STDMETHODIMP CDX9SubPic::Unlock(RECT* pDirtyRect) { - HRESULT hr = m_pSurface->UnlockRect(); - - if(pDirtyRect) { - m_rcDirty = *pDirtyRect; + HRESULT hr = m_pSurface->UnlockRect(); + + if(pDirtyRect) { + m_rcDirty = *pDirtyRect; if (!((CRect*)pDirtyRect)->IsRectEmpty()) { m_rcDirty.InflateRect(1, 1); m_rcDirty.left &= ~127; @@ -213,14 +213,14 @@ STDMETHODIMP CDX9SubPic::Unlock(RECT* pDirtyRect) m_rcDirty.bottom = (m_rcDirty.bottom + 63) & ~63; m_rcDirty &= CRect(CPoint(0, 0), m_size); } - } else { - m_rcDirty = CRect(CPoint(0, 0), m_size); - } - - CComPtr pTexture = (IDirect3DTexture9*)GetObject(); - if (pTexture && !((CRect*)pDirtyRect)->IsRectEmpty()) { - hr = pTexture->AddDirtyRect(&m_rcDirty); - } + } else { + m_rcDirty = CRect(CPoint(0, 0), m_size); + } + + CComPtr pTexture = (IDirect3DTexture9*)GetObject(); + if (pTexture && !((CRect*)pDirtyRect)->IsRectEmpty()) { + hr = pTexture->AddDirtyRect(&m_rcDirty); + } return S_OK; } @@ -228,57 +228,57 @@ STDMETHODIMP CDX9SubPic::AlphaBlt(const RECT* pSrc, const RECT* pDst, SubPicDesc { ASSERT(pTarget == NULL); - if(!pSrc || !pDst) { + if(!pSrc || !pDst) { return E_POINTER; - } + } CRect src(*pSrc), dst(*pDst); CComPtr pD3DDev; CComPtr pTexture = (IDirect3DTexture9*)GetObject(); - if(!pTexture || FAILED(pTexture->GetDevice(&pD3DDev)) || !pD3DDev) { + if(!pTexture || FAILED(pTexture->GetDevice(&pD3DDev)) || !pD3DDev) { return E_NOINTERFACE; - } + } HRESULT hr; - do { + do { D3DSURFACE_DESC d3dsd; ZeroMemory(&d3dsd, sizeof(d3dsd)); - if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/) { + if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/) { break; - } + } float w = (float)d3dsd.Width; float h = (float)d3dsd.Height; - struct { + struct { float x, y, z, rhw; float tu, tv; } - pVertices[] = { + pVertices[] = { {(float)dst.left, (float)dst.top, 0.5f, 2.0f, (float)src.left / w, (float)src.top / h}, {(float)dst.right, (float)dst.top, 0.5f, 2.0f, (float)src.right / w, (float)src.top / h}, {(float)dst.left, (float)dst.bottom, 0.5f, 2.0f, (float)src.left / w, (float)src.bottom / h}, {(float)dst.right, (float)dst.bottom, 0.5f, 2.0f, (float)src.right / w, (float)src.bottom / h}, }; - - for(ptrdiff_t i = 0; i < countof(pVertices); i++) { + + for(ptrdiff_t i = 0; i < countof(pVertices); i++) { pVertices[i].x -= 0.5; pVertices[i].y -= 0.5; } hr = pD3DDev->SetTexture(0, pTexture); - // GetRenderState fails for devices created with D3DCREATE_PUREDEVICE - // so we need to provide default values in case GetRenderState fails + // GetRenderState fails for devices created with D3DCREATE_PUREDEVICE + // so we need to provide default values in case GetRenderState fails DWORD abe, sb, db; - if (FAILED(pD3DDev->GetRenderState(D3DRS_ALPHABLENDENABLE, &abe))) - abe = FALSE; - if (FAILED(pD3DDev->GetRenderState(D3DRS_SRCBLEND, &sb))) - sb = D3DBLEND_ONE; - if (FAILED(pD3DDev->GetRenderState(D3DRS_DESTBLEND, &db))) - db = D3DBLEND_ZERO; + if (FAILED(pD3DDev->GetRenderState(D3DRS_ALPHABLENDENABLE, &abe))) + abe = FALSE; + if (FAILED(pD3DDev->GetRenderState(D3DRS_SRCBLEND, &sb))) + sb = D3DBLEND_ONE; + if (FAILED(pD3DDev->GetRenderState(D3DRS_DESTBLEND, &db))) + db = D3DBLEND_ZERO; hr = pD3DDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); hr = pD3DDev->SetRenderState(D3DRS_LIGHTING, FALSE); @@ -291,17 +291,17 @@ STDMETHODIMP CDX9SubPic::AlphaBlt(const RECT* pSrc, const RECT* pDst, SubPicDesc hr = pD3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); hr = pD3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - if(pSrc == pDst) { - hr = pD3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - hr = pD3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);} - else { - hr = pD3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - hr = pD3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);} - hr = pD3DDev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); + if(pSrc == pDst) { + hr = pD3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + hr = pD3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);} + else { + hr = pD3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + hr = pD3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);} + hr = pD3DDev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); - hr = pD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - hr = pD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - hr = pD3DDev->SetSamplerState(0, D3DSAMP_BORDERCOLOR, 0xFF000000); + hr = pD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + hr = pD3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + hr = pD3DDev->SetSamplerState(0, D3DSAMP_BORDERCOLOR, 0xFF000000); /*// @@ -318,14 +318,14 @@ STDMETHODIMP CDX9SubPic::AlphaBlt(const RECT* pSrc, const RECT* pDst, SubPicDesc hr = pD3DDev->SetPixelShader(NULL); - if((m_bExternalRenderer) && (FAILED(hr = pD3DDev->BeginScene()))) + if((m_bExternalRenderer) && (FAILED(hr = pD3DDev->BeginScene()))) break; hr = pD3DDev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); hr = pD3DDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, pVertices, sizeof(pVertices[0])); - if(m_bExternalRenderer) - hr = pD3DDev->EndScene(); + if(m_bExternalRenderer) + hr = pD3DDev->EndScene(); // @@ -336,60 +336,60 @@ STDMETHODIMP CDX9SubPic::AlphaBlt(const RECT* pSrc, const RECT* pDst, SubPicDesc pD3DDev->SetRenderState(D3DRS_DESTBLEND, db); return S_OK; - } while(0); + } while(0); return E_FAIL; } - + // // CDX9SubPicAllocator // -CDX9SubPicAllocator::CDX9SubPicAllocator(IDirect3DDevice9* pD3DDev, SIZE maxsize, bool fPow2Textures, bool bExternalRenderer) - : CSubPicAllocatorImpl(maxsize, true, fPow2Textures) +CDX9SubPicAllocator::CDX9SubPicAllocator(IDirect3DDevice9* pD3DDev, SIZE maxsize, bool fPow2Textures, bool bExternalRenderer) + : CSubPicAllocatorImpl(maxsize, true, fPow2Textures) , m_pD3DDev(pD3DDev) , m_maxsize(maxsize) - , m_bExternalRenderer(bExternalRenderer) + , m_bExternalRenderer(bExternalRenderer) { -} - -CCritSec CDX9SubPicAllocator::ms_SurfaceQueueLock; - -CDX9SubPicAllocator::~CDX9SubPicAllocator() -{ - ClearCache(); -} - -void CDX9SubPicAllocator::GetStats(int &_nFree, int &_nAlloc) -{ - CAutoLock Lock(&ms_SurfaceQueueLock); - _nFree = m_FreeSurfaces.GetCount(); - _nAlloc = m_AllocatedSurfaces.GetCount(); -} - -void CDX9SubPicAllocator::ClearCache() -{ - { - // Clear the allocator of any remaining subpics - CAutoLock Lock(&ms_SurfaceQueueLock); - for (POSITION pos = m_AllocatedSurfaces.GetHeadPosition(); pos; ) { - CDX9SubPic *pSubPic = m_AllocatedSurfaces.GetNext(pos); - pSubPic->m_pAllocator = NULL; - } - m_AllocatedSurfaces.RemoveAll(); - m_FreeSurfaces.RemoveAll(); - } +} + +CCritSec CDX9SubPicAllocator::ms_SurfaceQueueLock; + +CDX9SubPicAllocator::~CDX9SubPicAllocator() +{ + ClearCache(); +} + +void CDX9SubPicAllocator::GetStats(int &_nFree, int &_nAlloc) +{ + CAutoLock Lock(&ms_SurfaceQueueLock); + _nFree = m_FreeSurfaces.GetCount(); + _nAlloc = m_AllocatedSurfaces.GetCount(); +} + +void CDX9SubPicAllocator::ClearCache() +{ + { + // Clear the allocator of any remaining subpics + CAutoLock Lock(&ms_SurfaceQueueLock); + for (POSITION pos = m_AllocatedSurfaces.GetHeadPosition(); pos; ) { + CDX9SubPic *pSubPic = m_AllocatedSurfaces.GetNext(pos); + pSubPic->m_pAllocator = NULL; + } + m_AllocatedSurfaces.RemoveAll(); + m_FreeSurfaces.RemoveAll(); + } } // ISubPicAllocator STDMETHODIMP CDX9SubPicAllocator::ChangeDevice(IUnknown* pDev) { - ClearCache(); + ClearCache(); CComQIPtr pD3DDev = pDev; - if(!pD3DDev) { - return E_NOINTERFACE; - } + if(!pD3DDev) { + return E_NOINTERFACE; + } CAutoLock cAutoLock(this); m_pD3DDev = pD3DDev; @@ -397,21 +397,21 @@ STDMETHODIMP CDX9SubPicAllocator::ChangeDevice(IUnknown* pDev) return __super::ChangeDevice(pDev); } -STDMETHODIMP CDX9SubPicAllocator::SetMaxTextureSize(SIZE MaxTextureSize) -{ - ClearCache(); - m_maxsize = MaxTextureSize; - SetCurSize(MaxTextureSize); - return S_OK; -} - +STDMETHODIMP CDX9SubPicAllocator::SetMaxTextureSize(SIZE MaxTextureSize) +{ + ClearCache(); + m_maxsize = MaxTextureSize; + SetCurSize(MaxTextureSize); + return S_OK; +} + // ISubPicAllocatorImpl bool CDX9SubPicAllocator::Alloc(bool fStatic, ISubPic** ppSubPic) { - if(!ppSubPic) { - return false; - } + if(!ppSubPic) { + return false; + } CAutoLock cAutoLock(this); @@ -422,46 +422,46 @@ bool CDX9SubPicAllocator::Alloc(bool fStatic, ISubPic** ppSubPic) int Width = m_maxsize.cx; int Height = m_maxsize.cy; - if(m_fPow2Textures) { + if(m_fPow2Textures) { Width = Height = 1; - while(Width < m_maxsize.cx) { - Width <<= 1; - } - while(Height < m_maxsize.cy) { - Height <<= 1; - } - } - if (!fStatic) { - CAutoLock cAutoLock(&ms_SurfaceQueueLock); - POSITION FreeSurf = m_FreeSurfaces.GetHeadPosition(); - if (FreeSurf) { - pSurface = m_FreeSurfaces.GetHead(); - m_FreeSurfaces.RemoveHead(); - } + while(Width < m_maxsize.cx) { + Width <<= 1; + } + while(Height < m_maxsize.cy) { + Height <<= 1; + } + } + if (!fStatic) { + CAutoLock cAutoLock(&ms_SurfaceQueueLock); + POSITION FreeSurf = m_FreeSurfaces.GetHeadPosition(); + if (FreeSurf) { + pSurface = m_FreeSurfaces.GetHead(); + m_FreeSurfaces.RemoveHead(); + } } - if (!pSurface) { - CComPtr pTexture; - if(FAILED(m_pD3DDev->CreateTexture(Width, Height, 1, 0, D3DFMT_A8R8G8B8, fStatic?D3DPOOL_SYSTEMMEM:D3DPOOL_DEFAULT, &pTexture, NULL))) { - return false; - } + if (!pSurface) { + CComPtr pTexture; + if(FAILED(m_pD3DDev->CreateTexture(Width, Height, 1, 0, D3DFMT_A8R8G8B8, fStatic?D3DPOOL_SYSTEMMEM:D3DPOOL_DEFAULT, &pTexture, NULL))) { + return false; + } - if(FAILED(pTexture->GetSurfaceLevel(0, &pSurface))) { - return false; - } - } + if(FAILED(pTexture->GetSurfaceLevel(0, &pSurface))) { + return false; + } + } - *ppSubPic = DEBUG_NEW CDX9SubPic(pSurface, fStatic ? 0 : this, m_bExternalRenderer); - if(!(*ppSubPic)) { - return false; - } + *ppSubPic = DEBUG_NEW CDX9SubPic(pSurface, fStatic ? 0 : this, m_bExternalRenderer); + if(!(*ppSubPic)) { + return false; + } (*ppSubPic)->AddRef(); - if (!fStatic) { - CAutoLock cAutoLock(&ms_SurfaceQueueLock); - m_AllocatedSurfaces.AddHead((CDX9SubPic *)*ppSubPic); - } - - return true; + if (!fStatic) { + CAutoLock cAutoLock(&ms_SurfaceQueueLock); + m_AllocatedSurfaces.AddHead((CDX9SubPic *)*ppSubPic); + } + + return true; } diff --git a/src/subpic/DX9SubPic.h b/src/subpic/DX9SubPic.h index ef40d6b16..0a0287453 100644 --- a/src/subpic/DX9SubPic.h +++ b/src/subpic/DX9SubPic.h @@ -21,45 +21,45 @@ #pragma once -#include "SubPicImpl.h" -#include "SubPicAllocatorPresenterImpl.h" -#include +#include "SubPicImpl.h" +#include "SubPicAllocatorPresenterImpl.h" +#include // CDX9SubPic -class CVirtualLock -{ -public: - virtual void Lock() = 0; - virtual void Unlock() = 0; -}; -typedef void (FLock)(void *_pLock); -class CScopeLock -{ - void *m_pLock; - FLock *m_pUnlockFunc; -public: - CScopeLock() {}; // let's make cppcheck happy - template - class TCLocker - { - public: - static void fs_Locker(void *_pLock) { - ((t_Lock *)_pLock)->Unlock(); - } - }; - template - CScopeLock(t_Lock &_Lock) { - _Lock.Lock(); - m_pLock = &_Lock; - m_pUnlockFunc = TCLocker::fs_Locker; - } - ~CScopeLock() { - m_pUnlockFunc(m_pLock); - } -}; -class CDX9SubPicAllocator; -class CDX9SubPic : public CSubPicImpl +class CVirtualLock +{ +public: + virtual void Lock() = 0; + virtual void Unlock() = 0; +}; +typedef void (FLock)(void *_pLock); +class CScopeLock +{ + void *m_pLock; + FLock *m_pUnlockFunc; +public: + CScopeLock() {}; // let's make cppcheck happy + template + class TCLocker + { + public: + static void fs_Locker(void *_pLock) { + ((t_Lock *)_pLock)->Unlock(); + } + }; + template + CScopeLock(t_Lock &_Lock) { + _Lock.Lock(); + m_pLock = &_Lock; + m_pUnlockFunc = TCLocker::fs_Locker; + } + ~CScopeLock() { + m_pUnlockFunc(m_pLock); + } +}; +class CDX9SubPicAllocator; +class CDX9SubPic : public CSubPicImpl { CComPtr m_pSurface; @@ -67,10 +67,10 @@ class CDX9SubPic : public CSubPicImpl STDMETHODIMP_(void*) GetObject() const; // returns IDirect3DTexture9* public: - CDX9SubPicAllocator *m_pAllocator; - bool m_bExternalRenderer; - CDX9SubPic(IDirect3DSurface9* pSurface, CDX9SubPicAllocator *pAllocator, bool bExternalRenderer); - ~CDX9SubPic(); + CDX9SubPicAllocator *m_pAllocator; + bool m_bExternalRenderer; + CDX9SubPic(IDirect3DSurface9* pSurface, CDX9SubPicAllocator *pAllocator, bool bExternalRenderer); + ~CDX9SubPic(); // ISubPic STDMETHODIMP GetDesc(SubPicDesc& spd) const; @@ -83,25 +83,25 @@ class CDX9SubPic : public CSubPicImpl // CDX9SubPicAllocator -class CDX9SubPicAllocator : public CSubPicAllocatorImpl, public CCritSec +class CDX9SubPicAllocator : public CSubPicAllocatorImpl, public CCritSec { CComPtr m_pD3DDev; CSize m_maxsize; - bool m_bExternalRenderer; + bool m_bExternalRenderer; bool Alloc(bool fStatic, ISubPic** ppSubPic); public: - static CCritSec ms_SurfaceQueueLock; - CAtlList > m_FreeSurfaces; - CAtlList m_AllocatedSurfaces; - void GetStats(int &_nFree, int &_nAlloc); - CDX9SubPicAllocator(IDirect3DDevice9* pD3DDev, SIZE maxsize, bool fPow2Textures, bool bExternalRenderer); - ~CDX9SubPicAllocator(); - void ClearCache(); + static CCritSec ms_SurfaceQueueLock; + CAtlList > m_FreeSurfaces; + CAtlList m_AllocatedSurfaces; + void GetStats(int &_nFree, int &_nAlloc); + CDX9SubPicAllocator(IDirect3DDevice9* pD3DDev, SIZE maxsize, bool fPow2Textures, bool bExternalRenderer); + ~CDX9SubPicAllocator(); + void ClearCache(); // ISubPicAllocator STDMETHODIMP ChangeDevice(IUnknown* pDev); - STDMETHODIMP SetMaxTextureSize(SIZE MaxTextureSize); + STDMETHODIMP SetMaxTextureSize(SIZE MaxTextureSize); }; diff --git a/src/subpic/ISimpleSubPic.h b/src/subpic/ISimpleSubPic.h index e30e8a160..304a32407 100644 --- a/src/subpic/ISimpleSubPic.h +++ b/src/subpic/ISimpleSubPic.h @@ -1,16 +1,16 @@ #pragma once #include "ISubPic.h" -#include "XySubRenderIntf.h" +#include "XySubRenderIntf.h" // // ISimpleSubPic // -interface __declspec(uuid("8ca58386-cc13-439b-a226-eaaaffbcedcb")) -ISimpleSubPic : +interface __declspec(uuid("8ca58386-cc13-439b-a226-eaaaffbcedcb")) +ISimpleSubPic : public IUnknown { - STDMETHOD (AlphaBlt) (SubPicDesc* target) PURE; + STDMETHOD (AlphaBlt) (SubPicDesc* target) PURE; }; // @@ -33,7 +33,7 @@ public IUnknown //fix me: & => * STDMETHOD (GetStats) (int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop /*[out]*/) PURE; - STDMETHOD (GetStats) (int nSubPic /*[in]*/, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop /*[out]*/) PURE; + STDMETHOD (GetStats) (int nSubPic /*[in]*/, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop /*[out]*/) PURE; }; interface __declspec(uuid("1f277b1b-c28d-4022-b00e-373d0b1b54cd")) @@ -56,5 +56,5 @@ public IUnknown { REFERENCE_TIME rt, double fps) PURE; STDMETHOD_(bool, IsColorTypeSupported) (int type) PURE; -}; - +}; + diff --git a/src/subpic/ISubPic.h b/src/subpic/ISubPic.h index 31a48ee5f..ad8560589 100644 --- a/src/subpic/ISubPic.h +++ b/src/subpic/ISubPic.h @@ -44,7 +44,7 @@ enum ColorType { }; #pragma pack(push, 1) -struct SubPicDesc { +struct SubPicDesc { int type; int w, h, bpp, pitch, pitchUV; void* bits; @@ -52,12 +52,12 @@ struct SubPicDesc { BYTE* bitsV; RECT vidrect; // video rectangle - struct SubPicDesc() { - type = 0; - w = h = bpp = pitch = pitchUV = 0; - bits = NULL; - bitsU = bitsV = NULL; - } + struct SubPicDesc() { + type = 0; + w = h = bpp = pitch = pitchUV = 0; + bits = NULL; + bitsU = bitsV = NULL; + } }; #pragma pack(pop) @@ -65,9 +65,9 @@ struct SubPicDesc { // ISubPic // -interface __declspec(uuid("449E11F3-52D1-4a27-AA61-E2733AC92CC0")) -ISubPic : -public IUnknown { +interface __declspec(uuid("449E11F3-52D1-4a27-AA61-E2733AC92CC0")) +ISubPic : +public IUnknown { STDMETHOD_(void*, GetObject) () const PURE; STDMETHOD_(REFERENCE_TIME, GetStart) () const PURE; @@ -89,13 +89,13 @@ public IUnknown { STDMETHOD (Unlock) (RECT* pDirtyRect /*[in]*/) PURE; STDMETHOD (AlphaBlt) (const RECT* pSrc, const RECT* pDst, SubPicDesc* pTarget = NULL /*[in]*/) PURE; - STDMETHOD (GetSourceAndDest) (SIZE* pSize /*[in]*/, RECT* pRcSource /*[out]*/, RECT* pRcDest /*[out]*/) PURE; - STDMETHOD (SetVirtualTextureSize) (const SIZE pSize, const POINT pTopLeft) PURE; - - STDMETHOD_(REFERENCE_TIME, GetSegmentStart) () PURE; - STDMETHOD_(REFERENCE_TIME, GetSegmentStop) () PURE; - STDMETHOD_(void, SetSegmentStart) (REFERENCE_TIME rtStart) PURE; - STDMETHOD_(void, SetSegmentStop) (REFERENCE_TIME rtStop) PURE; + STDMETHOD (GetSourceAndDest) (SIZE* pSize /*[in]*/, RECT* pRcSource /*[out]*/, RECT* pRcDest /*[out]*/) PURE; + STDMETHOD (SetVirtualTextureSize) (const SIZE pSize, const POINT pTopLeft) PURE; + + STDMETHOD_(REFERENCE_TIME, GetSegmentStart) () PURE; + STDMETHOD_(REFERENCE_TIME, GetSegmentStop) () PURE; + STDMETHOD_(void, SetSegmentStart) (REFERENCE_TIME rtStart) PURE; + STDMETHOD_(void, SetSegmentStop) (REFERENCE_TIME rtStop) PURE; }; interface __declspec(uuid("728B3CDC-B0B2-4DA8-8426-AEDE9C90674E")) @@ -113,9 +113,9 @@ public ISubPic { // ISubPicAllocator // -interface __declspec(uuid("CF7C3C23-6392-4a42-9E72-0736CFF793CB")) -ISubPicAllocator : -public IUnknown { +interface __declspec(uuid("CF7C3C23-6392-4a42-9E72-0736CFF793CB")) +ISubPicAllocator : +public IUnknown { STDMETHOD (SetCurSize) (SIZE size /*[in]*/) PURE; STDMETHOD (SetCurVidRect) (RECT curvidrect) PURE; @@ -125,26 +125,26 @@ public IUnknown { STDMETHOD_(bool, IsDynamicWriteOnly) () PURE; STDMETHOD (ChangeDevice) (IUnknown* pDev) PURE; - STDMETHOD (SetMaxTextureSize) (SIZE MaxTextureSize) PURE; + STDMETHOD (SetMaxTextureSize) (SIZE MaxTextureSize) PURE; }; -interface __declspec(uuid("379DD04B-F132-475E-9901-AB02FF4351A7")) -ISubPicExAllocator : -public ISubPicAllocator { - STDMETHOD_(bool, IsSpdColorTypeSupported) (int type) PURE; - STDMETHOD_(int, SetSpdColorType) (int color_type) PURE; - +interface __declspec(uuid("379DD04B-F132-475E-9901-AB02FF4351A7")) +ISubPicExAllocator : +public ISubPicAllocator { + STDMETHOD_(bool, IsSpdColorTypeSupported) (int type) PURE; + STDMETHOD_(int, SetSpdColorType) (int color_type) PURE; + STDMETHOD (GetStaticEx) (ISubPicEx** ppSubPic /*[out]*/) PURE; - STDMETHOD (AllocDynamicEx) (ISubPicEx** ppSubPic /*[out]*/) PURE; + STDMETHOD (AllocDynamicEx) (ISubPicEx** ppSubPic /*[out]*/) PURE; }; // // ISubPicProvider // -interface __declspec(uuid("D62B9A1A-879A-42db-AB04-88AA8F243CFD")) -ISubPicProvider : -public IUnknown { +interface __declspec(uuid("D62B9A1A-879A-42db-AB04-88AA8F243CFD")) +ISubPicProvider : +public IUnknown { STDMETHOD (Lock) () PURE; STDMETHOD (Unlock) () PURE; @@ -157,7 +157,7 @@ public IUnknown { STDMETHOD_(bool, IsAnimated) (POSITION pos) PURE; STDMETHOD (Render) (SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox) PURE; - STDMETHOD (GetTextureSize) (POSITION pos, SIZE& MaxTextureSize, SIZE& VirtualSize, POINT& VirtualTopLeft) PURE; + STDMETHOD (GetTextureSize) (POSITION pos, SIZE& MaxTextureSize, SIZE& VirtualSize, POINT& VirtualTopLeft) PURE; }; interface __declspec(uuid("F8B6C39E-4188-41E0-9CCF-79579C376A40")) @@ -173,9 +173,9 @@ public ISubPicProvider { // ISubPicQueue // -interface __declspec(uuid("C8334466-CD1E-4ad1-9D2D-8EE8519BD180")) -ISubPicQueue : -public IUnknown { +interface __declspec(uuid("C8334466-CD1E-4ad1-9D2D-8EE8519BD180")) +ISubPicQueue : +public IUnknown { STDMETHOD (SetSubPicProvider) (ISubPicProvider* pSubPicProvider /*[in]*/) PURE; STDMETHOD (GetSubPicProvider) (ISubPicProvider** pSubPicProvider /*[out]*/) PURE; @@ -193,9 +193,9 @@ public IUnknown { // ISubPicAllocatorPresenter // -interface __declspec(uuid("CF75B1F0-535C-4074-8869-B15F177F944E")) -ISubPicAllocatorPresenter : -public IUnknown { +interface __declspec(uuid("CF75B1F0-535C-4074-8869-B15F177F944E")) +ISubPicAllocatorPresenter : +public IUnknown { STDMETHOD (CreateRenderer) (IUnknown** ppRenderer) PURE; STDMETHOD_(SIZE, GetVideoSize) (bool fCorrectAR = true) PURE; @@ -214,27 +214,27 @@ public IUnknown { STDMETHOD (SetVideoAngle) (Vector v, bool fRepaint = true) PURE; STDMETHOD (SetPixelShader) (LPCSTR pSrcData, LPCSTR pTarget) PURE; - - STDMETHOD_(bool, ResetDevice) () PURE; - - STDMETHOD_(bool, DisplayChange) () PURE; + + STDMETHOD_(bool, ResetDevice) () PURE; + + STDMETHOD_(bool, DisplayChange) () PURE; }; -interface __declspec(uuid("767AEBA8-A084-488a-89C8-F6B74E53A90F")) -ISubPicAllocatorPresenter2 : -public ISubPicAllocatorPresenter { - STDMETHOD (SetPixelShader2) (LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace) PURE; - STDMETHOD_(SIZE, GetVisibleVideoSize) () PURE; -}; - - +interface __declspec(uuid("767AEBA8-A084-488a-89C8-F6B74E53A90F")) +ISubPicAllocatorPresenter2 : +public ISubPicAllocatorPresenter { + STDMETHOD (SetPixelShader2) (LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace) PURE; + STDMETHOD_(SIZE, GetVisibleVideoSize) () PURE; +}; + + // // ISubStream // -interface __declspec(uuid("DE11E2FB-02D3-45e4-A174-6B7CE2783BDB")) -ISubStream : -public IPersist { +interface __declspec(uuid("DE11E2FB-02D3-45e4-A174-6B7CE2783BDB")) +ISubStream : +public IPersist { STDMETHOD_(int, GetStreamCount) () PURE; STDMETHOD (GetStreamInfo) (int i, WCHAR** ppName, LCID* pLCID) PURE; STDMETHOD_(int, GetStream) () PURE; diff --git a/src/subpic/MemSubPic.cpp b/src/subpic/MemSubPic.cpp index 8635aaed1..5084cdd70 100644 --- a/src/subpic/MemSubPic.cpp +++ b/src/subpic/MemSubPic.cpp @@ -232,14 +232,14 @@ STDMETHODIMP CMemSubPic::GetDesc(SubPicDesc& spd) const STDMETHODIMP CMemSubPic::CopyTo(ISubPicEx* pSubPic) { HRESULT hr; - if(FAILED(hr = __super::CopyTo(pSubPic))) { + if(FAILED(hr = __super::CopyTo(pSubPic))) { return hr; - } - - SubPicDesc src, dst; - if(FAILED(GetDesc(src)) || FAILED(pSubPic->GetDesc(dst))) { + } + + SubPicDesc src, dst; + if(FAILED(GetDesc(src)) || FAILED(pSubPic->GetDesc(dst))) { return E_FAIL; - } + } while(!m_rectListDirty.IsEmpty()) { CRect& cRect = m_rectListDirty.GetHead(); @@ -254,9 +254,9 @@ STDMETHODIMP CMemSubPic::CopyTo(ISubPicEx* pSubPic) STDMETHODIMP CMemSubPic::ClearDirtyRect(DWORD color) { - if(m_rectListDirty.IsEmpty()) { + if(m_rectListDirty.IsEmpty()) { return S_OK; - } + } while(!m_rectListDirty.IsEmpty()) { //pDirtyRect = m_rectListDirty.RemoveHead(); @@ -267,9 +267,9 @@ STDMETHODIMP CMemSubPic::ClearDirtyRect(DWORD color) { for(int j = 0, h = dirtyRect.Height(); j < h; j++, p += m_spd.pitch) { -#ifdef _WIN64 - memsetd(p, color, w*4); // nya -#else +#ifdef _WIN64 + memsetd(p, color, w*4); // nya +#else __asm { mov eax, color @@ -278,8 +278,8 @@ STDMETHODIMP CMemSubPic::ClearDirtyRect(DWORD color) cld rep stosd } - -#endif + +#endif } } else @@ -298,7 +298,7 @@ STDMETHODIMP CMemSubPic::ClearDirtyRect(DWORD color) } } } - m_rectListDirty.RemoveAll(); + m_rectListDirty.RemoveAll(); return S_OK; } @@ -308,37 +308,37 @@ STDMETHODIMP CMemSubPic::Lock(SubPicDesc& spd) } STDMETHODIMP CMemSubPic::Unlock( CAtlList* dirtyRectList ) -{ - int src_type = m_spd.type; - int dst_type = m_alpha_blt_dst_type; - if( (src_type==MSP_RGBA && (dst_type == MSP_RGB32 || - dst_type == MSP_RGB24 || - dst_type == MSP_RGB16 || - dst_type == MSP_RGB15)) - || - (src_type==MSP_XY_AUYV && dst_type == MSP_YUY2)//ToDo: fix me MSP_AYUV - || - (src_type==MSP_AYUV && dst_type == MSP_AYUV) - || - (src_type==MSP_AYUV_PLANAR && (dst_type == MSP_IYUV || - dst_type == MSP_YV12 || - dst_type == MSP_P010 || - dst_type == MSP_P016 || - dst_type == MSP_NV12 || - dst_type == MSP_NV21))) - { - return UnlockOther(dirtyRectList); - } - else if(src_type==MSP_RGBA && (dst_type == MSP_YUY2 || - dst_type == MSP_AYUV || //ToDo: fix me MSP_AYUV - dst_type == MSP_IYUV || - dst_type == MSP_YV12 || - dst_type == MSP_NV12 || - dst_type == MSP_NV21 || - dst_type == MSP_P010 || - dst_type == MSP_P016)) - { - return UnlockRGBA_YUV(dirtyRectList); +{ + int src_type = m_spd.type; + int dst_type = m_alpha_blt_dst_type; + if( (src_type==MSP_RGBA && (dst_type == MSP_RGB32 || + dst_type == MSP_RGB24 || + dst_type == MSP_RGB16 || + dst_type == MSP_RGB15)) + || + (src_type==MSP_XY_AUYV && dst_type == MSP_YUY2)//ToDo: fix me MSP_AYUV + || + (src_type==MSP_AYUV && dst_type == MSP_AYUV) + || + (src_type==MSP_AYUV_PLANAR && (dst_type == MSP_IYUV || + dst_type == MSP_YV12 || + dst_type == MSP_P010 || + dst_type == MSP_P016 || + dst_type == MSP_NV12 || + dst_type == MSP_NV21))) + { + return UnlockOther(dirtyRectList); + } + else if(src_type==MSP_RGBA && (dst_type == MSP_YUY2 || + dst_type == MSP_AYUV || //ToDo: fix me MSP_AYUV + dst_type == MSP_IYUV || + dst_type == MSP_YV12 || + dst_type == MSP_NV12 || + dst_type == MSP_NV21 || + dst_type == MSP_P010 || + dst_type == MSP_P016)) + { + return UnlockRGBA_YUV(dirtyRectList); } return E_NOTIMPL; } @@ -346,9 +346,9 @@ STDMETHODIMP CMemSubPic::Unlock( CAtlList* dirtyRectList ) HRESULT CMemSubPic::UnlockOther(CAtlList* dirtyRectList) { SetDirtyRectEx(dirtyRectList); - if(m_rectListDirty.IsEmpty()) { + if(m_rectListDirty.IsEmpty()) { return S_OK; - } + } POSITION pos = m_rectListDirty.GetHeadPosition(); while(pos!=NULL) @@ -437,7 +437,7 @@ HRESULT CMemSubPic::UnlockRGBA_YUV(CAtlList* dirtyRectList) SetDirtyRectEx(dirtyRectList); ONCER( SaveRect2File(dirtyRectList->GetHead(), "F:/mplayer_MinGW_full/MinGW/home/Administrator/xy_vsfilter/debug.rect2") ); - if(m_rectListDirty.IsEmpty()) { + if(m_rectListDirty.IsEmpty()) { return S_OK; } @@ -535,51 +535,51 @@ void CMemSubPic::SubsampleAndInterlace( const CRect& cRect, bool u_first ) STDMETHODIMP CMemSubPic::AlphaBlt( const RECT* pSrc, const RECT* pDst, SubPicDesc* pTarget ) { - if(!pSrc || !pDst || !pTarget) { + if(!pSrc || !pDst || !pTarget) { return E_POINTER; } int src_type = m_spd.type; int dst_type = pTarget->type; - - if( (src_type==MSP_RGBA && (dst_type == MSP_RGB32 || - dst_type == MSP_RGB24 || - dst_type == MSP_RGB16 || - dst_type == MSP_RGB15 || - dst_type == MSP_RGBA || - dst_type == MSP_YUY2 ||//ToDo: fix me MSP_RGBA changed into AxYU AxYV after unlock, may be confusing - dst_type == MSP_AYUV )) - || - (src_type==MSP_XY_AUYV && dst_type == MSP_YUY2)//ToDo: fix me MSP_AYUV - || - (src_type==MSP_AYUV && dst_type == MSP_AYUV) - || - (src_type==MSP_AYUV_PLANAR && (dst_type == MSP_IYUV || - dst_type == MSP_YV12)) ) - { - return AlphaBltOther(pSrc, pDst, pTarget); - } - else if ( src_type==MSP_AYUV_PLANAR && (dst_type == MSP_NV12 || + + if( (src_type==MSP_RGBA && (dst_type == MSP_RGB32 || + dst_type == MSP_RGB24 || + dst_type == MSP_RGB16 || + dst_type == MSP_RGB15 || + dst_type == MSP_RGBA || + dst_type == MSP_YUY2 ||//ToDo: fix me MSP_RGBA changed into AxYU AxYV after unlock, may be confusing + dst_type == MSP_AYUV )) + || + (src_type==MSP_XY_AUYV && dst_type == MSP_YUY2)//ToDo: fix me MSP_AYUV + || + (src_type==MSP_AYUV && dst_type == MSP_AYUV) + || + (src_type==MSP_AYUV_PLANAR && (dst_type == MSP_IYUV || + dst_type == MSP_YV12)) ) + { + return AlphaBltOther(pSrc, pDst, pTarget); + } + else if ( src_type==MSP_AYUV_PLANAR && (dst_type == MSP_NV12 || dst_type == MSP_NV21 ) ) { return AlphaBltAnv12_Nv12(pSrc, pDst, pTarget); } - - else if( src_type==MSP_AYUV_PLANAR && (dst_type == MSP_P010 || - dst_type == MSP_P016 ) ) - { - return AlphaBltAnv12_P010(pSrc, pDst, pTarget); - } - else if( src_type==MSP_RGBA && (dst_type == MSP_IYUV || - dst_type == MSP_YV12)) - { - return AlphaBltAxyuAxyv_Yv12(pSrc, pDst, pTarget); - } - else if( src_type==MSP_RGBA && (dst_type == MSP_NV12|| - dst_type == MSP_NV21)) - { - return AlphaBltAxyuAxyv_Nv12(pSrc, pDst, pTarget); - } - else if( src_type==MSP_RGBA && (dst_type == MSP_P010 || + + else if( src_type==MSP_AYUV_PLANAR && (dst_type == MSP_P010 || + dst_type == MSP_P016 ) ) + { + return AlphaBltAnv12_P010(pSrc, pDst, pTarget); + } + else if( src_type==MSP_RGBA && (dst_type == MSP_IYUV || + dst_type == MSP_YV12)) + { + return AlphaBltAxyuAxyv_Yv12(pSrc, pDst, pTarget); + } + else if( src_type==MSP_RGBA && (dst_type == MSP_NV12|| + dst_type == MSP_NV21)) + { + return AlphaBltAxyuAxyv_Nv12(pSrc, pDst, pTarget); + } + else if( src_type==MSP_RGBA && (dst_type == MSP_P010 || dst_type == MSP_P016)) { return AlphaBltAxyuAxyv_P010(pSrc, pDst, pTarget); @@ -588,10 +588,10 @@ STDMETHODIMP CMemSubPic::AlphaBlt( const RECT* pSrc, const RECT* pDst, SubPicDes } HRESULT CMemSubPic::AlphaBltOther(const RECT* pSrc, const RECT* pDst, SubPicDesc* pTarget) -{ +{ const SubPicDesc& src = m_spd; - SubPicDesc dst = *pTarget; // copy, because we might modify it - + SubPicDesc dst = *pTarget; // copy, because we might modify it + CRect rs(*pSrc), rd(*pDst); if(dst.h < 0) { @@ -599,9 +599,9 @@ HRESULT CMemSubPic::AlphaBltOther(const RECT* pSrc, const RECT* pDst, SubPicDesc rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; } - if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { + if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { return E_INVALIDARG; - } + } int w = rs.Width(), h = rs.Height(); BYTE* s = (BYTE*)src.bits + src.pitch*rs.top + ((rs.left*src.bpp)>>3);//rs.left*4 BYTE* d = (BYTE*)dst.bits + dst.pitch*rd.top + ((rd.left*dst.bpp)>>3); @@ -653,12 +653,12 @@ HRESULT CMemSubPic::AlphaBltOther(const RECT* pSrc, const RECT* pDst, SubPicDesc BYTE* s2end = s2 + w*4; DWORD* d2 = (DWORD*)d; for(; s2 < s2end; s2 += 4, d2++) - { + { if(s2[3] < 0xff) { *d2 = (((((*d2&0x00ff00ff)*s2[3])>>8) + (*((DWORD*)s2)&0x00ff00ff))&0x00ff00ff) | (((((*d2&0x0000ff00)*s2[3])>>8) + (*((DWORD*)s2)&0x0000ff00))&0x0000ff00); - } + } } } break; @@ -669,13 +669,13 @@ HRESULT CMemSubPic::AlphaBltOther(const RECT* pSrc, const RECT* pDst, SubPicDesc BYTE* s2end = s2 + w*4; DWORD* d2 = (DWORD*)d; for(; s2 < s2end; s2 += 4, d2++) - { + { if(s2[3] < 0xff) { *d2 = (((((*d2&0x00ff00ff)*s2[3])>>8) + (*((DWORD*)s2)&0x00ff00ff))&0x00ff00ff) | (((((*d2&0x0000ff00)*s2[3])>>8) + (*((DWORD*)s2)&0x0000ff00))&0x0000ff00) | (*d2&0xff000000); - } + } } } break; @@ -1078,8 +1078,8 @@ HRESULT CMemSubPic::AlphaBltAnv12_P010( const RECT* pSrc, const RECT* pDst, SubP { //fix me: check colorspace and log error const SubPicDesc& src = m_spd; - SubPicDesc dst = *pTarget; // copy, because we might modify it - + SubPicDesc dst = *pTarget; // copy, because we might modify it + CRect rs(*pSrc), rd(*pDst); if(dst.h < 0) { @@ -1087,9 +1087,9 @@ HRESULT CMemSubPic::AlphaBltAnv12_P010( const RECT* pSrc, const RECT* pDst, SubP rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; } - if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { + if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { return E_INVALIDARG; - } + } int w = rs.Width(), h = rs.Height(); bool bottom_down = rd.top > rd.bottom; @@ -1118,8 +1118,8 @@ HRESULT CMemSubPic::AlphaBltAnv12_Nv12( const RECT* pSrc, const RECT* pDst, SubP { //fix me: check colorspace and log error const SubPicDesc& src = m_spd; - SubPicDesc dst = *pTarget; // copy, because we might modify it - + SubPicDesc dst = *pTarget; // copy, because we might modify it + CRect rs(*pSrc), rd(*pDst); if(dst.h < 0) { @@ -1127,9 +1127,9 @@ HRESULT CMemSubPic::AlphaBltAnv12_Nv12( const RECT* pSrc, const RECT* pDst, SubP rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; } - if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { + if(rs.Width() != rd.Width() || rs.Height() != abs(rd.Height())) { return E_INVALIDARG; - } + } int w = rs.Width(), h = rs.Height(); bool bottom_down = rd.top > rd.bottom; @@ -1608,23 +1608,23 @@ CMemSubPicAllocator::CMemSubPicAllocator(int alpha_blt_dst_type, SIZE maxsize, i bool CMemSubPicAllocator::AllocEx(bool fStatic, ISubPicEx** ppSubPic) { - if(!ppSubPic) { - return false; - } + if(!ppSubPic) { + return false; + } SubPicDesc spd; spd.w = m_maxsize.cx; spd.h = m_maxsize.cy; spd.bpp = 32; spd.pitch = (spd.w*spd.bpp)>>3; spd.type = m_type; - spd.bits = DEBUG_NEW BYTE[spd.pitch*spd.h]; - if(!spd.bits) { - return false; - } - *ppSubPic = DEBUG_NEW CMemSubPic(spd, m_alpha_blt_dst_type); - if(!(*ppSubPic)) { - return false; - } + spd.bits = DEBUG_NEW BYTE[spd.pitch*spd.h]; + if(!spd.bits) { + return false; + } + *ppSubPic = DEBUG_NEW CMemSubPic(spd, m_alpha_blt_dst_type); + if(!(*ppSubPic)) { + return false; + } (*ppSubPic)->AddRef(); - return true; + return true; } diff --git a/src/subpic/MemSubPic.h b/src/subpic/MemSubPic.h index 4c72fc5bb..f404a46c2 100644 --- a/src/subpic/MemSubPic.h +++ b/src/subpic/MemSubPic.h @@ -21,13 +21,13 @@ #pragma once -#include "SubPicImpl.h" +#include "SubPicImpl.h" // CMemSubPic typedef const UINT8 CUINT8, *PCUINT8; -class CMemSubPic : public CSubPicExImpl +class CMemSubPic : public CSubPicExImpl { public: static void AlphaBltYv12Luma(byte* dst, int dst_pitch, int w, int h, const byte* sub, const byte* alpha, int sub_pitch); @@ -95,7 +95,7 @@ class CMemSubPic : public CSubPicExImpl // CMemSubPicAllocator -class CMemSubPicAllocator : public CSubPicExAllocatorImpl +class CMemSubPicAllocator : public CSubPicExAllocatorImpl { int m_type; int m_alpha_blt_dst_type; diff --git a/src/subpic/PooledSubPic.cpp b/src/subpic/PooledSubPic.cpp index 98988ccbf..e464d69d0 100644 --- a/src/subpic/PooledSubPic.cpp +++ b/src/subpic/PooledSubPic.cpp @@ -175,21 +175,21 @@ STDMETHODIMP_(int) CPooledSubPicAllocator::SetSpdColorType( int color_type ) } STDMETHODIMP_(bool) CPooledSubPicAllocator::IsSpdColorTypeSupported( int type ) -{ - if( (type==MSP_RGBA) - || - (type==MSP_XY_AUYV && _alpha_blt_dst_type == MSP_YUY2) - || - (type==MSP_AYUV && _alpha_blt_dst_type == MSP_AYUV) - || - (type==MSP_AYUV_PLANAR && (_alpha_blt_dst_type == MSP_IYUV || - _alpha_blt_dst_type == MSP_YV12 || - _alpha_blt_dst_type == MSP_P010 || - _alpha_blt_dst_type == MSP_P016 || - _alpha_blt_dst_type == MSP_NV12 || - _alpha_blt_dst_type == MSP_NV21)) ) - { - return true; +{ + if( (type==MSP_RGBA) + || + (type==MSP_XY_AUYV && _alpha_blt_dst_type == MSP_YUY2) + || + (type==MSP_AYUV && _alpha_blt_dst_type == MSP_AYUV) + || + (type==MSP_AYUV_PLANAR && (_alpha_blt_dst_type == MSP_IYUV || + _alpha_blt_dst_type == MSP_YV12 || + _alpha_blt_dst_type == MSP_P010 || + _alpha_blt_dst_type == MSP_P016 || + _alpha_blt_dst_type == MSP_NV12 || + _alpha_blt_dst_type == MSP_NV21)) ) + { + return true; } return false; } diff --git a/src/subpic/PooledSubPic.h b/src/subpic/PooledSubPic.h index 77ab6de2f..0fd7e44b0 100644 --- a/src/subpic/PooledSubPic.h +++ b/src/subpic/PooledSubPic.h @@ -13,7 +13,7 @@ interface IPooledAllocator STDMETHOD_(void, OnItemDestruct)(void* Item) PURE; }; -class CPooledSubPicAllocator : public CSubPicExAllocatorImpl//, public IPooledAllocator +class CPooledSubPicAllocator : public CSubPicExAllocatorImpl//, public IPooledAllocator { public: STDMETHODIMP_(void) ReleaseItem(void* Item); diff --git a/src/subpic/SimpleSubPicProviderImpl.cpp b/src/subpic/SimpleSubPicProviderImpl.cpp index 230d63033..34d2c45c6 100644 --- a/src/subpic/SimpleSubPicProviderImpl.cpp +++ b/src/subpic/SimpleSubPicProviderImpl.cpp @@ -14,21 +14,21 @@ SimpleSubPicProvider::SimpleSubPicProvider( int alpha_blt_dst_type, SIZE spd_size, RECT video_rect, IDirectVobSubXy *consumer , HRESULT* phr/*=NULL*/ ) - : CUnknown(NAME("CSubPicQueueImpl"), NULL) - , m_alpha_blt_dst_type(alpha_blt_dst_type) - , m_spd_size(spd_size) - , m_video_rect(video_rect) - , m_rtNow(0) + : CUnknown(NAME("CSubPicQueueImpl"), NULL) + , m_alpha_blt_dst_type(alpha_blt_dst_type) + , m_spd_size(spd_size) + , m_video_rect(video_rect) + , m_rtNow(0) , m_fps(25.0) , m_consumer(consumer) { - if(phr) { - *phr = consumer ? S_OK : E_INVALIDARG; - } - - m_prefered_colortype.AddTail(MSP_AYUV_PLANAR); - m_prefered_colortype.AddTail(MSP_AYUV); - m_prefered_colortype.AddTail(MSP_XY_AUYV); + if(phr) { + *phr = consumer ? S_OK : E_INVALIDARG; + } + + m_prefered_colortype.AddTail(MSP_AYUV_PLANAR); + m_prefered_colortype.AddTail(MSP_AYUV); + m_prefered_colortype.AddTail(MSP_XY_AUYV); m_prefered_colortype.AddTail(MSP_RGBA); } @@ -39,210 +39,210 @@ SimpleSubPicProvider::~SimpleSubPicProvider() STDMETHODIMP SimpleSubPicProvider::NonDelegatingQueryInterface( REFIID riid, void** ppv ) { - return - QI(ISimpleSubPicProvider) + return + QI(ISimpleSubPicProvider) __super::NonDelegatingQueryInterface(riid, ppv); } STDMETHODIMP SimpleSubPicProvider::SetSubPicProvider( IUnknown* subpic_provider ) -{ +{ if (subpic_provider!=NULL) { - CComQIPtr tmp = subpic_provider; - if (tmp) - { - CAutoLock cAutoLock(&m_csSubPicProvider); - m_pSubPicProviderEx = tmp; - - if(m_pSubPicProviderEx!=NULL) - { - POSITION pos = m_prefered_colortype.GetHeadPosition(); - while(pos!=NULL) - { - int color_type = m_prefered_colortype.GetNext(pos); - if( m_pSubPicProviderEx->IsColorTypeSupported( color_type ) && - IsSpdColorTypeSupported( color_type ) ) - { - m_spd_type = color_type; - break; - } - } - } - Invalidate(); - - return S_OK; + CComQIPtr tmp = subpic_provider; + if (tmp) + { + CAutoLock cAutoLock(&m_csSubPicProvider); + m_pSubPicProviderEx = tmp; + + if(m_pSubPicProviderEx!=NULL) + { + POSITION pos = m_prefered_colortype.GetHeadPosition(); + while(pos!=NULL) + { + int color_type = m_prefered_colortype.GetNext(pos); + if( m_pSubPicProviderEx->IsColorTypeSupported( color_type ) && + IsSpdColorTypeSupported( color_type ) ) + { + m_spd_type = color_type; + break; + } + } + } + Invalidate(); + + return S_OK; } - + return E_NOTIMPL; } - + return S_OK; } STDMETHODIMP SimpleSubPicProvider::GetSubPicProvider( IUnknown** subpic_provider ) { - if(!subpic_provider) { - return E_POINTER; - } - - CAutoLock cAutoLock(&m_csSubPicProvider); - - if(m_pSubPicProviderEx) { - *subpic_provider = m_pSubPicProviderEx; - (*subpic_provider)->AddRef(); - } - + if(!subpic_provider) { + return E_POINTER; + } + + CAutoLock cAutoLock(&m_csSubPicProvider); + + if(m_pSubPicProviderEx) { + *subpic_provider = m_pSubPicProviderEx; + (*subpic_provider)->AddRef(); + } + return !!*subpic_provider ? S_OK : E_FAIL; } STDMETHODIMP SimpleSubPicProvider::SetFPS( double fps ) { - m_fps = fps; - + m_fps = fps; + return S_OK; } STDMETHODIMP SimpleSubPicProvider::SetTime( REFERENCE_TIME rtNow ) { - m_rtNow = rtNow; - + m_rtNow = rtNow; + return S_OK; } STDMETHODIMP SimpleSubPicProvider::Invalidate( REFERENCE_TIME rtInvalidate /*= -1*/ ) { - CAutoLock cQueueLock(&m_csLock); - - if( m_pSubPic && m_subpic_stop >= rtInvalidate) - { - m_pSubPic = NULL; - } + CAutoLock cQueueLock(&m_csLock); + + if( m_pSubPic && m_subpic_stop >= rtInvalidate) + { + m_pSubPic = NULL; + } return S_OK; } - -STDMETHODIMP_(bool) SimpleSubPicProvider::LookupSubPic( REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic /*[out]*/ ) -{ - if(output_subpic!=NULL) - { - *output_subpic = NULL; - CComPtr temp = NULL; - bool result = LookupSubPicEx(now, &temp); + +STDMETHODIMP_(bool) SimpleSubPicProvider::LookupSubPic( REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic /*[out]*/ ) +{ + if(output_subpic!=NULL) + { + *output_subpic = NULL; + CComPtr temp = NULL; + bool result = LookupSubPicEx(now, &temp); if (result && temp) { (*output_subpic = new SimpleSubpic(temp, m_alpha_blt_dst_type))->AddRef(); - } - return result; - } - return false; -} + } + return result; + } + return false; +} STDMETHODIMP SimpleSubPicProvider::GetStats( int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop ) { - CAutoLock cAutoLock(&m_csLock); - - nSubPics = 0; - rtNow = m_rtNow; - rtStart = rtStop = 0; - - if(m_pSubPic) - { - nSubPics = 1; - rtStart = m_subpic_start; - rtStop = m_subpic_stop; - } - + CAutoLock cAutoLock(&m_csLock); + + nSubPics = 0; + rtNow = m_rtNow; + rtStart = rtStop = 0; + + if(m_pSubPic) + { + nSubPics = 1; + rtStart = m_subpic_start; + rtStop = m_subpic_stop; + } + return S_OK; } STDMETHODIMP SimpleSubPicProvider::GetStats( int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop ) { - CAutoLock cAutoLock(&m_csLock); - - if(!m_pSubPic || nSubPic != 0) - return E_INVALIDARG; - - rtStart = m_subpic_start; - rtStop = m_subpic_stop; - + CAutoLock cAutoLock(&m_csLock); + + if(!m_pSubPic || nSubPic != 0) + return E_INVALIDARG; + + rtStart = m_subpic_start; + rtStop = m_subpic_stop; + return S_OK; } - -bool SimpleSubPicProvider::LookupSubPicEx(REFERENCE_TIME rtNow, IXySubRenderFrame** sub_render_frame) -{ - if(!sub_render_frame) - return(false); - - *sub_render_frame = NULL; - - if(m_subpic_start <= rtNow && rtNow < m_subpic_stop && m_pSubPic) - { - (*sub_render_frame = m_pSubPic)->AddRef(); - } - else - { - CComPtr pSubPicProvider; - if(SUCCEEDED(GetSubPicProviderEx(&pSubPicProvider)) && pSubPicProvider - && SUCCEEDED(pSubPicProvider->Lock())) - { - double fps = m_fps; - - if(POSITION pos = pSubPicProvider->GetStartPosition(rtNow, fps)) - { - REFERENCE_TIME rtStart = pSubPicProvider->GetStart(pos, fps); - REFERENCE_TIME rtStop = pSubPicProvider->GetStop(pos, fps); - - if(rtStart <= rtNow && rtNow < rtStop) - { - RenderTo(sub_render_frame, rtNow, rtNow+1, fps, true); - } - } - - pSubPicProvider->Unlock(); - - if(*sub_render_frame) - { - CAutoLock cAutoLock(&m_csLock); - - m_pSubPic = *sub_render_frame; - } - } - } - return(!!*sub_render_frame); -} + +bool SimpleSubPicProvider::LookupSubPicEx(REFERENCE_TIME rtNow, IXySubRenderFrame** sub_render_frame) +{ + if(!sub_render_frame) + return(false); + + *sub_render_frame = NULL; + + if(m_subpic_start <= rtNow && rtNow < m_subpic_stop && m_pSubPic) + { + (*sub_render_frame = m_pSubPic)->AddRef(); + } + else + { + CComPtr pSubPicProvider; + if(SUCCEEDED(GetSubPicProviderEx(&pSubPicProvider)) && pSubPicProvider + && SUCCEEDED(pSubPicProvider->Lock())) + { + double fps = m_fps; + + if(POSITION pos = pSubPicProvider->GetStartPosition(rtNow, fps)) + { + REFERENCE_TIME rtStart = pSubPicProvider->GetStart(pos, fps); + REFERENCE_TIME rtStop = pSubPicProvider->GetStop(pos, fps); + + if(rtStart <= rtNow && rtNow < rtStop) + { + RenderTo(sub_render_frame, rtNow, rtNow+1, fps, true); + } + } + + pSubPicProvider->Unlock(); + + if(*sub_render_frame) + { + CAutoLock cAutoLock(&m_csLock); + + m_pSubPic = *sub_render_frame; + } + } + } + return(!!*sub_render_frame); +} HRESULT SimpleSubPicProvider::GetSubPicProviderEx( ISubPicProviderEx2** pSubPicProviderEx ) { - if(!pSubPicProviderEx) { - return E_POINTER; - } - - CAutoLock cAutoLock(&m_csSubPicProvider); - - if(m_pSubPicProviderEx) { - *pSubPicProviderEx = m_pSubPicProviderEx; - (*pSubPicProviderEx)->AddRef(); - } - + if(!pSubPicProviderEx) { + return E_POINTER; + } + + CAutoLock cAutoLock(&m_csSubPicProvider); + + if(m_pSubPicProviderEx) { + *pSubPicProviderEx = m_pSubPicProviderEx; + (*pSubPicProviderEx)->AddRef(); + } + return !!*pSubPicProviderEx ? S_OK : E_FAIL; } HRESULT SimpleSubPicProvider::RenderTo( IXySubRenderFrame** pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps, BOOL bIsAnimated ) { - HRESULT hr = E_FAIL; - - if(!pSubPic) { - return hr; - } - - CComPtr pSubPicProviderEx; - if(FAILED(GetSubPicProviderEx(&pSubPicProviderEx)) || !pSubPicProviderEx) { - return hr; - } - - if(FAILED(pSubPicProviderEx->Lock())) { - return hr; - } - + HRESULT hr = E_FAIL; + + if(!pSubPic) { + return hr; + } + + CComPtr pSubPicProviderEx; + if(FAILED(GetSubPicProviderEx(&pSubPicProviderEx)) || !pSubPicProviderEx) { + return hr; + } + + if(FAILED(pSubPicProviderEx->Lock())) { + return hr; + } + CAtlList rectList; CComPtr sub_render_frame; @@ -256,33 +256,33 @@ HRESULT SimpleSubPicProvider::RenderTo( IXySubRenderFrame** pSubPic, REFERENCE_T hr = pSubPicProviderEx->RenderEx(pSubPic, m_spd_type, m_spd_size, size_render_with, CRect(0,0,size_render_with.cx,size_render_with.cy), - bIsAnimated ? rtStart : ((rtStart+rtStop)/2), fps); - - POSITION pos = pSubPicProviderEx->GetStartPosition(rtStart, fps); - - pSubPicProviderEx->GetStartStop(pos, fps, m_subpic_start, m_subpic_stop); - - pSubPicProviderEx->Unlock(); - + bIsAnimated ? rtStart : ((rtStart+rtStop)/2), fps); + + POSITION pos = pSubPicProviderEx->GetStartPosition(rtStart, fps); + + pSubPicProviderEx->GetStartStop(pos, fps, m_subpic_start, m_subpic_stop); + + pSubPicProviderEx->Unlock(); + return hr; } bool SimpleSubPicProvider::IsSpdColorTypeSupported( int type ) { - if( (type==MSP_RGBA) - || - (type==MSP_XY_AUYV && m_alpha_blt_dst_type == MSP_YUY2) - || - (type==MSP_AYUV && m_alpha_blt_dst_type == MSP_AYUV)//ToDo: fix me MSP_AYUV - || - (type==MSP_AYUV_PLANAR && (m_alpha_blt_dst_type == MSP_IYUV || - m_alpha_blt_dst_type == MSP_YV12 || - m_alpha_blt_dst_type == MSP_P010 || - m_alpha_blt_dst_type == MSP_P016 || - m_alpha_blt_dst_type == MSP_NV12 || - m_alpha_blt_dst_type == MSP_NV21)) ) - { - return true; + if( (type==MSP_RGBA) + || + (type==MSP_XY_AUYV && m_alpha_blt_dst_type == MSP_YUY2) + || + (type==MSP_AYUV && m_alpha_blt_dst_type == MSP_AYUV)//ToDo: fix me MSP_AYUV + || + (type==MSP_AYUV_PLANAR && (m_alpha_blt_dst_type == MSP_IYUV || + m_alpha_blt_dst_type == MSP_YV12 || + m_alpha_blt_dst_type == MSP_P010 || + m_alpha_blt_dst_type == MSP_P016 || + m_alpha_blt_dst_type == MSP_NV12 || + m_alpha_blt_dst_type == MSP_NV21)) ) + { + return true; } return false; } @@ -320,8 +320,8 @@ SimpleSubPicProvider2::~SimpleSubPicProvider2() STDMETHODIMP SimpleSubPicProvider2::NonDelegatingQueryInterface( REFIID riid, void** ppv ) { - return - QI(ISimpleSubPicProvider) + return + QI(ISimpleSubPicProvider) __super::NonDelegatingQueryInterface(riid, ppv); } @@ -331,9 +331,9 @@ STDMETHODIMP SimpleSubPicProvider2::SetSubPicProvider( IUnknown* subpic_provider if (subpic_provider!=NULL) { - HRESULT hr; - CComQIPtr tmp = subpic_provider; - if (tmp) + HRESULT hr; + CComQIPtr tmp = subpic_provider; + if (tmp) { m_cur_provider = NULL; delete m_old_provider; diff --git a/src/subpic/SimpleSubPicProviderImpl.h b/src/subpic/SimpleSubPicProviderImpl.h index 4418b2ed6..2c1e9feb9 100644 --- a/src/subpic/SimpleSubPicProviderImpl.h +++ b/src/subpic/SimpleSubPicProviderImpl.h @@ -13,47 +13,47 @@ interface IDirectVobSubXy; class SimpleSubPicProvider: public CUnknown, public ISimpleSubPicProvider { public: - SimpleSubPicProvider(int alpha_blt_dst_type, SIZE spd_size, RECT video_rect, IDirectVobSubXy *consumer, HRESULT* phr=NULL); - virtual ~SimpleSubPicProvider(); - - DECLARE_IUNKNOWN; - STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - - bool LookupSubPicEx(REFERENCE_TIME rtNow, IXySubRenderFrame** sub_render_frame); - HRESULT GetSubPicProviderEx(ISubPicProviderEx2** pSubPicProviderEx); - HRESULT RenderTo(IXySubRenderFrame** pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps, BOOL bIsAnimated); - bool IsSpdColorTypeSupported(int type); -public: + SimpleSubPicProvider(int alpha_blt_dst_type, SIZE spd_size, RECT video_rect, IDirectVobSubXy *consumer, HRESULT* phr=NULL); + virtual ~SimpleSubPicProvider(); + + DECLARE_IUNKNOWN; + STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); + + bool LookupSubPicEx(REFERENCE_TIME rtNow, IXySubRenderFrame** sub_render_frame); + HRESULT GetSubPicProviderEx(ISubPicProviderEx2** pSubPicProviderEx); + HRESULT RenderTo(IXySubRenderFrame** pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps, BOOL bIsAnimated); + bool IsSpdColorTypeSupported(int type); +public: // ISimpleSubPicProvider STDMETHODIMP SetSubPicProvider(IUnknown* subpic_provider); - STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); - - STDMETHODIMP SetFPS(double fps); + STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); + + STDMETHODIMP SetFPS(double fps); STDMETHODIMP SetTime(REFERENCE_TIME rtNow); - STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); - - STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); + + STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); -private: - CCritSec m_csSubPicProvider; - CComPtr m_pSubPicProviderEx; - - CAtlList m_prefered_colortype; -protected: - int m_alpha_blt_dst_type; - SIZE m_spd_size; - RECT m_video_rect; - int m_spd_type; - double m_fps; - REFERENCE_TIME m_rtNow; - +private: + CCritSec m_csSubPicProvider; + CComPtr m_pSubPicProviderEx; + + CAtlList m_prefered_colortype; +protected: + int m_alpha_blt_dst_type; + SIZE m_spd_size; + RECT m_video_rect; + int m_spd_type; + double m_fps; + REFERENCE_TIME m_rtNow; + CComPtr m_pAllocator; - CCritSec m_csLock; - REFERENCE_TIME m_subpic_start,m_subpic_stop; + CCritSec m_csLock; + REFERENCE_TIME m_subpic_start,m_subpic_stop; CComPtr m_pSubPic; IDirectVobSubXy *m_consumer; @@ -67,30 +67,30 @@ class SimpleSubPicProvider: public CUnknown, public ISimpleSubPicProvider class SimpleSubPicProvider2: public CUnknown, public ISimpleSubPicProvider { public: - SimpleSubPicProvider2(int alpha_blt_dst_type, SIZE max_size, SIZE cur_size, RECT video_rect, + SimpleSubPicProvider2(int alpha_blt_dst_type, SIZE max_size, SIZE cur_size, RECT video_rect, IDirectVobSubXy *consumer, HRESULT* phr=NULL); - virtual ~SimpleSubPicProvider2(); - - DECLARE_IUNKNOWN; - STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); -public: - SimpleSubPicProvider2(const SimpleSubPicProvider2&); - void operator=(const SimpleSubPicProvider2&)const; - + virtual ~SimpleSubPicProvider2(); + + DECLARE_IUNKNOWN; + STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); +public: + SimpleSubPicProvider2(const SimpleSubPicProvider2&); + void operator=(const SimpleSubPicProvider2&)const; + // ISimpleSubPicProvider STDMETHODIMP SetSubPicProvider(IUnknown* subpic_provider); - STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); - - STDMETHODIMP SetFPS(double fps); + STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); + + STDMETHODIMP SetFPS(double fps); STDMETHODIMP SetTime(REFERENCE_TIME rtNow); - STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); - - STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); + + STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); - + protected: int m_alpha_blt_dst_type; SIZE m_max_size; diff --git a/src/subpic/SimpleSubPicWrapper.cpp b/src/subpic/SimpleSubPicWrapper.cpp index d4dd586fd..c1aac16b7 100644 --- a/src/subpic/SimpleSubPicWrapper.cpp +++ b/src/subpic/SimpleSubPicWrapper.cpp @@ -22,8 +22,8 @@ SimpleSubPicWrapper::SimpleSubPicWrapper( ISubPic* inner_obj ) STDMETHODIMP SimpleSubPicWrapper::NonDelegatingQueryInterface( REFIID riid, void** ppv ) { - return - QI(ISimpleSubPic) + return + QI(ISimpleSubPic) __super::NonDelegatingQueryInterface(riid, ppv); } diff --git a/src/subpic/SimpleSubPicWrapper.h b/src/subpic/SimpleSubPicWrapper.h index fc52c1766..b429f1aeb 100644 --- a/src/subpic/SimpleSubPicWrapper.h +++ b/src/subpic/SimpleSubPicWrapper.h @@ -13,7 +13,7 @@ class SimpleSubPicWrapper: public CUnknown, public ISimpleSubPic SimpleSubPicWrapper(ISubPicEx * inner_obj); SimpleSubPicWrapper(ISubPic* inner_obj); - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); STDMETHODIMP AlphaBlt(SubPicDesc* target); diff --git a/src/subpic/SimpleSubpicImpl.cpp b/src/subpic/SimpleSubpicImpl.cpp index c034b9e67..f3eb109dd 100644 --- a/src/subpic/SimpleSubpicImpl.cpp +++ b/src/subpic/SimpleSubpicImpl.cpp @@ -26,8 +26,8 @@ SimpleSubpic::~SimpleSubpic() STDMETHODIMP SimpleSubpic::NonDelegatingQueryInterface( REFIID riid, void** ppv ) { - return - QI(ISimpleSubPic) + return + QI(ISimpleSubPic) __super::NonDelegatingQueryInterface(riid, ppv); } @@ -65,16 +65,16 @@ STDMETHODIMP SimpleSubpic::AlphaBlt( SubPicDesc* target ) HRESULT SimpleSubpic::AlphaBltAnv12_P010( SubPicDesc* target, const Bitmap& src ) { //fix me: check colorspace and log error - SubPicDesc dst = *target; // copy, because we might modify it - + SubPicDesc dst = *target; // copy, because we might modify it + CRect rd(src.pos, src.size); if(dst.h < 0) { dst.h = -dst.h; rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; - } - + } + int w = src.size.cx, h = src.size.cy; bool bottom_down = rd.top > rd.bottom; @@ -103,16 +103,16 @@ HRESULT SimpleSubpic::AlphaBltAnv12_P010( SubPicDesc* target, const Bitmap& src HRESULT SimpleSubpic::AlphaBltAnv12_Nv12( SubPicDesc* target, const Bitmap& src ) { //fix me: check colorspace and log error - SubPicDesc dst = *target; // copy, because we might modify it - + SubPicDesc dst = *target; // copy, because we might modify it + CRect rd(src.pos, src.size); if(dst.h < 0) { dst.h = -dst.h; rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; - } - + } + int w = src.size.cx, h = src.size.cy; bool bottom_down = rd.top > rd.bottom; @@ -140,16 +140,16 @@ HRESULT SimpleSubpic::AlphaBltAnv12_Nv12( SubPicDesc* target, const Bitmap& src HRESULT SimpleSubpic::AlphaBlt( SubPicDesc* target, const Bitmap& src ) { - SubPicDesc dst = *target; // copy, because we might modify it - + SubPicDesc dst = *target; // copy, because we might modify it + CRect rd(src.pos, src.size); if(dst.h < 0) { dst.h = -dst.h; rd.bottom = dst.h - rd.bottom; rd.top = dst.h - rd.top; - } - + } + int w = src.size.cx, h = src.size.cy; const BYTE* s = reinterpret_cast(src.pixels); BYTE* d = reinterpret_cast(dst.bits) + dst.pitch*rd.top + ((rd.left*dst.bpp)>>3); @@ -202,12 +202,12 @@ HRESULT SimpleSubpic::AlphaBlt( SubPicDesc* target, const Bitmap& src ) const BYTE* s2end = s2 + w*4; DWORD* d2 = (DWORD*)d; for(; s2 < s2end; s2 += 4, d2++) - { + { if(s2[3] < 0xff) { *d2 = (((((*d2&0x00ff00ff)*s2[3])>>8) + (*((DWORD*)s2)&0x00ff00ff))&0x00ff00ff) | (((((*d2&0x0000ff00)*s2[3])>>8) + (*((DWORD*)s2)&0x0000ff00))&0x0000ff00); - } + } } } break; @@ -218,13 +218,13 @@ HRESULT SimpleSubpic::AlphaBlt( SubPicDesc* target, const Bitmap& src ) const BYTE* s2end = s2 + w*4; DWORD* d2 = (DWORD*)d; for(; s2 < s2end; s2 += 4, d2++) - { + { if(s2[3] < 0xff) { *d2 = (((((*d2&0x00ff00ff)*s2[3])>>8) + (*((DWORD*)s2)&0x00ff00ff))&0x00ff00ff) | (((((*d2&0x0000ff00)*s2[3])>>8) + (*((DWORD*)s2)&0x0000ff00))&0x0000ff00) | (*d2&0xff000000); - } + } } } break; diff --git a/src/subpic/SimpleSubpicImpl.h b/src/subpic/SimpleSubpicImpl.h index 52e5c70e7..e9cf6a7a6 100644 --- a/src/subpic/SimpleSubpicImpl.h +++ b/src/subpic/SimpleSubpicImpl.h @@ -10,7 +10,7 @@ class SimpleSubpic : public CUnknown, public ISimpleSubPic SimpleSubpic(IXySubRenderFrame*sub_render_frame, int alpha_blt_dst_type); ~SimpleSubpic(); public: - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); STDMETHODIMP AlphaBlt(SubPicDesc* target); diff --git a/src/subpic/SubPicImpl.cpp b/src/subpic/SubPicImpl.cpp index 9425d9bb0..365f366f9 100644 --- a/src/subpic/SubPicImpl.cpp +++ b/src/subpic/SubPicImpl.cpp @@ -1,506 +1,506 @@ -/* - * $Id: SubPicImpl.cpp 2786 2010-12-17 16:42:55Z XhmikosR $ - * - * (C) 2003-2006 Gabest - * (C) 2006-2010 see AUTHORS - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#include "stdafx.h" -#include "SubPicImpl.h" -#include "CRect2.h" -#include "../DSUtil/DSUtil.h" -#include "../DSUtil/xy_utils.h" - -// -// CSubPicImplHelper -// - -CSubPicImplHelper::CSubPicImplHelper() - : m_rtStart(0), m_rtStop(0) - , m_rtSegmentStart(0), m_rtSegmentStop(0) - , m_rcDirty(0, 0, 0, 0), m_maxsize(0, 0), m_size(0, 0), m_vidrect(0, 0, 0, 0) - , m_VirtualTextureSize(0, 0), m_VirtualTextureTopLeft (0, 0) -{ -} - -// ISubPic - -STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetStart() const -{ - return(m_rtStart); -} - -STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetStop() const -{ - return(m_rtStop); -} - -STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetSegmentStart() -{ - if (m_rtSegmentStart) { - return(m_rtSegmentStart); - } - return(m_rtStart); -} - -STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetSegmentStop() -{ - if (m_rtSegmentStop) { - return(m_rtSegmentStop); - } - return(m_rtStop); -} - -STDMETHODIMP_(void) CSubPicImplHelper::SetSegmentStart(REFERENCE_TIME rtStart) -{ - m_rtSegmentStart = rtStart; -} - -STDMETHODIMP_(void) CSubPicImplHelper::SetSegmentStop(REFERENCE_TIME rtStop) -{ - m_rtSegmentStop = rtStop; -} - -STDMETHODIMP_(void) CSubPicImplHelper::SetStart(REFERENCE_TIME rtStart) -{ - m_rtStart = rtStart; -} - -STDMETHODIMP_(void) CSubPicImplHelper::SetStop(REFERENCE_TIME rtStop) -{ - m_rtStop = rtStop; -} - -STDMETHODIMP CSubPicImplHelper::CopyTo(ISubPic* pSubPic) -{ - if(!pSubPic) - return E_POINTER; - - pSubPic->SetStart(m_rtStart); - pSubPic->SetStop(m_rtStop); - pSubPic->SetSegmentStart(m_rtSegmentStart); - pSubPic->SetSegmentStop(m_rtSegmentStop); - pSubPic->SetDirtyRect(m_rcDirty); - pSubPic->SetSize(m_size, m_vidrect); - pSubPic->SetVirtualTextureSize(m_VirtualTextureSize, m_VirtualTextureTopLeft); - - return S_OK; -} - -STDMETHODIMP CSubPicImplHelper::GetDirtyRect(RECT* pDirtyRect) const -{ - return pDirtyRect ? *pDirtyRect = m_rcDirty, S_OK : E_POINTER; -} - -STDMETHODIMP CSubPicImplHelper::GetSourceAndDest(SIZE* pSize, RECT* pRcSource, RECT* pRcDest) -{ - CheckPointer (pRcSource, E_POINTER); - CheckPointer (pRcDest, E_POINTER); - - if(m_size.cx > 0 && m_size.cy > 0) { - CRect rcTemp = m_rcDirty; - - // FIXME - rcTemp.DeflateRect(1, 1); - - *pRcSource = rcTemp; - - rcTemp.OffsetRect (m_VirtualTextureTopLeft); - *pRcDest = CRect (rcTemp.left * pSize->cx / m_VirtualTextureSize.cx, - rcTemp.top * pSize->cy / m_VirtualTextureSize.cy, - rcTemp.right * pSize->cx / m_VirtualTextureSize.cx, - rcTemp.bottom * pSize->cy / m_VirtualTextureSize.cy); - - return S_OK; - } else { - return E_INVALIDARG; - } -} - -STDMETHODIMP CSubPicImplHelper::SetDirtyRect(RECT* pDirtyRect) -{ - return pDirtyRect ? m_rcDirty = *pDirtyRect, S_OK : E_POINTER; -} - -STDMETHODIMP CSubPicImplHelper::GetMaxSize(SIZE* pMaxSize) const -{ - return pMaxSize ? *pMaxSize = m_maxsize, S_OK : E_POINTER; -} - -STDMETHODIMP CSubPicImplHelper::SetSize(SIZE size, RECT vidrect) -{ - m_size = size; - m_vidrect = vidrect; - - if(m_size.cx > m_maxsize.cx) { - m_size.cy = MulDiv(m_size.cy, m_maxsize.cx, m_size.cx); - m_size.cx = m_maxsize.cx; - } - - if(m_size.cy > m_maxsize.cy) { - m_size.cx = MulDiv(m_size.cx, m_maxsize.cy, m_size.cy); - m_size.cy = m_maxsize.cy; - } - - if(m_size.cx != size.cx || m_size.cy != size.cy) { - m_vidrect.top = MulDiv(m_vidrect.top, m_size.cx, size.cx); - m_vidrect.bottom = MulDiv(m_vidrect.bottom, m_size.cx, size.cx); - m_vidrect.left = MulDiv(m_vidrect.left, m_size.cy, size.cy); - m_vidrect.right = MulDiv(m_vidrect.right, m_size.cy, size.cy); - } - m_VirtualTextureSize = m_size; - - return S_OK; -} - -STDMETHODIMP CSubPicImplHelper::SetVirtualTextureSize (const SIZE pSize, const POINT pTopLeft) -{ - m_VirtualTextureSize.SetSize (pSize.cx, pSize.cy); - m_VirtualTextureTopLeft.SetPoint (pTopLeft.x, pTopLeft.y); - - return S_OK; -} - -// -// CSubPicImpl -// - -CSubPicImpl::CSubPicImpl() - :CUnknown(NAME("CSubPicImpl"), NULL) - ,CSubPicImplHelper() -{ - -} - -STDMETHODIMP CSubPicImpl::NonDelegatingQueryInterface( REFIID riid, void** ppv ) -{ - return - QI(ISubPic) - __super::NonDelegatingQueryInterface(riid, ppv); -} - -// -// CSubPicExImpl -// - -CSubPicExImpl::CSubPicExImpl() - :CUnknown(NAME("CSubPicExImpl"),NULL),CSubPicImplHelper() -{ - -} - -STDMETHODIMP CSubPicExImpl::NonDelegatingQueryInterface( REFIID riid, void** ppv ) -{ +/* + * $Id: SubPicImpl.cpp 2786 2010-12-17 16:42:55Z XhmikosR $ + * + * (C) 2003-2006 Gabest + * (C) 2006-2010 see AUTHORS + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "stdafx.h" +#include "SubPicImpl.h" +#include "CRect2.h" +#include "../DSUtil/DSUtil.h" +#include "../DSUtil/xy_utils.h" + +// +// CSubPicImplHelper +// + +CSubPicImplHelper::CSubPicImplHelper() + : m_rtStart(0), m_rtStop(0) + , m_rtSegmentStart(0), m_rtSegmentStop(0) + , m_rcDirty(0, 0, 0, 0), m_maxsize(0, 0), m_size(0, 0), m_vidrect(0, 0, 0, 0) + , m_VirtualTextureSize(0, 0), m_VirtualTextureTopLeft (0, 0) +{ +} + +// ISubPic + +STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetStart() const +{ + return(m_rtStart); +} + +STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetStop() const +{ + return(m_rtStop); +} + +STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetSegmentStart() +{ + if (m_rtSegmentStart) { + return(m_rtSegmentStart); + } + return(m_rtStart); +} + +STDMETHODIMP_(REFERENCE_TIME) CSubPicImplHelper::GetSegmentStop() +{ + if (m_rtSegmentStop) { + return(m_rtSegmentStop); + } + return(m_rtStop); +} + +STDMETHODIMP_(void) CSubPicImplHelper::SetSegmentStart(REFERENCE_TIME rtStart) +{ + m_rtSegmentStart = rtStart; +} + +STDMETHODIMP_(void) CSubPicImplHelper::SetSegmentStop(REFERENCE_TIME rtStop) +{ + m_rtSegmentStop = rtStop; +} + +STDMETHODIMP_(void) CSubPicImplHelper::SetStart(REFERENCE_TIME rtStart) +{ + m_rtStart = rtStart; +} + +STDMETHODIMP_(void) CSubPicImplHelper::SetStop(REFERENCE_TIME rtStop) +{ + m_rtStop = rtStop; +} + +STDMETHODIMP CSubPicImplHelper::CopyTo(ISubPic* pSubPic) +{ + if(!pSubPic) + return E_POINTER; + + pSubPic->SetStart(m_rtStart); + pSubPic->SetStop(m_rtStop); + pSubPic->SetSegmentStart(m_rtSegmentStart); + pSubPic->SetSegmentStop(m_rtSegmentStop); + pSubPic->SetDirtyRect(m_rcDirty); + pSubPic->SetSize(m_size, m_vidrect); + pSubPic->SetVirtualTextureSize(m_VirtualTextureSize, m_VirtualTextureTopLeft); + + return S_OK; +} + +STDMETHODIMP CSubPicImplHelper::GetDirtyRect(RECT* pDirtyRect) const +{ + return pDirtyRect ? *pDirtyRect = m_rcDirty, S_OK : E_POINTER; +} + +STDMETHODIMP CSubPicImplHelper::GetSourceAndDest(SIZE* pSize, RECT* pRcSource, RECT* pRcDest) +{ + CheckPointer (pRcSource, E_POINTER); + CheckPointer (pRcDest, E_POINTER); + + if(m_size.cx > 0 && m_size.cy > 0) { + CRect rcTemp = m_rcDirty; + + // FIXME + rcTemp.DeflateRect(1, 1); + + *pRcSource = rcTemp; + + rcTemp.OffsetRect (m_VirtualTextureTopLeft); + *pRcDest = CRect (rcTemp.left * pSize->cx / m_VirtualTextureSize.cx, + rcTemp.top * pSize->cy / m_VirtualTextureSize.cy, + rcTemp.right * pSize->cx / m_VirtualTextureSize.cx, + rcTemp.bottom * pSize->cy / m_VirtualTextureSize.cy); + + return S_OK; + } else { + return E_INVALIDARG; + } +} + +STDMETHODIMP CSubPicImplHelper::SetDirtyRect(RECT* pDirtyRect) +{ + return pDirtyRect ? m_rcDirty = *pDirtyRect, S_OK : E_POINTER; +} + +STDMETHODIMP CSubPicImplHelper::GetMaxSize(SIZE* pMaxSize) const +{ + return pMaxSize ? *pMaxSize = m_maxsize, S_OK : E_POINTER; +} + +STDMETHODIMP CSubPicImplHelper::SetSize(SIZE size, RECT vidrect) +{ + m_size = size; + m_vidrect = vidrect; + + if(m_size.cx > m_maxsize.cx) { + m_size.cy = MulDiv(m_size.cy, m_maxsize.cx, m_size.cx); + m_size.cx = m_maxsize.cx; + } + + if(m_size.cy > m_maxsize.cy) { + m_size.cx = MulDiv(m_size.cx, m_maxsize.cy, m_size.cy); + m_size.cy = m_maxsize.cy; + } + + if(m_size.cx != size.cx || m_size.cy != size.cy) { + m_vidrect.top = MulDiv(m_vidrect.top, m_size.cx, size.cx); + m_vidrect.bottom = MulDiv(m_vidrect.bottom, m_size.cx, size.cx); + m_vidrect.left = MulDiv(m_vidrect.left, m_size.cy, size.cy); + m_vidrect.right = MulDiv(m_vidrect.right, m_size.cy, size.cy); + } + m_VirtualTextureSize = m_size; + + return S_OK; +} + +STDMETHODIMP CSubPicImplHelper::SetVirtualTextureSize (const SIZE pSize, const POINT pTopLeft) +{ + m_VirtualTextureSize.SetSize (pSize.cx, pSize.cy); + m_VirtualTextureTopLeft.SetPoint (pTopLeft.x, pTopLeft.y); + + return S_OK; +} + +// +// CSubPicImpl +// + +CSubPicImpl::CSubPicImpl() + :CUnknown(NAME("CSubPicImpl"), NULL) + ,CSubPicImplHelper() +{ + +} + +STDMETHODIMP CSubPicImpl::NonDelegatingQueryInterface( REFIID riid, void** ppv ) +{ + return + QI(ISubPic) + __super::NonDelegatingQueryInterface(riid, ppv); +} + +// +// CSubPicExImpl +// + +CSubPicExImpl::CSubPicExImpl() + :CUnknown(NAME("CSubPicExImpl"),NULL),CSubPicImplHelper() +{ + +} + +STDMETHODIMP CSubPicExImpl::NonDelegatingQueryInterface( REFIID riid, void** ppv ) +{ return QI(ISubPicEx) (riid == __uuidof(ISubPic)) ? GetInterface( static_cast(this), ppv) : - __super::NonDelegatingQueryInterface(riid, ppv); -} - -STDMETHODIMP CSubPicExImpl::CopyTo( ISubPicEx* pSubPicEx ) -{ - if(!pSubPicEx) - return E_POINTER; - - pSubPicEx->SetStart(m_rtStart); - pSubPicEx->SetStop(m_rtStop); - pSubPicEx->SetSegmentStart(m_rtSegmentStart); - pSubPicEx->SetSegmentStop(m_rtSegmentStop); - pSubPicEx->SetDirtyRectEx(&m_rectListDirty); - pSubPicEx->SetSize(m_size, m_vidrect); - pSubPicEx->SetVirtualTextureSize(m_VirtualTextureSize, m_VirtualTextureTopLeft); - - return S_OK; -} - -STDMETHODIMP CSubPicExImpl::SetDirtyRect(RECT* pDirtyRect) -{ - HRESULT hr = CSubPicImplHelper::SetDirtyRect(pDirtyRect); - if(hr && pDirtyRect) - { - m_rectListDirty.RemoveAll(); - m_rectListDirty.AddTail(*pDirtyRect); - return S_OK; - } - else - { - return E_POINTER; - } -} - -STDMETHODIMP CSubPicExImpl::SetDirtyRectEx(CAtlList* dirtyRectList) -{ - if(dirtyRectList!=NULL) - { - m_rectListDirty.RemoveAll(); - m_rcDirty.SetRectEmpty(); - - POSITION tagPos = NULL; - POSITION pos = dirtyRectList->GetHeadPosition(); - while(pos!=NULL) - { - m_rcDirty |= dirtyRectList->GetNext(pos); - } - MergeRects(*dirtyRectList, &m_rectListDirty); - return S_OK; - } - return E_POINTER; -} - -STDMETHODIMP CSubPicExImpl::GetDirtyRects( CAtlList& dirtyRectList /*[out]*/ ) const -{ - POSITION pos = m_rectListDirty.GetHeadPosition(); - while(pos!=NULL) - { - dirtyRectList.AddTail(m_rectListDirty.GetNext(pos)); - } - return S_OK; -} - -STDMETHODIMP CSubPicExImpl::Unlock( RECT* pDirtyRect /*[in]*/ ) -{ - if(pDirtyRect) - { - CAtlList tmp; - tmp.AddTail(*pDirtyRect); - return Unlock(&tmp); - } - else - { - return Unlock( reinterpret_cast*>(NULL) ); - } -} - - -// -// CSubPicAllocatorImpl -// - -CSubPicAllocatorImpl::CSubPicAllocatorImpl(SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures ) - : CUnknown(NAME("ISubPicAllocatorImpl"), NULL) - , m_cursize(cursize) - , m_fDynamicWriteOnly(fDynamicWriteOnly) - , m_fPow2Textures(fPow2Textures) -{ - m_curvidrect = CRect(CPoint(0,0), m_cursize); -} - -STDMETHODIMP CSubPicAllocatorImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) -{ - return - QI(ISubPicAllocator) - __super::NonDelegatingQueryInterface(riid, ppv); -} - -// ISubPicAllocator - -STDMETHODIMP CSubPicAllocatorImpl::SetCurSize(SIZE cursize) -{ - m_cursize = cursize; - return S_OK; -} - -STDMETHODIMP CSubPicAllocatorImpl::SetCurVidRect(RECT curvidrect) -{ - m_curvidrect = curvidrect; - return S_OK; -} - -STDMETHODIMP CSubPicAllocatorImpl::GetStatic(ISubPic** ppSubPic) -{ - if(!ppSubPic) { - return E_POINTER; - } - - if(!m_pStatic) { - if(!Alloc(true, &m_pStatic) || !m_pStatic) { - return E_OUTOFMEMORY; - } - } - - m_pStatic->SetSize(m_cursize, m_curvidrect); - - (*ppSubPic = m_pStatic)->AddRef(); - - return S_OK; -} - -STDMETHODIMP CSubPicAllocatorImpl::AllocDynamic(ISubPic** ppSubPic) -{ - if(!ppSubPic) { - return E_POINTER; - } - - if(!Alloc(false, ppSubPic) || !*ppSubPic) { - return E_OUTOFMEMORY; - } - - (*ppSubPic)->SetSize(m_cursize, m_curvidrect); - - return S_OK; -} - -STDMETHODIMP_(bool) CSubPicAllocatorImpl::IsDynamicWriteOnly() -{ - return(m_fDynamicWriteOnly); -} - -STDMETHODIMP CSubPicAllocatorImpl::ChangeDevice(IUnknown* pDev) -{ - m_pStatic = NULL; - return S_OK; -} - -// -// CSubPicExAllocatorImpl -// - -CSubPicExAllocatorImpl::CSubPicExAllocatorImpl( SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures ) - :CUnknown(NAME("CSubPicExAllocatorImpl"), NULL) - , m_cursize(cursize) - , m_fDynamicWriteOnly(fDynamicWriteOnly) - , m_fPow2Textures(fPow2Textures) -{ - -} - -STDMETHODIMP CSubPicExAllocatorImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) -{ - return - QI(ISubPicExAllocator) - QI(ISubPicAllocator) - __super::NonDelegatingQueryInterface(riid, ppv); -} - -// ISubPicAllocator - -STDMETHODIMP CSubPicExAllocatorImpl::SetCurSize(SIZE cursize) -{ - m_cursize = cursize; - return S_OK; -} - -STDMETHODIMP CSubPicExAllocatorImpl::SetCurVidRect(RECT curvidrect) -{ - m_curvidrect = curvidrect; - return S_OK; -} - -STDMETHODIMP CSubPicExAllocatorImpl::GetStatic(ISubPic** ppSubPic) -{ - if( !ppSubPic ) - { - return GetStaticEx(NULL); - } - else - { - ISubPicEx *temp; - HRESULT result = GetStaticEx(&temp); - *ppSubPic = temp; - return result; - } -} - -STDMETHODIMP CSubPicExAllocatorImpl::AllocDynamic(ISubPic** ppSubPic) -{ - if( !ppSubPic ) - { - return AllocDynamicEx(NULL); - } - else - { - ISubPicEx *temp; - HRESULT result = AllocDynamicEx(&temp); - *ppSubPic = temp; - return result; - } -} - -STDMETHODIMP_(bool) CSubPicExAllocatorImpl::IsDynamicWriteOnly() -{ - return(m_fDynamicWriteOnly); -} - -STDMETHODIMP CSubPicExAllocatorImpl::ChangeDevice(IUnknown* pDev) -{ - m_pStatic = NULL; - return S_OK; -} - -// ISubPicExAllocator - -STDMETHODIMP CSubPicExAllocatorImpl::GetStaticEx(ISubPicEx** ppSubPic) -{ - if(!ppSubPic) { - return E_POINTER; - } - - if(!m_pStatic) { - if(!AllocEx(true, &m_pStatic) || !m_pStatic) { - return E_OUTOFMEMORY; - } - } - - m_pStatic->SetSize(m_cursize, m_curvidrect); - - (*ppSubPic = m_pStatic)->AddRef(); - - return S_OK; -} - -STDMETHODIMP CSubPicExAllocatorImpl::AllocDynamicEx(ISubPicEx** ppSubPic) -{ - if(!ppSubPic) { - return E_POINTER; - } - - if(!AllocEx(false, ppSubPic) || !*ppSubPic) { - return E_OUTOFMEMORY; - } - - (*ppSubPic)->SetSize(m_cursize, m_curvidrect); - - return S_OK; -} - -bool CSubPicExAllocatorImpl::Alloc( bool fStatic, ISubPic** ppSubPic ) -{ - if(ppSubPic==NULL) - { - return AllocEx(fStatic, NULL); - } - else - { - ISubPicEx *temp; - bool result = AllocEx(fStatic, &temp); - *ppSubPic = temp; - return result; - } -} - -STDMETHODIMP_(int) CSubPicExAllocatorImpl::SetSpdColorType( int color_type ) -{ - (color_type); - return MSP_RGBA; -} - -STDMETHODIMP_(bool) CSubPicExAllocatorImpl::IsSpdColorTypeSupported( int type ) -{ - return MSP_RGBA==type; -} + __super::NonDelegatingQueryInterface(riid, ppv); +} + +STDMETHODIMP CSubPicExImpl::CopyTo( ISubPicEx* pSubPicEx ) +{ + if(!pSubPicEx) + return E_POINTER; + + pSubPicEx->SetStart(m_rtStart); + pSubPicEx->SetStop(m_rtStop); + pSubPicEx->SetSegmentStart(m_rtSegmentStart); + pSubPicEx->SetSegmentStop(m_rtSegmentStop); + pSubPicEx->SetDirtyRectEx(&m_rectListDirty); + pSubPicEx->SetSize(m_size, m_vidrect); + pSubPicEx->SetVirtualTextureSize(m_VirtualTextureSize, m_VirtualTextureTopLeft); + + return S_OK; +} + +STDMETHODIMP CSubPicExImpl::SetDirtyRect(RECT* pDirtyRect) +{ + HRESULT hr = CSubPicImplHelper::SetDirtyRect(pDirtyRect); + if(hr && pDirtyRect) + { + m_rectListDirty.RemoveAll(); + m_rectListDirty.AddTail(*pDirtyRect); + return S_OK; + } + else + { + return E_POINTER; + } +} + +STDMETHODIMP CSubPicExImpl::SetDirtyRectEx(CAtlList* dirtyRectList) +{ + if(dirtyRectList!=NULL) + { + m_rectListDirty.RemoveAll(); + m_rcDirty.SetRectEmpty(); + + POSITION tagPos = NULL; + POSITION pos = dirtyRectList->GetHeadPosition(); + while(pos!=NULL) + { + m_rcDirty |= dirtyRectList->GetNext(pos); + } + MergeRects(*dirtyRectList, &m_rectListDirty); + return S_OK; + } + return E_POINTER; +} + +STDMETHODIMP CSubPicExImpl::GetDirtyRects( CAtlList& dirtyRectList /*[out]*/ ) const +{ + POSITION pos = m_rectListDirty.GetHeadPosition(); + while(pos!=NULL) + { + dirtyRectList.AddTail(m_rectListDirty.GetNext(pos)); + } + return S_OK; +} + +STDMETHODIMP CSubPicExImpl::Unlock( RECT* pDirtyRect /*[in]*/ ) +{ + if(pDirtyRect) + { + CAtlList tmp; + tmp.AddTail(*pDirtyRect); + return Unlock(&tmp); + } + else + { + return Unlock( reinterpret_cast*>(NULL) ); + } +} + + +// +// CSubPicAllocatorImpl +// + +CSubPicAllocatorImpl::CSubPicAllocatorImpl(SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures ) + : CUnknown(NAME("ISubPicAllocatorImpl"), NULL) + , m_cursize(cursize) + , m_fDynamicWriteOnly(fDynamicWriteOnly) + , m_fPow2Textures(fPow2Textures) +{ + m_curvidrect = CRect(CPoint(0,0), m_cursize); +} + +STDMETHODIMP CSubPicAllocatorImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) +{ + return + QI(ISubPicAllocator) + __super::NonDelegatingQueryInterface(riid, ppv); +} + +// ISubPicAllocator + +STDMETHODIMP CSubPicAllocatorImpl::SetCurSize(SIZE cursize) +{ + m_cursize = cursize; + return S_OK; +} + +STDMETHODIMP CSubPicAllocatorImpl::SetCurVidRect(RECT curvidrect) +{ + m_curvidrect = curvidrect; + return S_OK; +} + +STDMETHODIMP CSubPicAllocatorImpl::GetStatic(ISubPic** ppSubPic) +{ + if(!ppSubPic) { + return E_POINTER; + } + + if(!m_pStatic) { + if(!Alloc(true, &m_pStatic) || !m_pStatic) { + return E_OUTOFMEMORY; + } + } + + m_pStatic->SetSize(m_cursize, m_curvidrect); + + (*ppSubPic = m_pStatic)->AddRef(); + + return S_OK; +} + +STDMETHODIMP CSubPicAllocatorImpl::AllocDynamic(ISubPic** ppSubPic) +{ + if(!ppSubPic) { + return E_POINTER; + } + + if(!Alloc(false, ppSubPic) || !*ppSubPic) { + return E_OUTOFMEMORY; + } + + (*ppSubPic)->SetSize(m_cursize, m_curvidrect); + + return S_OK; +} + +STDMETHODIMP_(bool) CSubPicAllocatorImpl::IsDynamicWriteOnly() +{ + return(m_fDynamicWriteOnly); +} + +STDMETHODIMP CSubPicAllocatorImpl::ChangeDevice(IUnknown* pDev) +{ + m_pStatic = NULL; + return S_OK; +} + +// +// CSubPicExAllocatorImpl +// + +CSubPicExAllocatorImpl::CSubPicExAllocatorImpl( SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures ) + :CUnknown(NAME("CSubPicExAllocatorImpl"), NULL) + , m_cursize(cursize) + , m_fDynamicWriteOnly(fDynamicWriteOnly) + , m_fPow2Textures(fPow2Textures) +{ + +} + +STDMETHODIMP CSubPicExAllocatorImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) +{ + return + QI(ISubPicExAllocator) + QI(ISubPicAllocator) + __super::NonDelegatingQueryInterface(riid, ppv); +} + +// ISubPicAllocator + +STDMETHODIMP CSubPicExAllocatorImpl::SetCurSize(SIZE cursize) +{ + m_cursize = cursize; + return S_OK; +} + +STDMETHODIMP CSubPicExAllocatorImpl::SetCurVidRect(RECT curvidrect) +{ + m_curvidrect = curvidrect; + return S_OK; +} + +STDMETHODIMP CSubPicExAllocatorImpl::GetStatic(ISubPic** ppSubPic) +{ + if( !ppSubPic ) + { + return GetStaticEx(NULL); + } + else + { + ISubPicEx *temp; + HRESULT result = GetStaticEx(&temp); + *ppSubPic = temp; + return result; + } +} + +STDMETHODIMP CSubPicExAllocatorImpl::AllocDynamic(ISubPic** ppSubPic) +{ + if( !ppSubPic ) + { + return AllocDynamicEx(NULL); + } + else + { + ISubPicEx *temp; + HRESULT result = AllocDynamicEx(&temp); + *ppSubPic = temp; + return result; + } +} + +STDMETHODIMP_(bool) CSubPicExAllocatorImpl::IsDynamicWriteOnly() +{ + return(m_fDynamicWriteOnly); +} + +STDMETHODIMP CSubPicExAllocatorImpl::ChangeDevice(IUnknown* pDev) +{ + m_pStatic = NULL; + return S_OK; +} + +// ISubPicExAllocator + +STDMETHODIMP CSubPicExAllocatorImpl::GetStaticEx(ISubPicEx** ppSubPic) +{ + if(!ppSubPic) { + return E_POINTER; + } + + if(!m_pStatic) { + if(!AllocEx(true, &m_pStatic) || !m_pStatic) { + return E_OUTOFMEMORY; + } + } + + m_pStatic->SetSize(m_cursize, m_curvidrect); + + (*ppSubPic = m_pStatic)->AddRef(); + + return S_OK; +} + +STDMETHODIMP CSubPicExAllocatorImpl::AllocDynamicEx(ISubPicEx** ppSubPic) +{ + if(!ppSubPic) { + return E_POINTER; + } + + if(!AllocEx(false, ppSubPic) || !*ppSubPic) { + return E_OUTOFMEMORY; + } + + (*ppSubPic)->SetSize(m_cursize, m_curvidrect); + + return S_OK; +} + +bool CSubPicExAllocatorImpl::Alloc( bool fStatic, ISubPic** ppSubPic ) +{ + if(ppSubPic==NULL) + { + return AllocEx(fStatic, NULL); + } + else + { + ISubPicEx *temp; + bool result = AllocEx(fStatic, &temp); + *ppSubPic = temp; + return result; + } +} + +STDMETHODIMP_(int) CSubPicExAllocatorImpl::SetSpdColorType( int color_type ) +{ + (color_type); + return MSP_RGBA; +} + +STDMETHODIMP_(bool) CSubPicExAllocatorImpl::IsSpdColorTypeSupported( int type ) +{ + return MSP_RGBA==type; +} diff --git a/src/subpic/SubPicProviderExWrapper.cpp b/src/subpic/SubPicProviderExWrapper.cpp index 1da5dead0..f6004869c 100644 --- a/src/subpic/SubPicProviderExWrapper.cpp +++ b/src/subpic/SubPicProviderExWrapper.cpp @@ -4,7 +4,7 @@ /************************************************************************/ #include "stdafx.h" -#include "SubPicProviderExWrapper.h" +#include "SubPicProviderExWrapper.h" #include "../DSUtil/DSUtil.h" CSubPicProviderExWrapper* CSubPicProviderExWrapper::GetSubPicProviderExWrapper(ISubPicProvider* const inner_provider) @@ -22,14 +22,14 @@ CSubPicProviderExWrapper::~CSubPicProviderExWrapper() { } - + // ISubPicProvider STDMETHODIMP CSubPicProviderExWrapper::NonDelegatingQueryInterface( REFIID riid, void** ppv ) { - return - QI(ISubPicProvider) - QI(ISubPicProviderEx) + return + QI(ISubPicProvider) + QI(ISubPicProviderEx) __super::NonDelegatingQueryInterface(riid, ppv); } @@ -82,16 +82,16 @@ STDMETHODIMP CSubPicProviderExWrapper::GetTextureSize( POSITION pos, SIZE& MaxTe STDMETHODIMP_(VOID) CSubPicProviderExWrapper::GetStartStop( POSITION pos, double fps, /*out*/REFERENCE_TIME& start, /*out*/REFERENCE_TIME& stop ) { - start = _inner_provider->GetStart(pos, fps); + start = _inner_provider->GetStart(pos, fps); stop = _inner_provider->GetStop(pos, fps); } STDMETHODIMP CSubPicProviderExWrapper::RenderEx( SubPicDesc& spd, REFERENCE_TIME rt, double fps, CAtlList& rectList ) { - CRect cRect = new CRect(0,0,0,0); - HRESULT hr = Render(spd, rt, fps, cRect); - if(SUCCEEDED(hr)) - rectList.AddTail(cRect); + CRect cRect = new CRect(0,0,0,0); + HRESULT hr = Render(spd, rt, fps, cRect); + if(SUCCEEDED(hr)) + rectList.AddTail(cRect); return hr; } diff --git a/src/subpic/SubPicProviderExWrapper.h b/src/subpic/SubPicProviderExWrapper.h index b351a96d4..4e3062537 100644 --- a/src/subpic/SubPicProviderExWrapper.h +++ b/src/subpic/SubPicProviderExWrapper.h @@ -1,47 +1,47 @@ /************************************************************************/ /* author: xy */ /* date: 20111013 */ -/************************************************************************/ - -#pragma once - -#include "ISubPic.h" - -class CSubPicProviderExWrapper : public CUnknown, public ISubPicProviderEx -{ -private: - CSubPicProviderExWrapper(ISubPicProvider* const inner_provider);//disable inheriting - - CComPtr _inner_provider; -public: - static CSubPicProviderExWrapper* GetSubPicProviderExWrapper(ISubPicProvider* const inner_provider); - virtual ~CSubPicProviderExWrapper(); - - DECLARE_IUNKNOWN; - STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - - // ISubPicProvider - - STDMETHODIMP Lock(); - STDMETHODIMP Unlock(); - - STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps); - STDMETHODIMP_(POSITION) GetNext(POSITION pos); - - STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps); - STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps); - - STDMETHODIMP_(bool) IsAnimated (POSITION pos); - - STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox); - STDMETHODIMP GetTextureSize (POSITION pos, SIZE& MaxTextureSize, SIZE& VirtualSize, POINT& VirtualTopLeft); - - // ISubPicProviderEx - - STDMETHODIMP_(VOID) GetStartStop(POSITION pos, double fps, /*out*/REFERENCE_TIME& start, /*out*/REFERENCE_TIME& stop); - - STDMETHODIMP RenderEx(SubPicDesc& spd, REFERENCE_TIME rt, double fps, CAtlList& rectList); - - STDMETHODIMP_(bool) IsColorTypeSupported(int type); - STDMETHODIMP_(int) SetOutputColorType(int type);//Important! May failed! -}; +/************************************************************************/ + +#pragma once + +#include "ISubPic.h" + +class CSubPicProviderExWrapper : public CUnknown, public ISubPicProviderEx +{ +private: + CSubPicProviderExWrapper(ISubPicProvider* const inner_provider);//disable inheriting + + CComPtr _inner_provider; +public: + static CSubPicProviderExWrapper* GetSubPicProviderExWrapper(ISubPicProvider* const inner_provider); + virtual ~CSubPicProviderExWrapper(); + + DECLARE_IUNKNOWN; + STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); + + // ISubPicProvider + + STDMETHODIMP Lock(); + STDMETHODIMP Unlock(); + + STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps); + STDMETHODIMP_(POSITION) GetNext(POSITION pos); + + STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps); + STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps); + + STDMETHODIMP_(bool) IsAnimated (POSITION pos); + + STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox); + STDMETHODIMP GetTextureSize (POSITION pos, SIZE& MaxTextureSize, SIZE& VirtualSize, POINT& VirtualTopLeft); + + // ISubPicProviderEx + + STDMETHODIMP_(VOID) GetStartStop(POSITION pos, double fps, /*out*/REFERENCE_TIME& start, /*out*/REFERENCE_TIME& stop); + + STDMETHODIMP RenderEx(SubPicDesc& spd, REFERENCE_TIME rt, double fps, CAtlList& rectList); + + STDMETHODIMP_(bool) IsColorTypeSupported(int type); + STDMETHODIMP_(int) SetOutputColorType(int type);//Important! May failed! +}; diff --git a/src/subpic/SubPicProviderImpl.cpp b/src/subpic/SubPicProviderImpl.cpp index 65bd76a3b..6d66770b4 100644 --- a/src/subpic/SubPicProviderImpl.cpp +++ b/src/subpic/SubPicProviderImpl.cpp @@ -1,83 +1,83 @@ -/* - * $Id: SubPicProviderImpl.cpp 2585 2010-09-18 12:39:20Z xhmikosr $ - * - * (C) 2003-2006 Gabest - * (C) 2006-2010 see AUTHORS - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#include "stdafx.h" -#include "SubPicProviderImpl.h" -#include "../DSUtil/DSUtil.h" - -// -// CSubPicProviderImpl -// - -CSubPicProviderImpl::CSubPicProviderImpl(CCritSec* pLock) - : CUnknown(NAME("CSubPicProviderImpl"), NULL) - , m_pLock(pLock) -{ -} - -CSubPicProviderImpl::~CSubPicProviderImpl() -{ -} - -STDMETHODIMP CSubPicProviderImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) -{ - return - QI(ISubPicProvider) - QI(ISubPicProviderEx) - __super::NonDelegatingQueryInterface(riid, ppv); -} - -// ISubPicProvider - -STDMETHODIMP CSubPicProviderImpl::Lock() -{ - return m_pLock ? m_pLock->Lock(), S_OK : E_FAIL; -} - -STDMETHODIMP CSubPicProviderImpl::Unlock() -{ - return m_pLock ? m_pLock->Unlock(), S_OK : E_FAIL; -} +/* + * $Id: SubPicProviderImpl.cpp 2585 2010-09-18 12:39:20Z xhmikosr $ + * + * (C) 2003-2006 Gabest + * (C) 2006-2010 see AUTHORS + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "stdafx.h" +#include "SubPicProviderImpl.h" +#include "../DSUtil/DSUtil.h" + +// +// CSubPicProviderImpl +// + +CSubPicProviderImpl::CSubPicProviderImpl(CCritSec* pLock) + : CUnknown(NAME("CSubPicProviderImpl"), NULL) + , m_pLock(pLock) +{ +} + +CSubPicProviderImpl::~CSubPicProviderImpl() +{ +} + +STDMETHODIMP CSubPicProviderImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv) +{ + return + QI(ISubPicProvider) + QI(ISubPicProviderEx) + __super::NonDelegatingQueryInterface(riid, ppv); +} + +// ISubPicProvider + +STDMETHODIMP CSubPicProviderImpl::Lock() +{ + return m_pLock ? m_pLock->Lock(), S_OK : E_FAIL; +} + +STDMETHODIMP CSubPicProviderImpl::Unlock() +{ + return m_pLock ? m_pLock->Unlock(), S_OK : E_FAIL; +} // ISubPicProviderEx STDMETHODIMP_(VOID) CSubPicProviderImpl::GetStartStop( POSITION pos, double fps, /*out*/REFERENCE_TIME& start, /*out*/REFERENCE_TIME& stop ) { - start = GetStart(pos, fps); + start = GetStart(pos, fps); stop = GetStop(pos, fps); } STDMETHODIMP CSubPicProviderImpl::RenderEx( SubPicDesc& spd, REFERENCE_TIME rt, double fps, CAtlList& rectList ) { - CRect cRect = new CRect(0,0,0,0); - HRESULT hr = Render(spd, rt, fps, cRect); - if(SUCCEEDED(hr)) - rectList.AddTail(cRect); + CRect cRect = new CRect(0,0,0,0); + HRESULT hr = Render(spd, rt, fps, cRect); + if(SUCCEEDED(hr)) + rectList.AddTail(cRect); return hr; } - -STDMETHODIMP_(bool) CSubPicProviderImpl::IsColorTypeSupported( int type ) -{ - return type==MSP_RGBA; -} - + +STDMETHODIMP_(bool) CSubPicProviderImpl::IsColorTypeSupported( int type ) +{ + return type==MSP_RGBA; +} + diff --git a/src/subpic/SubPicQueueImpl.h b/src/subpic/SubPicQueueImpl.h index 50ad4340e..b5ac349e3 100644 --- a/src/subpic/SubPicQueueImpl.h +++ b/src/subpic/SubPicQueueImpl.h @@ -1,147 +1,147 @@ -/* - * $Id: SubPicQueueImpl.h 2786 2010-12-17 16:42:55Z XhmikosR $ - * - * (C) 2003-2006 Gabest - * (C) 2006-2010 see AUTHORS - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#pragma once - -#include "ISubPic.h" -#include "ISimpleSubPic.h" - - -class CSubPicQueueImpl : public CUnknown, public ISubPicQueue, public ISimpleSubPicProvider -{ - CAtlList m_prefered_colortype; - - CCritSec m_csSubPicProvider; - CComPtr m_pSubPicProviderEx; - -protected: - double m_fps; - REFERENCE_TIME m_rtNow; - REFERENCE_TIME m_rtNowLast; - - CComPtr m_pAllocator; - - HRESULT RenderTo(ISubPicEx* pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps, BOOL bIsAnimated); - +/* + * $Id: SubPicQueueImpl.h 2786 2010-12-17 16:42:55Z XhmikosR $ + * + * (C) 2003-2006 Gabest + * (C) 2006-2010 see AUTHORS + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#pragma once + +#include "ISubPic.h" +#include "ISimpleSubPic.h" + + +class CSubPicQueueImpl : public CUnknown, public ISubPicQueue, public ISimpleSubPicProvider +{ + CAtlList m_prefered_colortype; + + CCritSec m_csSubPicProvider; + CComPtr m_pSubPicProviderEx; + +protected: + double m_fps; + REFERENCE_TIME m_rtNow; + REFERENCE_TIME m_rtNowLast; + + CComPtr m_pAllocator; + + HRESULT RenderTo(ISubPicEx* pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps, BOOL bIsAnimated); + HRESULT SetSubPicProviderEx(ISubPicProviderEx* pSubPicProviderEx); - HRESULT GetSubPicProviderEx(ISubPicProviderEx** pSubPicProviderEx); -public: - CSubPicQueueImpl(ISubPicExAllocator* pAllocator, HRESULT* phr, const int *prefered_colortype=NULL, int prefered_colortype_num=0); - virtual ~CSubPicQueueImpl(); - - DECLARE_IUNKNOWN; - STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - - // ISubPicQueue - - STDMETHODIMP SetSubPicProvider(ISubPicProvider* pSubPicProvider); - STDMETHODIMP GetSubPicProvider(ISubPicProvider** pSubPicProvider); - - STDMETHODIMP SetFPS(double fps); - STDMETHODIMP SetTime(REFERENCE_TIME rtNow); - + HRESULT GetSubPicProviderEx(ISubPicProviderEx** pSubPicProviderEx); +public: + CSubPicQueueImpl(ISubPicExAllocator* pAllocator, HRESULT* phr, const int *prefered_colortype=NULL, int prefered_colortype_num=0); + virtual ~CSubPicQueueImpl(); + + DECLARE_IUNKNOWN; + STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); + + // ISubPicQueue + + STDMETHODIMP SetSubPicProvider(ISubPicProvider* pSubPicProvider); + STDMETHODIMP GetSubPicProvider(ISubPicProvider** pSubPicProvider); + + STDMETHODIMP SetFPS(double fps); + STDMETHODIMP SetTime(REFERENCE_TIME rtNow); + // ISimpleSubPicProvider STDMETHODIMP SetSubPicProvider(IUnknown* subpic_provider); - STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); - - STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1) = 0; -/* - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic) = 0; - - STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0; - STDMETHODIMP GetStats(int nSubPics, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0; -*/ -}; - -class CSubPicQueue : public CSubPicQueueImpl, private CAMThread -{ - int m_nMaxSubPic; - BOOL m_bDisableAnim; - - CInterfaceList m_Queue; - - CCritSec m_csQueueLock; // for protecting CInterfaceList - - - POSITION m_subPos;//use to pass to the SubPic provider to produce the next SubPic - - REFERENCE_TIME UpdateQueue(); - void AppendQueue(ISubPic* pSubPic); - int GetQueueCount(); - - REFERENCE_TIME m_rtQueueMin; - REFERENCE_TIME m_rtQueueMax; - REFERENCE_TIME m_rtQueueStart, m_rtInvalidate; - - // CAMThread - - bool m_fBreakBuffering; - enum {EVENT_EXIT, EVENT_TIME, EVENT_COUNT}; // IMPORTANT: _EXIT must come before _TIME if we want to exit fast from the destructor - HANDLE m_ThreadEvents[EVENT_COUNT]; - enum {QueueEvents_NOTEMPTY, QueueEvents_NOTFULL, QueueEvents_COUNT}; - HANDLE m_QueueEvents[QueueEvents_COUNT]; - DWORD ThreadProc(); - -public: - CSubPicQueue(int nMaxSubPic, BOOL bDisableAnim, ISubPicExAllocator* pAllocator, HRESULT* phr); - virtual ~CSubPicQueue(); - - // ISubPicQueue - - STDMETHODIMP SetFPS(double fps); - STDMETHODIMP SetTime(REFERENCE_TIME rtNow); - - STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic); - - STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); - STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); - - // ISimpleSubPicProvider - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); -}; - -class CSubPicQueueNoThread : public CSubPicQueueImpl -{ - CCritSec m_csLock; - CComPtr m_pSubPic; - - CAtlList m_prefered_colortype; - - bool LookupSubPicEx(REFERENCE_TIME rtNow, ISubPicEx** ppSubPic); -public: - CSubPicQueueNoThread(ISubPicExAllocator* pAllocator, HRESULT* phr, const int *prefered_colortype=NULL, int prefered_colortype_num=0); - virtual ~CSubPicQueueNoThread(); - - // ISubPicQueue - STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic); - - STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); - STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); - - // ISimpleSubPicProvider - STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); -}; - + STDMETHODIMP GetSubPicProvider(IUnknown** subpic_provider); + + STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1) = 0; +/* + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic) = 0; + + STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0; + STDMETHODIMP GetStats(int nSubPics, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0; +*/ +}; + +class CSubPicQueue : public CSubPicQueueImpl, private CAMThread +{ + int m_nMaxSubPic; + BOOL m_bDisableAnim; + + CInterfaceList m_Queue; + + CCritSec m_csQueueLock; // for protecting CInterfaceList + + + POSITION m_subPos;//use to pass to the SubPic provider to produce the next SubPic + + REFERENCE_TIME UpdateQueue(); + void AppendQueue(ISubPic* pSubPic); + int GetQueueCount(); + + REFERENCE_TIME m_rtQueueMin; + REFERENCE_TIME m_rtQueueMax; + REFERENCE_TIME m_rtQueueStart, m_rtInvalidate; + + // CAMThread + + bool m_fBreakBuffering; + enum {EVENT_EXIT, EVENT_TIME, EVENT_COUNT}; // IMPORTANT: _EXIT must come before _TIME if we want to exit fast from the destructor + HANDLE m_ThreadEvents[EVENT_COUNT]; + enum {QueueEvents_NOTEMPTY, QueueEvents_NOTFULL, QueueEvents_COUNT}; + HANDLE m_QueueEvents[QueueEvents_COUNT]; + DWORD ThreadProc(); + +public: + CSubPicQueue(int nMaxSubPic, BOOL bDisableAnim, ISubPicExAllocator* pAllocator, HRESULT* phr); + virtual ~CSubPicQueue(); + + // ISubPicQueue + + STDMETHODIMP SetFPS(double fps); + STDMETHODIMP SetTime(REFERENCE_TIME rtNow); + + STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic); + + STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + + // ISimpleSubPicProvider + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); +}; + +class CSubPicQueueNoThread : public CSubPicQueueImpl +{ + CCritSec m_csLock; + CComPtr m_pSubPic; + + CAtlList m_prefered_colortype; + + bool LookupSubPicEx(REFERENCE_TIME rtNow, ISubPicEx** ppSubPic); +public: + CSubPicQueueNoThread(ISubPicExAllocator* pAllocator, HRESULT* phr, const int *prefered_colortype=NULL, int prefered_colortype_num=0); + virtual ~CSubPicQueueNoThread(); + + // ISubPicQueue + STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1); + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic); + + STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop); + + // ISimpleSubPicProvider + STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME now /*[in]*/, ISimpleSubPic** output_subpic/*[out]*/); +}; + From 133eea0257ef49cc53cffb1a530241aa795368e1 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 18 Nov 2022 23:40:20 +0100 Subject: [PATCH 2/4] csri: stop advertising support for unimplemented formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An application is supposed to first configure a supported format via csri_request_fmt(..) for an instance and then pass frames in the previously requested format to csri_render(..). This setup logic was broken, when support for non BGR_ formats was dropped in 50d3b3b7ab712ee2419f48de14db1b01a8406e43 and applications can no longer detect whether a format is supported ahead of time and will instead crash when trying to render using any non BGR_ frame. Supposedly the non-BGR formats already didn't work properly before their removal. And since xy-VSFilter ungracefully bailed out on those for 10½ years now, it is highly unlikely anyone is actually (still) using them anyway. So just properly signal them as unsupported, so format probing is possible again. (Aegisub exclusively uses BGR_ since 2010, predating the removal in xy-VSFilter. See Aegisub SVN r5079 or 824294078f23cb77e4a46d9b927421f7888002e2) --- src/filters/transform/vsfilter/csriapi.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/filters/transform/vsfilter/csriapi.cpp b/src/filters/transform/vsfilter/csriapi.cpp index b032db02d..f45364594 100644 --- a/src/filters/transform/vsfilter/csriapi.cpp +++ b/src/filters/transform/vsfilter/csriapi.cpp @@ -114,12 +114,12 @@ CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt) // Check if pixel format is supported switch (fmt->pixfmt) { case CSRI_F_BGR_: - case CSRI_F_BGR: - case CSRI_F_YUY2: - case CSRI_F_YV12: inst->pixfmt = fmt->pixfmt; break; + case CSRI_F_BGR: // guliverkli2-VSFilter and old xy-VSFilter used to + case CSRI_F_YUY2: // support those formats, but they were dropped in + case CSRI_F_YV12: // 50d3b3b7ab712ee2419f48de14db1b01a8406e43 default: return -1; } @@ -144,11 +144,10 @@ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time) break; default: - ASSERT(0); - CString msg; - msg.Format(_T("Anything other then RGB32 is NOT supported!")); - MessageBox(NULL, msg, _T("Warning"), MB_OKCANCEL|MB_ICONWARNING); - int o = 0; o=o/o; + ASSERT(0); + CString msg; + msg.Format(_T("Anything other then RGB32 is NOT supported!")); + MessageBox(NULL, msg, _T("Warning"), MB_OKCANCEL|MB_ICONWARNING); return; } spd.vidrect = inst->video_rect; From cd641d391b2a6fff402cf6628703cd14a3b7303c Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 18 Nov 2022 23:24:21 +0100 Subject: [PATCH 3/4] [UNTESTED] DirectVobSubFilter: stop overriding known BT.601 matrices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit e928f83920b04bb33e0df69c74bbaa8d04a47260 allowed colorimetry information to be received from the DirectShow filter chain, so we don’t need to rely on resolution-based guesses as much. However, since it only checked for BT709 (and assigned a suboptimal fallback for SMPTE240) but not BT601, a known-to-be BT601 matrix was still overriden by the fallback guess for larger video resolutions. --- .../transform/vsfilter/DirectVobSubFilter.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp index 526fdc0f5..8b8c36157 100644 --- a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp +++ b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp @@ -2287,10 +2287,22 @@ void CDirectVobSubFilter::SetYuvMatrix() } else { - yuv_matrix = (extformat.VideoTransferMatrix == DXVA2_VideoTransferMatrix_BT709 || - extformat.VideoTransferMatrix == DXVA2_VideoTransferMatrix_SMPTE240M || - m_xy_size_opt[SIZE_ORIGINAL_VIDEO].cx > m_bt601Width || - m_xy_size_opt[SIZE_ORIGINAL_VIDEO].cy > m_bt601Height) ? ColorConvTable::BT709 : ColorConvTable::BT601; + switch (extformat.VideoTransferMatrix) + { + // FIXME: ColorConvTable doesn't support SMPTE240M. + // Since it's more similar to BT709 than BT601, prefer the former. + case DXVA2_VideoTransferMatrix_SMPTE240M: // -fallthrough + case DXVA2_VideoTransferMatrix_BT709: + yuv_matrix = ColorConvTable::BT709; + break; + case DXVA2_VideoTransferMatrix_BT601: + yuv_matrix = ColorConvTable::BT601; + break; + default: + yuv_matrix = (m_xy_size_opt[SIZE_ORIGINAL_VIDEO].cx > m_bt601Width || + m_xy_size_opt[SIZE_ORIGINAL_VIDEO].cy > m_bt601Height) ? + ColorConvTable::BT709 : ColorConvTable::BT601; + } } } else From c8448681c8ec784bb889f0d8a0f50349cb422e96 Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 18 Nov 2022 23:57:16 +0100 Subject: [PATCH 4/4] [UNTESTED] csri: add support for BGRA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xy-VSFilter already works with an alpha channel for BGR_ since 6a6f7cb39a446aa761abe40ffc94d659fe4a4c3f, so we just need to accept an additional format. Treating the padding byte of BGR_ as alpha may of course create its own problem. But given - the change to RGBA supposedly fixed some SSF bug - this behaviour existed since 2014 - I don’t know who besides Aegisub uses the csri interface I’m wary of changing this now. Regarding the naming mismatch BGR* and RGB*: csri has two distinct types for RGB* and BGR* with the name signifying the order of colour channels. Of those, guliverkli2 and xy-VSFilter always only supported the BGR* variants and mapped them to their internal RGB* types. This is most likely just a naming mismatch and *VSFilter’s RGB* types actually use BGR order. A look at the YUV to "RGB" conversion from the Aegisub commit mentioned in the previous commit corrobarates this. Even if not, this already dating back to guliverkli2 probably means every modern csri application already expects and relies on this. --- src/filters/transform/vsfilter/csriapi.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/filters/transform/vsfilter/csriapi.cpp b/src/filters/transform/vsfilter/csriapi.cpp index f45364594..0436a28cf 100644 --- a/src/filters/transform/vsfilter/csriapi.cpp +++ b/src/filters/transform/vsfilter/csriapi.cpp @@ -114,6 +114,7 @@ CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt) // Check if pixel format is supported switch (fmt->pixfmt) { case CSRI_F_BGR_: + case CSRI_F_BGRA: inst->pixfmt = fmt->pixfmt; break; @@ -136,7 +137,10 @@ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time) spd.w = inst->screen_res.cx; spd.h = inst->screen_res.cy; switch (inst->pixfmt) { + // xy-VSFilter treats BGR_ as having an alpha channel since 2014, + // specifically commit 6a6f7cb39a446aa761abe40ffc94d659fe4a4c3f case CSRI_F_BGR_: + case CSRI_F_BGRA: spd.type = MSP_RGBA; spd.bpp = 32; spd.bits = frame->planes[0]; @@ -146,7 +150,7 @@ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time) default: ASSERT(0); CString msg; - msg.Format(_T("Anything other then RGB32 is NOT supported!")); + msg.Format(_T("Anything other than BGR(A)32 is NOT supported!")); MessageBox(NULL, msg, _T("Warning"), MB_OKCANCEL|MB_ICONWARNING); return; }