Debugging antialiasing algorithms

Erel

B4X founder
Staff member
Licensed User
Longtime User
In case you wondered how it looks to debug antialiasing issues:

SS-2018-10-25_12.44.49.png


The window on the left side is a very useful utility named Magnifixer: http://www.blacksunsoftware.com/screenmagnifier.html
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The new features will be released next week. A short preview:

test.gif


(it looks better in the real program)

The code for the circle and sinus graph:
B4X:
Sub DrawSinus (width As Int)
   Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "logo.png", 32, 32, True)
   Dim source As BCPaintSource = bc.CreatePaintSourceFromBitmap(bmp)
   Dim p As BCPath
   p.Initialize(0, 0)
   For x = 0 To 1000 Step 12
       Dim y As Float = 100 * SinD(x) + 200
       p.LineTo(x, y)
   Next
   bc.DrawPath(p, xui.Color_Red, False, width)
   Do While True
       source.SrcOffsetY = source.SrcOffsetY + 1
       source.SrcOffsetX = source.SrcOffsetX + 1
       bc.DrawCircle2(400, 400, 100, source, True, 0)
       ImageView1.SetBitmap(bc.Bitmap)
       Sleep(50)
   Loop
End Sub
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
1. Would not "Brush" be more consistent nomenclature over "paint source"?
2. The bc variable is what type of object?
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
At this point only DrawPathFull is missing.
What I have created (here) is not very efficient :(
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The new drawing methods are much more complicated. The difference between a single pixel line to an antialiased thick line is huge. The algorithm is completely different.

The new methods include:
- Thick lines.
- Thick rectangles and filled rectangles.
- Thick circles and filled circles.
- Thick paths where the lines are nicely connected:

SS-2018-10-25_18.25.06.png


- Filled paths:

test.gif


The brush can be a simple color or a BitmapCreator (including Bitmaps).
All drawings are antialiased:

SS-2018-10-25_18.28.49.png


Antialiasing is very important on the desktop as most monitors are not high scale. It is also important for using it in XUI2D games as it allows drawing with a scale of 1 and without too much jagged graphics.
 

Star-Dust

Expert
Licensed User
Longtime User
Filledpaths is enough for me. I do not need the rest :p
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, the performance of these methods with simple colors will not be better than Android Canvas. The Android Canvas is very fast. They are faster in B4J and B4i.
If you are already using BitmapCreator (XUI2D for example) then there is a big performance gain because you don't need to convert the Canvas bitmap to BitmapCreator.
 

Star-Dust

Expert
Licensed User
Longtime User
BTW, the performance of these methods with simple colors will not be better than Android Canvas. The Android Canvas is very fast. They are faster in B4J and B4i.
If you are already using BitmapCreator (XUI2D for example) then there is a big performance gain because you don't need to convert the Canvas bitmap to BitmapCreator.
:(
 
Top