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

The following examples show how to use java.awt.image.RenderedImage#getTileGridYOffset() . 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: J2KImageWriteParamJava.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
/** Set source */
private void setDefaults(RenderedImage imgsrc) {
    // override the params in the super class
    setSuperProperties();

    tilingMode = MODE_EXPLICIT;

    if (imgsrc != null) {
        this.imgsrc = imgsrc;
        tileGridXOffset = imgsrc.getTileGridXOffset();
        tileGridYOffset = imgsrc.getTileGridYOffset();
        tileWidth = imgsrc.getTileWidth();
        tileHeight = imgsrc.getTileHeight();
        tilingSet = true;

        numTiles = imgsrc.getNumXTiles() * imgsrc.getNumYTiles();
        numComponents = imgsrc.getSampleModel().getNumBands();
    }
    setDefaults();
}
 
Example 2
Source File: PixelIterator.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  data     the image which contains the sample values on which to iterate.
 * @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.
 */
PixelIterator(final RenderedImage data, final Rectangle subArea, final Dimension window) {
    final Rectangle bounds;
    image           = data;
    numBands        = data.getSampleModel().getNumBands();
    tileWidth       = data.getTileWidth();
    tileHeight      = data.getTileHeight();
    tileGridXOffset = data.getTileGridXOffset();
    tileGridYOffset = data.getTileGridYOffset();
    bounds          = intersection(data.getMinX(), data.getMinY(), data.getWidth(), data.getHeight(), subArea, window);
    lowerX          = bounds.x;
    lowerY          = bounds.y;
    upperX          = Math.addExact(lowerX, bounds.width);
    upperY          = Math.addExact(lowerY, bounds.height);
    tileLowerX      = floorDiv(Math.subtractExact(lowerX, tileGridXOffset), tileWidth);
    tileLowerY      = floorDiv(Math.subtractExact(lowerY, tileGridYOffset), tileHeight);
    tileUpperX      =  ceilDiv(Math.subtractExact(upperX, tileGridXOffset), tileWidth);
    tileUpperY      =  ceilDiv(Math.subtractExact(upperY, tileGridYOffset), tileHeight);
    windowWidth     = (window != null) ? window.width  : 0;
    windowHeight    = (window != null) ? window.height : 0;
}
 
Example 3
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 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;
}