Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15273134
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2008-05-12 14:01:25


scale为缩放比例,以8*8的ascii点阵字库为基准进行缩放,
fcolor为显示文字时的前景色
bcolor为显示文字时的背景色
mod为显示模式


typedef struct { int x0,y0,x1,y1; } LCD_RECT;
#define LCD_DRAWMODE_NORMAL (0)
#define LCD_DRAWMODE_XOR    (1<<0)
#define LCD_DRAWMODE_TRANS  (1<<1)
#define LCD_DRAWMODE_REV    (1<<2)

#define FONT_COLOR_BLACK    (0)
#define FONT_COLOR_RED      (0xff<<16)
#define FONT_COLOR_GREEN    (0xff<<8)
#define FONT_COLOR_BLUE     (0xff)
#define FONT_COLOR_WHITE    (FONT_COLOR_RED | FONT_COLOR_GREEN | FONT_COLOR_BLUE)

void get_lcd_pixel(uint32_t *data, uint32_t x, uint32_t y)
{
    uint32_t *fb_addr = (uint32_t *)(pxafb.screen_dma + 4*x + y*320*4);
    *data = *fb_addr;
}

void set_lcd_pixel(uint32_t data, uint32_t x, uint32_t y)
{
    uint32_t *fb_addr = (uint32_t *)(pxafb.screen_dma + 4*x + y*320*4);
    *fb_addr = data;
}

#define __FONT_WIDTH_SPACE 2
#define __FONT_HEIGHT_SPACE 2
static int font_width = 8;
static int font_height = 8;
static int screen_x = 0;
static int screen_y = 0;

void lcd_printf(char *string, int x, int y, int scale, int fcolor, int bcolor, int mod)
{
    static char bits[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
    char *data;
    char *p = string;
    char dots;
    int FONT_WIDTH,FONT_HEIGHT;
    int i,j,px,py;
    int font_fcolor,font_bcolor;

    FONT_WIDTH = font_width*scale;
    FONT_HEIGHT = font_height*scale;
    if(x != -1)screen_x = x;
    if(y != -1)screen_y = y;

    switch(mod & 0x7)
    {
        case LCD_DRAWMODE_NORMAL:
            font_fcolor = fcolor;
            font_bcolor = bcolor;
            break;
        /*
        case LCD_DRAWMODE_TRANS:
            
            break;
        case LCD_DRAWMODE_REV:
            
            break;
        */

        default:
            font_fcolor = -1;
            font_bcolor = 0;
            break;
    }
    
    for(;*p;p++)
    {
        int li,lj;

        dots = *p;
        if( (dots < 32) || (dots > 162) )dots = 32;
        data = GUI_F8x8_acFont[dots - 32];
        
        py = y;

        for(i = 0;i < font_height;i++)
        {
            dots = *data++;
            
            for(lj = 0;lj < scale;lj++)
            {
                px = x;

                for(j = 0;j < font_width;j++)
                {
                    char dbit;

                    dbit = dots & bits[j];

                    for(li = 0;li < scale;li++)
                    {
                        if(dbit)set_lcd_pixel(font_fcolor,px++,py);
                        else set_lcd_pixel(font_bcolor,px++,py);
                    }
                }

                for(li = 0;li < __FONT_WIDTH_SPACE;li++)
                {
                    set_lcd_pixel(font_bcolor,px++,py);
                }

                py++;
            }
        }

        for(i = 0;i < __FONT_HEIGHT_SPACE;i++)
        {
            px = x;
            for(j = 0;j < (FONT_WIDTH + __FONT_WIDTH_SPACE);j++)
            {
                set_lcd_pixel(font_bcolor,px++,py);
            }
            py++;
        }

        x = px;
        if( (x + FONT_WIDTH) > 320 ) {x = 0;y = py;}
        
        if(y >= 480)break;
    }
    screen_x = x;
    screen_y = y;
}

void lcd_draw_rect(LCD_RECT *rect, int color)
{
    int i,j;
    int x0,y0,x1,y1;
    x0 = rect->x0;
    y0 = rect->y0;
    x1 = rect->x1;
    y1 = rect->y1;
    
    for(i = x0;i < x1;i++)
    {
        set_lcd_pixel(color,i,y0);
        set_lcd_pixel(color,i,y1);
    }
    for(i = y0;i < y1;i++)
    {
        set_lcd_pixel(color,x0,i);
        set_lcd_pixel(color,x1,i);
    }
}
void lcd_fill_rect(LCD_RECT *rect, int color)
{
    int i,j;
    int x0,y0,x1,y1;
    x0 = rect->x0;
    y0 = rect->y0;
    x1 = rect->x1;
    y1 = rect->y1;
    
    for(i = y0;i < y1;i++)
     for(j = x0;j < x1;j++)
      set_lcd_pixel(color,j,i);
}


文件:lcd_printf.tar.gz
大小:5KB
下载:下载

阅读(2114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~