osd.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:9k
- #include "osd.h"
- #include "layer.h"
- #include "avmem.h"
- #include "text.h"
- #include "blit.h"
- #include "errors.h"
- STGXOBJ_Bitmap_t Bitmap[NUM_VPORTS];
- STAVMEM_BlockHandle_t BitmapBlockHandle[NUM_VPORTS];
- static INT32 gnOsdInitFlag = FALSE;
- static INT32 gnOsdTransparencyLevel;
- INT32 KB_OSDFillRect(INT32 nX,INT32 nY,INT32 nWidth,INT32 nHeight,ColrRef nColor)
- {
- STGXOBJ_Rectangle_t tRect;
- ST_ErrorCode_t nStErrCode;
- STGXOBJ_Color_t tColor;
-
- tRect.PositionX = (S32)nX;
- tRect.PositionY = (S32)nY;
- tRect.Width = (S32)nWidth;
- tRect.Height = (S32)nHeight;
-
- tColor.Type = STGXOBJ_COLOR_TYPE_ARGB4444;//STGXOBJ_COLOR_TYPE_ARGB1555;
- tColor.Value.ARGB1555.Alpha = (UINT8)((nColor >> 31) & 0x00000001);
- tColor.Value.ARGB1555.R = (UINT8)((nColor >> 19) & 0x0000001F);
- tColor.Value.ARGB1555.G = (UINT8)((nColor >> 11) & 0x0000001F);
- tColor.Value.ARGB1555.B = (UINT8)((nColor >> 3) & 0x0000001F);
-
- nStErrCode = STBLIT_FillRectangle(BLIT_Handle, &Bitmap[VPORT_OSD], &tRect, &tColor, &GtBlitContext);
-
- return RETOK;
- }
- INT32 KB_OSDRef2Rgb(ColrRef nColorRef, KB_OSDRGB *pRgb)
- {
- if (pRgb == NULL)
- {
- return RETFAIL3;
- }
-
- pRgb->cRed = (UINT8)((nColorRef >> 16) & 0x000000FF);
- pRgb->cGreen = (UINT8)((nColorRef >> 8) & 0x000000FF);
- pRgb->cBlue = (UINT8)((nColorRef) & 0x000000FF);
-
- return RETOK;
- }
- INT32 KB_OSDGetTransparency(void)
- {
- return gnOsdTransparencyLevel;
- }
- INT32 KB_OSDSetTransparency(INT32 nLevel)
- {
- if (nLevel < 0 || nLevel > 100)
- {
- return RETFAIL3;
- }
-
- gnOsdTransparencyLevel = nLevel;
- KB_LayerSetViewPortAlpha(VPORT_OSD, nLevel);
-
- return RETOK;
- }
- /*=============================================================
- 函数名称 : KB_OSDAllocate
- 功 能 : 在g_KBAvmemPartitionHandle[0]分区中分配存储空间
- 该空间能够容纳特定类型的位图数据,
- 这里的类型是本OSD 模块所支持的类型
- 入 口 : INT32 nWidth 位图的宽
- INT32 nHeight 位图的高
- 出 口 : 无
- 返 回 : 存储空间指针
- =============================================================*/
- void* KB_OSDAllocate(INT32 nWidth, INT32 nHeight)
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- STAVMEM_AllocBlockParams_t AllocParams;
- STAVMEM_BlockHandle_t BlockHandle;
-
- STGXOBJ_BitmapAllocParams_t BitmapAllocParams1, BitmapAllocParams2;
- STGXOBJ_Bitmap_t *Bitmap_p;
- STGXOBJ_Bitmap_t Bitmap;
-
- Bitmap_p = &Bitmap;
-
- /* Image Info */
- Bitmap_p->ColorType = STGXOBJ_COLOR_TYPE_ARGB4444;
- Bitmap_p->BitmapType = STGXOBJ_BITMAP_TYPE_RASTER_PROGRESSIVE;
- Bitmap_p->ColorSpaceConversion = STGXOBJ_ITU_R_BT601;
- Bitmap_p->AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
- Bitmap_p->Width = (U32)nWidth;
- Bitmap_p->Height = (U32)nHeight;
- /* Unused */
- Bitmap_p->PreMultipliedColor = FALSE;
- Bitmap_p->SubByteFormat = STGXOBJ_SUBBYTE_FORMAT_RPIX_MSB;
- Bitmap_p->BigNotLittle = FALSE;
-
- /* Get Alloc Parameters */
- ErrCode = STLAYER_GetBitmapAllocParams(g_KB_LayerHandle[LAYER_OSD], Bitmap_p, &BitmapAllocParams1, &BitmapAllocParams2);
- if ( ErrCode != ST_NO_ERROR )
- {
- printf("STLAYER_GetBitmapAllocParams()=%sn", DBGError(ErrCode));
- return NULL;
- }
-
- AllocParams.PartitionHandle = g_KBAvmemPartitionHandle[0];
- AllocParams.AllocMode = STAVMEM_ALLOC_MODE_BOTTOM_TOP;
- AllocParams.NumberOfForbiddenRanges = 0;
- AllocParams.ForbiddenRangeArray_p = (STAVMEM_MemoryRange_t *) NULL;
- AllocParams.NumberOfForbiddenBorders = 0;
- AllocParams.ForbiddenBorderArray_p = (void **) NULL;
- /* Values from layer fn */
- AllocParams.Size = BitmapAllocParams1.AllocBlockParams.Size;
- AllocParams.Alignment = BitmapAllocParams1.AllocBlockParams.Alignment;
- AllocParams.Alignment = 16;
-
- Bitmap_p->Pitch = BitmapAllocParams1.Pitch;
- Bitmap_p->Offset = BitmapAllocParams1.Offset;
- Bitmap_p->Data1_p = NULL;
- Bitmap_p->Size1 = AllocParams.Size;
- Bitmap_p->Data2_p = NULL;
- Bitmap_p->Size2 = 0;
-
- /* Allocate Display buffer */
- ErrCode = STAVMEM_AllocBlock( &AllocParams, &BlockHandle );
- if ( ErrCode != ST_NO_ERROR )
- {
- printf("Error allocating AVMEM memory : 0x%08Xn",ErrCode);
- return NULL;
- }
-
- ErrCode = STAVMEM_GetBlockAddress( BlockHandle, (void **)&(Bitmap_p->Data1_p));
- if ( ErrCode != ST_NO_ERROR )
- {
- printf("STAVMEM_GetBlockAddress(0x%x,0x%x)=%sn",
- Bitmap_p->Data1_p, Bitmap_p->Data2_p, DBGError(ErrCode));
- return NULL;
- }
-
- return Bitmap_p->Data1_p;
- }
- //在AVMEM 中为位图分配空间来存储其数据
- INT32 KB_OSDAllocBitmap(STGXOBJ_Bitmap_t *Bitmap_p,
- STAVMEM_BlockHandle_t *BlockHandle_p,
- U32 Width,
- U32 Height )
- {
- ST_ErrorCode_t ErrCode = ST_NO_ERROR;
- STAVMEM_AllocBlockParams_t AllocParams;
- STAVMEM_FreeBlockParams_t FreeBlockParams;
-
- if ( *BlockHandle_p != 0 )
- {
- printf("KB_OSDAllocBitmap *BlockHandle_p != 0 n");
- FreeBlockParams.PartitionHandle = g_KBAvmemPartitionHandle[0];
- (void) STAVMEM_FreeBlock(&FreeBlockParams, BlockHandle_p);
- }
-
- Bitmap_p->ColorType = STGXOBJ_COLOR_TYPE_ARGB4444;
- Bitmap_p->BitmapType = STGXOBJ_BITMAP_TYPE_RASTER_PROGRESSIVE;
- Bitmap_p->ColorSpaceConversion = STGXOBJ_ITU_R_BT601;
- Bitmap_p->AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
- Bitmap_p->Width = Width;
- Bitmap_p->Height = Height;
- Bitmap_p->PreMultipliedColor = FALSE;
- Bitmap_p->SubByteFormat = STGXOBJ_SUBBYTE_FORMAT_RPIX_MSB;
- Bitmap_p->BigNotLittle = FALSE;
-
- AllocParams.PartitionHandle = g_KBAvmemPartitionHandle[0];
- AllocParams.AllocMode = STAVMEM_ALLOC_MODE_BOTTOM_TOP;
- AllocParams.NumberOfForbiddenRanges = 0;
- AllocParams.ForbiddenRangeArray_p = (STAVMEM_MemoryRange_t *) NULL;
- AllocParams.NumberOfForbiddenBorders = 0;
- AllocParams.ForbiddenBorderArray_p = (void **) NULL;
- AllocParams.Size = Width * Height * KB_OSD_BYTES;
- AllocParams.Alignment = KB_OSD_BYTES /* BitmapAllocParams1.AllocBlockParams.Alignment */;
-
- Bitmap_p->Pitch = Width * KB_OSD_BYTES;
- Bitmap_p->Offset = 0;
- Bitmap_p->Data1_p = NULL;
- Bitmap_p->Size1 = AllocParams.Size;
- Bitmap_p->Data2_p = NULL;
- Bitmap_p->Size2 = 0;
-
- (void) STAVMEM_AllocBlock( &AllocParams, BlockHandle_p );
- ErrCode = STAVMEM_GetBlockAddress( *BlockHandle_p, (void **)&(Bitmap_p->Data1_p));
- if ( ErrCode != ST_NO_ERROR )
- {
- printf("STAVMEM_GetBlockAddress(0x%x,0x%x)=%sn",
- Bitmap_p->Data1_p, Bitmap_p->Data2_p, DBGError(ErrCode));
- return RETFIAL1;
- }
-
- return RETOK;
- }
- //初始化osd 显示,先安装BLIT,再初始化文本显示,再分配osd 的数据存储区,并将其
- //与打开的视频端口联系起来,光标也设置在该层,只是另行 分配视频端口
- //经过该过程,以后要在osd 上显示的数据都应拷贝到Bitmap[VPORT_OSD]中,而光标数据
- //放在Bitmap[VPORT_OSD_CURSOR] 中
- /*=============================================================
- 函数名称 : KB_OSDInit(void)
- 功 能 : 初始化osd 显示
- 入 口 : 无
- 出 口 : 无
- 返 回 : RETOK ---成功,RETFIAL1 ---失败
- 描 述 :
- =============================================================*/
- INT32 KB_OSDInit(void)
- {
- ST_ErrorCode_t nStErrCode;
- STGXOBJ_Rectangle_t OutputRectangle;
- INT32 nReturn;
-
- if (gnOsdInitFlag == TRUE)
- {
- return RETFIAL1;
- }
-
- /*nStErrCode = BLIT_Setup();
- if (nStErrCode != ST_NO_ERROR)
- {
- return RETFIAL1;
- }*/
-
- #ifdef J_OSD_USE_GFX
- nStErrCode = GFX_Setup();
- if (nStErrCode != ST_NO_ERROR)
- return(RETFIAL1);
- #endif
- //初始化文本显示
- KB_TxtInit();
-
- nReturn = KB_OSDAllocBitmap(&Bitmap[VPORT_OSD],
- &BitmapBlockHandle[VPORT_OSD],
- KB_OSD_WIDTH,
- KB_OSD_HEIGHT);
- if ( nReturn != RETOK )
- {
- printf("KB_OSDAllocBitmap(%d) error!n", VPORT_OSD);
- return(RETFIAL1);
- }
-
- Bitmap[VPORT_OSD].Width = KB_OSD_WIDTH;
- Bitmap[VPORT_OSD].Height = KB_OSD_HEIGHT;
- OutputRectangle.PositionX = 0;
- OutputRectangle.PositionY = 0;
- OutputRectangle.Height = KB_OSD_HEIGHT;
- OutputRectangle.Width = KB_OSD_WIDTH;
-
- KB_LayerOpenViewPort((UINT8)LAYER_OSD, (UINT8)VPORT_OSD, &Bitmap[VPORT_OSD],&OutputRectangle);
- //clear screen
- KB_OSDFillRect(0,0,KB_OSD_WIDTH,KB_OSD_HEIGHT,KB_COLOR_TRANSPARENCY);
- memset(Bitmap[VPORT_OSD].Data1_p,0x00,Bitmap[VPORT_OSD].Size1*KB_OSD_BYTES);
-
- gnOsdInitFlag = TRUE;
- gnOsdTransparencyLevel = 100;
- return RETOK;
- }
- /* EOF */