Fix DrawLineAa anti-aliasing inconsistency at certain angles#95
Fix DrawLineAa anti-aliasing inconsistency at certain angles#95
Conversation
Co-authored-by: reneschulte <7439129+reneschulte@users.noreply.github.com>
|
Did the Copilot's AI suggested this pull request?! |
|
Hi @epsi1on Yes, I've tried the new Copilot Coding Agent with this task, Very impressive how it works and it seems to have fixed the issue. But could you double check, please? Before I merge it in? |
reneschulte
left a comment
There was a problem hiding this comment.
Looks good. @copilot have you tried compiling this, running one of the samples and see if the drawn visuals are correct?
Hi, I'm not sure how did copilot fix this issue (file comparison do not give clear result) but I think i've found the problem which is way simpler. Let me check and will make pull request today. However could you please consider putting new nuget package if this issue is done? Thanks |
|
I think i've found the problem, but suddenly a bigger one appeared! Current code converts an ARGB but other places in code, in order to extract A,R,G,B components from the I think the right data type for color is Not sure if i'm right, what do you think? |
|
Signed integer's maximum value is |
|
We are doing bit shifting here, so dealing directly with the bits and bytes. int and uint both have 32 bit. |
|
you are right, but this test do not pass if |
|
It's been a while but I think WB uses pre-multiplied alpha, so the alpha is already applied to the RGB. |
I think this way (pre-multiply), transparency is not handled as expected (like when drawing a line with semi-transparent color). I'm not sure how copilot can handle all these and give you a correct solution where we know where is it. |
|
Better both of these items be handled at same time:
Actually my last PR are not approved so i did not made any further PR. I think i can handle this issue. |
|
OK, great. Appreciate it and sorry for my lack of time. |
Issue Summary
When using the
DrawLineAamethod, lines at certain angles were not being properly anti-aliased, resulting in a "stair-step" pattern rather than smooth edges. This was happening because of inconsistent handling of transparency calculations between horizontal and vertical lines.Root Cause
The issue was in the
AALineQ1method which handles the actual drawing of anti-aliased lines:deltax >= deltay), the transparency was calculated with one approachdeltay > deltax), the offset value was inverted (off ^= 0xff) before calculating transparencyThe Fix
The fix makes the transparency calculation consistent between horizontal and vertical lines by:
Before:
After:
This ensures that anti-aliased lines have consistent smoothing at all angles, addressing the issue shown in the screenshots.
Fixes #35.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.