Package org.apache.sis.image
Class Transferer
java.lang.Object
org.apache.sis.image.Transferer
- Direct Known Subclasses:
Transferer.DoubleToDirect,Transferer.DoubleToDouble,Transferer.DoubleToInteger,Transferer.FloatToDirect,Transferer.FloatToFloat,Transferer.FloatToInteger
Strategy for reading and writing data between two rasters, with a computation between them.
Some strategies are to write directly in the destination raster, other strategies are to use
an intermediate buffer. This class has the following constraints:
- Source values cannot be modified. Calculations must be done either directly in the target raster, or in a temporary buffer.
- Direct access to the
DataBufferarrays may disable video card acceleration. This class assumes that it is acceptable forfloatanddoubletypes, and to be avoided for integer types.
- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classReaddoublevalues from the source raster and write unsignedbytevalues in a temporary buffer.private static final classReaddoublevalues from the source and writedoublevalues directly in the target raster, without intermediate buffer.private static final classReaddoublevalues from the source raster and writedoublevalues in a temporary buffer.private static classReaddoublevalues from the source raster and writeintvalues in a temporary buffer.private static final classReaddoublevalues from the source raster and write signedshortvalues in a temporary buffer.private static final classReaddoublevalues from the source raster and write unsignedshortvalues in a temporary buffer.private static final classReadfloatvalues from the source raster and write unsignedbytevalues in a temporary buffer.private static final classReadfloatvalues from the source and writefloatvalues directly in the target raster, without intermediate buffer.private static final classReadfloatvalues from the source raster and writefloatvalues in a temporary buffer.private static classReadfloatvalues from the source raster and writeintvalues in a temporary buffer.private static final classReadfloatvalues from the source raster and write signedshortvalues in a temporary buffer.private static final classReadfloatvalues from the source raster and write unsignedshortvalues in a temporary buffer. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe band to read and write.protected final RectangleCoordinates of the region to read and write.protected final RasterThe image tile from which to read sample values.protected final WritableRasterThe image tile where to write sample values after processing. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransferer(Raster source, WritableRaster target, Rectangle aoi) Creates a new instance for transferring data between the two specified rasters. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcompute(org.opengis.referencing.operation.MathTransform1D[] converters) Computes all sample values from the source tile and writes the result in the target tile.(package private) abstract voidcomputeStrip(org.opengis.referencing.operation.MathTransform1D converter) (package private) static Transferercreate(Raster source, WritableRaster target, Rectangle aoi) Suggests a strategy for transferring data from the given source to the given target.(package private) static Transferercreate(RenderedImage source, WritableRaster target) Suggests a strategy for transferring data from the given source image to the given target.private static booleanReturnstrueif the given raster stores sample values at consecutive locations in each band.(package private) final intlength()Returns the number of elements inregion.(package private) intSetsregion.heightto the height of the buffer where values are stored during data transfer and whereMathTransform1Doperations are applied.private static booleansinglePrecision(Raster source) Returnstrueif the given raster use a data type that can be casted to thefloattype without precision lost.
-
Field Details
-
source
The image tile from which to read sample values. -
target
The image tile where to write sample values after processing. -
region
-
band
protected int band
-
-
Constructor Details
-
Transferer
Creates a new instance for transferring data between the two specified rasters. It is caller responsibility to ensure thataoiis contained in the bounds of bothsourceandtargetrasters.- Parameters:
source- image tile from which to read sample values.target- image tile where to write sample values after processing.aoi- the area of interest, oftentarget.getBounds().
-
-
Method Details
-
prepareTransferRegion
int prepareTransferRegion()Setsregion.heightto the height of the buffer where values are stored during data transfer and whereMathTransform1Doperations are applied. If thisTransfererdoes not use an intermediate buffer (i.e. if it copies values directly in the target buffer and processes them in-place), then this method should leaveregionunchanged.The default implementation does nothing. This is the most conservative approach since it does not require
Transfererto split data processing in strips, at the cost of more memory consumption if thisTransfererdoes not write data directly in the target tile.- Returns:
region.y + region.height.- See Also:
-
compute
public final void compute(org.opengis.referencing.operation.MathTransform1D[] converters) throws org.opengis.referencing.operation.TransformException Computes all sample values from the source tile and writes the result in the target tile. This method invokescomputeStrip(MathTransform1D)repetitively for sub-regions of the tile.- Parameters:
converters- the converters to apply on each band.- Throws:
org.opengis.referencing.operation.TransformException- if an error occurred during calculation.
-
computeStrip
abstract void computeStrip(org.opengis.referencing.operation.MathTransform1D converter) throws org.opengis.referencing.operation.TransformException Reads sample values from the source tile, applies the given operation for current region and band, then writes results in the target tile. The region and the band number must be set before to invoke this method.- Parameters:
converter- the operation to apply on sample values in current region and current band number.- Throws:
org.opengis.referencing.operation.TransformException- if an error occurred during calculation.
-
length
final int length()Returns the number of elements inregion. This is a helper method for subclass implementations. -
create
Suggests a strategy for transferring data from the given source image to the given target. This method assumes that the source image uses the same pixel coordinate system than the target raster (i.e. that pixels at the same coordinates are at the same location on Earth). It also assumes that the target tile is fully included in the bounds of a single source tile. That later condition is met if the target grid tiles has been created byImageLayout.- Parameters:
source- image from which to read sample values.target- image tile where to write sample values after processing.- Returns:
- object to use for applying the operation.
-
create
Suggests a strategy for transferring data from the given source to the given target. The operation to apply on sample values during transfer is specified later, during the call tocompute(MathTransform1D[]).- Parameters:
source- image tile from which to read sample values.target- image tile where to write sample values after processing.aoi- the area of interest, oftentarget.getBounds(). It is caller responsibility to ensure thataoiis contained insourceandtargetbounds.- Returns:
- object to use for applying the operation.
-
singlePrecision
Returnstrueif the given raster use a data type that can be casted to thefloattype without precision lost. If the type is unknown, then this method returnsfalse. Note that this method also returnsfalseforDataBuffer.TYPE_INTbecause conversion of 32 bits integer to thefloattype may lost precision digits. -
isDirect
Returnstrueif the given raster stores sample values at consecutive locations in each band. In other words, verifies if the given raster uses a pixel stride of 1 with no gab between lines. Another condition is that the data buffer must start at offset 0.
-