-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
sparc
-
solaris_7
Name: boT120536 Date: 01/16/2001
(submitted against kest-sol-fcs)
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
javac the included java file.
run it with 'java ColorCvtBug <jpeg image>'
If you set 'BUG' (a static class variable) to 'Works' (another static class
variable) the source image will not have Alpha and the program will work
(this should show the program is relatively well formed). If you set it
to 'ColorConvertAlpha' (default) the source image will have an Alpha channel
and the program will die. With 'INSTRUMENT' true (default) you will notice
that the x parameter to 'setSample' is never reset to zero at the start of
a new scan line.
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.image.ColorConvertOp;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.WritableRaster;
import javax.swing.JFrame;
public class ColorCvtBug extends JFrame {
static int Works = 1;
static int ColorConvertAlpha = 2;
static int BUG=ColorConvertAlpha;
static boolean INSTRUMENT=true;
BufferedImage img;
BufferedImage lum;
public ColorCvtBug(Image src) {
MediaTracker track = new MediaTracker(this);
track.addImage(src, 1);
try {
track.waitForID(1);
}
catch (InterruptedException ie) { }
if (BUG == ColorConvertAlpha) {
img = new BufferedImage(src.getWidth(null),
src.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
} else {
// No alpha channel for Working case and Setting Bug.
img = new BufferedImage(src.getWidth(null),
src.getHeight(null),
BufferedImage.TYPE_INT_RGB);
}
Graphics2D g2d = img.createGraphics();
g2d.fill(new Rectangle(0,0,img.getWidth(), img.getHeight()));
g2d.drawImage(src, 0, 0, this);
int width = img.getWidth();
int height = img.getHeight();
ColorModel cm = new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int [] {8,8}, true,
img.getColorModel().isAlphaPremultiplied(),
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
SampleModel sm = new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, width, height, 2, 2*width,
new int [] { 0, 1 });
final WritableRaster wr;
wr = Raster.createWritableRaster(sm, new Point(0,0));
WritableRaster dstWr = wr;
// This gives you the why it dies (x is not reset for
// each scan line):
if (INSTRUMENT) {
dstWr = new WritableRaster(wr.getSampleModel(), wr.getDataBuffer(),
new Point(0,0)) {
public void setSample(int x, int y, int b, int val) {
System.out.println("set Sample(" +
x + ", " + y + ", " +
b + ", " + val +
")");
wr.setSample(x,y,b,val);
}
};
}
lum = new BufferedImage(cm, dstWr, cm.isAlphaPremultiplied(), null);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(img, lum);
setSize(500, 300);
show();
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
AffineTransform at;
at = AffineTransform.getTranslateInstance(0,0);
g2d.drawImage(img, at, this);
at = AffineTransform.getTranslateInstance(img.getWidth(),0);
g2d.drawImage(lum, at, this);
}
public static void main(String args[]) {
Toolkit tk = Toolkit.getDefaultToolkit();
for (int i=0; i< args.length; i++) {
Image img = tk.createImage(args[i]);
new ColorCvtBug(img);
}
}
}
(Review ID: 111102)
======================================================================