Package org.apache.sis.image
Class WritablePixelIterator
java.lang.Object
org.apache.sis.image.PixelIterator
org.apache.sis.image.WritablePixelIterator
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
BandedIterator
A pixel iterator capable to write sample values. This iterator can edit pixel values in place,
or write values in a different destination image than the source image. Source and destination
images must use the same sample model and the same coordinates (both for pixels and tiles).
Casting a
To check if a
Contrarily to PixelIterator
, WritablePixelIterator
needs to be closed after
iteration in order to release tiles. Example:
Casting a PixelIterator
To check if a PixelIterator
can be used for writing pixels, a … instanceof WritablePixelIterator
check is not sufficient. The PixelIterator.isWritable()
method should be invoked instead.- Since:
- 1.0
- Version:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.image.PixelIterator
PixelIterator.Builder, PixelIterator.Window<T extends Buffer>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final WritableRenderedImage
The image where pixels will be written, ornull
if the image is read-only.private WritableRaster
The current tile where pixels will be written, ornull
if no write operation is under way. -
Constructor Summary
ConstructorsConstructorDescriptionWritablePixelIterator
(Raster input, WritableRaster output, Rectangle subArea, Dimension window, SequenceType order) Creates an iterator for the given region in the given raster.WritablePixelIterator
(RenderedImage input, WritableRenderedImage output, Rectangle subArea, Dimension window, SequenceType order) Creates an iterator for the given region in the given image. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases any resources hold by this iterator.static WritablePixelIterator
create
(WritableRenderedImage data) Creates an iterator for all pixels in the given image.(package private) final WritableRaster
The current raster destination raster, ornull
if none.(package private) final Raster
Invoked byPixelIterator.fetchTile()
when iteration switch to a new tile.boolean
Returnstrue
if this iterator can write pixel values.(package private) void
Releases the tiles acquired by this iterator, if any.void
setDataElements
(Object values) Sets the data elements (not necessarily band values) of current pixel.void
setPixel
(double[] values) Sets the sample values of current pixel for all bands.void
setPixel
(float[] values) Sets the sample values of current pixel for all bands.void
setPixel
(int[] values) Sets the sample values of current pixel for all bands.void
setSample
(int band, double value) Writes a sample value in the specified band of current pixel.void
setSample
(int band, float value) Writes a sample value in the specified band of current pixel.void
setSample
(int band, int value) Writes a sample value in the specified band of current pixel.Methods inherited from class org.apache.sis.image.PixelIterator
acquiredTile, changedRowOrTile, create, createWindow, createWindow, createWindow, fetchValues, getDataElements, getDataType, getDomain, getIterationOrder, getNumBands, getPixel, getPixel, getPixel, getPosition, getSample, getSampleDouble, getSampleFloat, getSampleRanges, getTransferType, isSameRowAndTile, moveTo, next, rewind
-
Field Details
-
destination
The image where pixels will be written, ornull
if the image is read-only. The destination image may or may not be the same instance than the sourcePixelIterator.image
. However, the sample model, the minimal X and Y values and the tile grid must be the same. -
destRaster
The current tile where pixels will be written, ornull
if no write operation is under way. It may or may not be the same instance thanPixelIterator.currentRaster
.
-
-
Constructor Details
-
WritablePixelIterator
WritablePixelIterator(Raster input, WritableRaster output, Rectangle subArea, Dimension window, SequenceType order) Creates an iterator for the given region in the given raster.- Parameters:
input
- the raster which contains the sample values to read.output
- the raster where to write the sample values, ornull
for read-only iterator.subArea
- the raster region where to perform the iteration, ornull
for iterating over all the raster domain.window
- size of the window to use inPixelIterator.createWindow(TransferType)
method, ornull
if none.order
-null
orSequenceType.LINEAR
. Other values may be added in future versions.
-
WritablePixelIterator
WritablePixelIterator(RenderedImage input, WritableRenderedImage output, Rectangle subArea, Dimension window, SequenceType order) Creates an iterator for the given region in the given image.- Parameters:
input
- the image which contains the sample values to read.output
- the image where to write the sample values, ornull
for read-only iterator.subArea
- the image region where to perform the iteration, ornull
for iterating over all the image domain.window
- size of the window to use inPixelIterator.createWindow(TransferType)
method, ornull
if none.order
-null
orSequenceType.LINEAR
. Other values may be added in future versions.
-
-
Method Details
-
create
Creates an iterator for all pixels in the given image. This is a convenience method fornew Builder().createWritable(data)
.- Parameters:
data
- the image which contains the sample values on which to iterate.- Returns:
- a new iterator traversing all pixels in the given image, in arbitrary order.
-
isWritable
public boolean isWritable()Returnstrue
if this iterator can write pixel values. For some implementations, being an instance ofWritablePixelIterator
is not sufficient for being able to write pixel values.Note: all instances created by
WritablePixelIterator.create(…)
methods are guaranteed totrue
.- Overrides:
isWritable
in classPixelIterator
- Returns:
true
if this iterator can be used for writing pixel values.
-
setSample
public void setSample(int band, int value) Writes a sample value in the specified band of current pixel. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetSample(int, int)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
band
- the band in which to set the sample value.value
- the sample value to write in the specified band.- See Also:
-
setSample
public void setSample(int band, float value) Writes a sample value in the specified band of current pixel. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetSample(int, float)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
band
- the band in which to set the sample value.value
- the sample value to write in the specified band.- See Also:
-
setSample
public void setSample(int band, double value) Writes a sample value in the specified band of current pixel. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetSample(int, double)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
band
- the band in which to set the sample value.value
- the sample value to write in the specified band.- See Also:
-
setPixel
public void setPixel(int[] values) Sets the sample values of current pixel for all bands. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetPixel(…)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
values
- the new sample values for current pixel.- See Also:
-
setPixel
public void setPixel(float[] values) Sets the sample values of current pixel for all bands. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetPixel(…)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
values
- the new sample values for current pixel.- See Also:
-
setPixel
public void setPixel(double[] values) Sets the sample values of current pixel for all bands. ThePixelIterator.next()
method must have returnedtrue
, or thePixelIterator.moveTo(int,int)
method must have been invoked successfully, before thissetPixel(…)
method is invoked. If above condition is not met, then this method behavior is undefined (there is no explicit bounds check for performance reasons).- Parameters:
values
- the new sample values for current pixel.- See Also:
-
setDataElements
Sets the data elements (not necessarily band values) of current pixel. TheObject
argument is a relatively opaque format (it may beint[]
,byte[]
, etc.). It should be the value provided by a call toPixelIterator.getDataElements(Object)
on an image using a compatible sample model.- Parameters:
values
- the new the data elements.- Since:
- 1.1
- See Also:
-
destination
The current raster destination raster, ornull
if none. -
fetchWritableTile
Invoked byPixelIterator.fetchTile()
when iteration switch to a new tile.- Overrides:
fetchWritableTile
in classPixelIterator
- Returns:
- if the new writable tile can also be used for reading, that tile. Otherwise
null
.
-
releaseTile
void releaseTile()Releases the tiles acquired by this iterator, if any. This method does nothing if the iterator is read-only.- Overrides:
releaseTile
in classPixelIterator
-
close
public void close()Releases any resources hold by this iterator. If some pixel values have been written, the changes are committed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-