Java Code Examples for java.awt.image.RenderedImage#getMinTileY()

The following examples show how to use java.awt.image.RenderedImage#getMinTileY() . 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: WritablePixelIterator.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an iterator for the given region in the given image.
 *
 * @param  input    the image which contains the sample values to read.
 * @param  output   the image where to write the sample values, or {@code null} for read-only iterator.
 * @param  subArea  the image region where to perform the iteration, or {@code null}
 *                  for iterating over all the image domain.
 * @param  window   size of the window to use in {@link #createWindow(TransferType)} method, or {@code null} if none.
 */
WritablePixelIterator(final RenderedImage input, final WritableRenderedImage output,
                      final Rectangle subArea, final Dimension window)
{
    super(input, subArea, window);
    destRaster  = null;
    destination = output;
    if (output != null) {
        if (!input.getSampleModel().equals(output.getSampleModel())) {
            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedSampleModel));
        } else if (input.getMinX()   != output.getMinX()  ||
                   input.getMinY()   != output.getMinY()  ||
                   input.getWidth()  != output.getWidth() ||
                   input.getHeight() != output.getHeight())
        {
            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedImageLocation));
        } else if (input.getMinTileX()   != output.getMinTileX()  ||
                   input.getMinTileY()   != output.getMinTileY()  ||
                   input.getTileWidth()  != output.getTileWidth() ||
                   input.getTileHeight() != output.getTileHeight())
        {
            throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedTileGrid));
        }
    }
}
 
Example 2
Source File: ExportMaskPixelsAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static long getNumMaskPixels(final RenderedImage maskImage, int sceneRasterWidth, int sceneRasterHeight) {
    final int minTileX = maskImage.getMinTileX();
    final int minTileY = maskImage.getMinTileY();

    final int numXTiles = maskImage.getNumXTiles();
    final int numYTiles = maskImage.getNumYTiles();

    final Rectangle imageRect = new Rectangle(0, 0, sceneRasterWidth, sceneRasterHeight);

    long numMaskPixels = 0;
    for (int tileX = minTileX; tileX < minTileX + numXTiles; ++tileX) {
        for (int tileY = minTileY; tileY < minTileY + numYTiles; ++tileY) {
            final Rectangle tileRectangle = new Rectangle(maskImage.getTileGridXOffset() + tileX * maskImage.getTileWidth(),
                                                          maskImage.getTileGridYOffset() + tileY * maskImage.getTileHeight(),
                                                          maskImage.getTileWidth(), maskImage.getTileHeight());

            final Rectangle r = imageRect.intersection(tileRectangle);
            if (!r.isEmpty()) {
                Raster maskTile = maskImage.getTile(tileX, tileY);
                for (int y = r.y; y < r.y + r.height; y++) {
                    for (int x = r.x; x < r.x + r.width; x++) {
                        if (maskTile.getSample(x, y, 0) != 0) {
                            numMaskPixels++;
                        }
                    }
                }
            }
        }
    }
    return numMaskPixels;
}
 
Example 3
Source File: MaskFormActions.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private Rectangle2D handleImageMask(Mask mask, AffineTransform i2m) {
    RenderedImage image = mask.getSourceImage().getImage(0);
    final int minTileX = image.getMinTileX();
    final int minTileY = image.getMinTileY();
    final int numXTiles = image.getNumXTiles();
    final int numYTiles = image.getNumYTiles();
    final int width = image.getWidth();
    final int height = image.getHeight();
    int minX = width;
    int maxX = 0;
    int minY = height;
    int maxY = 0;

    for (int tileX = minTileX; tileX < minTileX + numXTiles; ++tileX) {
        for (int tileY = minTileY; tileY < minTileY + numYTiles; ++tileY) {
            final Raster data = image.getTile(tileX, tileY);
            for (int x = data.getMinX(); x < data.getMinX() + data.getWidth(); x++) {
                for (int y = data.getMinY(); y < data.getMinY() + data.getHeight(); y++) {
                    if (data.getSample(x, y, 0) != 0) {
                        minX = Math.min(x, minX);
                        maxX = Math.max(x, maxX);
                        minY = Math.min(y, minY);
                        maxY = Math.max(y, maxY);
                    }
                }
            }
        }
    }
    Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
    if (rect.isEmpty()) {
        return null;
    } else {
        return i2m.createTransformedShape(rect).getBounds2D();
    }
}
 
Example 4
Source File: ExportMaskPixelsAction.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Writes all pixel values of the given product within the given Mask to the specified out.
 *
 * @param out      the data output writer
 * @param product  the product providing the pixel values
 * @param maskName the mask name
 * @param mustCreateHeader
 * @param mustExportTiePoints
 * @param mustExportWavelengthsAndSF
 * @param pm       progress monitor
 * @return <code>true</code> for success, <code>false</code> if export has been terminated (by user)
 */
private static boolean exportMaskPixels(final PrintWriter out,
                                        final Product product,
                                        String maskName,
                                        boolean mustCreateHeader,
                                        boolean mustExportTiePoints,
                                        boolean mustExportWavelengthsAndSF,
                                        ProgressMonitor pm) throws IOException {

    final RenderedImage maskImage = product.getMaskGroup().get(maskName).getSourceImage();

    final int minTileX = maskImage.getMinTileX();
    final int minTileY = maskImage.getMinTileY();

    final int numXTiles = maskImage.getNumXTiles();
    final int numYTiles = maskImage.getNumYTiles();

    final int w = product.getSceneRasterWidth();
    final int h = product.getSceneRasterHeight();

    final Rectangle imageRect = new Rectangle(0, 0, w, h);

    pm.beginTask("Writing pixel data...", numXTiles * numYTiles + 2);
    try {
        if (mustCreateHeader) {
            createHeader(out, product, maskName, mustExportWavelengthsAndSF);
        }
        pm.worked(1);
        writeColumnNames(out, product, maskName, mustExportTiePoints);
        pm.worked(1);

        for (int tileX = minTileX; tileX < minTileX + numXTiles; ++tileX) {
            for (int tileY = minTileY; tileY < minTileY + numYTiles; ++tileY) {
                if (pm.isCanceled()) {
                    return false;
                }
                final Rectangle tileRectangle = new Rectangle(maskImage.getTileGridXOffset() + tileX * maskImage.getTileWidth(),
                                                              maskImage.getTileGridYOffset() + tileY * maskImage.getTileHeight(),
                                                              maskImage.getTileWidth(), maskImage.getTileHeight());

                final Rectangle r = imageRect.intersection(tileRectangle);
                if (!r.isEmpty()) {
                    Raster maskTile = maskImage.getTile(tileX, tileY);
                    for (int y = r.y; y < r.y + r.height; y++) {
                        for (int x = r.x; x < r.x + r.width; x++) {
                            if (maskTile.getSample(x, y, 0) != 0) {
                                writeDataLine(out, product, maskName, x, y, mustExportTiePoints);
                            }
                        }
                    }
                }
                pm.worked(1);
            }
        }
    } finally {
        pm.done();
    }

    return true;
}