Search code examples
c#c++winapiantialiasingmagnification

Magnification Windows API - How to add Smoothing/Anti Aliasing


Context

Since Windows 10 version 2004 update, the Magnifier windows application was updated. And as with every update, there are some issues with it.

Since those issues might take a long time to fix, I've decided to implement my own small project full screen magnifier.

I've been developing in c#, .Net 4.6 using the Magnification API from windows magnification.dll . All went good and well, and the main functionality is now implemented. One thing is missing though, a smoothing Mode for pixelated content... Windows Magnifier implements an anti aliasing/ smoothing to the Zoomed in content.

I've checked and the Magnification API, doesn't seem to provide that option.

how do i add smoothing mode to magnifier on windows magnification API?

I'm aware of pixel smoothing methods, but not familiar with win32 API to know where to hook the smoothing method to, before the screen refreshes.

EDIT:

Thanks to @IInspectable answer, after a small search i found this call to the Magnification API in a python project.

Based on that, I wrote this snippet in my C# application , and it works as intended!

[DllImport("Magnification.dll")]
private static extern bool MagSetFullscreenUseBitmapSmoothing(bool useSmoothing);

...

var isMagnifierInitialized = MagInitialize();
var isSmoothingActive = MagSetFullscreenUseBitmapSmoothing(true);

Solution

  • There is no public interface in the Magnification API that allows clients to apply filtering (other than color transforms). This used to be possible, but the MagSetImageScalingCallback API was deprecated in Windows 7:

    This function works only when Desktop Window Manager (DWM) is off.

    Even if it is still available, it will no longer work as designed. From Desktop Window Manager is always on:

    In Windows 8, Desktop Window Manager (DWM) is always ON and cannot be disabled by end users and apps.

    With that, you're pretty much out of luck trying to replicate the results of the Magnifier application's upscaler using the Magnification API.


    The Magnifier application appears to be using undocumented API calls to accomplish the upscaling effects. Running dumpbin /IMPORTS magnify.exe | findstr "Mag" lists some of the public APIs, as well as the following:

    • MagSetLensUseBitmapSmoothing
    • MagSetFullscreenUseBitmapSmoothing

    Unless you are willing to reverse-engineer those API calls, you're going to have to spend your time on another project, or look into a different solution.


    A note on the upscaling algorithm: If you look closely you'll notice that the upscaled image doesn't exhibit any of the artifacts associated with smoothing algorithms.

    Upscaled image

    The image isn't blurred in any way. Instead, it shows sharp edges everywhere. I don't know what upscaling algorithm is at work here. Wikipedia's entry on Pixel-art scaling algorithms lists some that have very similar properties. It might well be one of those, or a modified version thereof.