When copying an image using Graphics2D.drawImage(),I'm suprised to find that 
the isAlphaPremultiplied() property of the two images is not taken into 
account.  I believe the pixels are copied directly without respect to color 
model.

A little example is below.  I would expect the normalized (sRGB) pixel for each 
image to be the same, but instead the "real" pixel value is the same and the 
interpretation and normalized data differ.

Is this a bug or am I misunderstanding how these things should work?

Thanks much,
michael

[code]
        public static void main(String[] args) {
                BufferedImage premultiplied = new BufferedImage(10, 10, 
BufferedImage.TYPE_INT_ARGB);
                BufferedImage notpremultiplied = new BufferedImage(10, 10, 
BufferedImage.TYPE_INT_ARGB);
                
                premultiplied.coerceData(true);
                notpremultiplied.coerceData(false);
                
                Graphics2D preG = premultiplied.createGraphics();
                preG.setColor(new Color(0, 40, 0, 120));
                preG.fillRect(0, 0, 10, 10);
                preG.dispose();

                // prints:
                //      real: pixel:2013276160 120,0,85,0
                //      normalized: pixel:2013287680 120,0,85,0
                printOriginPixel(premultiplied);
                                
                Graphics2D notG = notpremultiplied.createGraphics();
                notG.drawImage(premultiplied, 0, 0, 10, 10, null);
                notG.dispose();

                // prints:
                //      real: pixel:2013276160 120,0,40,0
                //      normalized: pixel:2013276160 120,0,40,0
                printOriginPixel(notpremultiplied);
        }
        
        public static void printOriginPixel(BufferedImage image) {
                int defaultColorSpacePixel = image.getRGB(0, 0);
                int realPixel = ((int[]) image.getRaster().getDataElements(0, 
0, null))[0];

                System.out.println("real: pixel:"+ realPixel + " "
                                + image.getColorModel().getAlpha(realPixel)
                                + ","
                                + image.getColorModel().getRed(realPixel)
                                + ","
                                + image.getColorModel().getGreen(realPixel)
                                + ","
                                + image.getColorModel().getBlue(realPixel));
                System.out.println("normalized: pixel:" + 
defaultColorSpacePixel + " "
                                + 
ColorModel.getRGBdefault().getAlpha(defaultColorSpacePixel)
                                + ","
                                + 
ColorModel.getRGBdefault().getRed(defaultColorSpacePixel)
                                + ","
                                + 
ColorModel.getRGBdefault().getGreen(defaultColorSpacePixel)
                                + ","
                                + 
ColorModel.getRGBdefault().getBlue(defaultColorSpacePixel));
        }
[/code]
[Message sent by forum member 'kazoobrewer' (kazoobrewer)]

http://forums.java.net/jive/thread.jspa?messageID=293378

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to