如何通过编程确定android屏幕的bpp和像素颜色格式



我正在尝试将压缩的原始framebuffer数据流式传输到PC上的客户端应用程序,从Android上的服务器服务。在PC上,我想在我的客户端视图中显示这些原始数据作为流视频,提供Android设备屏幕的实时视图。我知道如何获得屏幕的分辨率,但不是比特每像素(BPP)也不是像素的颜色格式在Android(服务器)端编程的原始数据。请帮助。

我能在网上找到的都是本地代码。但是我真的希望尽可能保持Java定义的应用程序。

从FBIOGET_VSCREENINFO over ioctl获取BPP(bit -per-pixel),如下所示

int main () {
    int fbfd;
    struct fb_var_screeninfo variable_info;
    fbfd=open("/dev/fb0", O_RDWR);
    //in real life, check every ioctl if it returns -1
    ioctl (fbfd, FBIOGET_VSCREENINFO, &variable_info);
    //This is the required BPP value
    switch(variable_info.bits_per_pixel) {
        case 16: //pixel format is RGB_565
            break;
        case 24: //pixel format is RGB_888
            break;
        case 32: //pixel format is RGBX_8888
            break;
    }
}

终于弄明白了如何判定

  • BPP(bit -per-pixel)帧
  • 像素的实际RGB字节方向
  • framebuffer的大小&单个帧

    int main() {
        //Structs defined in "linux/fb.h"
        struct fb_var_screeninfo vscreeninfo;
        struct fb_fix_screeninfo fscreeninfo;
        //Open the framebuffer
        fbfd=open("/dev/graphics/fb0",O_RDONLY);
        if(fbfd==-1) {
            __android_log_print(ANDROID_LOG_ERROR,ERR,
                    "Could not open framebuffer fbfd=%d errno=%d",fbfd,errno);
            return errno;
        }
        //Fetch variable screen info
        ioct=ioctl(fbfd,FBIOGET_VSCREENINFO,&vscreeninfo);
        if(ioct==-1) {
            __android_log_print(ANDROID_LOG_ERROR,ERR,
                    "VSCREEN-IOCTL failed ioct=%d errno=%d",ioct,errno);
            return errno;
        }
        //Fetch fixed screen info
        ioct=ioctl(fbfd,FBIOGET_FSCREENINFO,&fscreeninfo);
        if(ioct==-1) {
            __android_log_print(ANDROID_LOG_ERROR,ERR,
                    "FSCREEN-IOCTL failed ioct=%d errno=%d",ioct,errno);
            return errno;
        }
        close(ioct);
        /**********************************VSCREEN DATA************************************/
        printf("nVscreen Info:-n");
        printf(" Xres   = %4ld | Yres   = %4ldn",vscreeninfo.xres,vscreeninfo.yres);
        printf(" BPP    = %4ld | Height = %4ld | Width = %4ldn",vscreeninfo.bits_per_pixel,
                                                                 vscreeninfo.height,
                                                                 vscreeninfo.width);
        printf(" Xres_V = %4ld | Yres_V = %4ldn",vscreeninfo.height,vscreeninfo.width);
        printf(" Pixel format : RGBX_%ld%ld%ld%ldn",vscreeninfo.red.length,
                                                     vscreeninfo.green.length,
                                                     vscreeninfo.blue.length,
                                                     vscreeninfo.transp.length);
        printf(" Begin of bitfields(Byte ordering):-n");     //In my case :
        printf("  Red    : %ldn",vscreeninfo.red.offset);    //Red    : 16
        printf("  Blue   : %ldn",vscreeninfo.blue.offset);   //Blue   : 0
        printf("  Green  : %ldn",vscreeninfo.green.offset);  //Green  : 8
        printf("  Transp : %ldn",vscreeninfo.transp.offset); //Transp : 24
                  //Hence orientation is : BGRT => (BGR4)RGB32 packed format
        /********************************~VSCREEN DATA************************************/
        /*********************************FSCREEN DATA************************************/
        printf("nFscreen Info:-n");
        printf(" Device ID : %sn",fscreeninfo.id);
        printf(" Start of FB physical address : %ldn",fscreeninfo.smem_start);
        printf(" Length of FB : %ldn",fscreeninfo.smem_len); //Size of framebuffer in bytes
        printf(" Length of Line : %ldn",fscreeninfo.line_length);
        printf(" Start of MMIO physical address : %ldn",fscreeninfo.mmio_start);
        printf(" Length of MMIO : %ldn",fscreeninfo.mmio_len);
        /********************************~FSCREEN DATA************************************/
        close(fbfd);
        return 0;
    }
    
引用

: -

  • Framebuffer数据http://www.ummon.eu/Linux/API/Devices/framebuffer.html
  • 打包的RGB格式http://linuxtv.org/downloads/v4l-dvb-apis/packed-rgb.html V4L2-PIX-FMT-RGB565

相关内容

  • 没有找到相关文章

最新更新