/** Superclass getRaster... */
  public final Raster getRaster(int x, int y, int w, int h) {
    if (w == 0 || h == 0) {
      return null;
    }

    //
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    //
    WritableRaster raster = saved;
    if (raster == null || raster.getWidth() < w || raster.getHeight() < h) {
      raster = getCachedRaster(dataModel, w, h);
      saved = raster;
    }

    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    //
    DataBufferInt rasterDB = (DataBufferInt) raster.getDataBuffer();
    int[] pixels = rasterDB.getBankData()[0];
    int off = rasterDB.getOffset();
    int scanlineStride =
        ((SinglePixelPackedSampleModel) raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;

    fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass.

    GraphicsUtil.coerceData(raster, dataModel, model.isAlphaPremultiplied());

    return raster;
  }
示例#2
0
  protected static void mult_INT_PACK_Data(WritableRaster wr) {
    // System.out.println("Multiply Int: " + wr);

    SinglePixelPackedSampleModel sppsm;
    sppsm = (SinglePixelPackedSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = sppsm.getScanlineStride();
    DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
    final int base =
        (db.getOffset()
            + sppsm.getOffset(
                wr.getMinX() - wr.getSampleModelTranslateX(),
                wr.getMinY() - wr.getSampleModelTranslateY()));
    // Access the pixel data array
    final int pixels[] = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
      int sp = base + y * scanStride;
      final int end = sp + width;
      while (sp < end) {
        int pixel = pixels[sp];
        int a = pixel >>> 24;
        if ((a >= 0) && (a < 255)) {
          pixels[sp] =
              ((a << 24)
                  | ((((pixel & 0xFF0000) * a) >> 8) & 0xFF0000)
                  | ((((pixel & 0x00FF00) * a) >> 8) & 0x00FF00)
                  | ((((pixel & 0x0000FF) * a) >> 8) & 0x0000FF));
        }
        sp++;
      }
    }
  }
  /**
   * Constructs a IntegerComponentRaster with the given SampleModel, DataBuffer, and parent.
   * DataBuffer must be a DataBufferInt and SampleModel must be of type
   * SinglePixelPackedSampleModel. When translated into the base Raster's coordinate system, aRegion
   * must be contained by the base Raster. Origin is the coodinate in the new Raster's coordinate
   * system of the origin of the base Raster. (The base Raster is the Raster's ancestor which has no
   * parent.)
   *
   * <p>Note that this constructor should generally be called by other constructors or create
   * methods, it should not be used directly.
   *
   * @param sampleModel The SampleModel that specifies the layout.
   * @param dataBuffer The DataBufferInt that contains the image data.
   * @param aRegion The Rectangle that specifies the image area.
   * @param origin The Point that specifies the origin.
   * @param parent The parent (if any) of this raster.
   */
  public IntegerComponentRaster(
      SampleModel sampleModel,
      DataBuffer dataBuffer,
      Rectangle aRegion,
      Point origin,
      IntegerComponentRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
      throw new RasterFormatException("IntegerComponentRasters must have" + "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt) dataBuffer;
    if (dbi.getNumBanks() != 1) {
      throw new RasterFormatException(
          "DataBuffer for IntegerComponentRasters" + " must only have 1 bank.");
    }
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
      SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sampleModel;
      int[] boffsets = sppsm.getBitOffsets();
      boolean notByteBoundary = false;
      for (int i = 1; i < boffsets.length; i++) {
        if ((boffsets[i] % 8) != 0) {
          notByteBoundary = true;
        }
      }
      this.type =
          (notByteBoundary
              ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
              : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

      this.scanlineStride = sppsm.getScanlineStride();
      this.pixelStride = 1;
      this.dataOffsets = new int[1];
      this.dataOffsets[0] = dbi.getOffset();
      this.bandOffset = this.dataOffsets[0];
      int xOffset = aRegion.x - origin.x;
      int yOffset = aRegion.y - origin.y;
      dataOffsets[0] += xOffset + yOffset * scanlineStride;
      this.numDataElems = sppsm.getNumDataElements();
    } else {
      throw new RasterFormatException(
          "IntegerComponentRasters must have" + " SinglePixelPackedSampleModel");
    }

    verify();
  }
示例#4
0
    public ZeroRecter_INT_PACK(WritableRaster wr) {
      super(wr);

      SinglePixelPackedSampleModel sppsm;
      sppsm = (SinglePixelPackedSampleModel) wr.getSampleModel();

      scanStride = sppsm.getScanlineStride();
      DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
      x0 = wr.getMinY();
      y0 = wr.getMinX();
      base =
          (db.getOffset()
              + sppsm.getOffset(
                  x0 - wr.getSampleModelTranslateX(), y0 - wr.getSampleModelTranslateY()));

      pixels = db.getBankData()[0];
      if (wr.getWidth() > 10) zeros = new int[wr.getWidth()];
      else zeros = null;
    }
示例#5
0
  protected static void divide_INT_PACK_Data(WritableRaster wr) {
    // System.out.println("Divide Int");

    SinglePixelPackedSampleModel sppsm;
    sppsm = (SinglePixelPackedSampleModel) wr.getSampleModel();

    final int width = wr.getWidth();

    final int scanStride = sppsm.getScanlineStride();
    DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
    final int base =
        (db.getOffset()
            + sppsm.getOffset(
                wr.getMinX() - wr.getSampleModelTranslateX(),
                wr.getMinY() - wr.getSampleModelTranslateY()));
    int pixel, a, aFP;
    // Access the pixel data array
    final int pixels[] = db.getBankData()[0];
    for (int y = 0; y < wr.getHeight(); y++) {
      int sp = base + y * scanStride;
      final int end = sp + width;
      while (sp < end) {
        pixel = pixels[sp];
        a = pixel >>> 24;
        if (a <= 0) {
          pixels[sp] = 0x00FFFFFF;
        } else if (a < 255) {
          aFP = (0x00FF0000 / a);
          pixels[sp] =
              ((a << 24)
                  | (((((pixel & 0xFF0000) >> 16) * aFP) & 0xFF0000))
                  | (((((pixel & 0x00FF00) >> 8) * aFP) & 0xFF0000) >> 8)
                  | (((((pixel & 0x0000FF)) * aFP) & 0xFF0000) >> 16));
        }
        sp++;
      }
    }
  }
 /*     */ public final Raster getRaster(
     int paramInt1, int paramInt2, int paramInt3, int paramInt4)
       /*     */ {
   /* 618 */ Raster localRaster = this.saved;
   /* 619 */ if ((localRaster == null)
       || (localRaster.getWidth() < paramInt3)
       || (localRaster.getHeight() < paramInt4))
   /*     */ {
     /* 622 */ localRaster = getCachedRaster(this.model, paramInt3, paramInt4);
     /* 623 */ this.saved = localRaster;
     /*     */ }
   /*     */
   /* 633 */ DataBufferInt localDataBufferInt = (DataBufferInt) localRaster.getDataBuffer();
   /* 634 */ int[] arrayOfInt = localDataBufferInt.getData(0);
   /* 635 */ int i = localDataBufferInt.getOffset();
   /* 636 */ int j =
       ((SinglePixelPackedSampleModel) localRaster.getSampleModel()).getScanlineStride();
   /*     */
   /* 638 */ int k = j - paramInt3;
   /*     */
   /* 640 */ fillRaster(arrayOfInt, i, k, paramInt1, paramInt2, paramInt3, paramInt4);
   /*     */
   /* 642 */ return localRaster;
   /*     */ }
 public void attachBuffer(int type, BufferedImage img) {
   DataBufferInt db = (DataBufferInt) img.getRaster().getDataBuffer();
   int stride =
       ((SinglePixelPackedSampleModel) img.getRaster().getSampleModel()).getScanlineStride();
   attachBuffer(type, db.getData(), db.getOffset(), stride);
 }
示例#8
0
  private WritableRaster boxFilterV(
      Raster src, WritableRaster dest, int skipX, int skipY, int boxSz, int loc) {

    final int w = src.getWidth();
    final int h = src.getHeight();

    // Check if the raster is wide enough to do _any_ work
    if (w < (2 * skipX)) return dest;
    if (h < (2 * skipY) + boxSz) return dest;

    final SinglePixelPackedSampleModel srcSPPSM =
        (SinglePixelPackedSampleModel) src.getSampleModel();

    final SinglePixelPackedSampleModel dstSPPSM =
        (SinglePixelPackedSampleModel) dest.getSampleModel();

    // Stride is the distance between two consecutive column elements,
    // in the one-dimention dataBuffer
    final int srcScanStride = srcSPPSM.getScanlineStride();
    final int dstScanStride = dstSPPSM.getScanlineStride();

    // Access the integer buffer for each image.
    DataBufferInt srcDB = (DataBufferInt) src.getDataBuffer();
    DataBufferInt dstDB = (DataBufferInt) dest.getDataBuffer();

    // Offset defines where in the stack the real data begin
    final int srcOff =
        (srcDB.getOffset()
            + srcSPPSM.getOffset(
                src.getMinX() - src.getSampleModelTranslateX(),
                src.getMinY() - src.getSampleModelTranslateY()));
    final int dstOff =
        (dstDB.getOffset()
            + dstSPPSM.getOffset(
                dest.getMinX() - dest.getSampleModelTranslateX(),
                dest.getMinY() - dest.getSampleModelTranslateY()));

    // Access the pixel value array
    final int[] srcPixels = srcDB.getBankData()[0];
    final int[] destPixels = dstDB.getBankData()[0];

    final int[] buffer = new int[boxSz];
    int curr, prev;

    // Fixed point normalization factor (8.24)
    final int scale = (1 << 24) / boxSz;

    /*
     * System.out.println("Info: srcOff: " + srcOff +
     *                    " x: " + skipX +
     *                    " y: " + skipY +
     *                    " w: " + w +
     *                    " h: " + h +
     *                    " boxSz " + boxSz +
     *                    " srcStride: " + srcScanStride);
     */

    for (int x = skipX; x < (w - skipX); x++) {
      int sp = srcOff + x;
      int dp = dstOff + x;
      int colEnd = sp + (h - skipY) * srcScanStride;

      int k = 0;
      int sumA = 0;
      int sumR = 0;
      int sumG = 0;
      int sumB = 0;

      sp += skipY * srcScanStride;
      int end = sp + (boxSz * srcScanStride);

      while (sp < end) {
        curr = buffer[k] = srcPixels[sp];
        sumA += (curr >>> 24);
        sumR += (curr >> 16) & 0xFF;
        sumG += (curr >> 8) & 0xFF;
        sumB += (curr) & 0xFF;
        k++;
        sp += srcScanStride;
      }

      dp += (skipY + loc) * dstScanStride;
      prev =
          destPixels[dp] =
              (((sumA * scale) & 0xFF000000)
                  | (((sumR * scale) & 0xFF000000) >>> 8)
                  | (((sumG * scale) & 0xFF000000) >>> 16)
                  | (((sumB * scale) & 0xFF000000) >>> 24));
      dp += dstScanStride;
      k = 0;
      while (sp < colEnd) {
        curr = buffer[k];
        if (curr == srcPixels[sp]) {
          destPixels[dp] = prev;
        } else {
          sumA -= (curr >>> 24);
          sumR -= (curr >> 16) & 0xFF;
          sumG -= (curr >> 8) & 0xFF;
          sumB -= (curr) & 0xFF;

          curr = buffer[k] = srcPixels[sp];

          sumA += (curr >>> 24);
          sumR += (curr >> 16) & 0xFF;
          sumG += (curr >> 8) & 0xFF;
          sumB += (curr) & 0xFF;
          prev =
              destPixels[dp] =
                  (((sumA * scale) & 0xFF000000)
                      | (((sumR * scale) & 0xFF000000) >>> 8)
                      | (((sumG * scale) & 0xFF000000) >>> 16)
                      | (((sumB * scale) & 0xFF000000) >>> 24));
        }
        k = (k + 1) % boxSz;
        sp += srcScanStride;
        dp += dstScanStride;
      }
    }
    return dest;
  }