Jump to content

Paint.NET clipboard format interop


Recommended Posts

Hi Paint.NET team,

Thanks for making a great image editor. Apologies if this post is in the wrong forum.

I'm developer of Construct 2, a native (C++) Windows app that creates HTML5 games. See www.scirra.com for more.

I believe lots of our users use Paint.NET for image editing before importing to Construct 2, especially since we recommend it as a better alternative to MS Paint. I'm trying to support Paint.NET's clipboard format so users can easily copy and paste artwork from Paint.NET in to their games. However I'm struggling to find a way to support alpha channels in Paint.NET's clipboard data. Sprites for games almost always use transparency, therefore supporting alpha is essential.

The only clipboard formats I can see coming from Paint.NET version 3.510.4297.28964 are:

CF_BITMAP with all alpha set to 0xFF

CF_DIB with all alpha set to 0xFF

CF_DIBV5 with all alpha set to 0xFF

"PaintDotNet.MaskedSurface". I cannot find any documentation on this format. We are a native app so we cannot use any .NET code to read it. At a glance it also looks very difficult to reverse engineer since it seems to use a variable length header, so I do not believe it is practical to try reverse engineering.

The best thing I can think of all-round is: just support the "PNG" format. Save the selection to a .png file and dump the entire file bytes in to clipboard memory. This has the following advantages:

- we already can read the PNG clipboard format with alpha

- Paint.NET can already read PNG clipboard data from other apps

- it appears to be a semi-standard, since Microsoft Office 2010 can read the format with alpha as well. Our editor supports PNG clipboard format, and we can paste images with alpha preserved in to Word 2010 and Powerpoint 2010. This should help make Paint.NET more useful as well, since it will fix alpha being lost when pasting in to MS Office.

The next best option I can think of is:

- set the correct alpha bytes in the DIBV5 format. Our editor already reads these if they're set, but Paint.NET overwrites them with 0xFF. Hopefully it's straightforward to do that...

Finally the last ditch option is if you can offer some tips to read the PaintDotNet.MaskedSurface format. However this looks like a time consuming option, so I would prefer not to get involved with it.

I strongly recommend supporting the PNG clipboard format since it will improve interoperability with several other programs, not just ours. Unfortunately if we cannot find a solution to this problem, since alpha is used routinely in game development, we will have to start recommending a different tool - a great shame given the quality of Paint.NET.

Thanks and please let me know what your thoughts are!

Edited by AshleyScirra
Link to comment
Share on other sites

Here: http://forums.getpai...__fromsearch__1

Here: http://forums.getpai...__fromsearch__1

and here: http://forums.getpai...__fromsearch__1

I think I have a bug filed to look at supporting the "PNG" format for copying to the clipboard in 4.0.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Having read this thread http://forums.getpaint.net/index.php?/topic/24201-get-pixel-from-another-layer/ and played with illnab 1024's clipboard code (codelab tutorial 4), I couldn't work out why I can access the clipboard BGR values but the Alpha would always be 255 (despite the copied layer being mostly Alpha = 0).

I assume this explains the problem? :/

I fourth the .png proposal, or at least some way of easily accessing the clipboard alpha.

(and look forward to seeing some useful plugins that this would make possible [bB?])

Rick - your ongoing work is really appreciated! :star: :star: :star: :star: :star:

(you've just posted a reply - and the last link looks interesting - but a simple(ish) piece of code for codelab plugins to access clipboard alpha would be very useful).

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Woops, turns out I didn't have a bug. Now I do ...

It'd be simple to just add PNG. However, it'd also be nice to implement this in such a way that it doesn't add a whole bunch of memory usage. To me it'd make sense to put the following data in the clipboard:

1. DIBV5 in the exact same way it's done now, where the image is rendered onto a white background.

2. PNG format, which gives you all the alpha information if you want (straight alpha, not premultiplied)

3. Instead of MaskedSurface, just copy the selection data.

#1 works that way because while I was fixing up clipboard stuff, I noticed that every app out there seems to paste alpha-laden images in its own specially broken way. So I always copy opaque pixels. (one of those links above should have my stream-of-consciousness about this)

#3 is important because right now MaskedSurface ends up duplicating a lot of data from #1.

And you should never try to interpret the MaskedSurface data (you already knew that though). That's an internal implementation detail and subject to change, even if the changes only make different versions of Paint.NET incompatible with each other in order to discourage interop with this private data format.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

>> And you should never try to interpret the MaskedSurface data (you already knew that though).

We talked about "PaintDotNet.MaskedSurface" some time ago. And I'm interpreting it in the meantime. There is no other chance in the moment to get the usefull information about the alpha and the selection path. I need the information in an other application.

There is also a tool in the meantime to save the selections on the clipboard to a selections folder and restore them to the clipboard on request (with a completely transparent bitmap). So you are able to paste just the selection path.

To remove the bitmap data from "PaintDotNet.MaskedSurface" and add a PNG is for sure a good idea and avoids to add addtitonal memory to the clipboard.

Maybe at some time the selection could be added as an SVG path object to the clipboard or additonally as an 8bit mask.

midoras signature.gif

Link to comment
Share on other sites

We talked about "PaintDotNet.MaskedSurface" some time ago. And I'm interpreting it in the meantime. There is no other chance in the moment to get the usefull information about the alpha and the selection path. I need the information in an other application.

You should be prepared for your app to break then, on any Paint.NET update.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

You should be prepared for your app to break then, on any Paint.NET update.

For sure. It's a private and undocumented format (as the .pdn file type). The verification checks in the code should catch any changes in the format.

BTW: Many users are happy that there is a plugin for i.e Irfanview to view composite image, layers and channels of .pdn files.

midoras signature.gif

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...