gpt4 book ai didi

android - 如何将原始 RGB 帧缓冲文件转换为可视格式?

转载 作者:太空宇宙 更新时间:2023-11-03 23:32:30 25 4
gpt4 key购买 nike

我知道之前有人问过这个问题。原帖在这里how to convert 16-bit RGB Frame Buffer to a viewable format?但是我没有得到我想要的输出。

目前我正在处理帧缓冲区。确切的图片是我正在访问安卓手机的帧缓冲区(/dev/graphics/fb0)(通过“adb”shell)。我使用“dd”获取帧缓冲区。

cd /dev/graphics

dd if=fb0 of=/sdcard/fb0.raw bs=1 count=width*height*3 //this width and height are based on mobile screen specification. And 3 is for RGB888

我使用了这段代码 -

#include <stdio.h>
#include <stdlib.h>
#include <bmpfile.h>

int main(int argc, char **argv)
{
bmpfile_t *bmp;
int i, j;
char* infilename;
FILE* infile;
char* outfile;
int width;
int height;
int depth;
unsigned char red, green, blue; // 8-bits each
unsigned short pixel; // 16-bits per pixel
//rgb_pixel_t bpixel = {128, 64, 0, 0};
//make && ./raw565tobmp fb.rgb565 720 480 32 fb.bmp && gnome-open fb.bmp

if (argc < 6) {
printf("Usage: %s infile width height depth outfile.\n", argv[0]);
exit(EXIT_FAILURE);
}

infilename = argv[1];
outfile = argv[5];

infile = fopen(infilename, "rb");
if (NULL == infile) {
perror("Couldn't read infile");
exit(EXIT_FAILURE);
}

width = atoi(argv[2]);
height = atoi(argv[3]);
depth = atoi(argv[4]);

// should be depth/8 at 16-bit depth, but 32-bit depth works better
short buffer[height*width*(depth/16)];
printf("depth: %d", depth);
if (fread(&buffer, 1, height*width*(depth/16), infile) != height*width*(depth/16)) {
fputs("infile dimensions don't match the size you supplied\n", stderr);
}
printf("depth: %d", depth);

if ((bmp = bmp_create(width, height, depth)) == NULL) {
printf("Invalid depth value: '%d'. Try 1, 4, 8, 16, 24, or 32.\n", depth);
exit(EXIT_FAILURE);
}

for (i = 0; i < width; ++i) { // 720
for (j = 0; j < height; ++j ) { // 480
pixel = buffer[width*j+i];

red = (unsigned short)((pixel & 0xFF0000) >> 16); // 8
green = (unsigned short)((pixel & 0x00FF00) >> 8); // 8
blue = (unsigned short)(pixel & 0x0000FF); // 8

rgb_pixel_t bpixel = {blue, green, red, 0};
bmp_set_pixel(bmp, i, j, bpixel);
}
}

bmp_save(bmp, outfile);
bmp_destroy(bmp);

return 0;
}

这个程序的输入 - ./a.out fb0.raw 480 854 24/data/new.bmp

argv[1]=输入文件

argv[2]=宽度

argv[3]=高度

argv[4]=深度

argv[5]=输出文件

最初代码在这里给出how to convert 16-bit RGB Frame Buffer to a viewable format?

现在,在打开 bmp 文件后,我得到的所有内容都是黑色。为什么会这样?

以及如何显示帧缓冲区?

最佳答案

为了不重新发明轮子,我尝试重新使用现有工具:

  1. 获取帧缓冲区:

    adb pull /dev/graphics/fb0 androidFB
  2. 找到我们的帧缓冲文件中使用的格式。为此,我使用实用程序 avconv(但您也可以使用 ffmpeg),并与自制脚本相关联:

    #!/bin/bash

    #Change FB_RESOLUTION value by the android device's resolution
    FB_RESOLUTION=240x320
    OUTPUT_DIR=fbresult

    #format come from: avconv -pix_fmts| cut -f 2 -d " "
    format=(yuv420p yuyv422 rgb24 bgr24 yuv422p yuv444p yuv410p yuv411p gray monow monob pal8 yuvj420p yuvj422p yuvj444p xvmcmc xvmcidct uyvy422 uyyvyy411 bgr8 bgr4 bgr4_byte rgb8 rgb4 rgb4_byte nv12 nv21 argb rgba abgr bgra gray16be gray16le yuv440p yuvj440p yuva420p vdpau_h264 vdpau_mpeg1 vdpau_mpeg2 vdpau_wmv3 vdpau_vc1 rgb48be rgb48le rgb565be rgb565le rgb555be rgb555le bgr565be bgr565le bgr555be bgr555le vaapi_moco vaapi_idct vaapi_vld yuv420p16le yuv420p16be yuv422p16le yuv422p16be yuv444p16le yuv444p16be vdpau_mpeg4 dxva2_vld rgb444le rgb444be bgr444le bgr444be y400a bgr48be bgr48le yuv420p9be yuv420p9le yuv420p10be yuv420p10le yuv422p10be yuv422p10le yuv444p9be yuv444p9le yuv444p10be yuv444p10le yuv422p9be yuv422p9le vda_vld gbrp gbrp9be gbrp9le gbrp10be gbrp10le gbrp16be gbrp16le)


    mkdir $OUTPUT_DIR

    for item in ${format[*]}
    do
    #Loop through operation
    avconv -vframes 1 -f rawvideo -pix_fmt $item -s $FB_RESOLUTION -i androidFB $OUTPUT_DIR/$item.png
    done
  3. 浏览 OUTPUT_DIR 目录以查找具有正确外观的图像。文件的名称是要使用的格式:XXXX.png 要使用的格式将是 XXXX

  4. 您现在可以使用以下命令将帧缓冲区转换为 PNG(不要忘记用正确的值替换分辨率 FB_RESOLUTION 和格式 XXXX)

    avconv -vframes 1 -f rawvideo -pix_fmt XXXX -s FB_RESOLUTION -i androidFB androidFB.png

关于android - 如何将原始 RGB 帧缓冲文件转换为可视格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12456174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com