How To activate anti-aliasing with Graphics class?

Hello, I need to compare drawing libraries in terms of performance. The tests are made with and without anti-alisasing. I’ve tried to find a function to activate this functionnality in Juce but it wasn’t a success.

Here is the code I’m using:

Image image(Image::ARGB, WIDTH, HEIGHT, true);
Graphics graphic(image);
graphic.setColour(Colours::white);	
graphic.drawLine(0,0, 9999, 9999);

I’ve saved the image in a PNG file, a zoom with IrfanView shows me that anti-aliasing is off.
So, what is the function to activate anti-aliasing ?

Thanks.
Bouba

PS: Sorry it’s not easy to understand me, i’m french :wink:

Well everything’s anti-aliased by default, so no need to activate it.

I didn’t really see the point of spending days writing ugly versions of all the graphics functions, and nobody’s yet complained that it looks too nice.

The EdgeTable class does let you specify how many times it’s oversampled though, so you could use that directly for drawing paths, rather than going via the Graphics class.

I’d be interested to see the results, as I’ve never benchmarked it. None of the graphics stuff uses MMX at the moment though (I keep meaning to do a bit of optimisation there, especially now that Mac is on intel too). What are you comparing with?

Ok, but I tried to draw that line with other libraries. I see grey pixels at the border of the line, but with juce there is only a white line without the effect of anti-aliasing, why ? I’m new to computer graphics, and I think I’ve not again all the bases to understand everything, so sorry if my words are strange. I’ve read that there is multiple solutions to do anti-aliased lines, what is the one used in Juce ? You notice to me that I could use the EdgeTable, for now, how can I simply draw the same line as the previous code in this post in an Image, and then a PNG File ?

I need to find a library to draw musical partitions, I’ve selected 5 libraries to compare. For now I’ve tested Cairo, AGG, QtSVG, ImageMagick (witch seems to be very slow) , and Juce.

Thank your for this quick response, your message makes me realize that I had counsidered the different anti-aliased techniques used in those libraries.

Baptiste

PS: Sorry it’s not easy to understand me, i’m french :wink:

[quote=“bouba”]Ok, but I tried to draw that line with other libraries. I see grey pixels at the border of the line, but with juce there is only a white line without the effect of anti-aliasing, why ? I’m new to computer graphics, and I think I’ve not again all the bases to understand everything, so sorry if my words are strange. I’ve read that there is multiple solutions to do anti-aliased lines, what is the one used in Juce ? You notice to me that I could use the EdgeTable, for now, how can I simply draw the same line as the previous code in this post in an Image, and then a PNG File ?

I need to find a library to draw musical partitions, I’ve selected 5 libraries to compare. For now I’ve tested Cairo, AGG, QtSVG, ImageMagick (witch seems to be very slow) , and Juce.

Thank your for this quick response, your message makes me realize that I had counsidered the different anti-aliased techniques used in those libraries.

Baptiste

PS: Sorry it’s not easy to understand me, i’m french ;-)[/quote]

If you draw a line at exactly 45 degrees, then it’s not going to need any anti-aliasing… Try some more interesting angles and see what you get. Or use Path::addLine to create a path and fill that.

Sounds like you’re missing the point slightly though, if you’re drawing musical notes - for drawing the staff, you should draw the horizontal and vertical lines with fillRect, because that won’t be blurred like an anti-aliased line would be. And for the notes, you’d use paths or fonts, not lines.

Sorry to dig up an old Thread. But, I too have the same question.

I am doing a fillPath on the Graphics object with a solid colour. This is done repeatedly by expanding the path by a fixed value(just like an outer stroke).
With every operation I can see gaps between the filled paths, possibly down to anti-aliasing.
I just wanted to compare the output with anti-aliasing turned on and off.

It was mentioned in this thread that you can specify the EdgeTable class how many times its oversampled.
I checked out the EdgeTable class and didn’t find any interfaces to do the same.

Is there any other method by which anti-aliasing can be turned off?

Care to post a screenshot?

Hi Vinn,

As asked by you, I have attached the Screenshots showcasing the gaps between the paths.

I have showcased a simple case here in which a rectangle has been expanded 3 times by 100 pixels…


Fig 1, a simple fillPath is called (Path happens to be rectangle)


Fig 2, a fillPath is called on an offsetted path(from the boundary of the previous path to an expanded boundary of 100 pixels) - 1st time


Fig 3, a fillPath is called on an offsetted path(from the boundary of the previous path to an expanded boundary of 100 pixels) - 2nd time


Fig 4, a fillPath is called on an offsetted path(from the boundary of the previous path to an expanded boundary of 100 pixels) - 3rd time

As can be seen clearly, every time a fill path is called there are some gaps between the boundaries.


Fig 5, shows a zoomed view of the gap between the boundaries.

This issue can be seen for all kinds of path, not necessarily a rectangle, but for an ellipse, circle etc.
It looks like issue related to translucent pixels coming into the picture due to anti-aliasing.
To verify this only wanted to check whether anti-aliasing can be turned off.

Anti-aliasing cannot be turned off. Obviously if you draw lines that straddle two pixels, then it’ll look blurred when you zoom in.

You can either:
a) Ignore it
b) Draw your content using fillRect (int, int, int, int)
c) Draw your shapes so that they’re aligned with the edges of pixels.

But bear in mind that pixels are shrinking, scale factors are changing, and drawing a 1x1 rectangle does not always mean 1 pixel any more. It’s good practice to design graphics that will look ok at any arbitrary scale factor or sub-pixel alignment.