论坛元老
- 积分
- 5246
- 金钱
- 5246
- 注册时间
- 2012-8-25
- 在线时间
- 1024 小时
|
本帖最后由 gotofly21 于 2018-8-3 08:47 编辑
做一个项目,很多页面显示的汉字大同小异。字库存在外部flash,stm32 ram很大用不完,本着反正闲着也是闲着,做了一个缓冲区减少读取字库次数,效果有点,原来拉窗明显,现在几乎没有。算法很粗糙。
[mw_shl_code=applescript,true]
#define BYTES_PER_FONT 144 //最大支持32*32的汉字
static uint8_t GUI_FontDataBuf[BYTES_PER_FONT];
//字库缓存 减少字库读取次数
typedef struct
{
uint8_t GUI_FontDataBuf[BYTES_PER_FONT];
uint32_t addr;
uint32_t shiyong_lv;
} ziku_huancun_t;
#define ziku_huancun_n 50
ziku_huancun_t ziku_huancun_s[ziku_huancun_n];
uint8_t* ziku_huancun_caxu( uint32_t addr )
{
ziku_huancun_t* ziku_huancun_p = ziku_huancun_s;
uint8_t* data_p;
data_p = 0;
uint32_t i;
for( i = 0; i < ziku_huancun_n; i++ )
{
if( ziku_huancun_p->addr == addr )
{
if( ziku_huancun_p->shiyong_lv < 100000000 )
{
ziku_huancun_p->shiyong_lv += 1000;
}
data_p = ziku_huancun_p->GUI_FontDataBuf;
// break;
}
else if( ziku_huancun_p->shiyong_lv > 1 )
{
ziku_huancun_p->shiyong_lv--;
}
ziku_huancun_p++;
}
return data_p;
}
void ziku_huancun_huancun( uint32_t addr, uint8_t* data_p )
{
ziku_huancun_t* ziku_huancun_p = ziku_huancun_s;
uint32_t i, cun_f, min_shiyong_lv;
cun_f = 0;
ziku_huancun_p = ziku_huancun_s;
min_shiyong_lv = ziku_huancun_p->shiyong_lv;
ziku_huancun_p++;
for( i = 1; i < ziku_huancun_n; i++ )
{
if( min_shiyong_lv > ziku_huancun_p->shiyong_lv )
{
min_shiyong_lv = ziku_huancun_p->shiyong_lv;
cun_f = i;
}
ziku_huancun_p++;
}
ziku_huancun_p = ziku_huancun_s + cun_f;
ziku_huancun_p->addr = addr;
ziku_huancun_p->shiyong_lv = min_shiyong_lv + 1000;
memcpy( ziku_huancun_p->GUI_FontDataBuf, data_p, BYTES_PER_FONT );
}
extern void SST25ReadArray( uint32_t address, char* pData, uint16_t nCount );
uint8_t* GUI_hanzi_datap( uint32_t addr, uint32_t lenth ) //GUIcharP 调用 addr 从字库起始偏移 gui调这个函数,返回点阵地址
{
uint8_t* data_p = 0;
addr += 0x10000;
data_p = ziku_huancun_caxu( addr );
if( data_p == 0 )
{
SST25ReadArray( addr, ( char* )GUI_FontDataBuf, ( uint16_t )lenth );
ziku_huancun_huancun( addr, GUI_FontDataBuf );
data_p = GUI_FontDataBuf;
}
return data_p;
}[/mw_shl_code]
|
|