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.MultiPixelPackedSampleModel;
0027: import java.awt.image.RasterFormatException;
0028: import java.awt.image.SampleModel;
0029: import java.util.Arrays;
0030: import java.util.Random;
0031:
0032: import javax.swing.JSplitPane;
0033:
0034: import junit.framework.TestCase;
0035:
0036: public class MultiPixelPackedSampleModelTest extends TestCase {
0037: final int w = 20;
0038:
0039: final int h = 20;
0040:
0041: final int bPixelBits = 2;
0042:
0043: final int sPixelBits = 4;
0044:
0045: final int iPixelBits = 8;
0046:
0047: final int bDataBitOffset = bPixelBits;
0048:
0049: final int sDataBitOffset = sPixelBits;
0050:
0051: final int iDataBitOffset = iPixelBits;
0052:
0053: int scanlineStride = 6;
0054:
0055: byte byteTestData[];
0056:
0057: short shortTestData[];
0058:
0059: int intTestData[];
0060:
0061: DataBufferByte dbb1, dbb2;
0062:
0063: DataBufferUShort dbu1, dbu2;
0064:
0065: DataBufferInt dbi1, dbi2;
0066:
0067: MultiPixelPackedSampleModel mppsmb1, mppsmb2, mppsmu1, mppsmu2,
0068: mppsmi1, mppsmi2;
0069:
0070: @Override
0071: protected void setUp() throws Exception {
0072: super .setUp();
0073:
0074: dbb1 = new DataBufferByte(
0075: w
0076: / (DataBuffer
0077: .getDataTypeSize(DataBuffer.TYPE_BYTE) / bPixelBits)
0078: * h);
0079: dbb2 = new DataBufferByte(scanlineStride * h
0080: + (bDataBitOffset + 7) / 8);
0081: dbu1 = new DataBufferUShort(
0082: w
0083: / (DataBuffer
0084: .getDataTypeSize(DataBuffer.TYPE_USHORT) / sPixelBits)
0085: * h);
0086: dbu2 = new DataBufferUShort(scanlineStride * h
0087: + (sDataBitOffset + 15) / 16);
0088: dbi1 = new DataBufferInt(
0089: w
0090: / (DataBuffer
0091: .getDataTypeSize(DataBuffer.TYPE_INT) / iPixelBits)
0092: * h);
0093: dbi2 = new DataBufferInt(scanlineStride * h
0094: + (iDataBitOffset + 31) / 32);
0095:
0096: mppsmb1 = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
0097: w, h, bPixelBits);
0098: mppsmb2 = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
0099: w, h, bPixelBits, scanlineStride, bDataBitOffset);
0100: mppsmu1 = new MultiPixelPackedSampleModel(
0101: DataBuffer.TYPE_USHORT, w, h, sPixelBits);
0102: mppsmu2 = new MultiPixelPackedSampleModel(
0103: DataBuffer.TYPE_USHORT, w, h, sPixelBits,
0104: scanlineStride, sDataBitOffset);
0105: mppsmi1 = new MultiPixelPackedSampleModel(DataBuffer.TYPE_INT,
0106: w, h, iPixelBits);
0107: mppsmi2 = new MultiPixelPackedSampleModel(DataBuffer.TYPE_INT,
0108: w, h, iPixelBits, scanlineStride, iDataBitOffset);
0109:
0110: // initTestData();
0111: }
0112:
0113: public MultiPixelPackedSampleModelTest(String name) {
0114: super (name);
0115: }
0116:
0117: public final void testGetDataType() {
0118: assertEquals(DataBuffer.TYPE_BYTE, mppsmb1.getDataType());
0119: assertEquals(DataBuffer.TYPE_BYTE, mppsmb2.getDataType());
0120: assertEquals(DataBuffer.TYPE_USHORT, mppsmu1.getDataType());
0121: assertEquals(DataBuffer.TYPE_USHORT, mppsmu2.getDataType());
0122: assertEquals(DataBuffer.TYPE_INT, mppsmi1.getDataType());
0123: assertEquals(DataBuffer.TYPE_INT, mppsmi2.getDataType());
0124: }
0125:
0126: public final void testGetNumBands() {
0127: assertEquals(1, mppsmb1.getNumBands());
0128: assertEquals(1, mppsmb2.getNumBands());
0129: assertEquals(1, mppsmu1.getNumBands());
0130: assertEquals(1, mppsmu2.getNumBands());
0131: assertEquals(1, mppsmi1.getNumBands());
0132: assertEquals(1, mppsmi2.getNumBands());
0133: }
0134:
0135: public final void testGetWidth() {
0136: assertEquals(w, mppsmb1.getWidth());
0137: assertEquals(w, mppsmb2.getWidth());
0138: assertEquals(w, mppsmu1.getWidth());
0139: assertEquals(w, mppsmu2.getWidth());
0140: assertEquals(w, mppsmi1.getWidth());
0141: assertEquals(w, mppsmi2.getWidth());
0142: }
0143:
0144: public final void testGetHeight() {
0145: assertEquals(h, mppsmb1.getHeight());
0146: assertEquals(h, mppsmb2.getHeight());
0147: assertEquals(h, mppsmu1.getHeight());
0148: assertEquals(h, mppsmu2.getHeight());
0149: assertEquals(h, mppsmi1.getHeight());
0150: assertEquals(h, mppsmi2.getHeight());
0151: }
0152:
0153: public final void testGetDataBitOffset() {
0154: assertEquals(0, mppsmb1.getDataBitOffset());
0155: assertEquals(bDataBitOffset, mppsmb2.getDataBitOffset());
0156: assertEquals(0, mppsmu1.getDataBitOffset());
0157: assertEquals(sDataBitOffset, mppsmu2.getDataBitOffset());
0158: assertEquals(0, mppsmi1.getDataBitOffset());
0159: assertEquals(iDataBitOffset, mppsmi2.getDataBitOffset());
0160: }
0161:
0162: public final void testGetNumDataElements() {
0163: assertEquals(1, mppsmb1.getNumDataElements());
0164: assertEquals(1, mppsmb2.getNumDataElements());
0165: assertEquals(1, mppsmu1.getNumDataElements());
0166: assertEquals(1, mppsmu2.getNumDataElements());
0167: assertEquals(1, mppsmi1.getNumDataElements());
0168: assertEquals(1, mppsmi2.getNumDataElements());
0169: }
0170:
0171: public final void testGetScanlineStride() {
0172: assertEquals(
0173: w
0174: / (DataBuffer
0175: .getDataTypeSize(DataBuffer.TYPE_BYTE) / bPixelBits),
0176: mppsmb1.getScanlineStride());
0177: assertEquals(scanlineStride, mppsmb2.getScanlineStride());
0178: assertEquals(
0179: w
0180: / (DataBuffer
0181: .getDataTypeSize(DataBuffer.TYPE_USHORT) / sPixelBits),
0182: mppsmu1.getScanlineStride());
0183: assertEquals(scanlineStride, mppsmu2.getScanlineStride());
0184: assertEquals(
0185: w
0186: / (DataBuffer
0187: .getDataTypeSize(DataBuffer.TYPE_INT) / iPixelBits),
0188: mppsmi1.getScanlineStride());
0189: assertEquals(scanlineStride, mppsmi2.getScanlineStride());
0190: }
0191:
0192: public final void testGetTransferType() {
0193: assertEquals(DataBuffer.TYPE_BYTE, mppsmb1.getTransferType());
0194: assertEquals(DataBuffer.TYPE_BYTE, mppsmb2.getTransferType());
0195: assertEquals(DataBuffer.TYPE_BYTE, mppsmu1.getTransferType());
0196: assertEquals(DataBuffer.TYPE_BYTE, mppsmu2.getTransferType());
0197: assertEquals(DataBuffer.TYPE_BYTE, mppsmi1.getTransferType());
0198: assertEquals(DataBuffer.TYPE_BYTE, mppsmi2.getTransferType());
0199: }
0200:
0201: public final void testGetPixelBitStride() {
0202: assertEquals(bPixelBits, mppsmb1.getPixelBitStride());
0203: assertEquals(bPixelBits, mppsmb2.getPixelBitStride());
0204: assertEquals(sPixelBits, mppsmu1.getPixelBitStride());
0205: assertEquals(sPixelBits, mppsmu2.getPixelBitStride());
0206: assertEquals(iPixelBits, mppsmi1.getPixelBitStride());
0207: assertEquals(iPixelBits, mppsmi2.getPixelBitStride());
0208: }
0209:
0210: public final void testGetSampleSize() {
0211: int samplesSize[];
0212: int standard[] = new int[1];
0213:
0214: standard[0] = bPixelBits;
0215: samplesSize = mppsmb1.getSampleSize();
0216: assertTrue(Arrays.equals(samplesSize, standard));
0217: samplesSize = mppsmb2.getSampleSize();
0218: assertTrue(Arrays.equals(samplesSize, standard));
0219:
0220: standard[0] = sPixelBits;
0221: samplesSize = mppsmu1.getSampleSize();
0222: assertTrue(Arrays.equals(samplesSize, standard));
0223: samplesSize = mppsmu2.getSampleSize();
0224: assertTrue(Arrays.equals(samplesSize, standard));
0225:
0226: standard[0] = iPixelBits;
0227: samplesSize = mppsmi1.getSampleSize();
0228: assertTrue(Arrays.equals(samplesSize, standard));
0229: samplesSize = mppsmi2.getSampleSize();
0230: assertTrue(Arrays.equals(samplesSize, standard));
0231: }
0232:
0233: public final void testGetSampleSizeBand() {
0234: for (int b = 0; b < mppsmb1.getNumBands(); b++) {
0235: assertEquals(bPixelBits, mppsmb1.getSampleSize(b));
0236: }
0237:
0238: for (int b = 0; b < mppsmb2.getNumBands(); b++) {
0239: assertEquals(bPixelBits, mppsmb2.getSampleSize(b));
0240: }
0241:
0242: for (int b = 0; b < mppsmu1.getNumBands(); b++) {
0243: assertEquals(sPixelBits, mppsmu1.getSampleSize(b));
0244: }
0245:
0246: for (int b = 0; b < mppsmu2.getNumBands(); b++) {
0247: assertEquals(sPixelBits, mppsmu2.getSampleSize(b));
0248: }
0249:
0250: for (int b = 0; b < mppsmi1.getNumBands(); b++) {
0251: assertEquals(iPixelBits, mppsmi1.getSampleSize(b));
0252: }
0253:
0254: for (int b = 0; b < mppsmi2.getNumBands(); b++) {
0255: assertEquals(iPixelBits, mppsmi2.getSampleSize(b));
0256: }
0257: }
0258:
0259: public final void testEquals() {
0260: SampleModel sm;
0261:
0262: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, w,
0263: h, bPixelBits);
0264: assertTrue(mppsmb1.equals(sm));
0265: assertFalse(mppsmb2.equals(sm));
0266:
0267: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, w,
0268: h, bPixelBits, scanlineStride, bDataBitOffset);
0269: assertTrue(mppsmb2.equals(sm));
0270: assertFalse(mppsmb1.equals(sm));
0271:
0272: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_USHORT, w,
0273: h, sPixelBits);
0274: assertTrue(mppsmu1.equals(sm));
0275: assertFalse(mppsmu2.equals(sm));
0276:
0277: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_USHORT, w,
0278: h, sPixelBits, scanlineStride, sDataBitOffset);
0279: assertTrue(mppsmu2.equals(sm));
0280: assertFalse(mppsmu1.equals(sm));
0281:
0282: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_INT, w, h,
0283: iPixelBits);
0284: assertTrue(mppsmi1.equals(sm));
0285: assertFalse(mppsmi2.equals(sm));
0286:
0287: sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_INT, w, h,
0288: iPixelBits, scanlineStride, iDataBitOffset);
0289: assertTrue(mppsmi2.equals(sm));
0290: assertFalse(mppsmi1.equals(sm));
0291:
0292: }
0293:
0294: public final void testCreateCompatibleSampleModel() {
0295: SampleModel sm;
0296: MultiPixelPackedSampleModel mppsm;
0297:
0298: sm = mppsmb1.createCompatibleSampleModel(w, h);
0299: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0300: mppsm = (MultiPixelPackedSampleModel) sm;
0301: assertEquals(DataBuffer.TYPE_BYTE, mppsm.getDataType());
0302: assertEquals(w, mppsm.getWidth());
0303: assertEquals(h, mppsm.getHeight());
0304: assertEquals(bPixelBits, mppsm.getPixelBitStride());
0305:
0306: sm = mppsmb2.createCompatibleSampleModel(w, h);
0307: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0308: mppsm = (MultiPixelPackedSampleModel) sm;
0309: assertEquals(DataBuffer.TYPE_BYTE, mppsm.getDataType());
0310: assertEquals(w, mppsm.getWidth());
0311: assertEquals(h, mppsm.getHeight());
0312: assertEquals(bPixelBits, mppsm.getPixelBitStride());
0313:
0314: sm = mppsmu1.createCompatibleSampleModel(w, h);
0315: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0316: mppsm = (MultiPixelPackedSampleModel) sm;
0317: assertEquals(DataBuffer.TYPE_USHORT, mppsm.getDataType());
0318: assertEquals(w, mppsm.getWidth());
0319: assertEquals(h, mppsm.getHeight());
0320: assertEquals(sPixelBits, mppsm.getPixelBitStride());
0321:
0322: sm = mppsmu2.createCompatibleSampleModel(w, h);
0323: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0324: mppsm = (MultiPixelPackedSampleModel) sm;
0325: assertEquals(DataBuffer.TYPE_USHORT, mppsm.getDataType());
0326: assertEquals(w, mppsm.getWidth());
0327: assertEquals(h, mppsm.getHeight());
0328: assertEquals(sPixelBits, mppsm.getPixelBitStride());
0329:
0330: sm = mppsmi1.createCompatibleSampleModel(w, h);
0331: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0332: mppsm = (MultiPixelPackedSampleModel) sm;
0333: assertEquals(DataBuffer.TYPE_INT, mppsm.getDataType());
0334: assertEquals(w, mppsm.getWidth());
0335: assertEquals(h, mppsm.getHeight());
0336: assertEquals(iPixelBits, mppsm.getPixelBitStride());
0337:
0338: sm = mppsmi2.createCompatibleSampleModel(w, h);
0339: assertTrue(sm instanceof MultiPixelPackedSampleModel);
0340: mppsm = (MultiPixelPackedSampleModel) sm;
0341: assertEquals(DataBuffer.TYPE_INT, mppsm.getDataType());
0342: assertEquals(w, mppsm.getWidth());
0343: assertEquals(h, mppsm.getHeight());
0344: assertEquals(iPixelBits, mppsm.getPixelBitStride());
0345:
0346: }
0347:
0348: public final void testCreateSubsetSampleModel() {
0349: int bands[] = { 0 };
0350: int wrongBands[] = { 0, 1 };
0351:
0352: try {
0353: mppsmb1.createSubsetSampleModel(null);
0354: } catch (RasterFormatException e) {
0355: fail();
0356: }
0357:
0358: try {
0359: mppsmb1.createSubsetSampleModel(bands);
0360: } catch (RasterFormatException e) {
0361: fail();
0362: }
0363:
0364: try {
0365: mppsmb1.createSubsetSampleModel(wrongBands);
0366: } catch (RasterFormatException e) {
0367: assertTrue(true);
0368: }
0369: }
0370:
0371: public final void testCreateDataBuffer() {
0372: DataBuffer db;
0373:
0374: db = mppsmb1.createDataBuffer();
0375: assertEquals(dbb1.getDataType(), db.getDataType());
0376: assertEquals(dbb1.getNumBanks(), db.getNumBanks());
0377: assertEquals(dbb1.getSize(), db.getSize());
0378: assertTrue(Arrays.equals(dbb1.getOffsets(), db.getOffsets()));
0379:
0380: db = mppsmb2.createDataBuffer();
0381: assertEquals(dbb2.getDataType(), db.getDataType());
0382: assertEquals(dbb2.getNumBanks(), db.getNumBanks());
0383: assertEquals(dbb2.getSize(), db.getSize());
0384: assertTrue(Arrays.equals(dbb2.getOffsets(), db.getOffsets()));
0385:
0386: db = mppsmu1.createDataBuffer();
0387: assertEquals(dbu1.getDataType(), db.getDataType());
0388: assertEquals(dbu1.getNumBanks(), db.getNumBanks());
0389: assertEquals(dbu1.getSize(), db.getSize());
0390: assertTrue(Arrays.equals(dbu1.getOffsets(), db.getOffsets()));
0391:
0392: db = mppsmu2.createDataBuffer();
0393: assertEquals(dbu2.getDataType(), db.getDataType());
0394: assertEquals(dbu2.getNumBanks(), db.getNumBanks());
0395: assertEquals(dbu2.getSize(), db.getSize());
0396: assertTrue(Arrays.equals(dbu2.getOffsets(), db.getOffsets()));
0397:
0398: db = mppsmi1.createDataBuffer();
0399: assertEquals(dbi1.getDataType(), db.getDataType());
0400: assertEquals(dbi1.getNumBanks(), db.getNumBanks());
0401: assertEquals(dbi1.getSize(), db.getSize());
0402: assertTrue(Arrays.equals(dbi1.getOffsets(), db.getOffsets()));
0403:
0404: db = mppsmi2.createDataBuffer();
0405: assertEquals(dbi2.getDataType(), db.getDataType());
0406: assertEquals(dbi2.getNumBanks(), db.getNumBanks());
0407: assertEquals(dbi2.getSize(), db.getSize());
0408: assertTrue(Arrays.equals(dbi2.getOffsets(), db.getOffsets()));
0409: }
0410:
0411: public final void testGetBitOffset() {
0412: int pixelStride;
0413: int bitOffset;
0414: int offset;
0415: int type;
0416: int dataElemSize;
0417:
0418: pixelStride = mppsmb1.getPixelBitStride();
0419: bitOffset = mppsmb1.getDataBitOffset();
0420: type = mppsmb1.getDataType();
0421: dataElemSize = DataBuffer.getDataTypeSize(type);
0422: for (int x = 0; x < w; x++) {
0423: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0424: assertEquals(offset, mppsmb1.getBitOffset(x));
0425: }
0426:
0427: pixelStride = mppsmb2.getPixelBitStride();
0428: bitOffset = mppsmb2.getDataBitOffset();
0429: type = mppsmb2.getDataType();
0430: dataElemSize = DataBuffer.getDataTypeSize(type);
0431: for (int x = 0; x < w; x++) {
0432: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0433: assertEquals(offset, mppsmb2.getBitOffset(x));
0434: }
0435:
0436: pixelStride = mppsmu1.getPixelBitStride();
0437: bitOffset = mppsmu1.getDataBitOffset();
0438: type = mppsmu1.getDataType();
0439: dataElemSize = DataBuffer.getDataTypeSize(type);
0440: for (int x = 0; x < w; x++) {
0441: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0442: assertEquals(offset, mppsmu1.getBitOffset(x));
0443: }
0444:
0445: pixelStride = mppsmu2.getPixelBitStride();
0446: bitOffset = mppsmu2.getDataBitOffset();
0447: type = mppsmu2.getDataType();
0448: dataElemSize = DataBuffer.getDataTypeSize(type);
0449: for (int x = 0; x < w; x++) {
0450: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0451: assertEquals(offset, mppsmu2.getBitOffset(x));
0452: }
0453:
0454: pixelStride = mppsmi1.getPixelBitStride();
0455: bitOffset = mppsmi1.getDataBitOffset();
0456: type = mppsmi1.getDataType();
0457: dataElemSize = DataBuffer.getDataTypeSize(type);
0458: for (int x = 0; x < w; x++) {
0459: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0460: assertEquals(offset, mppsmi1.getBitOffset(x));
0461: }
0462:
0463: pixelStride = mppsmi2.getPixelBitStride();
0464: bitOffset = mppsmi2.getDataBitOffset();
0465: type = mppsmi2.getDataType();
0466: dataElemSize = DataBuffer.getDataTypeSize(type);
0467: for (int x = 0; x < w; x++) {
0468: offset = (x * pixelStride + bitOffset) & (dataElemSize - 1);
0469: assertEquals(offset, mppsmi2.getBitOffset(x));
0470: }
0471: }
0472:
0473: public final void testGetOffset() {
0474: int stride;
0475: int pixelStride;
0476: int bitOffset;
0477: int offset;
0478: int type;
0479: int dataElemSize;
0480:
0481: stride = mppsmb1.getScanlineStride();
0482: pixelStride = mppsmb1.getPixelBitStride();
0483: bitOffset = mppsmb1.getDataBitOffset();
0484: type = mppsmb1.getDataType();
0485: dataElemSize = DataBuffer.getDataTypeSize(type);
0486: for (int y = 0; y < h; y++) {
0487: for (int x = 0; x < w; x++) {
0488: offset = y * stride + (x * pixelStride + bitOffset)
0489: / dataElemSize;
0490: assertEquals(offset, mppsmb1.getOffset(x, y));
0491: }
0492: }
0493:
0494: stride = mppsmb2.getScanlineStride();
0495: pixelStride = mppsmb2.getPixelBitStride();
0496: bitOffset = mppsmb2.getDataBitOffset();
0497: type = mppsmb2.getDataType();
0498: dataElemSize = DataBuffer.getDataTypeSize(type);
0499: for (int y = 0; y < h; y++) {
0500: for (int x = 0; x < w; x++) {
0501: offset = y * stride + (x * pixelStride + bitOffset)
0502: / dataElemSize;
0503: assertEquals(offset, mppsmb2.getOffset(x, y));
0504: }
0505: }
0506:
0507: stride = mppsmu1.getScanlineStride();
0508: pixelStride = mppsmu1.getPixelBitStride();
0509: bitOffset = mppsmu1.getDataBitOffset();
0510: type = mppsmu1.getDataType();
0511: dataElemSize = DataBuffer.getDataTypeSize(type);
0512: for (int y = 0; y < h; y++) {
0513: for (int x = 0; x < w; x++) {
0514: offset = y * stride + (x * pixelStride + bitOffset)
0515: / dataElemSize;
0516: assertEquals(offset, mppsmu1.getOffset(x, y));
0517: }
0518: }
0519:
0520: stride = mppsmu2.getScanlineStride();
0521: pixelStride = mppsmu2.getPixelBitStride();
0522: bitOffset = mppsmu2.getDataBitOffset();
0523: type = mppsmu2.getDataType();
0524: dataElemSize = DataBuffer.getDataTypeSize(type);
0525: for (int y = 0; y < h; y++) {
0526: for (int x = 0; x < w; x++) {
0527: offset = y * stride + (x * pixelStride + bitOffset)
0528: / dataElemSize;
0529: assertEquals(offset, mppsmu2.getOffset(x, y));
0530: }
0531: }
0532:
0533: stride = mppsmi1.getScanlineStride();
0534: pixelStride = mppsmi1.getPixelBitStride();
0535: bitOffset = mppsmi1.getDataBitOffset();
0536: type = mppsmi1.getDataType();
0537: dataElemSize = DataBuffer.getDataTypeSize(type);
0538: for (int y = 0; y < h; y++) {
0539: for (int x = 0; x < w; x++) {
0540: offset = y * stride + (x * pixelStride + bitOffset)
0541: / dataElemSize;
0542: assertEquals(offset, mppsmi1.getOffset(x, y));
0543: }
0544: }
0545:
0546: stride = mppsmi2.getScanlineStride();
0547: pixelStride = mppsmi2.getPixelBitStride();
0548: bitOffset = mppsmi2.getDataBitOffset();
0549: type = mppsmi2.getDataType();
0550: dataElemSize = DataBuffer.getDataTypeSize(type);
0551: for (int y = 0; y < h; y++) {
0552: for (int x = 0; x < w; x++) {
0553: offset = y * stride + (x * pixelStride + bitOffset)
0554: / dataElemSize;
0555: assertEquals(offset, mppsmi2.getOffset(x, y));
0556: }
0557: }
0558: }
0559:
0560: public final void testGetDataElements() {
0561: initDataBuffers();
0562: byte bde[] = new byte[1];
0563: short sde[] = new short[1];
0564: int ide[] = new int[1];
0565: Object de;
0566: int trType;
0567: int idx;
0568:
0569: idx = 0;
0570: trType = mppsmb1.getTransferType();
0571: for (int y = 0; y < h; y++) {
0572: for (int x = 0; x < w; x++) {
0573: de = null;
0574: de = mppsmb1.getDataElements(x, y, de, dbb1);
0575: switch (trType) {
0576: case DataBuffer.TYPE_BYTE:
0577: bde = (byte[]) de;
0578: assertEquals(1, bde.length);
0579: assertEquals(byteTestData[idx++] & 0xff,
0580: bde[0] & 0xff);
0581: break;
0582: case DataBuffer.TYPE_USHORT:
0583: sde = (short[]) de;
0584: assertEquals(1, sde.length);
0585: assertEquals(byteTestData[idx++] & 0xff,
0586: sde[0] & 0xff);
0587: break;
0588: case DataBuffer.TYPE_INT:
0589: ide = (int[]) de;
0590: assertEquals(1, ide.length);
0591: assertEquals(byteTestData[idx++] & 0xff, ide[0]);
0592: break;
0593: default:
0594: throw new IllegalArgumentException(
0595: "Wrong TransferType");
0596: }
0597: }
0598: }
0599:
0600: idx = 0;
0601: trType = mppsmb2.getTransferType();
0602: for (int y = 0; y < h; y++) {
0603: for (int x = 0; x < w; x++) {
0604: de = null;
0605: de = mppsmb2.getDataElements(x, y, de, dbb2);
0606: switch (trType) {
0607: case DataBuffer.TYPE_BYTE:
0608: bde = (byte[]) de;
0609: assertEquals(1, bde.length);
0610: assertEquals(byteTestData[idx++] & 0xff,
0611: bde[0] & 0xff);
0612: break;
0613: case DataBuffer.TYPE_USHORT:
0614: sde = (short[]) de;
0615: assertEquals(1, sde.length);
0616: assertEquals(byteTestData[idx++] & 0xff,
0617: sde[0] & 0xff);
0618: break;
0619: case DataBuffer.TYPE_INT:
0620: ide = (int[]) de;
0621: assertEquals(1, ide.length);
0622: assertEquals(byteTestData[idx++] & 0xff, ide[0]);
0623: break;
0624: default:
0625: throw new IllegalArgumentException(
0626: "Wrong TransferType");
0627: }
0628: }
0629: }
0630:
0631: idx = 0;
0632: trType = mppsmu1.getTransferType();
0633: for (int y = 0; y < h; y++) {
0634: for (int x = 0; x < w; x++) {
0635: de = null;
0636: de = mppsmu1.getDataElements(x, y, de, dbu1);
0637: switch (trType) {
0638: case DataBuffer.TYPE_BYTE:
0639: bde = (byte[]) de;
0640: assertEquals(1, bde.length);
0641: assertEquals(shortTestData[idx++] & 0xffff,
0642: bde[0] & 0xff);
0643: break;
0644: case DataBuffer.TYPE_USHORT:
0645: sde = (short[]) de;
0646: assertEquals(1, sde.length);
0647: assertEquals(shortTestData[idx++] & 0xffff,
0648: sde[0] & 0xff);
0649: break;
0650: case DataBuffer.TYPE_INT:
0651: ide = (int[]) de;
0652: assertEquals(1, ide.length);
0653: assertEquals(shortTestData[idx++] & 0xffff, ide[0]);
0654: break;
0655: default:
0656: throw new IllegalArgumentException(
0657: "Wrong TransferType");
0658: }
0659: }
0660: }
0661:
0662: idx = 0;
0663: trType = mppsmu2.getTransferType();
0664: for (int y = 0; y < h; y++) {
0665: for (int x = 0; x < w; x++) {
0666: de = null;
0667: de = mppsmu2.getDataElements(x, y, de, dbu2);
0668: switch (trType) {
0669: case DataBuffer.TYPE_BYTE:
0670: bde = (byte[]) de;
0671: assertEquals(1, bde.length);
0672: assertEquals(shortTestData[idx++] & 0xffff,
0673: bde[0] & 0xff);
0674: break;
0675: case DataBuffer.TYPE_USHORT:
0676: sde = (short[]) de;
0677: assertEquals(1, sde.length);
0678: assertEquals(shortTestData[idx++] & 0xffff,
0679: sde[0] & 0xff);
0680: break;
0681: case DataBuffer.TYPE_INT:
0682: ide = (int[]) de;
0683: assertEquals(1, ide.length);
0684: assertEquals(shortTestData[idx++], ide[0]);
0685: break;
0686: default:
0687: throw new IllegalArgumentException(
0688: "Wrong TransferType");
0689: }
0690: }
0691: }
0692:
0693: idx = 0;
0694: trType = mppsmi1.getTransferType();
0695: for (int y = 0; y < h; y++) {
0696: for (int x = 0; x < w; x++) {
0697: de = null;
0698: de = mppsmi1.getDataElements(x, y, de, dbi1);
0699: switch (trType) {
0700: case DataBuffer.TYPE_BYTE:
0701: bde = (byte[]) de;
0702: assertEquals(1, bde.length);
0703: assertEquals(intTestData[idx++], bde[0] & 0xff);
0704: break;
0705: case DataBuffer.TYPE_USHORT:
0706: sde = (short[]) de;
0707: assertEquals(1, sde.length);
0708: assertEquals(intTestData[idx++], sde[0] & 0xffff);
0709: break;
0710: case DataBuffer.TYPE_INT:
0711: ide = (int[]) de;
0712: assertEquals(1, ide.length);
0713: assertEquals(intTestData[idx++], ide[0]);
0714: break;
0715: default:
0716: throw new IllegalArgumentException(
0717: "Wrong TransferType");
0718: }
0719: }
0720: }
0721:
0722: idx = 0;
0723: trType = mppsmi2.getTransferType();
0724: for (int y = 0; y < h; y++) {
0725: for (int x = 0; x < w; x++) {
0726: de = null;
0727: de = mppsmi2.getDataElements(x, y, de, dbi2);
0728: switch (trType) {
0729: case DataBuffer.TYPE_BYTE:
0730: bde = (byte[]) de;
0731: assertEquals(1, bde.length);
0732: assertEquals(intTestData[idx++], bde[0] & 0xff);
0733: break;
0734: case DataBuffer.TYPE_USHORT:
0735: sde = (short[]) de;
0736: assertEquals(1, sde.length);
0737: assertEquals(intTestData[idx++], sde[0] & 0xffff);
0738: break;
0739: case DataBuffer.TYPE_INT:
0740: ide = (int[]) de;
0741: assertEquals(1, ide.length);
0742: assertEquals(intTestData[idx++], ide[0]);
0743: break;
0744: default:
0745: throw new IllegalArgumentException(
0746: "Wrong TransferType");
0747: }
0748: }
0749: }
0750: }
0751:
0752: public final void testGetDataElementsA() {
0753: initDataBuffers();
0754: Object tDE, rDE;
0755: byte tde[];
0756: byte rde[];
0757: short stde[];
0758: short srde[];
0759: int itde[];
0760: int irde[];
0761: int trType;
0762:
0763: trType = mppsmb1.getTransferType();
0764: tDE = null;
0765: tDE = mppsmb1.getDataElements(0, 0, 1, 1, tDE, dbb1);
0766: rDE = getDataElementsB(0, 0, 1, 1, trType);
0767: switch (trType) {
0768: case DataBuffer.TYPE_BYTE:
0769: tde = (byte[]) tDE;
0770: rde = (byte[]) rDE;
0771: assertTrue(Arrays.equals(rde, tde));
0772: break;
0773: case DataBuffer.TYPE_USHORT:
0774: stde = (short[]) tDE;
0775: srde = (short[]) rDE;
0776: assertTrue(Arrays.equals(srde, stde));
0777: break;
0778: case DataBuffer.TYPE_INT:
0779: itde = (int[]) tDE;
0780: irde = (int[]) rDE;
0781: assertTrue(Arrays.equals(irde, itde));
0782: break;
0783: default:
0784: throw new IllegalArgumentException("Wrong Transfer Type");
0785: }
0786:
0787: tDE = null;
0788: tDE = mppsmb1.getDataElements(0, 0, w / 2, h / 2, tDE, dbb1);
0789: rDE = getDataElementsB(0, 0, w / 2, w / 2, trType);
0790: switch (trType) {
0791: case DataBuffer.TYPE_BYTE:
0792: tde = (byte[]) tDE;
0793: rde = (byte[]) rDE;
0794: assertTrue(Arrays.equals(rde, tde));
0795: break;
0796: case DataBuffer.TYPE_USHORT:
0797: stde = (short[]) tDE;
0798: srde = (short[]) rDE;
0799: assertTrue(Arrays.equals(srde, stde));
0800: break;
0801: case DataBuffer.TYPE_INT:
0802: itde = (int[]) tDE;
0803: irde = (int[]) rDE;
0804: assertTrue(Arrays.equals(irde, itde));
0805: break;
0806: default:
0807: throw new IllegalArgumentException("Wrong Transfer Type");
0808: }
0809:
0810: tDE = null;
0811: tDE = mppsmb1.getDataElements(0, 0, w, h, tDE, dbb1);
0812: rDE = getDataElementsB(0, 0, w, h, trType);
0813: switch (trType) {
0814: case DataBuffer.TYPE_BYTE:
0815: tde = (byte[]) tDE;
0816: rde = (byte[]) rDE;
0817: assertTrue(Arrays.equals(rde, tde));
0818: break;
0819: case DataBuffer.TYPE_USHORT:
0820: stde = (short[]) tDE;
0821: srde = (short[]) rDE;
0822: assertTrue(Arrays.equals(srde, stde));
0823: break;
0824: case DataBuffer.TYPE_INT:
0825: itde = (int[]) tDE;
0826: irde = (int[]) rDE;
0827: assertTrue(Arrays.equals(irde, itde));
0828: break;
0829: default:
0830: throw new IllegalArgumentException("Wrong Transfer Type");
0831: }
0832:
0833: trType = mppsmb2.getTransferType();
0834: tDE = null;
0835: tDE = mppsmb2.getDataElements(0, 0, 1, 1, tDE, dbb2);
0836: rDE = getDataElementsB(0, 0, 1, 1, trType);
0837: switch (trType) {
0838: case DataBuffer.TYPE_BYTE:
0839: tde = (byte[]) tDE;
0840: rde = (byte[]) rDE;
0841: assertTrue(Arrays.equals(rde, tde));
0842: break;
0843: case DataBuffer.TYPE_USHORT:
0844: stde = (short[]) tDE;
0845: srde = (short[]) rDE;
0846: assertTrue(Arrays.equals(srde, stde));
0847: break;
0848: case DataBuffer.TYPE_INT:
0849: itde = (int[]) tDE;
0850: irde = (int[]) rDE;
0851: assertTrue(Arrays.equals(irde, itde));
0852: break;
0853: default:
0854: throw new IllegalArgumentException("Wrong Transfer Type");
0855: }
0856:
0857: tDE = null;
0858: tDE = mppsmb2.getDataElements(0, 0, w / 2, h / 2, tDE, dbb2);
0859: rDE = getDataElementsB(0, 0, w / 2, w / 2, trType);
0860: switch (trType) {
0861: case DataBuffer.TYPE_BYTE:
0862: tde = (byte[]) tDE;
0863: rde = (byte[]) rDE;
0864: assertTrue(Arrays.equals(rde, tde));
0865: break;
0866: case DataBuffer.TYPE_USHORT:
0867: stde = (short[]) tDE;
0868: srde = (short[]) rDE;
0869: assertTrue(Arrays.equals(srde, stde));
0870: break;
0871: case DataBuffer.TYPE_INT:
0872: itde = (int[]) tDE;
0873: irde = (int[]) rDE;
0874: assertTrue(Arrays.equals(irde, itde));
0875: break;
0876: default:
0877: throw new IllegalArgumentException("Wrong Transfer Type");
0878: }
0879:
0880: tDE = null;
0881: tDE = mppsmb2.getDataElements(0, 0, w, h, tDE, dbb2);
0882: rDE = getDataElementsB(0, 0, w, h, trType);
0883: switch (trType) {
0884: case DataBuffer.TYPE_BYTE:
0885: tde = (byte[]) tDE;
0886: rde = (byte[]) rDE;
0887: assertTrue(Arrays.equals(rde, tde));
0888: break;
0889: case DataBuffer.TYPE_USHORT:
0890: stde = (short[]) tDE;
0891: srde = (short[]) rDE;
0892: assertTrue(Arrays.equals(srde, stde));
0893: break;
0894: case DataBuffer.TYPE_INT:
0895: itde = (int[]) tDE;
0896: irde = (int[]) rDE;
0897: assertTrue(Arrays.equals(irde, itde));
0898: break;
0899: default:
0900: throw new IllegalArgumentException("Wrong Transfer Type");
0901: }
0902:
0903: trType = mppsmu1.getTransferType();
0904: tDE = null;
0905: tDE = mppsmu1.getDataElements(0, 0, 1, 1, tDE, dbu1);
0906: rDE = getDataElementsUS(0, 0, 1, 1, trType);
0907: switch (trType) {
0908: case DataBuffer.TYPE_BYTE:
0909: tde = (byte[]) tDE;
0910: rde = (byte[]) rDE;
0911: assertTrue(Arrays.equals(rde, tde));
0912: break;
0913: case DataBuffer.TYPE_USHORT:
0914: stde = (short[]) tDE;
0915: srde = (short[]) rDE;
0916: assertTrue(Arrays.equals(srde, stde));
0917: break;
0918: case DataBuffer.TYPE_INT:
0919: itde = (int[]) tDE;
0920: irde = (int[]) rDE;
0921: assertTrue(Arrays.equals(irde, itde));
0922: break;
0923: default:
0924: throw new IllegalArgumentException("Wrong Transfer Type");
0925: }
0926:
0927: tDE = null;
0928: tDE = mppsmu1.getDataElements(0, 0, w / 2, h / 2, tDE, dbu1);
0929: rDE = getDataElementsUS(0, 0, w / 2, w / 2, trType);
0930: switch (trType) {
0931: case DataBuffer.TYPE_BYTE:
0932: tde = (byte[]) tDE;
0933: rde = (byte[]) rDE;
0934: assertTrue(Arrays.equals(rde, tde));
0935: break;
0936: case DataBuffer.TYPE_USHORT:
0937: stde = (short[]) tDE;
0938: srde = (short[]) rDE;
0939: assertTrue(Arrays.equals(srde, stde));
0940: break;
0941: case DataBuffer.TYPE_INT:
0942: itde = (int[]) tDE;
0943: irde = (int[]) rDE;
0944: assertTrue(Arrays.equals(irde, itde));
0945: break;
0946: default:
0947: throw new IllegalArgumentException("Wrong Transfer Type");
0948: }
0949:
0950: tDE = null;
0951: tDE = mppsmu1.getDataElements(0, 0, w, h, tDE, dbu1);
0952: rDE = getDataElementsUS(0, 0, w, h, trType);
0953: switch (trType) {
0954: case DataBuffer.TYPE_BYTE:
0955: tde = (byte[]) tDE;
0956: rde = (byte[]) rDE;
0957: assertTrue(Arrays.equals(rde, tde));
0958: break;
0959: case DataBuffer.TYPE_USHORT:
0960: stde = (short[]) tDE;
0961: srde = (short[]) rDE;
0962: assertTrue(Arrays.equals(srde, stde));
0963: break;
0964: case DataBuffer.TYPE_INT:
0965: itde = (int[]) tDE;
0966: irde = (int[]) rDE;
0967: assertTrue(Arrays.equals(irde, itde));
0968: break;
0969: default:
0970: throw new IllegalArgumentException("Wrong Transfer Type");
0971: }
0972:
0973: trType = mppsmu2.getTransferType();
0974: tDE = null;
0975: tDE = mppsmu2.getDataElements(0, 0, 1, 1, tDE, dbu2);
0976: rDE = getDataElementsUS(0, 0, 1, 1, trType);
0977: switch (trType) {
0978: case DataBuffer.TYPE_BYTE:
0979: tde = (byte[]) tDE;
0980: rde = (byte[]) rDE;
0981: assertTrue(Arrays.equals(rde, tde));
0982: break;
0983: case DataBuffer.TYPE_USHORT:
0984: stde = (short[]) tDE;
0985: srde = (short[]) rDE;
0986: assertTrue(Arrays.equals(srde, stde));
0987: break;
0988: case DataBuffer.TYPE_INT:
0989: itde = (int[]) tDE;
0990: irde = (int[]) rDE;
0991: assertTrue(Arrays.equals(irde, itde));
0992: break;
0993: default:
0994: throw new IllegalArgumentException("Wrong Transfer Type");
0995: }
0996:
0997: tDE = null;
0998: tDE = mppsmu2.getDataElements(0, 0, w / 2, h / 2, tDE, dbu2);
0999: rDE = getDataElementsUS(0, 0, w / 2, w / 2, trType);
1000: switch (trType) {
1001: case DataBuffer.TYPE_BYTE:
1002: tde = (byte[]) tDE;
1003: rde = (byte[]) rDE;
1004: assertTrue(Arrays.equals(rde, tde));
1005: break;
1006: case DataBuffer.TYPE_USHORT:
1007: stde = (short[]) tDE;
1008: srde = (short[]) rDE;
1009: assertTrue(Arrays.equals(srde, stde));
1010: break;
1011: case DataBuffer.TYPE_INT:
1012: itde = (int[]) tDE;
1013: irde = (int[]) rDE;
1014: assertTrue(Arrays.equals(irde, itde));
1015: break;
1016: default:
1017: throw new IllegalArgumentException("Wrong Transfer Type");
1018: }
1019:
1020: tDE = null;
1021: tDE = mppsmu2.getDataElements(0, 0, w, h, tDE, dbu2);
1022: rDE = getDataElementsUS(0, 0, w, h, trType);
1023: switch (trType) {
1024: case DataBuffer.TYPE_BYTE:
1025: tde = (byte[]) tDE;
1026: rde = (byte[]) rDE;
1027: assertTrue(Arrays.equals(rde, tde));
1028: break;
1029: case DataBuffer.TYPE_USHORT:
1030: stde = (short[]) tDE;
1031: srde = (short[]) rDE;
1032: assertTrue(Arrays.equals(srde, stde));
1033: break;
1034: case DataBuffer.TYPE_INT:
1035: itde = (int[]) tDE;
1036: irde = (int[]) rDE;
1037: assertTrue(Arrays.equals(irde, itde));
1038: break;
1039: default:
1040: throw new IllegalArgumentException("Wrong Transfer Type");
1041: }
1042:
1043: trType = mppsmi1.getTransferType();
1044: tDE = null;
1045: tDE = mppsmi1.getDataElements(0, 0, 1, 1, tDE, dbi1);
1046: rDE = getDataElementsI(0, 0, 1, 1, trType);
1047: switch (trType) {
1048: case DataBuffer.TYPE_BYTE:
1049: tde = (byte[]) tDE;
1050: rde = (byte[]) rDE;
1051: assertTrue(Arrays.equals(rde, tde));
1052: break;
1053: case DataBuffer.TYPE_USHORT:
1054: stde = (short[]) tDE;
1055: srde = (short[]) rDE;
1056: assertTrue(Arrays.equals(srde, stde));
1057: break;
1058: case DataBuffer.TYPE_INT:
1059: itde = (int[]) tDE;
1060: irde = (int[]) rDE;
1061: assertTrue(Arrays.equals(irde, itde));
1062: break;
1063: default:
1064: throw new IllegalArgumentException("Wrong Transfer Type");
1065: }
1066:
1067: tDE = null;
1068: tDE = mppsmi1.getDataElements(0, 0, w / 2, h / 2, tDE, dbi1);
1069: rDE = getDataElementsI(0, 0, w / 2, w / 2, trType);
1070: switch (trType) {
1071: case DataBuffer.TYPE_BYTE:
1072: tde = (byte[]) tDE;
1073: rde = (byte[]) rDE;
1074: assertTrue(Arrays.equals(rde, tde));
1075: break;
1076: case DataBuffer.TYPE_USHORT:
1077: stde = (short[]) tDE;
1078: srde = (short[]) rDE;
1079: assertTrue(Arrays.equals(srde, stde));
1080: break;
1081: case DataBuffer.TYPE_INT:
1082: itde = (int[]) tDE;
1083: irde = (int[]) rDE;
1084: assertTrue(Arrays.equals(irde, itde));
1085: break;
1086: default:
1087: throw new IllegalArgumentException("Wrong Transfer Type");
1088: }
1089:
1090: tDE = null;
1091: tDE = mppsmi1.getDataElements(0, 0, w, h, tDE, dbi1);
1092: rDE = getDataElementsI(0, 0, w, h, trType);
1093: switch (trType) {
1094: case DataBuffer.TYPE_BYTE:
1095: tde = (byte[]) tDE;
1096: rde = (byte[]) rDE;
1097: assertTrue(Arrays.equals(rde, tde));
1098: break;
1099: case DataBuffer.TYPE_USHORT:
1100: stde = (short[]) tDE;
1101: srde = (short[]) rDE;
1102: assertTrue(Arrays.equals(srde, stde));
1103: break;
1104: case DataBuffer.TYPE_INT:
1105: itde = (int[]) tDE;
1106: irde = (int[]) rDE;
1107: assertTrue(Arrays.equals(irde, itde));
1108: break;
1109: default:
1110: throw new IllegalArgumentException("Wrong Transfer Type");
1111: }
1112:
1113: trType = mppsmi2.getTransferType();
1114: tDE = null;
1115: tDE = mppsmi2.getDataElements(0, 0, 1, 1, tDE, dbi2);
1116: rDE = getDataElementsI(0, 0, 1, 1, trType);
1117: switch (trType) {
1118: case DataBuffer.TYPE_BYTE:
1119: tde = (byte[]) tDE;
1120: rde = (byte[]) rDE;
1121: assertTrue(Arrays.equals(rde, tde));
1122: break;
1123: case DataBuffer.TYPE_USHORT:
1124: stde = (short[]) tDE;
1125: srde = (short[]) rDE;
1126: assertTrue(Arrays.equals(srde, stde));
1127: break;
1128: case DataBuffer.TYPE_INT:
1129: itde = (int[]) tDE;
1130: irde = (int[]) rDE;
1131: assertTrue(Arrays.equals(irde, itde));
1132: break;
1133: default:
1134: throw new IllegalArgumentException("Wrong Transfer Type");
1135: }
1136:
1137: tDE = null;
1138: tDE = mppsmi2.getDataElements(0, 0, w / 2, h / 2, tDE, dbi2);
1139: rDE = getDataElementsI(0, 0, w / 2, w / 2, trType);
1140: switch (trType) {
1141: case DataBuffer.TYPE_BYTE:
1142: tde = (byte[]) tDE;
1143: rde = (byte[]) rDE;
1144: assertTrue(Arrays.equals(rde, tde));
1145: break;
1146: case DataBuffer.TYPE_USHORT:
1147: stde = (short[]) tDE;
1148: srde = (short[]) rDE;
1149: assertTrue(Arrays.equals(srde, stde));
1150: break;
1151: case DataBuffer.TYPE_INT:
1152: itde = (int[]) tDE;
1153: irde = (int[]) rDE;
1154: assertTrue(Arrays.equals(irde, itde));
1155: break;
1156: default:
1157: throw new IllegalArgumentException("Wrong Transfer Type");
1158: }
1159:
1160: tDE = null;
1161: tDE = mppsmi2.getDataElements(0, 0, w, h, tDE, dbi2);
1162: rDE = getDataElementsI(0, 0, w, h, trType);
1163: switch (trType) {
1164: case DataBuffer.TYPE_BYTE:
1165: tde = (byte[]) tDE;
1166: rde = (byte[]) rDE;
1167: assertTrue(Arrays.equals(rde, tde));
1168: break;
1169: case DataBuffer.TYPE_USHORT:
1170: stde = (short[]) tDE;
1171: srde = (short[]) rDE;
1172: assertTrue(Arrays.equals(srde, stde));
1173: break;
1174: case DataBuffer.TYPE_INT:
1175: itde = (int[]) tDE;
1176: irde = (int[]) rDE;
1177: assertTrue(Arrays.equals(irde, itde));
1178: break;
1179: default:
1180: throw new IllegalArgumentException("Wrong Transfer Type");
1181: }
1182: }
1183:
1184: public final void testGetPixel() {
1185: initDataBuffers();
1186:
1187: int pixel[];
1188: int idx;
1189:
1190: pixel = null;
1191: idx = 0;
1192: for (int y = 0; y < h; y++) {
1193: for (int x = 0; x < w; x++) {
1194: pixel = mppsmb1.getPixel(x, y, pixel, dbb1);
1195: assertEquals(byteTestData[idx++] & 0xff, pixel[0]);
1196: }
1197: }
1198:
1199: pixel = null;
1200: idx = 0;
1201: for (int y = 0; y < h; y++) {
1202: for (int x = 0; x < w; x++) {
1203: pixel = mppsmb2.getPixel(x, y, pixel, dbb2);
1204: assertEquals(byteTestData[idx++] & 0xff, pixel[0]);
1205: }
1206: }
1207:
1208: pixel = null;
1209: idx = 0;
1210: for (int y = 0; y < h; y++) {
1211: for (int x = 0; x < w; x++) {
1212: pixel = mppsmu1.getPixel(x, y, pixel, dbu1);
1213: assertEquals(shortTestData[idx++] & 0xffff, pixel[0]);
1214: }
1215: }
1216:
1217: pixel = null;
1218: idx = 0;
1219: for (int y = 0; y < h; y++) {
1220: for (int x = 0; x < w; x++) {
1221: pixel = mppsmu2.getPixel(x, y, pixel, dbu2);
1222: assertEquals(shortTestData[idx++] & 0xffff, pixel[0]);
1223: }
1224: }
1225:
1226: pixel = null;
1227: idx = 0;
1228: for (int y = 0; y < h; y++) {
1229: for (int x = 0; x < w; x++) {
1230: pixel = mppsmi1.getPixel(x, y, pixel, dbi1);
1231: assertEquals(intTestData[idx++], pixel[0]);
1232: }
1233: }
1234:
1235: pixel = null;
1236: idx = 0;
1237: for (int y = 0; y < h; y++) {
1238: for (int x = 0; x < w; x++) {
1239: pixel = mppsmi2.getPixel(x, y, pixel, dbi2);
1240: assertEquals(intTestData[idx++], pixel[0]);
1241: }
1242: }
1243: }
1244:
1245: public final void testGetPixels() {
1246: initDataBuffers();
1247: int tpixel[] = null;
1248: int rpixel[];
1249:
1250: tpixel = mppsmb1.getPixels(0, 0, 1, 1, tpixel, dbb1);
1251: rpixel = getPixelsB(0, 0, 1, 1);
1252: assertTrue(Arrays.equals(rpixel, tpixel));
1253:
1254: tpixel = null;
1255: tpixel = mppsmb1.getPixels(0, 0, w / 2, h / 2, tpixel, dbb1);
1256: rpixel = getPixelsB(0, 0, w / 2, h / 2);
1257: assertTrue(Arrays.equals(rpixel, tpixel));
1258:
1259: tpixel = null;
1260: tpixel = mppsmb1.getPixels(0, 0, w, h, tpixel, dbb1);
1261: rpixel = getPixelsB(0, 0, w, h);
1262: assertTrue(Arrays.equals(rpixel, tpixel));
1263:
1264: tpixel = null;
1265: tpixel = mppsmb2.getPixels(0, 0, 1, 1, tpixel, dbb2);
1266: rpixel = getPixelsB(0, 0, 1, 1);
1267: assertTrue(Arrays.equals(rpixel, tpixel));
1268:
1269: tpixel = null;
1270: tpixel = mppsmb2.getPixels(0, 0, w / 2, h / 2, tpixel, dbb2);
1271: rpixel = getPixelsB(0, 0, w / 2, h / 2);
1272: assertTrue(Arrays.equals(rpixel, tpixel));
1273:
1274: tpixel = null;
1275: tpixel = mppsmb2.getPixels(0, 0, w, h, tpixel, dbb2);
1276: rpixel = getPixelsB(0, 0, w, h);
1277: assertTrue(Arrays.equals(rpixel, tpixel));
1278:
1279: tpixel = null;
1280: tpixel = mppsmu1.getPixels(0, 0, 1, 1, tpixel, dbu1);
1281: rpixel = getPixelsUS(0, 0, 1, 1);
1282: assertTrue(Arrays.equals(rpixel, tpixel));
1283:
1284: tpixel = null;
1285: tpixel = mppsmu1.getPixels(0, 0, w / 2, h / 2, tpixel, dbu1);
1286: rpixel = getPixelsUS(0, 0, w / 2, h / 2);
1287: assertTrue(Arrays.equals(rpixel, tpixel));
1288:
1289: tpixel = null;
1290: tpixel = mppsmu1.getPixels(0, 0, w, h, tpixel, dbu1);
1291: rpixel = getPixelsUS(0, 0, w, h);
1292: assertTrue(Arrays.equals(rpixel, tpixel));
1293:
1294: tpixel = null;
1295: tpixel = mppsmu2.getPixels(0, 0, 1, 1, tpixel, dbu2);
1296: rpixel = getPixelsUS(0, 0, 1, 1);
1297: assertTrue(Arrays.equals(rpixel, tpixel));
1298:
1299: tpixel = null;
1300: tpixel = mppsmu2.getPixels(0, 0, w / 2, h / 2, tpixel, dbu2);
1301: rpixel = getPixelsUS(0, 0, w / 2, h / 2);
1302: assertTrue(Arrays.equals(rpixel, tpixel));
1303:
1304: tpixel = null;
1305: tpixel = mppsmu2.getPixels(0, 0, w, h, tpixel, dbu2);
1306: rpixel = getPixelsUS(0, 0, w, h);
1307: assertTrue(Arrays.equals(rpixel, tpixel));
1308:
1309: tpixel = null;
1310: tpixel = mppsmi1.getPixels(0, 0, 1, 1, tpixel, dbi1);
1311: rpixel = getPixelsI(0, 0, 1, 1);
1312: assertTrue(Arrays.equals(rpixel, tpixel));
1313:
1314: tpixel = null;
1315: tpixel = mppsmi1.getPixels(0, 0, w / 2, h / 2, tpixel, dbi1);
1316: rpixel = getPixelsI(0, 0, w / 2, h / 2);
1317: assertTrue(Arrays.equals(rpixel, tpixel));
1318:
1319: tpixel = null;
1320: tpixel = mppsmi1.getPixels(0, 0, w, h, tpixel, dbi1);
1321: rpixel = getPixelsI(0, 0, w, h);
1322: assertTrue(Arrays.equals(rpixel, tpixel));
1323:
1324: tpixel = null;
1325: tpixel = mppsmi2.getPixels(0, 0, 1, 1, tpixel, dbi2);
1326: rpixel = getPixelsI(0, 0, 1, 1);
1327: assertTrue(Arrays.equals(rpixel, tpixel));
1328:
1329: tpixel = null;
1330: tpixel = mppsmi2.getPixels(0, 0, w / 2, h / 2, tpixel, dbi2);
1331: rpixel = getPixelsI(0, 0, w / 2, h / 2);
1332: assertTrue(Arrays.equals(rpixel, tpixel));
1333:
1334: tpixel = null;
1335: tpixel = mppsmi2.getPixels(0, 0, w, h, tpixel, dbi2);
1336: rpixel = getPixelsI(0, 0, w, h);
1337: assertTrue(Arrays.equals(rpixel, tpixel));
1338: }
1339:
1340: public final void testGetSample() {
1341: initDataBuffers();
1342: int sample;
1343: int idx;
1344:
1345: idx = 0;
1346: for (int y = 0; y < h; y++) {
1347: for (int x = 0; x < w; x++) {
1348: sample = mppsmb1.getSample(x, y, 0, dbb1);
1349: assertEquals(byteTestData[idx++] & 0xff, sample);
1350: }
1351: }
1352:
1353: idx = 0;
1354: for (int y = 0; y < h; y++) {
1355: for (int x = 0; x < w; x++) {
1356: sample = mppsmb2.getSample(x, y, 0, dbb2);
1357: assertEquals(byteTestData[idx++] & 0xff, sample);
1358: }
1359: }
1360:
1361: idx = 0;
1362: for (int y = 0; y < h; y++) {
1363: for (int x = 0; x < w; x++) {
1364: sample = mppsmu1.getSample(x, y, 0, dbu1);
1365: assertEquals(shortTestData[idx++] & 0xffff, sample);
1366: }
1367: }
1368:
1369: idx = 0;
1370: for (int y = 0; y < h; y++) {
1371: for (int x = 0; x < w; x++) {
1372: sample = mppsmu2.getSample(x, y, 0, dbu2);
1373: assertEquals(shortTestData[idx++] & 0xffff, sample);
1374: }
1375: }
1376:
1377: idx = 0;
1378: for (int y = 0; y < h; y++) {
1379: for (int x = 0; x < w; x++) {
1380: sample = mppsmi1.getSample(x, y, 0, dbi1);
1381: assertEquals(intTestData[idx++], sample);
1382: }
1383: }
1384:
1385: idx = 0;
1386: for (int y = 0; y < h; y++) {
1387: for (int x = 0; x < w; x++) {
1388: sample = mppsmi2.getSample(x, y, 0, dbi2);
1389: assertEquals(intTestData[idx++], sample);
1390: }
1391: }
1392: }
1393:
1394: public final void testGetSamples() {
1395: initDataBuffers();
1396: int rsamples[];
1397: int tsamples[];
1398:
1399: for (int b = 0; b < mppsmb1.getNumBands(); b++) {
1400: tsamples = null;
1401: tsamples = mppsmb1
1402: .getSamples(0, 0, 1, 1, b, tsamples, dbb1);
1403: rsamples = getSamplesB(0, 0, 1, 1, b);
1404: assertTrue(Arrays.equals(rsamples, tsamples));
1405: }
1406:
1407: for (int b = 0; b < mppsmb1.getNumBands(); b++) {
1408: tsamples = null;
1409: tsamples = mppsmb1.getSamples(0, 0, w / 2, h / 2, b,
1410: tsamples, dbb1);
1411: rsamples = getSamplesB(0, 0, w / 2, h / 2, b);
1412: assertTrue(Arrays.equals(rsamples, tsamples));
1413: }
1414:
1415: for (int b = 0; b < mppsmb1.getNumBands(); b++) {
1416: tsamples = null;
1417: tsamples = mppsmb1
1418: .getSamples(0, 0, w, h, b, tsamples, dbb1);
1419: rsamples = getSamplesB(0, 0, w, h, b);
1420: assertTrue(Arrays.equals(rsamples, tsamples));
1421: }
1422:
1423: for (int b = 0; b < mppsmb2.getNumBands(); b++) {
1424: tsamples = null;
1425: tsamples = mppsmb2
1426: .getSamples(0, 0, 1, 1, b, tsamples, dbb2);
1427: rsamples = getSamplesB(0, 0, 1, 1, b);
1428: assertTrue(Arrays.equals(rsamples, tsamples));
1429: }
1430:
1431: for (int b = 0; b < mppsmb2.getNumBands(); b++) {
1432: tsamples = null;
1433: tsamples = mppsmb2.getSamples(0, 0, w / 2, h / 2, b,
1434: tsamples, dbb2);
1435: rsamples = getSamplesB(0, 0, w / 2, h / 2, b);
1436: assertTrue(Arrays.equals(rsamples, tsamples));
1437: }
1438:
1439: for (int b = 0; b < mppsmb2.getNumBands(); b++) {
1440: tsamples = null;
1441: tsamples = mppsmb2
1442: .getSamples(0, 0, w, h, b, tsamples, dbb2);
1443: rsamples = getSamplesB(0, 0, w, h, b);
1444: assertTrue(Arrays.equals(rsamples, tsamples));
1445: }
1446:
1447: for (int b = 0; b < mppsmu1.getNumBands(); b++) {
1448: tsamples = null;
1449: tsamples = mppsmu1
1450: .getSamples(0, 0, 1, 1, b, tsamples, dbu1);
1451: rsamples = getSamplesUS(0, 0, 1, 1, b);
1452: assertTrue(Arrays.equals(rsamples, tsamples));
1453: }
1454:
1455: for (int b = 0; b < mppsmu1.getNumBands(); b++) {
1456: tsamples = null;
1457: tsamples = mppsmu1.getSamples(0, 0, w / 2, h / 2, b,
1458: tsamples, dbu1);
1459: rsamples = getSamplesUS(0, 0, w / 2, h / 2, b);
1460: assertTrue(Arrays.equals(rsamples, tsamples));
1461: }
1462:
1463: for (int b = 0; b < mppsmu1.getNumBands(); b++) {
1464: tsamples = null;
1465: tsamples = mppsmu1
1466: .getSamples(0, 0, w, h, b, tsamples, dbu1);
1467: rsamples = getSamplesUS(0, 0, w, h, b);
1468: assertTrue(Arrays.equals(rsamples, tsamples));
1469: }
1470:
1471: for (int b = 0; b < mppsmu2.getNumBands(); b++) {
1472: tsamples = null;
1473: tsamples = mppsmu2
1474: .getSamples(0, 0, 1, 1, b, tsamples, dbu2);
1475: rsamples = getSamplesUS(0, 0, 1, 1, b);
1476: assertTrue(Arrays.equals(rsamples, tsamples));
1477: }
1478:
1479: for (int b = 0; b < mppsmu2.getNumBands(); b++) {
1480: tsamples = null;
1481: tsamples = mppsmu2.getSamples(0, 0, w / 2, h / 2, b,
1482: tsamples, dbu2);
1483: rsamples = getSamplesUS(0, 0, w / 2, h / 2, b);
1484: assertTrue(Arrays.equals(rsamples, tsamples));
1485: }
1486:
1487: for (int b = 0; b < mppsmu2.getNumBands(); b++) {
1488: tsamples = null;
1489: tsamples = mppsmu2
1490: .getSamples(0, 0, w, h, b, tsamples, dbu2);
1491: rsamples = getSamplesUS(0, 0, w, h, b);
1492: assertTrue(Arrays.equals(rsamples, tsamples));
1493: }
1494:
1495: for (int b = 0; b < mppsmi1.getNumBands(); b++) {
1496: tsamples = null;
1497: tsamples = mppsmi1
1498: .getSamples(0, 0, 1, 1, b, tsamples, dbi1);
1499: rsamples = getSamplesI(0, 0, 1, 1, b);
1500: assertTrue(Arrays.equals(rsamples, tsamples));
1501: }
1502:
1503: for (int b = 0; b < mppsmi1.getNumBands(); b++) {
1504: tsamples = null;
1505: tsamples = mppsmi1.getSamples(0, 0, w / 2, h / 2, b,
1506: tsamples, dbi1);
1507: rsamples = getSamplesI(0, 0, w / 2, h / 2, b);
1508: assertTrue(Arrays.equals(rsamples, tsamples));
1509: }
1510:
1511: for (int b = 0; b < mppsmi1.getNumBands(); b++) {
1512: tsamples = null;
1513: tsamples = mppsmi1
1514: .getSamples(0, 0, w, h, b, tsamples, dbi1);
1515: rsamples = getSamplesI(0, 0, w, h, b);
1516: assertTrue(Arrays.equals(rsamples, tsamples));
1517: }
1518:
1519: for (int b = 0; b < mppsmi2.getNumBands(); b++) {
1520: tsamples = null;
1521: tsamples = mppsmi2
1522: .getSamples(0, 0, 1, 1, b, tsamples, dbi2);
1523: rsamples = getSamplesI(0, 0, 1, 1, b);
1524: assertTrue(Arrays.equals(rsamples, tsamples));
1525: }
1526:
1527: for (int b = 0; b < mppsmi2.getNumBands(); b++) {
1528: tsamples = null;
1529: tsamples = mppsmi2.getSamples(0, 0, w / 2, h / 2, b,
1530: tsamples, dbi2);
1531: rsamples = getSamplesI(0, 0, w / 2, h / 2, b);
1532: assertTrue(Arrays.equals(rsamples, tsamples));
1533: }
1534:
1535: for (int b = 0; b < mppsmi2.getNumBands(); b++) {
1536: tsamples = null;
1537: tsamples = mppsmi2
1538: .getSamples(0, 0, w, h, b, tsamples, dbi2);
1539: rsamples = getSamplesI(0, 0, w, h, b);
1540: assertTrue(Arrays.equals(rsamples, tsamples));
1541: }
1542:
1543: }
1544:
1545: public final void testSetDataElements() {
1546: initTestData();
1547: int trType;
1548: int idx;
1549: int pixelStride;
1550: int stride;
1551: int bitOffset;
1552:
1553: idx = 0;
1554: trType = mppsmb1.getTransferType();
1555: for (int y = 0; y < h; y++) {
1556: for (int x = 0; x < w; x++) {
1557: Object de;
1558: switch (trType) {
1559: case DataBuffer.TYPE_BYTE:
1560: byte bde[] = new byte[1];
1561: bde[0] = byteTestData[idx++];
1562: de = bde;
1563: break;
1564: case DataBuffer.TYPE_USHORT:
1565: short sde[] = new short[1];
1566: sde[0] = (short) (byteTestData[idx++] & 0xff);
1567: de = sde;
1568: break;
1569: case DataBuffer.TYPE_INT:
1570: int ide[] = new int[1];
1571: ide[0] = byteTestData[idx++] & 0xff;
1572: de = ide;
1573: break;
1574: default:
1575: throw new IllegalArgumentException(
1576: "Wrong Transfer Type: " + trType);
1577: }
1578: mppsmb1.setDataElements(x, y, de, dbb1);
1579: }
1580: }
1581: idx = 0;
1582: pixelStride = mppsmb1.getPixelBitStride();
1583: stride = mppsmb1.getScanlineStride();
1584: bitOffset = mppsmb1.getDataBitOffset();
1585: for (int y = 0; y < h; y++) {
1586: for (int x = 0; x < w; x++) {
1587: assertEquals(byteTestData[idx++] & 0xff, getPixel(x, y,
1588: pixelStride, bitOffset, stride, dbb1));
1589:
1590: }
1591: }
1592:
1593: idx = 0;
1594: trType = mppsmb2.getTransferType();
1595: for (int y = 0; y < h; y++) {
1596: for (int x = 0; x < w; x++) {
1597: Object de;
1598: switch (trType) {
1599: case DataBuffer.TYPE_BYTE:
1600: byte bde[] = new byte[1];
1601: bde[0] = byteTestData[idx++];
1602: de = bde;
1603: break;
1604: case DataBuffer.TYPE_USHORT:
1605: short sde[] = new short[1];
1606: sde[0] = (short) (byteTestData[idx++] & 0xff);
1607: de = sde;
1608: break;
1609: case DataBuffer.TYPE_INT:
1610: int ide[] = new int[1];
1611: ide[0] = byteTestData[idx++] & 0xff;
1612: de = ide;
1613: break;
1614: default:
1615: throw new IllegalArgumentException(
1616: "Wrong Transfer Type: " + trType);
1617: }
1618: mppsmb2.setDataElements(x, y, de, dbb2);
1619: }
1620: }
1621: idx = 0;
1622: pixelStride = mppsmb2.getPixelBitStride();
1623: stride = mppsmb2.getScanlineStride();
1624: bitOffset = mppsmb2.getDataBitOffset();
1625: for (int y = 0; y < h; y++) {
1626: for (int x = 0; x < w; x++) {
1627: assertEquals(byteTestData[idx++] & 0xff, getPixel(x, y,
1628: pixelStride, bitOffset, stride, dbb2));
1629:
1630: }
1631: }
1632:
1633: idx = 0;
1634: trType = mppsmu1.getTransferType();
1635: for (int y = 0; y < h; y++) {
1636: for (int x = 0; x < w; x++) {
1637: Object de;
1638: switch (trType) {
1639: case DataBuffer.TYPE_BYTE:
1640: byte bde[] = new byte[1];
1641: bde[0] = (byte) shortTestData[idx++];
1642: de = bde;
1643: break;
1644: case DataBuffer.TYPE_USHORT:
1645: short sde[] = new short[1];
1646: sde[0] = shortTestData[idx++];
1647: de = sde;
1648: break;
1649: case DataBuffer.TYPE_INT:
1650: int ide[] = new int[1];
1651: ide[0] = shortTestData[idx++] & 0xffff;
1652: de = ide;
1653: break;
1654: default:
1655: throw new IllegalArgumentException(
1656: "Wrong Transfer Type: " + trType);
1657: }
1658: mppsmu1.setDataElements(x, y, de, dbu1);
1659: }
1660: }
1661: idx = 0;
1662: pixelStride = mppsmu1.getPixelBitStride();
1663: stride = mppsmu1.getScanlineStride();
1664: bitOffset = mppsmu1.getDataBitOffset();
1665: for (int y = 0; y < h; y++) {
1666: for (int x = 0; x < w; x++) {
1667: assertEquals(shortTestData[idx++] & 0xffff, getPixel(x,
1668: y, pixelStride, bitOffset, stride, dbu1));
1669:
1670: }
1671: }
1672:
1673: idx = 0;
1674: trType = mppsmu2.getTransferType();
1675: for (int y = 0; y < h; y++) {
1676: for (int x = 0; x < w; x++) {
1677: Object de;
1678: switch (trType) {
1679: case DataBuffer.TYPE_BYTE:
1680: byte bde[] = new byte[1];
1681: bde[0] = (byte) shortTestData[idx++];
1682: de = bde;
1683: break;
1684: case DataBuffer.TYPE_USHORT:
1685: short sde[] = new short[1];
1686: sde[0] = shortTestData[idx++];
1687: de = sde;
1688: break;
1689: case DataBuffer.TYPE_INT:
1690: int ide[] = new int[1];
1691: ide[0] = shortTestData[idx++] & 0xffff;
1692: de = ide;
1693: break;
1694: default:
1695: throw new IllegalArgumentException(
1696: "Wrong Transfer Type: " + trType);
1697: }
1698: mppsmu2.setDataElements(x, y, de, dbu2);
1699: }
1700: }
1701: idx = 0;
1702: pixelStride = mppsmu2.getPixelBitStride();
1703: stride = mppsmu2.getScanlineStride();
1704: bitOffset = mppsmu2.getDataBitOffset();
1705: for (int y = 0; y < h; y++) {
1706: for (int x = 0; x < w; x++) {
1707: assertEquals(shortTestData[idx++] & 0xffff, getPixel(x,
1708: y, pixelStride, bitOffset, stride, dbu2));
1709:
1710: }
1711: }
1712:
1713: idx = 0;
1714: trType = mppsmi1.getTransferType();
1715: for (int y = 0; y < h; y++) {
1716: for (int x = 0; x < w; x++) {
1717: Object de;
1718: switch (trType) {
1719: case DataBuffer.TYPE_BYTE:
1720: byte bde[] = new byte[1];
1721: bde[0] = (byte) intTestData[idx++];
1722: de = bde;
1723: break;
1724: case DataBuffer.TYPE_USHORT:
1725: short sde[] = new short[1];
1726: sde[0] = (short) intTestData[idx++];
1727: de = sde;
1728: break;
1729: case DataBuffer.TYPE_INT:
1730: int ide[] = new int[1];
1731: ide[0] = intTestData[idx++];
1732: de = ide;
1733: break;
1734: default:
1735: throw new IllegalArgumentException(
1736: "Wrong Transfer Type: " + trType);
1737: }
1738: mppsmi1.setDataElements(x, y, de, dbi1);
1739: }
1740: }
1741: idx = 0;
1742: pixelStride = mppsmi1.getPixelBitStride();
1743: stride = mppsmi1.getScanlineStride();
1744: bitOffset = mppsmi1.getDataBitOffset();
1745: for (int y = 0; y < h; y++) {
1746: for (int x = 0; x < w; x++) {
1747: assertEquals(intTestData[idx++], getPixel(x, y,
1748: pixelStride, bitOffset, stride, dbi1));
1749:
1750: }
1751: }
1752:
1753: idx = 0;
1754: trType = mppsmi2.getTransferType();
1755: for (int y = 0; y < h; y++) {
1756: for (int x = 0; x < w; x++) {
1757: Object de;
1758: switch (trType) {
1759: case DataBuffer.TYPE_BYTE:
1760: byte bde[] = new byte[1];
1761: bde[0] = (byte) intTestData[idx++];
1762: de = bde;
1763: break;
1764: case DataBuffer.TYPE_USHORT:
1765: short sde[] = new short[1];
1766: sde[0] = (short) intTestData[idx++];
1767: de = sde;
1768: break;
1769: case DataBuffer.TYPE_INT:
1770: int ide[] = new int[1];
1771: ide[0] = intTestData[idx++];
1772: de = ide;
1773: break;
1774: default:
1775: throw new IllegalArgumentException(
1776: "Wrong Transfer Type: " + trType);
1777: }
1778: mppsmi2.setDataElements(x, y, de, dbi2);
1779: }
1780: }
1781: idx = 0;
1782: pixelStride = mppsmi2.getPixelBitStride();
1783: stride = mppsmi2.getScanlineStride();
1784: bitOffset = mppsmi2.getDataBitOffset();
1785: for (int y = 0; y < h; y++) {
1786: for (int x = 0; x < w; x++) {
1787: assertEquals(intTestData[idx++], getPixel(x, y,
1788: pixelStride, bitOffset, stride, dbi2));
1789:
1790: }
1791: }
1792:
1793: // Regression for HARMONY-2779
1794: try {
1795: new MultiPixelPackedSampleModel(0, 52, 4, 8)
1796: .setDataElements(6, 2, (Object) null,
1797: new DataBufferFloat(4, 1));
1798: fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
1799: } catch (ArrayIndexOutOfBoundsException ex) {
1800: // expected
1801: }
1802:
1803: // Regression for HARMONY-2779
1804: try {
1805: new MultiPixelPackedSampleModel(0, 14907, 18936, 2)
1806: .setDataElements(14, 14, new JSplitPane(),
1807: (DataBuffer) null);
1808: fail("NullPointerException was not thrown"); //$NON-NLS-1$
1809: } catch (NullPointerException ex) {
1810: // expected
1811: }
1812: }
1813:
1814: public final void testSetPixel() {
1815: initTestData();
1816: int pixel[] = new int[1];
1817: int idx;
1818: int pixelStride;
1819: int stride;
1820: int bitOffset;
1821:
1822: idx = 0;
1823: for (int y = 0; y < h; y++) {
1824: for (int x = 0; x < w; x++) {
1825: pixel[0] = byteTestData[idx++];
1826: mppsmb1.setPixel(x, y, pixel, dbb1);
1827: }
1828: }
1829:
1830: idx = 0;
1831: pixelStride = mppsmb1.getPixelBitStride();
1832: stride = mppsmb1.getScanlineStride();
1833: bitOffset = mppsmb1.getDataBitOffset();
1834: for (int y = 0; y < h; y++) {
1835: for (int x = 0; x < w; x++) {
1836: assertEquals(byteTestData[idx++], getPixel(x, y,
1837: pixelStride, bitOffset, stride, dbb1));
1838: }
1839: }
1840:
1841: idx = 0;
1842: for (int y = 0; y < h; y++) {
1843: for (int x = 0; x < w; x++) {
1844: pixel[0] = byteTestData[idx++];
1845: mppsmb2.setPixel(x, y, pixel, dbb2);
1846: }
1847: }
1848:
1849: idx = 0;
1850: pixelStride = mppsmb2.getPixelBitStride();
1851: stride = mppsmb2.getScanlineStride();
1852: bitOffset = mppsmb2.getDataBitOffset();
1853: for (int y = 0; y < h; y++) {
1854: for (int x = 0; x < w; x++) {
1855: assertEquals(byteTestData[idx++], getPixel(x, y,
1856: pixelStride, bitOffset, stride, dbb2));
1857: }
1858: }
1859:
1860: idx = 0;
1861: for (int y = 0; y < h; y++) {
1862: for (int x = 0; x < w; x++) {
1863: pixel[0] = shortTestData[idx++];
1864: mppsmu1.setPixel(x, y, pixel, dbu1);
1865: }
1866: }
1867:
1868: idx = 0;
1869: pixelStride = mppsmu1.getPixelBitStride();
1870: stride = mppsmu1.getScanlineStride();
1871: bitOffset = mppsmu1.getDataBitOffset();
1872: for (int y = 0; y < h; y++) {
1873: for (int x = 0; x < w; x++) {
1874: assertEquals(shortTestData[idx++], getPixel(x, y,
1875: pixelStride, bitOffset, stride, dbu1));
1876: }
1877: }
1878:
1879: idx = 0;
1880: for (int y = 0; y < h; y++) {
1881: for (int x = 0; x < w; x++) {
1882: pixel[0] = shortTestData[idx++];
1883: mppsmu2.setPixel(x, y, pixel, dbu2);
1884: }
1885: }
1886:
1887: idx = 0;
1888: pixelStride = mppsmu2.getPixelBitStride();
1889: stride = mppsmu2.getScanlineStride();
1890: bitOffset = mppsmu2.getDataBitOffset();
1891: for (int y = 0; y < h; y++) {
1892: for (int x = 0; x < w; x++) {
1893: assertEquals(shortTestData[idx++], getPixel(x, y,
1894: pixelStride, bitOffset, stride, dbu2));
1895: }
1896: }
1897:
1898: idx = 0;
1899: for (int y = 0; y < h; y++) {
1900: for (int x = 0; x < w; x++) {
1901: pixel[0] = intTestData[idx++];
1902: mppsmi1.setPixel(x, y, pixel, dbi1);
1903: }
1904: }
1905:
1906: idx = 0;
1907: pixelStride = mppsmi1.getPixelBitStride();
1908: stride = mppsmi1.getScanlineStride();
1909: bitOffset = mppsmi1.getDataBitOffset();
1910: for (int y = 0; y < h; y++) {
1911: for (int x = 0; x < w; x++) {
1912: assertEquals(intTestData[idx++], getPixel(x, y,
1913: pixelStride, bitOffset, stride, dbi1));
1914: }
1915: }
1916:
1917: idx = 0;
1918: for (int y = 0; y < h; y++) {
1919: for (int x = 0; x < w; x++) {
1920: pixel[0] = intTestData[idx++];
1921: mppsmi2.setPixel(x, y, pixel, dbi2);
1922: }
1923: }
1924:
1925: idx = 0;
1926: pixelStride = mppsmi2.getPixelBitStride();
1927: stride = mppsmi2.getScanlineStride();
1928: bitOffset = mppsmi2.getDataBitOffset();
1929: for (int y = 0; y < h; y++) {
1930: for (int x = 0; x < w; x++) {
1931: assertEquals(intTestData[idx++], getPixel(x, y,
1932: pixelStride, bitOffset, stride, dbi2));
1933: }
1934: }
1935: }
1936:
1937: public final void testSetPixels() {
1938: initTestData();
1939: int pixels[];
1940: int pixelStride;
1941: int stride;
1942: int bitOffset;
1943:
1944: pixelStride = mppsmb1.getPixelBitStride();
1945: stride = mppsmb1.getScanlineStride();
1946: bitOffset = mppsmb1.getDataBitOffset();
1947:
1948: pixels = createPixelsFromByteData(0, 0, 1, 1);
1949: mppsmb1.setPixels(0, 0, 1, 1, pixels, dbb1);
1950: assertEquals(byteTestData[0] & 0xff, getPixel(0, 0,
1951: pixelStride, bitOffset, stride, dbb1));
1952:
1953: pixels = createPixelsFromByteData(0, 0, w / 2, h / 2);
1954: mppsmb1.setPixels(0, 0, w / 2, h / 2, pixels, dbb1);
1955: for (int y = 0; y < h / 2; y++) {
1956: for (int x = 0; x < w / 2; x++) {
1957: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
1958: x, y, pixelStride, bitOffset, stride, dbb1));
1959: }
1960: }
1961:
1962: pixels = createPixelsFromByteData(0, 0, w, h);
1963: mppsmb1.setPixels(0, 0, w, h, pixels, dbb1);
1964: for (int y = 0; y < h; y++) {
1965: for (int x = 0; x < w; x++) {
1966: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
1967: x, y, pixelStride, bitOffset, stride, dbb1));
1968: }
1969: }
1970:
1971: pixelStride = mppsmb2.getPixelBitStride();
1972: stride = mppsmb2.getScanlineStride();
1973: bitOffset = mppsmb2.getDataBitOffset();
1974:
1975: pixels = createPixelsFromByteData(0, 0, 1, 1);
1976: mppsmb2.setPixels(0, 0, 1, 1, pixels, dbb2);
1977: assertEquals(byteTestData[0] & 0xff, getPixel(0, 0,
1978: pixelStride, bitOffset, stride, dbb2));
1979:
1980: pixels = createPixelsFromByteData(0, 0, w / 2, h / 2);
1981: mppsmb2.setPixels(0, 0, w / 2, h / 2, pixels, dbb2);
1982: for (int y = 0; y < h / 2; y++) {
1983: for (int x = 0; x < w / 2; x++) {
1984: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
1985: x, y, pixelStride, bitOffset, stride, dbb2));
1986: }
1987: }
1988:
1989: pixels = createPixelsFromByteData(0, 0, w, h);
1990: mppsmb2.setPixels(0, 0, w, h, pixels, dbb2);
1991: for (int y = 0; y < h; y++) {
1992: for (int x = 0; x < w; x++) {
1993: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
1994: x, y, pixelStride, bitOffset, stride, dbb2));
1995: }
1996: }
1997:
1998: pixelStride = mppsmu1.getPixelBitStride();
1999: stride = mppsmu1.getScanlineStride();
2000: bitOffset = mppsmu1.getDataBitOffset();
2001:
2002: pixels = createPixelsFromShortData(0, 0, 1, 1);
2003: mppsmu1.setPixels(0, 0, 1, 1, pixels, dbu1);
2004: assertEquals(shortTestData[0] & 0xffff, getPixel(0, 0,
2005: pixelStride, bitOffset, stride, dbu1));
2006:
2007: pixels = createPixelsFromShortData(0, 0, w / 2, h / 2);
2008: mppsmu1.setPixels(0, 0, w / 2, h / 2, pixels, dbu1);
2009: for (int y = 0; y < h / 2; y++) {
2010: for (int x = 0; x < w / 2; x++) {
2011: assertEquals(shortTestData[y * w + x] & 0xffff,
2012: getPixel(x, y, pixelStride, bitOffset, stride,
2013: dbu1));
2014: }
2015: }
2016:
2017: pixels = createPixelsFromShortData(0, 0, w, h);
2018: mppsmu1.setPixels(0, 0, w, h, pixels, dbu1);
2019: for (int y = 0; y < h; y++) {
2020: for (int x = 0; x < w; x++) {
2021: assertEquals(shortTestData[y * w + x] & 0xffff,
2022: getPixel(x, y, pixelStride, bitOffset, stride,
2023: dbu1));
2024: }
2025: }
2026:
2027: pixelStride = mppsmu2.getPixelBitStride();
2028: stride = mppsmu2.getScanlineStride();
2029: bitOffset = mppsmu2.getDataBitOffset();
2030:
2031: pixels = createPixelsFromShortData(0, 0, 1, 1);
2032: mppsmu2.setPixels(0, 0, 1, 1, pixels, dbu2);
2033: assertEquals(shortTestData[0] & 0xffff, getPixel(0, 0,
2034: pixelStride, bitOffset, stride, dbu2));
2035:
2036: pixels = createPixelsFromShortData(0, 0, w / 2, h / 2);
2037: mppsmu2.setPixels(0, 0, w / 2, h / 2, pixels, dbu2);
2038: for (int y = 0; y < h / 2; y++) {
2039: for (int x = 0; x < w / 2; x++) {
2040: assertEquals(shortTestData[y * w + x] & 0xffff,
2041: getPixel(x, y, pixelStride, bitOffset, stride,
2042: dbu2));
2043: }
2044: }
2045:
2046: pixels = createPixelsFromShortData(0, 0, w, h);
2047: mppsmu2.setPixels(0, 0, w, h, pixels, dbu2);
2048: for (int y = 0; y < h; y++) {
2049: for (int x = 0; x < w; x++) {
2050: assertEquals(shortTestData[y * w + x] & 0xffff,
2051: getPixel(x, y, pixelStride, bitOffset, stride,
2052: dbu2));
2053: }
2054: }
2055:
2056: pixelStride = mppsmi1.getPixelBitStride();
2057: stride = mppsmi1.getScanlineStride();
2058: bitOffset = mppsmi1.getDataBitOffset();
2059:
2060: pixels = createPixelsFromIntData(0, 0, 1, 1);
2061: mppsmi1.setPixels(0, 0, 1, 1, pixels, dbi1);
2062: assertEquals(intTestData[0], getPixel(0, 0, pixelStride,
2063: bitOffset, stride, dbi1));
2064:
2065: pixels = createPixelsFromIntData(0, 0, w / 2, h / 2);
2066: mppsmi1.setPixels(0, 0, w / 2, h / 2, pixels, dbi1);
2067: for (int y = 0; y < h / 2; y++) {
2068: for (int x = 0; x < w / 2; x++) {
2069: assertEquals(intTestData[y * w + x], getPixel(x, y,
2070: pixelStride, bitOffset, stride, dbi1));
2071: }
2072: }
2073:
2074: pixels = createPixelsFromIntData(0, 0, w, h);
2075: mppsmi1.setPixels(0, 0, w, h, pixels, dbi1);
2076: for (int y = 0; y < h; y++) {
2077: for (int x = 0; x < w; x++) {
2078: assertEquals(intTestData[y * w + x], getPixel(x, y,
2079: pixelStride, bitOffset, stride, dbi1));
2080: }
2081: }
2082:
2083: pixelStride = mppsmi2.getPixelBitStride();
2084: stride = mppsmi2.getScanlineStride();
2085: bitOffset = mppsmi2.getDataBitOffset();
2086:
2087: pixels = createPixelsFromIntData(0, 0, 1, 1);
2088: mppsmi2.setPixels(0, 0, 1, 1, pixels, dbi2);
2089: assertEquals(intTestData[0] & 0xff, getPixel(0, 0, pixelStride,
2090: bitOffset, stride, dbi2));
2091:
2092: pixels = createPixelsFromIntData(0, 0, w / 2, h / 2);
2093: mppsmi2.setPixels(0, 0, w / 2, h / 2, pixels, dbi2);
2094: for (int y = 0; y < h / 2; y++) {
2095: for (int x = 0; x < w / 2; x++) {
2096: assertEquals(intTestData[y * w + x], getPixel(x, y,
2097: pixelStride, bitOffset, stride, dbi2));
2098: }
2099: }
2100:
2101: pixels = createPixelsFromIntData(0, 0, w, h);
2102: mppsmi2.setPixels(0, 0, w, h, pixels, dbi2);
2103: for (int y = 0; y < h; y++) {
2104: for (int x = 0; x < w; x++) {
2105: assertEquals(intTestData[y * w + x], getPixel(x, y,
2106: pixelStride, bitOffset, stride, dbi2));
2107: }
2108: }
2109: }
2110:
2111: public final void testSetSample() {
2112: initTestData();
2113: int sample;
2114: int idx;
2115: int pixelStride;
2116: int stride;
2117: int bitOffset;
2118:
2119: idx = 0;
2120: for (int y = 0; y < h; y++) {
2121: for (int x = 0; x < w; x++) {
2122: sample = byteTestData[idx++];
2123: mppsmb1.setSample(x, y, 0, sample, dbb1);
2124: }
2125: }
2126: idx = 0;
2127: pixelStride = mppsmb1.getPixelBitStride();
2128: stride = mppsmb1.getScanlineStride();
2129: bitOffset = mppsmb1.getDataBitOffset();
2130: for (int y = 0; y < h; y++) {
2131: for (int x = 0; x < w; x++) {
2132: assertEquals(byteTestData[idx++], getPixel(x, y,
2133: pixelStride, bitOffset, stride, dbb1));
2134: }
2135: }
2136:
2137: idx = 0;
2138: for (int y = 0; y < h; y++) {
2139: for (int x = 0; x < w; x++) {
2140: sample = byteTestData[idx++];
2141: mppsmb2.setSample(x, y, 0, sample, dbb2);
2142: }
2143: }
2144: idx = 0;
2145: pixelStride = mppsmb2.getPixelBitStride();
2146: stride = mppsmb2.getScanlineStride();
2147: bitOffset = mppsmb2.getDataBitOffset();
2148: for (int y = 0; y < h; y++) {
2149: for (int x = 0; x < w; x++) {
2150: assertEquals(byteTestData[idx++], getPixel(x, y,
2151: pixelStride, bitOffset, stride, dbb2));
2152: }
2153: }
2154:
2155: idx = 0;
2156: for (int y = 0; y < h; y++) {
2157: for (int x = 0; x < w; x++) {
2158: sample = shortTestData[idx++];
2159: mppsmu1.setSample(x, y, 0, sample, dbu1);
2160: }
2161: }
2162: idx = 0;
2163: pixelStride = mppsmu1.getPixelBitStride();
2164: stride = mppsmu1.getScanlineStride();
2165: bitOffset = mppsmu1.getDataBitOffset();
2166: for (int y = 0; y < h; y++) {
2167: for (int x = 0; x < w; x++) {
2168: assertEquals(shortTestData[idx++], getPixel(x, y,
2169: pixelStride, bitOffset, stride, dbu1));
2170: }
2171: }
2172:
2173: idx = 0;
2174: for (int y = 0; y < h; y++) {
2175: for (int x = 0; x < w; x++) {
2176: sample = shortTestData[idx++];
2177: mppsmu2.setSample(x, y, 0, sample, dbu2);
2178: }
2179: }
2180: idx = 0;
2181: pixelStride = mppsmu2.getPixelBitStride();
2182: stride = mppsmu2.getScanlineStride();
2183: bitOffset = mppsmu2.getDataBitOffset();
2184: for (int y = 0; y < h; y++) {
2185: for (int x = 0; x < w; x++) {
2186: assertEquals(shortTestData[idx++], getPixel(x, y,
2187: pixelStride, bitOffset, stride, dbu2));
2188: }
2189: }
2190:
2191: idx = 0;
2192: for (int y = 0; y < h; y++) {
2193: for (int x = 0; x < w; x++) {
2194: sample = intTestData[idx++];
2195: mppsmi1.setSample(x, y, 0, sample, dbi1);
2196: }
2197: }
2198: idx = 0;
2199: pixelStride = mppsmi1.getPixelBitStride();
2200: stride = mppsmi1.getScanlineStride();
2201: bitOffset = mppsmi1.getDataBitOffset();
2202: for (int y = 0; y < h; y++) {
2203: for (int x = 0; x < w; x++) {
2204: assertEquals(intTestData[idx++], getPixel(x, y,
2205: pixelStride, bitOffset, stride, dbi1));
2206: }
2207: }
2208:
2209: idx = 0;
2210: for (int y = 0; y < h; y++) {
2211: for (int x = 0; x < w; x++) {
2212: sample = intTestData[idx++];
2213: mppsmi2.setSample(x, y, 0, sample, dbi2);
2214: }
2215: }
2216: idx = 0;
2217: pixelStride = mppsmi2.getPixelBitStride();
2218: stride = mppsmi2.getScanlineStride();
2219: bitOffset = mppsmi2.getDataBitOffset();
2220: for (int y = 0; y < h; y++) {
2221: for (int x = 0; x < w; x++) {
2222: assertEquals(intTestData[idx++], getPixel(x, y,
2223: pixelStride, bitOffset, stride, dbi2));
2224: }
2225: }
2226: }
2227:
2228: public final void testSetSamples() {
2229: initTestData();
2230: int samples[];
2231: int pixelStride;
2232: int stride;
2233: int bitOffset;
2234: int numBands;
2235:
2236: pixelStride = mppsmb1.getPixelBitStride();
2237: stride = mppsmb1.getScanlineStride();
2238: bitOffset = mppsmb1.getDataBitOffset();
2239: numBands = mppsmb1.getNumBands();
2240:
2241: for (int b = 0; b < numBands; b++) {
2242: samples = createSamplesFromByteData(0, 0, 1, 1, b);
2243: mppsmb1.setSamples(0, 0, 1, 1, b, samples, dbb1);
2244: }
2245: assertEquals(byteTestData[0] & 0xff, getPixel(0, 0,
2246: pixelStride, bitOffset, stride, dbb1));
2247:
2248: for (int b = 0; b < numBands; b++) {
2249: samples = createSamplesFromByteData(0, 0, w / 2, h / 2, b);
2250: mppsmb1.setSamples(0, 0, w / 2, h / 2, b, samples, dbb1);
2251: }
2252: for (int y = 0; y < h / 2; y++) {
2253: for (int x = 0; x < w / 2; x++) {
2254: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
2255: x, y, pixelStride, bitOffset, stride, dbb1));
2256: }
2257: }
2258:
2259: for (int b = 0; b < numBands; b++) {
2260: samples = createSamplesFromByteData(0, 0, w, h, b);
2261: mppsmb1.setSamples(0, 0, w, h, b, samples, dbb1);
2262: }
2263: for (int y = 0; y < h; y++) {
2264: for (int x = 0; x < w; x++) {
2265: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
2266: x, y, pixelStride, bitOffset, stride, dbb1));
2267: }
2268: }
2269:
2270: pixelStride = mppsmb2.getPixelBitStride();
2271: stride = mppsmb2.getScanlineStride();
2272: bitOffset = mppsmb2.getDataBitOffset();
2273: numBands = mppsmb2.getNumBands();
2274:
2275: for (int b = 0; b < numBands; b++) {
2276: samples = createSamplesFromByteData(0, 0, 1, 1, b);
2277: mppsmb2.setSamples(0, 0, 1, 1, b, samples, dbb2);
2278: }
2279: assertEquals(byteTestData[0] & 0xff, getPixel(0, 0,
2280: pixelStride, bitOffset, stride, dbb2));
2281:
2282: for (int b = 0; b < numBands; b++) {
2283: samples = createSamplesFromByteData(0, 0, w / 2, h / 2, b);
2284: mppsmb2.setSamples(0, 0, w / 2, h / 2, b, samples, dbb2);
2285: }
2286: for (int y = 0; y < h / 2; y++) {
2287: for (int x = 0; x < w / 2; x++) {
2288: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
2289: x, y, pixelStride, bitOffset, stride, dbb2));
2290: }
2291: }
2292:
2293: for (int b = 0; b < numBands; b++) {
2294: samples = createSamplesFromByteData(0, 0, w, h, b);
2295: mppsmb2.setSamples(0, 0, w, h, b, samples, dbb2);
2296: }
2297: for (int y = 0; y < h; y++) {
2298: for (int x = 0; x < w; x++) {
2299: assertEquals(byteTestData[y * w + x] & 0xff, getPixel(
2300: x, y, pixelStride, bitOffset, stride, dbb2));
2301: }
2302: }
2303:
2304: pixelStride = mppsmu1.getPixelBitStride();
2305: stride = mppsmu1.getScanlineStride();
2306: bitOffset = mppsmu1.getDataBitOffset();
2307: numBands = mppsmu1.getNumBands();
2308:
2309: for (int b = 0; b < numBands; b++) {
2310: samples = createSamplesFromShortData(0, 0, 1, 1, b);
2311: mppsmu1.setSamples(0, 0, 1, 1, b, samples, dbu1);
2312: }
2313: assertEquals(shortTestData[0] & 0xffff, getPixel(0, 0,
2314: pixelStride, bitOffset, stride, dbu1));
2315:
2316: for (int b = 0; b < numBands; b++) {
2317: samples = createSamplesFromShortData(0, 0, w / 2, h / 2, b);
2318: mppsmu1.setSamples(0, 0, w / 2, h / 2, b, samples, dbu1);
2319: }
2320: for (int y = 0; y < h / 2; y++) {
2321: for (int x = 0; x < w / 2; x++) {
2322: assertEquals(shortTestData[y * w + x] & 0xffff,
2323: getPixel(x, y, pixelStride, bitOffset, stride,
2324: dbu1));
2325: }
2326: }
2327:
2328: for (int b = 0; b < numBands; b++) {
2329: samples = createSamplesFromShortData(0, 0, w, h, b);
2330: mppsmu1.setSamples(0, 0, w, h, b, samples, dbu1);
2331: }
2332: for (int y = 0; y < h; y++) {
2333: for (int x = 0; x < w; x++) {
2334: assertEquals(shortTestData[y * w + x] & 0xffff,
2335: getPixel(x, y, pixelStride, bitOffset, stride,
2336: dbu1));
2337: }
2338: }
2339:
2340: pixelStride = mppsmu2.getPixelBitStride();
2341: stride = mppsmu2.getScanlineStride();
2342: bitOffset = mppsmu2.getDataBitOffset();
2343: numBands = mppsmu2.getNumBands();
2344:
2345: for (int b = 0; b < numBands; b++) {
2346: samples = createSamplesFromShortData(0, 0, 1, 1, b);
2347: mppsmu2.setSamples(0, 0, 1, 1, b, samples, dbu2);
2348: }
2349: assertEquals(shortTestData[0] & 0xffff, getPixel(0, 0,
2350: pixelStride, bitOffset, stride, dbu2));
2351:
2352: for (int b = 0; b < numBands; b++) {
2353: samples = createSamplesFromShortData(0, 0, w / 2, h / 2, b);
2354: mppsmu2.setSamples(0, 0, w / 2, h / 2, b, samples, dbu2);
2355: }
2356: for (int y = 0; y < h / 2; y++) {
2357: for (int x = 0; x < w / 2; x++) {
2358: assertEquals(shortTestData[y * w + x] & 0xffff,
2359: getPixel(x, y, pixelStride, bitOffset, stride,
2360: dbu2));
2361: }
2362: }
2363:
2364: for (int b = 0; b < numBands; b++) {
2365: samples = createSamplesFromShortData(0, 0, w, h, b);
2366: mppsmu2.setSamples(0, 0, w, h, b, samples, dbu2);
2367: }
2368: for (int y = 0; y < h; y++) {
2369: for (int x = 0; x < w; x++) {
2370: assertEquals(shortTestData[y * w + x] & 0xffff,
2371: getPixel(x, y, pixelStride, bitOffset, stride,
2372: dbu2));
2373: }
2374: }
2375:
2376: pixelStride = mppsmi1.getPixelBitStride();
2377: stride = mppsmi1.getScanlineStride();
2378: bitOffset = mppsmi1.getDataBitOffset();
2379: numBands = mppsmi1.getNumBands();
2380:
2381: for (int b = 0; b < numBands; b++) {
2382: samples = createSamplesFromIntData(0, 0, 1, 1, b);
2383: mppsmi1.setSamples(0, 0, 1, 1, b, samples, dbi1);
2384: }
2385: assertEquals(intTestData[0], getPixel(0, 0, pixelStride,
2386: bitOffset, stride, dbi1));
2387:
2388: for (int b = 0; b < numBands; b++) {
2389: samples = createSamplesFromIntData(0, 0, w / 2, h / 2, b);
2390: mppsmi1.setSamples(0, 0, w / 2, h / 2, b, samples, dbi1);
2391: }
2392: for (int y = 0; y < h / 2; y++) {
2393: for (int x = 0; x < w / 2; x++) {
2394: assertEquals(intTestData[y * w + x], getPixel(x, y,
2395: pixelStride, bitOffset, stride, dbi1));
2396: }
2397: }
2398:
2399: for (int b = 0; b < numBands; b++) {
2400: samples = createSamplesFromIntData(0, 0, w, h, b);
2401: mppsmi1.setSamples(0, 0, w, h, b, samples, dbi1);
2402: }
2403: for (int y = 0; y < h; y++) {
2404: for (int x = 0; x < w; x++) {
2405: assertEquals(intTestData[y * w + x], getPixel(x, y,
2406: pixelStride, bitOffset, stride, dbi1));
2407: }
2408: }
2409:
2410: pixelStride = mppsmi2.getPixelBitStride();
2411: stride = mppsmi2.getScanlineStride();
2412: bitOffset = mppsmi2.getDataBitOffset();
2413: numBands = mppsmi2.getNumBands();
2414:
2415: for (int b = 0; b < numBands; b++) {
2416: samples = createSamplesFromIntData(0, 0, 1, 1, b);
2417: mppsmi2.setSamples(0, 0, 1, 1, b, samples, dbi2);
2418: }
2419: assertEquals(intTestData[0], getPixel(0, 0, pixelStride,
2420: bitOffset, stride, dbi2));
2421:
2422: for (int b = 0; b < numBands; b++) {
2423: samples = createSamplesFromIntData(0, 0, w / 2, h / 2, b);
2424: mppsmi2.setSamples(0, 0, w / 2, h / 2, b, samples, dbi2);
2425: }
2426: for (int y = 0; y < h / 2; y++) {
2427: for (int x = 0; x < w / 2; x++) {
2428: assertEquals(intTestData[y * w + x], getPixel(x, y,
2429: pixelStride, bitOffset, stride, dbi2));
2430: }
2431: }
2432:
2433: for (int b = 0; b < numBands; b++) {
2434: samples = createSamplesFromIntData(0, 0, w, h, b);
2435: mppsmi2.setSamples(0, 0, w, h, b, samples, dbi2);
2436: }
2437: for (int y = 0; y < h; y++) {
2438: for (int x = 0; x < w; x++) {
2439: assertEquals(intTestData[y * w + x], getPixel(x, y,
2440: pixelStride, bitOffset, stride, dbi2));
2441: }
2442: }
2443: }
2444:
2445: private void initTestData() {
2446: int maxByte = (1 << bPixelBits) - 1;
2447: int maxShort = (1 << sPixelBits) - 1;
2448: int maxInt = (1 << iPixelBits) - 1;
2449: Random r = new Random();
2450: int size = w * h;
2451:
2452: byteTestData = new byte[size];
2453: for (int i = 0; i < size; i++) {
2454: byteTestData[i] = (byte) ((int) (r.nextDouble() * maxByte) & 0xff);
2455: }
2456:
2457: shortTestData = new short[size];
2458: for (int i = 0; i < size; i++) {
2459: shortTestData[i] = (short) ((int) (r.nextDouble() * maxShort) & 0xffff);
2460: }
2461:
2462: intTestData = new int[size];
2463: for (int i = 0; i < size; i++) {
2464: intTestData[i] = (int) (r.nextDouble() * maxInt);
2465: }
2466: }
2467:
2468: private void initDataBuffers() {
2469: initTestData();
2470: int pixelStride = mppsmb1.getPixelBitStride();
2471: int stride = mppsmb1.getScanlineStride();
2472: int offset = mppsmb1.getDataBitOffset();
2473: int idx = 0;
2474: for (int y = 0; y < h; y++) {
2475: for (int x = 0; x < w; x++) {
2476: setPixel(x, y, pixelStride, offset, stride,
2477: byteTestData[idx++], dbb1);
2478: }
2479: }
2480:
2481: pixelStride = mppsmb2.getPixelBitStride();
2482: stride = mppsmb2.getScanlineStride();
2483: offset = mppsmb2.getDataBitOffset();
2484: idx = 0;
2485: for (int y = 0; y < h; y++) {
2486: for (int x = 0; x < w; x++) {
2487: setPixel(x, y, pixelStride, offset, stride,
2488: byteTestData[idx++], dbb2);
2489: }
2490: }
2491:
2492: pixelStride = mppsmu1.getPixelBitStride();
2493: stride = mppsmu1.getScanlineStride();
2494: offset = mppsmu1.getDataBitOffset();
2495: idx = 0;
2496: for (int y = 0; y < h; y++) {
2497: for (int x = 0; x < w; x++) {
2498: setPixel(x, y, pixelStride, offset, stride,
2499: shortTestData[idx++], dbu1);
2500: }
2501: }
2502:
2503: pixelStride = mppsmu2.getPixelBitStride();
2504: stride = mppsmu2.getScanlineStride();
2505: offset = mppsmu2.getDataBitOffset();
2506: idx = 0;
2507: for (int y = 0; y < h; y++) {
2508: for (int x = 0; x < w; x++) {
2509: setPixel(x, y, pixelStride, offset, stride,
2510: shortTestData[idx++], dbu2);
2511: }
2512: }
2513:
2514: pixelStride = mppsmi1.getPixelBitStride();
2515: stride = mppsmi1.getScanlineStride();
2516: offset = mppsmi1.getDataBitOffset();
2517: idx = 0;
2518: for (int y = 0; y < h; y++) {
2519: for (int x = 0; x < w; x++) {
2520: setPixel(x, y, pixelStride, offset, stride,
2521: intTestData[idx++], dbi1);
2522: }
2523: }
2524:
2525: pixelStride = mppsmi2.getPixelBitStride();
2526: stride = mppsmi2.getScanlineStride();
2527: offset = mppsmi2.getDataBitOffset();
2528: idx = 0;
2529: for (int y = 0; y < h; y++) {
2530: for (int x = 0; x < w; x++) {
2531: setPixel(x, y, pixelStride, offset, stride,
2532: intTestData[idx++], dbi2);
2533: }
2534: }
2535: }
2536:
2537: private void setPixel(int x, int y, int pixelStride, int bitOffset,
2538: int scanline, int pixel, DataBuffer db) {
2539:
2540: int type = db.getDataType();
2541: int dataElemSize = DataBuffer.getDataTypeSize(type);
2542: int bitMask = (1 << pixelStride) - 1;
2543: int bitnum = bitOffset + x * pixelStride;
2544: int idx = (y * scanline + bitnum / dataElemSize);
2545: int dataElem = db.getElem(idx);
2546: int shift = dataElemSize - (bitnum & (dataElemSize - 1))
2547: - pixelStride;
2548: int mask = ~(bitMask << shift);
2549: dataElem &= mask;
2550: dataElem |= (pixel & bitMask) << shift;
2551: db.setElem(idx, dataElem);
2552: }
2553:
2554: private int getPixel(int x, int y, int pixelStride, int bitOffset,
2555: int scanline, DataBuffer db) {
2556:
2557: int type = db.getDataType();
2558: int dataElemSize = DataBuffer.getDataTypeSize(type);
2559: int bitMask = (1 << pixelStride) - 1;
2560: int bitnum = bitOffset + x * pixelStride;
2561: int idx = (y * scanline + bitnum / dataElemSize);
2562: int dataElem = db.getElem(idx);
2563: int shift = dataElemSize - (bitnum & (dataElemSize - 1))
2564: - pixelStride;
2565: return (dataElem >> shift) & bitMask;
2566: }
2567:
2568: private Object getDataElementsB(int x, int y, int width,
2569: int height, int transferType) {
2570: Object de;
2571: int size = width * height;
2572: int idx = 0;
2573: switch (transferType) {
2574: case DataBuffer.TYPE_BYTE:
2575: byte bde[] = new byte[size];
2576: for (int yi = y; yi < y + height; yi++) {
2577: for (int xi = x; xi < x + width; xi++) {
2578: bde[idx++] = byteTestData[yi * w + xi];
2579: }
2580: }
2581: de = bde;
2582: break;
2583: case DataBuffer.TYPE_USHORT:
2584: short sde[] = new short[size];
2585: for (int yi = y; yi < y + height; yi++) {
2586: for (int xi = x; xi < x + width; xi++) {
2587: sde[idx++] = (short) (byteTestData[yi * w + xi] & 0xff);
2588: }
2589: }
2590: de = sde;
2591: break;
2592: case DataBuffer.TYPE_INT:
2593: int ide[] = new int[size];
2594: for (int yi = y; yi < y + height; yi++) {
2595: for (int xi = x; xi < x + width; xi++) {
2596: ide[idx++] = byteTestData[yi * w + xi] & 0xff;
2597: }
2598: }
2599: de = ide;
2600: break;
2601: default:
2602: throw new IllegalArgumentException("Wrong Transfer Type");
2603: }
2604: return de;
2605: }
2606:
2607: private Object getDataElementsUS(int x, int y, int width,
2608: int height, int transferType) {
2609: Object de;
2610: int size = width * height;
2611: int idx = 0;
2612: switch (transferType) {
2613: case DataBuffer.TYPE_BYTE:
2614: byte bde[] = new byte[size];
2615: for (int yi = y; yi < y + height; yi++) {
2616: for (int xi = x; xi < x + width; xi++) {
2617: bde[idx++] = (byte) shortTestData[yi * w + xi];
2618: }
2619: }
2620: de = bde;
2621: break;
2622: case DataBuffer.TYPE_USHORT:
2623: short sde[] = new short[size];
2624: for (int yi = y; yi < y + height; yi++) {
2625: for (int xi = x; xi < x + width; xi++) {
2626: sde[idx++] = shortTestData[yi * w + xi];
2627: }
2628: }
2629: de = sde;
2630: break;
2631: case DataBuffer.TYPE_INT:
2632: int ide[] = new int[size];
2633: for (int yi = y; yi < y + height; yi++) {
2634: for (int xi = x; xi < x + width; xi++) {
2635: ide[idx++] = shortTestData[yi * w + xi] & 0xffff;
2636: }
2637: }
2638: de = ide;
2639: break;
2640: default:
2641: throw new IllegalArgumentException("Wrong Transfer Type");
2642: }
2643: return de;
2644: }
2645:
2646: private Object getDataElementsI(int x, int y, int width,
2647: int height, int transferType) {
2648: Object de;
2649: int size = width * height;
2650: int idx = 0;
2651: switch (transferType) {
2652: case DataBuffer.TYPE_BYTE:
2653: byte bde[] = new byte[size];
2654: for (int yi = y; yi < y + height; yi++) {
2655: for (int xi = x; xi < x + width; xi++) {
2656: bde[idx++] = (byte) intTestData[yi * w + xi];
2657: }
2658: }
2659: de = bde;
2660: break;
2661: case DataBuffer.TYPE_USHORT:
2662: short sde[] = new short[size];
2663: for (int yi = y; yi < y + height; yi++) {
2664: for (int xi = x; xi < x + width; xi++) {
2665: sde[idx++] = (short) intTestData[yi * w + xi];
2666: }
2667: }
2668: de = sde;
2669: break;
2670: case DataBuffer.TYPE_INT:
2671: int ide[] = new int[size];
2672: for (int yi = y; yi < y + height; yi++) {
2673: for (int xi = x; xi < x + width; xi++) {
2674: ide[idx++] = byteTestData[yi * w + xi] & 0xff;
2675: }
2676: }
2677: de = ide;
2678: break;
2679: default:
2680: throw new IllegalArgumentException("Wrong Transfer Type");
2681: }
2682: return de;
2683: }
2684:
2685: private int[] getPixelsB(int x, int y, int width, int height) {
2686: int pixels[] = new int[width * height];
2687: int idx = 0;
2688: for (int yi = y; yi < y + height; yi++) {
2689: for (int xi = x; xi < x + width; xi++) {
2690: pixels[idx++] = byteTestData[yi * w + xi] & 0xff;
2691: }
2692: }
2693: return pixels;
2694: }
2695:
2696: private int[] getPixelsUS(int x, int y, int width, int height) {
2697: int pixels[] = new int[width * height];
2698: int idx = 0;
2699: for (int yi = y; yi < y + height; yi++) {
2700: for (int xi = x; xi < x + width; xi++) {
2701: pixels[idx++] = shortTestData[yi * w + xi] & 0xffff;
2702: }
2703: }
2704: return pixels;
2705: }
2706:
2707: private int[] getPixelsI(int x, int y, int width, int height) {
2708: int pixels[] = new int[width * height];
2709: int idx = 0;
2710: for (int yi = y; yi < y + height; yi++) {
2711: for (int xi = x; xi < x + width; xi++) {
2712: pixels[idx++] = intTestData[yi * w + xi];
2713: }
2714: }
2715: return pixels;
2716: }
2717:
2718: private int[] getSamplesB(int x, int y, int width, int height, int b) {
2719: int samples[] = new int[width * height];
2720: int idx = 0;
2721: for (int y1 = y; y1 < y + height; y1++) {
2722: for (int x1 = x; x1 < x + width; x1++) {
2723: samples[idx++] = byteTestData[y1 * w + x1] & 0xff;
2724: }
2725: }
2726: return samples;
2727: }
2728:
2729: private int[] getSamplesUS(int x, int y, int width, int height,
2730: int b) {
2731: int samples[] = new int[width * height];
2732: int idx = 0;
2733: for (int y1 = y; y1 < y + height; y1++) {
2734: for (int x1 = x; x1 < x + width; x1++) {
2735: samples[idx++] = shortTestData[y1 * w + x1] & 0xffff;
2736: }
2737: }
2738: return samples;
2739: }
2740:
2741: private int[] getSamplesI(int x, int y, int width, int height, int b) {
2742: int samples[] = new int[width * height];
2743: int idx = 0;
2744: for (int y1 = y; y1 < y + height; y1++) {
2745: for (int x1 = x; x1 < x + width; x1++) {
2746: samples[idx++] = intTestData[y1 * w + x1];
2747: }
2748: }
2749: return samples;
2750: }
2751:
2752: private int[] createPixelsFromByteData(int x, int y, int width,
2753: int height) {
2754: int pixels[] = new int[width * height];
2755: int idx = 0;
2756: for (int yi = y; yi < y + height; yi++) {
2757: for (int xi = x; xi < x + width; xi++) {
2758: pixels[idx++] = byteTestData[yi * w + xi] & 0xff;
2759: }
2760: }
2761: return pixels;
2762: }
2763:
2764: private int[] createPixelsFromShortData(int x, int y, int width,
2765: int height) {
2766: int pixels[] = new int[width * height];
2767: int idx = 0;
2768: for (int yi = y; yi < y + height; yi++) {
2769: for (int xi = x; xi < x + width; xi++) {
2770: pixels[idx++] = shortTestData[yi * w + xi] & 0xffff;
2771: }
2772: }
2773: return pixels;
2774: }
2775:
2776: private int[] createPixelsFromIntData(int x, int y, int width,
2777: int height) {
2778: int pixels[] = new int[width * height];
2779: int idx = 0;
2780: for (int yi = y; yi < y + height; yi++) {
2781: for (int xi = x; xi < x + width; xi++) {
2782: pixels[idx++] = intTestData[yi * w + xi];
2783: }
2784: }
2785: return pixels;
2786: }
2787:
2788: private int[] createSamplesFromByteData(int x, int y, int width,
2789: int height, int bank) {
2790: return createPixelsFromByteData(x, y, width, height);
2791: }
2792:
2793: private int[] createSamplesFromShortData(int x, int y, int width,
2794: int height, int bank) {
2795: return createPixelsFromShortData(x, y, width, height);
2796: }
2797:
2798: private int[] createSamplesFromIntData(int x, int y, int width,
2799: int height, int bank) {
2800: return createPixelsFromIntData(x, y, width, height);
2801: }
2802:
2803: }
|