如何以编程方式确定android屏幕的bpp和像素颜色格式?

时间:2013-05-25 09:15:54

标签: c linux-device-driver framebuffer android-ndk-r7 bpp

我正在尝试通过Android上的服务器服务将压缩的原始帧缓冲区数据流式传输到PC上的客户端应用程序。在PC上,我想在客户端视图中将此原始数据显示为流式视频,从而实时显示Android设备的屏幕。我知道如何获得屏幕的分辨率, 每像素位数(BPP)以及 Pixel的颜色格式原始数据以编程方式在Android(服务器)端。请帮忙。

我通过互联网找到的只是本机代码。但我真的希望尽可能地将应用程序保持为Java。

从FBIOGET_VSCREENINFO到ioctl获取BPP(每像素位数)如下

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;
    }
}

1 个答案:

答案 0 :(得分:3)

最后想出了如何确定

  • 帧的BPP(每像素位数)
  • Pixel中的实际RGB字节方向
  • 帧缓冲区的大小&个别框架

    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   = %4ld\n",vscreeninfo.xres,vscreeninfo.yres);
        printf(" BPP    = %4ld | Height = %4ld | Width = %4ld\n",vscreeninfo.bits_per_pixel,
                                                                 vscreeninfo.height,
                                                                 vscreeninfo.width);
        printf(" Xres_V = %4ld | Yres_V = %4ld\n",vscreeninfo.height,vscreeninfo.width);
        printf(" Pixel format : RGBX_%ld%ld%ld%ld\n",vscreeninfo.red.length,
                                                     vscreeninfo.green.length,
                                                     vscreeninfo.blue.length,
                                                     vscreeninfo.transp.length);
        printf(" Begin of bitfields(Byte ordering):-\n");     //In my case :
        printf("  Red    : %ld\n",vscreeninfo.red.offset);    //Red    : 16
        printf("  Blue   : %ld\n",vscreeninfo.blue.offset);   //Blue   : 0
        printf("  Green  : %ld\n",vscreeninfo.green.offset);  //Green  : 8
        printf("  Transp : %ld\n",vscreeninfo.transp.offset); //Transp : 24
                  //Hence orientation is : BGRT => (BGR4)RGB32 packed format
        /********************************~VSCREEN DATA************************************/
    
        /*********************************FSCREEN DATA************************************/
        printf("\nFscreen Info:-\n");
        printf(" Device ID : %s\n",fscreeninfo.id);
        printf(" Start of FB physical address : %ld\n",fscreeninfo.smem_start);
        printf(" Length of FB : %ld\n",fscreeninfo.smem_len); //Size of framebuffer in bytes
        printf(" Length of Line : %ld\n",fscreeninfo.line_length);
        printf(" Start of MMIO physical address : %ld\n",fscreeninfo.mmio_start);
        printf(" Length of MMIO : %ld\n",fscreeninfo.mmio_len);
        /********************************~FSCREEN DATA************************************/
    
        close(fbfd);
        return 0;
    }
    

参考文献: -