📄 hxcolor.cpp
字号:
{CID_RGB8, RGB8toRGB8},
{CID_BGR32, RGB8toBGR32},
{CID_ARGB32, RGB8toRGB32},
{CID_UNKNOWN,0}};
#else
static CCLINK pcclRGB8 [] = { {CID_UNKNOWN, 0} };
#endif
/* "XING to *" converters: */
static CCLINK pcclXing [] = { {CID_YV12, XINGtoYV12},
{CID_YUY2, XINGtoYUY2},
{CID_UYVY, XINGtoUYVY},
{CID_RGB32, XINGtoRGB32},
{CID_RGB24, XINGtoRGB24},
{CID_RGB565, XINGtoRGB565},
#ifdef _8_BIT_SUPPORT
{CID_RGB8, XINGtoRGB8},
#endif
{CID_ARGB32, XINGtoRGB32},
{CID_UNKNOWN,0}
};
/* "BGR* to *" converters: */
static CCLINK pcclBGR32 [] = { {CID_I420, BGR_32toI420},
{CID_UNKNOWN,0}
};
static CCLINK pcclBGR24 [] = { {CID_I420, BGR24toI420},
{CID_UNKNOWN,0}
};
/* unsupported input formats: */
static CCLINK pcclUNKNOWN [] = {{CID_UNKNOWN, 0}};
/*
* Color formats/Converters map:
*/
static PCCLINK ppcclColorMap[] =
{
pcclI420,
pcclYV12,
pcclYVU9,
pcclYUY2,
pcclUYVY,
pcclRGB32,
pcclRGB24,
pcclRGB565,
pcclRGB555,
pcclRGB8,
pcclXing,
pcclARGB32,
pcclYUVA,
pcclYUVU,
pcclUNKNOWN,
pcclBGR32,
pcclBGR24
};
/*
* Retrieve the list of color formats that can be converted to, given an input
* format
* Use:
* HX_RESULT GetCompatibleColorFormats (INT32 cidIn, INT32* pcidOut, UINT32* pnSize);
* Input:
* cidIn - input color format ID (!CID_UNKNOWN)
* pcidOut - in - empty array, out - filled array of supported output formats
* pnSize - in - size of array, out - number of elements in array
* Returns:
* result
*/HX_RESULT HXEXPORT ENTRYPOINT(GetCompatibleColorFormats)(
INT32 cidIn /* in */,
INT32* pcidOut /* in/out */,
UINT32* pnSize /* in/out */)
{
HX_RESULT res = HXR_FAIL;
/* check parameters: */
int nConversions = sizeof(ppcclColorMap)/sizeof(PCCLINK);
if(cidIn >= 0 && cidIn < nConversions && pcidOut && pnSize)
{
UINT32 nFormats = 0;
/* scan color map: */
PCCLINK pccl = ppcclColorMap [cidIn];
while(pccl && pccl->cidOut != CID_UNKNOWN && nFormats < *pnSize)
{
pcidOut[nFormats] = pccl->cidOut;
/* try next element in the list: */
pccl++;
nFormats++;
}
res = HXR_OK;
*pnSize = nFormats;
}
return res;
}
/*
* Find Converter to trasform data in format X to format Y.
* Use:
* LPHXCOLORCONVERTER GetColorConverter (INT32 cidIn, INT32 cidOut);
* Input:
* cidIn - input color format ID (!CID_UNKNOWN)
* cidOut - desirable output color format ID (!CID_UNKNOWN)
* Returns:
* pointer to an appropriate color conversion routine, if success;
* NULL - conversion is not supported.
*/
LPHXCOLORCONVERTER HXEXPORT ENTRYPOINT(GetColorConverter) (INT32 cidIn, INT32 cidOut)
{
/* check parameters: */
int nConversions = sizeof(ppcclColorMap)/sizeof(PCCLINK);
if (cidIn >= 0 && cidIn < nConversions &&
cidOut >= 0 && cidOut <= NFORMATS) {
/* scan color map: */
PCCLINK pccl = ppcclColorMap [cidIn];
while (pccl &&
pccl->cidOut != CID_UNKNOWN) {
/* check output format: */
if (pccl->cidOut == cidOut)
return pccl->pfnCC;
/* try next element in the list: */
pccl ++;
}
}
return NULL;
}
LPHXCOLORCONVERTER2 HXEXPORT ENTRYPOINT(GetColorConverter2) (INT32 cidIn, INT32 cidOut)
{
CCLINK2 *pTemp = NULL;
/* check parameters: */
if (cidIn == CID_I420)
{
pTemp = pcclI420x;
}
else if (cidIn == CID_YV12)
{
pTemp = pcclYV12x;
}
else if (cidIn == CID_YUY2)
{
pTemp = pcclYUY2x;
}
else if (cidIn == CID_UYVY)
{
pTemp = pcclUYVYx;
}
if (pTemp)
{
/* scan color map: */
for (int i=0; pTemp[i].cidOut != CID_UNKNOWN; i++)
{
/* check output format: */
if (pTemp[i].cidOut == cidOut)
return pTemp[i].pfnCC;
}
}
return NULL;
}
/*
* Try selected compatible color formats.
* Use:
* BOOL ScanCompatibleColorFormats (INT32 cidIn, INT32 cidOutMask, void *pParam,
* BOOL (*pfnTryIt) (void *pParam, INT32 cidOut, LPHXCOLORCONVERTER pfnCC));
* Input:
* cidIn - input color format ID (!CID_UNKNOWN)
* cidOutMask - masks output formats to try (use ~0 to scan all formats)
* pParam - pointer to a parameter block to pass to fpTryIt ()
* pfnTryIt - pointer to a function, which will be called for each
* compatible output format;
* Returns:
* TRUE, if fpTryIt() has exited with TRUE status;
* FALSE, if non of the compatible formats has been accepted by fpTryIt().
*/
BOOL HXEXPORT ENTRYPOINT(ScanCompatibleColorFormats) (INT32 cidIn, INT32 cidOutMask, void *pParam,
BOOL (*pfnTryIt) (void *pParam, INT32 cidOut, LPHXCOLORCONVERTER pfnCC), INT32)
{
/* check parameters: */
int nConversions = sizeof(ppcclColorMap)/sizeof(PCCLINK);
if (cidIn >= 0 && cidIn < nConversions && pfnTryIt != NULL) {
/* scan color map: */
PCCLINK pccl = ppcclColorMap [cidIn];
while (pccl->cidOut != CID_UNKNOWN) {
/* try this format: */
if ((cidOutMask & (1U << pccl->cidOut)) &&
(* pfnTryIt) (pParam, pccl->cidOut, pccl->pfnCC))
return TRUE;
/* try next element in the list: */
pccl ++;
}
}
return FALSE;
}
/*
* Try all compatible color formats.
*/
BOOL HXEXPORT ENTRYPOINT(ScanAllCompatibleColorFormats) (INT32 cidIn,void *pParam,
BOOL (*pfnTryIt) (void *pParam, INT32 cidOut, LPHXCOLORCONVERTER pfnCC), INT32)
{
return ENTRYPOINT(ScanCompatibleColorFormats) (cidIn, (INT32)~0, pParam, pfnTryIt);
}
/***********************
* Old HXCOLOR.DLL interface:
****************************************************/
#ifdef _FAT_HXCOLOR
/*
* Converts a YUV buffer into an RGB buffer in the specified format.
*/
void HXEXPORT ENTRYPOINT(ConvertYUVtoRGB) (UCHAR* ySrc, UCHAR* uSrc, UCHAR* vSrc,
INT32 nPitchSrc,
UCHAR* Dst, INT32 nWidth, INT32 nHeight,
INT32 nPitchDst, INT16 nFormat, INT16 nExpand)
{
#if defined(_WINDOWS) || defined(_UNIX)
static void (*cc []) (unsigned char *, unsigned char *, unsigned char *, int, unsigned char *, int, int, int) =
{
oldI420toRGB24, oldI420toRGB555, oldI420toRGB565,
oldI420toRGB24x2, oldI420toRGB555x2, oldI420toRGB565x2
};
/* get function index: */
register int idx = (nFormat - T_RGB888);
if (idx < 0 || idx > 2) return; /* bad format */
if (nExpand) idx += 3;
/* call color converter/interpolator: */
(* cc [idx]) (ySrc, uSrc, vSrc, nPitchSrc, Dst, nWidth, nHeight, nPitchDst);
#elif defined (_MACINTOSH)
/* Mac version uses big endian RGB32 format only.
* Note, that our *->RGB32 converters will generate correct output
* on both LE & BE machines: */
(nExpand? oldI420toRGB32x2: oldI420toRGB32)
(ySrc, uSrc, vSrc, nPitchSrc, Dst, nWidth, nHeight, nPitchDst);
#endif
}
void HXEXPORT ENTRYPOINT(ConvertYUVtoMacRGB32) (UCHAR* ySrc, UCHAR* uSrc, UCHAR* vSrc, INT32 nPitchSrc,
UCHAR* Dst, INT32 nWidth, INT32 nHeight, INT32 nPitchDst, INT16 nFormat, INT16 nExpand)
{
/* Mac version uses big endian RGB32 format only.
* Note, that our *->RGB32 converters will generate correct output
* on both LE & BE machines: */
(nExpand? oldI420toRGB32x2: oldI420toRGB32)
(ySrc, uSrc, vSrc, nPitchSrc, Dst, nWidth, nHeight, nPitchDst);
}
/*
* Converts a 24bit RGB Buffer into a 32bit RGB buffer, used mainly on the Macintosh.
*/
void HXEXPORT ENTRYPOINT(ConvertRGB24toXRGB) (UCHAR* pSrc, UCHAR* pDest,
ULONG32 srcSize, ULONG32 destSize, INT32 nWidth, INT32 nHeight)
{
/* this shall generate a correct padded RGB32 on both LE & BE machines: */
RGB24toRGB32 (pDest, nWidth, nHeight, (nWidth*3+3)&~3, 0, 0, nWidth, nHeight,
pSrc, nWidth, nHeight, nWidth * 4, 0, 0, nWidth, nHeight);
}
/*
* Converts a RGB3 buffer into a YUV buffer in Y'CbCr 4:2:0 format.
*/
void HXEXPORT ENTRYPOINT(ConvertRGBtoYUV) (UCHAR* pInput, UCHAR* pOutput,
INT32 nWidth, INT32 nHeight, BOOL bBGR)
{
/* ignore bBRG for now: */
RGB24toI420 (pOutput, nWidth, nHeight, (nWidth*3+3)&~3, 0, 0, nWidth, nHeight,
pInput, nWidth, nHeight, nWidth, 0, 0, nWidth, nHeight);
}
#endif
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -