Pixmap from QImage is broken
-
Put your qDebug() before the return in MainWindow::colorManage() will show you the warnings. Putting them after the return statement is somewhat useless.
-
Hi,
Just in case, there are several return statement in the LittleCMS sample code, you should check all of them.
-
@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); -
@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 ...
-
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.
-
@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.pngAnd here is what qt saved to hard disk:
http://code.ademmler.com/toDisplay.jpgNote:
I have also contacted the author of little CMS - he wrote this sample code.
I got stuck between opinions and thoughts -
@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.pngAnd here is what qt saved to hard disk:
http://code.ademmler.com/toDisplay.jpg -
And here is the pixmap saved to hard disk:
http://code.ademmler.com/qtPixmap.jpgWhich is also ok - hence I do not understand what's going wrong with displaying this ...
-
@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 -
@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? -
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.