Class ImageUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final void
canEncodeImage
(ImageWriter writer, ColorModel colorModel, SampleModel sampleModel) Checks that the providedImageWriter
can encode the providedColorModel
andSampleModel
.static final void
canEncodeImage
(ImageWriter writer, ImageTypeSpecifier type) Checks that the providedImageWriter
can encode the providedImageTypeSpecifier
or not.static String
Converts the provided object toString
static ColorModel
createColorModel
(ColorSpace colorSpace, SampleModel sampleModel) static final ColorModel
createColorModel
(SampleModel sampleModel) Creates aColorModel
that may be used with the specifiedSampleModel
.static long
static final ImageTypeSpecifier
getDestinationType
(ImageReadParam param, Iterator imageTypes) Gets the destination image type.static int
static List
getJDKImageReaderWriterSPI
(ServiceRegistry registry, String formatName, boolean isReader) (package private) static int
getJvmVersion
(String jvmSpecificationVersion) static byte[]
getPackedBinaryData
(Raster raster, Rectangle rect) For the case of binary data (isBinary()
returnstrue
), return the binary data as a packed byte array.static long
static byte[]
getUnpackedBinaryData
(Raster raster, Rectangle rect) Returns the binary data unpacked into an array of bytes.static final boolean
imageIsContiguous
(RenderedImage image) Returns whether the image has contiguous data across rows.static boolean
isBinary
(SampleModel sm) static boolean
Tests whether the color indices represent a gray-scale image with the indicated number of bits over the color component range [0,255].static boolean
isIndicesForGrayscale
(byte[] r, byte[] g, byte[] b) Tests whether the color indices represent a gray-scale image.static boolean
Returnstrue
if the givenColorSpace
object is an instance ofICC_ColorSpace
but is not one of the standardColorSpace
s returned byColorSpace.getInstance()
.static void
processOnRegistration
(ServiceRegistry registry, Class category, String formatName, ImageReaderWriterSpi spi, int deregisterJvmVersion, int priorityJvmVersion) static int
static void
setPackedBinaryData
(byte[] binaryDataArray, WritableRaster raster, Rectangle rect) Sets the suppliedRaster
's data from an array of packed binary data of the form returned bygetPackedBinaryData()
.static void
setUnpackedBinaryData
(byte[] bdata, WritableRaster raster, Rectangle rect) Copies data into the packed array of theRaster
from an array of unpacked data of the form returned bygetUnpackedBinaryData()
.
-
Constructor Details
-
ImageUtil
public ImageUtil()
-
-
Method Details
-
createColorModel
Creates aColorModel
that may be used with the specifiedSampleModel
. If a suitableColorModel
cannot be found, this method returnsnull
.Suitable
ColorModel
s are guaranteed to exist for all instances ofComponentSampleModel
. For 1- and 3- bandedSampleModel
s, the returnedColorModel
will be opaque. For 2- and 4-bandedSampleModel
s, the output will use alpha transparency which is not premultiplied. 1- and 2-banded data will use a grayscaleColorSpace
, and 3- and 4-banded data a sRGBColorSpace
. Data with 5 or more bands will have aBogusColorSpace
.An instance of
DirectColorModel
will be created for instances ofSinglePixelPackedSampleModel
with no more than 4 bands.An instance of
IndexColorModel
will be created for instances ofMultiPixelPackedSampleModel
. The colormap will be a grayscale ramp with1 invalid input: '<'invalid input: '<' numberOfBits
entries ranging from zero to at most 255.- Returns:
- An instance of
ColorModel
that is suitable for the suppliedSampleModel
, ornull
. - Throws:
IllegalArgumentException
- IfsampleModel
isnull
.
-
getPackedBinaryData
For the case of binary data (isBinary()
returnstrue
), return the binary data as a packed byte array. The data will be packed as eight bits per byte with no bit offset, i.e., the first bit in each image line will be the left-most of the first byte of the line. The line stride in bytes will be(int)((getWidth()+7)/8)
. The length of the returned array will be the line stride multiplied bygetHeight()
- Returns:
- the binary data as a packed array of bytes with zero offset
of
null
if the data are not binary. - Throws:
IllegalArgumentException
- ifisBinary()
returnsfalse
with theSampleModel
of the suppliedRaster
as argument.
-
getUnpackedBinaryData
Returns the binary data unpacked into an array of bytes. The line stride will be the width of theRaster
.- Throws:
IllegalArgumentException
- ifisBinary()
returnsfalse
with theSampleModel
of the suppliedRaster
as argument.
-
setPackedBinaryData
public static void setPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect) Sets the suppliedRaster
's data from an array of packed binary data of the form returned bygetPackedBinaryData()
.- Throws:
IllegalArgumentException
- ifisBinary()
returnsfalse
with theSampleModel
of the suppliedRaster
as argument.
-
setUnpackedBinaryData
Copies data into the packed array of theRaster
from an array of unpacked data of the form returned bygetUnpackedBinaryData()
.If the data are binary, then the target bit will be set if and only if the corresponding byte is non-zero.
- Throws:
IllegalArgumentException
- ifisBinary()
returnsfalse
with theSampleModel
of the suppliedRaster
as argument.
-
isBinary
-
createColorModel
-
getElementSize
-
getTileSize
-
getBandSize
-
isGrayscaleMapping
Tests whether the color indices represent a gray-scale image with the indicated number of bits over the color component range [0,255]. The grayscale mapping may be inverted, i.e., 0 -> 255 and mapSize -> 0.- Parameters:
icm
- The gray-to-color mapping.- Returns:
- Whether the
IndexColorModel
maps indexi
to((255*i)/icm.getMapSize()-1)
. - Throws:
IllegalArgumentException
- ificm
isnull
.
-
isIndicesForGrayscale
public static boolean isIndicesForGrayscale(byte[] r, byte[] g, byte[] b) Tests whether the color indices represent a gray-scale image.- Parameters:
r
- The red channel color indices.g
- The green channel color indices.b
- The blue channel color indices.- Returns:
- If all the indices have 256 entries, and are identical mappings,
return
true
; otherwise, returnfalse
.
-
convertObjectToString
Converts the provided object toString
-
canEncodeImage
public static final void canEncodeImage(ImageWriter writer, ImageTypeSpecifier type) throws IIOException Checks that the providedImageWriter
can encode the providedImageTypeSpecifier
or not. If not, anIIOException
will be thrown.- Parameters:
writer
- The providedImageWriter
.type
- The image to be tested.- Throws:
IIOException
- If the writer cannot encoded the provided image.
-
canEncodeImage
public static final void canEncodeImage(ImageWriter writer, ColorModel colorModel, SampleModel sampleModel) throws IIOException Checks that the providedImageWriter
can encode the providedColorModel
andSampleModel
. If not, anIIOException
will be thrown.- Parameters:
writer
- The providedImageWriter
.colorModel
- The providedColorModel
.sampleModel
- The providedSampleModel
.- Throws:
IIOException
- If the writer cannot encoded the provided image.
-
imageIsContiguous
Returns whether the image has contiguous data across rows. -
getDestinationType
public static final ImageTypeSpecifier getDestinationType(ImageReadParam param, Iterator imageTypes) throws IIOException Gets the destination image type.- Throws:
IIOException
-
isNonStandardICCColorSpace
Returnstrue
if the givenColorSpace
object is an instance ofICC_ColorSpace
but is not one of the standardColorSpace
s returned byColorSpace.getInstance()
.- Parameters:
cs
- TheColorSpace
to test.
-
getJDKImageReaderWriterSPI
public static List getJDKImageReaderWriterSPI(ServiceRegistry registry, String formatName, boolean isReader) -
processOnRegistration
public static void processOnRegistration(ServiceRegistry registry, Class category, String formatName, ImageReaderWriterSpi spi, int deregisterJvmVersion, int priorityJvmVersion) -
getJvmVersion
-
readMultiByteInteger
- Throws:
IOException
-