[OpenJDK 2D-Dev] getClip()/getClipBounds() bug fix (of 8004859) causes new bug

Nicolas nicarran at gmail.com
Mon Oct 14 02:11:14 UTC 2013


The getClip()/getClipBounds bug fix
(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8004859) changed
sun.java2d.SunGraphics2D.transformShape(AffineTransform tx, Shape clip)
to use a Rectangle2D.Double instead of Float and this change causes the
rounding (done by casting from double to float) to be lost. The lack of
rounding causes a bug on my program when using the jre 1.7.0.40, which
is not present on 1.7.0.25.  Take a look at the test case
ClippingTest.java (attached), it draws clippingOn40.png (attached) when
running the JRE 1.7.0.40, and clippingOn25.png (attached) when running
JRE 1.7.0.25. Notice that on 1.7.0.25 the drawing does not show the
center darker line... the clipping regions do not overlap.

A fix to this new bug is to change:
----
return new Rectangle2D.Double(matrix[0], matrix[1],
    matrix[2] - matrix[0],
    matrix[3] - matrix[1]);
----
on line 1947 of sun.java2d.SunGraphics2D to:
----
new Rectangle2D.Float((float)matrix[0], (float)matrix[1],
    (float)(matrix[2] - matrix[0]),
    (float)(matrix[3] - matrix[1])
    );
----

My application calculates the clipping regions on screen using doubles
and a procedure slightly different (but equivalent if we take away the
insignificant digits of the calculation) compared to the one used by
SunGraphics2D, so when SunGraphics2D transform them (calculates the
usrClip) there are small differences (due to insignificant digits) that
in some cases end up being magnified to a full pixel [as the clipRegion
is calculated using floor() and ceil() inside the getBounds() called by
SunGraphics2D.validateCompClip()] by the current implementation
(1.7.0.40) and were nicely cut off by the previous (1.7.0.25) when it
rounded the result using Rectangle2D.Float.

Please let me know if I can be of more help,
Nicolas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ClippingTest.java
Type: text/x-java
Size: 1294 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20131013/bcb27ee6/ClippingTest.java>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clippingOn25.png
Type: image/png
Size: 375 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20131013/bcb27ee6/clippingOn25.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clippingOn40.png
Type: image/png
Size: 392 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20131013/bcb27ee6/clippingOn40.png>


More information about the 2d-dev mailing list