Paint.NET v3.22 is now available

It’s that time again: a new version of Paint.NET! This release fixes a few minor bugs and adds a new, much-needed Reduce Noise effect. You can download it from the website at http://www.getpaint.net, or use the built-in updater by clicking on Help -> Check for Updates within the application.

Changes:

  • New: “Reduce Noise” effect.
  • Changed: Ctrl+W will now close Paint.NET if zero images are open.
  • Fixed: In Windows XP, when launching web content, sometimes Internet Explorer was used instead of the user’s chosen default browser.
  • Fixed: The Unfocus effect was not handling alpha values properly.
  • Fixed: The Brightness / Contrast adjustment was only displaying its text in English.
  • Fixed: The /auto parameter for the installer now correctly allows for an automated installation. This was inadvertently broken in 3.20.

Enjoy!

Paint.NET v3.22 Beta 2 is now available

There weren’t many changes for this update, but they’re all in the installer so I felt it was very important to get wider testing before trusting the code enough for a final release. Anyway, as usual you can get the update from the website at http://www.getpaint.net/ or you can use the built-in updater from the Help -> Check for Updates menu item. You will need to make sure that “Also check for Beta releases” is enabled, by clicking on the “Options” button after clicking the “Check for Updates” menu item.

Changes since Beta 1:

  • Fixed: Some uncommon installer bugs
  • Fixed: Very poor performance during installation or updating, sometimes causing the removal of the previous version to take 20 minutes

Enjoy!

Refactoring A Mountain: Late-Binding for Paint.NET v4.0

Like I stated earlier, I’ve finally started work on Paint.NET v4.0 (yay!). To that end, I’ll be focusing most of my development time throughout 2008 on this effort. There will still be Paint.NET releases in the meantime, as there is plenty of life left in the 3.xx architecture. There are a lot of small features that Paint.NET lacks and needs to catch up on that are feasible even without the changes I am slowly architecting into the 4.0 branch. I’m also hoping and planning to integrate some of the more popular or useful community plugins (with permission of course!).

A major change in the Paint.NET architecture for version 4.0 is the introduction of a pervasive late-binding and inversion-of-control mechanism. At a glance it looks like a localized version of COM: “give me an object that implements this interface, btw I don’t care what concrete class actually implements it” (actually, in COM you quite often do specify which implementation you want, but bear with me).

It isn’t anything revolutionary, but refactoring it into a code base that weighs in at 150,000 lines of code is a lot of work. It’s being very educational to me to go through and see all the poor code choices that have been made over the last 4 years. If only I had been psychic back then, I would have known the right way to do things! πŸ™‚

Consider a line of code to load an image resource:

.Β Β Β Β  string labelText = PdnResources.GetString(“SomeDialog.SomeControl.Text”);

PdnResources is a static class that contains all the logic for retrieving the string resource from the appropriate language file. However, having this as a static class is a very very bad thing, and this pattern is repeated for many other classes that need to be accessible throughout the application. Any piece of code can load resources, even if it shouldn’t be able to. For example, there is code in the Layer and Document classes to load the default name for a layer, and this is not appropriate for code that is in the data layer of the application. This text should be supplied by whoever is creating the objects, or hooked in at the UI layer somehow instead.

To that end, this code will be moved out of a static class and into a public interface and a concrete, private implementation. A bindings provider (or scope) will serve as the mechanism for accessing it.

public interface IResourcesService { … }

internal sealed class ResourcesService : IResourcesService { … }

bindings.RegisterService<IResourcesService, ResourcesService>();

string labelText = bindings.GetService<IResourcesService>().GetString(
“SomeDialog.SomeControl.Text”);

At first glance, this may not appear to buy much, and is more code that is less expressive. But it allows me several things, including the freedom to move the resource loader, or to hide it from pieces of code (such as plugins, or from the data layer). I can do more granular versioning so that if plugins do need access I can at least continue to change it with more freedom (just introduce a “IResourcesServiceV2” or whatever). I can implement things like pseudo-localization by way of chaining together two implementations of IResourcesService. Logging and fault injection can be made easier, as they can also be implemented as a chained implementation. By “chained implementation” I mean that the normal implementation stays as-is, but a second implementation is registered so that it passes-through method calls while also performing some other service, such as logging or transformation. The primary implementation can then be kept clean and simple.

The “bindings” object would never be available globally or statically. Any object that needs to use it must take it via its constructor. This is proving to be a lot of work to enforce, but I believe it will be worth it. It makes it easier to analyze things like layering and dependency flow if code can’t just magically go and grab resources from static locations, and is instead forced to go through an object that is supplied by its creator/owner. For example, if I don’t want the data layer to be able to load resources, then I simply remove the IResourcesService from its bindings object. The only way to access the concrete class at that point would be via reflection, which is easy enough to detect and combat against.

