|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.image.PJGImage
edu.rit.image.BaseColorImage
edu.rit.image.PJGHueImage
public class PJGHueImage
Class PJGHueImage provides a color image that is read from or written to a file in Parallel Java Graphics (PJG) format; class PJGHueImage is best suited when the image has a continuous range of hues. For further information about the PJG format, see class PJGImage. The image is layered on top of an integer matrix (type int[][]). The height and width of the image are equal to the number of rows and columns in the underlying matrix.
To get and set the image's pixel data, use the getPixel(), getPixelColor(), setPixel(), setPixelColor(), and setPixelHSB() methods. You only need to allocate storage in the pixel data matrix for the portions of the image you are actually accessing; the complete matrix need not be allocated. Class Arrays has static methods for allocating portions of a matrix.
Changing the contents of the underlying matrix directly will also change the image. The color information is stored in a matrix element as follows:
A color may be specified using hue, saturation, and brightness components instead of red, green, and blue components.
The hue component gives the basic color. A hue of 0 = red; 1/6 = yellow; 2/6 = green; 3/6 = cyan; 4/6 = blue; 5/6 = magenta; 1 = red again. Intermediate hue values yield intermediate colors.
The saturation component specifies how gray or colored the color is. A saturation of 0 yields fully gray; a saturation of 1 yields fully colored. Intermediate saturation values yield mixtures of gray and colored.
The brightness component specifies how dark or light the color is. A brightness of 0 yields fully dark (black); a brightness of 1 yields fully light (somewhere between white and colored depending on the saturation). Intermediate brightness values yield somewhere between a gray shade and a darkened color (depending on the saturation).
To write a PJGHueImage object to a PJG image file, call the prepareToWrite() method, specifying the output stream to write. The prepareToWrite() method returns an instance of class PJGImage.Writer. Call the methods of the PJG image writer object to write the pixel data, or sections of the pixel data, to the output stream. When finished, close the PJG image writer.
When writing an image to a PJG file, class PJGHueImage uses Huffman delta encoded 24-bit hue pixel data segments (see class PJGImage) to compress the pixel data. This technique will work well if the image has a continous range of hues, where each pixel's RGB components are the same or nearly the same as the neighboring pixels' RGB components.
To read a PJGHueImage object from a PJG image file, call the prepareToRead() method, specifying the input stream to read. The prepareToRead() method returns an instance of class PJGImage.Reader. Call the methods of the PJG image reader object to read the pixel data, or sections of the pixel data, from the input stream. When finished, close the PJG image reader.
To get a BufferedImage object that uses the same underlying pixel data matrix as the PJGHueImage object, call the getBufferedImage() method. You can then do all the following with the BufferedImage: display it on the screen, draw into it using a graphics context, copy another BufferedImage into it, read it from or write it to a file using package javax.imageio (which typically supports PNG, JPG, and GIF formats). The rows and columns of the underlying matrix need not all be allocated when accessing the BufferedImage. If you get a pixel from the BufferedImage in an unallocated row or column, a pixel value of 0 (black) is returned. If you set a pixel in the BufferedImage in an unallocated row or column, the pixel value is discarded.
Note: Class PJGHueImage is not multiple thread safe.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class edu.rit.image.PJGImage |
|---|
PJGImage.Reader, PJGImage.Writer |
| Constructor Summary | |
|---|---|
PJGHueImage()
Construct a new PJG hue image. |
|
PJGHueImage(int theHeight,
int theWidth,
int[][] theMatrix)
Construct a new PJG hue image with the given height, width, and underlying matrix. |
|
| Method Summary | |
|---|---|
PJGImage.Reader |
prepareToRead(InputStream theStream)
Prepare to read this image from the given input stream. |
PJGImage.Writer |
prepareToWrite(OutputStream theStream)
Prepare to write this image to the given output stream. |
| Methods inherited from class edu.rit.image.BaseColorImage |
|---|
fill, fill, fill, fill, fill, fill, fillHSB, getBufferedImage, getDisplayable, getMatrix, getPixel, getPixel, getPixel, getPixelColor, setMatrix, setPixel, setPixel, setPixel, setPixel, setPixel, setPixelColor, setPixelHSB |
| Methods inherited from class edu.rit.image.PJGImage |
|---|
addComment, clearComments, createFromStream, getComments, getCreationTime, getHeight, getWidth, readFromStream, setCreationTime |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PJGHueImage()
public PJGHueImage(int theHeight,
int theWidth,
int[][] theMatrix)
theHeight - Image height in pixels.theWidth - Image width in pixels.theMatrix - Underlying matrix.
NullPointerException - (unchecked exception) Thrown if theMatrix is null.
IllegalArgumentException - (unchecked exception) Thrown if theHeight <= 0. Thrown if
theWidth <= 0. Thrown if theMatrix.length does
not equal theHeight.| Method Detail |
|---|
public PJGImage.Writer prepareToWrite(OutputStream theStream)
throws IOException
For improved performance, specify an output stream with buffering, such as an instance of class java.io.BufferedOutputStream.
prepareToWrite in class PJGImagetheStream - Output stream.
NullPointerException - (unchecked exception) Thrown if theStream is null.
IOException - Thrown if an I/O error occurred.
public PJGImage.Reader prepareToRead(InputStream theStream)
throws IOException
For improved performance, specify an input stream with buffering, such as an instance of class java.io.BufferedInputStream.
prepareToRead in class PJGImagetheStream - Input stream.
NullPointerException - (unchecked exception) Thrown if theStream is null.
IOException - Thrown if an I/O error occurred.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||