What's coming in Paint.NET v3.35

This next update to Paint.NET will fix the usual set of small bugs, introduce a new adjustment (Posterize), fix a major performance blemish related to selections, and add an Intersect selection mode.

As for the small bug fixes, turns out there’s the possibility that Paint.NET will crash if malformed data is in the clipboard from, of all things, certain WPF-based applications. For effects that use IndirectUI, there was a problem with "linked" sliders (using LinkValuesBasedOnBooleanRule). And, it was possible to get around some of the protections that IndirectUI put up to protect Paint.NET from certain types of plugin code. Currently this only seems to affect the Fern Fractal plugin. I’ve e-mailed the author and helped him to find a way to accomplish what he wanted without "breaking the rules," so to speak.

Posterize is an adjustment written by Ed Harvey. It allows you to restrict each of the red, green, and blue channels to only have between 2 to 64 discreet values. Normally each channel has up to 256 values … 0 through 255, which is the range for a byte. This can be useful to give your image a "faux-dithered" look, although of course there are many other creative ways to use it.

Selection performance has been a major sore point in Paint.NET over the last 3 years or so. The initial drawing of a selection is fine — it’s when you go to use union (add) or difference (subtract) combination modes that things get froggy. Really froggy. As in slow. Pathetically slow.

We’ve been using a very brute force algorithm that converts the selection to a bit-mask, then performs the boolean operations on each bit, and then traces the bitmask to recreate a selection path (selections in Paint.NET are stored as a a polygon list). This causes these operations to have performance that is proportional to the number of pixels in the area where the selection is located (its bounding rectangle, actually). On a large or even medium-sized image, these are immediately prohibitve to use. This algorithm was originally developed for use by the Magic Wand tool so that we could do per-pixel tolerance, and then convert back to the polygon representation that was required everywhere else in the application.

I have read both papers and tried to implement both of the algorithms. I have tried this several times, and have come close to completion but never quite made the leap to full comprehension, nor a finished implementation. I never had more than an evening or two in a row to devote to this pursuit — by my estimate, I would need at least a full two or three weeks. Maybe even a full month. These papers are from the academic world, and I haven’t had much practice there for quite some time! As such, the papers are very dense (in a good way) and require many readthroughs to fully understand.

I was never able to find a good implementation of the second algorithm by Grenier and Hormann, which was desirable because it was simpler and supposedly more efficient. In the end, GPC by Alan Murta won out: like previously mentioned, it is an implementation of Vatti’s algorithm, in C. It has been around for quite awhile and has needed no major revisions in many years. So, from an integrator’s standpoint (me!), it is the simplest and safest solution. I am happy to say that I have just purchased a Commercial Use license from the University of Manchester and that the next update to Paint.NET will be using it to substantially increase performance for selections!

This is a simple case of pragmatism versus idealism: ideally, I would have the time, the patience, and the mental acuity to implement these. In practice, it would take so long to do this myself that the cost of a Commercial Use License is actually the cheaper alternative. So for everyone who has donated to Paint.NET, this is how I’m using your money :) This does affect anyone interested in using the Paint.NET source code for their own commercial purposes: if you need any of the code related to selection stuff, you will have to purchase your own Commercial Use License from the University of Manchester.

The only way to get a feel for the performance increase is to cheat a little, with the current version of Paint.NET. Boot it up and create a 1024×768 image. Now, draw a circle selection that encompasses the whole image. Next, go to the toolbar and where it says "Selection Mode:", click on the down-arrow and choose "Subtract." Next, Draw another circle that is inside of the one you just draw. It’s very very slow. Next, undo this foolish thing you just did. Set the "Selection Mode:" to be "Invert (xor)" (this is the one mode that GDI+ gives you for free!). Now draw that second circle again and notice how smooth everything is. In the next update, this performance will also be there for Add (Union) and Subtract! The usability improvement is real and honest, and I think everyone will really like it.

Next, I’ve decided to add an Intersect selection mode. I’m not sure why I never did this before, to be honest. It was trivial to do, especially since GPC supports it right out of the box. Many other drawing programs offer this — it simply makes sure that the result of combining two selections is the area in which they overlap.

