| 
 | 
 
 楼主 |
发表于 2006-12-22 09:57:28
|
显示全部楼层
 
 
 
#include <stdio.h> 
#include <stdlib.h> 
#include <fcntl.h> 
#include <unistd.h> 
#include <string.h> 
#include <sys/ioctl.h> 
#include <sys/mman.h> 
#include <asm/page.h> 
#include <linux/fb.h> 
 
int fb; 
struct fb_var_screeninfo vinfo; 
struct fb_fix_screeninfo finfo; 
typedef struct { 
        unsigned char r; 
        unsigned char g; 
        unsigned char b; 
}rgb_t; 
unsigned long screen_size; 
unsigned char * lpScreenMem; 
 
int main(int argc, char ** argv) 
{ 
        int i, j; 
        rgb_t rgb; 
        fb = open("/dev/fb0", O_RDWR); 
        if (fb < 0) { 
                fprintf(stderr, "open /dev/fb0 error!\n"); 
                return -1; 
        } 
        if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo)) { 
                fprintf(stderr, "error get var screeninfo!\n"); 
                return -1; 
        } 
        printf("%dx%d %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); 
        screen_size = vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel /  ; 
        lpScreenMem = (unsigned char *)mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); 
        if (lpScreenMem == -1) { 
                return -1; 
        } 
        rgb.r = 0xff; 
        rgb.g = 0x00; 
        rgb.b = 0x00; 
        for (i = 0;i < 100;i ++) { 
                //draw_point(0, i, rgb); 
                for (j = 0;j < 100;j ++) { 
                        draw_point(i, j, rgb); 
                } 
        } 
        close(fb); 
} 
 
void draw_point(int x, int y, rgb_t rgb) 
{ 
        unsigned short * lpMem = (unsigned short *)(lpScreenMem + (x + y * vinfo.xres * 2)); 
        *lpMem = (unsigned short)((((unsigned short)rgb.r & 0x1f) << 11) + (((unsigned short)rgb.g & 0x3f) << 5) + (unsigned short)rgb.b); 
} 
 
我的颜色老是设置不对,你看看那里有错,先谢谢了! |   
 
 
 
 |