单片机系统中的一种文字平滑(抗锯齿)显示方法(转)

单片机系统中的一种文字平滑(抗锯齿)显示方法

STM32 抗锯齿中文显示另类方案分享

2.单片机用的是stm32f103c8t6,显示部分的代码很简单:

/************************************
/
/    AlphaBlend算法
/    输入:
/    foreground_color:前景色
/    background_color:背景色
/    alpha:alpha值
/    返回:最终显示的颜色值(RGB565格式)
*************************************/
uint16_t LCD_AlphaBlend(uint32_t foreground_color,uint32_t background_color,uint8_t alpha){
    uint16_t r=0,g=0,b=0;
    if((foreground_color==0xffffff)&&(background_color==0)){    //默认的前景和背景色,不做alpha计算
        r=alpha;
        g=alpha;
        b=alpha;
    }
    else{
        uint8_t *fg = (uint8_t *)&foreground_color;
        uint8_t *bg = (uint8_t *)&background_color;
            
        b = ((int)(*fg * alpha) + (int)*bg * (256 - alpha))>>8;
        fg++;bg++;
        g = ((int)(*fg * alpha) + (int)*bg * (256 - alpha))>>8;
        fg++;bg++;
        r = ((int)(*fg * alpha) + (int)*bg * (256 - alpha))>>8;
    }
    uint16_t temp= (((b >>3) & 0x1f)<<0)|(((g>>2) & 0x3f) << 5) |(((r >>3) & 0x1f) <<11);
    return (temp << 8) | (temp >> 8);//由于用的是DMA传输,需要高低字节互换
}
 
/*****************
 *显示中文字符
 ****************/
void LCD_ShowZhChar(int x,int y,char *str,uint32_t fc,uint32_t bc){
    memset(fontCache, 0, sizeof(fontCache));    //fontCache是字库显示缓存,32x32x2大小
    uint16_t *p = fontCache;
    for (int i = 0; i < ZH_FONT_WIDTH*ZH_FONT_HEIGHT; i++)
    {
        *p = LCD_AlphaBlend(fc,bc, gZhFont[i]);
        p++;
    }
 
    LCD_setAddrWindow(x, y, x+ZH_FONT_WIDTH-1, y+ZH_FONT_HEIGHT-1);//设置显示区域
    SPI_LCD_CS_LOW();
    SPI_LCD_DATA_R();
    LCD_DMA_Send((uint8_t *)fontCache, sizeof(fontCache));         //DMA发送
    while(is_LCD_DMA_busy);
    SPI_LCD_CS_HIGH();
}
原文地址:https://www.cnblogs.com/LittleTiger/p/13529779.html