Search in sources :

Example 1 with RasterAccessor

use of javax.media.jai.RasterAccessor in project geowave by locationtech.

the class WarpOpImage method computeRect.

/**
 * Warps a rectangle. If ROI is present, the intersection between ROI and tile bounds is
 * calculated; The result ROI will be used for calculations inside the computeRect() method.
 */
@Override
protected void computeRect(final PlanarImage[] sources, final WritableRaster dest, final Rectangle destRect) {
    // Retrieve format tags.
    final RasterFormatTag[] formatTags = getFormatTags();
    final RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
    RandomIter roiIter = null;
    boolean roiContainsTile = false;
    boolean roiDisjointTile = false;
    // tile bounds is taken.
    if (hasROI) {
        final Rectangle srcRectExpanded = mapDestRect(destRect, 0);
        // The tile dimension is extended for avoiding border errors
        srcRectExpanded.setRect(srcRectExpanded.getMinX() - leftPad, srcRectExpanded.getMinY() - topPad, srcRectExpanded.getWidth() + rightPad + leftPad, srcRectExpanded.getHeight() + bottomPad + topPad);
        if (!roiBounds.intersects(srcRectExpanded)) {
            roiDisjointTile = true;
        } else {
            roiContainsTile = roi.contains(srcRectExpanded);
            if (!roiContainsTile) {
                if (!roi.intersects(srcRectExpanded)) {
                    roiDisjointTile = true;
                } else {
                    final PlanarImage roiIMG = getImage();
                    roiIter = RandomIterFactory.create(roiIMG, null, TILE_CACHED, ARRAY_CALC);
                }
            }
        }
    }
    if (!hasROI || !roiDisjointTile) {
        switch(dst.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                computeRectByte(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_USHORT:
                computeRectUShort(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_SHORT:
                computeRectShort(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_INT:
                computeRectInt(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_FLOAT:
                computeRectFloat(sources[0], dst, roiIter, roiContainsTile);
                break;
            case DataBuffer.TYPE_DOUBLE:
                computeRectDouble(sources[0], dst, roiIter, roiContainsTile);
                break;
        }
        // WritableRaster
        if (dst.isDataCopy()) {
            dst.clampDataArrays();
            dst.copyDataToRaster();
        }
    } else {
        // set to backgroundValues
        if (setBackground) {
            ImageUtil.fillBackground(dest, destRect, backgroundValues);
        }
    }
}
Also used : RasterFormatTag(javax.media.jai.RasterFormatTag) Rectangle(java.awt.Rectangle) RandomIter(javax.media.jai.iterator.RandomIter) PlanarImage(javax.media.jai.PlanarImage) RasterAccessor(javax.media.jai.RasterAccessor)

Aggregations

Rectangle (java.awt.Rectangle)1 PlanarImage (javax.media.jai.PlanarImage)1 RasterAccessor (javax.media.jai.RasterAccessor)1 RasterFormatTag (javax.media.jai.RasterFormatTag)1 RandomIter (javax.media.jai.iterator.RandomIter)1