/** * Calculates the position of a pixel in the ByteBuffer. * * This method calculates the position of a pixel and returns the offset to this pixel in bytes. Use this method for * direct access to ByteBuffers. * * @param x * x coordinate * @param y * y coordinate * @return byte offset to the pixel with the specified coordinate or -1 if outside of the bytebuffer. */ public final int calculatePos( int x, int y ) { return dataAccess.calculatePos( x, y ); }
/** * Calculates the position of a pixel in a view (FloatBuffer, etc.) of the ByteBuffer. * * This method considers different sample sizes (eg. byte, float) and returns the position in sample strides (not * byte strides). Use this method to get proper positions for ByteBuffer views like FloatBuffer, ShortBuffer, etc.. * * @param x * x coordinate * @param y * y coordinate * @return offset to the pixel with the specified coordinates or -1 if outside of the bytebuffer. */ public final int calculateViewPos( int x, int y ) { return dataAccess.calculateViewPos( x, y ); }
/** * @param newData * to use. * @param dataRect * defining the width, height and offset for the data. */ void setByteBuffer( ByteBuffer newData, RasterRect dataRect ) { synchronized ( LOCK ) { if ( newData != null ) { if ( dataRect != null ) { createMaxView( dataRect ); } if ( newData.capacity() < requiredBufferSize() ) { // System.out.println( "required: " + requiredBufferSize() ); // System.out.println( "size: " + newData.capacity() ); LOG.error( "The given byteBuffer does not contain enough space for the current view." ); return; } // update the line stride to match the data. } this.data = newData; } }
public ByteBufferRasterData getSubset( RasterRect sampleDomain ) { // return this.getSubset( env.x, env.y, env.width, env.height ); // return createCompatibleRasterData( sampleDomain ); ByteBufferRasterData result = createCompatibleRasterData( new DataView( getView().x + sampleDomain.x, getView().y + sampleDomain.y, sampleDomain.width, sampleDomain.height, dataInfo ) ); if ( dataAccess.hasDataBuffer() && dataAccess.getReader() == null ) { // the data was loaded, but no reader was available, we need a copy of the data. result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), dataAccess.getBytebufferDomain() ); // result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), view ); // result.data = this.data.asReadOnlyBuffer(); } // result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), view ); // result.data = this.data.asReadOnlyBuffer(); return result; }
/** * @return the Reader which supplies this buffer with data, may be <code>null</code> */ public RasterReader getReader() { return this.dataAccess.getReader(); } }
/** * Prepares the byte buffer for reading / writing thus instantiates it with values (no) data; */ public void prepareBuffer() { synchronized ( LOCK ) { if ( data == null ) { data = ByteBufferPool.allocate( requiredBufferSize(), false ); boolean noData = false; if ( reader != null ) { try { BufferResult dataResult = reader.read( maxViewData, data ); if ( dataResult != null ) { data = dataResult.getResult(); data.rewind(); } // RasterRect rect = dataResult.getRect(); // lineStride = pixelStride * rect.width; } catch ( IOException e ) { LOG.debug( "No data available: " + e.getLocalizedMessage(), e ); // the data is no longer available, lets just fill it with no data values noData = true; } } if ( noData ) { fillWithNoData(); } } } }
/** * Fills the entire buffer with no data values. Note this operation is only possible on writable buffers. */ public void fillWithNoData() { dataAccess.fillWithNoData(); }
/** * @return the domain of validity of the byte buffer, which need not be the view on the data. */ public RasterRect getBytebufferDomain() { return dataAccess.getBytebufferDomain(); }
/** * @return The internal ByteBuffer. */ public ByteBuffer getByteBuffer() { return dataAccess.getByteBuffer(); }
public void dispose() { this.dataAccess.dispose(); }
/** * @return the loaded buffer and the rectangle for which the buffer has data. */ public Pair<ByteBuffer, RasterRect> getDataRect() { return new Pair<ByteBuffer, RasterRect>( getByteBuffer(), dataAccess.getDataRectangle() ); } }
/** * Creates a new ByteBufferRasterData instance. * * @param view * the raster rectangle defining the sample domain of this raster data. * @param rasterWidth * width of the raster data * @param rasterHeight * height of the raster data * @param reader * to be used to read the data from a location. * @param originalDataInfo * containing information about this raster data object * @param init * true if the ByteBuffer should be initialized */ protected ByteBufferRasterData( DataView view, int rasterWidth, int rasterHeight, RasterReader reader, RasterDataInfo originalDataInfo, boolean init ) { // this.view = view; this.rasterWidth = rasterWidth; this.rasterHeight = rasterHeight; this.dataInfo = originalDataInfo; this.dataAccess = new BufferAccess( reader, rasterWidth, rasterHeight, view, originalDataInfo, getPixelStride(), getLineStride(), getBandStride() ); if ( init ) { initByteBuffer(); } }
if ( dataAccess.hasDataBuffer() && dataAccess.getReader() == null ) { result.dataAccess.setByteBuffer( getByteBuffer().asReadOnlyBuffer(), dataAccess.getBytebufferDomain() );
@Override public PixelInterleavedRasterData createCompatibleRasterData( DataView view ) { return new PixelInterleavedRasterData( view, getOriginalWidth(), getOriginalHeight(), dataAccess.getReader(), dataInfo, false ); }
@Override public LineInterleavedRasterData createCompatibleRasterData( DataView view ) { return new LineInterleavedRasterData( view, getOriginalWidth(), getOriginalHeight(), dataAccess.getReader(), dataInfo, false ); }
/** * Calculates the position of a pixel in a view (FloatBuffer, etc.) of the ByteBuffer. * * This method considers different sample sizes (eg. byte, float) and returns the position in sample strides (not * byte strides). Use this method to get proper positions for ByteBuffer views like FloatBuffer, ShortBuffer, etc.. * * @param x * x coordinate * @param y * y coordinate * @return offset to the pixel with the specified coordinates or -1 if outside of the bytebuffer. */ public final int calculateViewPos( int x, int y ) { int pos = calculatePos( x, y ) / dataInfo.dataSize; return pos < 0 ? -1 : pos; }
/** * Calculates the position of a sample in a view (FloatBuffer, etc.) of the ByteBuffer. * * This method considers different sample sizes (eg. byte, float) and returns the position in sample stides (not * byte strides). Use this method to get proper positions for ByteBuffer-views like FloatBuffer, ShortBuffer, etc.. * * @param x * x coordinate * @param y * y coordinate * @param band * band index of the sample * @return offset to the sample with the specified coordinates */ public final int calculateViewPos( int x, int y, int band ) { return dataAccess.calculateViewPos( x, y, band ); }
@Override public BandInterleavedRasterData createCompatibleRasterData( DataView view ) { return new BandInterleavedRasterData( view, getOriginalWidth(), getOriginalHeight(), dataAccess.getReader(), dataInfo, false ); }
/** * Calculates the position of a sample in the ByteBuffer. * * This method calculates the position of a pixel and returns the offset to this pixel in bytes. Use this method for * direct access to ByteBuffers. * * @param x * x coordinate * @param y * y coordinate * @param bandOfView * band index of the sample * @return byte offset to the sample with the specified coordinate or -1 if outside of the bytebuffer. */ public final int calculatePos( int x, int y, int bandOfView ) { return dataAccess.calculatePos( x, y, bandOfView ); }
@Override protected ByteBufferRasterData createCompatibleEmptyRasterData() { return new LineInterleavedRasterData( getView(), getOriginalWidth(), getOriginalHeight(), dataAccess.getReader(), dataInfo, false ); }