// only support to BITMAP 888 convert to YUV420sp
U8 *OSD_Bitmap888ToYUV(U8 *bitmapFileBuff, int *pYuvWidth, int *pYuvHeight)
{
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHead;
long offset = 0;
if(NULL == bitmapFileBuff)
{
LOG_ERROR(DBG_MODULE_OSD, "[%s] param NULL, buf:%p, \n", __func__, bitmapFileBuff);
return NULL;
}
memcpy(&fileHeader, bitmapFileBuff, sizeof(BITMAPFILEHEADER));
offset += sizeof(BITMAPFILEHEADER);
memcpy(&infoHead, bitmapFileBuff + offset, sizeof(BITMAPINFOHEADER));
offset += sizeof(BITMAPINFOHEADER);
LOG_INFO(DBG_MODULE_OSD, "w:%d, h:%d, bitCount:%d offset:%d\n", (int)infoHead.ciWidth, (int)infoHead.ciHeight, infoHead.ciBitCount, (int)fileHeader.cfoffBits);
LOG_INFO(DBG_MODULE_OSD, " infoHead.ciCompress:%x\n", (int)infoHead.ciCompress);
int yuvWidth = infoHead.ciWidth;
int yuvHeight = infoHead.ciHeight;
*pYuvWidth = yuvWidth;
*pYuvHeight = yuvHeight;
U8 *yuvBuffer = (U8 *)malloc(yuvWidth * yuvHeight * 1.5);
if(yuvBuffer == NULL)
{
LOG_ERROR(DBG_MODULE_OSD, "[%s] malloc failed \n", __func__);
return NULL;
}
U8 *UVBuffer = yuvBuffer + yuvWidth * yuvHeight;
U8 *bitmapBuff = bitmapFileBuff + offset;
int bitmapLineByte = (infoHead.ciWidth * BIMAP888_BIT_COUNT + 3) / 4 * 4; //计算图像每行像素所占的字节数
{
int x , y;
U8 *bitmapData;
U8 *pYData = yuvBuffer;
U8 *pUVData = UVBuffer;
for(y = 0; y < (yuvHeight - yuvHeight % 2); y++)
{
bitmapData = bitmapBuff + bitmapLineByte * (yuvHeight - y - 1);
for(x = 0; x < (yuvWidth - yuvWidth % 2); x++)
{
U8 bValue = *(bitmapData + 0) ;
U8 gValue = *(bitmapData + 1) ;
U8 rValue = *(bitmapData + 2) ;
// convert color rgb to yuv
U8 yValue = (((66 * rValue + 129 * gValue + 25 * bValue + 128) >> 8) + 16);
U8 uValue = ((-38 * rValue - 74 * gValue + 112 * bValue + 128) >> 8) + 128 ;
U8 vValue = ((112 * rValue - 94 * gValue - 18 * bValue + 128) >> 8) + 128 ;
*(pYData + x) = yValue;
if((!(x & 1)) && (!(y & 1)))
{
*(pUVData + x) = uValue;
*(pUVData + x + 1) =
BITMAP转YUV420
最新推荐文章于 2022-07-13 17:04:32 发布