Ability to turn antialiasing on and off

87 views
Skip to first unread message

Botond Kósa

unread,
Nov 13, 2015, 4:55:38 PM11/13/15
to marlin-renderer
Hi Laurent,

I experienced some strange behavior when trying to turn off antialiasing on a MarlingGraphics2D:
  • If AA is turned off immediately after MarlingGraphics2D instantiation, the first draw(Shape) call results in an NPE:
    java.lang.NullPointerException: null
    at sun.java2d.pipe.AlphaColorPipe.renderPathTile(AlphaColorPipe.java:55) ~[na:1.8.0_65]
    at org.marlin.graphics.AAShapePipe.renderTiles(AAShapePipe.java:191) ~[marlin-graphics.jar:0.2.1]
    at org.marlin.graphics.AAShapePipe.renderPath(AAShapePipe.java:150) ~[marlin-graphics.jar:0.2.1]
    at org.marlin.graphics.AAShapePipe.draw(AAShapePipe.java:79) ~[marlin-graphics.jar:0.2.1]
    at sun.java2d.pipe.PixelToParallelogramConverter.draw(PixelToParallelogramConverter.java:148) ~[na:1.8.0_65]
    at org.marlin.graphics.MarlinGraphics2D.draw(MarlinGraphics2D.java:154) ~[marlin-graphics.jar:0.2.1]
  • Turning off AA after something has been drawn has no effect: further draws will be performed using AA.
Shouldn't MarlingGraphics2D delegate calls to the underlying Graphics when AA is off?

Regards,
Botond

Laurent Bourgès

unread,
Nov 13, 2015, 5:31:34 PM11/13/15
to marlin-...@googlegroups.com
Hi Botond,

MarlingGraphics2D only supports antialiasing rendering for now !

Is it really annoying ? I agree NPE is problematic but do you really need no AA ? please tell me why.


Actually I deliberately hacked the SunGraphics2D pipeline ... see:
https://github.com/bourgesl/marlin-graphics/blob/master/src/main/java/org/marlin/graphics/MarlinGraphics2D.java

First, setRenderingHint(s) method(s) should set validatePipe to true for force revalidating the all java2d pipeline:
   
validatePipe = true;

Moreover, I commented several (unused cases for me) in the method validatePipe (line 833) to simplify MarlinGraphics2D

Notably I disabled XOR / CLIP_SHAPE modes and antialising flag handling code:
/* sg2d.antialiasHint == SunHints.INTVAL_ANTIALIAS_ON */

It may be possible to use the redirect flag to detect unsupported cases and then use the standard java2d pipeline.


Please tell me if it is critical, I could spend some time on this problem at the end of month; I am too busy for now.

Regards,
Laurent


-- 

Botond Kósa

unread,
Nov 13, 2015, 6:15:21 PM11/13/15
to marlin-renderer
Turning off AA temporarily could be useful for performance reasons, when the renderings with and without AA would be visually indistinguishable. For example when drawing polygons with thick borders, we first call fill(Shape) to draw the surface, then draw(Shape) to draw the border. The fill could be performed without AA because the border covers the edge of the surface completely, hiding the jaggies. Then AA would have to be turned on before drawing the border.

It would also be nice if MarlinGraphics2D could be used as a drop-in replacement for any java.awt.Graphics2D, without the need to modify the client code. But the whole thing is not critical. We're not using Marlin in production yet, I was just playing around.

Botond

Botond Kósa

unread,
Mar 2, 2016, 6:11:45 AM3/2/16
to marlin-renderer
Hi Laurent,

I noticed that in marlin-graphics v0.2.2 all graphics operations are redirected to Marlin, even clearRect and fillRect. Since marlin does not support drawing without antialiasing, it has to be turned on, causing a slight performance degradation. I did some quick-and-dirty benchmarks and it turned out that both clearRect and fillRect are performed about 20% slower in v0.2.2 than in v0.2.1.

It would be nice if MarlinGraphics2D delegated all operations to the underlying graphics when AA is turned off. There are some use-cases when drawing without AA would definitely pay off (e.g. we are drawing a full-screen heat map consisting of tiny squares of different color).

Regards,
Botond

Laurent Bourgès

unread,
Mar 3, 2016, 4:18:08 AM3/3/16
to marlin-...@googlegroups.com
Hi Botond,

2016-03-02 12:11 GMT+01:00 Botond Kósa <boton...@idata.hu>:
Hi Laurent,

I noticed that in marlin-graphics v0.2.2 all graphics operations are redirected to Marlin, even clearRect and fillRect. Since marlin does not support drawing without antialiasing, it has to be turned on, causing a slight performance degradation. I did some quick-and-dirty benchmarks and it turned out that both clearRect and fillRect are performed about 20% slower in v0.2.2 than in v0.2.1.

When the affine transform is complex (rotation or shear), it may give better quality if Marlin is used (and performance) than pisces ...
I agree it is slower when antialiasing is disabled (and often clearRect is just needed to reset the image).
 
It would be nice if MarlinGraphics2D delegated all operations to the underlying graphics when AA is turned off. There are some use-cases when drawing without AA would definitely pay off (e.g. we are drawing a full-screen heat map consisting of tiny squares of different color).

I implemented this feature in the latest release:
https://github.com/bourgesl/marlin-graphics/releases

Changes:

  • Only redirect graphics operations to Marlin when the RenderingHints.KEY_ANTIALIASING) is NOT RenderingHints.VALUE_ANTIALIAS_OFF (antialiasing can now be disabled)
  • do not redirect graphics operations to Marlin for rectangular shapes by default; set the System property 'MarlinGraphics.redirectRect=true' to potentially improve the rendering quality for complex affine transforms
Cheers,
Laurent

Botond Kósa

unread,
Mar 3, 2016, 5:57:43 PM3/3/16
to marlin-renderer
Thanks for the quick response. However, marlin-graphics 0.2.3 throws the following exception when trying to create a MarlinGraphics2D for a BufferedImage:

Caused by: java.lang.IllegalStateException: Unable to create MarlinGraphics2D pipeline (MarlinRenderingEngine) !
at org.marlin.graphics.MarlinGraphics2D.<clinit>(MarlinGraphics2D.java:860) ~[marlin-graphics.jar:0.2.3]
... 6 common frames omitted
Caused by: java.lang.NoClassDefFoundError: sun/java2d/ReentrantContext
at org.marlin.graphics.MarlinGraphics2D.<clinit>(MarlinGraphics2D.java:839) ~[marlin-graphics.jar:0.2.3]

I am using Oracle JDK 1.8.0_74.

Botond

Laurent Bourgès

unread,
Mar 4, 2016, 3:30:32 AM3/4/16
to marlin-...@googlegroups.com
Botond,

I fixed the classloader/dependency issue in this marlin-graphics 0.2.3 release:
https://github.com/bourgesl/marlin-graphics/releases/tag/v0.2.3b2

You must use the new marlin-0.7.3.3-Unsafe.jar !

Laurent

Botond Kósa

unread,
Mar 4, 2016, 7:11:11 AM3/4/16
to marlin-renderer
Thanks, it works now.

Botond
Reply all
Reply to author
Forward
0 new messages