|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.deegree.coverage.raster.data.nio.ByteBufferRasterData
public abstract class ByteBufferRasterData
This abstract class implements the RasterData interface for ByteBuffer based raster.
It is based on java.nio.ByteBuffer and implements common get- and set-operations on the data. The different InterleaveTypes are implemented by additional subclasses.
get- and set-operations are implemented naive and access all data sample-wise. For efficiency subclasses should overwrite methods that access more than one sample and leverage the knowledge of the internal storage format (interleaving).
TODO: Only implements access to byte and float data at the moment. Copy float methods for other data types and change 'Float/float' to short, int, long or double. These types are supported by ByteBuffer and the according methods only differ in the name of the type (eg. getFloat, getInt, getDouble,...). Opposed to the methods for bytes, which lack the type in the method names (eg. only get()).
Also this implementation is able to store a sub-view on another ByteBufferRasterData
, resp. ByteBuffer. With
this feature you are able to create subsets without copying the data. Though the current deegree SimpleRaster
implementation makes no use of it.
Field Summary | |
---|---|
protected BufferAccess |
dataAccess
Buffer access holds a reference to the reader so not all data should be in memory |
protected RasterDataInfo |
dataInfo
the raster data info of the original data, not the view. |
String |
info
information on this raster data |
protected int |
rasterHeight
the height of the raster |
protected int |
rasterWidth
the width of the raster |
Fields inherited from interface org.deegree.coverage.raster.data.RasterData |
---|
TYPE_BYTE_RGB, TYPE_BYTE_RGBA |
Constructor Summary | |
---|---|
protected |
ByteBufferRasterData(DataView view,
int rasterWidth,
int rasterHeight,
RasterReader reader,
RasterDataInfo originalDataInfo)
Creates a new ByteBufferRasterData instance. |
protected |
ByteBufferRasterData(DataView view,
int rasterWidth,
int rasterHeight,
RasterReader reader,
RasterDataInfo originalDataInfo,
boolean init)
Creates a new ByteBufferRasterData instance. |
Method Summary | |
---|---|
RasterData |
asReadOnly()
Return a read-only version of this RasterData. |
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. |
protected boolean |
checkBounds(int x,
int y,
int width,
int height)
Checks whether a given rect is inside the raster. |
protected void |
checkBoundsEx(int x,
int y,
int width,
int height)
Checks whether a given rect is inside the raster, throws an exception if outside. |
protected static int |
clampSize(int dstSize,
int dstOrdinate,
int srcSize,
int srcOrdinate,
int copySize)
Clamp to the minimal size of the given values. |
protected abstract ByteBufferRasterData |
createCompatibleEmptyRasterData()
|
ByteBufferRasterData |
createCompatibleRasterData()
Returns a new RasterData with the same size, bands, DataType and InterleaveType |
ByteBufferRasterData |
createCompatibleRasterData(BandType[] bands)
Returns a new RasterData with the same size, DataType and InterleaveType |
protected abstract ByteBufferRasterData |
createCompatibleRasterData(DataView view)
Implementation should create a view of this raster data. |
ByteBufferRasterData |
createCompatibleRasterData(int width,
int height)
Returns a new RasterData with the same DataType and InterleaveType and all bands |
ByteBufferRasterData |
createCompatibleRasterData(RasterRect env)
Returns a view as a new RasterData with the same DataType and InterleaveType but valid only for the given rect. |
RasterData |
createCompatibleRasterData(RasterRect sampleDomain,
BandType[] bands)
Returns a new RasterData with the same DataType and InterleaveType |
protected RasterDataInfo |
createRasterDataInfo(BandType[] bands)
Create the raster data info object for the given bands, if empty or null |
void |
dispose()
Try to dispose all allocated memory of this data object. |
void |
fillWithNoData()
Fills the entire buffer with no data values. |
int |
getBands()
Returns the number of bands of the raster |
abstract int |
getBandStride()
Returns the byte offset to the next sample of the same pixel. |
ByteBuffer |
getByteBuffer()
|
RasterRect |
getBytebufferDomain()
|
byte[] |
getBytePixel(int x,
int y,
byte[] result)
Returns a byte array with all sample values from coordinate x/y. |
byte[] |
getBytes(int x,
int y,
int width,
int height,
int band,
byte[] result)
Gets values from the specified rectangle and band. |
byte |
getByteSample(int x,
int y,
int band)
Returns a byte sample from coordinate x/y and selected band. |
int |
getColumns()
Returns the width of the raster |
RasterDataInfo |
getDataInfo()
Returns an encapsulation of all available information of this raster data. |
DataType |
getDataType()
Returns the data type of the raster. |
double[] |
getDoublePixel(int x,
int y,
double[] result)
Returns a double array with all sample values from coordinate x/y. |
double[] |
getDoubles(int x,
int y,
int width,
int height,
int band,
double[] result)
Gets values from the specified rectangle and band. |
double |
getDoubleSample(int x,
int y,
int band)
Returns a double sample from coordinate x/y and selected band. |
float[] |
getFloatPixel(int x,
int y,
float[] result)
Returns a float array with all sample values from coordinate x/y. |
float[] |
getFloats(int x,
int y,
int width,
int height,
int band,
float[] result)
Gets values from the specified rectangle and band. |
float |
getFloatSample(int x,
int y,
int band)
Returns a float sample from coordinate x/y and selected band. |
int[] |
getIntPixel(int x,
int y,
int[] result)
Returns an integer array with all sample values from coordinate x/y. |
int[] |
getInts(int x,
int y,
int width,
int height,
int band,
int[] result)
Gets values from the specified rectangle and band. |
int |
getIntSample(int x,
int y,
int band)
Returns an integer sample from coordinate x/y and selected band. |
abstract int |
getLineStride()
Returns the byte offset to the next row (same column, same sample) |
byte[] |
getNullPixel(byte[] result)
Returns the no data values for this raster, or the view of this rasters bands. |
RasterDataInfo |
getOriginalDataInfo()
|
int |
getOriginalHeight()
|
int |
getOriginalWidth()
|
byte[] |
getPixel(int x,
int y,
byte[] result)
Returns a pixel as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array. |
abstract int |
getPixelStride()
Retruns the byte offset to the next pixel. |
RasterReader |
getReader()
|
int |
getRequiredBufferSize()
Returns the needed size of the ByteBuffer in bytes. |
int |
getRows()
Returns the height of the raster |
byte[] |
getSample(int x,
int y,
int band,
byte[] result)
Returns a sample as byte array, regardless of the DataType. i.e. a FLOAT DataType results in a four byte array |
short[] |
getShortPixel(int x,
int y,
short[] result)
Returns a short array with all sample values from coordinate x/y. |
short[] |
getShorts(int x,
int y,
int width,
int height,
int band,
short[] result)
Gets values from the specified rectangle and band. |
short |
getShortSample(int x,
int y,
int band)
Returns a short sample from coordinate x/y and selected band. |
ByteBufferRasterData |
getSubset(RasterRect sampleDomain)
Returns new RasterData object for the specified rectangle. |
ByteBufferRasterData |
getSubset(RasterRect sampleDomain,
BandType[] bands)
Returns new single-band RasterData object for the specified rectangle. |
DataView |
getView()
|
protected void |
initByteBuffer()
Initialize the internal ByteBuffer |
protected static int |
min(int... sizes)
Returns the smallest value of all int s. |
void |
setByteBuffer(ByteBuffer buf,
DataView dataRect)
Use the given bytebuffer as a data source. |
void |
setBytePixel(int x,
int y,
byte[] pixel)
Sets a single pixel with byte values for each sample. |
void |
setBytes(int x,
int y,
int width,
int height,
int band,
byte[] values)
Sets values from the array to the specified rectangle and band. |
void |
setByteSample(int x,
int y,
int band,
byte value)
Sets a single byte sample on coordinate x/y and selected band. |
void |
setDoublePixel(int x,
int y,
double[] pixel)
Sets a single pixel with double values for each sample. |
void |
setDoubles(int x,
int y,
int width,
int height,
int band,
double[] values)
Sets values from the array to the specified rectangle and band. |
void |
setDoubleSample(int x,
int y,
int band,
double value)
Sets a single double sample on coordinate x/y and selected band. |
void |
setFloatPixel(int x,
int y,
float[] pixel)
Sets a single pixel with float values for each sample. |
void |
setFloats(int x,
int y,
int width,
int height,
int band,
float[] values)
Sets values from the array to the specified rectangle and band. |
void |
setFloatSample(int x,
int y,
int band,
float value)
Sets a single float sample on coordinate x/y and selected band. |
void |
setIntPixel(int x,
int y,
int[] pixel)
Sets a single pixel with integer values for each sample. |
void |
setInts(int x,
int y,
int width,
int height,
int band,
int[] values)
Sets values from the array to the specified rectangle and band. |
void |
setIntSample(int x,
int y,
int band,
int value)
Sets a single integer sample on coordinate x/y and selected band. |
void |
setNoDataValue(byte[] values)
Sets the no data values for this raster |
void |
setPixel(int x,
int y,
byte[] result)
Sets a pixel with data from a byte array, regardless of the DataType. i.e. a float sample must be packed as a four byte array. |
void |
setSample(int x,
int y,
int band,
byte[] value)
Sets a sample with data from a byte array, regardless of the DataType. i.e. a float must be packed as a four byte array |
void |
setShortPixel(int x,
int y,
short[] pixel)
Sets a single pixel with short values for each sample. |
void |
setShorts(int x,
int y,
int width,
int height,
int band,
short[] values)
Sets values from the array to the specified rectangle and band. |
void |
setShortSample(int x,
int y,
int band,
short value)
Sets a single short sample on coordinate x/y and selected band. |
void |
setSubset(int x0,
int y0,
int width,
int height,
int dstBand,
RasterData sourceRaster,
int srcBand)
Sets a single band of the raster with values from one band of the sourceRaster. |
void |
setSubset(int dstX,
int dstY,
int width,
int height,
int dstBand,
RasterData srcRaster,
int srcBand,
int srcX,
int srcY)
Sets a single band of the raster with values from one band of the sourceRaster. |
void |
setSubset(int x0,
int y0,
int width,
int height,
RasterData sourceRaster)
Sets the raster with values from sourceRaster. |
void |
setSubset(int dstX,
int dstY,
int width,
int height,
RasterData srcRaster,
int srcX,
int srcY)
Sets the raster with values from sourceRaster. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.deegree.coverage.raster.data.RasterData |
---|
createCompatibleWritableRasterData |
Field Detail |
---|
protected int rasterWidth
protected int rasterHeight
protected RasterDataInfo dataInfo
protected BufferAccess dataAccess
public String info
Constructor Detail |
---|
protected ByteBufferRasterData(DataView view, int rasterWidth, int rasterHeight, RasterReader reader, RasterDataInfo originalDataInfo, boolean init)
view
- the raster rectangle defining the sample domain of this raster data.rasterWidth
- width of the raster datarasterHeight
- height of the raster datareader
- to be used to read the data from a location.originalDataInfo
- containing information about this raster data objectinit
- true if the ByteBuffer should be initializedprotected ByteBufferRasterData(DataView view, int rasterWidth, int rasterHeight, RasterReader reader, RasterDataInfo originalDataInfo)
view
- the raster rectangle defining the sample domain of this raster data.rasterWidth
- width of the raster datarasterHeight
- height of the raster datareader
- to be used to read the data.originalDataInfo
- containing information about this raster data objectMethod Detail |
---|
protected abstract ByteBufferRasterData createCompatibleRasterData(DataView view)
view
- the new view on this data
ByteBuffer
protected abstract ByteBufferRasterData createCompatibleEmptyRasterData()
public abstract int getPixelStride()
public abstract int getBandStride()
public abstract int getLineStride()
public void fillWithNoData()
public DataView getView()
protected void initByteBuffer()
public void setByteBuffer(ByteBuffer buf, DataView dataRect)
buf
- to set.dataRect
- defining the width, height and position of the data.public final int getRequiredBufferSize()
public ByteBufferRasterData createCompatibleRasterData(int width, int height)
RasterData
createCompatibleRasterData
in interface RasterData
width
- width of the new rasterheight
- height of the new raster
public ByteBufferRasterData createCompatibleRasterData(RasterRect env)
RasterData
createCompatibleRasterData
in interface RasterData
env
- the raster rectangle defining the sample domain of this raster data.
public RasterData createCompatibleRasterData(RasterRect sampleDomain, BandType[] bands)
RasterData
createCompatibleRasterData
in interface RasterData
sampleDomain
- the raster rectangle defining the sample domain of this raster data.bands
- indices to the requested bands
public ByteBufferRasterData createCompatibleRasterData(BandType[] bands)
RasterData
createCompatibleRasterData
in interface RasterData
bands
- definitions of the new rasterdata.
public ByteBufferRasterData createCompatibleRasterData()
RasterData
createCompatibleRasterData
in interface RasterData
public RasterData asReadOnly()
RasterData
asReadOnly
in interface RasterData
public DataType getDataType()
RasterData
getDataType
in interface RasterData
public int getBands()
RasterData
getBands
in interface RasterData
public RasterDataInfo getDataInfo()
RasterData
getDataInfo
in interface RasterData
public RasterDataInfo getOriginalDataInfo()
public int getOriginalHeight()
public RasterRect getBytebufferDomain()
public int getOriginalWidth()
public byte[] getNullPixel(byte[] result)
RasterData
getNullPixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public void setNoDataValue(byte[] values)
RasterData
setNoDataValue
in interface RasterData
values
- an array with the null valuespublic final int getColumns()
RasterData
getColumns
in interface RasterData
public final int getRows()
RasterData
getRows
in interface RasterData
public ByteBuffer getByteBuffer()
protected final void checkBoundsEx(int x, int y, int width, int height) throws IndexOutOfBoundsException
x
- The x position of the rect.y
- The y position of the rect.width
- The width of the rect.height
- The height of the rect.
IndexOutOfBoundsException
- if the given rect is outside the rasterprotected final boolean checkBounds(int x, int y, int width, int height)
x
- The x position of the rect.y
- The y position of the rect.width
- The width of the rect.height
- The height of the rect.
true
if the given rect is inside the raster, else false
public final int calculatePos(int x, int y)
x
- x coordinatey
- y coordinate
public final int calculatePos(int x, int y, int bandOfView)
x
- x coordinatey
- y coordinatebandOfView
- band index of the sample
public final int calculateViewPos(int x, int y)
x
- x coordinatey
- y coordinate
public final int calculateViewPos(int x, int y, int band)
x
- x coordinatey
- y coordinateband
- band index of the sample
public byte[] getBytes(int x, int y, int width, int height, int band, byte[] result)
RasterData
getBytes
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public byte[] getBytePixel(int x, int y, byte[] result)
RasterData
getBytePixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public byte getByteSample(int x, int y, int band)
RasterData
getByteSample
in interface RasterData
band
- band number for sample
public double[] getDoubles(int x, int y, int width, int height, int band, double[] result)
RasterData
getDoubles
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public double[] getDoublePixel(int x, int y, double[] result)
RasterData
getDoublePixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public double getDoubleSample(int x, int y, int band)
RasterData
getDoubleSample
in interface RasterData
band
- band number for sample
public float[] getFloats(int x, int y, int width, int height, int band, float[] result)
RasterData
getFloats
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public float[] getFloatPixel(int x, int y, float[] result)
RasterData
getFloatPixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public float getFloatSample(int x, int y, int band)
RasterData
getFloatSample
in interface RasterData
band
- band number for sample
public int[] getInts(int x, int y, int width, int height, int band, int[] result)
RasterData
getInts
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public int[] getIntPixel(int x, int y, int[] result)
RasterData
getIntPixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public int getIntSample(int x, int y, int band)
RasterData
getIntSample
in interface RasterData
band
- band number for sample
public byte[] getPixel(int x, int y, byte[] result)
RasterData
getPixel
in interface RasterData
result
- a byte array to put the values into or null
result
array or a new array, if the result
array is null
public byte[] getSample(int x, int y, int band, byte[] result)
RasterData
getSample
in interface RasterData
band
- selected bandresult
- an array to put the values into or null
result
array or a new array, if the result
array is null
public short[] getShorts(int x, int y, int width, int height, int band, short[] result)
RasterData
getShorts
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public short[] getShortPixel(int x, int y, short[] result)
RasterData
getShortPixel
in interface RasterData
result
- an array to put the values into or null
result
array or a new array, if the result
array is null
public short getShortSample(int x, int y, int band)
RasterData
getShortSample
in interface RasterData
band
- band number for sample
public ByteBufferRasterData getSubset(RasterRect sampleDomain)
RasterData
getSubset
in interface RasterData
sampleDomain
- rectangle for subset
public ByteBufferRasterData getSubset(RasterRect sampleDomain, BandType[] bands)
RasterData
getSubset
in interface RasterData
sampleDomain
- rectangle for subsetbands
- selected band
public void setBytes(int x, int y, int width, int height, int band, byte[] values)
RasterData
setBytes
in interface RasterData
values
- the samples to put into the rasterpublic void setBytePixel(int x, int y, byte[] pixel)
RasterData
setBytePixel
in interface RasterData
pixel
- array with one sample per bandpublic void setByteSample(int x, int y, int band, byte value)
RasterData
setByteSample
in interface RasterData
band
- band number for samplevalue
- new value for samplepublic void setDoubles(int x, int y, int width, int height, int band, double[] values)
RasterData
setDoubles
in interface RasterData
values
- the samples to put into the rasterpublic void dispose()
RasterData
dispose
in interface RasterData
public void setDoublePixel(int x, int y, double[] pixel)
RasterData
setDoublePixel
in interface RasterData
pixel
- array with one sample per bandpublic void setDoubleSample(int x, int y, int band, double value)
RasterData
setDoubleSample
in interface RasterData
band
- band number for samplevalue
- new value for samplepublic void setFloats(int x, int y, int width, int height, int band, float[] values)
RasterData
setFloats
in interface RasterData
values
- the samples to put into the rasterpublic void setFloatPixel(int x, int y, float[] pixel)
RasterData
setFloatPixel
in interface RasterData
pixel
- array with one sample per bandpublic void setFloatSample(int x, int y, int band, float value)
RasterData
setFloatSample
in interface RasterData
band
- band number for samplevalue
- new value for samplepublic void setPixel(int x, int y, byte[] result)
RasterData
setPixel
in interface RasterData
public void setInts(int x, int y, int width, int height, int band, int[] values)
RasterData
setInts
in interface RasterData
values
- the samples to put into the rasterpublic void setIntPixel(int x, int y, int[] pixel)
RasterData
setIntPixel
in interface RasterData
pixel
- array with one sample per bandpublic void setIntSample(int x, int y, int band, int value)
RasterData
setIntSample
in interface RasterData
band
- band number for samplevalue
- new value for samplepublic void setShorts(int x, int y, int width, int height, int band, short[] values)
RasterData
setShorts
in interface RasterData
values
- the samples to put into the rasterpublic void setShortPixel(int x, int y, short[] pixel)
RasterData
setShortPixel
in interface RasterData
pixel
- array with one sample per bandpublic void setShortSample(int x, int y, int band, short value)
RasterData
setShortSample
in interface RasterData
band
- band number for samplevalue
- new value for samplepublic void setSample(int x, int y, int band, byte[] value)
RasterData
setSample
in interface RasterData
band
- selected bandvalue
- array with the sample valuepublic void setSubset(int x0, int y0, int width, int height, RasterData sourceRaster)
RasterData
setSubset
in interface RasterData
x0
- insert positiony0
- insert positionwidth
- width of the subsetheight
- height of the subsetsourceRaster
- data source to copypublic void setSubset(int x0, int y0, int width, int height, int dstBand, RasterData sourceRaster, int srcBand)
RasterData
setSubset
in interface RasterData
x0
- insert positiony0
- insert positionwidth
- width of the subsetheight
- height of the subsetdstBand
- the index of the destination bandsourceRaster
- data source to copysrcBand
- the index of the source band of sourceRaster
public void setSubset(int dstX, int dstY, int width, int height, RasterData srcRaster, int srcX, int srcY)
RasterData
setSubset
in interface RasterData
dstX
- insert positiondstY
- insert positionwidth
- width of the subsetheight
- height of the subsetsrcRaster
- data source to copysrcX
- x offset in the source rastersrcY
- y offset in the source rasterpublic void setSubset(int dstX, int dstY, int width, int height, int dstBand, RasterData srcRaster, int srcBand, int srcX, int srcY)
RasterData
setSubset
in interface RasterData
dstX
- insert positiondstY
- insert positionwidth
- width of the subsetheight
- height of the subsetdstBand
- the index of the destination bandsrcRaster
- data source to copysrcBand
- the index of the source band of sourceRaster
srcX
- x offset in the source rastersrcY
- y offset in the source rasterprotected static final int clampSize(int dstSize, int dstOrdinate, int srcSize, int srcOrdinate, int copySize)
dstSize
- e.g. getWidth() or getHeight() of the destination raster.dstOrdinate
- e.g srcX, srcY, the location to put the data in destination raster.srcSize
- e.g. getWidth() or getHeight() of the source raster. *srcOrdinate
- e.g dstX, dstY, the location to read the data from the source raster.copySize
- e.g. width/height of rectangle to put data in this raster.
public String toString()
toString
in class Object
protected static final int min(int... sizes)
int
s.
sizes
-
protected RasterDataInfo createRasterDataInfo(BandType[] bands)
null the current dataInfo will be used.
- Parameters:
bands
-
- Returns:
- a new raster data info object with for the given bands.
public RasterReader getReader()
null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |