我知道以前有人问过这个问题。原始线程在这里如何将 16 位 RGB 帧缓冲区转换为可视格式?但我没有得到我想要的输出。
好吧,目前我正在处理帧缓冲区。确切的情况是我正在访问安卓手机的帧缓冲区(/dev/graphics/fb0)(通过“adb”外壳)。我使用“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]=输出文件
最初这里给出的代码如何将 16 位 RGB 帧缓冲区转换为可视格式?
现在在这里打开 bmp 文件后,我得到的一切都是黑色的。为什么会这样?
以及如何显示帧缓冲区?