[Android]读写fb0测试

直接读写fb0测试

 

1 写fb0

修改  system/extras/tests/framebuffer/fb_test.c

读取格式为RGB_888的bmp图片,显示到屏幕上

 

void draw_grid(int w, int h, void* _loc) {

    int i, j;

    int v;

    int stride = fi.line_length / (vi.bits_per_pixel >> 3);

    uint16_t *loc = _loc;

    uint32_t *loc32 = _loc;

    

    BMP_READ * bmp = bmp_open("test.bmp");

    if (bmp == NULL)

    {

        printf("bmp_open error \n");

        return;

    }

    

    int bmpWideth = bmp->u.r8888.i.biWidth;

    

    //the giving data

    unsigned char* pos = bmp->pdata;

    printf("pos[0] = %d %d %d \n", *pos, *(pos+1), *(pos+2) );

    printf("data size = %d\n", bmp->dataSize);

    printf("data type = %d\n", bmp->tpye);

    

    int bpp = 3;

    if (bmp->tpye == eRGBX_8888)

    {

        bpp = 4;

    }

    printf("bytes per pix = %d\n", bpp);

    

    int pix = 0;

    unsigned char r, g, b;

    //scan each row, so loop the height first

    for (j = 0; j < 700; j++)

    {

        for (i = 0; i < bmpWideth; i++)

        {

            b = *pos & 0xff;;

            g = *(pos + 1) & 0xff;

            r = *(pos + 2) & 0xff;

          

            pix = r | (g << 8) | (b << 16) | (0xff << 24);

            loc32[i + j*(stride)] = pix;

            pos += bpp;//3

        }

    }

 

执行结果

Unknown:/data/local/tmp # ./test-fb-simple

vi.xres = 720

vi.yres = 1280

vi.xresv = 736

vi.yresv = 2560

vi.xoff = 0

vi.yoff = 0

vi.bits_per_pixel = 32

fi.line_length = 2944

fi.smem_len = 11304960

fi.type = 0

====== fb_bitfield red.offset : 0

====== fb_bitfield red.length : 8

====== fb_bitfield red.msb_right : 0

====== fb_bitfield green.offset : 8

====== fb_bitfield green.length : 8

====== fb_bitfield green.msb_right : 0

====== fb_bitfield blue.offset : 16

====== fb_bitfield blue.length : 8

====== fb_bitfield blue.msb_right : 0

====== fb_bitfield transp.offset : 24

====== fb_bitfield transp.length : 8

====== fb_bitfield transp.msb_right : 0

active buffer: 0

check_bmp : bmp width(500) or height(747)

check_bmp : 24 eRGBX_888

bmp->header.bfOffBits = 54

bmp->dataSize = 1120500

pos[0] = 25 46 78

data size = 1120500

data type = 2

active buffer: 1

active buffer: 0

Unknown:/data/local/tmp #

 

在屏幕左上方显示了图片,由于bmp图片的存储格式有正常和倒置2种数据存放方式,这里测试图片是倒置存放的,我们的程序是直接显示,没有根据h的正负值进行处理,所以 看上去倒置了,但是,我们的试验结果已经出来了。

 

 

2 读fb0保存数据

 

早期的Android中,截图操作就是直接读取fb0,但是,现在这样的操作已经行不通了,因为显示系统的设计比较复杂了,有多缓冲等机制,不再是单纯的framebuffer机制,直接获取到的图片可能是静态的,也可能是混乱的图片。

(可以看到,获取到的图片没有状态栏 statusbar, 透明度也异常)

 

 

 

你可能感兴趣的:(Android)