public static PaintContext getContext(
     BufferedImage bufImg, AffineTransform xform, RenderingHints hints, Rectangle devBounds) {
   WritableRaster raster = bufImg.getRaster();
   ColorModel cm = bufImg.getColorModel();
   int maxw = devBounds.width;
   Object val = hints.get(hints.KEY_INTERPOLATION);
   boolean filter =
       (val == null
           ? (hints.get(hints.KEY_RENDERING) == hints.VALUE_RENDER_QUALITY)
           : (val != hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
   if (raster instanceof IntegerInterleavedRaster && (!filter || isFilterableDCM(cm))) {
     IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
     if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
       return new Int(iir, cm, xform, maxw, filter);
     }
   } else if (raster instanceof ByteInterleavedRaster) {
     ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
     if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
       if (filter) {
         if (isFilterableICM(cm)) {
           return new ByteFilter(bir, cm, xform, maxw);
         }
       } else {
         return new Byte(bir, cm, xform, maxw);
       }
     }
   }
   return new Any(raster, cm, xform, maxw, filter);
 }
 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;
 }
  private static void renderLabeled(
      GrayS32 labelImage, int[] colors, IntegerInterleavedRaster raster) {
    int rasterIndex = 0;
    int data[] = raster.getDataStorage();

    int w = labelImage.getWidth();
    int h = labelImage.getHeight();

    for (int y = 0; y < h; y++) {
      int indexSrc = labelImage.startIndex + y * labelImage.stride;
      for (int x = 0; x < w; x++) {
        data[rasterIndex++] = colors[labelImage.data[indexSrc++]];
      }
    }
  }
  private static void renderBinary(
      GrayU8 binaryImage, boolean invert, IntegerInterleavedRaster raster) {
    int rasterIndex = 0;
    int data[] = raster.getDataStorage();

    int w = binaryImage.getWidth();
    int h = binaryImage.getHeight();

    if (invert) {
      for (int y = 0; y < h; y++) {
        int indexSrc = binaryImage.startIndex + y * binaryImage.stride;
        for (int x = 0; x < w; x++) {
          data[rasterIndex++] = binaryImage.data[indexSrc++] > 0 ? 0 : 0xFFFFFFFF;
        }
      }
    } else {
      for (int y = 0; y < h; y++) {
        int indexSrc = binaryImage.startIndex + y * binaryImage.stride;
        for (int x = 0; x < w; x++) {
          data[rasterIndex++] = binaryImage.data[indexSrc++] > 0 ? 0xFFFFFFFF : 0;
        }
      }
    }
  }
Ejemplo n.º 7
0
  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());
    }
  }