Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15530261
  • 博文数量: 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-06-04 19:22:45

#define ___video_memory_screen_dma_ddr_addr (0x80000000 + 128*1024*1024 - 3*1024*1024)

#define ___lcd_screen_width (320)
#define ___lcd_screen_height (480)
#define PAGE_SHIFT        12
#define PAGE_SIZE        (1UL << PAGE_SHIFT)


typedef unsigned long        u_long;
#define uint32_t    u_long

void get_lcd_pixel(uint32_t *data, uint32_t x, uint32_t y)
{
    uint32_t *fb_addr = (uint32_t *)(___video_memory_screen_dma_ddr_addr + PAGE_SIZE + 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 *)(___video_memory_screen_dma_ddr_addr + PAGE_SIZE + 4*x + y*320*4);
    *fb_addr = data;
}


#define X (0x88888888)
#define O (-2)
#define _NOT_PAINT_DOT O
#define _picture_X (10)
#define _picture_Y (12)
typedef struct
{
    uint32_t data[_picture_Y][_picture_X];
}_picture_struct;

typedef struct
{
    int x;
    int y;
    _picture_struct *ppic;
    _picture_struct pic;
}_picture_struct_save;

static _picture_struct _picture_buf[]=
{
    {
        .data =
        {
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

};

static uint32_t lcd_posx = 0,lcd_posy = 0;
static uint32_t _pictures = 0;
static uint32_t _log_not_first = 0;
static _picture_struct_save picture_restore;

inline uint32_t get_lcd_posx(void)
{
    return lcd_posx;
}

inline uint32_t get_lcd_posy(void)
{
    return lcd_posy;
}

inline set_lcd_posx(int pos_x)
{
    lcd_posx = pos_x;
}

inline set_lcd_poxy(int pos_y)
{
    lcd_posy = pos_y;
}

void dkb_logo_paint(_picture_struct *pic, int pos_x, int pos_y)
{
    int i,j;

    for(i = 0;i < _picture_Y;i++)
    {
        for(j = 0;j < _picture_X;j++)
        {
            if(pic->data[i][j] != _NOT_PAINT_DOT)
            {
                set_lcd_pixel(pic->data[i][j], pos_x+j, pos_y+i);
            }
        }
    }
}

void dkb_logo_paint_restore(_picture_struct_save *pic)
{
    dkb_logo_paint(&pic->pic, pic->x, pic->y);
}

void dkb_logo_save(_picture_struct_save *pic, _picture_struct *ppic, int pos_x, int pos_y)
{
    int i,j;

    if(_log_not_first)
    {
        //restore the pre-pos image

        dkb_logo_paint_restore(&picture_restore);
    }
    _log_not_first = 1;

    pic->x = pos_x;
    pic->y = pos_y;
    pic->ppic = ppic;

    for(i = 0;i < _picture_Y;i++)
    {
        for(j = 0;j < _picture_X;j++)
        {
            if(ppic->data[i][j] != _NOT_PAINT_DOT)
            {
                get_lcd_pixel(&pic->pic.data[i][j], pic->x+j, pic->y+i);
            }else pic->pic.data[i][j] = _NOT_PAINT_DOT;
        }
    }
}

void dkb_logo_direction_method(void)
{
    static int direction = 1;
    if(direction)
    {
        if( (_pictures >= ( (sizeof(_picture_buf)/sizeof(_picture_buf[0])) - 1 )) )
        {
            _pictures--;
            direction = 0;
        }else _pictures++;
    }
    else
    {
        if(_pictures)_pictures--;
        else direction = 1;
    }
}

void dkb_logo_pos_method(void)
{
    int pos_x,pos_y;

    pos_x = get_lcd_posx();
    pos_y = get_lcd_posy();
    
    pos_y += 4;
    if(pos_y > ___lcd_screen_height)
    {
        pos_y = 0;
        pos_x += _picture_X;
        if(pos_x > ___lcd_screen_width)
        {
            pos_x = 0;
        }
    }

    set_lcd_posx(pos_x);
    set_lcd_poxy(pos_y);
}

void dkb_logo(void)
{
    static int counts = 0;
    if(++counts > 30)
    {
        _picture_struct *ppic;
        int pos_x,pos_y;
        
        ppic = &_picture_buf[_pictures];
        pos_x = get_lcd_posx();
        pos_y = get_lcd_posy();

        dkb_logo_save(&picture_restore, ppic, pos_x, pos_y);
        dkb_logo_paint(ppic, pos_x, pos_y);

        dkb_logo_direction_method();
        dkb_logo_pos_method();

        counts = 0;
    }
}


效果2:

#define ___video_memory_screen_dma_ddr_addr (0x80000000 + 128*1024*1024 - 3*1024*1024)

#define ___lcd_screen_width (320)
#define ___lcd_screen_height (480)
#define PAGE_SHIFT        12
#define PAGE_SIZE        (1UL << PAGE_SHIFT)


typedef unsigned long        u_long;
#define uint32_t    u_long

void get_lcd_pixel(uint32_t *data, uint32_t x, uint32_t y)
{
    uint32_t *fb_addr = (uint32_t *)(___video_memory_screen_dma_ddr_addr + PAGE_SIZE + 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 *)(___video_memory_screen_dma_ddr_addr + PAGE_SIZE + 4*x + y*320*4);
    *fb_addr = data;
}


#define X (1)
#define O (-2)
#define _NOT_PAINT_DOT O
#define _picture_X (20)
#define _picture_Y (24)
typedef struct
{
    uint32_t data[_picture_Y][_picture_X];
}_picture_struct_saves;

typedef struct
{
    signed char data[_picture_Y][_picture_X];
}_picture_struct;

typedef struct
{
    int x;
    int y;
    _picture_struct *ppic;
    _picture_struct_saves pic;
}_picture_struct_save;

static _picture_struct _picture_buf[]=
{
    {
        .data =
        {
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X},
            {X,X,X,X,X,X,X,X,X,X}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,X,X,X,X,X,X,X,X,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,X,X,X,X,X,X,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,X,X,X,X,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

    {
        .data =
        {
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,X,X,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O},
            {O,O,O,O,O,O,O,O,O,O}
        }
    },

};

static uint32_t lcd_posx = ___lcd_screen_width/4,lcd_posy = 0;
static uint32_t _pictures = 0;
static uint32_t _log_not_first = 0;
static _picture_struct_save picture_restore;

inline uint32_t get_lcd_posx(void)
{
    return lcd_posx;
}

inline uint32_t get_lcd_posy(void)
{
    return lcd_posy;
}

inline set_lcd_posx(int pos_x)
{
    lcd_posx = pos_x;
}

inline set_lcd_poxy(int pos_y)
{
    lcd_posy = pos_y;
}

void dkb_logo_paint(_picture_struct *pic, int pos_x, int pos_y, int color)
{
    int i,j;

    for(i = 0;i < _picture_Y;i++)
    {
        for(j = 0;j < _picture_X;j++)
        {
            if(pic->data[i][j] != _NOT_PAINT_DOT)
            {
                set_lcd_pixel(color, pos_x+j, pos_y+i);
            }
        }
    }
}

void dkb_logo_paint_restore(_picture_struct_save *pic)
{
    int i,j;
    int pos_x,pos_y;

    pos_x = pic->x;
    pos_y = pic->y;

    for(i = 0;i < _picture_Y;i++)
    {
        for(j = 0;j < _picture_X;j++)
        {
            if(pic->pic.data[i][j] != _NOT_PAINT_DOT)
            {
                set_lcd_pixel(pic->pic.data[i][j], pos_x+j, pos_y+i);
            }
        }
    }
}

void dkb_logo_save(_picture_struct_save *pic, _picture_struct *ppic, int pos_x, int pos_y)
{
    int i,j;

    if(_log_not_first)
    {
        //restore the pre-pos image

        dkb_logo_paint_restore(&picture_restore);
    }
    _log_not_first = 1;

    pic->x = pos_x;
    pic->y = pos_y;
    pic->ppic = ppic;

    for(i = 0;i < _picture_Y;i++)
    {
        for(j = 0;j < _picture_X;j++)
        {
            if(ppic->data[i][j] != _NOT_PAINT_DOT)
            {
                get_lcd_pixel(&pic->pic.data[i][j], pic->x+j, pic->y+i);
            }else pic->pic.data[i][j] = _NOT_PAINT_DOT;
        }
    }
}

void dkb_logo_direction_method(void)
{
    static int direction = 1;
    if(direction)
    {
        if( (_pictures >= ( (sizeof(_picture_buf)/sizeof(_picture_buf[0])) - 1 )) )
        {
            _pictures--;
            direction = 0;
        }else _pictures++;
    }
    else
    {
        if(_pictures)_pictures--;
        else direction = 1;
    }
}

void dkb_logo_pos_method(void)
{
    int pos_x,pos_y;

    pos_x = get_lcd_posx();
    pos_y = get_lcd_posy();
    
    pos_y += 4;
    if(pos_y > ___lcd_screen_height)
    {
        pos_y = 0;
        pos_x += _picture_X + 4;
        if(pos_x > ___lcd_screen_width)
        {
            pos_x = 0;
        }
    }

    set_lcd_posx(pos_x);
    set_lcd_poxy(pos_y);
}

void dkb_logo(int color, int mod)
{
    static int counts = 0;
    if( (++counts > 30) || (mod) )
    {
        _picture_struct *ppic;
        int pos_x,pos_y;
        
        ppic = &_picture_buf[_pictures];
        pos_x = get_lcd_posx();
        pos_y = get_lcd_posy();

        dkb_logo_save(&picture_restore, ppic, pos_x, pos_y);
        dkb_logo_paint(ppic, pos_x, pos_y ,color);

        dkb_logo_direction_method();
        dkb_logo_pos_method();

        counts = 0;
    }
}

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