I plan on extending this pattern to all of the static classes in the SystemLayer assembly as well. Instead of just bluntly calling into the PaintDotNet.SystemLayer.FileSystem static class, for instance, you would ask for the IFileSystemService via your local bindings provider object. The SystemLayer DLL would then have a static class with one function that would be responsible for registering all of the bindings.

This may even make things easier for Miguel de Icaza and his Mono port, Paint-Mono, although it’s too early to tell for certain. Done properly, there could be a PaintDotNet.SystemLayer.NetFxWin32.dll and a PaintDotNet.SystemLayer.MonoLinux.dll, and a simple configuration or command-line switch of some sort would choose which one to use at startup. I’ve paid attention to his blog posts and other documentation and it has brought to light some areas that still need to be separated into the SystemLayer DLL.

And while this could be a boon for Miguel, it’s also good for me and isn’t something I’m necessarily doing to directly help out his porting efforts. What if the differences between the XP and Vista code paths grew so great that I needed two different versions of the SystemLayer DLL? Or, what about a Mac OS version?* Moving to a late binding system and avoiding static classes will make things much, much cleaner. Who knows, maybe I can stuff Windows Forms itself behind an abstraction layer and decouple Paint.NET from it. That’s actually one of the things that the new IndirectUI system in v3.20 has allowed me to practice with: I could port the thing over to WPF or even to a console window, and the effects/plugin code wouldn’t know the slightest difference.

* This should not be taken as an announcement of a plan to release a Mac OS version.

Paint.NET v3.22 – Beta release now available

