NickeManarin / ScreenToGif

🎬 ScreenToGif allows you to record a selected area of your screen, edit and save it as a gif or video.
http://www.screentogif.com
Microsoft Public License
23.48k stars 2.17k forks source link

[Feature Request] Add other image scaling algorithms like bilinear or bicubic #387

Open Naetmul opened 5 years ago

Naetmul commented 5 years ago

Problem

The image resized to ~50% of the original size with ScreenToGif showed visibly lower quality than the image resized to ~50% of the original size with Photoshop. The former image had some visible artifacts (something like over-sharpening) due to the scaling.

This kind of problem will also apply when enlarging images.

Cause

System.Windows.Media, which is used in WPF, uses "linear" scaling as the default scaling algorithm as stated in the MS document. There are also other algorithms in System.Windows.Media: NearestNeighbor (lower quality than linear) and Fant (higher quality than linear). The problem is that all the supported scaling algorithms of System.Windows.Media, which are NearestNeighbor, Linear, Fant, do not give us good results.

This is discussed in a StackOverflow question and VirtualDub blog. The followings are talking about the Fant algorithm, which is the highest quality algorithm among them:

In practice, it's a lot more blurry for downscaling than GDI's cubic downscaling, so the theory about averaging sounds about right.

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. ... it showed more aliasing than a conventional triangle filter (precise bilinear in VirtualDub) or bicubic decimation filter -- not too surprising for a box filter.

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.

Therefore, adding the Fant algorithm only seems easy (because we only need to change the option parameter), but it seems not so good.

Suggestion

Add other image scaling algorithms like "bilinear" or "bicubic" scaling algorithms.

Notes

They are already in GDI+ (System.Drawing), but they are not available in System.Windows.Media.

Some notes when using GDI+'s bicubic scaling: InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images

NickeManarin commented 4 years ago

With the next version, Fant and NearestNeighbor were added.

For others algorithms, they need to be implemented manually.