1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8038000 8047066
*
* @summary Verifies that we could create different type of Rasters with height 1
* and strideline which exceeds raster width.
* Also checks that a set of RasterOp work correctly with such kind of Rasters.
* For 8047066 verifies that ColorConvertOp could process
* Raster (ByteBuffer + SinglePixelPackedSampleModel)
*
* @run main bug8038000
*/
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.util.Arrays;
public class bug8038000 {
public static void main(String[] args) throws Exception {
new bug8038000().checkOps();
// No exceptions - Passed
}
private void checkOps() throws Exception {
RasterOp[] ops = new RasterOp[] {
new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB),
ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), null),
new AffineTransformOp(AffineTransform.getScaleInstance(1, 1.1), null)
};
for (RasterOp op: ops) {
// Banded rasters
checkOp(Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 10,
new int[] {0, 1, 2}, new int[]{2,1,0}, null),
Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 10, 1, 1001,
new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);
checkOp(Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 10,
new int[] {0, 1, 2}, new int[]{2,1,0}, null),
Raster.createBandedRaster(DataBuffer.TYPE_USHORT, 10, 1, 1001,
new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);
checkOp(Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 10,
new int[] {0, 1, 2}, new int[]{2,1,0}, null),
Raster.createBandedRaster(DataBuffer.TYPE_INT, 10, 1, 1001,
new int[] {0, 1, 2}, new int[]{2,1,0}, null), op);
// Interleaved rasters
checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
10, 1, 30, 3, new int[]{0, 1, 2}, null),
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
10, 1, 1001, 3, new int[]{0, 1, 2}, null),
op);
checkOp(Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
10, 1, 30, 3, new int[]{0, 1, 2}, null),
Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
10, 1, 1001, 3, new int[]{0, 1, 2}, null),
op);
// Packed rasters
checkOp(Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 10,
new int[] {0x01, 0x02, 0x04}, null),
Raster.createPackedRaster(new DataBufferByte(10), 10, 1, 2000,
new int[] {0x01, 0x02, 0x04}, null),
op);
checkOp(Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 10,
new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),
Raster.createPackedRaster(new DataBufferInt(10), 10, 1, 20,
new int[] {0xff0000, 0x00ff00, 0x0000ff}, null),
op);
}
}
/**
* Takes two identical rasters (identical with the exception of scanline stride)
* fills their pixels with identical data, applies the RasterOp to both rasters
* and checks that the result is the same
*/
private void checkOp(WritableRaster wr1, WritableRaster wr2, RasterOp op) {
System.out.println("Checking " + op + " with rasters: \n " + wr1 +
"\n " + wr2);
try {
WritableRaster r1 = op.filter(fillRaster(wr1), null);
WritableRaster r2 = op.filter(fillRaster(wr2), null);
compareRasters(r1, r2);
} catch (ImagingOpException e) {
System.out.println(" Skip: Op is not supported: " + e);
}
}
private WritableRaster fillRaster(WritableRaster wr) {
int c = 0;
for(int x = wr.getMinX(); x < wr.getMinX() + wr.getWidth(); x++) {
for(int y = wr.getMinY(); y < wr.getMinY() + wr.getHeight(); y++) {
for (int b = 0; b < wr.getNumBands(); b++) {
wr.setSample(x, y, b, c++);
}
}
}
return wr;
}
private void compareRasters(Raster r1, Raster r2) {
Rectangle bounds = r1.getBounds();
if (!bounds.equals(r2.getBounds())) {
throw new RuntimeException("Bounds differ.");
}
if (r1.getNumBands() != r2.getNumBands()) {
throw new RuntimeException("Bands differ.");
}
int[] b1 = new int[r1.getNumBands()];
int[] b2 = new int[r1.getNumBands()];
for (int x = (int) bounds.getX(); x < bounds.getMaxX(); x++) {
for (int y = (int) bounds.getY(); y < bounds.getMaxY(); y++) {
r1.getPixel(x,y, b1);
r2.getPixel(x,y, b2);
if (!Arrays.equals(b1, b2)) {
throw new RuntimeException("Pixels differ.");
}
}
}
}
}
|