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

The following examples show how to use java.awt.image.WritableRaster#setRect() . 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: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static WritableRaster renderedImage2DoubleWritableRaster( RenderedImage renderedImage, boolean nullBorders ) {
    int width = renderedImage.getWidth();
    int height = renderedImage.getHeight();

    Raster data = renderedImage.getData();
    WritableRaster writableRaster = createWritableRaster(width, height, Double.class, null, null);
    writableRaster.setRect(data);
    if (nullBorders) {
        for( int c = 0; c < width; c++ ) {
            writableRaster.setSample(c, 0, 0, doubleNovalue);
            writableRaster.setSample(c, height - 1, 0, doubleNovalue);
        }
        for( int r = 0; r < height; r++ ) {
            writableRaster.setSample(0, r, 0, doubleNovalue);
            writableRaster.setSample(width - 1, r, 0, doubleNovalue);
        }
    }
    return writableRaster;
}
 
Example 2
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static WritableRaster renderedImage2IntWritableRaster( RenderedImage renderedImage, boolean nullBorders ) {
    int width = renderedImage.getWidth();
    int height = renderedImage.getHeight();

    Raster data = renderedImage.getData();
    WritableRaster writableRaster = createWritableRaster(width, height, Integer.class, null, null);
    writableRaster.setRect(data);
    if (nullBorders) {
        for( int c = 0; c < width; c++ ) {
            writableRaster.setSample(c, 0, 0, intNovalue);
            writableRaster.setSample(c, height - 1, 0, intNovalue);
        }
        for( int r = 0; r < height; r++ ) {
            writableRaster.setSample(0, r, 0, intNovalue);
            writableRaster.setSample(width - 1, r, 0, intNovalue);
        }
    }
    return writableRaster;
}
 
Example 3
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static WritableRaster renderedImage2ShortWritableRaster( RenderedImage renderedImage, boolean nullBorders ) {
    int width = renderedImage.getWidth();
    int height = renderedImage.getHeight();

    Raster data = renderedImage.getData();
    WritableRaster writableRaster = createWritableRaster(width, height, Short.class, null, null);
    writableRaster.setRect(data);
    if (nullBorders) {
        for( int c = 0; c < width; c++ ) {
            writableRaster.setSample(c, 0, 0, shortNovalue);
            writableRaster.setSample(c, height - 1, 0, shortNovalue);
        }
        for( int r = 0; r < height; r++ ) {
            writableRaster.setSample(0, r, 0, shortNovalue);
            writableRaster.setSample(width - 1, r, 0, shortNovalue);
        }
    }
    return writableRaster;
}
 
Example 4
Source File: TIFFRenderedImage.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public WritableRaster copyData(WritableRaster raster) {
    if (raster == null) {
        return read(new Rectangle(0, 0, getWidth(), getHeight()));
    } else {
        Raster src = read(raster.getBounds());
        raster.setRect(src);
        return raster;
    }
}
 
Example 5
Source File: TIFFRenderedImage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public WritableRaster copyData(WritableRaster raster) {
    if (raster == null) {
        return read(new Rectangle(0, 0, getWidth(), getHeight()));
    } else {
        Raster src = read(raster.getBounds());
        raster.setRect(src);
        return raster;
    }
}
 
Example 6
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 7
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;
}