-
Bug
-
Resolution: Won't Fix
-
P3
-
6u10, 7, 8, 9
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP SP3, also verified on Linux
A DESCRIPTION OF THE PROBLEM :
Drawing on a BufferedImage created as a Raster with an IndexColorModel when the graphics object has antialiasing enabled yields unexpected results. Lines are longer than they should be, placed on completely different coordinates. Filled circles are not drawn as circles, but rather a mess of pixels. Text rendering and drawing existing images, however, seems to work fine.
This is a regression, as this worked fine up until at least 1.6.0_07. We have confirmed it is broken on 1.6.0_13.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the sample code attached: draw lines and boxes with antialiasing on.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Lines should appear, perhaps with some ugly artifacts as antialiasing may not translate well into indexed colors.
ACTUAL -
Lines missing, or drawn on other parts of the screen.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestImageBug
{
public static void main( String args[] ) throws IOException
{
byte[] map = new byte[] {(byte)0x00, (byte)0xff};
ColorModel colorModel = new IndexColorModel( 1, 2, map, map, map );
SampleModel sampleModel = colorModel.createCompatibleSampleModel( 1024, 1024 );
Point origin = new Point( 0, 0 );
WritableRaster writableRaster = Raster.createWritableRaster( sampleModel, origin );
BufferedImage image = new BufferedImage( colorModel, writableRaster, false, null );
Graphics2D graphics = image.createGraphics();
graphics.setColor( Color.WHITE );
graphics.fillRect( 0, 0, image.getWidth(), image.getHeight() );
graphics.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
//
// comment out this line to see a "normal" image
//
graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
for( int i = 0; i < 100; i++ )
{
int x1 = i + ( 10 * i );
int y1 = i + ( 10 * i );
int x2 = x1 + 512;
int y2 = image.getHeight() - ( 10 * i );
graphics.setStroke( new BasicStroke( 2.0f ) );
graphics.setColor( Color.BLACK );
graphics.drawLine( x1, y1, x2, y2 );
graphics.setStroke( new BasicStroke( 4.0f ) );
graphics.setColor( Color.RED );
graphics.drawRect( x1-2, y1-2, 4, 4 );
graphics.drawRect( x2-2, y2-2, 4, 4 );
}
graphics.dispose();
ImageIO.write( image, "gif", new File("output.gif") );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Disabling anti-aliasing works, but it is undesirable to have to include this as a special case for black and white mode.
Release Regression From : 6u7
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP SP3, also verified on Linux
A DESCRIPTION OF THE PROBLEM :
Drawing on a BufferedImage created as a Raster with an IndexColorModel when the graphics object has antialiasing enabled yields unexpected results. Lines are longer than they should be, placed on completely different coordinates. Filled circles are not drawn as circles, but rather a mess of pixels. Text rendering and drawing existing images, however, seems to work fine.
This is a regression, as this worked fine up until at least 1.6.0_07. We have confirmed it is broken on 1.6.0_13.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the sample code attached: draw lines and boxes with antialiasing on.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Lines should appear, perhaps with some ugly artifacts as antialiasing may not translate well into indexed colors.
ACTUAL -
Lines missing, or drawn on other parts of the screen.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestImageBug
{
public static void main( String args[] ) throws IOException
{
byte[] map = new byte[] {(byte)0x00, (byte)0xff};
ColorModel colorModel = new IndexColorModel( 1, 2, map, map, map );
SampleModel sampleModel = colorModel.createCompatibleSampleModel( 1024, 1024 );
Point origin = new Point( 0, 0 );
WritableRaster writableRaster = Raster.createWritableRaster( sampleModel, origin );
BufferedImage image = new BufferedImage( colorModel, writableRaster, false, null );
Graphics2D graphics = image.createGraphics();
graphics.setColor( Color.WHITE );
graphics.fillRect( 0, 0, image.getWidth(), image.getHeight() );
graphics.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
//
// comment out this line to see a "normal" image
//
graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
for( int i = 0; i < 100; i++ )
{
int x1 = i + ( 10 * i );
int y1 = i + ( 10 * i );
int x2 = x1 + 512;
int y2 = image.getHeight() - ( 10 * i );
graphics.setStroke( new BasicStroke( 2.0f ) );
graphics.setColor( Color.BLACK );
graphics.drawLine( x1, y1, x2, y2 );
graphics.setStroke( new BasicStroke( 4.0f ) );
graphics.setColor( Color.RED );
graphics.drawRect( x1-2, y1-2, 4, 4 );
graphics.drawRect( x2-2, y2-2, 4, 4 );
}
graphics.dispose();
ImageIO.write( image, "gif", new File("output.gif") );
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Disabling anti-aliasing works, but it is undesirable to have to include this as a special case for black and white mode.
Release Regression From : 6u7
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.