Last, I’m reassigning the keyboard shortcuts for the selection modes. Before, you would hold Control for Add/union, hold the right mouse button for Subtract/difference, and Control+Right for Invert/Xor. These are kind of weird, and non-standard, and plus I needed a key for Intersect. So, in the next update the shortcuts will be Control for Add/union, Alt for Subtract/difference, Control+Right mouse button for Invert/Xor, and Alt+Right mouse button for Intersect.

I’m hoping to have a beta of v3.35 out within a few weeks, and the final release in early-to-mid July.

Blogroll

41 comments

As always, keep up the good work. Seems like I had 3.31 for ages (though now I’m starting to wonder what’s up with the version number jumps (ie: 3.31 to 3.35)). Still, no complaints here (since the one feature I do want is in the “Frequently Asked for Features” possibly slated for v4.0 and yes I can wait patiently).

The “bump amount” is admittedly arbitrary, to an extent — I try to find a number that I feel gives the right impression as to the amount of improvement. A +0.01 bump is strictly for bugfix releases, however. Right now I am doing small improvements to the 3.xx codebase so that I can “buy time” for working on 4.0.

Nice to see an improvement coming there, I have to admit, I noticed the performance degradation there several times now, but one thing is also pretty ugly, performance-wise: The moving lines around the selection. Granted, they’re nice for a single rectangular or circular selection but for really large and/or complex selections things get much worse.

As a quick test to try it out: Start with a fresh image, use Add Noise in default settings, use magic wand with 30 % tolerance and global flood mode.

This is enough to slow down PDN to a crawl on my system (Core 2 Duo, 2 GHz) and it’s apparently done by the UI thread, so menus won’t come up immediately, reaction to mouse clicks and key presses are delayed severely, etc.

For 4.0, do you think you plan on writing your own implementation of the selection algorithm at that point?

I’m no evangelist, and I wouldn’t presume to tell you how to develop your program. I just know that if it were me, and I were the sole developer of such a popular and powerful tool, I’d probably want to depend on foreign code as little as possible.

@Pat VanDusen, to the extent of my knowledge, he isnt actually using ‘foreign code’ as much as he is actually using the math for it, and once you use the improved tools I think you will find that there isnt going to be much better ;)

Pat, using the GPC code is a good thing. It was developed by someone who thoroughly understands the algorithm. The code has been unchanged for awhile, because it has needed no fixes. The interface into the code is exactly what I need. So, in this case, it’s exactly what I should be doing. There’s no need to worry that it is “foreign code,” as I am compiling it and can maintain it myself going forward. I’m not “resorting” to using it. C’mon, should I be writing my own C# compiler too? :)

This is a great paint program. It would be nice to have a SMUDGE tool.
The copy or clone tool could be improved. I have seen clone tools that you can use by placing the cuser in a source picture and then place the target curser in a diffrent picture all on the same layout.

I was wondering if you could get a burn and a dodge feature like on Photoshop. I Prefer to use paint.net than photoshop but this is two of the features i miss.
thanks in advance. thank you so much for providing a program like this for free. it helps those of us photographers who are just starting out!!

o_z — Yes, I found that implementation of the Grenier+Hormann algorith, but for various reasons (which I don’t remember right now), the code was not useful.

GPC has the added benefit of being tried and tested — it is used in other significant software projects. So, I have faith in its stability and correctness, even if the performance potential of its algorithm is less than that of Genier+Hormann’s.

Hi Rick thank you so much for your hard work you have helped so many people and it is inspiring that you have advanced this FREE program into a great photoshop alternative. Thank you so much! Great additions, keep up the good work. I owe you much gratitude as I have created successful professional marketing tools for my business.
-L

Paint.net is great i was wondering if there is editing to cover up blemishes(redness on face, acne, dark circles etc…) Paint.net edited my pictures beautifully and great effects way better then paint! Thank you*

i wander if one of these days the tool guidelines or something like that will be part of paint.net like in wordperfect draw when you have the rulers on the top and side in either inches or centimeters and you can pull a horizontal line and a vertical line for dimensions guideline and draw on them or snap a line to them. again it is very helpful when you want to draw to scale. Just my two cents!

it would be very nice to take the toolbars and attach them into the main toolbar at the top or side instead of having them “float” But besides that the program is wonderful im very surprized to see such a great program for free i would also like to see some more effects but im not gonna cry about it lol Good Job