javax.imageio

Class ImageTypeSpecifier

public class ImageTypeSpecifier extends Object

ImageTypeSpecifier store the color and sample models associated with an IIOImage.
Field Summary
protected ColorModelcolorModel
The image's color model.
protected SampleModelsampleModel
The image's sample model.
Constructor Summary
ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)
Construct an image type specifier with the given models.
ImageTypeSpecifier(RenderedImage image)
Construct an image type specifier that describes the given rendered image.
Method Summary
static ImageTypeSpecifiercreateBanded(ColorSpace colorSpace, int[] bankIndices, int[] bankOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
Create an image type specifier for a banded image using a component color model and a banded sample model.
BufferedImagecreateBufferedImage(int width, int height)
Create a buffered image with the given dimensions using that has the characteristics specified by this image type specifier.
static ImageTypeSpecifiercreateFromBufferedImageType(int bufferedImageType)
Create an image type specifier that describes the given buffered image type.
static ImageTypeSpecifiercreateFromRenderedImage(RenderedImage image)
Create an image type specifier that describes the given rendered image's type.
static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned)
Create a grayscale image type specifier, given the number of bits, data type and whether or not the data is signed.
static ImageTypeSpecifiercreateGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied)
Create a grayscale image type specifier, given the number of bits, data type and whether or not the data is signed.
static ImageTypeSpecifiercreateIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType)
Return an image type specifier for an image that uses an indexed colour model where each colour value has the specified number of bits and type and where the colour tables are those given.
static ImageTypeSpecifiercreateInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
Create an image type specifier that uses a component colour model and a pixel interleaved sample model.
static ImageTypeSpecifiercreatePacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied)
Create an image type specifier using a direct color model and a packed sample model.
intgetBitsPerBand(int band)
Get the number of bits per sample in the given band.
intgetBufferedImageType()
Get the buffered image constant specified by this image type specifier.
ColorModelgetColorModel()
Get the color model specified by this image type specifier.
intgetNumBands()
Get the number of bands specified by this image type specifier's sample model.
intgetNumComponents()
Get the number of components specified by this image type specifier's color model.
SampleModelgetSampleModel(int width, int height)
Create a sample model that is compatible with the one specified by this image type specifier, with the given dimensions.
SampleModelgetSampleModel()
Get the sample model specified by this image type specifier.

Field Detail

colorModel

protected ColorModel colorModel
The image's color model.

sampleModel

protected SampleModel sampleModel
The image's sample model.

Constructor Detail

ImageTypeSpecifier

public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)
Construct an image type specifier with the given models.

Parameters: colorModel the color model sampleModel the sample model

Throws: IllegalArgumentException if either model argument is null IllegalArgumentException if the models are incompatible with one another

ImageTypeSpecifier

public ImageTypeSpecifier(RenderedImage image)
Construct an image type specifier that describes the given rendered image.

Parameters: image a rendered image

Throws: IllegalArgumentException if image is null

Method Detail

createBanded

public static ImageTypeSpecifier createBanded(ColorSpace colorSpace, int[] bankIndices, int[] bankOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
Create an image type specifier for a banded image using a component color model and a banded sample model.

Parameters: colorSpace the color space bankIndices the bank indices at which each band will be stored bandOffsets the starting band offset for each band within its bank dataType the data type, a DataBuffer constant hasAlpha true if this image type specifier should have an alpha component, false otherwise isAlphaPremultiplied true if other color components should be premultiplied by the alpha component, false otherwise

Returns: a banded image type specifier

Throws: IllegalArgumentException if any of colorSpace, bankIndices or bankOffsets is null IllegalArgumentException if bankIndices and bankOffsets differ in length if dataType is not a valid DataBuffer constant

UNKNOWN: IllegalArgumentException if the number of color space components, including the alpha component if requested, is different from bandOffsets.length

createBufferedImage

public BufferedImage createBufferedImage(int width, int height)
Create a buffered image with the given dimensions using that has the characteristics specified by this image type specifier.

Parameters: the width of the buffered image, in pixels the height of the buffered image, in pixels

Returns: a buffered image

Throws: IllegalArgumentException if either width or height is less than or equal to zero IllegalArgumentException if width * height is greater than Integer.MAX_VALUE or if the storage required is greater than Integer.MAX_VALUE

createFromBufferedImageType

public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType)
Create an image type specifier that describes the given buffered image type.

Parameters: bufferedImageType the buffered image type to represent with the returned image type specifier

Returns: a new image type specifier

Throws: IllegalArgumentException if bufferedImageType is not a BufferedImage constant or is BufferedImage.TYPE_CUSTOM

createFromRenderedImage

public static ImageTypeSpecifier createFromRenderedImage(RenderedImage image)
Create an image type specifier that describes the given rendered image's type.

Parameters: image the rendered image

Returns: a new image type specifier

Throws: IllegalArgumentException if image is null

createGrayscale

