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 WritableRenderedImageThe image where pixels will be written, ornullif the image is read-only.private WritableRasterThe current tile where pixels will be written, ornullif 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 TypeMethodDescriptionvoidclose()Releases any resources hold by this iterator.static WritablePixelIteratorcreate(WritableRenderedImage data) Creates an iterator for all pixels in the given image.(package private) final WritableRasterThe current raster destination raster, ornullif none.(package private) final RasterInvoked byPixelIterator.fetchTile()when iteration switch to a new tile.booleanReturnstrueif this iterator can write pixel values.(package private) voidReleases the tiles acquired by this iterator, if any.voidsetDataElements(Object values) Sets the data elements (not necessarily band values) of current pixel.voidsetPixel(double[] values) Sets the sample values of current pixel for all bands.voidsetPixel(float[] values) Sets the sample values of current pixel for all bands.voidsetPixel(int[] values) Sets the sample values of current pixel for all bands.voidsetSample(int band, double value) Writes a sample value in the specified band of current pixel.voidsetSample(int band, float value) Writes a sample value in the specified band of current pixel.voidsetSample(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, ornullif 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, ornullif 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, ornullfor read-only iterator.subArea- the raster region where to perform the iteration, ornullfor iterating over all the raster domain.window- size of the window to use inPixelIterator.createWindow(TransferType)method, ornullif none.order-nullorSequenceType.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, ornullfor read-only iterator.subArea- the image region where to perform the iteration, ornullfor iterating over all the image domain.window- size of the window to use inPixelIterator.createWindow(TransferType)method, ornullif none.order-nullorSequenceType.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()Returnstrueif this iterator can write pixel values. For some implementations, being an instance ofWritablePixelIteratoris not sufficient for being able to write pixel values.Note: all instances created by
WritablePixelIterator.create(…)methods are guaranteed totrue.- Overrides:
isWritablein classPixelIterator- Returns:
trueif 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. TheObjectargument 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, ornullif none. -
fetchWritableTile
Invoked byPixelIterator.fetchTile()when iteration switch to a new tile.- Overrides:
fetchWritableTilein 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:
releaseTilein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-