0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: /**
0018: * @author Igor V. Stolyarov
0019: * @version $Revision$
0020: */package java.awt.image;
0021:
0022: import java.awt.image.DataBuffer;
0023: import java.awt.image.DataBufferByte;
0024: import java.awt.image.DataBufferInt;
0025: import java.awt.image.DataBufferUShort;
0026: import java.awt.image.SampleModel;
0027: import java.awt.image.SinglePixelPackedSampleModel;
0028: import java.util.Arrays;
0029: import java.util.Random;
0030:
0031: import junit.framework.TestCase;
0032:
0033: public class SinglePixelPackedSampleModelTest extends TestCase {
0034: int w = 10;
0035: int h = 10;
0036: int scanlineStride = 20;
0037:
0038: int bitMaskB[] = { 0x3, 0xc, 0x30, 0xc0 };
0039: int bitOffsetsB[] = { 0, 2, 4, 6 };
0040: int samplesSizeB[] = { 2, 2, 2, 2 };
0041: int bitMaskUS[] = { 0xf, 0xf0, 0xf00, 0xf000 };
0042: int bitOffsetsUS[] = { 0, 4, 8, 12 };
0043: int samplesSizeUS[] = { 4, 4, 4, 4 };
0044: int bitMaskI[] = { 0xff, 0xff00, 0xff0000, 0xff000000 };
0045: int bitOffsetsI[] = { 0, 8, 16, 24 };
0046: int samplesSizeI[] = { 8, 8, 8, 8 };
0047:
0048: byte byteTestData[];
0049: short shortTestData[];
0050: int intTestData[];
0051:
0052: DataBufferByte dbb1, dbb2;
0053: DataBufferUShort dbu1, dbu2;
0054: DataBufferInt dbi1, dbi2;
0055:
0056: SinglePixelPackedSampleModel sppsmb1, sppsmb2, sppsmu1, sppsmu2,
0057: sppsmi1, sppsmi2;
0058:
0059: public static void main(String[] args) {
0060: junit.textui.TestRunner
0061: .run(SinglePixelPackedSampleModelTest.class);
0062: }
0063:
0064: /*
0065: * @see TestCase#setUp()
0066: */
0067: @Override
0068: protected void setUp() throws Exception {
0069: super .setUp();
0070: dbb1 = new DataBufferByte(w * h);
0071: dbb2 = new DataBufferByte(scanlineStride * (h - 1) + w);
0072: dbu1 = new DataBufferUShort(w * h);
0073: dbu2 = new DataBufferUShort(scanlineStride * (h - 1) + w);
0074: dbi1 = new DataBufferInt(w * h);
0075: dbi2 = new DataBufferInt(scanlineStride * (h - 1) + w);
0076: sppsmb1 = new SinglePixelPackedSampleModel(
0077: DataBuffer.TYPE_BYTE, w, h, bitMaskB);
0078: sppsmb2 = new SinglePixelPackedSampleModel(
0079: DataBuffer.TYPE_BYTE, w, h, scanlineStride, bitMaskB);
0080: sppsmu1 = new SinglePixelPackedSampleModel(
0081: DataBuffer.TYPE_USHORT, w, h, bitMaskUS);
0082: sppsmu2 = new SinglePixelPackedSampleModel(
0083: DataBuffer.TYPE_USHORT, w, h, scanlineStride, bitMaskUS);
0084: sppsmi1 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
0085: w, h, bitMaskI);
0086: sppsmi2 = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
0087: w, h, scanlineStride, bitMaskI);
0088: initTestData();
0089: }
0090:
0091: /**
0092: * Constructor for SinglePixelPackedSampleModelTest.
0093: * @param name
0094: */
0095: public SinglePixelPackedSampleModelTest(String name) {
0096: super (name);
0097: }
0098:
0099: public final void testGetDataType() {
0100: assertEquals(DataBuffer.TYPE_BYTE, sppsmb1.getDataType());
0101: assertEquals(DataBuffer.TYPE_BYTE, sppsmb2.getDataType());
0102: assertEquals(DataBuffer.TYPE_USHORT, sppsmu1.getDataType());
0103: assertEquals(DataBuffer.TYPE_USHORT, sppsmu2.getDataType());
0104: assertEquals(DataBuffer.TYPE_INT, sppsmi1.getDataType());
0105: assertEquals(DataBuffer.TYPE_INT, sppsmi2.getDataType());
0106: }
0107:
0108: public final void testGetHeight() {
0109: assertEquals(h, sppsmb1.getHeight());
0110: assertEquals(h, sppsmb2.getHeight());
0111: assertEquals(h, sppsmu1.getHeight());
0112: assertEquals(h, sppsmu2.getHeight());
0113: assertEquals(h, sppsmi1.getHeight());
0114: assertEquals(h, sppsmi2.getHeight());
0115: }
0116:
0117: public final void testGetWidth() {
0118: assertEquals(w, sppsmb1.getWidth());
0119: assertEquals(w, sppsmb2.getWidth());
0120: assertEquals(w, sppsmu1.getWidth());
0121: assertEquals(w, sppsmu2.getWidth());
0122: assertEquals(w, sppsmi1.getWidth());
0123: assertEquals(w, sppsmi2.getWidth());
0124: }
0125:
0126: public final void testGetScanlineStride() {
0127: assertEquals(w, sppsmb1.getScanlineStride());
0128: assertEquals(scanlineStride, sppsmb2.getScanlineStride());
0129: assertEquals(w, sppsmu1.getScanlineStride());
0130: assertEquals(scanlineStride, sppsmu2.getScanlineStride());
0131: assertEquals(w, sppsmi1.getScanlineStride());
0132: assertEquals(scanlineStride, sppsmi2.getScanlineStride());
0133: }
0134:
0135: public final void testGetTransferType() {
0136: assertEquals(DataBuffer.TYPE_BYTE, sppsmb1.getTransferType());
0137: assertEquals(DataBuffer.TYPE_BYTE, sppsmb2.getTransferType());
0138: assertEquals(DataBuffer.TYPE_USHORT, sppsmu1.getTransferType());
0139: assertEquals(DataBuffer.TYPE_USHORT, sppsmu2.getTransferType());
0140: assertEquals(DataBuffer.TYPE_INT, sppsmi1.getTransferType());
0141: assertEquals(DataBuffer.TYPE_INT, sppsmi2.getTransferType());
0142: }
0143:
0144: public final void testGetNumBands() {
0145: assertEquals(4, sppsmb1.getNumBands());
0146: assertEquals(4, sppsmb2.getNumBands());
0147: assertEquals(4, sppsmu1.getNumBands());
0148: assertEquals(4, sppsmu2.getNumBands());
0149: assertEquals(4, sppsmi1.getNumBands());
0150: assertEquals(4, sppsmi2.getNumBands());
0151: }
0152:
0153: public final void testGetBitMasks() {
0154: assertTrue(Arrays.equals(bitMaskB, sppsmb1.getBitMasks()));
0155: assertTrue(Arrays.equals(bitMaskB, sppsmb2.getBitMasks()));
0156: assertTrue(Arrays.equals(bitMaskUS, sppsmu1.getBitMasks()));
0157: assertTrue(Arrays.equals(bitMaskUS, sppsmu2.getBitMasks()));
0158: assertTrue(Arrays.equals(bitMaskI, sppsmi1.getBitMasks()));
0159: assertTrue(Arrays.equals(bitMaskI, sppsmi2.getBitMasks()));
0160: }
0161:
0162: public final void testCreateCompatibleSampleModel() {
0163: SampleModel sm;
0164: SinglePixelPackedSampleModel sppsm;
0165:
0166: sm = sppsmb1.createCompatibleSampleModel(w, h);
0167: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0168: sppsm = (SinglePixelPackedSampleModel) sm;
0169: assertEquals(DataBuffer.TYPE_BYTE, sppsm.getDataType());
0170: assertEquals(w, sppsm.getWidth());
0171: assertEquals(h, sppsm.getHeight());
0172: assertEquals(w, sppsm.getScanlineStride());
0173: assertTrue(Arrays.equals(bitMaskB, sppsm.getBitMasks()));
0174:
0175: sm = sppsmb2.createCompatibleSampleModel(w, h);
0176: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0177: sppsm = (SinglePixelPackedSampleModel) sm;
0178: assertEquals(DataBuffer.TYPE_BYTE, sppsm.getDataType());
0179: assertEquals(w, sppsm.getWidth());
0180: assertEquals(h, sppsm.getHeight());
0181: assertEquals(w, sppsm.getScanlineStride());
0182: assertTrue(Arrays.equals(bitMaskB, sppsm.getBitMasks()));
0183:
0184: sm = sppsmu1.createCompatibleSampleModel(w, h);
0185: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0186: sppsm = (SinglePixelPackedSampleModel) sm;
0187: assertEquals(DataBuffer.TYPE_USHORT, sppsm.getDataType());
0188: assertEquals(w, sppsm.getWidth());
0189: assertEquals(h, sppsm.getHeight());
0190: assertEquals(w, sppsm.getScanlineStride());
0191: assertTrue(Arrays.equals(bitMaskUS, sppsm.getBitMasks()));
0192:
0193: sm = sppsmu2.createCompatibleSampleModel(w, h);
0194: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0195: sppsm = (SinglePixelPackedSampleModel) sm;
0196: assertEquals(DataBuffer.TYPE_USHORT, sppsm.getDataType());
0197: assertEquals(w, sppsm.getWidth());
0198: assertEquals(h, sppsm.getHeight());
0199: assertEquals(w, sppsm.getScanlineStride());
0200: assertTrue(Arrays.equals(bitMaskUS, sppsm.getBitMasks()));
0201:
0202: sm = sppsmi1.createCompatibleSampleModel(w, h);
0203: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0204: sppsm = (SinglePixelPackedSampleModel) sm;
0205: assertEquals(DataBuffer.TYPE_INT, sppsm.getDataType());
0206: assertEquals(w, sppsm.getWidth());
0207: assertEquals(h, sppsm.getHeight());
0208: assertEquals(w, sppsm.getScanlineStride());
0209: assertTrue(Arrays.equals(bitMaskI, sppsm.getBitMasks()));
0210:
0211: sm = sppsmi2.createCompatibleSampleModel(w, h);
0212: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0213: sppsm = (SinglePixelPackedSampleModel) sm;
0214: assertEquals(DataBuffer.TYPE_INT, sppsm.getDataType());
0215: assertEquals(w, sppsm.getWidth());
0216: assertEquals(h, sppsm.getHeight());
0217: assertEquals(w, sppsm.getScanlineStride());
0218: assertTrue(Arrays.equals(bitMaskI, sppsm.getBitMasks()));
0219: }
0220:
0221: public final void testCreateDataBuffer() {
0222: DataBuffer db;
0223:
0224: db = sppsmb1.createDataBuffer();
0225: assertEquals(dbb1.getDataType(), db.getDataType());
0226: assertEquals(dbb1.getNumBanks(), db.getNumBanks());
0227: assertEquals(dbb1.getSize(), db.getSize());
0228: assertTrue(Arrays.equals(dbb1.getOffsets(), db.getOffsets()));
0229:
0230: db = sppsmb2.createDataBuffer();
0231: assertEquals(dbb2.getDataType(), db.getDataType());
0232: assertEquals(dbb2.getNumBanks(), db.getNumBanks());
0233: assertEquals(dbb2.getSize(), db.getSize());
0234: assertTrue(Arrays.equals(dbb2.getOffsets(), db.getOffsets()));
0235:
0236: db = sppsmu1.createDataBuffer();
0237: assertEquals(dbu1.getDataType(), db.getDataType());
0238: assertEquals(dbu1.getNumBanks(), db.getNumBanks());
0239: assertEquals(dbu1.getSize(), db.getSize());
0240: assertTrue(Arrays.equals(dbu1.getOffsets(), db.getOffsets()));
0241:
0242: db = sppsmu2.createDataBuffer();
0243: assertEquals(dbu2.getDataType(), db.getDataType());
0244: assertEquals(dbu2.getNumBanks(), db.getNumBanks());
0245: assertEquals(dbu2.getSize(), db.getSize());
0246: assertTrue(Arrays.equals(dbu2.getOffsets(), db.getOffsets()));
0247:
0248: db = sppsmi1.createDataBuffer();
0249: assertEquals(dbi1.getDataType(), db.getDataType());
0250: assertEquals(dbi1.getNumBanks(), db.getNumBanks());
0251: assertEquals(dbi1.getSize(), db.getSize());
0252: assertTrue(Arrays.equals(dbi1.getOffsets(), db.getOffsets()));
0253:
0254: db = sppsmi2.createDataBuffer();
0255: assertEquals(dbi2.getDataType(), db.getDataType());
0256: assertEquals(dbi2.getNumBanks(), db.getNumBanks());
0257: assertEquals(dbi2.getSize(), db.getSize());
0258: assertTrue(Arrays.equals(dbi2.getOffsets(), db.getOffsets()));
0259: }
0260:
0261: public final void testCreateSubsetSampleModel() {
0262: int masks[];
0263: int bands[] = { 0, 2 };
0264: SampleModel sm;
0265: SinglePixelPackedSampleModel sppsm;
0266:
0267: sm = sppsmb1.createSubsetSampleModel(bands);
0268: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0269: sppsm = (SinglePixelPackedSampleModel) sm;
0270: assertEquals(DataBuffer.TYPE_BYTE, sppsm.getDataType());
0271: assertEquals(w, sppsm.getWidth());
0272: assertEquals(h, sppsm.getHeight());
0273: assertEquals(w, sppsm.getScanlineStride());
0274: assertEquals(bands.length, sppsm.getNumBands());
0275: masks = sppsm.getBitMasks();
0276: for (int i = 0; i < masks.length; i++) {
0277: assertEquals(masks[i], bitMaskB[bands[i]]);
0278: }
0279:
0280: sm = sppsmb2.createSubsetSampleModel(bands);
0281: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0282: sppsm = (SinglePixelPackedSampleModel) sm;
0283: assertEquals(DataBuffer.TYPE_BYTE, sppsm.getDataType());
0284: assertEquals(w, sppsm.getWidth());
0285: assertEquals(h, sppsm.getHeight());
0286: assertEquals(scanlineStride, sppsm.getScanlineStride());
0287: assertEquals(bands.length, sppsm.getNumBands());
0288: masks = sppsm.getBitMasks();
0289: for (int i = 0; i < masks.length; i++) {
0290: assertEquals(masks[i], bitMaskB[bands[i]]);
0291: }
0292:
0293: sm = sppsmu1.createSubsetSampleModel(bands);
0294: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0295: sppsm = (SinglePixelPackedSampleModel) sm;
0296: assertEquals(DataBuffer.TYPE_USHORT, sppsm.getDataType());
0297: assertEquals(w, sppsm.getWidth());
0298: assertEquals(h, sppsm.getHeight());
0299: assertEquals(w, sppsm.getScanlineStride());
0300: assertEquals(bands.length, sppsm.getNumBands());
0301: masks = sppsm.getBitMasks();
0302: for (int i = 0; i < masks.length; i++) {
0303: assertEquals(masks[i], bitMaskUS[bands[i]]);
0304: }
0305:
0306: sm = sppsmu2.createSubsetSampleModel(bands);
0307: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0308: sppsm = (SinglePixelPackedSampleModel) sm;
0309: assertEquals(DataBuffer.TYPE_USHORT, sppsm.getDataType());
0310: assertEquals(w, sppsm.getWidth());
0311: assertEquals(h, sppsm.getHeight());
0312: assertEquals(scanlineStride, sppsm.getScanlineStride());
0313: assertEquals(bands.length, sppsm.getNumBands());
0314: masks = sppsm.getBitMasks();
0315: for (int i = 0; i < masks.length; i++) {
0316: assertEquals(masks[i], bitMaskUS[bands[i]]);
0317: }
0318:
0319: sm = sppsmi1.createSubsetSampleModel(bands);
0320: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0321: sppsm = (SinglePixelPackedSampleModel) sm;
0322: assertEquals(DataBuffer.TYPE_INT, sppsm.getDataType());
0323: assertEquals(w, sppsm.getWidth());
0324: assertEquals(h, sppsm.getHeight());
0325: assertEquals(w, sppsm.getScanlineStride());
0326: assertEquals(bands.length, sppsm.getNumBands());
0327: masks = sppsm.getBitMasks();
0328: for (int i = 0; i < masks.length; i++) {
0329: assertEquals(masks[i], bitMaskI[bands[i]]);
0330: }
0331:
0332: sm = sppsmi2.createSubsetSampleModel(bands);
0333: assertTrue(sm instanceof SinglePixelPackedSampleModel);
0334: sppsm = (SinglePixelPackedSampleModel) sm;
0335: assertEquals(DataBuffer.TYPE_INT, sppsm.getDataType());
0336: assertEquals(w, sppsm.getWidth());
0337: assertEquals(h, sppsm.getHeight());
0338: assertEquals(scanlineStride, sppsm.getScanlineStride());
0339: assertEquals(bands.length, sppsm.getNumBands());
0340: masks = sppsm.getBitMasks();
0341: for (int i = 0; i < masks.length; i++) {
0342: assertEquals(masks[i], bitMaskI[bands[i]]);
0343: }
0344: }
0345:
0346: public final void testEquals() {
0347: SampleModel sm;
0348:
0349: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w,
0350: h, bitMaskB);
0351: assertTrue(sppsmb1.equals(sm));
0352: assertFalse(sppsmb2.equals(sm));
0353:
0354: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w,
0355: h, scanlineStride, bitMaskB);
0356: assertFalse(sppsmb1.equals(sm));
0357: assertTrue(sppsmb2.equals(sm));
0358:
0359: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
0360: w, h, bitMaskUS);
0361: assertTrue(sppsmu1.equals(sm));
0362: assertFalse(sppsmu2.equals(sm));
0363:
0364: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
0365: w, h, scanlineStride, bitMaskUS);
0366: assertFalse(sppsmu1.equals(sm));
0367: assertTrue(sppsmu2.equals(sm));
0368:
0369: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w,
0370: h, bitMaskI);
0371: assertTrue(sppsmi1.equals(sm));
0372: assertFalse(sppsmi2.equals(sm));
0373:
0374: sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w,
0375: h, scanlineStride, bitMaskI);
0376: assertFalse(sppsmi1.equals(sm));
0377: assertTrue(sppsmi2.equals(sm));
0378: }
0379:
0380: public final void testGetBitOffsets() {
0381: int bitOffsets[];
0382:
0383: bitOffsets = sppsmb1.getBitOffsets();
0384: assertEquals(bitOffsetsB.length, bitOffsets.length);
0385: for (int i = 0; i < bitOffsets.length; i++) {
0386: assertEquals(bitOffsetsB[i], bitOffsets[i]);
0387: }
0388:
0389: bitOffsets = sppsmb2.getBitOffsets();
0390: assertEquals(bitOffsetsB.length, bitOffsets.length);
0391: for (int i = 0; i < bitOffsets.length; i++) {
0392: assertEquals(bitOffsetsB[i], bitOffsets[i]);
0393: }
0394:
0395: bitOffsets = sppsmu1.getBitOffsets();
0396: assertEquals(bitOffsetsUS.length, bitOffsets.length);
0397: for (int i = 0; i < bitOffsets.length; i++) {
0398: assertEquals(bitOffsetsUS[i], bitOffsets[i]);
0399: }
0400:
0401: bitOffsets = sppsmu2.getBitOffsets();
0402: assertEquals(bitOffsetsUS.length, bitOffsets.length);
0403: for (int i = 0; i < bitOffsets.length; i++) {
0404: assertEquals(bitOffsetsUS[i], bitOffsets[i]);
0405: }
0406:
0407: bitOffsets = sppsmi1.getBitOffsets();
0408: assertEquals(bitOffsetsI.length, bitOffsets.length);
0409: for (int i = 0; i < bitOffsets.length; i++) {
0410: assertEquals(bitOffsetsI[i], bitOffsets[i]);
0411: }
0412:
0413: bitOffsets = sppsmi2.getBitOffsets();
0414: assertEquals(bitOffsetsI.length, bitOffsets.length);
0415: for (int i = 0; i < bitOffsets.length; i++) {
0416: assertEquals(bitOffsetsI[i], bitOffsets[i]);
0417: }
0418: }
0419:
0420: public final void testNumDataElements() {
0421: assertEquals(1, sppsmb1.getNumDataElements());
0422: assertEquals(1, sppsmb2.getNumDataElements());
0423: assertEquals(1, sppsmu1.getNumDataElements());
0424: assertEquals(1, sppsmu2.getNumDataElements());
0425: assertEquals(1, sppsmu1.getNumDataElements());
0426: assertEquals(1, sppsmi2.getNumDataElements());
0427: }
0428:
0429: public final void testGetOffset() {
0430: for (int y = 0; y < h; y++) {
0431: for (int x = 0; x < w; x++) {
0432: assertEquals(y * w + x, sppsmb1.getOffset(x, y));
0433: }
0434: }
0435:
0436: for (int y = 0; y < h; y++) {
0437: for (int x = 0; x < w; x++) {
0438: assertEquals(y * scanlineStride + x, sppsmb2.getOffset(
0439: x, y));
0440: }
0441: }
0442:
0443: for (int y = 0; y < h; y++) {
0444: for (int x = 0; x < w; x++) {
0445: assertEquals(y * w + x, sppsmu1.getOffset(x, y));
0446: }
0447: }
0448:
0449: for (int y = 0; y < h; y++) {
0450: for (int x = 0; x < w; x++) {
0451: assertEquals(y * scanlineStride + x, sppsmu2.getOffset(
0452: x, y));
0453: }
0454: }
0455:
0456: for (int y = 0; y < h; y++) {
0457: for (int x = 0; x < w; x++) {
0458: assertEquals(y * w + x, sppsmi1.getOffset(x, y));
0459: }
0460: }
0461:
0462: for (int y = 0; y < h; y++) {
0463: for (int x = 0; x < w; x++) {
0464: assertEquals(y * scanlineStride + x, sppsmi2.getOffset(
0465: x, y));
0466: }
0467: }
0468: }
0469:
0470: public final void testGetSampleSize() {
0471: int samplesSize[];
0472:
0473: samplesSize = sppsmb1.getSampleSize();
0474: assertEquals(samplesSizeB.length, samplesSize.length);
0475: for (int i = 0; i < samplesSize.length; i++) {
0476: assertEquals(samplesSizeB[i], samplesSize[i]);
0477: }
0478:
0479: samplesSize = sppsmb2.getSampleSize();
0480: assertEquals(samplesSizeB.length, samplesSize.length);
0481: for (int i = 0; i < samplesSize.length; i++) {
0482: assertEquals(samplesSizeB[i], samplesSize[i]);
0483: }
0484:
0485: samplesSize = sppsmu1.getSampleSize();
0486: assertEquals(samplesSizeUS.length, samplesSize.length);
0487: for (int i = 0; i < samplesSize.length; i++) {
0488: assertEquals(samplesSizeUS[i], samplesSize[i]);
0489: }
0490:
0491: samplesSize = sppsmu2.getSampleSize();
0492: assertEquals(samplesSizeUS.length, samplesSize.length);
0493: for (int i = 0; i < samplesSize.length; i++) {
0494: assertEquals(samplesSizeUS[i], samplesSize[i]);
0495: }
0496:
0497: samplesSize = sppsmi1.getSampleSize();
0498: assertEquals(samplesSizeI.length, samplesSize.length);
0499: for (int i = 0; i < samplesSize.length; i++) {
0500: assertEquals(samplesSizeI[i], samplesSize[i]);
0501: }
0502:
0503: samplesSize = sppsmi2.getSampleSize();
0504: assertEquals(samplesSizeI.length, samplesSize.length);
0505: for (int i = 0; i < samplesSize.length; i++) {
0506: assertEquals(samplesSizeI[i], samplesSize[i]);
0507: }
0508: }
0509:
0510: public final void testGetPixel() {
0511: initDataBuffers();
0512: int tpixel[] = null;
0513: int rpixel[];
0514:
0515: for (int y = 0; y < h; y++) {
0516: for (int x = 0; x < w; x++) {
0517: tpixel = sppsmb1.getPixel(x, y, tpixel, dbb1);
0518: rpixel = getPixelB(x, y);
0519: assertTrue(Arrays.equals(rpixel, tpixel));
0520: }
0521: }
0522:
0523: for (int y = 0; y < h; y++) {
0524: for (int x = 0; x < w; x++) {
0525: tpixel = sppsmb2.getPixel(x, y, tpixel, dbb2);
0526: rpixel = getPixelB(x, y);
0527: assertTrue(Arrays.equals(rpixel, tpixel));
0528: }
0529: }
0530:
0531: for (int y = 0; y < h; y++) {
0532: for (int x = 0; x < w; x++) {
0533: tpixel = sppsmu1.getPixel(x, y, tpixel, dbu1);
0534: rpixel = getPixelUS(x, y);
0535: assertTrue(Arrays.equals(rpixel, tpixel));
0536: }
0537: }
0538:
0539: for (int y = 0; y < h; y++) {
0540: for (int x = 0; x < w; x++) {
0541: tpixel = sppsmu2.getPixel(x, y, tpixel, dbu2);
0542: rpixel = getPixelUS(x, y);
0543: assertTrue(Arrays.equals(rpixel, tpixel));
0544: }
0545: }
0546:
0547: for (int y = 0; y < h; y++) {
0548: for (int x = 0; x < w; x++) {
0549: tpixel = sppsmi1.getPixel(x, y, tpixel, dbi1);
0550: rpixel = getPixelI(x, y);
0551: assertTrue(Arrays.equals(rpixel, tpixel));
0552: }
0553: }
0554:
0555: for (int y = 0; y < h; y++) {
0556: for (int x = 0; x < w; x++) {
0557: tpixel = sppsmi2.getPixel(x, y, tpixel, dbi2);
0558: rpixel = getPixelI(x, y);
0559: assertTrue(Arrays.equals(rpixel, tpixel));
0560: }
0561: }
0562: }
0563:
0564: public final void testGetPixels() {
0565: initDataBuffers();
0566: int tpixel[] = null;
0567: int rpixel[];
0568:
0569: tpixel = sppsmb1.getPixels(0, 0, 1, 1, tpixel, dbb1);
0570: rpixel = getPixelsB(0, 0, 1, 1);
0571: assertTrue(Arrays.equals(rpixel, tpixel));
0572:
0573: tpixel = null;
0574: tpixel = sppsmb1.getPixels(0, 0, w / 2, h / 2, tpixel, dbb1);
0575: rpixel = getPixelsB(0, 0, w / 2, h / 2);
0576: assertTrue(Arrays.equals(rpixel, tpixel));
0577:
0578: tpixel = null;
0579: tpixel = sppsmb1.getPixels(0, 0, w, h, tpixel, dbb1);
0580: rpixel = getPixelsB(0, 0, w, h);
0581: assertTrue(Arrays.equals(rpixel, tpixel));
0582:
0583: tpixel = null;
0584: tpixel = sppsmb2.getPixels(0, 0, 1, 1, tpixel, dbb2);
0585: rpixel = getPixelsB(0, 0, 1, 1);
0586: assertTrue(Arrays.equals(rpixel, tpixel));
0587:
0588: tpixel = null;
0589: tpixel = sppsmb2.getPixels(0, 0, w / 2, h / 2, tpixel, dbb2);
0590: rpixel = getPixelsB(0, 0, w / 2, h / 2);
0591: assertTrue(Arrays.equals(rpixel, tpixel));
0592:
0593: tpixel = null;
0594: tpixel = sppsmb2.getPixels(0, 0, w, h, tpixel, dbb2);
0595: rpixel = getPixelsB(0, 0, w, h);
0596: assertTrue(Arrays.equals(rpixel, tpixel));
0597:
0598: tpixel = null;
0599: tpixel = sppsmu1.getPixels(0, 0, 1, 1, tpixel, dbu1);
0600: rpixel = getPixelsUS(0, 0, 1, 1);
0601: assertTrue(Arrays.equals(rpixel, tpixel));
0602:
0603: tpixel = null;
0604: tpixel = sppsmu1.getPixels(0, 0, w / 2, h / 2, tpixel, dbu1);
0605: rpixel = getPixelsUS(0, 0, w / 2, h / 2);
0606: assertTrue(Arrays.equals(rpixel, tpixel));
0607:
0608: tpixel = null;
0609: tpixel = sppsmu1.getPixels(0, 0, w, h, tpixel, dbu1);
0610: rpixel = getPixelsUS(0, 0, w, h);
0611: assertTrue(Arrays.equals(rpixel, tpixel));
0612:
0613: tpixel = null;
0614: tpixel = sppsmu2.getPixels(0, 0, 1, 1, tpixel, dbu2);
0615: rpixel = getPixelsUS(0, 0, 1, 1);
0616: assertTrue(Arrays.equals(rpixel, tpixel));
0617:
0618: tpixel = null;
0619: tpixel = sppsmu2.getPixels(0, 0, w / 2, h / 2, tpixel, dbu2);
0620: rpixel = getPixelsUS(0, 0, w / 2, h / 2);
0621: assertTrue(Arrays.equals(rpixel, tpixel));
0622:
0623: tpixel = null;
0624: tpixel = sppsmu2.getPixels(0, 0, w, h, tpixel, dbu2);
0625: rpixel = getPixelsUS(0, 0, w, h);
0626: assertTrue(Arrays.equals(rpixel, tpixel));
0627:
0628: tpixel = null;
0629: tpixel = sppsmi1.getPixels(0, 0, 1, 1, tpixel, dbi1);
0630: rpixel = getPixelsI(0, 0, 1, 1);
0631: assertTrue(Arrays.equals(rpixel, tpixel));
0632:
0633: tpixel = null;
0634: tpixel = sppsmi1.getPixels(0, 0, w / 2, h / 2, tpixel, dbi1);
0635: rpixel = getPixelsI(0, 0, w / 2, h / 2);
0636: assertTrue(Arrays.equals(rpixel, tpixel));
0637:
0638: tpixel = null;
0639: tpixel = sppsmi1.getPixels(0, 0, w, h, tpixel, dbi1);
0640: rpixel = getPixelsI(0, 0, w, h);
0641: assertTrue(Arrays.equals(rpixel, tpixel));
0642:
0643: tpixel = null;
0644: tpixel = sppsmi2.getPixels(0, 0, 1, 1, tpixel, dbi2);
0645: rpixel = getPixelsI(0, 0, 1, 1);
0646: assertTrue(Arrays.equals(rpixel, tpixel));
0647:
0648: tpixel = null;
0649: tpixel = sppsmi2.getPixels(0, 0, w / 2, h / 2, tpixel, dbi2);
0650: rpixel = getPixelsI(0, 0, w / 2, h / 2);
0651: assertTrue(Arrays.equals(rpixel, tpixel));
0652:
0653: tpixel = null;
0654: tpixel = sppsmi2.getPixels(0, 0, w, h, tpixel, dbi2);
0655: rpixel = getPixelsI(0, 0, w, h);
0656: assertTrue(Arrays.equals(rpixel, tpixel));
0657:
0658: }
0659:
0660: public final void testGetSample() {
0661: initDataBuffers();
0662: int tsample;
0663: int rsample;
0664:
0665: for (int y = 0; y < h; y++) {
0666: for (int x = 0; x < w; x++) {
0667: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
0668: tsample = sppsmb1.getSample(x, y, b, dbb1);
0669: rsample = getSampleB(x, y, b);
0670: assertEquals(tsample, rsample);
0671: }
0672: }
0673: }
0674:
0675: for (int y = 0; y < h; y++) {
0676: for (int x = 0; x < w; x++) {
0677: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
0678: tsample = sppsmb2.getSample(x, y, b, dbb2);
0679: rsample = getSampleB(x, y, b);
0680: assertEquals(tsample, rsample);
0681: }
0682: }
0683: }
0684:
0685: for (int y = 0; y < h; y++) {
0686: for (int x = 0; x < w; x++) {
0687: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
0688: tsample = sppsmu1.getSample(x, y, b, dbu1);
0689: rsample = getSampleUS(x, y, b);
0690: assertEquals(tsample, rsample);
0691: }
0692: }
0693: }
0694:
0695: for (int y = 0; y < h; y++) {
0696: for (int x = 0; x < w; x++) {
0697: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
0698: tsample = sppsmu2.getSample(x, y, b, dbu2);
0699: rsample = getSampleUS(x, y, b);
0700: assertEquals(tsample, rsample);
0701: }
0702: }
0703: }
0704:
0705: for (int y = 0; y < h; y++) {
0706: for (int x = 0; x < w; x++) {
0707: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
0708: tsample = sppsmi1.getSample(x, y, b, dbi1);
0709: rsample = getSampleI(x, y, b);
0710: assertEquals(tsample, rsample);
0711: }
0712: }
0713: }
0714:
0715: for (int y = 0; y < h; y++) {
0716: for (int x = 0; x < w; x++) {
0717: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
0718: tsample = sppsmi2.getSample(x, y, b, dbi2);
0719: rsample = getSampleI(x, y, b);
0720: assertEquals(tsample, rsample);
0721: }
0722: }
0723: }
0724: }
0725:
0726: public final void testGetSamples() {
0727: initDataBuffers();
0728: int rsamples[];
0729: int tsamples[];
0730:
0731: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
0732: tsamples = null;
0733: tsamples = sppsmb1
0734: .getSamples(0, 0, 1, 1, b, tsamples, dbb1);
0735: rsamples = getSamplesB(0, 0, 1, 1, b);
0736: assertTrue(Arrays.equals(rsamples, tsamples));
0737: }
0738:
0739: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
0740: tsamples = null;
0741: tsamples = sppsmb1.getSamples(0, 0, w / 2, h / 2, b,
0742: tsamples, dbb1);
0743: rsamples = getSamplesB(0, 0, w / 2, h / 2, b);
0744: assertTrue(Arrays.equals(rsamples, tsamples));
0745: }
0746:
0747: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
0748: tsamples = null;
0749: tsamples = sppsmb1
0750: .getSamples(0, 0, w, h, b, tsamples, dbb1);
0751: rsamples = getSamplesB(0, 0, w, h, b);
0752: assertTrue(Arrays.equals(rsamples, tsamples));
0753: }
0754:
0755: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
0756: tsamples = null;
0757: tsamples = sppsmb2
0758: .getSamples(0, 0, 1, 1, b, tsamples, dbb2);
0759: rsamples = getSamplesB(0, 0, 1, 1, b);
0760: assertTrue(Arrays.equals(rsamples, tsamples));
0761: }
0762:
0763: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
0764: tsamples = null;
0765: tsamples = sppsmb2.getSamples(0, 0, w / 2, h / 2, b,
0766: tsamples, dbb2);
0767: rsamples = getSamplesB(0, 0, w / 2, h / 2, b);
0768: assertTrue(Arrays.equals(rsamples, tsamples));
0769: }
0770:
0771: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
0772: tsamples = null;
0773: tsamples = sppsmb2
0774: .getSamples(0, 0, w, h, b, tsamples, dbb2);
0775: rsamples = getSamplesB(0, 0, w, h, b);
0776: assertTrue(Arrays.equals(rsamples, tsamples));
0777: }
0778:
0779: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
0780: tsamples = null;
0781: tsamples = sppsmu1
0782: .getSamples(0, 0, 1, 1, b, tsamples, dbu1);
0783: rsamples = getSamplesUS(0, 0, 1, 1, b);
0784: assertTrue(Arrays.equals(rsamples, tsamples));
0785: }
0786:
0787: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
0788: tsamples = null;
0789: tsamples = sppsmu1.getSamples(0, 0, w / 2, h / 2, b,
0790: tsamples, dbu1);
0791: rsamples = getSamplesUS(0, 0, w / 2, h / 2, b);
0792: assertTrue(Arrays.equals(rsamples, tsamples));
0793: }
0794:
0795: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
0796: tsamples = null;
0797: tsamples = sppsmu1
0798: .getSamples(0, 0, w, h, b, tsamples, dbu1);
0799: rsamples = getSamplesUS(0, 0, w, h, b);
0800: assertTrue(Arrays.equals(rsamples, tsamples));
0801: }
0802:
0803: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
0804: tsamples = null;
0805: tsamples = sppsmu2
0806: .getSamples(0, 0, 1, 1, b, tsamples, dbu2);
0807: rsamples = getSamplesUS(0, 0, 1, 1, b);
0808: assertTrue(Arrays.equals(rsamples, tsamples));
0809: }
0810:
0811: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
0812: tsamples = null;
0813: tsamples = sppsmu2.getSamples(0, 0, w / 2, h / 2, b,
0814: tsamples, dbu2);
0815: rsamples = getSamplesUS(0, 0, w / 2, h / 2, b);
0816: assertTrue(Arrays.equals(rsamples, tsamples));
0817: }
0818:
0819: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
0820: tsamples = null;
0821: tsamples = sppsmu2
0822: .getSamples(0, 0, w, h, b, tsamples, dbu2);
0823: rsamples = getSamplesUS(0, 0, w, h, b);
0824: assertTrue(Arrays.equals(rsamples, tsamples));
0825: }
0826:
0827: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
0828: tsamples = null;
0829: tsamples = sppsmi1
0830: .getSamples(0, 0, 1, 1, b, tsamples, dbi1);
0831: rsamples = getSamplesI(0, 0, 1, 1, b);
0832: assertTrue(Arrays.equals(rsamples, tsamples));
0833: }
0834:
0835: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
0836: tsamples = null;
0837: tsamples = sppsmi1.getSamples(0, 0, w / 2, h / 2, b,
0838: tsamples, dbi1);
0839: rsamples = getSamplesI(0, 0, w / 2, h / 2, b);
0840: assertTrue(Arrays.equals(rsamples, tsamples));
0841: }
0842:
0843: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
0844: tsamples = null;
0845: tsamples = sppsmi1
0846: .getSamples(0, 0, w, h, b, tsamples, dbi1);
0847: rsamples = getSamplesI(0, 0, w, h, b);
0848: assertTrue(Arrays.equals(rsamples, tsamples));
0849: }
0850:
0851: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
0852: tsamples = null;
0853: tsamples = sppsmi2
0854: .getSamples(0, 0, 1, 1, b, tsamples, dbi2);
0855: rsamples = getSamplesI(0, 0, 1, 1, b);
0856: assertTrue(Arrays.equals(rsamples, tsamples));
0857: }
0858:
0859: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
0860: tsamples = null;
0861: tsamples = sppsmi2.getSamples(0, 0, w / 2, h / 2, b,
0862: tsamples, dbi2);
0863: rsamples = getSamplesI(0, 0, w / 2, h / 2, b);
0864: assertTrue(Arrays.equals(rsamples, tsamples));
0865: }
0866:
0867: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
0868: tsamples = null;
0869: tsamples = sppsmi2
0870: .getSamples(0, 0, w, h, b, tsamples, dbi2);
0871: rsamples = getSamplesI(0, 0, w, h, b);
0872: assertTrue(Arrays.equals(rsamples, tsamples));
0873: }
0874:
0875: // Regression for HARMONY-2431
0876: try {
0877: new SinglePixelPackedSampleModel(3, 216, 1, new int[851])
0878: .getSamples(6, 7, 14, Integer.MAX_VALUE, 0,
0879: new int[] { 0, 0, 0 },
0880: new DataBufferDouble(7, 5));
0881: fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
0882: } catch (ArrayIndexOutOfBoundsException ex) {
0883: // expected
0884: }
0885: }
0886:
0887: public final void testGetDataElements() {
0888: initDataBuffers();
0889: Object tDE, rDE;
0890:
0891: tDE = null;
0892: for (int y = 0; y < h; y++) {
0893: for (int x = 0; x < w; x++) {
0894: tDE = sppsmb1.getDataElements(x, y, tDE, dbb1);
0895: rDE = getDataElementB(x, y);
0896: assertTrue(tDE instanceof byte[]);
0897: byte tde[] = (byte[]) tDE;
0898: byte rde[] = (byte[]) rDE;
0899: assertTrue(Arrays.equals(tde, rde));
0900: }
0901: }
0902:
0903: for (int y = 0; y < h; y++) {
0904: for (int x = 0; x < w; x++) {
0905: tDE = sppsmb2.getDataElements(x, y, tDE, dbb2);
0906: rDE = getDataElementB(x, y);
0907: assertTrue(tDE instanceof byte[]);
0908: byte tde[] = (byte[]) tDE;
0909: byte rde[] = (byte[]) rDE;
0910: assertTrue(Arrays.equals(tde, rde));
0911: }
0912: }
0913:
0914: tDE = null;
0915: for (int y = 0; y < h; y++) {
0916: for (int x = 0; x < w; x++) {
0917: tDE = sppsmu1.getDataElements(x, y, tDE, dbu1);
0918: rDE = getDataElementUS(x, y);
0919: assertTrue(tDE instanceof short[]);
0920: short tde[] = (short[]) tDE;
0921: short rde[] = (short[]) rDE;
0922: assertTrue(Arrays.equals(tde, rde));
0923: }
0924: }
0925:
0926: for (int y = 0; y < h; y++) {
0927: for (int x = 0; x < w; x++) {
0928: tDE = sppsmu2.getDataElements(x, y, tDE, dbu2);
0929: rDE = getDataElementUS(x, y);
0930: assertTrue(tDE instanceof short[]);
0931: short tde[] = (short[]) tDE;
0932: short rde[] = (short[]) rDE;
0933: assertTrue(Arrays.equals(tde, rde));
0934: }
0935: }
0936:
0937: tDE = null;
0938: for (int y = 0; y < h; y++) {
0939: for (int x = 0; x < w; x++) {
0940: tDE = sppsmi1.getDataElements(x, y, tDE, dbi1);
0941: rDE = getDataElementI(x, y);
0942: assertTrue(tDE instanceof int[]);
0943: int tde[] = (int[]) tDE;
0944: int rde[] = (int[]) rDE;
0945: assertTrue(Arrays.equals(tde, rde));
0946: }
0947: }
0948:
0949: for (int y = 0; y < h; y++) {
0950: for (int x = 0; x < w; x++) {
0951: tDE = sppsmi2.getDataElements(x, y, tDE, dbi2);
0952: rDE = getDataElementI(x, y);
0953: assertTrue(tDE instanceof int[]);
0954: int tde[] = (int[]) tDE;
0955: int rde[] = (int[]) rDE;
0956: assertTrue(Arrays.equals(tde, rde));
0957: }
0958: }
0959: }
0960:
0961: public final void testGetDataElementsA() {
0962: initDataBuffers();
0963: Object tDE, rDE;
0964: byte tde[];
0965: byte rde[];
0966: short stde[];
0967: short srde[];
0968: int itde[];
0969: int irde[];
0970:
0971: tDE = null;
0972: tDE = sppsmb1.getDataElements(0, 0, 1, 1, tDE, dbb1);
0973: rDE = getDataElementsB(0, 0, 1, 1);
0974: assertTrue(tDE instanceof byte[]);
0975: tde = (byte[]) tDE;
0976: rde = (byte[]) rDE;
0977: assertTrue(Arrays.equals(tde, rde));
0978:
0979: tDE = null;
0980: tDE = sppsmb1.getDataElements(0, 0, w / 2, h / 2, tDE, dbb1);
0981: rDE = getDataElementsB(0, 0, w / 2, h / 2);
0982: assertTrue(tDE instanceof byte[]);
0983: tde = (byte[]) tDE;
0984: rde = (byte[]) rDE;
0985: assertTrue(Arrays.equals(tde, rde));
0986:
0987: tDE = null;
0988: tDE = sppsmb1.getDataElements(0, 0, w, h, tDE, dbb1);
0989: rDE = getDataElementsB(0, 0, w, h);
0990: assertTrue(tDE instanceof byte[]);
0991: tde = (byte[]) tDE;
0992: rde = (byte[]) rDE;
0993: assertTrue(Arrays.equals(tde, rde));
0994:
0995: tDE = null;
0996: tDE = sppsmb2.getDataElements(0, 0, 1, 1, tDE, dbb2);
0997: rDE = getDataElementsB(0, 0, 1, 1);
0998: assertTrue(tDE instanceof byte[]);
0999: tde = (byte[]) tDE;
1000: rde = (byte[]) rDE;
1001: assertTrue(Arrays.equals(tde, rde));
1002:
1003: tDE = null;
1004: tDE = sppsmb2.getDataElements(0, 0, w / 2, h / 2, tDE, dbb2);
1005: rDE = getDataElementsB(0, 0, w / 2, h / 2);
1006: assertTrue(tDE instanceof byte[]);
1007: tde = (byte[]) tDE;
1008: rde = (byte[]) rDE;
1009: assertTrue(Arrays.equals(tde, rde));
1010:
1011: tDE = null;
1012: tDE = sppsmb2.getDataElements(0, 0, w, h, tDE, dbb2);
1013: rDE = getDataElementsB(0, 0, w, h);
1014: assertTrue(tDE instanceof byte[]);
1015: tde = (byte[]) tDE;
1016: rde = (byte[]) rDE;
1017: assertTrue(Arrays.equals(tde, rde));
1018:
1019: tDE = null;
1020: tDE = sppsmu1.getDataElements(0, 0, 1, 1, tDE, dbu1);
1021: rDE = getDataElementsUS(0, 0, 1, 1);
1022: assertTrue(tDE instanceof short[]);
1023: stde = (short[]) tDE;
1024: srde = (short[]) rDE;
1025: assertTrue(Arrays.equals(stde, srde));
1026:
1027: tDE = null;
1028: tDE = sppsmu1.getDataElements(0, 0, w / 2, h / 2, tDE, dbu1);
1029: rDE = getDataElementsUS(0, 0, w / 2, h / 2);
1030: assertTrue(tDE instanceof short[]);
1031: stde = (short[]) tDE;
1032: srde = (short[]) rDE;
1033: assertTrue(Arrays.equals(stde, srde));
1034:
1035: tDE = null;
1036: tDE = sppsmu1.getDataElements(0, 0, w, h, tDE, dbu1);
1037: rDE = getDataElementsUS(0, 0, w, h);
1038: assertTrue(tDE instanceof short[]);
1039: stde = (short[]) tDE;
1040: srde = (short[]) rDE;
1041: assertTrue(Arrays.equals(stde, srde));
1042:
1043: tDE = null;
1044: tDE = sppsmu2.getDataElements(0, 0, 1, 1, tDE, dbu2);
1045: rDE = getDataElementsUS(0, 0, 1, 1);
1046: assertTrue(tDE instanceof short[]);
1047: stde = (short[]) tDE;
1048: srde = (short[]) rDE;
1049: assertTrue(Arrays.equals(stde, srde));
1050:
1051: tDE = null;
1052: tDE = sppsmu2.getDataElements(0, 0, w / 2, h / 2, tDE, dbu2);
1053: rDE = getDataElementsUS(0, 0, w / 2, h / 2);
1054: assertTrue(tDE instanceof short[]);
1055: stde = (short[]) tDE;
1056: srde = (short[]) rDE;
1057: assertTrue(Arrays.equals(stde, srde));
1058:
1059: tDE = null;
1060: tDE = sppsmu2.getDataElements(0, 0, w, h, tDE, dbu2);
1061: rDE = getDataElementsUS(0, 0, w, h);
1062: assertTrue(tDE instanceof short[]);
1063: stde = (short[]) tDE;
1064: srde = (short[]) rDE;
1065: assertTrue(Arrays.equals(stde, srde));
1066:
1067: tDE = null;
1068: tDE = sppsmi1.getDataElements(0, 0, 1, 1, tDE, dbi1);
1069: rDE = getDataElementsI(0, 0, 1, 1);
1070: assertTrue(tDE instanceof int[]);
1071: itde = (int[]) tDE;
1072: irde = (int[]) rDE;
1073: assertTrue(Arrays.equals(itde, irde));
1074:
1075: tDE = null;
1076: tDE = sppsmi1.getDataElements(0, 0, w / 2, h / 2, tDE, dbi1);
1077: rDE = getDataElementsI(0, 0, w / 2, h / 2);
1078: assertTrue(tDE instanceof int[]);
1079: itde = (int[]) tDE;
1080: irde = (int[]) rDE;
1081: assertTrue(Arrays.equals(itde, irde));
1082:
1083: tDE = null;
1084: tDE = sppsmi1.getDataElements(0, 0, w, h, tDE, dbi1);
1085: rDE = getDataElementsI(0, 0, w, h);
1086: assertTrue(tDE instanceof int[]);
1087: itde = (int[]) tDE;
1088: irde = (int[]) rDE;
1089: assertTrue(Arrays.equals(itde, irde));
1090:
1091: tDE = null;
1092: tDE = sppsmi2.getDataElements(0, 0, 1, 1, tDE, dbi2);
1093: rDE = getDataElementsI(0, 0, 1, 1);
1094: assertTrue(tDE instanceof int[]);
1095: itde = (int[]) tDE;
1096: irde = (int[]) rDE;
1097: assertTrue(Arrays.equals(tde, rde));
1098:
1099: tDE = null;
1100: tDE = sppsmi2.getDataElements(0, 0, w / 2, h / 2, tDE, dbi2);
1101: rDE = getDataElementsI(0, 0, w / 2, h / 2);
1102: assertTrue(tDE instanceof int[]);
1103: itde = (int[]) tDE;
1104: irde = (int[]) rDE;
1105: assertTrue(Arrays.equals(tde, rde));
1106:
1107: tDE = null;
1108: tDE = sppsmi2.getDataElements(0, 0, w, h, tDE, dbi2);
1109: rDE = getDataElementsI(0, 0, w, h);
1110: assertTrue(tDE instanceof int[]);
1111: itde = (int[]) tDE;
1112: irde = (int[]) rDE;
1113: assertTrue(Arrays.equals(tde, rde));
1114: }
1115:
1116: private void initDataBuffers() {
1117: for (int y = 0; y < h; y++) {
1118: for (int x = 0; x < w; x++) {
1119: dbb1.setElem(y * w + x, byteTestData[y * w + x]);
1120: }
1121: }
1122:
1123: for (int y = 0; y < h; y++) {
1124: for (int x = 0; x < w; x++) {
1125: dbb2.setElem(y * scanlineStride + x, byteTestData[y * w
1126: + x]);
1127: }
1128: }
1129: for (int y = 0; y < h; y++) {
1130: for (int x = 0; x < w; x++) {
1131: dbu1.setElem(y * w + x, shortTestData[y * w + x]);
1132: }
1133: }
1134: for (int y = 0; y < h; y++) {
1135: for (int x = 0; x < w; x++) {
1136: dbu2.setElem(y * scanlineStride + x, shortTestData[y
1137: * w + x]);
1138: }
1139: }
1140: for (int y = 0; y < h; y++) {
1141: for (int x = 0; x < w; x++) {
1142: dbi1.setElem(y * w + x, intTestData[y * w + x]);
1143: }
1144: }
1145: for (int y = 0; y < h; y++) {
1146: for (int x = 0; x < w; x++) {
1147: dbi2.setElem(y * scanlineStride + x, intTestData[y * w
1148: + x]);
1149: }
1150: }
1151: }
1152:
1153: public final void testSetDataElements() {
1154: initTestData();
1155: byte bdata[];
1156: short sdata[];
1157: int idata[];
1158:
1159: int idx = 0;
1160: byte bde[] = new byte[1];
1161: for (int y = 0; y < h; y++) {
1162: for (int x = 0; x < w; x++) {
1163: bde[0] = byteTestData[idx++];
1164: sppsmb1.setDataElements(x, y, bde, dbb1);
1165: }
1166: }
1167: idx = 0;
1168: bdata = dbb1.getData();
1169: for (int y = 0; y < h; y++) {
1170: for (int x = 0; x < w; x++) {
1171: assertEquals(
1172: bdata[y * sppsmb1.getScanlineStride() + x],
1173: byteTestData[idx++]);
1174: }
1175: }
1176:
1177: idx = 0;
1178: for (int y = 0; y < h; y++) {
1179: for (int x = 0; x < w; x++) {
1180: bde[0] = byteTestData[idx++];
1181: sppsmb2.setDataElements(x, y, bde, dbb2);
1182: }
1183: }
1184: idx = 0;
1185: bdata = dbb2.getData();
1186: for (int y = 0; y < h; y++) {
1187: for (int x = 0; x < w; x++) {
1188: assertEquals(
1189: bdata[y * sppsmb2.getScanlineStride() + x],
1190: byteTestData[idx++]);
1191: }
1192: }
1193:
1194: idx = 0;
1195: short sde[] = new short[1];
1196: for (int y = 0; y < h; y++) {
1197: for (int x = 0; x < w; x++) {
1198: sde[0] = shortTestData[idx++];
1199: sppsmu1.setDataElements(x, y, sde, dbu1);
1200: }
1201: }
1202: idx = 0;
1203: sdata = dbu1.getData();
1204: for (int y = 0; y < h; y++) {
1205: for (int x = 0; x < w; x++) {
1206: assertEquals(
1207: sdata[y * sppsmu1.getScanlineStride() + x],
1208: shortTestData[idx++]);
1209: }
1210: }
1211:
1212: idx = 0;
1213: for (int y = 0; y < h; y++) {
1214: for (int x = 0; x < w; x++) {
1215: sde[0] = shortTestData[idx++];
1216: sppsmu2.setDataElements(x, y, sde, dbu2);
1217: }
1218: }
1219: idx = 0;
1220: sdata = dbu2.getData();
1221: for (int y = 0; y < h; y++) {
1222: for (int x = 0; x < w; x++) {
1223: assertEquals(
1224: sdata[y * sppsmu2.getScanlineStride() + x],
1225: shortTestData[idx++]);
1226: }
1227: }
1228:
1229: idx = 0;
1230: int ide[] = new int[1];
1231: for (int y = 0; y < h; y++) {
1232: for (int x = 0; x < w; x++) {
1233: ide[0] = intTestData[idx++];
1234: sppsmi1.setDataElements(x, y, ide, dbi1);
1235: }
1236: }
1237: idx = 0;
1238: idata = dbi1.getData();
1239: for (int y = 0; y < h; y++) {
1240: for (int x = 0; x < w; x++) {
1241: assertEquals(
1242: idata[y * sppsmi1.getScanlineStride() + x],
1243: intTestData[idx++]);
1244: }
1245: }
1246:
1247: idx = 0;
1248: for (int y = 0; y < h; y++) {
1249: for (int x = 0; x < w; x++) {
1250: ide[0] = intTestData[idx++];
1251: sppsmi2.setDataElements(x, y, ide, dbi2);
1252: }
1253: }
1254: idx = 0;
1255: idata = dbi2.getData();
1256: for (int y = 0; y < h; y++) {
1257: for (int x = 0; x < w; x++) {
1258: assertEquals(
1259: idata[y * sppsmi2.getScanlineStride() + x],
1260: intTestData[idx++]);
1261: }
1262: }
1263: }
1264:
1265: public final void testSetDataElementsA() {
1266: initTestData();
1267: byte bdata[];
1268: short sdata[];
1269: int idata[];
1270:
1271: sppsmb1.setDataElements(0, 0, w, h, byteTestData, dbb1);
1272: int idx = 0;
1273: bdata = dbb1.getData();
1274: for (int y = 0; y < h; y++) {
1275: for (int x = 0; x < w; x++) {
1276: assertEquals(
1277: bdata[y * sppsmb1.getScanlineStride() + x],
1278: byteTestData[idx++]);
1279: }
1280: }
1281:
1282: sppsmb2.setDataElements(0, 0, w, h, byteTestData, dbb2);
1283: idx = 0;
1284: bdata = dbb2.getData();
1285: for (int y = 0; y < h; y++) {
1286: for (int x = 0; x < w; x++) {
1287: assertEquals(
1288: bdata[y * sppsmb2.getScanlineStride() + x],
1289: byteTestData[idx++]);
1290: }
1291: }
1292:
1293: sppsmu1.setDataElements(0, 0, w, h, shortTestData, dbu1);
1294: idx = 0;
1295: sdata = dbu1.getData();
1296: for (int y = 0; y < h; y++) {
1297: for (int x = 0; x < w; x++) {
1298: assertEquals(
1299: sdata[y * sppsmu1.getScanlineStride() + x],
1300: shortTestData[idx++]);
1301: }
1302: }
1303:
1304: sppsmu2.setDataElements(0, 0, w, h, shortTestData, dbu2);
1305: idx = 0;
1306: sdata = dbu2.getData();
1307: for (int y = 0; y < h; y++) {
1308: for (int x = 0; x < w; x++) {
1309: assertEquals(
1310: sdata[y * sppsmu2.getScanlineStride() + x],
1311: shortTestData[idx++]);
1312: }
1313: }
1314:
1315: sppsmi1.setDataElements(0, 0, w, h, intTestData, dbi1);
1316: idx = 0;
1317: idata = dbi1.getData();
1318: for (int y = 0; y < h; y++) {
1319: for (int x = 0; x < w; x++) {
1320: assertEquals(
1321: idata[y * sppsmi1.getScanlineStride() + x],
1322: intTestData[idx++]);
1323: }
1324: }
1325:
1326: sppsmi2.setDataElements(0, 0, w, h, intTestData, dbi2);
1327: idx = 0;
1328: idata = dbi2.getData();
1329: for (int y = 0; y < h; y++) {
1330: for (int x = 0; x < w; x++) {
1331: assertEquals(
1332: idata[y * sppsmi2.getScanlineStride() + x],
1333: intTestData[idx++]);
1334: }
1335: }
1336: }
1337:
1338: public final void testSetPixel() {
1339: initTestData();
1340: byte bdata[];
1341: short sdata[];
1342: int idata[];
1343: int idx;
1344:
1345: idx = 0;
1346: for (int y = 0; y < h; y++) {
1347: for (int x = 0; x < w; x++) {
1348: int pixel[] = createPixelFromByteDataElem(byteTestData[idx++]);
1349: sppsmb1.setPixel(x, y, pixel, dbb1);
1350: }
1351: }
1352: idx = 0;
1353: bdata = dbb1.getData();
1354: for (int y = 0; y < h; y++) {
1355: for (int x = 0; x < w; x++) {
1356: assertEquals(
1357: bdata[y * sppsmb1.getScanlineStride() + x],
1358: byteTestData[idx++]);
1359: }
1360: }
1361:
1362: idx = 0;
1363: for (int y = 0; y < h; y++) {
1364: for (int x = 0; x < w; x++) {
1365: int pixel[] = createPixelFromByteDataElem(byteTestData[idx++]);
1366: sppsmb2.setPixel(x, y, pixel, dbb2);
1367: }
1368: }
1369: idx = 0;
1370: bdata = dbb2.getData();
1371: for (int y = 0; y < h; y++) {
1372: for (int x = 0; x < w; x++) {
1373: assertEquals(
1374: bdata[y * sppsmb2.getScanlineStride() + x],
1375: byteTestData[idx++]);
1376: }
1377: }
1378:
1379: idx = 0;
1380: for (int y = 0; y < h; y++) {
1381: for (int x = 0; x < w; x++) {
1382: int pixel[] = createPixelFromShortDataElem(shortTestData[idx++]);
1383: sppsmu1.setPixel(x, y, pixel, dbu1);
1384: }
1385: }
1386: idx = 0;
1387: sdata = dbu1.getData();
1388: for (int y = 0; y < h; y++) {
1389: for (int x = 0; x < w; x++) {
1390: assertEquals(
1391: sdata[y * sppsmu1.getScanlineStride() + x],
1392: shortTestData[idx++]);
1393: }
1394: }
1395:
1396: idx = 0;
1397: for (int y = 0; y < h; y++) {
1398: for (int x = 0; x < w; x++) {
1399: int pixel[] = createPixelFromShortDataElem(shortTestData[idx++]);
1400: sppsmu2.setPixel(x, y, pixel, dbu2);
1401: }
1402: }
1403: idx = 0;
1404: sdata = dbu2.getData();
1405: for (int y = 0; y < h; y++) {
1406: for (int x = 0; x < w; x++) {
1407: assertEquals(
1408: sdata[y * sppsmu2.getScanlineStride() + x],
1409: shortTestData[idx++]);
1410: }
1411: }
1412:
1413: idx = 0;
1414: for (int y = 0; y < h; y++) {
1415: for (int x = 0; x < w; x++) {
1416: int pixel[] = createPixelFromIntDataElem(intTestData[idx++]);
1417: sppsmi1.setPixel(x, y, pixel, dbi1);
1418: }
1419: }
1420: idx = 0;
1421: idata = dbi1.getData();
1422: for (int y = 0; y < h; y++) {
1423: for (int x = 0; x < w; x++) {
1424: assertEquals(
1425: idata[y * sppsmi1.getScanlineStride() + x],
1426: intTestData[idx++]);
1427: }
1428: }
1429:
1430: idx = 0;
1431: for (int y = 0; y < h; y++) {
1432: for (int x = 0; x < w; x++) {
1433: int pixel[] = createPixelFromIntDataElem(intTestData[idx++]);
1434: sppsmi2.setPixel(x, y, pixel, dbi2);
1435: }
1436: }
1437: idx = 0;
1438: idata = dbi2.getData();
1439: for (int y = 0; y < h; y++) {
1440: for (int x = 0; x < w; x++) {
1441: assertEquals(
1442: idata[y * sppsmi2.getScanlineStride() + x],
1443: intTestData[idx++]);
1444: }
1445: }
1446: }
1447:
1448: public final void testSetPixels() {
1449: initTestData();
1450: int pixels[];
1451: byte bdata[];
1452: short sdata[];
1453: int idata[];
1454:
1455: pixels = createPixelsFromByteDataElements(byteTestData);
1456: sppsmb1.setPixels(0, 0, w, h, pixels, dbb1);
1457: int idx = 0;
1458: bdata = dbb1.getData();
1459: for (int y = 0; y < h; y++) {
1460: for (int x = 0; x < w; x++) {
1461: assertEquals(
1462: bdata[y * sppsmb1.getScanlineStride() + x],
1463: byteTestData[idx++]);
1464: }
1465: }
1466:
1467: sppsmb2.setPixels(0, 0, w, h, pixels, dbb2);
1468: idx = 0;
1469: bdata = dbb2.getData();
1470: for (int y = 0; y < h; y++) {
1471: for (int x = 0; x < w; x++) {
1472: assertEquals(
1473: bdata[y * sppsmb2.getScanlineStride() + x],
1474: byteTestData[idx++]);
1475: }
1476: }
1477:
1478: pixels = createPixelsFromShortDataElements(shortTestData);
1479: sppsmu1.setPixels(0, 0, w, h, pixels, dbu1);
1480: idx = 0;
1481: sdata = dbu1.getData();
1482: for (int y = 0; y < h; y++) {
1483: for (int x = 0; x < w; x++) {
1484: assertEquals(
1485: sdata[y * sppsmu1.getScanlineStride() + x],
1486: shortTestData[idx++]);
1487: }
1488: }
1489:
1490: sppsmu2.setPixels(0, 0, w, h, pixels, dbu2);
1491: idx = 0;
1492: sdata = dbu2.getData();
1493: for (int y = 0; y < h; y++) {
1494: for (int x = 0; x < w; x++) {
1495: assertEquals(
1496: sdata[y * sppsmu2.getScanlineStride() + x],
1497: shortTestData[idx++]);
1498: }
1499: }
1500:
1501: pixels = createPixelsFromIntDataElements(intTestData);
1502: sppsmi1.setPixels(0, 0, w, h, pixels, dbi1);
1503: idx = 0;
1504: idata = dbi1.getData();
1505: for (int y = 0; y < h; y++) {
1506: for (int x = 0; x < w; x++) {
1507: assertEquals(
1508: idata[y * sppsmi1.getScanlineStride() + x],
1509: intTestData[idx++]);
1510: }
1511: }
1512:
1513: sppsmi2.setPixels(0, 0, w, h, pixels, dbi2);
1514: idx = 0;
1515: idata = dbi2.getData();
1516: for (int y = 0; y < h; y++) {
1517: for (int x = 0; x < w; x++) {
1518: assertEquals(
1519: idata[y * sppsmi2.getScanlineStride() + x],
1520: intTestData[idx++]);
1521: }
1522: }
1523:
1524: // Regression for HARMONY-2431
1525: try {
1526: new SinglePixelPackedSampleModel(1, 127, 3, 0, new int[970])
1527: .setPixels(Integer.MAX_VALUE, 1, 13, 1,
1528: new int[] {}, new DataBufferDouble(7, 5));
1529: fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
1530: } catch (ArrayIndexOutOfBoundsException ex) {
1531: // expected
1532: }
1533: }
1534:
1535: public final void testSetSample() {
1536: initTestData();
1537: int sample, idx;
1538: byte bdata[];
1539: short sdata[];
1540: int idata[];
1541:
1542: idx = 0;
1543: for (int y = 0; y < h; y++) {
1544: for (int x = 0; x < w; x++) {
1545: byte byteDataElem = byteTestData[idx++];
1546: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
1547: sample = createSampleFromByteDataElem(byteDataElem,
1548: b);
1549: sppsmb1.setSample(x, y, b, sample, dbb1);
1550: }
1551: }
1552: }
1553: idx = 0;
1554: bdata = dbb1.getData();
1555: for (int y = 0; y < h; y++) {
1556: for (int x = 0; x < w; x++) {
1557: assertEquals(
1558: bdata[y * sppsmb1.getScanlineStride() + x],
1559: byteTestData[idx++]);
1560: }
1561: }
1562:
1563: idx = 0;
1564: for (int y = 0; y < h; y++) {
1565: for (int x = 0; x < w; x++) {
1566: byte byteDataElem = byteTestData[idx++];
1567: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
1568: sample = createSampleFromByteDataElem(byteDataElem,
1569: b);
1570: sppsmb2.setSample(x, y, b, sample, dbb2);
1571: }
1572: }
1573: }
1574: idx = 0;
1575: bdata = dbb2.getData();
1576: for (int y = 0; y < h; y++) {
1577: for (int x = 0; x < w; x++) {
1578: assertEquals(
1579: bdata[y * sppsmb2.getScanlineStride() + x],
1580: byteTestData[idx++]);
1581: }
1582: }
1583:
1584: idx = 0;
1585: for (int y = 0; y < h; y++) {
1586: for (int x = 0; x < w; x++) {
1587: short shortDataElem = shortTestData[idx++];
1588: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
1589: sample = createSampleFromShortDataElem(
1590: shortDataElem, b);
1591: sppsmu1.setSample(x, y, b, sample, dbu1);
1592: }
1593: }
1594: }
1595: idx = 0;
1596: sdata = dbu1.getData();
1597: for (int y = 0; y < h; y++) {
1598: for (int x = 0; x < w; x++) {
1599: assertEquals(
1600: sdata[y * sppsmu1.getScanlineStride() + x],
1601: shortTestData[idx++]);
1602: }
1603: }
1604:
1605: idx = 0;
1606: for (int y = 0; y < h; y++) {
1607: for (int x = 0; x < w; x++) {
1608: short shortDataElem = shortTestData[idx++];
1609: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
1610: sample = createSampleFromShortDataElem(
1611: shortDataElem, b);
1612: sppsmu2.setSample(x, y, b, sample, dbu2);
1613: }
1614: }
1615: }
1616: idx = 0;
1617: sdata = dbu2.getData();
1618: for (int y = 0; y < h; y++) {
1619: for (int x = 0; x < w; x++) {
1620: assertEquals(
1621: sdata[y * sppsmu2.getScanlineStride() + x],
1622: shortTestData[idx++]);
1623: }
1624: }
1625:
1626: idx = 0;
1627: for (int y = 0; y < h; y++) {
1628: for (int x = 0; x < w; x++) {
1629: int intDataElem = intTestData[idx++];
1630: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
1631: sample = createSampleFromIntDataElem(intDataElem, b);
1632: sppsmi1.setSample(x, y, b, sample, dbi1);
1633: }
1634: }
1635: }
1636: idx = 0;
1637: idata = dbi1.getData();
1638: for (int y = 0; y < h; y++) {
1639: for (int x = 0; x < w; x++) {
1640: assertEquals(
1641: idata[y * sppsmi1.getScanlineStride() + x],
1642: intTestData[idx++]);
1643: }
1644: }
1645:
1646: idx = 0;
1647: for (int y = 0; y < h; y++) {
1648: for (int x = 0; x < w; x++) {
1649: int intDataElem = intTestData[idx++];
1650: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
1651: sample = createSampleFromIntDataElem(intDataElem, b);
1652: sppsmi2.setSample(x, y, b, sample, dbi2);
1653: }
1654: }
1655: }
1656: idx = 0;
1657: idata = dbi2.getData();
1658: for (int y = 0; y < h; y++) {
1659: for (int x = 0; x < w; x++) {
1660: assertEquals(
1661: idata[y * sppsmi2.getScanlineStride() + x],
1662: intTestData[idx++]);
1663: }
1664: }
1665: }
1666:
1667: public final void testSetSamples() {
1668: initTestData();
1669: int idx;
1670: int samples[];
1671: byte bdata[];
1672: short sdata[];
1673: int idata[];
1674:
1675: for (int b = 0; b < sppsmb1.getNumBands(); b++) {
1676: samples = createSamplesFromByteDataElements(byteTestData, b);
1677: sppsmb1.setSamples(0, 0, w, h, b, samples, dbb1);
1678: }
1679: idx = 0;
1680: bdata = dbb1.getData();
1681: for (int y = 0; y < h; y++) {
1682: for (int x = 0; x < w; x++) {
1683: assertEquals(
1684: bdata[y * sppsmb1.getScanlineStride() + x],
1685: byteTestData[idx++]);
1686: }
1687: }
1688:
1689: for (int b = 0; b < sppsmb2.getNumBands(); b++) {
1690: samples = createSamplesFromByteDataElements(byteTestData, b);
1691: sppsmb2.setSamples(0, 0, w, h, b, samples, dbb2);
1692: }
1693: idx = 0;
1694: bdata = dbb2.getData();
1695: for (int y = 0; y < h; y++) {
1696: for (int x = 0; x < w; x++) {
1697: assertEquals(
1698: bdata[y * sppsmb2.getScanlineStride() + x],
1699: byteTestData[idx++]);
1700: }
1701: }
1702:
1703: for (int b = 0; b < sppsmu1.getNumBands(); b++) {
1704: samples = createSamplesFromShortDataElements(shortTestData,
1705: b);
1706: sppsmu1.setSamples(0, 0, w, h, b, samples, dbu1);
1707: }
1708: idx = 0;
1709: sdata = dbu1.getData();
1710: for (int y = 0; y < h; y++) {
1711: for (int x = 0; x < w; x++) {
1712: assertEquals(
1713: sdata[y * sppsmu1.getScanlineStride() + x],
1714: shortTestData[idx++]);
1715: }
1716: }
1717:
1718: for (int b = 0; b < sppsmu2.getNumBands(); b++) {
1719: samples = createSamplesFromShortDataElements(shortTestData,
1720: b);
1721: sppsmu2.setSamples(0, 0, w, h, b, samples, dbu2);
1722: }
1723: idx = 0;
1724: sdata = dbu2.getData();
1725: for (int y = 0; y < h; y++) {
1726: for (int x = 0; x < w; x++) {
1727: assertEquals(
1728: sdata[y * sppsmu2.getScanlineStride() + x],
1729: shortTestData[idx++]);
1730: }
1731: }
1732:
1733: for (int b = 0; b < sppsmi1.getNumBands(); b++) {
1734: samples = createSamplesFromIntDataElements(intTestData, b);
1735: sppsmi1.setSamples(0, 0, w, h, b, samples, dbi1);
1736: }
1737: idx = 0;
1738: idata = dbi1.getData();
1739: for (int y = 0; y < h; y++) {
1740: for (int x = 0; x < w; x++) {
1741: assertEquals(
1742: idata[y * sppsmi1.getScanlineStride() + x],
1743: intTestData[idx++]);
1744: }
1745: }
1746:
1747: for (int b = 0; b < sppsmi2.getNumBands(); b++) {
1748: samples = createSamplesFromIntDataElements(intTestData, b);
1749: sppsmi2.setSamples(0, 0, w, h, b, samples, dbi2);
1750: }
1751: idx = 0;
1752: idata = dbi2.getData();
1753: for (int y = 0; y < h; y++) {
1754: for (int x = 0; x < w; x++) {
1755: assertEquals(
1756: idata[y * sppsmi2.getScanlineStride() + x],
1757: intTestData[idx++]);
1758: }
1759: }
1760: }
1761:
1762: private void initTestData() {
1763: int maxByte = 255;
1764: int maxShort = 65535;
1765: long maxInt = (1l << 32) - 1;
1766: Random r = new Random();
1767: int size = w * h;
1768:
1769: byteTestData = new byte[size];
1770: for (int i = 0; i < size; i++) {
1771: byteTestData[i] = (byte) ((int) (r.nextDouble() * maxByte) & 0xff);
1772: }
1773:
1774: shortTestData = new short[size];
1775: for (int i = 0; i < size; i++) {
1776: shortTestData[i] = (short) ((int) (r.nextDouble() * maxShort) & 0xffff);
1777: }
1778:
1779: intTestData = new int[size];
1780: for (int i = 0; i < size; i++) {
1781: intTestData[i] = (int) (r.nextDouble() * maxInt);
1782: }
1783: }
1784:
1785: private int[] getPixelB(int x, int y) {
1786: int pixel[] = new int[4];
1787: int pix = byteTestData[y * w + x] & 0xff;
1788: for (int i = 0; i < 4; i++) {
1789: pixel[i] = (pix & bitMaskB[i]) >> bitOffsetsB[i];
1790: }
1791: return pixel;
1792: }
1793:
1794: private int[] getPixelUS(int x, int y) {
1795: int pixel[] = new int[4];
1796: int pix = shortTestData[y * w + x] & 0xffff;
1797: for (int i = 0; i < 4; i++) {
1798: pixel[i] = (pix & bitMaskUS[i]) >> bitOffsetsUS[i];
1799: }
1800: return pixel;
1801: }
1802:
1803: private int[] getPixelI(int x, int y) {
1804: int pixel[] = new int[4];
1805: int pix = intTestData[y * w + x];
1806: for (int i = 0; i < 4; i++) {
1807: pixel[i] = (pix & bitMaskI[i]) >> bitOffsetsI[i];
1808: }
1809: return pixel;
1810: }
1811:
1812: private int[] getPixelsB(int x, int y, int width, int height) {
1813: int pixel[] = new int[4 * width * height];
1814: int idx = 0;
1815: for (int y1 = y; y1 < y + height; y1++) {
1816: for (int x1 = x; x1 < x + width; x1++) {
1817: int pix = byteTestData[y1 * w + x1] & 0xff;
1818: for (int i = 0; i < 4; i++) {
1819: pixel[idx++] = (pix & bitMaskB[i]) >> bitOffsetsB[i];
1820: }
1821: }
1822: }
1823: return pixel;
1824: }
1825:
1826: private int[] getPixelsUS(int x, int y, int width, int height) {
1827: int pixel[] = new int[4 * width * height];
1828: int idx = 0;
1829: for (int y1 = y; y1 < y + height; y1++) {
1830: for (int x1 = x; x1 < x + width; x1++) {
1831: int pix = shortTestData[y1 * w + x1] & 0xffff;
1832: for (int i = 0; i < 4; i++) {
1833: pixel[idx++] = (pix & bitMaskUS[i]) >> bitOffsetsUS[i];
1834: }
1835: }
1836: }
1837: return pixel;
1838: }
1839:
1840: private int[] getPixelsI(int x, int y, int width, int height) {
1841: int pixel[] = new int[4 * width * height];
1842: int idx = 0;
1843: for (int y1 = y; y1 < y + height; y1++) {
1844: for (int x1 = x; x1 < x + width; x1++) {
1845: int pix = intTestData[y1 * w + x1];
1846: for (int i = 0; i < 4; i++) {
1847: pixel[idx++] = (pix & bitMaskI[i]) >> bitOffsetsI[i];
1848: }
1849: }
1850: }
1851: return pixel;
1852: }
1853:
1854: private int getSampleB(int x, int y, int b) {
1855: int pix = byteTestData[y * w + x] & 0xff;
1856: int sample = (pix & bitMaskB[b]) >> bitOffsetsB[b];
1857: return sample;
1858: }
1859:
1860: private int getSampleUS(int x, int y, int b) {
1861: int pix = shortTestData[y * w + x] & 0xffff;
1862: int sample = (pix & bitMaskUS[b]) >> bitOffsetsUS[b];
1863: return sample;
1864: }
1865:
1866: private int getSampleI(int x, int y, int b) {
1867: int pix = intTestData[y * w + x];
1868: int sample = (pix & bitMaskI[b]) >> bitOffsetsI[b];
1869: return sample;
1870: }
1871:
1872: private int[] getSamplesB(int x, int y, int width, int height, int b) {
1873: int samples[] = new int[width * height];
1874: int idx = 0;
1875: for (int y1 = y; y1 < y + height; y1++) {
1876: for (int x1 = x; x1 < x + width; x1++) {
1877: int pix = byteTestData[y1 * w + x1] & 0xff;
1878: samples[idx++] = (pix & bitMaskB[b]) >> bitOffsetsB[b];
1879: }
1880: }
1881: return samples;
1882: }
1883:
1884: private int[] getSamplesUS(int x, int y, int width, int height,
1885: int b) {
1886: int samples[] = new int[width * height];
1887: int idx = 0;
1888: for (int y1 = y; y1 < y + height; y1++) {
1889: for (int x1 = x; x1 < x + width; x1++) {
1890: int pix = shortTestData[y1 * w + x1] & 0xffff;
1891: samples[idx++] = (pix & bitMaskUS[b]) >> bitOffsetsUS[b];
1892: }
1893: }
1894: return samples;
1895: }
1896:
1897: private int[] getSamplesI(int x, int y, int width, int height, int b) {
1898: int samples[] = new int[width * height];
1899: int idx = 0;
1900: for (int y1 = y; y1 < y + height; y1++) {
1901: for (int x1 = x; x1 < x + width; x1++) {
1902: int pix = intTestData[y1 * w + x1];
1903: samples[idx++] = (pix & bitMaskI[b]) >> bitOffsetsI[b];
1904: }
1905: }
1906: return samples;
1907: }
1908:
1909: private Object getDataElementB(int x, int y) {
1910: byte pixel[] = new byte[1];
1911: pixel[0] = byteTestData[y * w + x];
1912: return pixel;
1913: }
1914:
1915: private Object getDataElementUS(int x, int y) {
1916: short pixel[] = new short[1];
1917: pixel[0] = shortTestData[y * w + x];
1918: return pixel;
1919: }
1920:
1921: private Object getDataElementI(int x, int y) {
1922: int pixel[] = new int[1];
1923: pixel[0] = intTestData[y * w + x];
1924: return pixel;
1925: }
1926:
1927: private Object getDataElementsB(int x, int y, int width, int height) {
1928: byte pixels[] = new byte[width * height];
1929: int idx = 0;
1930: for (int y1 = y; y1 < y + height; y1++) {
1931: for (int x1 = x; x1 < x + width; x1++) {
1932: pixels[idx++] = byteTestData[y1 * w + x1];
1933: }
1934: }
1935: return pixels;
1936: }
1937:
1938: private Object getDataElementsUS(int x, int y, int width, int height) {
1939: short pixels[] = new short[width * height];
1940: int idx = 0;
1941: for (int y1 = y; y1 < y + height; y1++) {
1942: for (int x1 = x; x1 < x + width; x1++) {
1943: pixels[idx++] = shortTestData[y1 * w + x1];
1944: }
1945: }
1946: return pixels;
1947: }
1948:
1949: private Object getDataElementsI(int x, int y, int width, int height) {
1950: int pixels[] = new int[width * height];
1951: int idx = 0;
1952: for (int y1 = y; y1 < y + height; y1++) {
1953: for (int x1 = x; x1 < x + width; x1++) {
1954: pixels[idx++] = intTestData[y1 * w + x1];
1955: }
1956: }
1957: return pixels;
1958: }
1959:
1960: private int[] createPixelFromByteDataElem(byte dataElem) {
1961: int pixel[] = new int[bitMaskB.length];
1962: for (int i = 0; i < bitMaskB.length; i++) {
1963: pixel[i] = (dataElem & bitMaskB[i]) >>> bitOffsetsB[i];
1964: }
1965: return pixel;
1966: }
1967:
1968: private int[] createPixelFromShortDataElem(short dataElem) {
1969: int pixel[] = new int[bitMaskUS.length];
1970: for (int i = 0; i < bitMaskUS.length; i++) {
1971: pixel[i] = (dataElem & bitMaskUS[i]) >>> bitOffsetsUS[i];
1972: }
1973: return pixel;
1974: }
1975:
1976: private int[] createPixelFromIntDataElem(int dataElem) {
1977: int pixel[] = new int[bitMaskI.length];
1978: for (int i = 0; i < bitMaskI.length; i++) {
1979: pixel[i] = (dataElem & bitMaskI[i]) >>> bitOffsetsI[i];
1980: }
1981: return pixel;
1982: }
1983:
1984: private int[] createPixelsFromByteDataElements(byte byteData[]) {
1985: int pixel[] = new int[bitMaskB.length * byteData.length];
1986: int idx = 0;
1987: for (byte element : byteData) {
1988: for (int i = 0; i < bitMaskB.length; i++) {
1989: pixel[idx++] = (element & bitMaskB[i]) >>> bitOffsetsB[i];
1990: }
1991: }
1992: return pixel;
1993: }
1994:
1995: private int[] createPixelsFromShortDataElements(short shortData[]) {
1996: int pixel[] = new int[bitMaskUS.length * shortData.length];
1997: int idx = 0;
1998: for (short element : shortData) {
1999: for (int i = 0; i < bitMaskUS.length; i++) {
2000: pixel[idx++] = (element & bitMaskUS[i]) >>> bitOffsetsUS[i];
2001: }
2002: }
2003: return pixel;
2004: }
2005:
2006: private int[] createPixelsFromIntDataElements(int intData[]) {
2007: int pixel[] = new int[bitMaskI.length * intData.length];
2008: int idx = 0;
2009: for (int element : intData) {
2010: for (int i = 0; i < bitMaskI.length; i++) {
2011: pixel[idx++] = (element & bitMaskI[i]) >>> bitOffsetsI[i];
2012: }
2013: }
2014: return pixel;
2015: }
2016:
2017: private int createSampleFromByteDataElem(byte dataElem, int bank) {
2018: return (dataElem & bitMaskB[bank]) >>> bitOffsetsB[bank];
2019: }
2020:
2021: private int createSampleFromShortDataElem(short dataElem, int bank) {
2022: return (dataElem & bitMaskUS[bank]) >>> bitOffsetsUS[bank];
2023: }
2024:
2025: private int createSampleFromIntDataElem(int dataElem, int bank) {
2026: return (dataElem & bitMaskI[bank]) >>> bitOffsetsI[bank];
2027: }
2028:
2029: private int[] createSamplesFromByteDataElements(byte byteData[],
2030: int bank) {
2031: int samples[] = new int[byteData.length];
2032: for (int i = 0; i < byteData.length; i++) {
2033: samples[i] = (byteData[i] & bitMaskB[bank]) >>> bitOffsetsB[bank];
2034: }
2035: return samples;
2036: }
2037:
2038: private int[] createSamplesFromShortDataElements(short shortData[],
2039: int bank) {
2040: int samples[] = new int[shortData.length];
2041: for (int i = 0; i < shortData.length; i++) {
2042: samples[i] = (shortData[i] & bitMaskUS[bank]) >>> bitOffsetsUS[bank];
2043: }
2044: return samples;
2045: }
2046:
2047: private int[] createSamplesFromIntDataElements(int intData[],
2048: int bank) {
2049: int samples[] = new int[intData.length];
2050: for (int i = 0; i < intData.length; i++) {
2051: samples[i] = (intData[i] & bitMaskI[bank]) >>> bitOffsetsI[bank];
2052: }
2053: return samples;
2054: }
2055:
2056: }
|