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
DataBuffer
arrays may disable video card acceleration. This class assumes that it is acceptable forfloat
anddouble
types, and to be avoided for integer types.
- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Readdouble
values from the source raster and write unsignedbyte
values in a temporary buffer.private static final class
Readdouble
values from the source and writedouble
values directly in the target raster, without intermediate buffer.private static final class
Readdouble
values from the source raster and writedouble
values in a temporary buffer.private static class
Readdouble
values from the source raster and writeint
values in a temporary buffer.private static final class
Readdouble
values from the source raster and write signedshort
values in a temporary buffer.private static final class
Readdouble
values from the source raster and write unsignedshort
values in a temporary buffer.private static final class
Readfloat
values from the source raster and write unsignedbyte
values in a temporary buffer.private static final class
Readfloat
values from the source and writefloat
values directly in the target raster, without intermediate buffer.private static final class
Readfloat
values from the source raster and writefloat
values in a temporary buffer.private static class
Readfloat
values from the source raster and writeint
values in a temporary buffer.private static final class
Readfloat
values from the source raster and write signedshort
values in a temporary buffer.private static final class
Readfloat
values from the source raster and write unsignedshort
values in a temporary buffer. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The band to read and write.protected final Rectangle
Coordinates of the region to read and write.protected final Raster
The image tile from which to read sample values.protected final WritableRaster
The image tile where to write sample values after processing. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Transferer
(Raster source, WritableRaster target, Rectangle aoi) Creates a new instance for transferring data between the two specified rasters. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
compute
(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 void
computeStrip
(org.opengis.referencing.operation.MathTransform1D converter) (package private) static Transferer
create
(Raster source, WritableRaster target, Rectangle aoi) Suggests a strategy for transferring data from the given source to the given target.(package private) static Transferer
create
(RenderedImage source, WritableRaster target) Suggests a strategy for transferring data from the given source image to the given target.private static boolean
Returnstrue
if the given raster stores sample values at consecutive locations in each band.(package private) final int
length()
Returns the number of elements inregion
.(package private) int
Setsregion.height
to the height of the buffer where values are stored during data transfer and whereMathTransform1D
operations are applied.private static boolean
singlePrecision
(Raster source) Returnstrue
if the given raster use a data type that can be casted to thefloat
type 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 thataoi
is contained in the bounds of bothsource
andtarget
rasters.- 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.height
to the height of the buffer where values are stored during data transfer and whereMathTransform1D
operations are applied. If thisTransferer
does 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 leaveregion
unchanged.The default implementation does nothing. This is the most conservative approach since it does not require
Transferer
to split data processing in strips, at the cost of more memory consumption if thisTransferer
does 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 thataoi
is contained insource
andtarget
bounds.- Returns:
- object to use for applying the operation.
-
singlePrecision
Returnstrue
if the given raster use a data type that can be casted to thefloat
type without precision lost. If the type is unknown, then this method returnsfalse
. Note that this method also returnsfalse
forDataBuffer.TYPE_INT
because conversion of 32 bits integer to thefloat
type may lost precision digits. -
isDirect
Returnstrue
if 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.
-