📄 lcd2478.c
字号:
int dx_x2;
int dy_x2;
int di;
dx = ix1 - ix0; /* two pixel's offset */
dy = iy1 - iy0;
if (dx > 0) {
dx_sym = 1; /* decide the increase size */
} else {
if (dx < 0) {
dx_sym = -1;
} else {
if (dy >= 0) {
lcd_DrawVLine(ix0, iy0, iy1, uicolor); /* dx==0,draw a vertical line */
} else {
lcd_DrawVLine(ix0, iy1, iy0, uicolor);
}
return;
}
}
if (dy > 0) {
dy_sym = 1;
} else {
if (dy < 0) {
dy_sym = -1;
} else {
if (dx >= 0) {
lcd_DrawHLine(ix0, ix1, iy0, uicolor); /* dy==0,Draw a horizontal line*/
} else {
lcd_DrawHLine(ix1, ix0, iy0, uicolor);
}
return;
}
}
dx = dx_sym * dx; /* get absolute value */
dy = dy_sym * dy;
dx_x2 = dx * 2; /* double dx */
dy_x2 = dy * 2; /* double dy */
/*
* dx >= dy, use x as benchmark
*/
if (dx >= dy) {
di = dy_x2 - dx;
while (ix0 != ix1) {
lcd_SetPixel(ix0, iy0, uicolor);
ix0 += dx_sym;
if (di < 0) {
di += dy_x2;
} else {
di += dy_x2 - dx_x2;
iy0 += dy_sym;
}
}
lcd_SetPixel(ix0, iy0, uicolor); /* display the last pixel */
} else {
/*
* dx < dy, use y as benchmark
*/
di = dx_x2 - dy;
while (iy0 != iy1) {
lcd_SetPixel(ix0, iy0, uicolor);
iy0 += dy_sym;
if (di < 0) {
di += dx_x2;
} else {
di += dx_x2 - dy_x2;
ix0 += dx_sym;
}
}
lcd_SetPixel(ix0, iy0, uicolor); /* display the last pixel */
}
}
/*********************************************************************************************************
** Function name : lcd_DrawRect
** Function Description : Draw a rectangle
** Input: ix0 x side coordinate of the first pixel
** iy0 y side coordinate of the first pixel
** ix1 x side coordinate of the last pixel
** iy1 y side coordinate of the last pixel
** uicolor the color of the pixel
** Output: none
*********************************************************************************************************/
void lcd_DrawRect (int ix0, int iy0, int ix1, int iy1, unsigned int uicolor)
{
lcd_DrawLine(ix0,iy0,ix1,iy0,uicolor);
lcd_DrawLine(ix1,iy0,ix1,iy1,uicolor);
lcd_DrawLine(ix1,iy1,ix0,iy1,uicolor);
lcd_DrawLine(ix0,iy1,ix0,iy0,uicolor);
}
/*********************************************************************************************************
** Function name : lcd_FillRect
** Function Description : Fill a rectangle
** Input: ix0 x side coordinate of the first pixel
** iy0 y side coordinate of the first pixel
** ix1 x side coordinate of the last pixel
** iy1 y side coordinate of the last pixel
** uicolor the color of the pixel
** Output: none
*********************************************************************************************************/
void lcd_FillRect (int ix0, int iy0, int ix1, int iy1, unsigned int uicolor)
{
int i;
if (iy1 > iy0) {
for (i = iy0; i <= iy1; i++) {
lcd_DrawLine(ix0, i, ix1, i, uicolor);
}
} else {
for (i = iy0; i >= iy1; i--) {
lcd_DrawLine(ix0, i, ix1, i, uicolor);
}
}
}
#if (HWORDMODE == 1)
/*********************************************************************************************************
** Function name : lcd_DrawBmp
** Function Description : Draw a bmp
** Input: ix0 x side coordinate of the first pixel
** iy0 y side coordinate of the first pixel
** iwidth x side width
** ilength y side length
** pucBmp the bmp array pointer
** Output: none
*********************************************************************************************************/
void lcd_DrawBmp (int ix0,
int iy0,
int iwidth,
int ilength,
unsigned short *pucBmp)
{
int ix, iy;
unsigned int uicolor;
for (iy = iy0; iy < ilength + iy0; iy++) {
for (ix = ix0; ix < iwidth + ix0; ix++) {
uicolor = *pucBmp++;
lcd_SetPixel(ix, iy, uicolor);
}
}
}
#else
/*********************************************************************************************************
** Function name : lcd_DrawBmp
** Function Description : Draw a bmp
** Input: ix0 x side coordinate of the first pixel
** iy0 y side coordinate of the first pixel
** iwidth x side width
** ilength y side length
** pucBmp the bmp array pointer
** Output: none
*********************************************************************************************************/
void lcd_DrawBmp (int ix0,
int iy0,
int iwidth,
int ilength,
unsigned char *pucBmp)
{
int ix, iy;
unsigned int uicolor;
for (iy = iy0; iy < ilength + iy0; iy++) {
for (ix = ix0; ix < iwidth + ix0; ix++) {
uicolor = *(pucBmp + 1) | (*(pucBmp) << 8);
lcd_SetPixel(ix, iy, uicolor);
pucBmp += 2;
}
}
}
#endif
/*********************************************************************************************************
** Function name : delay_Ns
** Function Description : delay time
** Input: idly the necessary time
** Output: none
*********************************************************************************************************/
void delay_Ns (int idly)
{
int i;
for(; idly > 0; idly--) {
for (i = 0; i < 5000; i++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -