?? convert.cpp
字號:
/*
* Convert.cpp
*
* Convert colorspace
*
* DirectDraw YUV420P project
*
* Copyright (c) 2004-2005 for Cyansoft Studio.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Log: Convert.cpp,v $
* Revision 1.1 2005/01/17 13:42:59 jin.bai
* Initial revision
*
*
*/
#include <windows.h>
#include "YUV2RGB.H"
#include "Convert.h"
//
// Global macro
//
#define SOURCE_BIT_COUNT 12
#define SOURCE_COLOR_SPACE mmioFOURCC ('I', '4', '2', '0') // YUV420P or I420 or IYUV
#define NONETYPE 0
#define YUV2RGB32 1
#define YUV2RGB24 2
#define YUV2RGB565 3
#define YUV2RGB555 4
#define YUV2YUY2 5
//
// Convert class
//
Converter::Converter() : m_lpBuffer (NULL), m_dwVideoType (NONETYPE), m_pConvert (NULL)
{
m_vfSource.vfBitCount = SOURCE_BIT_COUNT;
m_vfSource.vfFourCC = SOURCE_COLOR_SPACE;
}
Converter::~Converter()
{
if (m_lpBuffer)
{
free (m_lpBuffer);
m_lpBuffer = NULL;
}
}
BOOL Converter::Create(PVIDEO_FORMAT_T pVfSource, PVIDEO_FORMAT_T pVfDest)
{
// Check if the input param is NULL
if (!pVfSource || !pVfDest) return FALSE;
if (pVfSource->vfBitCount != m_vfSource.vfBitCount ||
pVfSource->vfFourCC != m_vfSource.vfFourCC)
{
return FALSE;
}
// Same width and same height
if (pVfSource->vfWidth != pVfDest->vfWidth ||
pVfSource->vfHeight != pVfDest->vfHeight)
{
return FALSE;
}
switch (pVfDest->vfFourCC)
{
case BI_RGB:
if (pVfDest->vfBitCount == 32)
{
m_dwVideoType = YUV2RGB32;
m_vfDest.vfBitCount = 32;
m_pConvert = yuv2rgb_32;
}
else if (pVfDest->vfBitCount == 24)
{
m_dwVideoType =YUV2RGB24;
m_vfDest.vfBitCount = 24;
m_pConvert = yuv2rgb_24;
}
else if (pVfDest->vfBitCount == 16)
{
m_dwVideoType = YUV2RGB565;
m_vfDest.vfBitCount = 16;
m_pConvert = yuv2rgb_565;
}
else if (pVfDest->vfBitCount == 15)
{
m_dwVideoType = YUV2RGB555;
m_vfDest.vfBitCount = 16;
m_pConvert = yuv2rgb_555;
}
else
{
m_dwVideoType = NONETYPE;
}
break;
case mmioFOURCC('Y', 'U', 'Y', '2'):
m_dwVideoType = YUV2YUY2;
m_vfDest.vfBitCount = 16;
m_pConvert = yuy2_out;
break;
default:
m_dwVideoType = NONETYPE;
break;
}
if (m_dwVideoType != NONETYPE)
{
// Save
m_vfDest.vfWidth = pVfDest->vfWidth;
m_vfDest.vfHeight = pVfDest->vfHeight;
m_vfDest.vfFourCC = pVfDest->vfFourCC;
m_vfSource.vfWidth = pVfSource->vfWidth;
m_vfSource.vfHeight = pVfSource->vfHeight;
return AllocBuffer(&m_vfDest);
}
return FALSE;
}
BOOL Converter::AllocBuffer(PVIDEO_FORMAT_T pVidFormat)
{
if (m_lpBuffer)
{
free (m_lpBuffer);
m_lpBuffer = NULL;
}
// Alloc buffer
m_lpBuffer = (LPBYTE) malloc((pVidFormat->vfWidth * pVidFormat->vfHeight * pVidFormat->vfBitCount) >> 3);
return m_lpBuffer != NULL;
}
BOOL Converter::Convert(LPBYTE lpSourceBuffer, LPBYTE *lppDestBuffer)
{
BOOL bRtn = FALSE;
if (!lpSourceBuffer || !lppDestBuffer) return bRtn;
if (!m_lpBuffer || m_dwVideoType == NONETYPE || !m_pConvert) return bRtn;
__try
{
(*m_pConvert)(lpSourceBuffer, m_vfSource.vfWidth, (LPBYTE)lpSourceBuffer + (m_vfSource.vfWidth * m_vfSource.vfHeight), \
(LPBYTE)lpSourceBuffer + ((m_vfSource.vfWidth * m_vfSource.vfHeight * 5) >> 2), \
m_vfSource.vfWidth >> 1, m_lpBuffer, m_vfDest.vfWidth, m_vfDest.vfHeight, m_vfDest.vfWidth);
(*lppDestBuffer) = m_lpBuffer;
bRtn = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
bRtn = FALSE;
}
return bRtn;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -