// 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
最新推荐文章于 2024-05-25 18:59:22 发布
这段代码提供了从BITMAP 888、1555和565格式转换到YUV420sp的函数。通过读取BITMAP文件并进行颜色空间转换,将位图数据适配为YUV420sp格式,适用于视频处理和显示。

最低0.47元/天 解锁文章
1584

被折叠的 条评论
为什么被折叠?



