Path: blob/master/test/jdk/sun/awt/image/bug8038000.java
41149 views
/*1* Copyright (c) 2014, 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 8038000 804706626*27* @summary Verifies that we could create different type of Rasters with height 128* and strideline which exceeds raster width.29* Also checks that a set of RasterOp work correctly with such kind of Rasters.30* For 8047066 verifies that ColorConvertOp could process31* Raster (ByteBuffer + SinglePixelPackedSampleModel)32*33* @run main bug803800034*/3536import java.awt.*;37import java.awt.color.ColorSpace;38import java.awt.geom.AffineTransform;39import java.awt.image.*;40import java.util.Arrays;4142public class bug8038000 {4344public static void main(String[] args) throws Exception {45new bug8038000().checkOps();4647// No exceptions - Passed48}4950private void checkOps() throws Exception {5152RasterOp[] ops = new RasterOp[] {53new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB),54ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), null),55new AffineTransformOp(AffineTransform.getScaleInstance(1, 1.1), null)56};575859for (RasterOp op: ops) {60// Banded rasters61checkOp(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 10,62new int[] {0, 1, 2}, new int[]{2,1,0}, null),63Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 1001,64new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);65checkOp(Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 10,66new int[] {0, 1, 2}, new int[]{2,1,0}, null),67Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 1001,68new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);69checkOp(Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 10,70new int[] {0, 1, 2}, new int[]{2,1,0}, null),71Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 1001,72new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);7374// Interleaved rasters75checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,7610, 1, 30, 3, new int[]{0, 1, 2}, null),77Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,7810, 1, 1001, 3, new int[]{0, 1, 2}, null),79op);8081checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,8210, 1, 30, 3, new int[]{0, 1, 2}, null),83Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,8410, 1, 1001, 3, new int[]{0, 1, 2}, null),85op);8687// Packed rasters88checkOp(Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 10,89new int[] {0x01, 0x02, 0x04}, null),90Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 2000,91new int[] {0x01, 0x02, 0x04}, null),92op);93checkOp(Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 10,94new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),95Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 20,96new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),97op);9899}100}101102/**103* Takes two identical rasters (identical with the exception of scanline stride)104* fills their pixels with identical data, applies the RasterOp to both rasters105* and checks that the result is the same106*/107private void checkOp(WritableRaster wr1, WritableRaster wr2, RasterOp op) {108System.out.println("Checking " + op + " with rasters: \n " + wr1 +109"\n " + wr2);110try {111WritableRaster r1 = op.filter(fillRaster(wr1), null);112WritableRaster r2 = op.filter(fillRaster(wr2), null);113compareRasters(r1, r2);114} catch (ImagingOpException e) {115System.out.println(" Skip: Op is not supported: " + e);116}117}118119private WritableRaster fillRaster(WritableRaster wr) {120int c = 0;121for(int x = wr.getMinX(); x < wr.getMinX() + wr.getWidth(); x++) {122for(int y = wr.getMinY(); y < wr.getMinY() + wr.getHeight(); y++) {123for (int b = 0; b < wr.getNumBands(); b++) {124wr.setSample(x, y, b, c++);125}126}127}128return wr;129}130131private void compareRasters(Raster r1, Raster r2) {132Rectangle bounds = r1.getBounds();133if (!bounds.equals(r2.getBounds())) {134throw new RuntimeException("Bounds differ.");135}136137if (r1.getNumBands() != r2.getNumBands()) {138throw new RuntimeException("Bands differ.");139}140141int[] b1 = new int[r1.getNumBands()];142int[] b2 = new int[r1.getNumBands()];143144for (int x = (int) bounds.getX(); x < bounds.getMaxX(); x++) {145for (int y = (int) bounds.getY(); y < bounds.getMaxY(); y++) {146r1.getPixel(x,y, b1);147r2.getPixel(x,y, b2);148if (!Arrays.equals(b1, b2)) {149throw new RuntimeException("Pixels differ.");150}151}152}153}154}155156157