您尚未登录。

楼主 #1 2020-03-31 18:31:01

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

求助 qt 如何改为rgb565

问题描述:
    我的lcd 使用的是spi lcd st7789 的驱动,它是以rgb565 作为色彩输出到 /dev/fb0 的。但是这也导致了我的qt 界面色彩输出无法还原,qt输出的是rgb8888。请问大神们有解决方法嘛???驱动是直接用的内核原有的驱动 设备书描述如下
 

 &spi0{
    #address-cells = <1>;
    #size-cells = <0>;

    status = "okay";

//    pinctrl-names = "default";
//    pinctrl-0 = <&spi1_pins &spi1_cs_pins>;
//    cs-gpios = <&pio 0 11 GPIO_ACTIVE_HIGH>; 

   ips13: ips13@0{
        compatible = "sitronix,st7789v";
        reg = <0>;
        status = "okay";

        spi-max-frequency = <50000000>;
        rotate = <0>;
        fps = <25>;
        buswidth = <8>;
        dc-gpios = <&pio 0 11 GPIO_ACTIVE_HIGH>;     /* PA11 */
        reset-gpios = <&pio 0 12 GPIO_ACTIVE_HIGH>; /* PA12 */
 //       led-gpios = <&pio 0 0 GPIO_ACTIVE_LOW>;  /* PA0 */
        debug = <0x0>;
        spi-cpha;
		spi-cpol;
    };


};
 

测试图片如图
FluxBB bbcode 测试

最近编辑记录 wugang0420 (2020-03-31 19:18:12)

离线

#2 2020-03-31 18:37:01

孤星泪
会员
注册时间: 2020-03-18
已发帖子: 235
积分: 231

Re: 求助 qt 如何改为rgb565

三原色输出正常吗?

离线

楼主 #3 2020-03-31 18:53:03

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

离线

楼主 #4 2020-03-31 18:53:48

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

孤星泪 说:

三原色输出正常吗?

直接通过rgb565 刷fb0 是正常的

离线

#5 2020-03-31 18:59:44

孤星泪
会员
注册时间: 2020-03-18
已发帖子: 235
积分: 231

Re: 求助 qt 如何改为rgb565

wugang0420 说:

直接通过rgb565 刷fb0 是正常的

也就是说 RGB888 刷 fb0 不正常?

离线

楼主 #6 2020-03-31 19:17:11

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

孤星泪 说:

也就是说 RGB888 刷 fb0 不正常?

对啊,关键是哪个屏的格式原来就是rgb565的屏,但是qt 往fb0输出的是rgb8888。不知道怎么转换

离线

#7 2020-03-31 20:01:31

firstman
会员
注册时间: 2019-04-06
已发帖子: 279
积分: 279

Re: 求助 qt 如何改为rgb565

记得Qt会自动根据fbX自动适配像素分辨率, 我感觉你的驱动和硬件没有匹配好.

buildroot 编译一个fbtest 测试程序检测试一试.

离线

#8 2020-03-31 22:01:22

hexenzhou
会员
注册时间: 2020-03-24
已发帖子: 21
积分: 5

Re: 求助 qt 如何改为rgb565

驱动的lcd配置输出不对,应用层的ioctl程序会查询lcd驱动的液晶屏颜色模式,显然你的驱动返回了rgb888的24位模式,而不是正确的rgb565格式。

离线

楼主 #9 2020-04-01 18:07:46

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

hexenzhou 说:

驱动的lcd配置输出不对,应用层的ioctl程序会查询lcd驱动的液晶屏颜色模式,显然你的驱动返回了rgb888的24位模式,而不是正确的rgb565格式。


是rgb 565 啊,但是系统输出是bgr565 因为我配置为bgr后,开机的企鹅脚才是正常的黄色,rgb 显示的是蓝色,下面是我读的配置信息

 

