3266N/A/*
4248N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3266N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3266N/A *
3266N/A * This code is free software; you can redistribute it and/or modify it
3266N/A * under the terms of the GNU General Public License version 2 only, as
3266N/A * published by the Free Software Foundation.
3266N/A *
3266N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3266N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3266N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3266N/A * version 2 for more details (a copy is included in the LICENSE file that
3266N/A * accompanied this code).
3266N/A *
3266N/A * You should have received a copy of the GNU General Public License version
3266N/A * 2 along with this work; if not, write to the Free Software Foundation,
3266N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3266N/A *
4248N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4248N/A * or visit www.oracle.com if you need additional information or have any
4248N/A * questions.
4248N/A*/
3266N/A
3266N/A/*
3266N/A * @test
3266N/A * @bug 6782574
3266N/A * @summary Test verifies that incorrect sample masks are correctly handled
3266N/A * by the constructor of the SinglePixelPackedSampleModel class
3266N/A * and do not cause internal error in the medialib glue code.
3266N/A *
3266N/A * @run main IncorrectSampleMaskTest
3266N/A */
3266N/A
3266N/Aimport java.awt.geom.AffineTransform;
3266N/Aimport java.awt.image.AffineTransformOp;
3266N/Aimport java.awt.image.BufferedImageOp;
3266N/Aimport java.awt.image.DataBuffer;
3266N/Aimport java.awt.image.DataBufferByte;
3266N/Aimport java.awt.image.DataBufferInt;
3266N/Aimport java.awt.image.DataBufferUShort;
3266N/Aimport java.awt.image.Raster;
3266N/Aimport java.awt.image.RasterOp;
3266N/Aimport java.awt.image.WritableRaster;
3266N/Aimport java.awt.image.SinglePixelPackedSampleModel;
3266N/A
3266N/Apublic class IncorrectSampleMaskTest {
3266N/A public static void main(String[] args) {
3266N/A int[] dataTypes = new int[] {
3266N/A DataBuffer.TYPE_BYTE,
3266N/A DataBuffer.TYPE_USHORT,
3266N/A DataBuffer.TYPE_INT };
3266N/A
3266N/A for (int type : dataTypes) {
3266N/A doTest(type);
3266N/A }
3266N/A }
3266N/A
3266N/A private static final int w = 100;
3266N/A private static final int h = 100;
3266N/A
3266N/A private static AffineTransform at =
3266N/A AffineTransform.getScaleInstance(0.5, 0.5);
3266N/A
3266N/A private static RasterOp op =
3266N/A new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
3266N/A
3266N/A private static void doTest(int dataType) {
3266N/A int maxSize = DataBuffer.getDataTypeSize(dataType);
3266N/A System.out.println("Type size: " + maxSize);
3266N/A
3266N/A int theMask = (int)(1L << (maxSize + 2)) - 1;
3266N/A System.out.printf("theMask=%x\n", theMask);
3266N/A
3266N/A SinglePixelPackedSampleModel sm =
3266N/A new SinglePixelPackedSampleModel(dataType, w, h,
3266N/A new int[] { theMask });
3266N/A
3266N/A
3266N/A int[] sampleSize = sm.getSampleSize();
3266N/A for (int s : sampleSize) {
3266N/A if (s > maxSize) {
3266N/A throw new RuntimeException("Test failed: sample size is too big:" + s);
3266N/A }
3266N/A }
3266N/A
3266N/A System.out.println("Test medialib...");
3266N/A DataBuffer buf = createDataBuffer(dataType);
3266N/A
3266N/A WritableRaster wr = Raster.createWritableRaster(sm, buf, null);
3266N/A
3266N/A op.filter(wr, null);
3266N/A System.out.println("Test PASSED.");
3266N/A }
3266N/A
3266N/A private static DataBuffer createDataBuffer(int type) {
3266N/A switch (type) {
3266N/A case DataBuffer.TYPE_BYTE: {
3266N/A byte[] buf = new byte[w * h];
3266N/A return new DataBufferByte(buf, buf.length);
3266N/A }
3266N/A case DataBuffer.TYPE_USHORT: {
3266N/A short[] buf = new short[w * h];
3266N/A return new DataBufferUShort(buf, buf.length);
3266N/A }
3266N/A case DataBuffer.TYPE_INT: {
3266N/A int[] buf = new int[w * h];
3266N/A return new DataBufferInt(buf, buf.length);
3266N/A }
3266N/A default :
3266N/A throw new RuntimeException("Unsupported data type.");
3266N/A }
3266N/A }
3266N/A}