TagStudio icon indicating copy to clipboard operation
TagStudio copied to clipboard

feat: render `.pdn` thumbnails.

Open Sola-ris opened this issue 4 months ago • 8 comments

Summary

Add support for rendering .pdn thumbnails. Fixes https://github.com/TagStudioDev/TagStudio/issues/1147

.pdn files have an XML header that contains the thumbnail as a base64 encoded .png file. The file layout is the following:

  • 4 byte magic number (PDN3)
  • 24-bit little-endian int specifying the header's length
  • The XML header
  • The actual image data which we don't care about

The header itself looks like this:

<pdnImage width="800" height="600" layers="1" savedWithVersion="5.109.9343.2610">
    <custom>
        <thumb png="base64 string" />
    </custom>
</pdnImage>

Sources for the file format

  • http://justsolve.archiveteam.org/wiki/Paint.NET_image
    • Apparently there's a compresed version of the file format, but I couldn't get Paint.NET to produce that one
  • https://github.com/rivy/OpenPDN
    • https://github.com/rivy/OpenPDN/blob/master/src/Data/Document.cs#L64-L120
    • https://github.com/rivy/OpenPDN/blob/master/src/DocumentWorkspace.cs#L2594-L2610
  • https://github.com/addisonElliott/pypdn/blob/master/pypdn/reader.py#L142-L143
  • The test file opened in a text editor

Before

before

After

after

File used for testing

pdn.zip (The actual file is archived since GitHub doesn't allow uploading .pdn files)

Tasks Completed

  • Platforms Tested:
    • [ ] Windows x86
    • [ ] Windows ARM
    • [ ] macOS x86
    • [ ] macOS ARM
    • [x] Linux x86
    • [ ] Linux ARM
  • Tested For:
    • [x] Basic functionality
    • [ ] PyInstaller executable

Sola-ris avatar Sep 24 '25 20:09 Sola-ris

.pdn files have an XML header that contains the thumbnail as a base64 encoded .png file.

Well that's convenient

TrigamDev avatar Sep 24 '25 20:09 TrigamDev

Transparent backgrounds appear to be interpreted as pure black in the thumbnail preview, but not in the sidebar preview.

TrigamDev avatar Sep 25 '25 23:09 TrigamDev

I'll take a look

Sola-ris avatar Sep 26 '25 13:09 Sola-ris

Regular PNGs have a background added, if they're in RGBA. I've given the thumbnail the same treatment with-background

Sola-ris avatar Sep 26 '25 14:09 Sola-ris

I haven't noticed any other images in my library with a transparent background having a background added. And I'd argue that if it is a behavior in other file types, it should be fixed as it's very unintuitive and unwanted behavior.

TrigamDev avatar Sep 26 '25 14:09 TrigamDev

Happens for regular images and exr image. I have no opinion on it, but I don't think it's something that should be changed as part of this issue.

Sola-ris avatar Sep 26 '25 14:09 Sola-ris

Yeah I agree that it should be a separate issue.. Thanks for your work on the thumbnail rendering btw, didn't expect someone to start working on these so quickly.

TrigamDev avatar Sep 26 '25 15:09 TrigamDev

You're welcome :D

Sola-ris avatar Sep 26 '25 16:09 Sola-ris