the fixed information is as follow:
id=fb_st7789v
sem_start=0
smem_len=115200
type=0
line_length=480
mmio_start=0
mmio_len=0
variable information is as follow:
The xres is :240
The yres is :240
xres_virtual=240
yres_virtual=240
xoffset=0
yoffset=0
bits_per_pixel is :16
red.offset=11
red.length=5
red.msb_right=0
green.offset=5
green.length=6
green.msb_right=0
blue.offset=0
blue.length=5
blue.msb_right=0
transp.offset=0
transp.length=0
transp.msb_right=0
height=0
width=0
buffersize:115200

离线

楼主 #10 2020-04-01 18:13:00

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

hexenzhou 说:

驱动的lcd配置输出不对,应用层的ioctl程序会查询lcd驱动的液晶屏颜色模式,显然你的驱动返回了rgb888的24位模式,而不是正确的rgb565格式。

配置为bgr 后qt 颜色 红色变为了灰绿色 ,绿色变为了紫色,蓝色变为了浅蓝色,很奇怪,但是自己通过刷fb0 ,显示会正常,系统默认以bgr 输出,很奇怪不知道怎么配置。大神有方法嘛?

离线

#11 2020-04-01 18:29:18

小智
会员
注册时间: 2019-10-16
已发帖子: 109
积分: 86

Re: 求助 qt 如何改为rgb565

你使用qt直接操作的fb0吧?直接操作Framebuffer ?

离线

楼主 #12 2020-04-01 18:45:18

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

小智 说:

你使用qt直接操作的fb0吧?直接操作Framebuffer ?

qt直接操作的fb0 ,还能怎么操作呢??

export LD_LIBRARY_PATH=/opt/qt5.9-install/lib:/lib:/usr/lib:/usr/local/tslib/lib
export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/qt5.9-install/plugins
#export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
export QT_DEBUG_LUGINS=1
 
export QT_QPA_PLATFORM=linuxfb:fb=linuxfb:fb=/dev/fb0:size=240x240:mmSize=240x240:offset=0x0:tty=/dev/tty1
export QT_QPA_FONTDIR=/opt/qt5.9-install/fonts

# export QT_QPA_EGLFS_WIDTH=240
# export QT_QPA_EGLFS_HEIGHT=240
#export QT_QPA_EGLFS_DEPTH=16
# export QT_QPA_EGLFS_PHYSICAL_WIDTH=240
# export QT_QPA_EGLFS_PHYSICAL_HEIGHT=240
#export QT_QPA_EGLFS_FORCE888

离线

#13 2020-04-01 19:05:35

小智
会员
注册时间: 2019-10-16
已发帖子: 109
积分: 86

Re: 求助 qt 如何改为rgb565

建议看看qt-everywhere-opensource-src-5.9.8\qtbase\src\plugins\platforms\linuxfb下面qlinuxfbscreen.cpp的源码,

static int determineDepth(const fb_var_screeninfo &vinfo)
{
    int depth = vinfo.bits_per_pixel;
    if (depth== 24) {
        depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
        if (depth <= 0)
            depth = 24; // reset if color component lengths are not reported
    } else if (depth == 16) {
        depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
        if (depth <= 0)
            depth = 16;
    }
    return depth;
}

static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth)
{
    const fb_bitfield rgba[4] = { info.red, info.green,
                                  info.blue, info.transp };

    QImage::Format format = QImage::Format_Invalid;

    switch (depth) {
    case 32: {
        const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
                                         {0, 8, 0}, {24, 8, 0}};
        const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
                                         {16, 8, 0}, {24, 8, 0}};
        if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_ARGB32;
        } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB32;
        } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB32;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 24: {
        const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0},
                                       {0, 8, 0}, {0, 0, 0}};
        const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0},
                                       {16, 8, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB888;
        } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB888;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 18: {
        const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0},
                                       {0, 6, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0)
            format = QImage::Format_RGB666;
        break;
    }
    case 16: {
        const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0},
                                       {0, 5, 0}, {0, 0, 0}};
        const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0},
                                       {11, 5, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB16;
        } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB16;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 15: {
        const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0},
                                        {0, 5, 0}, {15, 1, 0}};
        const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0},
                                        {10, 5, 0}, {15, 1, 0}};
        if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB555;
        } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB555;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 12: {
        const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0},
                                       {0, 4, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0)
            format = QImage::Format_RGB444;
        break;
    }
    case 8:
        break;
    case 1:
        format = QImage::Format_Mono; //###: LSB???
        break;
    default:
        break;
    }

    return format;
}

