public WritableRaster makeRaster(int w, int h) {
   WritableRaster ras = makeRaster(colorModel, srcRas, w, h);
   IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster) ras;
   outData = iiRas.getDataStorage();
   outSpan = iiRas.getScanlineStride();
   outOff = iiRas.getDataOffset(0);
   return ras;
 }
 public WritableRaster makeRaster(int w, int h) {
   // Note that we do not pass srcRas to makeRaster since it
   // is a Byte Raster and this colorModel needs an Int Raster
   WritableRaster ras = makeRaster(colorModel, null, w, h);
   IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster) ras;
   outData = iiRas.getDataStorage();
   outSpan = iiRas.getScanlineStride();
   outOff = iiRas.getDataOffset(0);
   return ras;
 }
 public Int(
     IntegerInterleavedRaster srcRas,
     ColorModel cm,
     AffineTransform xform,
     int maxw,
     boolean filter) {
   super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
   this.srcRas = srcRas;
   this.inData = srcRas.getDataStorage();
   this.inSpan = srcRas.getScanlineStride();
   this.inOff = srcRas.getDataOffset(0);
   this.filter = filter;
 }
  public static void checkEquals(WritableRaster imgA, MultiSpectral imgB, float tol) {

    if (imgA.getNumBands() != imgB.getNumBands()) {
      throw new RuntimeException("Number of bands not equals");
    }

    if (imgA instanceof ByteInterleavedRaster) {
      ByteInterleavedRaster raster = (ByteInterleavedRaster) imgA;

      byte dataA[] = raster.getDataStorage();
      int strideA = raster.getScanlineStride();
      int offsetA = raster.getDataOffset(0) - raster.getPixelStride() + 1;

      // handle a special case where the RGB conversion is screwed
      for (int y = 0; y < imgA.getHeight(); y++) {
        int indexA = offsetA + strideA * y;

        for (int x = 0; x < imgA.getWidth(); x++) {
          for (int k = 0; k < imgB.getNumBands(); k++) {
            int valueA = dataA[indexA++] & 0xFF;
            double valueB = GeneralizedImageOps.get(imgB.getBand(k), x, y);
            if (Math.abs(valueA - valueB) > tol)
              throw new RuntimeException("Images are not equal: A = " + valueA + " B = " + valueB);
          }
        }
      }

    } else if (imgA instanceof IntegerInterleavedRaster) {
      IntegerInterleavedRaster raster = (IntegerInterleavedRaster) imgA;

      int dataA[] = raster.getDataStorage();
      int strideA = raster.getScanlineStride();
      int offsetA = raster.getDataOffset(0) - raster.getPixelStride() + 1;

      // handle a special case where the RGB conversion is screwed
      for (int y = 0; y < imgA.getHeight(); y++) {
        int indexA = offsetA + strideA * y;

        for (int x = 0; x < imgA.getWidth(); x++) {
          int valueA = dataA[indexA++];
          if (imgB.getNumBands() == 4) {
            int found0 = (valueA >> 24) & 0xFF;
            int found1 = (valueA >> 16) & 0xFF;
            int found2 = (valueA >> 8) & 0xFF;
            int found3 = valueA & 0xFF;

            double expected0 = GeneralizedImageOps.get(imgB.getBand(0), x, y);
            double expected1 = GeneralizedImageOps.get(imgB.getBand(1), x, y);
            double expected2 = GeneralizedImageOps.get(imgB.getBand(2), x, y);
            double expected3 = GeneralizedImageOps.get(imgB.getBand(3), x, y);

            if (Math.abs(found0 - expected0) > tol)
              throw new RuntimeException("Images are not equal");
            if (Math.abs(found1 - expected1) > tol)
              throw new RuntimeException("Images are not equal");
            if (Math.abs(found2 - expected2) > tol)
              throw new RuntimeException("Images are not equal");
            if (Math.abs(found3 - expected3) > tol)
              throw new RuntimeException("Images are not equal");
          } else if (imgB.getNumBands() == 3) {
            int found0 = (valueA >> 16) & 0xFF;
            int found1 = (valueA >> 8) & 0xFF;
            int found2 = valueA & 0xFF;

            double expected0 = GeneralizedImageOps.get(imgB.getBand(0), x, y);
            double expected1 = GeneralizedImageOps.get(imgB.getBand(1), x, y);
            double expected2 = GeneralizedImageOps.get(imgB.getBand(2), x, y);

            if (Math.abs(found0 - expected0) > tol)
              throw new RuntimeException("Images are not equal");
            if (Math.abs(found1 - expected1) > tol)
              throw new RuntimeException("Images are not equal");
            if (Math.abs(found2 - expected2) > tol)
              throw new RuntimeException("Images are not equal");
          } else {
            throw new RuntimeException("Unexpectd number of bands");
          }
        }
      }
    } else {
      throw new RuntimeException("Add support for raster type " + imgA.getClass().getSimpleName());
    }
  }