Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/plugins/png/WriteProgressive.java
38853 views
/*1* Copyright (c) 2001, 2017, 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 443261526* @summary Tests progressive writing in the PNG encoder27*/2829import java.awt.Color;30import java.awt.Graphics2D;31import java.awt.image.BufferedImage;32import java.io.File;33import java.io.IOException;34import java.util.Iterator;35import java.util.Random;3637import javax.imageio.IIOImage;38import javax.imageio.ImageIO;39import javax.imageio.ImageWriteParam;40import javax.imageio.ImageWriter;41import javax.imageio.stream.ImageOutputStream;4243public class WriteProgressive {4445public static void main(String[] args) throws IOException {46Iterator witer = ImageIO.getImageWritersByFormatName("png");47ImageWriter w = (ImageWriter)witer.next();4849File f = File.createTempFile("WriteProgressive", ".png");50ImageOutputStream ios = ImageIO.createImageOutputStream(f);51w.setOutput(ios);5253BufferedImage bi = new BufferedImage(100, 100,54BufferedImage.TYPE_3BYTE_BGR);55Graphics2D g = bi.createGraphics();56Random r = new Random(10);57for (int i = 0; i < 10000; i++) {58Color c =59new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));60g.setColor(c);61g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);62}6364IIOImage iioimage = new IIOImage(bi, null, null);6566ImageWriteParam param = w.getDefaultWriteParam();67param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);6869try {70w.write(null, iioimage, param);71} catch (NullPointerException npe) {72throw new RuntimeException("Got NPE during write!");73}7475ios.close();7677BufferedImage bi2 = ImageIO.read(f);78f.delete();7980ImageCompare.compare(bi, bi2);81}82}838485