Bug 428238 - Not able to render PSD file with depth other than 8 and 16
Summary: Not able to render PSD file with depth other than 8 and 16
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kimageformats
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.75.0
Platform: Compiled Sources All
: NOR normal
Target Milestone: ---
Assignee: Alex Merry
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-25 16:55 UTC by Gary Wang
Modified: 2022-07-07 16:57 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Example PSD file with depth == 16 (1.15 MB, application/x-zip-compressed)
2020-10-25 16:57 UTC, Gary Wang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Wang 2020-10-25 16:55:05 UTC
SUMMARY

Current kimageformats PSD plugin is not able to render PSD image if the image depth is not 8.


STEPS TO REPRODUCE
1. Find any PSD image which its bit depth is not 8 (mostly it will be 16, there is one example image found on my computer, which can be used for testing).
2. Make sure kimageformats is installed and try load that PSD image with Gwenview.
3. See the result.

OBSERVED RESULT

Image will not displayed correctly.

EXPECTED RESULT

Image can be rendered without problem.


SOFTWARE/OS VERSIONS
I build it manually so maybe the source revision is more useful.
kimageformats git revision: db0b5d571a303e2f3c3e307a541193776e5c26b4

ADDITIONAL INFORMATION

by looking at the source code we can know it doesn't support PSD image with depth != 8 :

https://invent.kde.org/frameworks/kimageformats/-/blob/master/src/imageformats/psd.cpp#L90-92


    if (header.depth != 8) {
        return false;
    }

If we'd like to add additional support like depth == 16, then we probably need to deal with the case when channel size is not 1 (currently it will assume the channel size is always 1, since it only support the case when depth == 8). We could do something like:

    int channel_size = header.depth / 8;
    const quint32 pixel_count = header.height * header.width;
    const quint32 channel_data_length = pixel_count * channel_size;

and we also need to change some other place to make it works. like the place when we calling decodeRLEData(), and the part for reading uncompressed image data. I don't have much experience about this so sorry I cannot make a working patch here :/

Krita can load the image correctly, maybe reuse the code from krita is also a good way to fix this issue. Probably related code:

https://github.com/KDE/krita/blob/8d8dc773da21a0357fd4e33e14253d5b962e9ad0/plugins/impex/psd/psd_image_data.cpp#L53
https://github.com/KDE/krita/blob/4f9cc2c19d3a950e2b4c48d7c87af7c64cb64c59/plugins/impex/psd/psd_pixel_utils.cpp#L240-L243
Comment 1 Gary Wang 2020-10-25 16:57:25 UTC
Created attachment 132735 [details]
Example PSD file with depth == 16

Inside the zip file, there is an example PSD file with depth == 16 and image data doesn't have compression.
Comment 2 Christoph Feck 2020-11-08 05:51:59 UTC
Probably fixed by https://invent.kde.org/frameworks/kimageformats/-/merge_requests/5
Comment 3 Gary Wang 2020-11-08 08:58:31 UTC
(In reply to Christoph Feck from comment #2)
> Probably fixed by
> https://invent.kde.org/frameworks/kimageformats/-/merge_requests/5

!4 and !5 partially fixed this issue for 16-bits PSD files, there are still 32-bits and 1-bit not supported from kimageformats (but krita do support them btw).
Comment 4 Christoph Feck 2020-11-08 13:43:58 UTC
Then !5 is probably wrong. It seems to assume that the only possible depth values are 8 and 16.
Comment 5 Gary Wang 2020-11-08 14:23:43 UTC
(In reply to Christoph Feck from comment #4)
> Then !5 is probably wrong. It seems to assume that the only possible depth
> values are 8 and 16.

The old implementation only supports 8-bits pre channel. Both !4 (by me) and !5 (by @chrisx) are intended to only add 16-bits support to the current PSD reader. Adding 1-bit and 32-bits will also need extra work to do, consider this as a feature request :)

There are CMYK and other color mode not supported by kimageformats' PSD reader, but I think (A)RGB/8 and (A)RGB/16 would cover most of the use case for casual user who need to view PSD files got from friends or from the Internet ;P

Btw I still hope guys from Krita dev team can also take a look but I'm not sure if I'm barking up the wrong tree, Krita's PSD support is much more complete than kimageformats', but I'm not sure if it's possible to port Krita's PSD support to this project and let Krita make use of this project directly if needed.
Comment 6 Mirco Miranda 2022-07-04 10:10:04 UTC
This should be solved by MR !56 (https://invent.kde.org/frameworks/kimageformats/-/merge_requests/56)
Comment 7 caulier.gilles 2022-07-06 11:41:17 UTC
Hi,

Look the story here :

https://bugs.kde.org/show_bug.cgi?id=261088

PSD >= 16 bits encoded as integer or float data is now supported since KF5 5.95.

Best

Gilles Caulier
Comment 8 Gary Wang 2022-07-07 16:57:18 UTC
Yeah, you're right, sorry I forgot to mark it as fixed when I noticed it's fixed. Thanks for the patch and release!