STM32F103尝试跑了下图形抗锯齿 C/C++

admin 2020-5-10 2196

下面是我实现的程序。
//   B  背景点的颜色
//   P  前景点的颜色
//   Alpha2 前景透明度 (0-100)
u16 Point_Mix(u16 B,u16 P,u8 Alpha2)
{
                u16  RGB_R1,RGB_G1,RGB_B1;
                u16  RGB_R2,RGB_G2,RGB_B2;
                u16  RGB_C;
        
                RGB_R2=((P>>11)&0x1F)*Alpha2/100;
                RGB_G2=((P>>5)&0x3F)*Alpha2/100;
                RGB_B2=(P&0x1F)*Alpha2/100;
        
                RGB_R1 = ((B>>11)&0x1F)*(100-Alpha2)/100;
                RGB_G1 = ((B>>5)&0x3F)*(100-Alpha2)/100;
                RGB_B1 = (B&0x1F)*(100-Alpha2)/100;
               
                RGB_C = ((RGB_R1+RGB_R2)<<11)+((RGB_G1+RGB_G2)<<5)+(RGB_B1+RGB_B2);
         
                return RGB_C;
}
现在不用多少内存了,你只要在画点前,先读取,然后再进行混合,再写入就好了。
/****************************************************************************
* 名    称:void ili9320_SetPoint(u16 x,u16 y,u16 point)
* 功    能:在指定座标画点
* 入口参数:x      行座标
*           y      列座标
*           point  点的颜色
* 出口参数:无
* 说    明:
* 调用方法:ili9320_SetPoint(10,10,0x0fe0);
****************************************************************************/
void ili9320_SetPoint(u16 x,u16 y,u16 point)
{
        u16 B,C;
  if ( (x>320)||(y>240) ) return;
        if(Point_Alpha==100)
        {
                ili9320_SetCursor(x,y);
                LCD_WriteRAM_Prepare();
                LCD_WriteRAM(point);
        }
        else
        {
                B=ili9320_GetPoint(x,y);           //先读点
                C=Point_Fix(B,point,Point_Alpha);  //混合
                ili9320_SetCursor(x,y);            //设置坐标点
                LCD_WriteRAM_Prepare();   
                LCD_WriteRAM(C);                   //写入
       }
}
主程序里面的实现方法
                  Point_Alpha=50;
                  GUI_Circle(100,150,40,Red,1);
                  Point_Alpha=80;
                  GUI_Circle(140,150,40,Yellow,1);
                  Point_Alpha=50;
                  GUI_Circle(180,150,40,Black,1);

源代码: https://github.com/MidoriYakumo/OURSTM-MINI-demo_clock

最新回复 [0]
返回