Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic PSD decoding support #233

Merged
merged 14 commits into from
Oct 6, 2023
Merged

Basic PSD decoding support #233

merged 14 commits into from
Oct 6, 2023

Conversation

qbnu
Copy link
Contributor

@qbnu qbnu commented Aug 29, 2023

Format documentation: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/

Adds support for decoding most common PSDs. If we can't decode them we try to display the embedded JPEG thumbnail instead. The decompression code is from SAIL: https://github.com/HappySeaFox/sail/blob/master/src/sail-codecs/psd/psd.c

Note

The PSD must have been saved with "Maximize Compatibility" in Photoshop. Otherwise the image data section will not contain the flattened image, in which case we just return the thumbnail.

Color Modes

Bitmap - Unsupported
Grayscale - Supported
Indexed - Unsupported
RGB - Supported
CMYK - Supported, but colors will be inaccurate. Similar behavior to IMDisplay.
Multichannel - I don't know what this is, but the two files I could find with it worked.
Duotone - Treated as grayscale, which is what the documentation suggests and the same behavior as ImageMagick and GIMP.
Lab - Supported if LCMS is present. Otherwise it's treated as grayscale.

Bit depths

Only 8-bit PSDs are supported.

Compression Modes

Raw/Uncompressed - I could only find one test file, but it should work.
RLE (run-length encoding) - Supported. Used in the vast majority of PSDs.
ZIP without prediction - Unsupported
ZIP with prediction - Unsupported

Alpha channels

Only supported for RGB PSDs. I couldn't get them to work with Lab.

ICC Profiles

Only supported for RGB PSDs.

EXIF Data

Supported. I added two new fields: "Software" (e.g. Adobe Photoshop CS6, GIMP 2.10.34, etc.) and "Date Time" (used by Photoshop to store modification date).

PSB (Large Document Format)

Thumbnail only

Some useful links

SAIL's PSD implementation:
https://github.com/HappySeaFox/sail/blob/master/src/sail-codecs/psd/psd.c

I looked into using psd_sdk, but I'm not sure how to build it as a DLL.

ImageMagick's implementation might be useful to look at:
https://github.com/ImageMagick/ImageMagick/blob/main/coders/psd.c

Duotone:
https://gitlab.gnome.org/GNOME/gimp/-/issues/19
https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/690

Lab color:
https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/476
https://expertphotography.com/lab-color-photoshop/

Maximize Compatibility/hasRealMergedData:
https://exiftool.org/forum/index.php?topic=12897.0

Detecting whether to use alpha channel:
psd-tools/psd-tools#369

Closes #29 and #228

@sylikc
Copy link
Owner

sylikc commented Aug 29, 2023

Hey, I'm sorry I've been busy for awhile. I'm going to merge in the older PRs in two weeks. And then cut a release since there's been a lot of new and changed features

@qbnu
Copy link
Contributor Author

qbnu commented Aug 29, 2023

@sylikc you should upgrade libjxl to a newer commit before you make the new release. 0.8.2 doesn't have the fix for libjxl/libjxl#2251, so right now all HDR images appear too dark.

@Hrxn
Copy link

Hrxn commented Aug 30, 2023

Is this already fixed in libjxl?
The linked issue is still open, and nothing is mentioned there..

@qbnu
Copy link
Contributor Author

qbnu commented Sep 4, 2023

@Hrxn looks like it
hdr-comp

@qbnu qbnu marked this pull request as draft September 21, 2023 03:15
@sylikc sylikc added the format support Related to add/remove/change of a specific format support. label Sep 23, 2023
@sylikc
Copy link
Owner

sylikc commented Sep 23, 2023

I'm back (life has been especially busy). I pulled in the updated libs, but the libjxl issue is still open. I'm thinking about cutting a release now, there's like tons of changes i've made in the past few months, mostly related to translations, but I really wanted to get the raw stuff in.

@qbnu qbnu changed the title Add support for embedded JPEG thumbnails in PSD files Basic PSD decoding support Sep 24, 2023
@qbnu qbnu marked this pull request as ready for review September 25, 2023 00:48
@qbnu
Copy link
Contributor Author

qbnu commented Sep 25, 2023

@sylikc the version of libjxl you pulled in already has the fix.

@sylikc
Copy link
Owner

sylikc commented Oct 3, 2023

@qbnu should I merge this in now or are you still doing some work on it?

@qbnu
Copy link
Contributor Author

qbnu commented Oct 3, 2023

@sylikc You can merge it. I want to improve it eventually but it works well enough for now.

"Date Time" might not be the best name to use. According to the EXIF spec it's usually used to refer to the last time the file was changed, but I couldn't think of a good name that wouldn't be confused with the filesystem's modification date. If you can think of something better you should change it. Maybe "Last edited date" or "Last edited on"?

@sylikc
Copy link
Owner

sylikc commented Oct 6, 2023

I was just looking at that... in ExifTool I think it's just DateTime, but in JPEGView probably hmm... the spec says it's usually the same as DateTimeOriginal, but it's not guaranteed.

We could just use something like "Exif Modified date:"? When other programs edit and re-save the file, there's no guarantee that that DateTime gets changed... based on your investigation, in Photoshop it looks like it would, but the ExifReader class would read it for all files which may not have been edited? hmm we can revisit this naming later

sylikc added a commit that referenced this pull request Oct 6, 2023
Adds support for decoding most common PSDs.  If decoding fails, display embedded JPEG.

Note: The PSD must have been saved with "Maximize Compatibility" in Photoshop. Otherwise the image data section will not contain the flattened image, in which case we just return the thumbnail.

Color Modes:
- Bitmap - Unsupported
+ Grayscale - Supported
- Indexed - Unsupported
+ RGB - Supported
~ CMYK - Supported, but colors will be inaccurate.
+ Multichannel - Supported
+ Duotone - Treated as grayscale
+ Lab - Supported if LCMS is present. Otherwise it's treated as grayscale.

Bits: Only 8-bit PSDs are supported.

Compression Modes:
+ Raw/Uncompressed - Supported
+ RLE (run-length encoding) - Supported. Used in the vast majority of PSDs.
- ZIP without prediction - Unsupported
- ZIP with prediction - Unsupported

Alpha channels:
+ Only supported for RGB PSDs.

ICC Profiles
+ Only supported for RGB PSDs.

EXIF Data
+ Supported.
  2 new fields added:
  + "Software" (e.g. Adobe Photoshop CS6, GIMP 2.10.34, etc.)
  + "Date Time" (used by Photoshop to store modification date)

PSB (Large Document Format)
+ Thumbnail only

See PR for more all details

Merge PR #233 by https://github.com/qbnu
@sylikc sylikc merged commit 1a816d6 into sylikc:master Oct 6, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format support Related to add/remove/change of a specific format support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants