Class RawImageInputStream
- java.lang.Object
-
- com.sun.media.imageio.stream.RawImageInputStream
-
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
,ImageInputStream
public class RawImageInputStream extends Object implements ImageInputStream
This class defines the content of theImageInputStream
containing several raw images with the same image type: the number of the images, the image type, the offset for the first sample of each image, and the image size information.ImageInputStream
methods are not commented individually. These methods merely forward the call to theImageInputStream
specified when theRawImageInputStream
is constructed.
-
-
Constructor Summary
Constructors Constructor Description RawImageInputStream(ImageInputStream source, SampleModel sampleModel, long[] imageOffsets, Dimension[] imageDimensions)
Constructor.RawImageInputStream(ImageInputStream source, ImageTypeSpecifier type, long[] imageOffsets, Dimension[] imageDimensions)
Constructor.RawImageInputStream(ImageInputStream source, InputSource xmlSource)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
void
flushBefore(long pos)
int
getBitOffset()
ByteOrder
getByteOrder()
long
getFlushedPosition()
Dimension
getImageDimension(int imageIndex)
Retrieves the dimnsion of theimageIndex
th image.long
getImageOffset(int imageIndex)
Retrieves the image offset of theimageIndex
th image.ImageTypeSpecifier
getImageType()
Retrieves the image type.int
getNumImages()
Retrieves the number of images in theImageInputStream
.long
getStreamPosition()
boolean
isCached()
boolean
isCachedFile()
boolean
isCachedMemory()
long
length()
void
mark()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
int
readBit()
long
readBits(int numBits)
boolean
readBoolean()
byte
readByte()
void
readBytes(IIOByteBuffer buf, int len)
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
void
readFully(char[] c, int off, int len)
void
readFully(double[] d, int off, int len)
void
readFully(float[] f, int off, int len)
void
readFully(int[] i, int off, int len)
void
readFully(long[] l, int off, int len)
void
readFully(short[] s, int off, int len)
int
readInt()
String
readLine()
long
readLong()
short
readShort()
int
readUnsignedByte()
long
readUnsignedInt()
int
readUnsignedShort()
String
readUTF()
void
reset()
void
seek(long pos)
void
setBitOffset(int bitOffset)
void
setByteOrder(ByteOrder byteOrder)
int
skipBytes(int n)
long
skipBytes(long n)
-
-
-
Constructor Detail
-
RawImageInputStream
public RawImageInputStream(ImageInputStream source, ImageTypeSpecifier type, long[] imageOffsets, Dimension[] imageDimensions)
Constructor.- Parameters:
source
- TheImageInputStream
containing all the raw images.type
- TheImageTypeSpecifier
for all the images in the stream.imageOffsets
- The position of the first sample for each image in the stream.imageDimensions
- The image size for each image in the stream.- Throws:
IllegalArgumentException
- If the sizes ofimageOffsets
andimageDimensions
are different or if either array is null.
-
RawImageInputStream
public RawImageInputStream(ImageInputStream source, SampleModel sampleModel, long[] imageOffsets, Dimension[] imageDimensions)
Constructor.This constructor is the same as
RawImageInputStream(ImageInputStream,ImageTypeSpecifier, long[],Dimension[])
except that aSampleModel
is supplied instead of anImageTypeSpecifier
. This constructor creates aColorModel
for the suppliedSampleModel
and then creates anImageTypeSpecifier
.Suitable
ColorModel
s are guaranteed to exist for all instances ofComponentSampleModel
. For 1- and 3- bandedSampleModel
s, theColorModel
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 use aColorSpace
which satisfies compatibility constraints but is merely a placeholder and does not perform correct color conversion to and from the C.I.E. XYZ and sRGB color spaces.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 << numberOfBits
entries ranging from zero to at most 255.- Parameters:
source
- TheImageInputStream
containing all the raw images.sampleModel
- TheSampleModel
for all the images in the stream.imageOffsets
- The position of the first sample for each image in the stream.imageDimensions
- The image size for each image in the stream.- Throws:
IllegalArgumentException
- IfsampleModel
is null.IllegalArgumentException
- If the sizes ofimageOffsets
andimageDimensions
are different or if either array is null.IllegalArgumentException
- If it is not possible to create aColorModel
from the suppliedSampleModel
.
-
RawImageInputStream
public RawImageInputStream(ImageInputStream source, InputSource xmlSource) throws SAXException, IOException
Constructor. ThexmlSource
must adhere to the following DTD:<!DOCTYPE "com_sun_media_imageio_stream_raw_1.0" [ <!ELEMENT com_sun_media_imageio_stream_raw_1.0 (byteOrder?, offset?, width?, height?, (ComponentSampleModel | MultiPixelPackedSampleModel | SinglePixelPackedSampleModel), (ComponentColorModel | DirectColorModel | IndexColorModel)?)> <!ATTLIST com_sun_media_imageio_stream_raw_1.0 xmlns CDATA #FIXED "http://com/sun/media/imageio"> <!ELEMENT byteOrder (#PCDATA)> <!-- Byte order of data stream --> <!-- Either "NETWORK" or "REVERSE" --> <!-- Data type: String --> <!ELEMENT offset (#PCDATA)> <!-- Byte offset to the image data in the stream --> <!-- Data type: long --> <!ELEMENT width (#PCDATA)> <!-- Image width; default value is SampleModel width --> <!-- Data type: int --> <!ELEMENT height (#PCDATA)> <!-- Image height; default value is SampleModel height --> <!-- Data type: int --> <!ELEMENT ComponentSampleModel EMPTY> <!-- ComponentSampleModel --> <!ATTLIST ComponentSampleModel dataType (BYTE | USHORT | SHORT | INT | FLOAT | DOUBLE) #REQUIRED <!-- Data type: String --> w CDATA #REQUIRED <!-- SampleModel width --> <!-- Data type: int --> h CDATA #REQUIRED <!-- SampleModel height --> <!-- Data type: int --> pixelStride CDATA "1" <!-- SampleModel pixel stride --> <!-- Data type: int --> scanlineStride CDATA #REQUIRED <!-- SampleModel line stride --> <!-- Data type: int --> bankIndices CDATA #IMPLIED <!-- SampleModel bank indices --> <!-- Data type: int array --> bandOffsets CDATA #REQUIRED> <!-- SampleModel band offsets --> <!-- Data type: int array --> <!ELEMENT MultiPixelPackedSampleModel EMPTY> <!-- MultiPixelPackedSampleModel --> <!ATTLIST MultiPixelPackedSampleModel dataType (BYTE | USHORT | INT) #REQUIRED <!-- Data type: String --> w CDATA #REQUIRED <!-- SampleModel width --> <!-- Data type: int --> h CDATA #REQUIRED <!-- SampleModel height --> <!-- Data type: int --> numberOfBits CDATA #REQUIRED <!-- Number of bits per pixel --> <!-- Data type: int --> scanlineStride CDATA #REQUIRED <!-- SampleModel line stride --> <!-- Data type: int --> dataBitOffset CDATA "0"> <!-- Offset to first valid bit in a line --> <!-- Data type: int --> <!ELEMENT SinglePixelPackedSampleModel EMPTY> <!-- SinglePixelPackedSampleModel --> <!ATTLIST SinglePixelPackedSampleModel dataType (BYTE | USHORT | INT) #REQUIRED <!-- Data type: String --> w CDATA #REQUIRED <!-- SampleModel width --> <!-- Data type: int --> h CDATA #REQUIRED <!-- SampleModel height --> <!-- Data type: int --> scanlineStride CDATA #REQUIRED <!-- SampleModel line stride --> <!-- Data type: int --> bitMasks CDATA #REQUIRED> <!-- Masks indicating RGBA positions --> <!-- Data type: int --> <!ELEMENT ComponentColorModel EMPTY> <!-- ComponentColorModel --> <!ATTLIST ComponentColorModel colorSpace (CIEXYZ | GRAY | LINEAR_RGB | PYCC | sRGB | URL) #REQUIRED <!-- A string representing a predefined ColorSpace or a URI representing the location of any ICC profile from which a ColorSpace may be created. --> <!-- Data type: String --> bits CDATA #IMPLIED <!-- Number of bits per color component --> <!-- Data type: int --> hasAlpha (true | false) #REQUIRED <!-- Whether an alpha channel is present --> <!-- Data type: boolean --> isAlphaPremultiplied (true | false) #REQUIRED <!-- Whether any alpha channel is premultiplied --> <!-- Data type: boolean --> transparency (BITMASK | OPAQUE | TRANSLUCENT) #REQUIRED <!-- The type of transparency --> transferType (BYTE | USHORT | SHORT | INT | FLOAT | DOUBLE) #REQUIRED> <!-- The data transfer type --> <!ELEMENT DirectColorModel EMPTY> <!-- DirectColorModel --> <!ATTLIST DirectColorModel colorSpace (LINEAR_RGB | sRGB | URL) #IMPLIED <!-- A string representing a predefined RGB ColorSpace or a URL representing the location of any ICC profile from which an RGB ColorSpace may be created. --> <!-- Data type: String --> bits CDATA #REQUIRED <!-- Number of bits per color component --> <!-- Data type: int --> rmask CDATA #REQUIRED <!-- Bitmask of the red component --> <!-- Data type: int --> gmask CDATA #REQUIRED <!-- Bitmask of the grenn component --> <!-- Data type: int --> bmask CDATA #REQUIRED <!-- Bitmask of the blue component --> <!-- Data type: int --> amask CDATA "0"> <!-- Bitmask of the alpha component --> <!-- Data type: int --> <!ELEMENT IndexColorModel EMPTY> <!-- IndexColorModel --> <!ATTLIST IndexColorModel bits CDATA #REQUIRED <!-- Number of bits per color component --> <!-- Data type: int --> size CDATA #REQUIRED <!-- Number of elements in the colormap --> <!-- Data type: int --> r CDATA #REQUIRED <!-- Red elements of the colormap --> <!-- Data type: byte array --> g CDATA #REQUIRED <!-- Green elements of the colormap --> <!-- Data type: byte array --> b CDATA #REQUIRED <!-- Blue elements of the colormap --> <!-- Data type: byte array --> a CDATA #IMPLIED> <!-- Alpha elements of the colormap --> <!-- Data type: byte array --> ]>
- Parameters:
source
- TheImageInputStream
containing all the raw images.xmlSource
- Theorg.xml.sax.InputSource
to provide the xml document in which the stream structure is defined.- Throws:
RuntimeException
- If the parse configuration isn't correct.IllegalArgumentException
- If the number of "width" elements isn't the same as the number of "height" elements.SAXException
- If one is thrown in parsing.IOException
- If one is thrown in parsing, or creating color space from a URL.
-
-
Method Detail
-
getImageType
public ImageTypeSpecifier getImageType()
Retrieves the image type.- Returns:
- the image type
-
getImageOffset
public long getImageOffset(int imageIndex)
Retrieves the image offset of theimageIndex
th image.- Parameters:
imageIndex
- the index of the image of interest.- Returns:
- the offset in the stream to the specified image.
- Throws:
IllegalArgumentException
- If the provided parameter is out of range.
-
getImageDimension
public Dimension getImageDimension(int imageIndex)
Retrieves the dimnsion of theimageIndex
th image.- Parameters:
imageIndex
- the index of the image of interest.- Returns:
- the size of the specified image.
- Throws:
IllegalArgumentException
- If the provided parameter is out of rangle.
-
getNumImages
public int getNumImages()
Retrieves the number of images in theImageInputStream
.- Returns:
- the number of image in the stream.
-
setByteOrder
public void setByteOrder(ByteOrder byteOrder)
- Specified by:
setByteOrder
in interfaceImageInputStream
-
getByteOrder
public ByteOrder getByteOrder()
- Specified by:
getByteOrder
in interfaceImageInputStream
-
read
public int read() throws IOException
- Specified by:
read
in interfaceImageInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
- Specified by:
read
in interfaceImageInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Specified by:
read
in interfaceImageInputStream
- Throws:
IOException
-
readBytes
public void readBytes(IIOByteBuffer buf, int len) throws IOException
- Specified by:
readBytes
in interfaceImageInputStream
- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException
- Specified by:
readBoolean
in interfaceDataInput
- Specified by:
readBoolean
in interfaceImageInputStream
- Throws:
IOException
-
readByte
public byte readByte() throws IOException
- Specified by:
readByte
in interfaceDataInput
- Specified by:
readByte
in interfaceImageInputStream
- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException
- Specified by:
readUnsignedByte
in interfaceDataInput
- Specified by:
readUnsignedByte
in interfaceImageInputStream
- Throws:
IOException
-
readShort
public short readShort() throws IOException
- Specified by:
readShort
in interfaceDataInput
- Specified by:
readShort
in interfaceImageInputStream
- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException
- Specified by:
readUnsignedShort
in interfaceDataInput
- Specified by:
readUnsignedShort
in interfaceImageInputStream
- Throws:
IOException
-
readChar
public char readChar() throws IOException
- Specified by:
readChar
in interfaceDataInput
- Specified by:
readChar
in interfaceImageInputStream
- Throws:
IOException
-
readInt
public int readInt() throws IOException
- Specified by:
readInt
in interfaceDataInput
- Specified by:
readInt
in interfaceImageInputStream
- Throws:
IOException
-
readUnsignedInt
public long readUnsignedInt() throws IOException
- Specified by:
readUnsignedInt
in interfaceImageInputStream
- Throws:
IOException
-
readLong
public long readLong() throws IOException
- Specified by:
readLong
in interfaceDataInput
- Specified by:
readLong
in interfaceImageInputStream
- Throws:
IOException
-
readFloat
public float readFloat() throws IOException
- Specified by:
readFloat
in interfaceDataInput
- Specified by:
readFloat
in interfaceImageInputStream
- Throws:
IOException
-
readDouble
public double readDouble() throws IOException
- Specified by:
readDouble
in interfaceDataInput
- Specified by:
readDouble
in interfaceImageInputStream
- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLine
in interfaceDataInput
- Specified by:
readLine
in interfaceImageInputStream
- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTF
in interfaceDataInput
- Specified by:
readUTF
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(short[] s, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(char[] c, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(int[] i, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(long[] l, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(float[] f, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
readFully
public void readFully(double[] d, int off, int len) throws IOException
- Specified by:
readFully
in interfaceImageInputStream
- Throws:
IOException
-
getStreamPosition
public long getStreamPosition() throws IOException
- Specified by:
getStreamPosition
in interfaceImageInputStream
- Throws:
IOException
-
getBitOffset
public int getBitOffset() throws IOException
- Specified by:
getBitOffset
in interfaceImageInputStream
- Throws:
IOException
-
setBitOffset
public void setBitOffset(int bitOffset) throws IOException
- Specified by:
setBitOffset
in interfaceImageInputStream
- Throws:
IOException
-
readBit
public int readBit() throws IOException
- Specified by:
readBit
in interfaceImageInputStream
- Throws:
IOException
-
readBits
public long readBits(int numBits) throws IOException
- Specified by:
readBits
in interfaceImageInputStream
- Throws:
IOException
-
length
public long length() throws IOException
- Specified by:
length
in interfaceImageInputStream
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException
- Specified by:
skipBytes
in interfaceDataInput
- Specified by:
skipBytes
in interfaceImageInputStream
- Throws:
IOException
-
skipBytes
public long skipBytes(long n) throws IOException
- Specified by:
skipBytes
in interfaceImageInputStream
- Throws:
IOException
-
seek
public void seek(long pos) throws IOException
- Specified by:
seek
in interfaceImageInputStream
- Throws:
IOException
-
mark
public void mark()
- Specified by:
mark
in interfaceImageInputStream
-
reset
public void reset() throws IOException
- Specified by:
reset
in interfaceImageInputStream
- Throws:
IOException
-
flushBefore
public void flushBefore(long pos) throws IOException
- Specified by:
flushBefore
in interfaceImageInputStream
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceImageInputStream
- Throws:
IOException
-
getFlushedPosition
public long getFlushedPosition()
- Specified by:
getFlushedPosition
in interfaceImageInputStream
-
isCached
public boolean isCached()
- Specified by:
isCached
in interfaceImageInputStream
-
isCachedMemory
public boolean isCachedMemory()
- Specified by:
isCachedMemory
in interfaceImageInputStream
-
isCachedFile
public boolean isCachedFile()
- Specified by:
isCachedFile
in interfaceImageInputStream
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceImageInputStream
- Throws:
IOException
-
-