/* * Copyright (c) 2003, 2017, 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 4641872 * @summary Tests writing compression modes of BMP plugin * @modules java.desktop/com.sun.imageio.plugins.bmp */ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; 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.PixelInterleavedSampleModel; import java.awt.image.Raster; import java.awt.image.SampleModel; import java.awt.image.SinglePixelPackedSampleModel; import java.awt.image.WritableRaster; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.imageio.IIOImage; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.ImageTypeSpecifier; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; import javax.imageio.metadata.IIOMetadata; import javax.imageio.plugins.bmp.BMPImageWriteParam; import javax.imageio.stream.ImageOutputStream; import javax.swing.JComponent; import javax.swing.JFrame; import com.sun.imageio.plugins.bmp.BMPMetadata; public class BMPCompressionTest { static final String format = "BMP"; public static void main(String[] args) { ImageWriter iw = null; Iterator writers = ImageIO.getImageWritersByFormatName(format); if (!writers.hasNext()) { throw new RuntimeException("No available Image writer for "+format); } iw = (ImageWriter)writers.next(); Iterator tests = Test.createTestSet(iw); while(tests.hasNext()) { Test t = (Test)tests.next(); System.out.println(t.getDescription()); t.doTest(); } } static class Test { static ImageWriter iw; private BufferedImage img; private String description; private BMPImageWriteParam param; private IIOMetadata meta; public static Iterator createTestSet(ImageWriter w) { List l = new LinkedList(); Test.iw = w; // variate compression types BMPImageWriteParam param = (BMPImageWriteParam)iw.getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); param.setCompressionType("BI_RGB"); if (param.canWriteCompressed()) { String[] cTypes = param.getCompressionTypes(); String[] cDescr = param.getCompressionQualityDescriptions(); float[] cValues = param.getCompressionQualityValues(); if (cDescr == null) { System.out.println("There are no compression quality description!"); } else { for(int i=0; i