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.

下面是获取RGB数据并将其放入帧缓冲存储器的主要代码.

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

这是我在系统中运行它时得到的结果.

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

LCD显示屏上出现了一个黑色矩形,而不是我要显示的图片.

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 **

推荐答案

根据我的 comments ,我建议你try 一下:

col = 0xFF000000 | (buffer[0][i*3] << 16) | (buffer[0][i*3+1] << 8) | buffer[0][i*3+2];

以确保您的图像是完全不透明的,而不是只有15%不透明的0x0F000000.

Linux相关问答推荐

空字符串和空文件的区别

线程创建会在 Linux 中触发页面错误吗?它与软脏 PTE 有什么关系?

SessionNotCreatedException:无法启动新会话.响应代码 500 在远程服务器上的 Apache Tomcat/10.0.23 上使用 ChromeDriver

使用 sed 命令仅打印正则表达式匹配

命令应在终端关闭后继续运行

有没有办法定义自定义隐式 GNU Make 规则?

在 Linux 中 Select 多个同名的可执行文件

如何在初始化脚本中以特定用户身份运行命令?

为什么我不能将 Unix Nohup 与 Bash For 循环一起使用?

在 64 位 Linux 操作系统上编译 32 位程序导致致命错误

在 Node.JS 中引用相对于应用程序根目录的文件的正确方法

从linux命令行写入串口

在 Linux 上的进程之间传递消息的最快技术?

列出当前目录和所有子目录中特定大小的文件

比较linux中两个未排序的列表,列出第二个文件中的唯一性

try 使用 sudo 将文件附加到根拥有的文件时权限被拒绝

如何运行我所有的 PHPUnit 测试?

事件驱动和异步有什么区别?在 epoll 和 AIO 之间?

在linux中根据内容拆分文件

在 bash 脚本中使用备用屏幕