Java Code Examples for java.awt.image.WritableRaster#getBounds()

The following examples show how to use java.awt.image.WritableRaster#getBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DIBCodec.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public void readKey8(byte[] in, int offset, int length, BufferedImage img) {
    DataBufferByte buf = (DataBufferByte) img.getRaster().getDataBuffer();
    WritableRaster raster = img.getRaster();
    int scanlineStride = raster.getSampleModel().getWidth();
    Rectangle r = raster.getBounds();
    r.x -= raster.getSampleModelTranslateX();
    r.y -= raster.getSampleModelTranslateY();
    
    int h=img.getHeight();
    int w=img.getWidth();
    int i=offset;
    int j=r.x+r.y*scanlineStride+(h-1)*scanlineStride;
    byte[] out=buf.getData();
    for (int y=0;y<h;y++) {
        System.arraycopy(in,i,out,j,w);
        i+=w;
        j-=scanlineStride;
    }
}
 
Example 2
Source File: DIBCodec.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public void readKey24(int[] in, int offset, int length, BufferedImage img) {
    DataBufferInt buf = (DataBufferInt) img.getRaster().getDataBuffer();
    WritableRaster raster = img.getRaster();
    int scanlineStride = raster.getSampleModel().getWidth();
    Rectangle r = raster.getBounds();
    r.x -= raster.getSampleModelTranslateX();
    r.y -= raster.getSampleModelTranslateY();
    
    int h=img.getHeight();
    int w=img.getWidth();
    int i=offset;
    int j=r.x+r.y*scanlineStride+(h-1)*scanlineStride;
    int[] out=buf.getData();
    for (int y=0;y<h;y++) {
        System.arraycopy(in,i,out,j,w);
        i+=w;
        j-=scanlineStride;
    }
}
 
Example 3
Source File: SimpleRenderedImage.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Copies an arbitrary rectangular region of the RenderedImage into a
 * caller-supplied WritableRaster. The region to be computed is determined by
 * clipping the bounds of the supplied WritableRaster against the bounds of
 * the image. The supplied WritableRaster must have a SampleModel that is
 * compatible with that of the image.
 * 
 * <p>
 * If the raster argument is null, the entire image will be copied into a
 * newly-created WritableRaster with a SampleModel that is compatible with
 * that of the image.
 * 
 * @param dest
 *          a WritableRaster to hold the returned portion of the image.
 * @return a reference to the supplied WritableRaster, or to a new
 *         WritableRaster if the supplied one was null.
 */
@Override
public WritableRaster copyData(WritableRaster dest) {
  Rectangle bounds;
  Raster tile;

  if (dest == null) {
    bounds = getBounds();
    Point p = new Point(minX, minY);
    /* A SampleModel to hold the entire image. */
    SampleModel sm = sampleModel.createCompatibleSampleModel(width, height);
    dest = Raster.createWritableRaster(sm, p);
  } else {
    bounds = dest.getBounds();
  }

  int startX = XToTileX(bounds.x);
  int startY = YToTileY(bounds.y);
  int endX = XToTileX(bounds.x + bounds.width - 1);
  int endY = YToTileY(bounds.y + bounds.height - 1);

  for (int j = startY; j <= endY; j++) {
    for (int i = startX; i <= endX; i++) {
      tile = getTile(i, j);
      Rectangle intersectRect = bounds.intersection(tile.getBounds());
      Raster liveRaster = tile.createChild(intersectRect.x, intersectRect.y, intersectRect.width,
          intersectRect.height, intersectRect.x, intersectRect.y, null);

      /*
       * WritableRaster.setDataElements takes into account of inRaster's minX
       * and minY and add these to x and y. Since liveRaster has the origin at
       * the correct location, the following call should not again give these
       * coordinates in places of x and y.
       */
      dest.setDataElements(0, 0, liveRaster);
    }
  }
  return dest;
}
 
Example 4
Source File: DIBCodec.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public void readKey4(byte[] in, int offset, int length, BufferedImage img) {
    DataBufferByte buf = (DataBufferByte) img.getRaster().getDataBuffer();
    WritableRaster raster = img.getRaster();
    int scanlineStride = raster.getSampleModel().getWidth();
    Rectangle r = raster.getBounds();
    r.x -= raster.getSampleModelTranslateX();
    r.y -= raster.getSampleModelTranslateY();
    
    throw new UnsupportedOperationException("readKey4 not yet implemented");
}
 
Example 5
Source File: SimpleRenderedImage.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}
 
Example 6
Source File: SimpleRenderedImage.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}