Example usage for java.awt.image DataBufferUShort getData

List of usage examples for java.awt.image DataBufferUShort getData

Introduction

In this page you can find the example usage for java.awt.image DataBufferUShort getData.

Prototype

public short[] getData() 

Source Link

Document

Returns the default (first) unsigned-short data array.

Usage

From source file:org.esa.s2tbx.dataio.s2.S2TileOpImage.java

@Override
protected synchronized void computeRect(PlanarImage[] sources, WritableRaster dest, Rectangle destRect) {
    final DataBufferUShort dataBuffer = (DataBufferUShort) dest.getDataBuffer();
    final short[] tileData = dataBuffer.getData();

    final int tileWidth = this.getTileWidth();
    final int tileHeight = this.getTileHeight();
    final int tileX = destRect.x / tileWidth;
    final int tileY = destRect.y / tileHeight;

    if (tileWidth * tileHeight != tileData.length) {
        throw new IllegalStateException(
                String.format("tileWidth (=%d) * tileHeight (=%d) != tileData.length (=%d)", tileWidth,
                        tileHeight, tileData.length));
    }/*w  w w.  j  a va  2s .c  o  m*/

    final Dimension jp2TileDim = getDimAtResolutionLevel(tileLayout.tileWidth, tileLayout.tileHeight,
            getLevel());

    final int jp2TileWidth = jp2TileDim.width;
    final int jp2TileHeight = jp2TileDim.height;
    final int jp2TileX = destRect.x / jp2TileWidth;
    final int jp2TileY = destRect.y / jp2TileHeight;

    File outputFile = null;
    try {
        outputFile = new File(cacheDir, FileUtils.exchangeExtension(imageFile.getName(),
                String.format("_R%d_TX%d_TY%d.pgx", getLevel(), jp2TileX, jp2TileY)));
    } catch (Exception e) {
        logger.severe(Utils.getStackTrace(e));
    }

    final File outputFile0 = getFirstComponentOutputFile(outputFile);
    // todo - outputFile0 may have already been created, although 'opj_decompress' has not finished execution.
    //        This may be the reason for party filled tiles, that sometimes occur
    if (!outputFile0.exists()) {
        logger.finest(String.format("Jp2ExeImage.readTileData(): recomputing res=%d, tile=(%d,%d)\n",
                getLevel(), jp2TileX, jp2TileY));
        try {
            decompressTile(outputFile, jp2TileX, jp2TileY);
        } catch (IOException e) {
            logger.severe("opj_decompress process failed! :" + Utils.getStackTrace(e));
            if (outputFile0.exists() && !outputFile0.delete()) {
                logger.severe("Failed to delete file: " + outputFile0.getAbsolutePath());
            }
        }
        if (!outputFile0.exists()) {
            Arrays.fill(tileData, S2Config.FILL_CODE_NO_FILE);
            return;
        }
    }

    try {
        logger.finest(String.format("Jp2ExeImage.readTileData(): reading res=%d, tile=(%d,%d)\n", getLevel(),
                jp2TileX, jp2TileY));
        readTileData(outputFile0, tileX, tileY, tileWidth, tileHeight, jp2TileX, jp2TileY, jp2TileWidth,
                jp2TileHeight, tileData, destRect);
    } catch (IOException e) {
        logger.severe("Failed to read uncompressed file data: " + Utils.getStackTrace(e));
    }
}