-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
beta
-
generic
-
generic
Name: gsC80088 Date: 03/09/99
Summary:
ReplicateScaleFilter fails to work properly when the origin of the input pixel buffer is not the origin
of the image.
Version:
I used java full version "Solaris_JDK_1.1.6_04"; however, the bug is also present in the Java 1.2
version.
ReplicateScaleFilter fails to filter the image data properly properly when the first value of the input
pixel buffer does not correspond to the first pixel in the image. In particular, the filter will fail when
off=0 but x>0 (see API). The result under this condition is the rendering of that region will be shifted
cyclicly (i.e. a chunk of the data from the left side of the region will appear on the right). Often an
ArrayIndexOutOfBoundsException is also thrown.
The bug can be traced this failure to a bug within ReplicateScaleFilter's setPixels() methods. Consider this
excerpt:
for (int dy = dy1; (sy = srcrows[dy]) < y + h; dy++) {
int srcoff = off + scansize * (sy - y);
int dx;
for (dx = dx1; (sx = srccols[dx]) < x + w; dx++) {
outpix[dx] = pixels[srcoff + sx]; // <=== incorrect
}
if (dx > dx1) {
consumer.setPixels(dx1, dy, dx - dx1, 1,
model, outpix, dx1, destWidth);
}
}
When the data is copied to outpix, it should be retrieved from pixels relative to the start of the pixel
buffer. srcoff gives the necessary offset in y; however, sx is the offset in relative to the source image's
origin, which is not correct. Just as y was subtracted from sy 3 lines above, x should be subtracted from
sx; i.e.:
outpix[dx] = pixels[srcoff + sx - x]; // <== correct
Example code:
A demonstration of this bug can be viewed with my ReplicateBugTest applet
(http://monet.astro.uiuc.edu/~rplante/topics/java/ReplicateBugDemo.html).
Source code is available there as well.
Ramifications:
This bug will manifest itself whenever ReplicateScaleFilter is used in conjunction with a
CropImageFilter with a negative cropX value (which one might do to pad an image). It is also likely to
come up when a large image is rendered and sent in smaller chunks that are not a full image width
wide.
(Review ID: 54896)
======================================================================