离线

#14 2020-04-01 19:09:40

小智
会员
注册时间: 2019-10-16
已发帖子: 109
积分: 86

Re: 求助 qt 如何改为rgb565

如果是获取参数失败了,那就直接改qt的源码,qlinuxfbscreen.cpp,强制变成rgb565模式的

离线

#15 2020-04-02 08:38:03

hexenzhou
会员
注册时间: 2020-03-24
已发帖子: 21
积分: 5

Re: 求助 qt 如何改为rgb565

要修改lcd驱动,直到默认的企鹅颜色和qt的颜色都正常了。

离线

楼主 #16 2020-04-02 10:29:44

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

hexenzhou 说:

要修改lcd驱动,直到默认的企鹅颜色和qt的颜色都正常了。

改为bgr 企鹅颜色就正常了,但是qt 眼是就奇怪了 红变为了绿色 绿色变为了紫红色,深蓝变为了浅蓝 ,驱动 后续还应如何改呢??

离线

楼主 #17 2020-04-02 10:30:27

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

小智 说:

建议看看qt-everywhere-opensource-src-5.9.8\qtbase\src\plugins\platforms\linuxfb下面qlinuxfbscreen.cpp的源码,

static int determineDepth(const fb_var_screeninfo &vinfo)
{
    int depth = vinfo.bits_per_pixel;
    if (depth== 24) {
        depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
        if (depth <= 0)
            depth = 24; // reset if color component lengths are not reported
    } else if (depth == 16) {
        depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
        if (depth <= 0)
            depth = 16;
    }
    return depth;
}

static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth)
{
    const fb_bitfield rgba[4] = { info.red, info.green,
                                  info.blue, info.transp };

    QImage::Format format = QImage::Format_Invalid;

    switch (depth) {
    case 32: {
        const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
                                         {0, 8, 0}, {24, 8, 0}};
        const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
                                         {16, 8, 0}, {24, 8, 0}};
        if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_ARGB32;
        } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB32;
        } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB32;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 24: {
        const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0},
                                       {0, 8, 0}, {0, 0, 0}};
        const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0},
                                       {16, 8, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB888;
        } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB888;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 18: {
        const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0},
                                       {0, 6, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0)
            format = QImage::Format_RGB666;
        break;
    }
    case 16: {
        const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0},
                                       {0, 5, 0}, {0, 0, 0}};
        const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0},
                                       {11, 5, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB16;
        } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB16;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 15: {
        const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0},
                                        {0, 5, 0}, {15, 1, 0}};
        const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0},
                                        {10, 5, 0}, {15, 1, 0}};
        if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB555;
        } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) {
            format = QImage::Format_RGB555;
            // pixeltype = BGRPixel;
        }
        break;
    }
    case 12: {
        const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0},
                                       {0, 4, 0}, {0, 0, 0}};
        if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0)
            format = QImage::Format_RGB444;
        break;
    }
    case 8:
        break;
    case 1:
        format = QImage::Format_Mono; //###: LSB???
        break;
    default:
        break;
    }

    return format;
}

好的我先改改试试

离线

楼主 #18 2020-04-03 12:50:03

wugang0420
会员
注册时间: 2019-12-11
已发帖子: 15
积分: 0

Re: 求助 qt 如何改为rgb565

感谢各位大佬的支持,问题终于解决了 linux 5.3.6   insmod fbtft_device.ko 就报错了,降低到 linux 4.16 在搞一次 颜色就正常了。不是qt问题啊。萌新感谢各位大佬的支持

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn