📄 dvb_osd.c
字号:
b8Match = TRUE;
}
u8CodeSize++;
if(u8CodeSize>sizeof(unsigned)*8)
{
OSD_DEBUG(( "decompress error\n"));
return FALSE;
}
}
// get run length
u16RunLength = 0;
u8RunLengthBitCounter = 0;
#if 0
b8Match = FALSE;
while(!b8Match)
{
u8BitPosition--;
u8RunLengthBitCounter++;
if( ( pu8Code[0]&(0x01<<u8BitPosition) )==0 )
u16RunLength = (u16RunLength<<1) + 0x00;
else
u16RunLength = (u16RunLength<<1) + 0x01;
if(u8BitPosition==0)
{
u8BitPosition = 8;
pu8Code+=1;
}
if(u16RunLength==0)
{
u16RunLength = 1;
b8Match = TRUE;
}
if(u8RunLengthBitCounter==4)
{
u16RunLength = u16RunLength & 0x07;
if(u16RunLength==0x07)
{
u16RunLength = u16BmpWidth;
}
else if(u16RunLength==0x06)
{
u16RunLength = 16;
}
else
{
u16RunLength+=3;
}
b8Match = TRUE;
}
}
#else
#define RL_BIT 4
if(u8BitPosition>=RL_BIT)
{
u16RunLength = pu8Code[0]>>(u8BitPosition-RL_BIT);
u16RunLength = u16RunLength&( (0x01<<RL_BIT)-1 );
}
else
{
u16RunLength = pu8Code[0]&( (0x01<<u8BitPosition)-1 );
u16RunLength = u16RunLength<<(RL_BIT-u8BitPosition);
u16RunLength += pu8Code[1]>>(8-RL_BIT+u8BitPosition);
}
if(u16RunLength>=0x08)
{
u8RunLengthBitCounter = RL_BIT;
u16RunLength = u16RunLength & 0x07;
if(u16RunLength==0x07)
{
u16RunLength = u16BmpWidth;
}
else if(u16RunLength==0x06)
{
u16RunLength = 16;
}
else
{
u16RunLength+=3;
}
}
else
{
u8RunLengthBitCounter = 1;
u16RunLength = 1;
}
if(u8BitPosition>u8RunLengthBitCounter)
{
u8BitPosition -= u8RunLengthBitCounter;
}
else
{
pu8Code += 1;
u8BitPosition = u8BitPosition+8-u8RunLengthBitCounter;
}
#endif
OSD_DEBUG(("%hx,%d ", u8Decode, (int)u16RunLength));
// fill into line
for(u16idx=0; u16idx<u16RunLength; u16idx++)
{
*(pu8Line+u16idx) = u8Decode;
}
pu8Line+=u16RunLength;
}
OSD_DEBUG(("EOL\n"));
return TRUE;
}
/*******************************************************************************************/
bool8 OSD_LoadBitmap(u16 u16HandleID, OSD_BmpLoadParams *pstBmp)
{
CT_OSD_FrameHandleParams* pstOSDFrameHandle = NULL;
u8 * pu8BmpBuffer = NULL;
u16 u16BmpWidth = 0;
u16 u16BmpHeight = 0;
u16 u16Count = 0;
u16 u16RegionWidth = 0;
u16 u16RegionHeight = 0;
u32 u32FrameWorkAddr = 0;
u32 u32Addr;
if (pstBmp->enRegion >= EN_CT_OSD_FRAME_REGION_NUMBER)
{
return FALSE;
}
if (pstBmp->pu8Data == NULL)
{
return FALSE;
}
pstOSDFrameHandle = CT_OSD_GetFrameHandle(u16HandleID);
if (pstOSDFrameHandle==NULL)
{
return FALSE;
}
/*
* Get bitmap width and height (top + bottom).
*/
u16BmpWidth = pstBmp->u16Width;
u16BmpHeight = pstBmp->u16Height;
switch(pstBmp->enRegion)
{
default:
case EN_CT_OSD_FRAME_REGION_DISPLAY:
u32FrameWorkAddr = pstOSDFrameHandle->u32DisplayRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16DisplayRegionHeight;
break;
case EN_CT_OSD_FRAME_REGION_WORKING:
u32FrameWorkAddr = pstOSDFrameHandle->u32WorkingRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16WorkingRegionHeight;
break;
#ifndef NO_BMP_REGION
case EN_CT_OSD_FRAME_REGION_BITMAP:
u32FrameWorkAddr = pstOSDFrameHandle->u32BitmapRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16BitmapRegionHeight;
break;
#endif
}
u16RegionWidth = pstOSDFrameHandle->stInitParams.u16RegionWidth;
u32FrameWorkAddr += ((u32)(pstBmp->u16PosY) * u16RegionWidth + pstBmp->u16PosX);
if (((pstBmp->u16PosX + u16BmpWidth) > u16RegionWidth) ||
((pstBmp->u16PosY + u16BmpHeight) > u16RegionHeight))
{
OSD_DEBUG(("Out of OSD_LoadBitmap Region\n"));
return FALSE;
}
pu8BmpBuffer = (u8 *)pstBmp->pu8Data;
for (u16Count = 0; u16Count < u16BmpHeight ; u16Count++)
{
u32Addr = u32FrameWorkAddr + (u32)(u16Count * u16RegionWidth);
memcpy((u8 *)u32Addr, (u8 *)pu8BmpBuffer, u16BmpWidth);
pu8BmpBuffer += u16BmpWidth;
}
return TRUE;
} /* end OSD_LoadBitmap */
#ifdef NO_BMP_REGION
/*******************************************************************************************/
static bool8 OSD_LoadBitmap_No_CK(u16 u16HandleID, OSD_BmpLoadParams *pstBmp)
{
CT_OSD_FrameHandleParams* pstOSDFrameHandle = NULL;
u8 * pu8BmpBuffer = NULL;
u16 u16BmpWidth = 0;
u16 u16BmpHeight = 0;
u16 u16Count = 0;
u16 u16RegionWidth = 0;
u16 u16RegionHeight = 0;
u32 u32FrameWorkAddr = 0;
u32 u32Addr;
u16 u16YIdx = 0;
u8 *u8DesPtr = NULL;
if (pstBmp->enRegion >= EN_CT_OSD_FRAME_REGION_NUMBER)
{
return FALSE;
}
if (pstBmp->pu8Data == NULL)
{
return FALSE;
}
pstOSDFrameHandle = CT_OSD_GetFrameHandle(u16HandleID);
if (pstOSDFrameHandle==NULL)
{
return FALSE;
}
/*
* Get bitmap width and height (top + bottom).
*/
u16BmpWidth = pstBmp->u16Width;
u16BmpHeight = pstBmp->u16Height;
switch(pstBmp->enRegion)
{
default:
case EN_CT_OSD_FRAME_REGION_DISPLAY:
u32FrameWorkAddr = pstOSDFrameHandle->u32DisplayRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16DisplayRegionHeight;
break;
case EN_CT_OSD_FRAME_REGION_WORKING:
u32FrameWorkAddr = pstOSDFrameHandle->u32WorkingRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16WorkingRegionHeight;
break;
#ifndef NO_BMP_REGION
case EN_CT_OSD_FRAME_REGION_BITMAP:
u32FrameWorkAddr = pstOSDFrameHandle->u32BitmapRegionTopFieldStartAddr;
u16RegionHeight = pstOSDFrameHandle->stInitParams.u16BitmapRegionHeight;
break;
#endif
}
u16RegionWidth = pstOSDFrameHandle->stInitParams.u16RegionWidth;
u32FrameWorkAddr += ((u32)(pstBmp->u16PosY) * u16RegionWidth + pstBmp->u16PosX);
if (((pstBmp->u16PosX + u16BmpWidth) > u16RegionWidth) ||
((pstBmp->u16PosY + u16BmpHeight) > u16RegionHeight))
{
OSD_DEBUG(("Out of OSD_LoadBitmap Region\n"));
return FALSE;
}
pu8BmpBuffer = (u8 *)pstBmp->pu8Data;
for (u16Count = 0; u16Count < u16BmpHeight ; u16Count++)
{
u32Addr = u32FrameWorkAddr + (u32)(u16Count * u16RegionWidth);
u8DesPtr = (u8 *)u32Addr;
for (u16YIdx = 0; u16YIdx < u16BmpWidth; u16YIdx++)
{
if (*(pu8BmpBuffer+u16YIdx) != u16AreaCopyColorKeyIndex)
{
*(u8DesPtr+u16YIdx) = (u8)(*(pu8BmpBuffer+u16YIdx));
}
}
pu8BmpBuffer += u16BmpWidth;
}
return TRUE;
} /* end OSD_LoadBitmap_No_CK */
#endif // end #ifdef NO_BMP_REGION
/*******************************************************************************************/
EN_OSD_ERROR DVB_OSDBitmap_LoadPlus (DVB_OSD_BmpParameter *pstBmp, u8 *pu8BmpData , u8 u8DstRegion)
{
OSD_BmpLoadParams stBmpLoad;
EN_CT_OSD_FRAME_REGION enDstCtRegion = EN_CT_OSD_FRAME_REGION_WORKING;
u32 u32BmpMode = 0;
u16 u16BmpWidth = 0;
u16 u16BmpHeight = 0;
u16 u16Count = 0;
u8* pu8HuffmanLineBuffer = NULL;
u32* pu32BmpSrcBuffer = NULL;
if (enCurrentOSDMode == EN_OSD_MODE_DISABLE)
{
return (EN_OSD_ERROR_DATA_FORMAT);
}
enDstCtRegion = OSD_GetCtRegionByDvbRegion(u8DstRegion);
if (pu8BmpData == NULL)
{
return (EN_OSD_ERROR_DATA_FORMAT);
}
pu32BmpSrcBuffer = (u32*)pu8BmpData;
u32BmpMode = (u32)*(pu32BmpSrcBuffer+1); // compression mode
u16BmpWidth = (u16)*(pu32BmpSrcBuffer+2); // the width
u16BmpHeight = (u16)*(pu32BmpSrcBuffer+3); // the width
pu32BmpSrcBuffer = pu32BmpSrcBuffer+4;
pstBmp->u16Width = u16BmpWidth;
pstBmp->u16Height = u16BmpHeight;
OSD_DEBUG(("bmp format %lu\n", u32BmpMode));
if(u32BmpMode==5 ) // huffman coding
{
stBmpLoad.u16PosY = pstBmp->u16PosY;
gen_point = 323;
pu8HuffmanLineBuffer = DVB_MemoryAllocate(u16BmpWidth);
if(pu8HuffmanLineBuffer==NULL)
{
OSD_DEBUG(( "huffman decode malloc fail!!\n"));
return EN_OSD_ERROR_BMP_SIZE;
}
HuffmanDecode_Init( (u8*)pu32BmpSrcBuffer, u16BmpWidth );
for(u16Count=0; u16Count<pstBmp->u16Height; u16Count++)
{
if( HuffmanDecode_GetLine( &pu8HuffmanLineBuffer[0]) ==FALSE)
{
DVB_MemoryFree(pu8HuffmanLineBuffer);
OSD_DEBUG(( "HuffmanDecode_GetLine() Fail 1\n"));
return EN_OSD_ERROR_DATA_FORMAT;
}
stBmpLoad.enRegion = enDstCtRegion;
stBmpLoad.u16PosX = pstBmp->u16PosX;
stBmpLoad.u16PosY = pstBmp->u16PosY+u16Count;
stBmpLoad.u16Width = pstBmp->u16Width;
stBmpLoad.u16Height = 1;
stBmpLoad.pu8Data = pu8HuffmanLineBuffer;
if (OSD_LoadBitmap(u16OSDFrameHandleID, (OSD_BmpLoadParams *)&stBmpLoad) != TRUE)
{
DVB_MemoryFree(pu8HuffmanLineBuffer);
OSD_DEBUG(( "OSD_LoadBitmap() Fail\n"));
return EN_OSD_ERROR_BMP_SIZE;
}
}
DVB_MemoryFree(pu8HuffmanLineBuffer);
OSD_DEBUG(( "HuffmanDecode Success\n"));
}
else
{
stBmpLoad.enRegion = enDstCtRegion;
stBmpLoad.u16PosX = pstBmp->u16PosX;
stBmpLoad.u16PosY = pstBmp->u16PosY;
stBmpLoad.u16Width = pstBmp->u16Width;
stBmpLoad.u16Height = pstBmp->u16Height;
stBmpLoad.pu8Data = (u8*)pu32BmpSrcBuffer;
if (OSD_LoadBitmap(u16OSDFrameHandleID, (OSD_BmpLoadParams *)&stBmpLoad) != TRUE)
{
return EN_OSD_ERROR_BMP_SIZE;
}
}
return (EN_OSD_NO_ERROR);
}
/*******************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -