org.deegree.coverage.raster.data.nio
Class BufferAccess

java.lang.Object
  extended by org.deegree.coverage.raster.data.nio.BufferAccess

public class BufferAccess
extends Object

The BufferAccess glue between the databuffer and the reader (which has access to the real data).

Version:
$Revision: 31644 $, $Date: 2011-08-24 22:27:43 +0200 (Wed, 24 Aug 2011) $
Author:
Rutger Bezema, last edited by: $Author: mschneider $

Field Summary
protected  RasterDataInfo dataInfo
          the raster data info of the original data, not the view.
 
Constructor Summary
BufferAccess(RasterReader rasterReader, int maxDataWidth, int maxDataHeight, DataView view, RasterDataInfo dataInfo, int pixelStride, int lineStride, int bandStride)
          Glue
 
Method Summary
 int calculatePos(int x, int y)
          Calculates the position of a pixel in the ByteBuffer.
 int calculatePos(int x, int y, int bandOfView)
          Calculates the position of a sample in the ByteBuffer.
 int calculateViewPos(int x, int y)
          Calculates the position of a pixel in a view (FloatBuffer, etc.) of the ByteBuffer.
 int calculateViewPos(int x, int y, int band)
          Calculates the position of a sample in a view (FloatBuffer, etc.) of the ByteBuffer.
 void dispose()
          Set the memory buffer to null and call dispose on the reader as well.
 void fillWithNoData()
          Fills the entire buffer with no data values.
 ByteBuffer getByteBuffer()
           
protected  RasterRect getBytebufferDomain()
           
protected  RasterRect getDataRectangle()
           
protected  int getMaxDataHeight()
           
protected  int getMaxDataWidth()
           
 RasterReader getReader()
           
protected  DataView getView()
           
protected  boolean hasDataBuffer()
           
 boolean isOutside()
           
 void prepareBuffer()
          Prepares the byte buffer for reading / writing thus instantiates it with values (no) data;
 int requiredBufferSize()
          Returns the needed size of the ByteBuffer in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataInfo

protected RasterDataInfo dataInfo
the raster data info of the original data, not the view.

Constructor Detail

BufferAccess

public BufferAccess(RasterReader rasterReader,
                    int maxDataWidth,
                    int maxDataHeight,
                    DataView view,
                    RasterDataInfo dataInfo,
                    int pixelStride,
                    int lineStride,
                    int bandStride)
Glue

Parameters:
rasterReader -
maxDataWidth -
maxDataHeight -
view -
dataInfo -
pixelStride -
lineStride -
bandStride -
Method Detail

calculatePos

public final int calculatePos(int x,
                              int y)
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.

Parameters:
x - x coordinate
y - y coordinate
Returns:
byte offset to the pixel with the specified coordinate or -1 if outside of the bytebuffer.

calculatePos

public final int calculatePos(int x,
                              int y,
                              int bandOfView)
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.

Parameters:
x - x coordinate
y - y coordinate
bandOfView - band index of the sample
Returns:
byte offset to the sample with the specified coordinate or -1 if outside of the bytebuffer.

calculateViewPos

public final int calculateViewPos(int x,
                                  int 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..

Parameters:
x - x coordinate
y - y coordinate
Returns:
offset to the pixel with the specified coordinates or -1 if outside of the bytebuffer.

calculateViewPos

public final int calculateViewPos(int x,
                                  int y,
                                  int band)
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..

Parameters:
x - x coordinate
y - y coordinate
band - band index of the sample
Returns:
offset to the sample with the specified coordinates

prepareBuffer

public void prepareBuffer()
Prepares the byte buffer for reading / writing thus instantiates it with values (no) data;


fillWithNoData

public void fillWithNoData()
Fills the entire buffer with no data values. Note this operation is only possible on writable buffers.


requiredBufferSize

public final int requiredBufferSize()
Returns the needed size of the ByteBuffer in bytes.

Returns:
size of the buffer

getByteBuffer

public ByteBuffer getByteBuffer()
Returns:
The internal ByteBuffer.

getReader

public RasterReader getReader()
Returns:
the reader which supplies this buffer with data, may be null if the buffer is not backed by data (a new memory based raster for example).

getMaxDataHeight

protected int getMaxDataHeight()
Returns:
the height of the raster backing this buffer.

getMaxDataWidth

protected int getMaxDataWidth()
Returns:
the width of the raster backing this buffer.

getBytebufferDomain

protected RasterRect getBytebufferDomain()
Returns:
the domain of validity of the bytebuffer.

hasDataBuffer

protected boolean hasDataBuffer()
Returns:
true if this BufferAccess instantiated it's buffer already.

getView

protected DataView getView()
Returns:
the raster's view on the data, not the rectangle for which the buffer has data.

getDataRectangle

protected RasterRect getDataRectangle()
Returns:
the rectangle for which the loaded buffer has data.

dispose

public void dispose()
Set the memory buffer to null and call dispose on the reader as well.


isOutside

public boolean isOutside()
Returns:


Copyright © 2011. All Rights Reserved.