Current version

v1.10.4 (stable)

Navigation

Main page
Archived news
Downloads
Documentation
   Capture
   Compiling
   Processing
   Crashes
Features
Filters
Plugin SDK
Knowledge base
Contact info
 
Other projects
   Altirra

Archives

Blog Archive

Very high quality Fant bitmap scaling

After seeing an interesting discussion about image scaling quality in Windows Presentation Foundation (WPF) I decided to take a look at its "High Quality" setting. It's documented in the BitmapScalingMode enum as being a synonym for "Fant" scaling:

http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode.aspx

Unfortunately, being sourced from academic literature, trying to find anything direct on Fant's algorithm results in a maze of links to paywalls and abstracts. After digging around a bit, though, I found enough detailed references and code fragments to figured it out, and also spent some time trying it out in a WPF application. (By the way, the WPF Designer is soooooo slooooooowwwwwww!) Now, WPF essentially supports three bitmap scaling modes: nearest, linear, and Fant. Nearest and linear are, as you'd expect, just point sampling and linear interpolation. Linear (bilinear) mode is restricted to a 2x2 kernel and does not use mipmaps, so it will start aliasing once you get below 70% or so. The Fant algorithm, however, is described as very high quality. Sounds interesting, right?

Well, not really.

It turns out that Fant's algorithm is... a box filter. More specifically, it is equivalent to linear interpolation for enlargement along an axis and a box filter for decimation. From what I gather, Fant's algorithm was originally interesting because of the way that the box filter was implemented, which was amenable to hardware implementation. By modern standards and implemented in software, though, it's unremarkable. I tried it out with some decimation settings on some test images and particularly a zone plate image, and it showed more aliasing than a conventional triangle filter (precise bilinear in VirtualDub) or bicubic decimation filter -- not too surprising for a box filter.

I don't know WPF very well, but from what I can gather, Fant's algorithm was made available because that's what the Windows Imaging Component (WIC) has available under the hood. Thing is, besides the mediocre quality, a box filter doesn't make sense when you are trying to support accelerated rendering since it's more expensive to implement than generating mipmaps and using trilinear filtering, which is already implemented directly in the texture sampling hardware. Box filtering isn't, which means it has to be done manually, which is slower... assuming that WPF even bothers accelerating it. It's also a somewhat awkward limitation since .NET has already had decent bilinear and bicubic decimation support available through System.Drawing (GDI+). Therefore, if you sometimes need to downscale images in your WPF based UI, you might consider prescaling them through GDI+ instead to get better quality.

Comments

This blog was originally open for comments when this entry was first posted, but was later closed and then removed due to spam and after a migration away from the original blog software. Unfortunately, it would have been a lot of work to reformat the comments to republish them. The author thanks everyone who posted comments and added to the discussion.