1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 6800846 27 * 28 * @summary Test verifes that images with short palette are rendered 29 * withourt artifacts. 30 * 31 * @run main DrawByteBinary 32 */ 33 34 35 import java.awt.*; 36 import java.awt.color.*; 37 import java.awt.image.*; 38 import static java.awt.image.BufferedImage.*; 39 40 41 public class DrawByteBinary { 42 main(String args[])43 public static void main(String args[]) { 44 int w = 100, h = 30; 45 int x = 10; 46 byte[] arr = {(byte)0xff, (byte)0x0, (byte)0x00}; 47 48 IndexColorModel newCM = new IndexColorModel(1, 2, arr, arr, arr); 49 BufferedImage orig = new BufferedImage(w, h, TYPE_BYTE_BINARY, newCM); 50 Graphics2D g2d = orig.createGraphics(); 51 g2d.setColor(Color.white); 52 g2d.fillRect(0, 0, w, h); 53 g2d.setColor(Color.black); 54 g2d.drawLine(x, 0, x, h); 55 g2d.dispose(); 56 57 IndexColorModel origCM = (IndexColorModel)orig.getColorModel(); 58 BufferedImage test = new BufferedImage(w, h, TYPE_BYTE_BINARY,origCM); 59 g2d = test.createGraphics(); 60 g2d.drawImage(orig, 0, 0, null); 61 g2d.dispose(); 62 63 int y = h / 2; 64 65 // we expect white color outside the line 66 if (test.getRGB(x - 1, y) != 0xffffffff) { 67 throw new RuntimeException("Invalid color outside the line."); 68 } 69 70 // we expect black color on the line 71 if (test.getRGB(x, y) != 0xff000000) { 72 throw new RuntimeException("Invalid color on the line."); 73 } 74 } 75 } 76