Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Pixmap from QImage is broken
QtWS25 Last Chance

Pixmap from QImage is broken

Scheduled Pinned Locked Moved Solved General and Desktop
littlecmspixmapimageimage display
15 Posts 5 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ademmler
    wrote on 10 Feb 2022, 17:20 last edited by
    #1

    Hi folks,

    in a sample project I try to implement littlecms as described here.(https://littlecms.com/blog/2020/12/09/using-lcms2-on-qt/)

    All went s fine - until I create the QPixmap to be displayed int the graphic scene.
    For debugging I also save the image to harddisk (next to the executable).

    a) When I load this image into the pixmap it works fine
    b) If I copy the image from memory the result is broken

    Here is my download page for sample projects.
    http://code.ademmler.com

    The effected lines are 94-100.

    Regards & Thx Alex

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    wrote on 11 Feb 2022, 11:30 last edited by ademmler 2 Nov 2022, 11:31
    #15

    Here is the reason and solution. Thanks to Marti Maria - the author of littlecms -
    to sort this out ...

    This program does not work because you missed the part on
    https://littlecms.com/blog/2020/12/09/using-lcms2-on-qt/ that says:

    Alpha channels are supported as long as the image is not using premultiplied alpha. To get alpha channel make sure to include cmsFLAGS_COPY_ALPHA in the flags field. This is explained in LittleCMS documentation.

    So, try: toDisplay = colorManage(sourceImage, profiles, INTENT_PERCEPTUAL, cmsFLAGS_COPY_ALPHA);*

    This fixed the issue for me.

    1 Reply Last reply
    2
  • C Offline
    C Offline
    Christian Ehrlicher Lifetime Qt Champion
    wrote on 10 Feb 2022, 17:59 last edited by
    #2

    Put your qDebug() before the return in MainWindow::colorManage() will show you the warnings. Putting them after the return statement is somewhat useless.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    A 1 Reply Last reply 10 Feb 2022, 20:07
    1
  • S Offline
    S Offline
    SGaist Lifetime Qt Champion
    wrote on 10 Feb 2022, 19:54 last edited by
    #3

    Hi,

    Just in case, there are several return statement in the LittleCMS sample code, you should check all of them.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    A 1 Reply Last reply 10 Feb 2022, 20:10
    0
  • A Offline
    A Offline
    ademmler
    replied to Christian Ehrlicher on 10 Feb 2022, 20:07 last edited by ademmler 2 Oct 2022, 20:13
    #4

    @Christian-Ehrlicher thx for your hint - I have overseen this :-)

    I have done this and here is the output:
    21:12:06: Starting /Users/ademmler/QtTryouts/GraphicsViewer/build/debug/GraphicsViewer.app/Contents/MacOS/GraphicsViewer ...

    Hence no error at all. As i wrote to SGaist the final image (saved to hardest for debugging) is fine. It really seems to be an issue with
    QPixmap pixmap = QPixmap::fromImage(toDisplay);

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    replied to SGaist on 10 Feb 2022, 20:10 last edited by
    #5

    @SGaist the result from littlecms is perfectly fine. As you can see from the image saved next to the executable.
    Especially when I load this into my graphics scene the result is ok:
    QPixmap pixmap;
    pixmap.load("toDisplay.jpg");

    but if I do this:
    QPixmap pixmap = QPixmap::fromImage(toDisplay);

    the image is "distorted/broken) somehow ...

    1 Reply Last reply
    0
  • M Offline
    M Offline
    mchinand
    wrote on 10 Feb 2022, 21:42 last edited by mchinand 2 Oct 2022, 22:15
    #6

    What is the format of the QImage (toDisplay->format())? Can you show exactly what you mean by 'the image is distorted/broken'.

    A 1 Reply Last reply 11 Feb 2022, 09:05
    0
  • C Offline
    C Offline
    Christian Ehrlicher Lifetime Qt Champion
    wrote on 11 Feb 2022, 05:56 last edited by Christian Ehrlicher 2 Nov 2022, 06:09
    #7

    When I run your program, cmsCreateMultiprofileTransform() returns a nullptr and (since I corrected the qDebug - output) get the warning 'Couldn't create color transform !' and then a QMessageBox that the image conversion failed.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    A 2 Replies Last reply 11 Feb 2022, 09:04
    1
  • A Offline
    A Offline
    ademmler
    replied to Christian Ehrlicher on 11 Feb 2022, 09:04 last edited by ademmler 2 Nov 2022, 09:10
    #8

    @Christian-Ehrlicher thx for your response.

    I have corrected my code - as you mentioned - but I do not get this warning.
    I get an broken image displayed. Here is a screenshot:
    http://code.ademmler.com/gvimg01.png

    And here is what qt saved to hard disk:
    http://code.ademmler.com/toDisplay.jpg

    Note:
    I have also contacted the author of little CMS - he wrote this sample code.
    I got stuck between opinions and thoughts

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    replied to mchinand on 11 Feb 2022, 09:05 last edited by ademmler 2 Nov 2022, 09:10
    #9

    @mchinand https://littlecms.com/blog/2020/12/09/using-lcms2-on-qt/

    little cmd uses a different format than qt - that is what the author wrote about it.
    I just try to create a working minimal sample ...

    Here is what the resulting image looks like:
    http://code.ademmler.com/gvimg01.png

    And here is what qt saved to hard disk:
    http://code.ademmler.com/toDisplay.jpg

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    wrote on 11 Feb 2022, 09:26 last edited by
    #10

    And here is the pixmap saved to hard disk:
    http://code.ademmler.com/qtPixmap.jpg

    Which is also ok - hence I do not understand what's going wrong with displaying this ...

    J 1 Reply Last reply 11 Feb 2022, 09:36
    0
  • J Offline
    J Offline
    J.Hilk Moderators
    replied to ademmler on 11 Feb 2022, 09:36 last edited by
    #11

    @ademmler have you checked the format of toDisplay ? Image::save does take guesses if the format is missing or wrong.
    Also you should check the return type of save, in case saving fails and you actually see the file of a previous attempt


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    A 2 Replies Last reply 11 Feb 2022, 09:39
    0
  • A Offline
    A Offline
    ademmler
    replied to Christian Ehrlicher on 11 Feb 2022, 09:38 last edited by
    #12

    @Christian-Ehrlicher said in Pixmap from QImage is broken:

    When I run your program, cmsCreateMultiprofileTransform() returns a nullptr and (since I corrected the qDebug - output) get the warning 'Couldn't create color transform !' and then a QMessageBox that the image conversion failed.

    Are you working on MacOS or Windows?
    Have you littlecms installed ? Or checked if you can use the libs I provided?

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    replied to J.Hilk on 11 Feb 2022, 09:39 last edited by
    #13

    @J-Hilk Gold idea - I will check.

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    replied to J.Hilk on 11 Feb 2022, 09:49 last edited by
    #14

    @J-Hilk

    Here is what I see in the debugger. Looks like all "images" have content.
    http://code.ademmler.com/debugger.png

    Pls - where can I see the "return value type" in this window?

    1 Reply Last reply
    0
  • A Offline
    A Offline
    ademmler
    wrote on 11 Feb 2022, 11:30 last edited by ademmler 2 Nov 2022, 11:31
    #15

    Here is the reason and solution. Thanks to Marti Maria - the author of littlecms -
    to sort this out ...

    This program does not work because you missed the part on
    https://littlecms.com/blog/2020/12/09/using-lcms2-on-qt/ that says:

    Alpha channels are supported as long as the image is not using premultiplied alpha. To get alpha channel make sure to include cmsFLAGS_COPY_ALPHA in the flags field. This is explained in LittleCMS documentation.

    So, try: toDisplay = colorManage(sourceImage, profiles, INTENT_PERCEPTUAL, cmsFLAGS_COPY_ALPHA);*

    This fixed the issue for me.

    1 Reply Last reply
    2

8/15

11 Feb 2022, 09:04

7 unread
  • Login

  • Login or register to search.
8 out of 15
  • First post
    8/15
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved