/* * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 6299168 6399660 6519600 * @summary Test verifies that the subsampling usage does not causes color * changes. * @run main BMPSubsamplingTest * @author andrew.brygin */ import java.awt.Color; import java.awt.Graphics2D; import java.awt.Transparency; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.DataBuffer; import java.awt.image.DirectColorModel; import java.awt.image.IndexColorModel; import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; import javax.imageio.IIOImage; import javax.imageio.ImageIO; import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; import javax.imageio.stream.ImageOutputStream; public class BMPSubsamplingTest { private static final int TYPE_INT_GRB = 0x100; private static final int TYPE_INT_GBR = 0x101; private static final int TYPE_INT_RBG = 0x102; private static final int TYPE_INT_BRG = 0x103; private static final int TYPE_3BYTE_RGB = 0x104; private static final int TYPE_3BYTE_GRB = 0x105; private static final int TYPE_USHORT_555_GRB = 0x106; private static final int TYPE_USHORT_555_BGR = 0x107; private static final int TYPE_USHORT_565_BGR = 0x108; private static final int TYPE_4BPP_INDEXED = 0x109; private String format = "BMP"; private int[] img_types = new int[] { BufferedImage.TYPE_INT_RGB, BufferedImage.TYPE_INT_BGR, TYPE_INT_GRB, TYPE_INT_GBR, TYPE_INT_RBG, TYPE_INT_BRG, BufferedImage.TYPE_USHORT_555_RGB, BufferedImage.TYPE_USHORT_565_RGB, TYPE_USHORT_555_GRB, TYPE_USHORT_555_BGR, TYPE_USHORT_565_BGR, BufferedImage.TYPE_3BYTE_BGR, TYPE_3BYTE_RGB, TYPE_3BYTE_GRB, BufferedImage.TYPE_BYTE_INDEXED, TYPE_4BPP_INDEXED }; Color[] colors = new Color[] { Color.red, Color.green, Color.blue }; private final int srcXSubsampling = 3; private final int srcYSubsampling = 3; int dx = 300; int h = 300; int w = dx * colors.length + srcXSubsampling; public BMPSubsamplingTest() throws IOException { ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next(); ImageWriteParam wparam = writer.getDefaultWriteParam(); wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); String[] types = wparam.getCompressionTypes(); for (int t = 0; t < img_types.length; t++) { int img_type = img_types[t]; System.out.println("Test for " + getImageTypeName(img_type)); BufferedImage image = getTestImage(img_type); ImageTypeSpecifier specifier = new ImageTypeSpecifier(image); if (!writer.getOriginatingProvider().canEncodeImage(specifier)) { System.out.println("Writer does not support encoding this buffered image type."); continue; } for(int i=0; i