public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned)
Create a grayscale image type specifier, given the number of bits, data type and whether or not the data is signed.

Parameters: bits the number of bits used to specify a greyscale value dataType a DataBuffer type constant isSigned true if this type specifier should support negative values, false otherwise

Returns: a greyscal image type specifier

Throws: IllegalArgumentException if bits is not 1, 2, 4, 8 or 16 IllegalArgumentException if dataType is not DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or DataBuffer.TYPE_USHORT if bits is larger than the number of bits in the given data type

createGrayscale

public static ImageTypeSpecifier createGrayscale(int bits, int dataType, boolean isSigned, boolean isAlphaPremultiplied)
Create a grayscale image type specifier, given the number of bits, data type and whether or not the data is signed.

Parameters: bits the number of bits used to specify a greyscale value dataType a DataBuffer type constant isSigned true if this type specifier should support negative values, false otherwise

Returns: a greyscal image type specifier

Throws: IllegalArgumentException if bits is not 1, 2, 4, 8 or 16 IllegalArgumentException if dataType is not DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or DataBuffer.TYPE_USHORT if bits is larger than the number of bits in the given data type

createIndexed

public static ImageTypeSpecifier createIndexed(byte[] redLUT, byte[] greenLUT, byte[] blueLUT, byte[] alphaLUT, int bits, int dataType)
Return an image type specifier for an image that uses an indexed colour model where each colour value has the specified number of bits and type and where the colour tables are those given.

Parameters: redLUT the red index values greenLUT the green index values blueLUT the blue index values alphaLUT the alpha index values bits the number of bits per index value dataType the type of each index value

Returns: an indexed image type specifier

Throws: IllegalArgumentException if any of the colour arrays, not including alphaLUT, is null IllegalArgumentException if bits is not 1, 2, 4, 8 or 16 IllegalArgumentException if dataType is not DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or DataBuffer.TYPE_USHORT if bits is larger than the number of bits in the given data type

createInterleaved

public static ImageTypeSpecifier createInterleaved(ColorSpace colorSpace, int[] bandOffsets, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied)
Create an image type specifier that uses a component colour model and a pixel interleaved sample model. Each pixel component will be stored in a separate value of the given data type.

Parameters: colorSpace the colour space used by the colour model bandOffsets the starting band offset for each band within its bank dataType the type of each pixel value hasAlpha true if an alpha channel should be specified, false otherwise isAlphaPremultiplied true if other colour channels should be premultiplied by the alpha value, false otherwise

Returns: an interleaved image type specifier

Throws: IllegalArgumentException if either colorSpace or bandOffsets is null if dataType is not a valid DataBuffer constant

UNKNOWN: IllegalArgumentException if the number of color space components, including the alpha component if requested, is different from bandOffsets.length

createPacked

public static ImageTypeSpecifier createPacked(ColorSpace colorSpace, int redMask, int greenMask, int blueMask, int alphaMask, int transferType, boolean isAlphaPremultiplied)
Create an image type specifier using a direct color model and a packed sample model. All pixel components will be packed into one value of the given data type.

Parameters: colorSpace the color space to use in the color model redMask the bitmask for the red bits greenMask the bitmask for the green bits blueMask the bitmask for the blue bits alphaMask the bitmask for the alpha bits transferType the data type used to store pixel values isAlphaPremultiplied true if other colour channels should be premultiplied by the alpha value, false otherwise

Returns: a packed image type specifier

Throws: IllegalArgumentException if colorSpace is null IllegalArgumentException if colorSpace does not have type ColorSpace.TYPE_RGB IllegalArgumentException if all masks are 0 IllegalArgumentException if dataType is not DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or DataBuffer.TYPE_INT

getBitsPerBand

public int getBitsPerBand(int band)
Get the number of bits per sample in the given band.

Parameters: band the band from which to get the number of bits

Returns: the number of bits in the given band

Throws: IllegalArgumentException if band is out-of-bounds

getBufferedImageType

public int getBufferedImageType()
Get the buffered image constant specified by this image type specifier.

Returns: a buffered image constant

getColorModel

public ColorModel getColorModel()
Get the color model specified by this image type specifier.

Returns: the color model

getNumBands

public int getNumBands()
Get the number of bands specified by this image type specifier's sample model.

Returns: the number of bands in the sample model

getNumComponents

public int getNumComponents()
Get the number of components specified by this image type specifier's color model.

Returns: the number of color components per pixel

getSampleModel

public SampleModel getSampleModel(int width, int height)
Create a sample model that is compatible with the one specified by this image type specifier, with the given dimensions.

Parameters: width the width of the returned sample model height the height of the returned sample model

Returns: a sample model compatible with the one in this image type specifier, with the given dimensions

Throws: IllegalArgumentException if either width or height is less than or equal to 0 IllegalArgumentException if width * height is greater than Intere.MAX_VALUE

getSampleModel

public SampleModel getSampleModel()
Get the sample model specified by this image type specifier.

Returns: the sample model