0N/A/*
2362N/A * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4405224
0N/A * @summary Test color conversion for images with alpha
0N/A */
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Transparency;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.ColorConvertOp;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.ComponentColorModel;
0N/Aimport java.awt.image.SampleModel;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.awt.image.PixelInterleavedSampleModel;
0N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.color.ColorSpace;
0N/A
0N/A
0N/Apublic class ColCvtAlpha {
0N/A
0N/A public static void main(String args[]) {
0N/A BufferedImage src
0N/A = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);
0N/A
0N/A // Set src pixel values
0N/A Color pelColor = new Color(100, 100, 100, 128);
0N/A for (int i = 0; i < 10; i++) {
0N/A src.setRGB(0, i, pelColor.getRGB());
0N/A }
0N/A
0N/A ColorModel cm = new ComponentColorModel
0N/A (ColorSpace.getInstance(ColorSpace.CS_GRAY),
0N/A new int [] {8,8}, true,
0N/A src.getColorModel().isAlphaPremultiplied(),
0N/A Transparency.TRANSLUCENT,
0N/A DataBuffer.TYPE_BYTE);
0N/A
0N/A SampleModel sm = new PixelInterleavedSampleModel
0N/A (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
0N/A new int [] { 0, 1 });
0N/A
0N/A WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));
0N/A
0N/A BufferedImage dst =
0N/A new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
0N/A dst = dst.getSubimage(0, 0, 1, 10);
0N/A
0N/A ColorConvertOp op = new ColorConvertOp(null);
0N/A
0N/A op.filter(src, dst);
0N/A
0N/A for (int i = 0; i < 10; i++) {
0N/A if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
0N/A throw new RuntimeException(
0N/A "Incorrect destination alpha value.");
0N/A }
0N/A }
0N/A
0N/A }
0N/A}