Path: blob/master/test/jdk/sun/awt/image/DrawByteBinary.java
41149 views
/*1* Copyright (c) 2009, 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 680084626*27* @summary Test verifes that images with short palette are rendered28* withourt artifacts.29*30* @run main DrawByteBinary31*/323334import java.awt.*;35import java.awt.color.*;36import java.awt.image.*;37import static java.awt.image.BufferedImage.*;383940public class DrawByteBinary {4142public static void main(String args[]) {43int w = 100, h = 30;44int x = 10;45byte[] arr = {(byte)0xff, (byte)0x0, (byte)0x00};4647IndexColorModel newCM = new IndexColorModel(1, 2, arr, arr, arr);48BufferedImage orig = new BufferedImage(w, h, TYPE_BYTE_BINARY, newCM);49Graphics2D g2d = orig.createGraphics();50g2d.setColor(Color.white);51g2d.fillRect(0, 0, w, h);52g2d.setColor(Color.black);53g2d.drawLine(x, 0, x, h);54g2d.dispose();5556IndexColorModel origCM = (IndexColorModel)orig.getColorModel();57BufferedImage test = new BufferedImage(w, h, TYPE_BYTE_BINARY,origCM);58g2d = test.createGraphics();59g2d.drawImage(orig, 0, 0, null);60g2d.dispose();6162int y = h / 2;6364// we expect white color outside the line65if (test.getRGB(x - 1, y) != 0xffffffff) {66throw new RuntimeException("Invalid color outside the line.");67}6869// we expect black color on the line70if (test.getRGB(x, y) != 0xff000000) {71throw new RuntimeException("Invalid color on the line.");72}73}74}757677