I know this question has been asked previously. Original thread is here how to convert 16-bit RGB Frame Buffer to a viewable format? But i am not getting my desire output.
Well currently I am dealing with frame buffer. The exact picture is that i am accessing frame buffer(/dev/graphics/fb0) of an android phone (through "adb" shell). I used "dd" to get the frame buffer.
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
I used this code -
#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;
}
Input of this program - ./a.out fb0.raw 480 854 24 /data/new.bmp
argv[1]=input file
argv[2]=width
argv[3]=height
argv[4]=depth
argv[5]=output file
originally the code is given here how to convert 16-bit RGB Frame Buffer to a viewable format?
Now here after opening the bmp file i am getting every thing is BLACK. Why this is so?
And how to display the frame buffer?