| java.lang.Object org.geotools.image.ImageWorker
ImageWorker | public class ImageWorker (Code) | | Helper methods for applying JAI operations on an image. The image is specified at
. Sucessive operations can
be applied by invoking the methods defined in this class, and the final image can
be obtained by invoking
ImageWorker.getRenderedImage at the end of the process.
If an exception is thrown during a method invocation, then this
ImageWorker is left in an undetermined state and should not be used anymore.
since: 2.3 version: $Id: ImageWorker.java 28776 2008-01-15 20:26:28Z desruisseaux $ author: Simone Giannecchini author: Bryce Nordgren author: Martin Desruisseaux |
Inner Class :final public static class PNGImageWriteParam extends ImageWriteParam | |
Constructor Summary | |
public | ImageWorker() Creates a new uninitialized builder for an
. | public | ImageWorker(File input) Creates a new builder for an image read from the specified file. | public | ImageWorker(RenderedImage image) Creates a new builder for the specified image. |
Method Summary | |
final public ImageWorker | addImage(RenderedImage renderedImage) Takes two rendered or renderable source images, and adds every pair of pixels, one from
each source image of the corresponding position and band. | public ImageWorker | addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is
. | final public ImageWorker | addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean translucent, int transparent, boolean errorDiffusion) Adds transparency to a preexisting image whose color model is
. | final public ImageWorker | binarize() Binarizes the
. | final public ImageWorker | binarize(double threshold) Binarizes the
. | final public ImageWorker | binarize(int value0, int value1) Binarizes the
(if not already done) and replace all 0
values by
value0 and all 1 values by
value1 . | final public ImageWorker | forceBitmaskIndexColorModel() Reduces the color model to
with
or
transparency. | final public ImageWorker | forceBitmaskIndexColorModel(int transparent, boolean errorDiffusion) Reduces the color model to
with
or
transparency. | final public ImageWorker | forceColorSpaceGRAYScale() Forces the
color model to the
. | final public ImageWorker | forceColorSpaceRGB() Forces the
color model to the
. | final public ImageWorker | forceComponentColorModel() Reformats the
to a
preserving
transparency. | final public ImageWorker | forceComponentColorModel(boolean checkTransparent) Reformats the
to a
preserving
transparency. | final public ImageWorker | forceIndexColorModel(boolean error) Reduces the color model to
.
If the current
already uses an
, then this method do
nothing. | final public ImageWorker | forceIndexColorModelForGIF(boolean errorDiffusion) Converts the image to a GIF-compliant image. | final public ImageWorker | format(int dataType) Formats the underlying image to the provided data type.
Parameters: dataType - to be used for this FormatDescriptor operation. | final public ROI | getImageAsROI() Returns a
built from the current
. | final public double[] | getMaximums() Returns the maximal values found in every
bands. | final public double[] | getMinimums() Returns the minimal values found in every
bands. | final public int | getNumBands() Returns the number of bands in the
. | final public PlanarImage | getPlanarImage() Returns the
as a planar image. | final public ROI | getROI() Returns the region of interest currently set, or
null if none. | final public RenderedImage | getRenderedImage() Returns the current image. | final public RenderedOp | getRenderedOperation() Returns the
as a rendered operation. | final public Object | getRenderingHint(RenderingHints.Key key) Returns the rendering hint for the specified key, or
null if none. | final public RenderingHints | getRenderingHints() Returns the rendering hints for an image to be computed by this class.
The default implementation returns the following hints:
- An
with tiles size computed automatically
from the current
size.
- Any additional hints specified through the
ImageWorker.setRenderingHint method.
| final public int | getTransparentPixel() Returns the transparent pixel value, or -1 if none. | final public ImageWorker | intensity() Creates an image which represents approximatively the intensity of
. | final public ImageWorker | invert() Inverts the pixel values of the
. | final public boolean | isBinary() Returns
true if the
is binary. | final public boolean | isBytes() Returns
true if the
stores its pixel values in 8 bits. | final public boolean | isColorSpaceGRAYScale() Returns
true if the
uses a GrayScale
. | final public boolean | isColorSpaceRGB() Returns
true if the
uses a RGB
. | final public boolean | isIndexed() Returns
true if the
uses an
. | final public boolean | isTranslucent() Returns
true if the
is
. | final public void | load(String source, int imageChoice, boolean readMetadata) Loads an image using the provided file name and the
, which are used to control caching and layout. | public static PlanarImage | loadPlanarImageImage(String source, RenderingHints hints, int imageChoice, boolean readMetadata) Loads an image using the provided file name and the provided hints, which
are used to control caching and layout.
Parameters: source - The source image. Parameters: hints - The hints to use. Parameters: imageChoice - For multipage images. | public static void | main(String[] args) Loads the image from the specified file, and
it in a window. | final public ImageWorker | makeColorTransparent(Color transparentColor) Replaces all occurences of the given color (usually opaque) by a fully transparent color.
Currents implementation supports image backed by any
IndexColorModel , or by
ComponentColorModel with
DataBuffer.TYPE_BYTE TYPE_BYTE . | final public ImageWorker | mask(RenderedImage mask, boolean maskValue, int newValue) Applies the specified mask over the current
. | final public ImageWorker | maskComponentColorModelByte(Color transparentColor) For an image backed by an
ComponentColorModel , replaces all occurences
of the given color (usually opaque) by a fully transparent color.
Parameters: transparentColor - The color to make transparent. | final public ImageWorker | maskIndexColorModelByte(Color transparentColor) For an image backed by an
IndexColorModel , replaces all occurences of the given
color (usually opaque) by a fully transparent color.
Parameters: transparentColor - The color to make transparent. | final public ImageWorker | multiplyConst(double[] inValues) Takes one rendered or renderable image and an array of double constants, and multiplies
every pixel of the same band of the source by the constant from the corresponding array
entry. | final public ImageWorker | removeRenderingHint(RenderingHints.Key key) Removes a rendering hint. | final public ImageWorker | rescaleToBytes() Rescales the
such that it uses 8 bits. | final public ImageWorker | retainBands(int numBands) Retains inconditionnaly the first
numBands of
.
All other bands (if any) are discarted without any further processing.
This method does nothing if the current
does not have
a greater amount of bands than
numBands .
Parameters: numBands - the number of bands to retain. | final public ImageWorker | retainBands(int[] bands) Retains inconditionnaly certain bands of
. | final public ImageWorker | retainFirstBand() Retains inconditionnaly the first band of
. | final public ImageWorker | retainLastBand() Retains inconditionnaly the last band of
. | final public ImageWorker | setImage(RenderedImage image) Prepare this builder for the specified image. | final public ImageWorker | setROI(ROI roi) Set the region of interest (ROI). | final public ImageWorker | setRenderingHint(RenderingHints.Key key, Object value) Sets a rendering hint tile to use for all images to be computed by this class. | final public ImageWorker | show() Shows the current
in a window together with the operation chain as a
. | final public ImageWorker | tile() If the was not already tiled, tile it. | final public ImageWorker | tileCacheEnabled(boolean status) If
false , disables the tile cache. | final public ImageWorker | write(File output) Writes the
to the specified file. | final public ImageWorker | writeGIF(Object destination, String compression, float compressionRate) Writes outs the image contained into this
ImageWorker as a GIF
using the provided destination, compression and compression rate.
It is worth to point out that the only compressions algorithm availaible
with the jdk
GIFImageWriter is "LZW" while the compression rates
have to be confined between 0 and 1. | final public void | writeJPEG(Object destination, String compression, float compressionRate, boolean nativeAcc) Writes outs the image contained into this
ImageWorker as a JPEG
using the provided destination , compression and compression rate.
The destination object can be anything providing that we have an
ImageOutputStreamSpi that recognizes it.
Parameters: destination - where to write the internal ImageWorker.image as a JPEG. Parameters: compression - algorithm. Parameters: compressionRate - percentage of compression. Parameters: nativeAcc - should we use native acceleration. | final public void | writePNG(Object destination, String compression, float compressionRate, boolean nativeAcc, boolean paletted) Writes outs the image contained into this
ImageWorker as a PNG
using the provided destination, compression and compression rate. | final public ImageWorker | xorConst(int[] values) Takes one rendered or renderable image and an array of integer constants, and performs a
bit-wise logical "xor" between every pixel in the same band of the source and the constant
from the corresponding array entry. |
image | protected RenderedImage image(Code) | | The image being built.
|
ImageWorker | public ImageWorker(File input) throws IOException(Code) | | Creates a new builder for an image read from the specified file.
Parameters: input - The file to read. throws: IOException - if the file can't be read. |
ImageWorker | public ImageWorker(RenderedImage image)(Code) | | Creates a new builder for the specified image. The images to be computed (if any)
will save their tiles in the default
.
Parameters: image - The source image. |
addImage | final public ImageWorker addImage(RenderedImage renderedImage)(Code) | | Takes two rendered or renderable source images, and adds every pair of pixels, one from
each source image of the corresponding position and band. See JAI
AddDescriptor for details.
Parameters: renderedImage - the RenderedImage to be added to this ImageWorker. this ImageWorker. See Also: AddDescriptor |
addTransparencyToIndexColorModel | public ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean errorDiffusion)(Code) | | Adds transparency to a preexisting image whose color model is
. For all pixels with the
value
false in the specified transparency mask, the corresponding
pixel in the
is set to the transparent pixel value.
All other pixels are left unchanged.
Parameters: alphaChannel - The mask to apply as a image. Parameters: errorDiffusion - Tells if I should use ErrorDiffusionDescriptor orOrderedDitherDescriptor JAi operations. this ImageWorker. See Also: ImageWorker.isTranslucent See Also: ImageWorker.forceBitmaskIndexColorModel |
addTransparencyToIndexColorModel | final public ImageWorker addTransparencyToIndexColorModel(RenderedImage alphaChannel, boolean translucent, int transparent, boolean errorDiffusion)(Code) | | Adds transparency to a preexisting image whose color model is
. First, this method creates a new index color model with the specified
transparent pixel, if needed (this method may skip this step if the specified pixel
is already transparent. Then for all pixels with the value
false in the specified
transparency mask, the corresponding pixel in the
is set to that
transparent value. All other pixels are left unchanged.
Parameters: alphaChannel - The mask to apply as a image. Parameters: translucent - true if images areallowed, or false if the resulting images must be a. Parameters: transparent - The value for transparent pixels, to be given to every pixels in the corresponding to false in the mask. Thespecial value -1 maps to the last pixel value allowed for the. Parameters: errorDiffusion - Tells if I should use ErrorDiffusionDescriptor orOrderedDitherDescriptor JAi operations. this ImageWorker. |
forceColorSpaceRGB | final public ImageWorker forceColorSpaceRGB()(Code) | | Forces the
color model to the
. If the current color
space is already of
, then this
method does nothing. This operation may loose the alpha channel.
this ImageWorker. See Also: ImageWorker.isColorSpaceRGB See Also: ColorConvertDescriptor |
forceComponentColorModel | final public ImageWorker forceComponentColorModel()(Code) | | Reformats the
to a
preserving
transparency. This is used especially in order to go from
PackedColorModel to
ComponentColorModel , which seems to
be well accepted from
PNGEncoder and
TIFFEncoder .
This code is adapted from jai-interests mailing list archive.
this ImageWorker. See Also: FormatDescriptor |
forceComponentColorModel | final public ImageWorker forceComponentColorModel(boolean checkTransparent)(Code) | | Reformats the
to a
preserving
transparency. This is used especially in order to go from
PackedColorModel to
ComponentColorModel , which seems to
be well accepted from
PNGEncoder and
TIFFEncoder .
This code is adapted from jai-interests mailing list archive.
Parameters: checkTransparent - tells this method to not consider fully transparent pixelswhen optimizing grayscale palettes. this ImageWorker. See Also: FormatDescriptor |
forceIndexColorModelForGIF | final public ImageWorker forceIndexColorModelForGIF(boolean errorDiffusion)(Code) | | Converts the image to a GIF-compliant image. This method has been created
in order to convert the input image to a form that is compatible with the
GIF model. It first remove the information about transparency since the
error diffusion and the error dither operations are unable to process
images with more than 3 bands. Afterwards the image is processed with an
error diffusion operator in order to reduce the number of bands from 3 to
1 and the number of color to 216. A suitable layout is used for the final
image via the
in order to
take into account the different layout model for the final image.
Tip: For optimizing writing GIF, we need to create the
image untiled. This can be done by invoking
(
, Boolean.FALSE)
first.
Parameters: errorDiffusion - Tells if I should use ErrorDiffusionDescriptor orOrderedDitherDescriptor JAi operations. this ImageWorker. See Also: ImageWorker.isIndexed See Also: ImageWorker.forceIndexColorModel See Also: ImageWorker.forceBitmaskIndexColorModel |
format | final public ImageWorker format(int dataType)(Code) | | Formats the underlying image to the provided data type.
Parameters: dataType - to be used for this FormatDescriptor operation. this ImageWorker |
getMaximums | final public double[] getMaximums()(Code) | | Returns the maximal values found in every
bands. If a
is defined, then the statistics
will be computed only over that region.
See Also: ImageWorker.getMinimums See Also: ImageWorker.setROI |
getMinimums | final public double[] getMinimums()(Code) | | Returns the minimal values found in every
bands. If a
is defined, then the statistics
will be computed only over that region.
See Also: ImageWorker.getMaximums See Also: ImageWorker.setROI |
getRenderingHints | final public RenderingHints getRenderingHints()(Code) | | Returns the rendering hints for an image to be computed by this class.
The default implementation returns the following hints:
- An
with tiles size computed automatically
from the current
size.
- Any additional hints specified through the
ImageWorker.setRenderingHint method. If the
user provided explicitly a
JAI.KEY_IMAGE_LAYOUT , then the user layout has
precedence over the automatic layout computed in previous step.
The rendering hints to use for image computation (never null ). |
getTransparentPixel | final public int getTransparentPixel()(Code) | | Returns the transparent pixel value, or -1 if none.
|
intensity | final public ImageWorker intensity()(Code) | | Creates an image which represents approximatively the intensity of
. The result is always a single-banded image. If the
image uses an
, then this
method just
without
any further processing. Otherwise, this method performs a simple
operation on the
in order to come up with a simple estimation of the
intensity of the image based on the average value of the color
components. It is worthwhile to note that the alpha band is stripped from
the image.
this ImageWorker. See Also: BandCombineDescriptor |
invert | final public ImageWorker invert()(Code) | | Inverts the pixel values of the
.
See Also: InvertDescriptor |
isColorSpaceGRAYScale | final public boolean isColorSpaceGRAYScale()(Code) | | Returns
true if the
uses a GrayScale
. Note that a GrayScale color space
doesn't mean that pixel values are directly stored as GrayScale
component. The image may be
as well.
See Also: ImageWorker.forceColorSpaceGRAYScale |
isColorSpaceRGB | final public boolean isColorSpaceRGB()(Code) | | Returns
true if the
uses a RGB
. Note that a RGB color space doesn't mean that pixel values are directly stored
as RGB components. The image may be
as well.
See Also: ImageWorker.forceColorSpaceRGB |
load | final public void load(String source, int imageChoice, boolean readMetadata)(Code) | | Loads an image using the provided file name and the
, which are used to control caching and layout.
Parameters: source - Filename of the source image to read. Parameters: imageChoice - Image index in multipage images. Parameters: readMatadata - If true , metadata will be read. |
loadPlanarImageImage | public static PlanarImage loadPlanarImageImage(String source, RenderingHints hints, int imageChoice, boolean readMetadata)(Code) | | Loads an image using the provided file name and the provided hints, which
are used to control caching and layout.
Parameters: source - The source image. Parameters: hints - The hints to use. Parameters: imageChoice - For multipage images. The loaded image. |
main | public static void main(String[] args)(Code) | | Loads the image from the specified file, and
it in a window. This method is mostly as a convenient way to test
operation chains. This method can be invoked from the command line. If an
optional
-operation argument is provided, the Java method (one of
the image operations provided in this class) immediately following it is
executed. Example:
java org.geotools.image.ImageWorker -operation binarize <var><filename></var>
|
makeColorTransparent | final public ImageWorker makeColorTransparent(Color transparentColor) throws IllegalStateException(Code) | | Replaces all occurences of the given color (usually opaque) by a fully transparent color.
Currents implementation supports image backed by any
IndexColorModel , or by
ComponentColorModel with
DataBuffer.TYPE_BYTE TYPE_BYTE . More types
may be added in future GeoTools versions.
Parameters: transparentColor - The color to make transparent. this image worker. throws: IllegalStateException - if the current has an unsupported colormodel. |
mask | final public ImageWorker mask(RenderedImage mask, boolean maskValue, int newValue)(Code) | | Applies the specified mask over the current
. The mask should be
- if it is not, this method will do it itself.
Then, for every pixels in the mask with value equals to
maskValue , the
corresponding pixel in the
will be set to the specified
newValue .
Note: current implementation force the color model to an
one. Future versions may avoid this change.
Parameters: mask - The mask to apply, as a image. Parameters: maskValue - The mask value to search for ( false for 0 or true for 1). Parameters: newValue - The new value for every pixels in corresponding to maskValue in the mask. this ImageWorker. newValue maskValue false |
maskIndexColorModelByte | final public ImageWorker maskIndexColorModelByte(Color transparentColor)(Code) | | For an image backed by an
IndexColorModel , replaces all occurences of the given
color (usually opaque) by a fully transparent color.
Parameters: transparentColor - The color to make transparent. this image worker.ImageWorker.makeColorTransparent |
multiplyConst | final public ImageWorker multiplyConst(double[] inValues)(Code) | | Takes one rendered or renderable image and an array of double constants, and multiplies
every pixel of the same band of the source by the constant from the corresponding array
entry. See JAI
MultiplyConstDescriptor for details.
Parameters: inValues - The constants to be multiplied. this ImageWorker. See Also: MultiplyConstDescriptor |
removeRenderingHint | final public ImageWorker removeRenderingHint(RenderingHints.Key key)(Code) | | Removes a rendering hint. Note that invoking this method is not the same
than invoking
(key, null) .
This is especially true for the
hint:
(
,
null) disables the use of any tile cache. In other words, this method call do
request a tile cache, which happen to be the "null" cache.
removeRenderingHint(
) unsets any tile cache
specified by a previous rendering hint. All images to be computed after this method
call will save their tiles in the
.
This ImageWorker |
rescaleToBytes | final public ImageWorker rescaleToBytes()(Code) | | Rescales the
such that it uses 8 bits. If the image already uses 8 bits,
then this method does nothing. Otherwise this method computes the minimum and maximum values
for each band,
them in the range
[0 .. 255] and force the resulting image to
DataBuffer.TYPE_BYTE TYPE_BYTE .
This ImageWorker See Also: ImageWorker.isBytes See Also: RescaleDescriptor |
retainBands | final public ImageWorker retainBands(int numBands)(Code) | | Retains inconditionnaly the first
numBands of
.
All other bands (if any) are discarted without any further processing.
This method does nothing if the current
does not have
a greater amount of bands than
numBands .
Parameters: numBands - the number of bands to retain. this ImageWorker. See Also: ImageWorker.getNumBands See Also: ImageWorker.retainFirstBand See Also: BandSelectDescriptor |
setImage | final public ImageWorker setImage(RenderedImage image)(Code) | | Prepare this builder for the specified image. The images to be computed (if any)
will save their tiles in the default
.
Parameters: image - The source image. |
setRenderingHint | final public ImageWorker setRenderingHint(RenderingHints.Key key, Object value)(Code) | | Sets a rendering hint tile to use for all images to be computed by this class. This method
applies only to the next images to be computed; images already computed before this method
call (if any) will not be affected.
Some common examples:
setRenderingHint(
, null)
disables completly the tile cache.
setRenderingHint(
, Boolean.FALSE)
forces all operators to produce untiled images.
This ImageWorker |
tile | final public ImageWorker tile()(Code) | | If the was not already tiled, tile it. Note that no tiling will be done
if 'getRenderingHints()' failed to suggest a tile size. This method is
for internal use by
ImageWorker.write methods only.
this ImageWorker. |
tileCacheEnabled | final public ImageWorker tileCacheEnabled(boolean status)(Code) | | If
false , disables the tile cache. Invoking this method with value
true cancel the last invocation with value
false . If this method was invoking many
time with value
false , then this method must be invoked the same amount of time
with the value
true for reenabling the cache.
Note: This method name doesn't contain the usual
set prefix
because it doesn't really set a flag. Instead it increments or decrements a counter.
This ImageWorker |
write | final public ImageWorker write(File output) throws IOException(Code) | | Writes the
to the specified file. This method differs
from
ImageIO.write(StringFile) in a number of ways:
- The
to use is inferred from the file
extension.
- If the image writer accepts
File objects as input, then the
file argument is given directly without creating an
ImageOutputStream object.
This is important for some formats like HDF, which work only with files.
- If the
is not tiled, then it is tiled prior to be written.
- If some special processing is needed for a given format, then the corresponding method
is invoked. Example:
ImageWorker.forceIndexColorModelForGIF .
this ImageWorker. |
writeGIF | final public ImageWorker writeGIF(Object destination, String compression, float compressionRate) throws IOException(Code) | | Writes outs the image contained into this
ImageWorker as a GIF
using the provided destination, compression and compression rate.
It is worth to point out that the only compressions algorithm availaible
with the jdk
GIFImageWriter is "LZW" while the compression rates
have to be confined between 0 and 1. AN acceptable values is usally 0.75f.
The destination object can be anything providing that we have an
ImageOutputStreamSpi that recognizes it.
Parameters: destination - where to write the internal ImageWorker.image as a gif. Parameters: compression - The name of compression algorithm. Parameters: compressionRate - percentage of compression, as a number between 0 and 1. this ImageWorker. throws: IOException - In case an error occurs during the search for anImageOutputStream or during the eoncding process. See Also: ImageWorker.forceIndexColorModelForGIF(boolean) |
writeJPEG | final public void writeJPEG(Object destination, String compression, float compressionRate, boolean nativeAcc) throws IOException(Code) | | Writes outs the image contained into this
ImageWorker as a JPEG
using the provided destination , compression and compression rate.
The destination object can be anything providing that we have an
ImageOutputStreamSpi that recognizes it.
Parameters: destination - where to write the internal ImageWorker.image as a JPEG. Parameters: compression - algorithm. Parameters: compressionRate - percentage of compression. Parameters: nativeAcc - should we use native acceleration. this ImageWorker. throws: IOException - In case an error occurs during the search for anImageOutputStream or during the eoncding process. |
writePNG | final public void writePNG(Object destination, String compression, float compressionRate, boolean nativeAcc, boolean paletted) throws IOException(Code) | | Writes outs the image contained into this
ImageWorker as a PNG
using the provided destination, compression and compression rate.
The destination object can be anything providing that we have an
ImageOutputStreamSpi that recognizes it.
Parameters: destination - where to write the internal ImageWorker.image as a PNG. Parameters: compression - algorithm. Parameters: compressionRate - percentage of compression. Parameters: nativeAcc - should we use native acceleration. Parameters: paletted - should we write the png as 8 bits? this ImageWorker. throws: IOException - In case an error occurs during the search for anImageOutputStream or during the eoncding process.ImageOutputStream |
xorConst | final public ImageWorker xorConst(int[] values)(Code) | | Takes one rendered or renderable image and an array of integer constants, and performs a
bit-wise logical "xor" between every pixel in the same band of the source and the constant
from the corresponding array entry. See JAI
XorConstDescriptor for details.
See Also: XorConstDescriptor |
|
|