📄 hantrodecoderutils.cpp
字号:
/*------------------------------------------------------------------------------
-- --
-- This software is confidential and proprietary and may be used --
-- only as expressly authorized by a licensing agreement from --
-- --
-- Hantro Products Oy. --
-- --
-- In the event of publication, the following notice is applicable: --
-- --
-- (C) COPYRIGHT 2005 HANTRO PRODUCTS OY --
-- ALL RIGHTS RESERVED --
-- --
-- The entire notice above must be reproduced on all copies. --
-- --
--------------------------------------------------------------------------------
--
-- Description : Hantro MPEG-4/H.263 Video Decoder DirectX Media Object
--
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
1. Include headers
------------------------------------------------------------------------------*/
#include "HantroDecoderUtils.h"
#include <ddraw.h>
//#define ENABLE_POST_FILTERING
#ifdef UNDER_CE
#ifdef ENABLE_POST_FILTERING
#include <pf.h>
#endif /* ENABLE_POST_FILTERING */
#endif /* UNDER_CE */
#include <stdio.h>
/*------------------------------------------------------------------------------
2. Module defines
------------------------------------------------------------------------------*/
#define HTR_DEBUG printf
#define HTR_DEBUG_XTRA //printf
/*------------------------------------------------------------------------------
3. BitsPerPixel function
------------------------------------------------------------------------------*/
ULONG BitsPerPixel(const GUID colorSpace)
{
/*
if( colorSpace == MEDIASUBTYPE_RGB565 )
{
return 16;
}
else //if( colorSpace == MEDIASUBTYPE_IYUV )
{
return 12;
}
*/
return 12;
}
HRESULT CHtrPostProc::Initialize(void)
{
HRESULT hr = S_OK;
#ifdef HTR_DDRAW
// Create DirectDraw object for the _active_ display driver
hr = DirectDrawCreate(NULL, &m_pDD, NULL);
// Set the co-operative level (m_pDD can't be null at this point)
hr = m_pDD->SetCooperativeLevel(NULL, DDSCL_NORMAL);
#endif HTR_DDRAW
#ifdef HTR_PP
// Initialize the cctTable
YuvToRgbInit(&cctTable[0], YUVTORGB_BT601_RANGE_1);
#endif HTR_PP
return hr;
}
HRESULT CHtrPostProc::Process(PostProcessorSurface* pIn,
PostProcessorSurface* pOut,
QuantizationData* pQuantData)
{
#ifdef HTR_DDRAW
HRESULT hr;
LPVOID lpSurface = NULL;
HLOCAL hMemHandle = NULL;
DDSURFACEDESC ddsd;
LPDIRECTDRAWSURFACE lpDDSIn;
LPDIRECTDRAWSURFACE lpDDSOut;
// Initialize the surface description for YCbCr 4:2:0
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
ZeroMemory(&ddsd.ddsCaps, sizeof(DDSCAPS));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
DDSD_PIXELFORMAT;// | DDSD_CAPS;
ddsd.dwWidth = pIn->m_width;
ddsd.dwHeight= pIn->m_height;
// ddsd.lPitch = (LONG)pIn->m_width;
ddsd.lpSurface = pIn->m_pBuffer;
// Set up the pixel format for YCbCr 4:2:0
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFlags= DDPF_FOURCC | DDPF_YUV;
ddsd.ddpfPixelFormat.dwYBitMask = 0x000000FF;
ddsd.ddpfPixelFormat.dwUBitMask = 0x000000FF;
ddsd.ddpfPixelFormat.dwVBitMask = 0x000000FF;
ddsd.ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y','V','1','2'); // MEDIASUBTYPE_YV12
ddsd.ddpfPixelFormat.dwYUVBitCount = (DWORD)12;
// Set up the caps flags
//ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
DWORD lNumCodes = 50;
DWORD code[50];
hr = m_pDD->GetFourCCCodes(&lNumCodes, &(code[0]));
printf("supported fourcc codes:\n");
for(int i=0; i<lNumCodes; i++)
{
printf("%c%c%c%c\n", code[i], code[i]>>8, code[i]>>16, code[i]>>24);
}
DDCAPS ddDriverCaps;
DDCAPS ddHelCaps;
hr = m_pDD->GetCaps(&ddDriverCaps, &ddHelCaps);
// Create the input surface
hr = m_pDD->CreateSurface(&ddsd, &lpDDSIn, NULL);
// Initialize the surface description
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | //DDSD_LPSURFACE |
DDSD_PIXELFORMAT | DDSD_CAPS;
ddsd.dwWidth = pOut->m_width;
ddsd.dwHeight= pOut->m_height;
//ddsd.lpSurface = pOut->m_pBuffer;
// Set up the pixel format for 16-bit RGB (5-6-5).
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
//ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
//ddsd.ddpfPixelFormat.dwRBitMask = 0x0000F100;
//ddsd.ddpfPixelFormat.dwGBitMask = 0x000007E0;
//ddsd.ddpfPixelFormat.dwBBitMask = 0x0000001F;
ddsd.ddpfPixelFormat.dwRGBBitCount = 24;
ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
// Set up the caps flags
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
// Create the output surface
hr = m_pDD->CreateSurface(&ddsd, &lpDDSOut, NULL);
DDBLTFX ddbltfx;
ZeroMemory(&ddbltfx, sizeof(ddbltfx));
ddbltfx.dwSize = sizeof(ddbltfx);
//hr = lpDDSOut->Blt(NULL, lpDDSIn, NULL, 0, &ddbltfx);
#endif
#ifdef HTR_PP
if( pIn->m_format == pOut->m_format )
{
memcpy(pOut->m_pBuffer,
pIn->m_pBuffer,
(pIn->m_width*pIn->m_height*BitsPerPixel(pIn->m_format)) / 8);
return S_OK;
}
if( pOut->m_format == MEDIASUBTYPE_RGB565 )
{
const u8* Y;
const u8* U;
const u8* V;
Y = pIn->m_pBuffer;
U = Y + pIn->m_width*pIn->m_height;
V = U + ((pIn->m_width*pIn->m_height)/4);
// convert color from YUV420 to RGB565
YuvToRgb16(&cctTable[0], Y, U, V, (u16*)pOut->m_pBuffer, pIn->m_width, pIn->m_height, pOut->m_width, -pOut->m_height, 0, 0, 0);
}
if( pOut->m_format == MEDIASUBTYPE_RGB24 )
{
// convert color from YUV420 to RGB24
}
#endif // HTR_PP
return S_OK;
}
HRESULT CHtrPostProc::Close(void)
{
#ifdef HTR_DDRAW
// Release the DirectDraw object
if( NULL != m_pDD )
{
m_pDD->Release();
m_pDD = NULL;
}
#endif HTR_DDRAW
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -