📄 textst_presctrl.cpp
字号:
* @remarks
* If pal == NULL, this indicates to load the directfb palette with all transparent.
*/
TEXTST_STATUS TextSTPresCtrlLoadPalette(TEXTST_PALETTE *pal, IDirectFBPalette *dfb_palette)
{
ULONG ulProcessedLength;
UBYTE ubPalEntryID;
ULONG Color;
BYTE *ClrBytes = (BYTE *)&Color;
DFBColor dfb_palette_entry[256];
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlLoadPalette: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlLoadPalette: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
if ( (pal == NULL) || (dfb_palette == NULL) )
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlLoadPalette: NULL pointer!\n"));
return (TEXTST_NULL_PTR);
}
else
{
/* Get current palette entries */
if (hTextSTPresCtrl->hTextST->DFBInfo.dfb_palette->GetEntries(hTextSTPresCtrl->hTextST->DFBInfo.dfb_palette,
dfb_palette_entry, 256, 0) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlLoadPalette: Failed to get palette entries!\n"));
return (TEXTST_FAILURE);
}
/* load dfb palette with new entries */
ulProcessedLength = 0;
while (ulProcessedLength < pal->length)
{
/* set palette entry id */
ubPalEntryID = pal->palette_entry[ (ulProcessedLength / 5) ].palette_entry_id;
if (hTextSTPresCtrl->hTextST->ulColorSpace == REC_601)
{
/* convert all colors to ARGB */
Color = textstpresctrlMakeARGBfromYCrCb601(pal->palette_entry[ (ulProcessedLength / 5) ].Y_value, // y
pal->palette_entry[ (ulProcessedLength / 5) ].Cr_value, //cr
pal->palette_entry[ (ulProcessedLength / 5) ].Cb_value, //cb
pal->palette_entry[ (ulProcessedLength / 5) ].T_value); //t
}
else
{
/* convert all colors to ARGB */
Color = textstpresctrlMakeARGBfromYCrCb709(pal->palette_entry[ (ulProcessedLength / 5) ].Y_value, // y
pal->palette_entry[ (ulProcessedLength / 5) ].Cr_value, //cr
pal->palette_entry[ (ulProcessedLength / 5) ].Cb_value, //cb
pal->palette_entry[ (ulProcessedLength / 5) ].T_value); //t
}
/* Set palette entry color information */
dfb_palette_entry[ubPalEntryID].a = ClrBytes[0];
dfb_palette_entry[ubPalEntryID].r = ClrBytes[1];
dfb_palette_entry[ubPalEntryID].g = ClrBytes[2];
dfb_palette_entry[ubPalEntryID].b = ClrBytes[3];
/* Adjust length of palette processed */
ulProcessedLength += 5;
}
}
/* set dfb palette entries */
if (dfb_palette->SetEntries(dfb_palette, dfb_palette_entry, 256, 0) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlLoadPalette: failed to set palette entries\n"));
return (TEXTST_FAILURE);
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlSetPalette -- Set palette for primary surface.
*
* @param
* dfb_palette -- palette to set to primary surface
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlSetPalette(IDirectFBPalette *dfb_palette)
{
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlSetPalette: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlSetPalette: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
if (dfb_palette == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlSetPalette: NULL pointer!\n"));
return (TEXTST_NULL_PTR);
}
/* Set the palette to the primary surface */
if (hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface->SetPalette(hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface, dfb_palette) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlSetPalette: Failed to set surface palette!\n"));
return (TEXTST_FAILURE);
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlFlip -- Flip the primary surface.
*
* @param
* dfb_palette -- palette to set to primary surface
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlFlip(void)
{
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlip: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Flip primary surface */
if (hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface->Flip(hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface, NULL, DSFLIP_NONE) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlip: Failed to flip primary surface!\n"));
return (TEXTST_FAILURE);
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlAddBmpObj -- Add a DPS's bitmap object to the TextST Presentation
* Controller Bitmap Queue.
*
* @param
* pBitmapObj -- Bitmap object for the DPS
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlAddBmpObj(TEXTST_BITMAP_OBJECT *pBitmapObj)
{
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlAddBmpObj: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlAddBmpObj: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Check that message queue is created */
if (hTextSTPresCtrl->BmpMsgQID == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlAddBmpObj: Msg queue not created!\n"));
return (TEXTST_FAILURE);
}
/* Send rendering info to the TextST Render task */
pBitmapObj->fValid = TRUE;
if (OS_MsgQSend(hTextSTPresCtrl->BmpMsgQID, (char *)pBitmapObj, sizeof(TEXTST_BITMAP_OBJECT), OS_NO_WAIT, OS_MSG_PRI_NORMAL) != OS_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlAddBmpObj: Failure sending message!\n"));
return (TEXTST_FAILURE);
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlFlushCompQ -- Flush the TextST Presentation Controller's composition queue.
*
* @param
* none
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlFlushCompQ(void)
{
TEXTST_COMPOSITION_INFO *pCompInfo = NULL;
BOOLEAN fDone = FALSE;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlFlushCompQ: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlushCompQ: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Check that message queue is created */
if (hTextSTPresCtrl->CompMsgQID == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlushCompQ: Msg queue not created!\n"));
return (TEXTST_FAILURE);
}
/* Remove all messages from the queue */
while (fDone != TRUE)
{
if (OS_MsgQRemove(hTextSTPresCtrl->CompMsgQID, (char *)&pCompInfo, sizeof(TEXTST_COMPOSITION_INFO *) ) != OS_OK)
{
fDone = TRUE;
break;
}
else
{
/* Release composition object */
textstpresctrlReleaseCompInfo(pCompInfo);
}
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlFlushBmpQ -- Flush the TextST Presentation Controller's bitmap queue.
*
* @param
* none
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlFlushBmpQ(void)
{
TEXTST_BITMAP_OBJECT BmpObj;
BOOLEAN fDone = FALSE;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlFlushBmpQ: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlushBmpQ: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Check that message queue is created */
if (hTextSTPresCtrl->BmpMsgQID == 0)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlFlushBmpQ: Msg queue not created!\n"));
return (TEXTST_FAILURE);
}
/* Remove all messages from the queue */
while (fDone != TRUE)
{
if (OS_MsgQRemove(hTextSTPresCtrl->BmpMsgQID, (char *)&BmpObj, sizeof(TEXTST_BITMAP_OBJECT)) != OS_OK)
{
fDone = TRUE;
break;
}
else
{
/* Release the bitmap object */
textstpresctrlReleaseBitmapObj(&BmpObj);
}
}
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlSuspend -- Suspend the TextST Presentation Controller
*
* @param
* none
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlSuspend(void)
{
TEXTST_COMPOSITION_INFO *pCompInfo = NULL;
TEXTST_BITMAP_OBJECT BitmapObj;
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlSuspend: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlSuspend: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Set flag to indicate a suspend is pending */
hTextSTPresCtrl->fSuspendPending = TRUE;
/* Send blank composition message in case presentation control task is waiting for a message */
OS_MsgQSend(hTextSTPresCtrl->CompMsgQID, (char *)&pCompInfo, sizeof(TEXTST_COMPOSITION_INFO *), OS_NO_WAIT, OS_MSG_PRI_NORMAL);
/* Send blank bitmap object message in case presentation control task is waiting for a message */
BitmapObj.fValid = FALSE;
OS_MsgQSend(hTextSTPresCtrl->BmpMsgQID, (char *)&BitmapObj, sizeof(TEXTST_BITMAP_OBJECT), OS_NO_WAIT, OS_MSG_PRI_NORMAL);
/* Release thread from waiting for PTS */
OS_SemGive(hTextSTPresCtrl->semPresentation);
/* Wait until presentation controller is suspended */
OS_SemTake(hTextSTPresCtrl->semSynch, OS_WAIT_FOREVER);
/* Clear the suspend pending flag */
hTextSTPresCtrl->fSuspendPending = FALSE;
return (TEXTST_SUCCESS);
}
/**
* TextSTPresCtrlResume -- Resume the TextST Presentation Controller
*
* @param
* none
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS TextSTPresCtrlResume(void)
{
DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlResume: Enter\n"));
if (hTextSTPresCtrl == NULL)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlResume: TextST Presentation Controller not created!\n"));
return (TEXTST_FAILURE);
}
/* Reset presentation semaphore */
OS_SemTake(hTextSTPresCtrl->semPresentation, OS_NO_WAIT);
/* Force the presentation controller task to stop wait */
OS_SemGive(hTextSTPresCtrl->semSuspend);
return (TEXTST_SUCCESS);
}
//////////////////////////////////////////////////////////////////////////////////
// Private Functions
//
/**
* textstpresctrlDisplayDPS -- Display the current dps.
*
* @param
* pBmpObj -- pointer to bitmap object of DPS to display
* pCompInfo -- pointer to composition info of DPS to display
*
* @retval
* TEXTST_STATUS
*/
TEXTST_STATUS textstpresctrlDisplayDPS(TEXTST_BITMAP_OBJECT *pBmpObj, TEXTST_COMPOSITION_INFO *pCompInfo)
{
UBYTE ubRegionID;
ULONG ulXcoord;
ULONG ulYcoord;
DBGPRINT(DBG_ON(DBG_TRACE), ("textstpresctrlDisplayDPS: Enter\n"));
if ( (pBmpObj == NULL) || (pCompInfo == NULL) )
{
DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlDisplayDPS: NULL pointer!\n"));
return (TEXTST_FAILURE);
}
/* Set drawing color to clear */
if (hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface->SetColorIndex(hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface, 0Xff) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlDisplayDPS: Failed to set color index!\n"));
return (TEXTST_FAILURE);
}
/*
* Clear the primary surface
*/
if (hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface->FillRectangle(hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface, 0, 0,
hTextSTPresCtrl->hTextST->DFBInfo.ScreenWidth, hTextSTPresCtrl->hTextST->DFBInfo.ScreenHeight) != DFB_OK)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlDisplayDPS: Failed to clear surface!\n"));
return (TEXTST_FAILURE);
}
for (int i = 0; i < pBmpObj->ubNumberOfRegions; i++)
{
/* Get region syle id to use */
ubRegionID = pCompInfo->region_style_id_ref[i];
/* Set coordinate of where to blit text image to */
ulXcoord = hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].region_info.region_horizontal_position;
ulYcoord = hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].region_info.region_vertical_position;
if (hTextSTPresCtrl->hTextST->pDSS->number_of_user_styles > 0)
{
/* adjust horizontal coordinates based on user style selected */
if (hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_horizontal_position_diretion == 0)
{
// right
ulXcoord += hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_horizontal_position_delta;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -