News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Help with Antialiasing a circle with GDI+

Started by LordAdef, April 11, 2025, 09:13:39 AM

Previous topic - Next topic

LordAdef

Hi guys,
I glued this example a bit in a hurry, but it works at least. Built with UASM. Attached the zip file with source code and .exe

In short, this is a way to use anti aliasing without GDI+. Purely with GDI.
The .exe file in the zip is using an upscale factor of 4. Meaning... how much 'bigger' we are drawing the thing in the back buffer. 

If interested, all the fun happens in the upscale_draw procedure.

GDI tends to be faster than GDI+. But I didn't benchmark comparing the two systems (mine, and Zedd's).


The left circle is in pure GDI. On the right, the same circle with the process applied:




zedd151

That looks pretty good.  :thumbsup:

No worries about the timing. Where I would use it the speed limiting factor are mostly the users mouse clicks. Unless it will be used for a fast paced game. Then the time it takes could be critical to game performance.

NoCforMe

So it appears that you're really not processing the image at all, apart from scaling it up and back down again, amiright? I mean, you're not applying Bresenham's algorithm or anything like that.

Looks like all the magic happens here
    inv SetStretchBltMode, dc, HALFTONE
due to the HALFTONE parameter.

Pretty slick.
Assembly language programming should be fun. That's why I do it.

LordAdef

Quote from: NoCforMe on April 13, 2025, 06:25:30 AMSo it appears that you're really not processing the image at all, apart from scaling it up and back down again, amiright? I mean, you're not applying Bresenham's algorithm or anything like that.

Looks like all the magic happens here
    inv SetStretchBltMode, dc, HALFTONE
due to the HALFTONE parameter.

Pretty slick.
Yep,

Print the shape upscaled in the back buffer, than print it to your main dc. No processing.

zedd151

Quote from: NoCforMe on April 13, 2025, 06:25:30 AMSo it appears that you're really not processing the image at all
I'd call it minimal processing, since it does do more than nothing.

QuotePretty slick.
Yes, and very good results. I would have to compare several different image sizes between gdi and gdiplus to make a better determination of how good the results are. But so far, looks really good.

LordAdef


LordAdef

Zedd, I've been doing this for quite a while. But for shapes. 
Two things to bare in mind:

1. line thickness expands inward and outwards, and must be scaled. We need to calculate the offset of this expansion outwards, or it may hit the rect boundary.

2. the Drawback: for larger shapes, you need a larger back buffer. I am currently using it to create buttons

zedd151


jj2007

Quote from: LordAdef on April 13, 2025, 06:18:04 AMall the fun happens in the upscale_draw procedure

The docs say you should add this:
    inv SetStretchBltMode, dc, HALFTONE  ;-> downsize back to original anti-aliasing
    inv SetBrushOrgEx, dc, 800, 800, 0
However, I can't see any difference. Well done, Alex :thumbsup:

LordAdef

Quote from: jj2007 on April 13, 2025, 05:21:25 PM
Quote from: LordAdef on April 13, 2025, 06:18:04 AMall the fun happens in the upscale_draw procedure

The docs say you should add this:
    inv SetStretchBltMode, dc, HALFTONE  ;-> downsize back to original anti-aliasing
    inv SetBrushOrgEx, dc, 800, 800, 0
However, I can't see any difference. Well done, Alex :thumbsup:
Thanks Johen!
    inv SetBrushOrgEx, dc, 800, 800, 0

No clue... not broken..didn't fixed it :dazzled:

I am very curious to time both systems and see whats happening

LordAdef

Hi guys,

I've created a new thread in the Laboratory (since is timing related), where I compare the 2 system.
thread is here: https://masm32.com/board/index.php?topic=12708.0