|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sixlegs.image.png.PngImage
For more information visit http://www.sixlegs.com/
ImageProducer
Field Summary | |
static int |
COLOR_TYPE_GRAY
|
static int |
COLOR_TYPE_GRAY_ALPHA
|
static int |
COLOR_TYPE_PALETTE
|
static int |
COLOR_TYPE_RGB
|
static int |
COLOR_TYPE_RGB_ALPHA
|
static int |
COMPRESSION_TYPE_BASE
|
static int |
FILTER_TYPE_BASE
|
static int |
FILTER_TYPE_INTRAPIXEL
|
static int |
INTERLACE_TYPE_ADAM7
|
static int |
INTERLACE_TYPE_NONE
|
static int |
SRGB_ABSOLUTE_COLORIMETRIC
|
static int |
SRGB_PERCEPTUAL
|
static int |
SRGB_RELATIVE_COLORIMETRIC
|
static int |
SRGB_SATURATION_PRESERVING
|
static int |
UNIT_METER
|
static int |
UNIT_MICROMETER
|
static int |
UNIT_PIXEL
|
static int |
UNIT_RADIAN
|
static int |
UNIT_UNKNOWN
|
Constructor Summary | |
PngImage(java.io.InputStream is)
Constructs a PngImage object from an input stream. |
|
PngImage(java.io.InputStream is,
boolean close)
Constructs a PngImage object from an input stream. |
|
PngImage(java.lang.String filename)
Constructs a PngImage object from a local PNG file. |
|
PngImage(java.net.URL url)
Constructs a PngImage object from a URL. |
Method Summary | |
void |
addConsumer(java.awt.image.ImageConsumer ic)
Adds an ImageConsumer to the list of consumers interested in
data for this image. |
java.awt.Color |
getBackgroundColor()
Get a suggested background color (from the bKGD chunk). |
int |
getBitDepth()
Gets bit depth of image data. |
int |
getColorType()
Gets the alpha and color properties of an image. |
java.util.Enumeration |
getErrors()
Returns an Enumeration of all the errors that occurred during
image production. |
void |
getEverything()
Ensures that the entire PNG file has been read. |
void |
getEverything(boolean throwFatalError)
Alternative to getEverything() which can throw
a fatal error if one was detected during the decoding process. |
java.util.Enumeration |
getGifExtensions()
Returns all known GIF Application Extensions. |
int |
getHeight()
Gets height of image in pixels. |
int |
getInterlaceType()
Gets the interlacing method used by this image. |
java.util.Enumeration |
getProperties()
Returns an Enumeration of the available properties. |
java.lang.Object |
getProperty(java.lang.String name)
Gets a property of this image by name. |
int[][] |
getSuggestedPalette(java.lang.String name)
Returns the suggested palette (sPLT chunk) specified by the palette name. |
java.util.Enumeration |
getSuggestedPalettes()
Returns an Enumeration of the available suggested palette names. |
TextChunk |
getTextChunk(java.lang.String key)
Returns the specified text chunk. |
java.util.Enumeration |
getTextChunks()
Returns the keys of all known text chunks. |
int |
getWidth()
Gets width of image in pixels. |
boolean |
hasAlphaChannel()
Returns true if the image has an alpha channel. |
boolean |
hasChunk(java.lang.String type)
Check if the specified chunk type appears at least once in this image. |
boolean |
hasErrors()
Checks if there were errors during image production. |
boolean |
hasFatalError()
|
boolean |
isConsumer(java.awt.image.ImageConsumer ic)
Determine if an ImageConsumer is on the list of consumers currently
interested in data for this image. |
boolean |
isGrayscale()
Returns true if the image is grayscale. |
boolean |
isIndexedColor()
Returns true if the image is paletted. |
static void |
registerChunk(ChunkHandler handler,
java.lang.String type)
Register a ChunkHandler to handle a user defined
chunk type. |
void |
removeConsumer(java.awt.image.ImageConsumer ic)
Remove an ImageConsumer from the list of consumers interested in
data for this image. |
void |
requestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)
Requests delivery of image data to the specified ImageConsumer
one more time in top-down, left-right order. |
static void |
setAllErrorsFatal(boolean allFatal)
Specifies whether all errors will abort the image production. |
void |
setBuffer(int[] pixels)
Set the internal pixel buffer to use when decoding the image. |
static void |
setDisplayExponent(double exponent)
Sets the default display exponent. |
void |
setFlushAfterNextProduction(boolean useFlush)
Readies this PngImage to be flushed after the next image
production, to free memory. |
static void |
setProgressiveDisplay(boolean progressive)
Interlaced images can either be displayed when completely read (default) or progressively. |
static void |
setUserExponent(double exponent)
Sets the default desired final user exponent. |
void |
startProduction(java.awt.image.ImageConsumer ic)
Adds an ImageConsumer to the list of consumers interested in
data for this image, and immediately start delivery of the
image data through the consumer/producer interface. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int COLOR_TYPE_GRAY
public static final int COLOR_TYPE_GRAY_ALPHA
public static final int COLOR_TYPE_PALETTE
public static final int COLOR_TYPE_RGB
public static final int COLOR_TYPE_RGB_ALPHA
public static final int INTERLACE_TYPE_NONE
public static final int INTERLACE_TYPE_ADAM7
public static final int FILTER_TYPE_BASE
public static final int FILTER_TYPE_INTRAPIXEL
public static final int COMPRESSION_TYPE_BASE
public static final int UNIT_UNKNOWN
public static final int UNIT_METER
public static final int UNIT_PIXEL
public static final int UNIT_MICROMETER
public static final int UNIT_RADIAN
public static final int SRGB_PERCEPTUAL
public static final int SRGB_RELATIVE_COLORIMETRIC
public static final int SRGB_SATURATION_PRESERVING
public static final int SRGB_ABSOLUTE_COLORIMETRIC
Constructor Detail |
public PngImage(java.lang.String filename) throws java.io.IOException
filename
- full path to local PNG filepublic PngImage(java.net.URL url) throws java.io.IOException
PngImage
object from a URL.
url
- URL of PNG imagepublic PngImage(java.io.InputStream is)
PngImage
object from an input stream.
Buffer the stream for better performance. The stream will be closed
when the image has been fully read or is flushed.
is
- InputStream containing PNG image dataBufferedInputStream
public PngImage(java.io.InputStream is, boolean close)
PngImage
object from an input stream.
Buffer the stream for better performance.
is
- InputStream containing PNG image dataclose
- Whether to close the input stream when the image
has been fully read or is flushed. When set to false you need
to manage the closing of the stream yourself. This is useful, for example, when
you have a file with multiple images concatenated together.BufferedInputStream
Method Detail |
public void addConsumer(java.awt.image.ImageConsumer ic)
ImageConsumer
to the list of consumers interested in
data for this image.
addConsumer
in interface java.awt.image.ImageProducer
ImageConsumer
public boolean isConsumer(java.awt.image.ImageConsumer ic)
ImageConsumer
is on the list of consumers currently
interested in data for this image.
isConsumer
in interface java.awt.image.ImageProducer
ImageConsumer
public void removeConsumer(java.awt.image.ImageConsumer ic)
ImageConsumer
from the list of consumers interested in
data for this image.
removeConsumer
in interface java.awt.image.ImageProducer
ImageConsumer
public void startProduction(java.awt.image.ImageConsumer ic)
ImageConsumer
to the list of consumers interested in
data for this image, and immediately start delivery of the
image data through the consumer/producer interface.
startProduction
in interface java.awt.image.ImageProducer
ImageConsumer
public void requestTopDownLeftRightResend(java.awt.image.ImageConsumer ic)
ImageConsumer
one more time in top-down, left-right order.
requestTopDownLeftRightResend
in interface java.awt.image.ImageProducer
startProduction(java.awt.image.ImageConsumer)
,
ImageConsumer
public static void setUserExponent(double exponent)
This method sets the user exponent for new PngImage
objects.
It is not possible to change the user exponent of an existing
PngImage
.
exponent
- desired user exponentpublic static void setDisplayExponent(double exponent)
This method sets the display exponent for new PngImage
objects.
It is not possible to change the display exponent of an existing
PngImage
.
exponent
- desired display exponentpublic boolean hasErrors()
ImageObserver
interface and the ERROR
flag is set.
ImageObserver
,
getErrors()
public boolean hasFatalError()
public java.util.Enumeration getErrors()
Enumeration
of all the errors that occurred during
image production. This includes any non-fatal errors.
hasErrors()
public static void setAllErrorsFatal(boolean allFatal)
public static void setProgressiveDisplay(boolean progressive)
PngImage
will call the setPixels
method of its registered image consumers after each pass.
Note: Images are only delivered progressively on the first production of the image data. Subsequent requests for the (cached) image data will send the image as a complete single frame.
ImageConsumer
,
ImageObserver
public java.awt.Color getBackgroundColor() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public int getWidth() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public int getHeight() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public int getBitDepth() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public int getInterlaceType() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public int getColorType() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
public boolean hasAlphaChannel() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
,
getColorType()
public boolean isGrayscale() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
,
getColorType()
public boolean isIndexedColor() throws java.io.IOException
java.io.IOException
getProperty(java.lang.String)
,
getColorType()
public java.lang.Object getProperty(java.lang.String name) throws java.io.IOException
null
.
Note: This method will only read up to the beginning of
the image data unless the image data has already been read,
either through the consumer/producer interface or by calling
getEverything()
.
The following properties are guaranteed to be defined:
Name | Type | Description |
"width" | Integer |
Image width in pixels |
"height" | Integer |
Image height in pixels |
"interlace type" | Integer |
See getInterlaceType |
"compression type" | Integer |
COMPRESSION_TYPE_BASE |
"filter type" | Integer |
FILTER_TYPE_BASE |
"color type" | Integer |
See getColorType |
"bit depth" | Integer |
1, 2, 4, 8, or 16 (1) |
"gamma" | Long |
File gamma * 100000 (2) |
"significant bits" | byte[] |
Significant bits per component: [r,g,b] [r,g,b,alpha] |
1 16-bit pixel components are reduced to 8 bits 2 Uses value from sRGB or gAMA chunks,
or default (45455 )3 For grayscale images, r == g == b |
The following properties are optional:
Name | Type | Description |
"palette" | int[][] |
Palette or suggested palette (PLTE chunk):[r,g,b][entry] [r,g,b][entry] |
"palette size" | Integer |
Size of palette, 1 - 256 |
"histogram" | int[] |
Palette entry usage frequency |
"background" | java.awt.Color |
Suggested background color |
"background low bytes" | java.awt.Color |
The low (least significant) bytes of a 16-bit background color |
"background index" | Integer |
The palette index of the suggested background color |
"time" | java.util.Date |
Time of last image modification |
"pixel dimensions x" | Long |
Pixels per unit, X axis |
"pixel dimensions y" | Long |
Pixels per unit, Y axis |
"pixel dimensions unit" | Integer |
UNIT_UNKNOWN or UNIT_METER |
"image position x" | Integer |
Horizontal offset from left of page |
"image position y" | Integer |
Vertical offset from top of page |
"image position unit" | Integer |
UNIT_PIXEL or UNIT_MICROMETER |
"pixel scale x" | Double |
Pixel width, physical scale of subject |
"pixel scale y" | Double |
Pixel height, physical scale of subject |
"pixel scale unit" | Integer |
UNIT_METER or UNIT_RADIAN |
"chromaticity xy" | long[][] |
CIE x,y chromaticities * 100000: [white,r,g,b][x,y] |
"chromaticity xyz" | double[][] |
CIE XYZ chromaticities: [white,r,g,b][X,Y,Z] |
"srgb rendering intent" | Integer |
SRGB_PERCEPTUAL or SRGB_RELATIVE_COLORIMETRIC or SRGB_SATURATION_PRESERVING or SRGB_ABSOLUTE_COLORIMETRIC |
"icc profile name" | String |
Internal ICC profile name |
"icc profile" | String |
Uncompressed ICC profile |
"pixel calibration purpose" | String |
Equation identifier |
"pixel calibration x0" | Integer |
Lower limit of original sample range |
"pixel calibration x1" | Integer |
Upper limit of original sample range |
"pixel calibration type" | Integer |
0 : Linear mapping1 : Base-e exponential mapping2 : Arbitrary-base exponential mapping3 : Hyperbolic mapping
|
"pixel calibration n" | Integer |
Number of parameters |
"pixel calibration unit" | String |
Symbol or description of unit |
"pixel calibration parameters" | double[] |
|
"gif disposal method" | Integer |
See GIF89a Graphic Control Extension specification |
"gif user input flag" | Integer |
See GIF89a Graphic Control Extension specification |
"gif delay time" | Integer |
See GIF89a Graphic Control Extension specification |
"transparency" | java.awt.Color |
Transparent color (4) |
"transparency low bytes" | java.awt.Color |
The low (least significant) bytes of a 16-bit transparency color (4) |
"transparency size" | Integer |
The number of palette entries with transparency information (5) |
4 Grayscale or truecolor images only 5 Indexed-color images only |
In addition, certain common (but still optional) text chunks
are available through the getProperty
interface:
Name | Type | Description |
"title" | TextChunk |
Short (one line) title or caption for image |
"author" | TextChunk |
Name of image's creator |
"description" | TextChunk |
Description of image (possibly long) |
"copyright" | TextChunk |
Copyright notice |
"creation time" | TextChunk |
Time of original image creation |
"software" | TextChunk |
Software used to create the image |
"disclaimer" | TextChunk |
Legal disclaimer |
"warning" | TextChunk |
Warning of nature of content |
"source" | TextChunk |
Device used to create the image |
"comment" | TextChunk |
Miscellaneous comment |
name
- a property name
java.io.IOException
getWidth()
,
getHeight()
,
getInterlaceType()
,
getColorType()
,
getTextChunk(java.lang.String)
,
getBackgroundColor()
public java.util.Enumeration getProperties() throws java.io.IOException
Enumeration
of the available properties.
java.io.IOException
getProperty(java.lang.String)
public void getEverything()
getErrors()
.
Note: The consumer/producer interface automatically
reads the entire PNG file. It usually is not necessary to call
getEverything()
unless you do not need the actual
image data.
public void getEverything(boolean throwFatalError) throws java.io.IOException
getEverything()
which can throw
a fatal error if one was detected during the decoding process.
throwFatalError
- if true, any fatal error will be thrown after
attempting to decode the image
java.io.IOException
public boolean hasChunk(java.lang.String type) throws java.io.IOException
Note: This method will only reflect chunks seen up to the
beginning of the image data unless the image data has already
been read, either through the consumer/producer interface or by
calling getEverything()
.
type
- the PNG chunk name, for example "tRNS"
.
java.io.IOException
public static void registerChunk(ChunkHandler handler, java.lang.String type) throws com.sixlegs.image.png.PngException
ChunkHandler
to handle a user defined
chunk type.
The chunk type must be four characters, ancillary (lowercase first letter),
and may not already be registered. You may register one of the supported
ancillary chunk types (except tRNS
) to override the standard behavior.
handler
- object to send chunk data totype
- chunk type
com.sixlegs.image.png.PngException
public java.util.Enumeration getSuggestedPalettes() throws java.io.IOException
Enumeration
of the available suggested palette names.
java.io.IOException
getSuggestedPalette(java.lang.String)
public int[][] getSuggestedPalette(java.lang.String name) throws java.io.IOException
name
- the name of the suggested palette
[r,g,b,alpha,freq][entry]
java.io.IOException
getSuggestedPalette(java.lang.String)
public TextChunk getTextChunk(java.lang.String key) throws java.io.IOException
Note: Text chunks may appear anywhere in the file. This
method will only read up to the beginning of the image data
unless the image data has already been read, either through the
consumer/producer interface or by calling
getEverything()
.
key
- the key of the desired chunk
java.io.IOException
getTextChunks()
,
getProperty(java.lang.String)
public java.util.Enumeration getTextChunks() throws java.io.IOException
Note: Text chunks may appear anywhere in the file. This
method will only read up to the beginning of the image data
unless the image data has already been read, either through the
consumer/producer interface or by calling
getEverything()
.
Enumeration
of the keys of text chunks read so far.
java.io.IOException
getTextChunk(java.lang.String)
public java.util.Enumeration getGifExtensions() throws java.io.IOException
Note: GIF Application Extensions may appear anywhere in
the file. This method will only read up to the beginning of the
image data unless the image data has already been read, either
through the consumer/producer interface or by calling
getEverything()
.
Enumeration
of all GifExtension objects read so far.
java.io.IOException
GifExtension
public void setFlushAfterNextProduction(boolean useFlush)
PngImage
to be flushed after the next image
production, to free memory.
After flushing, you may only call the getErrors()
and hasErrors()
methods on this object. The pixel
data will no longer be available through the consumer/producer
interface.
Note: Using a PixelGrabber
object on an Image
produced
by this PngImage
object will ask for a second production of the
pixel data, which will fail if the object has been flushed.
useFlush
- whether to flush after the next production; default is falsepublic void setBuffer(int[] pixels) throws java.io.IOException
(width * height)
is normally automatically allocated
if either the image is progressive or setFlushAfterNextProduction(boolean)
has
not been set. For performance or memory use issues you may supply your
own buffer with this method. The pixels are stored in 0xAARRGGBB
format.
pixels
- the pixel buffer to use; size must be at least (width * height)
java.lang.IllegalArgumentException
- if the pixel buffer is too short
java.lang.IllegalStateException
- if this PngImage
has been flushed.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |