-
Notifications
You must be signed in to change notification settings - Fork 127
Fix DrawLineAa anti-aliasing inconsistency at certain angles #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: reneschulte <[email protected]>
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 WriteableBitmapEx/Source/WriteableBitmapEx/WriteableBitmapBaseExtensions.cs Lines 58 to 72 in 5939fb6
but other places in code, in order to extract A,R,G,B components from the WriteableBitmapEx/Source/WriteableBitmapEx/WriteableBitmapAntialiasingExtensions.cs Lines 87 to 90 in 5939fb6
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.