JDK-6293336 : Black border appears at edges of some images in BILINEAR interpolation mode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0,5.0u4
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8,windows_xp
  • CPU: x86,sparc
  • Submitted: 2005-07-01
  • Updated: 2011-12-27
  • Resolved: 2005-10-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When the gc transform is a translation with no scaling (scale is 1.0 in x and y), a black border sometimes appears around some sides of some images if the RenderingHints.KEY_INTERPOLATION is set to RenderingHints.VALUE_INTERPOLATION_BINLEAR or BICUBIC.  Some images drawn in this mode appear fine, while others have a black border on the left and top, or right and bottom if the scale factor is exactly 1.0.

Setting the value to VALUE_INTERPOLATION_NEARESTNEIGBOR works fine in all cases, but looks very bad when actually scaled.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
A component that is painted similar to the method below might cause this.  (Unfortunately, I do not have a good, isolated test-case for this, and the below is copied and pasted together from several sources to illustrate the conditions.)

public void paint(Graphics gc)
{
    gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                          RenderingHints.VALUE_INTERPOLATION_BILINEAR);

     AffineTransform toPixelScaleAt = new AffineTransform();
     toPixelScaleAt.translate(
                             (paintExtents_.getX() - paintExtents_.getEndX()) / 2d,
                             (paintExtents_.getY() - paintExtents_.getEndY()) / 2d);

     gc.drawImage(image_, toPixelScaleAt, this);
}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The image would be drawn.
ACTUAL -
The image is drawn, only for some images, a 1-pixel black border appears along the left and top, or along the right and bottom.


REPRODUCIBILITY :
This bug can be reproduced often.

CUSTOMER SUBMITTED WORKAROUND :
Scaling by a tiny amount, such as:

    gc.scale(1.000001, 1.000001);

Seems to avoid the problem, and also slow down drawing.
###@###.### 2005-07-01 08:19:01 GMT

Comments
EVALUATION This bug surfaced when we fixed a bug related to the handling of image transforms with fractional translation components. Such transforms can affect the results of a scale operation when filtering is enabled because each pixel is now blended with its neighbors, but such translations components used to be ignored and the location rounded to the nearest integer. Once we started honoring the fractional translation components these operations which used to map into simple image copies, now required an image transform operation. In 1.5, when the operations in the test case started invoking image transform operations, they started running into some long-standing bugs in the image transform code, one of which is that we sometimes zero out the corners or edges of the bounds of a transformed image. Some of the cases where we zero out these bounds can be fixed with some more sophisticated glue code to our image transformation module, but all of these bugs were fixed much more comprehensively in Mustang by replacing our reliance on the older image transformation module with more direct image transformation loops designed to manage the entire operation much better - including the handling of edge and corner conditions which were a major failure of the older code. I will close this bug as a duplicate of the more general Mustang image transformation fixes.
08-10-2005