I am working on an embedded Linux system (kernel-5.10.24), there is a LCD display in it.
Now I am trying to show a JPEG picture on the LCD by using libjpeg.
I found an example code on the internet and tried it out in my system.
I found the display is showing a black rectangle when I chose to use RGB888 mode.
Here is the main code to get the RGB data and put it to frame buffer memory.
typedef unsigned int color_t;
///typedef unsigned short color_t;
#define BITS_PER_PIXEL 32
///#define BITS_PER_PIXEL 16
static struct fb_var_screeninfo __g_vinfo;
static color_t *__gp_frame = NULL;
.....
ioctl(fd, FBIOGET_VSCREENINFO, &__g_vinfo);
printf("bits_per_pixel = %d\n", __g_vinfo.bits_per_pixel);
printf("xres_virtual = %d\n", __g_vinfo.xres_virtual);
printf("yres_virtual = %d\n", __g_vinfo.yres_virtual);
printf("xres = %d\n", __g_vinfo.xres);
printf("yres = %d\n", __g_vinfo.yres);
__gp_frame = mmap(NULL, __g_vinfo.xres_virtual * __g_vinfo.yres_virtual *
__g_vinfo.bits_per_pixel / 8, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
......
......
int drawjpg(unsigned int x, unsigned int y, const char *name)
{
color_t col;
row_stride = cinfo.output_width * cinfo.output_components;
printf("width = %d\n", cinfo.output_width);
printf("height = %d\n", cinfo.output_height);
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, buffer, 1);
line = cinfo.output_scanline - 1 + y;
for(i = 0; i < cinfo.output_width; i++) {
#if (BITS_PER_PIXEL == 16)
char b, g, r;
r = (buffer[0][i*3] >> 3);
g = ((buffer[0][i*3+1] >> 2));
b = (buffer[0][i*3+2] >> 3);
col = (r << 11) | (g << 5) | b;
#elif (BITS_PER_PIXEL == 32)
col = (buffer[0][i*3] << 16) | (buffer[0][i*3+1] << 8) | buffer[0][i*3+2];
#endif
*(__gp_frame + line * __g_vinfo.xres + i + x) = col;
}
if (line >= __g_vinfo.yres) {
break;
}
}
.....
}
Here is what I got when ran it in system.
bits_per_pixel = 32
xres_virtual = 720
yres_virtual = 3840
xres = 720
yres = 1280
cinfo.image_width = 442
cinfo.image_height = 442
cinfo.jpeg_color_space = 3
cinfo.num_components = 3
-------------
width = 442
height = 442
There appeared a black rectangle in the LCD display, not the picture I want to show.
I tried to use #define BITS_PER_PIXEL 16
, there are 2 pictures shown in the display. But with 32
there is nothing shown.
With a limited knowledge on framebuffer programing, I think there might be something wrong in RGB data processing.
Since the display supports ARGB, so I changed to use col = 0x0F000000 | (buffer[0][i*3] << 16) | (buffer[0][i*3+1] << 8) | buffer[0][i*3+2];
, and got the same result.
What is wrong with the code when in 32
bit mode?
** I think this question is about programing
, and should NOT be closed **
Per my comment, I would suggest you try with:
col = 0xFF000000 | (buffer[0][i*3] << 16) | (buffer[0][i*3+1] << 8) | buffer[0][i*3+2];
to ensure your image is fully opaque, rather than 0x0F000000 which is only 15/255 opaque.