📄 glib.c
字号:
/*
*************************************************************************************************************
- 函数名称 : void Fill_Circle(U16 x0, U16 y0, U16 r)
- 函数说明 : 填充圆函数
- 输入参数 : x,y
- 输出参数 : 无
*************************************************************************************************************
*/
void Fill_Circle (U16 x0, U16 y0, U16 r)
{
U32 i;
U32 imax = ((int)((int)r*707))/1000+1;
U32 sqmax = (int)r*(int)r+(int)r/2;
U16 x = r;
LCD_DrawHLine(x0-r,y0,x0+r);
for (i=1; i<= imax; i++)
{
if ((i*i+x*x) >sqmax)
{
if (x>imax)
{
LCD_DrawHLine (x0-i+1,y0+x, x0+i-1);
LCD_DrawHLine (x0-i+1,y0-x, x0+i-1);
}
x--;
}
LCD_DrawHLine(x0-x,y0+i, x0+x);
LCD_DrawHLine(x0-x,y0-i, x0+x);
}
}
/*
*************************************************************************************************************
- 函数名称 : void Fill_Rect (int x0, int y0, U16 x1, U16 y1)
- 函数说明 : 填充矩形函数
- 输入参数 : x,y
- 输出参数 : 无
*************************************************************************************************************
*/
void Fill_Rect(U16 x0, U16 y0, U16 x1, U16 y1)
{
LCD_FillRect(x0,y0,x1,y1);
}
/*
*************************************************************************************************************
- 函数名称 : Log2Phy(int Color)
- 函数说明 : 逻辑颜色转实际颜色函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
U16 Log2Phy(U32 Color)
{
U32 r,g,b;
b = Color & 255;
g = (Color >> 8 ) & 255;
r = Color >> 16;
//b = (b + 42) / 85;
//g = (g * 7 + 127) / 255;
//r = (r * 7 + 127) / 255;
b = b / 8;
g = g / 4;
r = r / 8;
return b + (g << 5) + (r << 11);
}
/*
*************************************************************************************************************
- 函数名称 : LCD_Log2Phy(int Color)
- 函数说明 : 逻辑颜色转实际颜色上层函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
U16 LCD_Log2Phy(U32 Color)
{
U16 PhyColor;
PhyColor = Log2Phy(Color);
return PhyColor;
}
/*
*************************************************************************************************************
- 函数名称 : void Set_Color(int color)
- 函数说明 : 设定颜色的上层函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
void Set_Color(U32 color)
{
LCD_SetColor(LCD_Log2Phy(color));
}
/*
*************************************************************************************************************
- 函数名称 : void Set_Color(int color)
- 函数说明 : 设定颜色函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_SetColor(U16 PhyColor)
{
LCD_COLOR = PhyColor;
}
/*
*************************************************************************************************************
- 函数名称 : void Set_Color(int color)
- 函数说明 : 设定颜色的上层函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
void Set_BkColor(U32 color)
{
LCD_SetBkColor(LCD_Log2Phy(color));
}
/*
*************************************************************************************************************
- 函数名称 : void Set_Color(int color)
- 函数说明 : 设定颜色函数
- 输入参数 : color
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_SetBkColor(U16 PhyColor)
{
LCD_BKCOLOR = PhyColor;
}
/*
*****************************************************************************************************************
** 结束文件 **
*****************************************************************************************************************
*/
void LCD_DrawPixel (U16 x, U16 y)
{
SETPIXEL(x, y, LCD_COLOR);
}
/*
*************************************************************************************************************
- 函数名称 : U32 LCD_GetPixel(U16 x, U16 y)
- 函数说明 : 得到点值的函数
- 输入参数 : x,y
- 输出参数 : colof
*************************************************************************************************************
*/
U32 LCD_GetPixel(U16 x, U16 y)
{
return GETPIXEL(x,y);
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_DrawHLine (U16 x0, U16 y, U16 x1)
- 函数说明 : 画水平线函数
- 输入参数 : x,y,x1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_DrawHLine (U16 x0, U16 y0, U16 x1)
{
while (x0 <= x1)
{
SETPIXEL(x0, y0, LCD_COLOR);
x0++;
}
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_DrawVLine (U16 x, U16 y0, U16 y1)
- 函数说明 : 画竖直线函数
- 输入参数 : x,y,x1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_DrawVLine(U16 x0, U16 y0, U16 y1)
{
while (y0 <= y1)
{
SETPIXEL(x0, y0, LCD_COLOR);
y0++;
}
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_FillRect(U16 x0, U16 y0, U16 x1, U16 y1)
- 函数说明 : 填充矩形函数
- 输入参数 : x0,y0,x1,y1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_FillRect(U16 x0, U16 y0, U16 x1, U16 y1)
{
for (; y0 <= y1; y0++)
{
LCD_DrawHLine(x0,y0, x1);
}
}
/*
*************************************************************************************************************
- 函数名称 : DrawBitLine1BPP
- 函数说明 : 绘制位图函数
- 输入参数 : x0,y0,x1,y1
- 输出参数 : 无
*************************************************************************************************************
*/
static void DrawBitLine1BPP(U16 x, U16 y, U8 const*p, U16 Diff, U16 xsize, const U16*pTrans)
{
U16 pixels;
U32 Index0 = *(pTrans + 0);
U32 Index1 = LCD_COLOR;
pixels = *p;
switch (Diff&7)
{
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
case 3:
goto WriteBit3;
case 4:
goto WriteBit4;
case 5:
goto WriteBit5;
case 6:
goto WriteBit6;
case 7:
goto WriteBit7;
}
WriteBit0:
SETPIXEL(x+0, y, (pixels&(1<<7)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit1:
SETPIXEL(x+1, y, (pixels&(1<<6)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit2:
SETPIXEL(x+2, y, (pixels&(1<<5)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit3:
SETPIXEL(x+3, y, (pixels&(1<<4)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit4:
SETPIXEL(x+4, y, (pixels&(1<<3)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit5:
SETPIXEL(x+5, y, (pixels&(1<<2)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit6:
SETPIXEL(x+6, y, (pixels&(1<<1)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit7:
SETPIXEL(x+7, y, (pixels&(1<<0)) ? Index1 : Index0);
if (!--xsize)
return;
x+=8;
pixels = *(++p);
goto WriteBit0;
}
/*
*************************************************************************************************************
- 函数名称 : LCD_L0_DrawBitmap
- 函数说明 : 绘制位图函数
- 输入参数 :
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_L0_DrawBitmap(U16 x0, U16 y0,U16 xsize, U16 ysize,U16 BitsPerPixel,U16 BytesPerLine,
const U8* pData, U16 Diff,
const U16* pTrans)
{
U16 i;
switch (BitsPerPixel)
{
case 1:
for (i=0; i<ysize; i++)
{
DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
pData += BytesPerLine;
}
break;
}
}
/*
*****************************************************************************************************************
** 结束文件 **
*****************************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -