📄 func.c
字号:
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
/*显示bmp格式图片*/
void Paint_Bmp(U32 x0,U32 y0,unsigned char bmp[])
{
U32 x,y;
U32 c;
U32 i = 0;
U8* bmpData;
BMP_Displayed=0;
bmfh.bfType=(bmp[1]<<8)|(bmp[0]);
bmfh.bfSize=(bmp[5]<<24)|(bmp[4]<<16)|(bmp[3]<<8)|(bmp[2]);
bmfh.bfReserved=0;
bmfh.bfOffBits=(bmp[13]<<24)|(bmp[12]<<16)|(bmp[11]<<8)|(bmp[10]);
bmih.biSize=(bmp[17]<<24)|(bmp[16]<<16)|(bmp[15]<<8)|(bmp[14]);
bmih.biWidth=(bmp[21]<<24)|(bmp[20]<<16)|(bmp[19]<<8)|(bmp[18]);
bmih.biHeight=(bmp[25]<<24)|(bmp[24]<<16)|(bmp[23]<<8)|(bmp[22]);
bmih.biPlanes=(bmp[27]<<8)|(bmp[26]);
bmih.biBitCount=(bmp[29]<<8)|(bmp[28]);
bmih.biCompression=(bmp[33]<<24)|(bmp[32]<<16)|(bmp[31]<<8)|(bmp[30]);
bmih.biSizeImage=(bmp[37]<<24)|(bmp[36]<<16)|(bmp[35]<<8)|(bmp[34]);
bmih.biXPelsPerMeter=(bmp[41]<<24)|(bmp[40]<<16)|(bmp[39]<<8)|(bmp[38]);
bmih.biYPelsPerMeter=(bmp[45]<<24)|(bmp[44]<<16)|(bmp[43]<<8)|(bmp[42]);
bmih.biClrUsed=(bmp[49]<<24)|(bmp[48]<<16)|(bmp[47]<<8)|(bmp[46]);
bmih.biClrImportant=(bmp[53]<<24)|(bmp[52]<<16)|(bmp[51]<<8)|(bmp[50]);
bmpData=&bmp[bmfh.bfOffBits];
if(bmfh.bfType==('B'<<8)|('M'))
{
if(bmih.biBitCount!=24)
{
Uart_Printf("Error:This BMP picture is not 24bpp true color format!\n");
return;
}
else if(bmih.biCompression)
{
Uart_Printf("Error:This BMP picture has been compressed!\n");
return;
}
else if((bmih.biWidth>SCR_xSIZE) && (bmih.biHeight>SCR_ySIZE))
{
Uart_Printf("Error:This BMP picture is bigger than 480*640!\n");
return;
}
else
{
//BMP图片小于LCD尺寸,将图片置于LCD中央
if((bmih.biWidth<=LCD_xSIZE) && (bmih.biHeight<=LCD_ySIZE))
{
Uart_Printf("This BMP picture is less than 240*320.\n");
for(y=0;y<(LCD_ySIZE-bmih.biHeight)/2;y++)
{
for(x=0;x<LCD_xSIZE;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
}
for(;y<((LCD_ySIZE-bmih.biHeight)/2+bmih.biHeight);y++)
{
for(x=0;x<(LCD_xSIZE-bmih.biWidth)/2;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
for(;x<((LCD_xSIZE-bmih.biWidth)/2+bmih.biWidth);x++)
{
c=(bmpData[i]<<16) | (bmpData[i+1]<<8) | (bmpData[i+2]);
if(((x0+x)<SCR_xSIZE) && ((y0+y)<SCR_ySIZE) )
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=(U16)((((c&0x0000ff)>>3)<<11)|(((c&0x00ff00)>>10)<<5)|(((c&0xff0000)>>16))>>3);
i=i+3;
}
i=i+(bmih.biWidth%4); // 因为BMP图片的每行数据是4字节对齐,所以需要跳过冗余数据
for(;x<SCR_xSIZE;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
}
for(;y<LCD_ySIZE;y++)
{
for(x=0;x<LCD_xSIZE;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
}
}
// BMP图片的宽度大于LCD宽度,而高度却小于LCD高度
else if((bmih.biWidth>LCD_xSIZE) && (bmih.biHeight<=LCD_ySIZE))
{
Uart_Printf("X-SIZETh of the BMP picture is bigger than 240,/nAnd Y-SIZE is less than 320.\n");
for(y=0;y<(LCD_ySIZE-bmih.biHeight)/2;y++)
{
for(x=0;x<bmih.biWidth;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
}
for(;y<((LCD_ySIZE-bmih.biHeight)/2+bmih.biHeight);y++)
{
for(x=0;x<(bmih.biWidth);x++)
{
c=(bmpData[i]<<16) | (bmpData[i+1]<<8) | (bmpData[i+2]);
if(((x0+x)<SCR_xSIZE) && ((y0+y)<SCR_ySIZE) )
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=(U16)((((c&0x0000ff)>>3)<<11)|(((c&0x00ff00)>>10)<<5)|(((c&0xff0000)>>16))>>3);
i=i+3;
}
i=i+(bmih.biWidth%4); // 因为BMP图片的每行数据是4字节对齐,所以需要跳过冗余数据
}
for(;y<LCD_ySIZE;y++)
{
for(x=0;x<bmih.biWidth;x++)
{
LCD_BUFFER[LCD_ySIZE-(y0+y)-1][x0+x]=0xffff;
}
}
}
// BMP图片的宽度小于LCD宽度,而高度却大于LCD高度
else if((bmih.biWidth<=LCD_xSIZE) && (bmih.biHeight>LCD_ySIZE))
{
Uart_Printf("X-SIZETh of the BMP picture is less than 240,/nAnd Y-SIZE is bigger than 320.\n");
for(y=0;y<bmih.biHeight;y++)
{
for(x=0;x<(LCD_xSIZE-bmih.biWidth)/2;x++)
{
LCD_BUFFER[bmih.biHeight-(y0+y)-1][x0+x]=0xffff;
}
for(;x<((LCD_xSIZE-bmih.biWidth)/2+bmih.biWidth);x++)
{
c=(bmpData[i]<<16) | (bmpData[i+1]<<8) | (bmpData[i+2]);
if(((x0+x)<SCR_xSIZE) && ((y0+y)<SCR_ySIZE) )
LCD_BUFFER[bmih.biHeight-(y0+y)-1][x0+x]=(U16)((((c&0x0000ff)>>3)<<11)|(((c&0x00ff00)>>10)<<5)|(((c&0xff0000)>>16))>>3);
i=i+3;
}
i=i+(bmih.biWidth%4); // 因为BMP图片的每行数据是4字节对齐,所以需要跳过冗余数据
for(;x<SCR_xSIZE;x++)
{
LCD_BUFFER[bmih.biHeight-(y0+y)-1][x0+x]=0xffff;
}
}
}
//BMP图片大于LCD尺寸
else
{
Uart_Printf("This BMP picture is bigger than 240*320.\n");
for(y=0;y<bmih.biHeight;y++)
{
for(x=0;x<(bmih.biWidth);x++)
{
c=(bmpData[i]<<16) | (bmpData[i+1]<<8) | (bmpData[i+2]);
if(((x0+x)<SCR_xSIZE) && ((y0+y)<SCR_ySIZE) )
LCD_BUFFER[bmih.biHeight-(y0+y)-1][x0+x]=(U16)((((c&0x0000ff)>>3)<<11)|(((c&0x00ff00)>>10)<<5)|(((c&0xff0000)>>16))>>3);
i=i+3;
}
i=i+(bmih.biWidth%4); // 因为BMP图片的每行数据是4字节对齐,所以需要跳过冗余数据
}
}
Uart_Printf("This BMP picture has been displayed.\n");
BMP_Displayed=1;
}
}
else
{
Uart_Printf("This picture is not BMP format!\n");
}
}
//移动LCD中画面显示位置
void MoveViewPort(void)
{
int vx=0;
int vy=0;
int step=10;
Uart_Printf("Please enter KEY to scrolled!\n d/D:Scroll down\n u/U:Scroll up\n r/R:Scroll right\n l/L:Scroll left\n");
while(1)
{
switch(Uart_Getch())
{
case 'd': //down
case 'D':
if(bmih.biHeight<=LCD_ySIZE)
{
Uart_Printf("This picture don't need to be UP/DOWN scrolled!\n");
break;
}
vy=vy+step;
if((vy+LCD_ySIZE)>=bmih.biHeight)
{
vy=bmih.biHeight-LCD_ySIZE;
}
break;
case 'u': //up
case 'U':
if(bmih.biHeight<=LCD_ySIZE)
{
Uart_Printf("This picture don't need to be UP/DOWN scrolled!\n");
break;
}
vy=vy-step;
if(vy<=0)
{
vy=0;
}
break;
case 'r': //right
case 'R':
if(bmih.biWidth<=LCD_xSIZE)
{
Uart_Printf("This picture don't need to be LEFT/RIGHT scrolled!\n");
break;
}
vx=vx+step;
if((vx+LCD_xSIZE)>=bmih.biWidth)
{
vx=bmih.biWidth-LCD_xSIZE;
}
break;
case 'l': //left
case 'L':
if(bmih.biWidth<=LCD_xSIZE)
{
Uart_Printf("This picture don't need to be LEFT/RIGHT scrolled!\n");
break;
}
vx=vx-step;
if(vx<0)
{
vx=0;
}
break;
break;
case 'q':
case 'Q':
vLCDBASEU=(((U32)LCD_BUFFER&0x3fffff))>>1;
vLCDBASEL=(U32)vLCDBASEU+(PAGEWIDTH+OFFSIZE)*(LINEVAL+1);
while((rLCDCON1>>18)==0);
rLCDSADDR1=(vLCDBANK<<21)|(vLCDBASEU);
rLCDSADDR2=vLCDBASEL;
Uart_Printf("LCD Scrolled has been over!\n");
#ifdef DEBUG
Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
#endif
return;
default:
Uart_Printf("Please enter KEY: 'd','u','r' or 'l'!\n");
break;
}
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
}
}
void Lcd_MoveViewPort(int vx,int vy)
{
SET_IF();
vLCDBASEU=((((U32)LCD_BUFFER+vy*SCR_xSIZE+vx))&0x3fffff)>>1;
vLCDBASEL=(U32)vLCDBASEU+(PAGEWIDTH+OFFSIZE)*(LINEVAL+1);
while((rLCDCON1>>18)==0);
rLCDSADDR1=(vLCDBANK<<21)|(vLCDBASEU);
rLCDSADDR2=vLCDBASEL;
#ifdef DEBUG
Uart_Printf( "rLCDSADDR1=0x%x\n", rLCDSADDR1 );
Uart_Printf( "rLCDSADDR2=0x%x\n", rLCDSADDR2 );
Uart_Printf( "rLCDSADDR3=0x%x\n\n", rLCDSADDR3 );
#endif
CLR_IF();
}
// 接收来自UART0的BMP图片数据
U8 UART0_BMP_BUFFER[SCR_ySIZE*SCR_xSIZE];
U32 index;
void UART0_RecvBmp(void)
{
int i;
U8* BMP_BUFFER;
U32 FILE_SIZE;
U8 dummy;
BMP_BUFFER=UART0_BMP_BUFFER;
index=0;
dummy=RdURXH0(); // 在接收有效数据之前先清空UART0中的dummy数据
BMP_BUFFER[index++]=Uart_Getch(); //接收到BMP数据的'B'
BMP_BUFFER[index++]=Uart_Getch(); //接收到BMP数据的'M'
BMP_BUFFER[index++]=Uart_Getch(); //接收到BMP的文件大小
BMP_BUFFER[index++]=Uart_Getch();
BMP_BUFFER[index++]=Uart_Getch();
BMP_BUFFER[index++]=Uart_Getch();
FILE_SIZE=(BMP_BUFFER[index-1]<<24)|(BMP_BUFFER[index-2]<<16)|(BMP_BUFFER[index-3]<<8)|(BMP_BUFFER[index-4]);
for(i=6;i<FILE_SIZE;i++)
{
BMP_BUFFER[index++]=Uart_Getch();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -