Class ImageUtil
- java.lang.Object
-
- org.exoplatform.imageio.plugins.common.ImageUtil
-
public class ImageUtil extends Object
version: openjdk-7-ea-src-b35-11_sep_2008
-
-
Constructor Summary
Constructors Constructor Description ImageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcanEncodeImage(ImageWriter writer, ColorModel colorModel, SampleModel sampleModel)Checks that the providedImageWritercan encode the providedColorModelandSampleModel.static voidcanEncodeImage(ImageWriter writer, ImageTypeSpecifier type)Checks that the providedImageWritercan encode the providedImageTypeSpecifieror not.static StringconvertObjectToString(Object obj)Converts the provided object toStringstatic ColorModelcreateColorModel(ColorSpace colorSpace, SampleModel sampleModel)static ColorModelcreateColorModel(SampleModel sampleModel)Creates aColorModelthat may be used with the specifiedSampleModel.static longgetBandSize(SampleModel sm)static intgetElementSize(SampleModel sm)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 longgetTileSize(SampleModel sm)static byte[]getUnpackedBinaryData(Raster raster, Rectangle rect)Returns the binary data unpacked into an array of bytes.static booleanimageIsContiguous(RenderedImage image)Returns whether the image has contiguous data across rows.static booleanisBinary(SampleModel sm)static booleanisIndicesForGrayscale(byte[] r, byte[] g, byte[] b)Tests whether the color indices represent a gray-scale image.static voidsetPackedBinaryData(byte[] binaryDataArray, WritableRaster raster, Rectangle rect)Sets the suppliedRaster's data from an array of packed binary data of the form returned bygetPackedBinaryData().static voidsetUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect)Copies data into the packed array of theRasterfrom an array of unpacked data of the form returned bygetUnpackedBinaryData().
-
-
-
Method Detail
-
createColorModel
public static final ColorModel createColorModel(SampleModel sampleModel)
Creates aColorModelthat may be used with the specifiedSampleModel. If a suitableColorModelcannot be found, this method returnsnull.Suitable
ColorModels are guaranteed to exist for all instances ofComponentSampleModel. For 1- and 3- bandedSampleModels, the returnedColorModelwill be opaque. For 2- and 4-bandedSampleModels, 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
DirectColorModelwill be created for instances ofSinglePixelPackedSampleModelwith no more than 4 bands.An instance of
IndexColorModelwill be created for instances ofMultiPixelPackedSampleModel. The colormap will be a grayscale ramp with1 << numberOfBitsentries ranging from zero to at most 255.- Returns:
- An instance of
ColorModelthat is suitable for the suppliedSampleModel, ornull. - Throws:
IllegalArgumentException- IfsampleModelisnull.
-
getPackedBinaryData
public static byte[] getPackedBinaryData(Raster raster, Rectangle rect)
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
nullif the data are not binary. - Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
getUnpackedBinaryData
public static byte[] getUnpackedBinaryData(Raster raster, Rectangle rect)
Returns the binary data unpacked into an array of bytes. The line stride will be the width of theRaster.- Throws:
IllegalArgumentException- ifisBinary()returnsfalsewith theSampleModelof the suppliedRasteras 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()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
setUnpackedBinaryData
public static void setUnpackedBinaryData(byte[] bdata, WritableRaster raster, Rectangle rect)Copies data into the packed array of theRasterfrom 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()returnsfalsewith theSampleModelof the suppliedRasteras argument.
-
isBinary
public static boolean isBinary(SampleModel sm)
-
createColorModel
public static ColorModel createColorModel(ColorSpace colorSpace, SampleModel sampleModel)
-
getElementSize
public static int getElementSize(SampleModel sm)
-
getTileSize
public static long getTileSize(SampleModel sm)
-
getBandSize
public static long getBandSize(SampleModel sm)
-
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
public static String convertObjectToString(Object obj)
Converts the provided object toString
-
canEncodeImage
public static final void canEncodeImage(ImageWriter writer, ImageTypeSpecifier type) throws IIOException
Checks that the providedImageWritercan encode the providedImageTypeSpecifieror not. If not, anIIOExceptionwill 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 providedImageWritercan encode the providedColorModelandSampleModel. If not, anIIOExceptionwill be thrown.- Parameters:
writer- The providedImageWriter.colorModel- The providedColorModel.sampleModel- The providedSampleModel.- Throws:
IIOException- If the writer cannot encoded the provided image.
-
imageIsContiguous
public static final boolean imageIsContiguous(RenderedImage image)
Returns whether the image has contiguous data across rows.
-
-