Path: blob/master/test/jdk/javax/imageio/plugins/png/PngDitDepthTest.java
41155 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 499164726* @summary PNGMetadata.getAsTree() sets bitDepth to invalid value27* @run main PngDitDepthTest28*/2930import org.w3c.dom.Node;3132import javax.imageio.ImageIO;33import javax.imageio.ImageTypeSpecifier;34import javax.imageio.ImageWriter;35import javax.imageio.metadata.IIOInvalidTreeException;36import javax.imageio.metadata.IIOMetadata;37import java.awt.image.ColorModel;38import java.awt.image.SampleModel;39import java.util.Iterator;4041public class PngDitDepthTest {4243public static void main(String[] args) throws IIOInvalidTreeException {4445// getting the writer for the png format46Iterator iter = ImageIO.getImageWritersByFormatName("png");47ImageWriter writer = (ImageWriter) iter.next();4849// creating a color model50ColorModel colorModel = ColorModel.getRGBdefault();5152// creating a sample model53SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);5455// creating a default metadata object56IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);57String formatName = metaData.getNativeMetadataFormatName();5859// first call60Node metaDataNode = metaData.getAsTree(formatName);61try {62metaData.setFromTree(formatName, metaDataNode);63} catch (Exception ex) {64ex.printStackTrace();65}6667// second call (bitdepht is already set to an invalid value)68metaDataNode = metaData.getAsTree(formatName);6970metaData.setFromTree(formatName, metaDataNode);7172}73}747576