📄 g2d_test.c
字号:
G2D_SetRotationMode(G2D_Y_FLIP);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1+20, uG2dHeight/2-1-20, uG2dWidth/2-1+40, uG2dHeight/2-1, G2D_MAGENTA,1);
printf("Y-FLIP, press any key to exit\n");
Uart_getc();
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
void TestLineDrawingWithBlending(void)
{
u32 i;
u32 uG2dFbAddr, uG2dWidth, uG2dHeight;
int32 sAlphaVal;
CSPACE eBpp;
#ifdef INTERRUPT_MODE
pISR_2D=(unsigned)Isr_G2d;
rINTMSK2 &=~(BIT_2D);
G2D_InterruptEnable();
#endif
uG2dWidth=lcd_horizon_value;
uG2dHeight=lcd_line_value;
uG2dFbAddr=LCD_FRAME_BUFFER;
#if BPP_Mode==RGB16_Mode
eBpp=RGB16;
#elif BPP_Mode==RGB24_Mode
eBpp=RGB24;
#endif
printf("Width=%d, Height=%d, Framebuffer:0x%x\n", uG2dWidth, uG2dHeight, uG2dFbAddr);
printf("press any key to test alpha blending.\n");
G2D_ClearFrameEcolor(G2D_YELLOW, 0, 0);
Uart_getc();
G2D_SetAlphaMode(G2D_ALPHA_MODE);
G2D_SetAlphaValue(0xff);
for(i=0; i<uG2dHeight; i++)
if((i%4)==0)
G2D_PutLineEcolor(0,i,uG2dWidth-1,i,G2D_BLUE,1);
for(i=0; i<uG2dWidth; i++)
if((i%4)==0)
G2D_PutLineEcolor(i,0,i,uG2dHeight-1,G2D_BLUE,1);
sAlphaVal=255;
while(1) {
sAlphaVal -= 8;
if(sAlphaVal<=0) sAlphaVal=0;
G2D_SetAlphaValue((u8)sAlphaVal);
G2D_ClearFrameEcolor(G2D_YELLOW, 0, 0);
for(i=0; i<uG2dHeight; i++)
if((i%4)==0)
G2D_PutLineEcolor(0,i,uG2dWidth-1,i,G2D_BLUE,1);
for(i=0; i<uG2dWidth; i++)
if((i%4)==0)
G2D_PutLineEcolor(i,0,i,uG2dHeight-1,G2D_BLUE,1);
printf("Alpha:%d\n", sAlphaVal);
if(sAlphaVal==0) break;
// Uart_getc();
}
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
void TestLineDrawingClipping(void)
{
u32 uG2dFbAddr, uG2dWidth, uG2dHeight;
u32 uDec;
CSPACE eBpp;
#ifdef INTERRUPT_MODE
pISR_2D=(unsigned)Isr_G2d;
rINTMSK2 &=~(BIT_2D);
G2D_InterruptEnable();
#endif
uG2dWidth=lcd_horizon_value;
uG2dHeight=lcd_line_value;
uG2dFbAddr=LCD_FRAME_BUFFER;
#if BPP_Mode==RGB16_Mode
eBpp=RGB16;
#elif BPP_Mode==RGB24_Mode
eBpp=RGB24;
#endif
printf("Width=%d, Height=%d, Framebuffer:0x%x\n", uG2dWidth, uG2dHeight, uG2dFbAddr);
G2D_ClearFrameEcolor(G2D_BLACK, 0, 0);
printf("Simple Line Drawing, press any key to continue\n");
Uart_getc();
G2D_PutLineEcolor(0,0,uG2dWidth-1, 0, G2D_WHITE, 1);
G2D_PutLineEcolor(0,0,0, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(uG2dWidth-1,0,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,uG2dHeight-1,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,0,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,uG2dHeight-1,uG2dWidth-1, 0, G2D_WHITE, 1);
printf("Lines are displayed, press any key to test window clipping\n");
Uart_getc();
uDec=0;
while(1){
uDec+=8;
if((uG2dWidth-2*uDec <=32)||(uG2dHeight-2*uDec <=32)) break;
G2D_ClearFrameEcolor(G2D_BLACK, 0, 0);
G2D_SetClippingWindow(0+uDec, 0+uDec, uG2dWidth-uDec, uG2dHeight-uDec);
printf("[Clipping]x1=%d,y1=%d,x2=%d,y2=%d\n",uG2dWidth-uDec, uG2dHeight-uDec, uG2dWidth-uDec, uG2dHeight-uDec);
G2D_PutLineEcolor(0,0,uG2dWidth-1, 0, G2D_WHITE, 1);
G2D_PutLineEcolor(0,0,0, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(uG2dWidth-1,0,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,uG2dHeight-1,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,0,uG2dWidth-1, uG2dHeight-1, G2D_WHITE, 1);
G2D_PutLineEcolor(0,uG2dHeight-1,uG2dWidth-1, 0, G2D_WHITE, 1);
// Uart_getc();
}
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
void TestLineDrawingWithAll(void)
{
u32 uG2dFbAddr, uG2dWidth, uG2dHeight;
CSPACE eBpp;
#ifdef INTERRUPT_MODE
pISR_2D=(unsigned)Isr_G2d;
rINTMSK2 &=~(BIT_2D);
G2D_InterruptEnable();
#endif
uG2dWidth=lcd_horizon_value;
uG2dHeight=lcd_line_value;
uG2dFbAddr=LCD_FRAME_BUFFER;
#if BPP_Mode==RGB16_Mode
eBpp=RGB16;
#elif BPP_Mode==RGB24_Mode
eBpp=RGB24;
#endif
printf("Width=%d, Height=%d, Framebuffer:0x%x\n", uG2dWidth, uG2dHeight, uG2dFbAddr);
printf("Point Drawing with All Operations, press any key to test.\n");
G2D_ClearFrameEcolor(G2D_YELLOW, 0, 0);
G2D_RegisterPattern(pat8x8_rgbw);
Uart_getc();
G2D_SetAlphaMode(G2D_ALPHA_MODE);
G2D_SetAlphaValue(0xcf);
G2D_SetClippingWindow(uG2dWidth/4, uG2dHeight/4,uG2dWidth*3/4, uG2dHeight*3/4);
G2D_Set3rdOperand(G2D_OPERAND3_PAT);
G2D_SetRopEtype(ROP_SRC_XOR_3RD_OPRND);
G2D_PutLineEcolor(0,uG2dHeight/2-1,uG2dWidth-1, uG2dHeight/2-1, G2D_BLACK, 1);
G2D_PutLineEcolor(uG2dWidth/2-1,0, uG2dWidth/2-1, uG2dHeight-1,G2D_BLACK, 1);
G2D_PutLineEcolor(0,0,uG2dWidth-1, 0, G2D_BLACK, 1);
G2D_PutLineEcolor(0,0,0, uG2dHeight-1, G2D_BLACK, 1);
G2D_PutLineEcolor(uG2dWidth-1,0,uG2dWidth-1, uG2dHeight-1, G2D_BLACK, 1);
G2D_PutLineEcolor(0,uG2dHeight-1,uG2dWidth-1, uG2dHeight-1, G2D_BLACK, 1);
G2D_SetRotationMode(G2D_ROTATION_0_DEG_BIT);
G2D_PutLineEcolor(uG2dWidth/2-1, uG2dHeight/2-1, uG2dWidth/2-1+20, uG2dHeight/2-1-20, G2D_BLACK,1);
G2D_SetRotationMode(G2D_ROTATION_90_DEG_BIT);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1, uG2dHeight/2-1, uG2dWidth/2-1+20, uG2dHeight/2-1-20, G2D_RED,1);
G2D_SetRotationMode(G2D_ROTATION_180_DEG_BIT);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1, uG2dHeight/2-1, uG2dWidth/2-1+20, uG2dHeight/2-1-20, G2D_GREEN,1);
G2D_SetRotationMode(G2D_ROTATION_270_DEG_BIT);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1, uG2dHeight/2-1, uG2dWidth/2-1+20, uG2dHeight/2-1-20, G2D_BLUE,1);
G2D_SetRotationMode(G2D_ROTATION_0_DEG_BIT);
G2D_PutLineEcolor(uG2dWidth/2-1+20, uG2dHeight/2-1-20, uG2dWidth/2-1+40, uG2dHeight/2-1, G2D_BLACK,1);
G2D_SetRotationMode(G2D_X_FLIP);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1+20, uG2dHeight/2-1-20, uG2dWidth/2-1+40, uG2dHeight/2-1, G2D_CYAN,1);
G2D_SetRotationMode(G2D_Y_FLIP);
G2D_SetRotationOrg((u16)(uG2dWidth/2-1), (u16)(uG2dHeight/2-1));
G2D_PutLineEcolor(uG2dWidth/2-1+20, uG2dHeight/2-1-20, uG2dWidth/2-1+40, uG2dHeight/2-1, G2D_MAGENTA,1);
printf("Press any key to exit!\n");
Uart_getc();
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
void TestLineDrawingLastPixel(void)
{
u32 uG2dFbAddr, uG2dWidth, uG2dHeight;
bool IsDrawLastPoint;
CSPACE eBpp;
#ifdef INTERRUPT_MODE
pISR_2D=(unsigned)Isr_G2d;
rINTMSK2 &=~(BIT_2D);
G2D_InterruptEnable();
#endif
uG2dWidth=lcd_horizon_value;
uG2dHeight=lcd_line_value;
uG2dFbAddr=LCD_FRAME_BUFFER;
#if BPP_Mode==RGB16_Mode
eBpp=RGB16;
#elif BPP_Mode==RGB24_Mode
eBpp=RGB24;
#endif
printf("Width=%d, Height=%d, Framebuffer:0x%x\n", uG2dWidth, uG2dHeight, uG2dFbAddr);
G2D_ClearFrameEcolor(G2D_BLACK, 0, 0);
G2D_PutLineEcolor(uG2dWidth*3/4, 0, uG2dWidth*3/4, uG2dHeight-1, G2D_RED, 1);
printf("Line Drawing with Draw Last Point, press any key to continue\n");
Uart_getc();
IsDrawLastPoint=1;
G2D_PutLineEcolor(0, uG2dHeight/4,uG2dWidth*3/4, uG2dHeight/4, G2D_BLUE, IsDrawLastPoint);
printf("Line Drawing with Do Not Draw Last Point, press any key to continue\n");
Uart_getc();
IsDrawLastPoint=0;
G2D_PutLineEcolor(0, uG2dHeight*3/4,uG2dWidth*3/4, uG2dHeight*3/4, G2D_BLUE, IsDrawLastPoint);
printf("Press any key to exit!\n");
Uart_getc();
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
void TestColorExpansionSimple(void)
{
u32 uG2dFbAddr, uG2dWidth, uG2dHeight;
u32 uFontWidth, uFontHeight;
u32 uTextDrawingFbAddr;
CSPACE eBpp;
bool bIsTransparent=1;
#ifdef INTERRUPT_MODE
pISR_2D=(unsigned)Isr_G2d;
rINTMSK2 &=~(BIT_2D);
G2D_InterruptEnable();
#endif
uG2dWidth=lcd_horizon_value;
uG2dHeight=lcd_line_value;
uG2dFbAddr=LCD_FRAME_BUFFER;
#if BPP_Mode==RGB16_Mode
eBpp=RGB16;
#elif BPP_Mode==RGB24_Mode
eBpp=RGB24;
#endif
printf("Width=%d, Height=%d, Framebuffer:0x%x\n", uG2dWidth, uG2dHeight, uG2dFbAddr);
// Host to Screen Test
printf("Simple Host to Screen Color Expansion, press any key to continue");
G2D_ClearFrameEcolor(G2D_BLACK, 0, 0);
Uart_getc();
G2D_SetColorExpansionMethod(HOST2SCREEN);
G2D_SetFontColor(G2D_RED, G2D_BLACK, bIsTransparent);
G2D_SetFontType(FONT8BY8, &uFontWidth, &uFontHeight);
G2D_Printf(5, 5, "[2D]H2S Color Expansion");
printf("8x8 font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_GREEN, G2D_BLACK, bIsTransparent);
G2D_SetFontType(FONT8BY15, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*1/4+5, "[2D]H2S Color Expansion");
printf("8x15 font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_BLUE, G2D_BLACK, bIsTransparent);
G2D_SetFontType(FONT8BY16T, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*2/4+5, "[2D]H2S Color Expansion");
printf("8x16T font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_WHITE, G2D_BLACK, bIsTransparent);
G2D_SetFontType(FONT8BY16, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*3/4+5, "[2D]H2S Color Expansion");
printf("8x16 font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
// Screen to Screen Test
printf("Simple Screen to Screen Color Expansion, press any key to continue");
G2D_ClearFrameEcolor(G2D_BLACK, 0, 0);
Uart_getc();
uTextDrawingFbAddr=(uG2dFbAddr&0xff000000)+0x800000;
G2D_SetColorExpansionMethod(SCREEN2SCREEN);
G2D_SetFontAddr(uTextDrawingFbAddr);
G2D_SetFontColor(G2D_RED, G2D_BLACK, bIsTransparent);
G2D_FillMemoryForTextDrawing(FONT8BY8, uTextDrawingFbAddr);
G2D_SetFontType(FONT8BY8, &uFontWidth, &uFontHeight);
G2D_Printf(5, 5, "[2D]S2S Color Expansion");
printf("8x8 font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_GREEN, G2D_BLACK, bIsTransparent);
G2D_FillMemoryForTextDrawing(FONT8BY15, uTextDrawingFbAddr);
G2D_SetFontType(FONT8BY15, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*1/4+5, "[2D]S2S Color Expansion");
printf("8x15 font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_BLUE, G2D_BLACK, bIsTransparent);
G2D_FillMemoryForTextDrawing(FONT8BY16T, uTextDrawingFbAddr);
G2D_SetFontType(FONT8BY16T, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*2/4+5, "[2D]S2S Color Expansion");
printf("8x16T font is dispayed using color expansion, press any key to continue.\n");
Uart_getc();
G2D_SetFontColor(G2D_WHITE, G2D_BLACK, bIsTransparent);
G2D_FillMemoryForTextDrawing(FONT8BY16, uTextDrawingFbAddr);
G2D_SetFontType(FONT8BY16, &uFontWidth, &uFontHeight);
G2D_Printf(5, uG2dHeight*3/4+5, "[2D]S2S Color Expansion");
printf("8x16 font is dispayed using color expansion, press any key to exit.\n");
Uart_getc();
#ifdef INTERRUPT_MODE
G2D_InterruptDisable();
// INTC_Disable(BIT_2D);
#endif
G2D_InitSetting(uG2dFbAddr, eBpp, uG2dWidth, uG2dHeight, 0, 0, uG2dWidth, uG2dHeight);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -