Bug 419823 - The reference image tool cannot load files with the wrong extension on Windows
Summary: The reference image tool cannot load files with the wrong extension on Windows
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Tools/Reference Images (other bugs)
Version First Reported In: 4.2.9
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Halla Rempt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-07 23:50 UTC by silvershard7
Modified: 2020-04-08 12:45 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
A mountainous landscape screenshotted & downloaded from MapCrunch (253.53 KB, image/png)
2020-04-07 23:50 UTC, silvershard7
Details

Note You need to log in before you can comment on or make changes to this bug.
Description silvershard7 2020-04-07 23:50:00 UTC
Created attachment 127375 [details]
A mountainous landscape screenshotted & downloaded from MapCrunch

SUMMARY
When I try to select a screenshot I've downloaded from mapcrunch as a reference image I get the error message "Could not load C:/Users/(name)/Desktop/References/Environment/Photography/MapCrunch/28508396.png."
It works with any other image file on my computer that I've tested, even if it's a file from that same directory. Renaming or moving the screenshots doesn't fix the problem either.
The tool is able to insert the images if I drag them to my browser and copy from there, and use the "paste reference image from system clipboard" option.

STEPS TO REPRODUCE
1. Select "Reference Image Tool"
2. Go to Tool Options and select "Add Reference Image"
3. Navigate to and select the file

OBSERVED RESULT

"Could not load C:/Users/(name)/Desktop/References/Environment/Photography/MapCrunch/28508396.png."

EXPECTED RESULT

Image is inserted as a reference image.

SOFTWARE/OS VERSIONS
Windows: 10
Qt Version: 5.12.7
Comment 1 Halla Rempt 2020-04-08 10:28:57 UTC
I have no problems inserting that image as a reference image, but: it's a jpeg image not a png image. Opening with another image viewer gives the following error:

libpng error: Not a PNG file
QImageReader::read() using format hint "png" failed: "Unknown error"
A bad Qt image decoder moved the buffer to 8 in a call to canRead()! Rewinding.
Image format is actually "jpeg" not "png"

I'll reboot to Windows to see whether has more problems with mis-named image files than Linux.
Comment 2 Halla Rempt 2020-04-08 10:36:32 UTC
Yes, on Windows the detection of the file type is different than on Linux, apparently, and depends only on the extension.
Comment 3 Halla Rempt 2020-04-08 12:13:36 UTC
Curiouser... Even if I rename it to .jpg, the image fails to load on Windows.
Comment 4 Halla Rempt 2020-04-08 12:45:08 UTC
Git commit f35fba8e4a6bab6b2d037044e2569f0c184278c8 by Boudewijn Rempt.
Committed on 08/04/2020 at 12:43.
Pushed by rempt into branch 'master'.

Use QImageReader to read the reference images

QImage::load can in some versions of Qt refuse to load an image
with the wrong extension, e.g. a file.png that's actually a jpeg
file. By using QImageReader we can make sure Krita only checks
the actual contents of the image to determine its type.

M  +12   -2    libs/ui/KisReferenceImage.cpp

https://invent.kde.org/kde/krita/commit/f35fba8e4a6bab6b2d037044e2569f0c184278c8
Comment 5 Halla Rempt 2020-04-08 12:45:24 UTC
Git commit 64737d8390534239bf02de9421bd210ddb05c6e4 by Boudewijn Rempt.
Committed on 08/04/2020 at 12:45.
Pushed by rempt into branch 'krita/4.3'.

Use QImageReader to read the reference images

QImage::load can in some versions of Qt refuse to load an image
with the wrong extension, e.g. a file.png that's actually a jpeg
file. By using QImageReader we can make sure Krita only checks
the actual contents of the image to determine its type.
(cherry picked from commit f35fba8e4a6bab6b2d037044e2569f0c184278c8)

M  +12   -2    libs/ui/KisReferenceImage.cpp

https://invent.kde.org/kde/krita/commit/64737d8390534239bf02de9421bd210ddb05c6e4