JDK-4989837 : image interpolation under some TXes incorrectly rounds colour components.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2004-02-06
  • Updated: 2005-05-31
  • Resolved: 2005-05-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 betaFixed
Related Reports
Relates :  
Relates :  
Description
The following small example program draws a white image into a 3 byte BGR
image. The graphics used to draw has a Tx with a scale that is very close
to identity but is non-integral
As of the fix for 4916948 this goes through a different code path where
there's apparently rounding errors in the evaluation of the colour
components for the output pixels. the pixels in the source image are
all white but in the destination image they are all(?) 0xfdfefe

The problme is seen on windows (XP) and solaris 9 sparc.
One consequence of this is in printing code where such errors can occur
with fp arithmetic scaling between user, image and printer spaces.
The resulting printout is both not pure white and doesn't compress
using postscript run-length encoding. In one case this caused a spool
file to grow from 300K to 9.5Mb - and take much longer to generate and
print.

import java.awt.*;
import java.awt.image.*;

public class ImgCol {

    public static void main(String args[]) {
	
	int sz = 10;
	BufferedImage bi =
	    new BufferedImage(sz,sz, BufferedImage.TYPE_BYTE_GRAY);
	Graphics g = bi.getGraphics();
	g.setColor(Color.white);
	g.fillRect(0,0,sz,sz);
	System.out.println("pix before="+
			   Integer.toHexString(0xffffff&bi.getRGB(0,0)));
	BufferedImage bgrImg =
	    new BufferedImage(sz,sz, BufferedImage.TYPE_3BYTE_BGR);
	
	Graphics2D g2 = (Graphics2D)bgrImg.getGraphics();
	//g2.translate(0.0001,0.0001);
	g2.scale(1.0001,1.0001);
	g2.drawImage(bi, 0,0,sz,sz,0,0,sz,sz,Color.white,null);
	System.out.println("pix after="+
			   Integer.toHexString(0xffffff&bgrImg.getRGB(0,0)));
    }
}

Comments
EVALUATION There are really two bugs here. The first bug is that a very slight delta from integers in the coordinate transform will trigger full image transformation code when it is really not necessary as the sub-pixel skew should not change the data. Thus, time is being wasted by doing a full transform when a simple image copy would suffice. The second bug is that the image transformation code has roundoff errors in it which cause it to turn white into slightly off-white colors. This effect should be below the visual threshold so it is not a very big problem for screen rendering, but it degrades the accuracy of our image operations, especially when multiple operations are built on top of each other as might occur with a media rich image manipulation program. ###@###.### 2004-02-06 After further consideration it was decided to submit the first bug mentioned above as a new bug (4990624) that will be committed to be fixed in Tiger as that change is a regression from earlier releases. This bug will then specifically deal with the inaccuracies of the image transformation code which results in the off-by-1 pixel results. That issue is an old problem and not a regression so we will not pursue a fix for this bug in the Tiger time frame. Fixing 4990624 will result in this bug being no longer reproducible using the indicated sample code, but a simple change to the code to use a scale factor of more like 1.01 will continue to show the poorly rounded pixel results even after the fix for 4990624 is implemented. ###@###.### 2004-02-06 The errors in interpolation were fixed when the new image transformation pipelines were integrated (see 5051527). I will mark this bug fixed when I develop an automated test case that verifies the correct interpolation... ###@###.### 2005-05-19 03:19:28 GMT
19-05-2005