This release fixes a few minor bugs and adds a new, much-needed Reduce Noise effect. You can get it from the website (http://www.getpaint.net/) or via the built-in updater by going to Help -> Check for Updates. (Make sure that “Also check for beta releases” is enabled, by clicking on the “Options” button after clicking the “Check for Updates” menu item). Final release is tentatively scheduled for mid-January.

Changes:

  • New: “Reduce Noise” effect.
  • Changed: Ctrl+W will now close Paint.NET if zero images are open.
  • Fixed: In Windows XP, when launching web content, sometimes Internet Explorer was used instead of the user’s chosen default browser.
  • Fixed: Unfocus was not handling alpha values properly.
  • Fixed: Brightness / Contrast adjustment was only displaying its text in English.
  • Fixed: The /auto parameter for the installer now correctly allows for an automated installation. This was inadvertantly broken in 3.20.

Typo Bugs – OnScroll() versus OnShown()

I just recently fixed a bug in Paint.NET where I had inadvertently overridden the OnScroll() method instead of the OnShown() method. The code I added was meant to raise the priority of the UI thread while a dialog was initializing (in its constructor), and then drop the priority back to normal once the dialog was finally visible (in OnShown()). This was shown to improve the snappiness of Paint.NET’s UI because it does a lot of processing in background threads, which was then competing with dialog initialization and initial rendering. Since the reversion code was in OnScroll(), which never gets called, the reversion simply never happens. If I’d done a more careful code review, I probably would have caught this.

The reason it was in OnScroll() is because I typed “override OnS” and then expected Visual Studio to auto-complete the method signature. It did this correctly, but I had already overridden OnShown() and so the next match was OnScroll(). Luckily in this case there was no major negative consequence.

Don’t Forget To Accept Pounds!

Awhile ago I blogged about making sure you accept Euros in addition to U.S. dollars. I also blogged on Friday that I had [finally] added Australian dollars to the Paint.NET donations page. Several were quick to comment that I did not have British pounds on there, and so I also decided to put that on the donations page.

You see, the pound is worth even more than the Euro. The former is worth $1.9856 while the latter is currently at $1.4366. And, imagine my surprise when a significant percentage of new donations are now in pounds! In fact, over 30% of them are. The numbers seem smaller – 4 pounds here, 8 pounds there – but it is still good for people to be able to donate in whatever currency they are most comfortable with. With the conversion rates the way they are it generally ends up as a little bonus on my side anyway. The U.S. dollar is just not what it used to be.

So please donate to Paint.NET – just make sure you use anything except U.S. dollars πŸ™‚ And if you’re setting up a donations page for your freeware or other project, you’d do good to accept as many types of currencies as your payment processor(s) will allow (for me, that is PayPal). I’m reminded of the comic by Mike Peters where the kid holds out her hand and asks her dad, “Can I have my allowance for this month?” The dad pulls out a wad of cash and she scowls, “…. in Euros.”
http://cartoonistgroup.com/store/add.php?iid=18715
(sorry folks, can’t inline the image due to their copyright/licensing)

Australian $ added to Paint.NET Donations page

Someone made a blog comment the other day about not having a button on the Paint.NET Donate page for Australian currency. I realized they were totally right and there was no reason to not have it, so today I added it.

Also, freeware developers … do not underestimate having a release close to Christmas time. My donations are up 111% this month compared to November (which, in turn, was up 64% over October). Next month will probably show a sharp downward correction, but that’s fine and is to be expected.

Quick Thoughts on Continuations for UI Code

Continuations in C#, as exposed via the yield keyword and “iterator blocks”, is a seriously underused and under-researched feature. In C++, you can use Win32 fibers to accomplish the same, and this is in fact how they are implemented in the .NET 2.0 runtime. Update: They are not implemented using Fibers. Thanks for the clarification James. Learn something knew every day!

Did you know that you can use these to implement blocks of code that can literally jump between threads? Quite useful for UI code so you can avoid using all sorts of tedious synchronization and messaging primitives, and also avoid having to split your tasks into multiple functions. Instead of writing function 1 which kicks off a task on the thread pool, then function 2 that performs the long-running task (load a file, download some data, compute something useful), and then function 3 that executes on the UI thread when that is done and sets some UI flags … you can write 1 function that is hosted by a dispatcher or executor of some sort, and then use “yield return” to spit instructions at it. Need to report progress? No problem. Switch to the UI thread, tell your ProgressBar control what’s up, then switch back to the background thread. “yield return new SwitchTo(Thread.UI)” and “yield return new SwitchTo(Thread.Background)” are going to prove quite handy for Paint.NET v4.0.

I’ve been experimenting with this concept a little bit, and the results are promising. I have a simple application that has a “AsyncImageBox” control that uses continuations. It has one function, “LoadTheImage” which implements all of the logic for establishing a connection with a server, downloading the image, reporting progress in the UI, and hooking up the final image to the UI. When the block of code needs to do something that must be done on the UI thread (report progress), it just switches over to the UI thread and does it. Then it reverts to the background thread. This is all inside of 1 function of code, there is no “queue this to the thread pool” or “invoke this message over to the other thread” or “wait on this mutex” or “set this signal” nonsense. I can use traditional synchronous/blocking code (aka, “easier to write, read, debug, maintain, understand, etc.”) for all of this.

Usability: Yes, No, Cancel, Huh?

I think MessageBox should be added to the list of banned API’s in Windows. I think it is overused and presents an easy but lazy way for a developer to ask questions that the user shouldn’t have to care about. People never read the text that is presented on them, and as a result the wrong things often happen.

As an example, consider the meeting I had with a CPA today*. I brought along a spreadsheet on a USB stick that detailed some of my finances. While he had it open, he inadvertently made a change to the spreadsheet (not a big deal – it was just a copy). When our discussion and meeting was done, he closed the spreadsheet so that he could return my USB stick. So he clicked on File, and then Exit, and was immediately presented with:

Most of us are used to this dialog and usually know what our answer will be even before we’re asked. We would click “No.” But here’s the interesting thing that I heard him say out loud:

Β Β Β Β CPA: “Yes, I want to close it.”

And then he clicked on the “Yes” button. The dialog was asking him to save it, not confirm his intent to close it. But for some reason he assumed the dialog was asking him to confirm his intent instead of serve a warning. I hardly blame it on a lack of intelligence, but rather on the usability of Excel, et. al. and the terrible “Yes, No, Cancel” pattern that [almost] all developers seem to be stuck on reusing.

If a task dialog pattern had been used instead, he may have clicked on the button that corresponded with his actual intent, which would have been to click “No”. For Paint.NET v3.0, I instituted these all over Paint.NET in an effort to improve usability.

In this case, “Yes” is replaced by “Save” and “No” is replaced by “Don’t Save”. It is much clearer what will happen when you click on them – there is less left to be assumed, extrapolated, or guessed at by the user. In the “Yes, No, Cancel” dialog above, it is not really clear what happens when you click “No” or “Cancel” – for the former, the changes are discarded and the application exits. For the latter, the changes are left in memory and the application stays open.

These dialogs require more code, but only because there are 8 string resources and 5 graphic resources to load or prepare. The code itself is still quite clear and easy to read, and easy to duplicate. I have a class called TaskDialog with a static function that takes all the text and graphics and then prepares a WinForms dialog that is shown modally. The button that was pressed is then returned to the caller.

Anyway, this was an interesting real-life story and I thought it was worth sharing.

* Yes, this is a true story! πŸ™‚

Ed Harvey's Effects updated for Paint.NET v3.20

Ed Harvey has made quite a name for himself on the Paint.NET forum by consistently releasing some of the best and most comprehensive effect plugins. He has just released an updated version of his effects plugin pack that supports Paint.NET v3.20 and uses some of its IndirectUI capabilities.

I highly recommend this plugin pack, so go and download it! In all, there are over 20 effects that go into the Blurs, Distort, and Color effect menus. Here’s a preview:

Original (Olivia Wilde)

Dents (one of his coolest and most popular effects)

Crystalize

Multi View Warp

Simplify