📄 g2d.c
字号:
// cf. SRC window coordinate
//
// (usSrcX1, usSrcY1) (usSrcX2, usSrcY1)
// *---------------------------------*
// | |
// | |
// | Window |
// | |
// | |
// *---------------------------------*
// (usSrcX1, usSrcY2) (usSrcX2, usSrcY2)
void G2D_GetRotationOrgXY(u16 usSrcX1, u16 usSrcY1, u16 usSrcX2, u16 usSrcY2, u16 usDestX1, u16 usDestY1,
ROT_DEG eRotDegree, u16* usOrgX, u16* usOrgY)
{
G2D_CheckFifo(17);
switch(eRotDegree)
{
case ROT_0:
return;
case ROT_90:
*usOrgX = (usDestX1 - usDestY1 + usSrcX1 + usSrcY2)/2;
*usOrgY = (usDestX1 + usDestY1 - usSrcX1 + usSrcY2)/2;
break;
case ROT_180:
*usOrgX = (usDestX1 + usSrcX2)/2;
*usOrgY = (usDestY1 + usSrcY2)/2;
break;
case ROT_270:
*usOrgX = (usDestX1 + usDestY1 + usSrcX2 - usSrcY1)/2;
*usOrgY = (usDestY1 - usDestX1 + usSrcX2 + usSrcY1)/2;
break;
default:
Assert(0); // UnSupported Rotation Degree!
break;
}
}
void G2D_RotateImage(
u16 usSrcX1, u16 usSrcY1, u16 usSrcX2, u16 usSrcY2,
u16 usDestX1, u16 usDestY1, ROT_DEG eRotDegree)
{
u16 usOrgX, usOrgY;
u32 uRotDegree;
G2D_GetRotationOrgXY(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usDestX1, usDestY1, eRotDegree, &usOrgX, &usOrgY);
G2D_CheckFifo(17);
Outp16(rG2D_ROT_OC_X, usOrgX);
Outp16(rG2D_ROT_OC_Y, usOrgY);
uRotDegree =
(eRotDegree == ROT_0) ? G2D_ROTATION_0_DEG_BIT :
(eRotDegree == ROT_90) ? G2D_ROTATION_90_DEG_BIT :
(eRotDegree == ROT_180) ? G2D_ROTATION_180_DEG_BIT : G2D_ROTATION_270_DEG_BIT;
Outp32(rG2D_ROT_MODE, uRotDegree);
}
void G2D_RotateWithBitBlt(
u16 usSrcX1, u16 usSrcY1, u16 usSrcX2, u16 usSrcY2,
u16 usDestX1, u16 usDestY1, ROT_DEG eRotDegree)
{
u16 usOrgX, usOrgY;
u32 uRotDegree;
G2D_GetRotationOrgXY(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usDestX1, usDestY1, eRotDegree, &usOrgX, &usOrgY);
G2D_CheckFifo(17);
Outp16(rG2D_ROT_OC_X, usOrgX);
Outp16(rG2D_ROT_OC_Y, usOrgY);
uRotDegree =
(eRotDegree == ROT_0) ? G2D_ROTATION_0_DEG_BIT :
(eRotDegree == ROT_90) ? G2D_ROTATION_90_DEG_BIT :
(eRotDegree == ROT_180) ? G2D_ROTATION_180_DEG_BIT : G2D_ROTATION_270_DEG_BIT ;
Outp32(rG2D_ROT_MODE, uRotDegree);
G2D_BitBlt(usSrcX1, usSrcY1, usSrcX2, usSrcY2, usSrcX1, usSrcY1, usSrcX2, usSrcY2, false);
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void G2D_SetTransparentMode1(bool bIsTransparent, u32 uBsColor)
{
u32 uRopRegVal;
G2D_CheckFifo(17);
uRopRegVal=Inp32(rG2D_ROP);
uRopRegVal =
(bIsTransparent == 1) ? (uRopRegVal | G2D_TRANSPARENT_BIT) : (uRopRegVal & ~(G2D_TRANSPARENT_BIT));
Outp32(rG2D_ROP, uRopRegVal);
// register Blue Screen Color
Outp32(rG2D_BS_COLOR, uBsColor);
}
void G2D_SetTransparentMode(bool bIsTransparent, G2D_COLOR eBsColor)
{
G2D_SetTransparentMode1(bIsTransparent, oG2d.m_uColorVal[eBsColor]);
}
// if ucTransMode is '1', Transparent Mode
// else '0', Opaque Mode
void G2D_SetColorKeyOn1(u32 uBsColor)
{
G2D_CheckFifo(17);
Outp32(rG2D_ROP, Inp32(rG2D_ROP) | G2D_TRANSPARENT_BIT);
// register Blue Screen Color
Outp32(rG2D_BS_COLOR, uBsColor);
}
void G2D_SetColorKeyOn(G2D_COLOR eBsColor)
{
G2D_SetColorKeyOn1(oG2d.m_uColorVal[eBsColor]);
}
void G2D_SetColorKeyOff(void)
{
G2D_CheckFifo(17);
// Blue screen off
Outp32(rG2D_ROP, Inp32(rG2D_ROP) & ~(G2D_TRANSPARENT_BIT));
// color key off
Outp32(rG2D_COLORKEY_CNTL, (Inp32(rG2D_COLORKEY_CNTL) &= ~(0x1U<<31)));
}
void G2D_SetPatternOffsetX(u8 ucPatOffsetX)
{
ucPatOffsetX &= 0x7; // ucPatOffsetX[2:0]
G2D_CheckFifo(17);
Outp32(rG2D_PAT_OFF_X, ucPatOffsetX);
}
void G2D_SetPatternOffsetY(u8 ucPatOffsetY)
{
ucPatOffsetY &= 0x7; // ucPatOffsetY[2:0]
G2D_CheckFifo(17);
Outp32(rG2D_PAT_OFF_Y, ucPatOffsetY);
}
void G2D_SetFgEcolor(G2D_COLOR eFgColor)
{
G2D_SetFgColor(oG2d.m_uColorVal[eFgColor]);
}
void G2D_SetFgColor(u32 uFgColor)
{
uFgColor &= 0x00ffffff;
Outp32(rG2D_FG_COLOR, uFgColor);
}
void G2D_SetBgEcolor(G2D_COLOR eBgColor)
{
G2D_SetBgColor(oG2d.m_uColorVal[eBgColor]);
}
void G2D_SetBgColor(u32 uBgColor)
{
uBgColor &= 0x00ffffff;
Outp32(rG2D_BG_COLOR, uBgColor);
}
// if bIsTransparent == 1, Transparent Mode and uBgColor isn't applied
// else if bIsTransparent ==0, Opaque Mode
void G2D_SetFontColor1(u32 uFontColor, u32 uBgColor, bool bIsTransparent)
{
u32 uRopRegVal;
G2D_CheckFifo(17);
uRopRegVal=Inp32(rG2D_ROP);
uRopRegVal =
(bIsTransparent == 1) ? (uRopRegVal | G2D_TRANSPARENT_BIT) : (uRopRegVal & ~(G2D_TRANSPARENT_BIT));
Outp32(rG2D_ROP, uRopRegVal);
Outp32(rG2D_FG_COLOR, uFontColor);
Outp32(rG2D_BG_COLOR, uBgColor);
}
void G2D_SetFontColor(G2D_COLOR eFontColor, G2D_COLOR eBgColor, bool bIsTransparent)
{
G2D_SetFontColor1(oG2d.m_uColorVal[eFontColor], oG2d.m_uColorVal[eBgColor], bIsTransparent);
}
void G2D_PutString(u32 uPosX, u32 uPosY, char* cStr)
{
u8* ucOneLetter;
u32 uHostData = 0x0;
u32 uTempData = 0x0;
int i, j, k;
u32 uPosX2, uPosY2;
u32 uFontOffset;
u32 uAddressOffset;
// Only support 8X15 font size
// All font size will be implemented, but now only support 8X15 font size
if(oG2d.m_bIsBitBlt==true) printf("Host to screen BitBLT!\n");
if(oG2d.m_uFontWidth==8 && oG2d.m_uFontHeight==8)
uFontOffset = 8;
else if(oG2d.m_uFontWidth==8 && oG2d.m_uFontHeight==15)
uFontOffset = 15;
else if(oG2d.m_uFontWidth==8 && oG2d.m_uFontHeight==16)
uFontOffset = 16;
uPosX2 = uPosX + oG2d.m_uFontWidth - 1;
uPosY2 = uPosY + oG2d.m_uFontHeight - 1;
G2D_CheckFifo(17);
for (i=0; i<strlen(cStr); i++)
{
if (oG2d.m_bIsBitBlt == true)
{
Outp32(rG2D_COORD2_X, uPosX); // COORD_0: LeftTop
Outp32(rG2D_COORD2_Y, uPosY);
Outp32(rG2D_COORD3_X, uPosX2); // COORD_1: RightBottom
Outp32(rG2D_COORD3_Y, uPosY2);
//printf("HS BitBLT!\n");
}
if (oG2d.m_bIsBitBlt == false)
{
Outp32(rG2D_COORD0_X, uPosX); // COORD_0: LeftTop
Outp32(rG2D_COORD0_Y, uPosY);
Outp32(rG2D_COORD1_X, uPosX2); // COORD_1: RightBottom
Outp32(rG2D_COORD1_Y, uPosY2);
}
//ucOneLetter = oG2d.m_upFontType + (cStr[i]-START_ASCII)*15; // get start address of chosen letter in font8x15
ucOneLetter = oG2d.m_upFontType + (cStr[i]-START_ASCII)*uFontOffset; // get start address of chosen letter in font8x15
uHostData = uTempData = 0;
for (j=0; j<4; j++) // Generate of first 1 word of data for a font (start)
{
uTempData = (u32)ucOneLetter[j];
uHostData |= (uTempData << (24 - 8*j));
}
if (oG2d.m_bIsScr2Scr==1 && oG2d.m_bIsBitBlt ==0) {
uAddressOffset=((oG2d.m_uFontWidth/8*oG2d.m_uFontHeight+3)/4)*4;
G2D_SetCMDR7(oG2d.m_uFontAddr+(cStr[i]-START_ASCII)*uAddressOffset);
}
else if (oG2d.m_bIsBitBlt) {
Outp32(rG2D_CMDR2, uHostData);
while(!bG2dDone);
bG2dDone=0;
}
else {
Outp32(rG2D_CMDR4, uHostData); // Set New font
while(!bG2dDone);
bG2dDone=0;
}
// for(k=0; k<3; k++) // Generate next 3 word of data for the font (continue)
for(k=0; k<((uFontOffset-4+3)/4); k++) // Generate next n word of data for the font (continue)
{
uHostData = uTempData = 0;
for (j=0+4*(k+1); j<4+4*(k+1); j++) // Upto font height(height: 15)
{
uTempData = (u32)ucOneLetter[j];
uHostData |= (uTempData<< (24 - 8*(j%4)));
}
if (oG2d.m_bIsScr2Scr==1 && oG2d.m_bIsBitBlt ==0) break;
else if (oG2d.m_bIsBitBlt) {
Outp32(rG2D_CMDR3, uHostData);
while(!bG2dDone);
bG2dDone=0;
}
else {
Outp32(rG2D_CMDR5, uHostData);
while(!bG2dDone);
bG2dDone=0;
}
}
uPosX = uPosX2; // Set left top X coordinate of next letter
uPosX2 = uPosX + oG2d.m_uFontWidth - 1; // Set rigth bottom X coordiante of next letter
}
}
// If bIsHost == 0, Host to screen text drawing
// else if bIsHost == 1, Memory to screen text drawing
void G2D_Printf(u32 uPosX, u32 uPosY, const char* cpFmt, ...)
{
va_list eAp;
char cString[256];
va_start(eAp, cpFmt);
vsprintf(cString, cpFmt, eAp);
G2D_PutString(uPosX, uPosY, cString);
va_end(eAp);
}
//Inserted or Modified by Boaz.kim//
void G2D_Init(void) // Adding
{
u32 uLcdWidth, uLcdHeight;
CSPACE eBgBpp;
LCD_WINDOW eBgWin;
u32 uLcdFbAddr;
eBgWin=WIN0;
eBgBpp=RGB24;
uLcdFbAddr = _DRAM_BaseAddress+0x04000000;
#if (LCD_MODULE_TYPE== LTV350QV_RGB)
printf("Selected LCD Module Type: LTV350QV_RGB\n");
uLcdWidth=320;
uLcdHeight=240;
#elif (LCD_MODULE_TYPE == LTS222QV_CPU)
printf("Selected LCD Module Type: LTS222QV_CPU\n");
uLcdWidth=240;
uLcdHeight=320;
#elif (LCD_MODULE_TYPE == LTP700WV_RGB)
printf("Selected LCD Module Type: LTP700WV_RGB\n");
uLcdWidth=800;
uLcdHeight=480;
#elif (LCD_MODULE_TYPE == LTE480WV_RGB)
printf("Selected LCD Module Type: LTE480WV_RGB\n");
uLcdWidth=800;
uLcdHeight=480;
#else
Assert(0);
#endif
LCD_SetPort();
LCD_InitLDI(MAIN);
LCD_SetPort();
LCD_InitLDI(MAIN);
LCD_InitBase();
LCD_InitWin(eBgBpp, uLcdWidth, uLcdHeight, 0, 0, uLcdWidth, uLcdHeight, 0, 0, uLcdFbAddr, eBgWin, false);
LCD_SetWinOnOff(1, eBgWin);
LCD_GetFrmSz(&uLcdWidth, &uLcdHeight, eBgWin);
GLIB_InitInstance(uLcdFbAddr, uLcdWidth, uLcdHeight, eBgBpp);
GLIB_DrawPattern(uLcdWidth, uLcdHeight);
GLIB_PutLine(0, 0, 0, uLcdHeight-1, C_BLUE);
LCD_Start();
printf("lcdwidht=%d, lcdheight=%d\n", uLcdWidth, uLcdHeight);
G2D_InitSetting(uLcdFbAddr, eBgBpp, uLcdWidth, uLcdHeight, 0, 0, uLcdWidth, uLcdHeight);
}
void G2D_InitSetting(u32 uFbStAddr, CSPACE eBpp, u32 uCwMaxHSz, u32 uCwMaxVSz,
u32 uX1_Cw, u32 uY1_Cw, u32 uX2_Cw, u32 uY2_Cw) // modification
{
Assert(uCwMaxHSz <= 2048); // Max horizontal size of clipping window should be 2048.
Assert(uCwMaxVSz <= 2048); // Max vertical size of clipping window should be 2048.
// Initialize color
switch(eBpp) {
case ARGB8: // 15-bpp, The name of ARGB8 should be changed to proper name.
oG2d.m_uColorVal[G2D_BLACK] = 0x0;
oG2d.m_uColorVal[G2D_RED] = (0x1f<<10);
oG2d.m_uColorVal[G2D_GREEN] =(0x1f<<5);
oG2d.m_uColorVal[G2D_BLUE] =(0x1f<<0);
oG2d.m_uColorVal[G2D_WHITE] =0x7fff;
break;
case RGB16:
oG2d.m_uColorVal[G2D_BLACK] = 0x0;
oG2d.m_uColorVal[G2D_RED] = 0x1f<<11;
oG2d.m_uColorVal[G2D_GREEN] = 0x3f<<5;
oG2d.m_uColorVal[G2D_BLUE] = 0x1f<<0;
oG2d.m_uColorVal[G2D_WHITE] = 0xffff;
break;
case RGB18:
oG2d.m_uColorVal[G2D_BLACK] = 0x0;
oG2d.m_uColorVal[G2D_RED] = 0x3f<<12;
oG2d.m_uColorVal[G2D_GREEN] = 0x3f<<6;
oG2d.m_uColorVal[G2D_BLUE] = 0x3f<<0;
oG2d.m_uColorVal[G2D_WHITE] = 0xffff;
break;
case RGB24:
oG2d.m_uColorVal[G2D_BLACK] = 0x0;
oG2d.m_uColorVal[G2D_RED] = 0xff0000;
oG2d.m_uColorVal[G2D_GREEN] = 0xff00;
oG2d.m_uColorVal[G2D_BLUE] = 0xff;
oG2d.m_uColorVal[G2D_WHITE] = 0xffffff;
break;
default:
oG2d.m_uColorVal[G2D_BLACK] = 0x0;
oG2d.m_uColorVal[G2D_RED] = 0x1f<<11;
oG2d.m_uColorVal[G2D_GREEN] = 0x3f<<5;
oG2d.m_uColorVal[G2D_BLUE] = 0x1f<<0;
oG2d.m_uColorVal[G2D_WHITE] = 0xffff;
break;
}
oG2d.m_uFbStAddr = uFbStAddr;
oG2d.m_uColorVal[G2D_YELLOW] = (oG2d.m_uColorVal[G2D_RED] | oG2d.m_uColorVal[G2D_GREEN]);
oG2d.m_uColorVal[G2D_CYAN] = (oG2d.m_uColorVal[G2D_GREEN] | oG2d.m_uColorVal[G2D_BLUE]);
oG2d.m_uColorVal[G2D_MAGENTA] = (oG2d.m_uColorVal[G2D_RED] | oG2d.m_uColorVal[G2D_BLUE]);
oG2d.m_uHoriRes = uCwMaxHSz;
oG2d.m_uMaxDx = uCwMaxHSz - 1;
oG2d.m_uMaxDy = uCwMaxVSz - 1;
oG2d.m_uCwX1 = uX1_Cw;
oG2d.m_uCwY1 = uY1_Cw;
oG2d.m_uCwX2 = uX2_Cw - 1;
oG2d.m_uCwY2 = uY2_Cw - 1;
oG2d.m_uBytes = (eBpp == RGB24) ? 4 : 2;
oG2d.m_upFontType = (u8 *)font8x15;
oG2d.m_uFontWidth = 8;
oG2d.m_uFontHeight = 15;
oG2d.m_eBpp = eBpp;
oG2d.m_bIsBitBlt = false;
// oG2d.m_bIsBitBlt = true;
oG2d.m_bIsScr2Scr = false;
oG2d.m_uFontAddr = (uFbStAddr&0xff000000)+0x800000;
G2D_DisableEffect(); // Disable per-pixel/per-plane alpha blending and fading
G2D_SetColorKeyOff();
G2D_InitRegs(eBpp);
}
void G2D_ClearFrameEcolor(G2D_COLOR eColor, u32 uPosX, u32 uPosY) // modification
{
G2D_ClearFrame(oG2d.m_uColorVal[eColor], uPosX, uPosY);
}
void G2D_ClearFrame(u32 uColor, u32 uPosX, u32 uPosY) //modification
{
int i;
u16 uTmpColor;
if(oG2d.m_uBytes == 2)
uTmpColor = uColor & 0xffff;
for (i=uPosX+(oG2d.m_uMaxDx+1)*uPosY; i<(oG2d.m_uMaxDx+1)*(oG2d.m_uMaxDy+1); i++)
{
if(oG2d.m_uBytes == 4) // RGB24
Outp32(oG2d.m_uFbStAddr+i*oG2d.m_uBytes, uColor);
else if(oG2d.m_uBytes == 2) // RGB16
Outp16(oG2d.m_uFbStAddr+i*oG2d.m_uBytes, uTmpColor);
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -