J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4886506 |
| 27 | * @summary Test verifies that byte lookup table with single lookup array |
| 28 | * does not cause medialib routine crsh. |
| 29 | * @run main SingleArrayTest |
| 30 | */ |
| 31 | |
| 32 | import java.awt.image.BufferedImage; |
| 33 | import java.awt.image.ByteLookupTable; |
| 34 | import java.awt.image.LookupOp; |
| 35 | import java.awt.image.Raster; |
| 36 | import java.awt.image.WritableRaster; |
| 37 | |
| 38 | public class SingleArrayTest { |
| 39 | public static void main(String[] args) { |
| 40 | SingleArrayTest t = new SingleArrayTest(); |
| 41 | t.doTest(BufferedImage.TYPE_3BYTE_BGR); |
| 42 | t.doTest(BufferedImage.TYPE_4BYTE_ABGR); |
| 43 | t.doTest(BufferedImage.TYPE_INT_RGB); |
| 44 | t.doTest(BufferedImage.TYPE_INT_ARGB); |
| 45 | t.doTest(BufferedImage.TYPE_INT_BGR); |
| 46 | t.doTest(BufferedImage.TYPE_BYTE_GRAY); |
| 47 | } |
| 48 | |
| 49 | private LookupOp op; |
| 50 | |
| 51 | public SingleArrayTest() { |
| 52 | |
| 53 | byte[] array = new byte[256]; |
| 54 | for (int i = 0; i < 256; i++) { |
| 55 | array[i] = (byte)i; |
| 56 | } |
| 57 | ByteLookupTable table = new ByteLookupTable(0, array); |
| 58 | |
| 59 | op = new LookupOp(table, null); |
| 60 | } |
| 61 | |
| 62 | public void doTest(int bi_type) { |
| 63 | System.out.println("Test for type: " + bi_type); |
| 64 | BufferedImage src = new BufferedImage(2, 2, bi_type); |
| 65 | |
| 66 | BufferedImage dst = new BufferedImage(2, 2, bi_type); |
| 67 | |
| 68 | doTest(src.getData(), dst.getRaster()); |
| 69 | |
| 70 | doTest(src, dst); |
| 71 | |
| 72 | System.out.println("Test passed."); |
| 73 | } |
| 74 | |
| 75 | public void doTest(Raster src, WritableRaster dst) { |
| 76 | System.out.println("Test for raster:" + src); |
| 77 | try { |
| 78 | dst = op.filter(src, dst); |
| 79 | } catch (Exception e) { |
| 80 | throw new RuntimeException("Test failed.", e); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | public void doTest(BufferedImage src, BufferedImage dst) { |
| 85 | System.out.println("Test for image: " + src); |
| 86 | try { |
| 87 | dst = op.filter(src, dst); |
| 88 | } catch (Exception e) { |
| 89 | throw new RuntimeException("Test failed.", e); |
| 90 | } |
| 91 | } |
| 92 | } |