Class GrayImageRow
- java.lang.Object
-
- edu.rit.image.GrayImageRow
-
public class GrayImageRow extends java.lang.ObjectClass GrayImageRow provides one row of a grayscale image. The image row is layered on top of a byte array (type byte[]). Use the setArray() method to specify which array this is. The width of the image row is equal to the number of elements in the underlying array. The image row's underlying array usually is (but does not have to be) one row of an image's underlying matrix.To read and write the pixels of an image row, use the getIntPixel(), getPixel(), setIntPixel(), and setPixel() methods. These methods represent a pixel value as an integer in the range 0 .. 255 or as a floating point number in the range 0.0 .. 1.0. The image row's interpretation attribute specifies how to map between the numerical pixel value and the shade of gray. If the interpretation is ZERO_IS_WHITE, then a value of 0 or 0.0 represents white and 255 or 1.0 represents black. If the interpretation is ZERO_IS_BLACK, then a value of 0 or 0.0 represents black and 255 or 1.0 represents white. The default interpretation is ZERO_IS_BLACK. To change the interpretation, call the setInterpretation() method.
Changing the contents of the underlying matrix directly will also change the image row. In the underlying matrix, a value of 0 represents black and a value of 255 represents white.
-
-
Field Summary
Fields Modifier and Type Field and Description static PJGGrayImage.InterpretationZERO_IS_BLACKA pixel value of 0 or 0.0 is black, 255 or 1.0 is white.static PJGGrayImage.InterpretationZERO_IS_WHITEA pixel value of 0 or 0.0 is white, 255 or 1.0 is black.
-
Constructor Summary
Constructors Constructor and Description GrayImageRow(byte[] theArray)Construct a new grayscale image row on top of the given array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidfill(float val)Set all pixels in this image row to the given value.voidfill(int val)Set all pixels in this image row to the given value.byte[]getArray()Obtain this image row's underlying array.PJGGrayImage.InterpretationgetInterpretation()Get this image row's interpretation.intgetIntPixel(int c)Obtain the pixel at the given column in this image row.floatgetPixel(int c)Obtain the pixel at the given column in this image row.voidsetArray(byte[] theArray)Set this image row's underlying array.voidsetInterpretation(PJGGrayImage.Interpretation theInterpretation)Set this image row's interpretation.voidsetIntPixel(int c, int val)Set the pixel at the given column in this image row.voidsetPixel(int c, float val)Set the pixel at the given column in this image row.
-
-
-
Field Detail
-
ZERO_IS_WHITE
public static final PJGGrayImage.Interpretation ZERO_IS_WHITE
A pixel value of 0 or 0.0 is white, 255 or 1.0 is black.
-
ZERO_IS_BLACK
public static final PJGGrayImage.Interpretation ZERO_IS_BLACK
A pixel value of 0 or 0.0 is black, 255 or 1.0 is white.
-
-
Constructor Detail
-
GrayImageRow
public GrayImageRow(byte[] theArray)
Construct a new grayscale image row on top of the given array. The image row's interpretation isZERO_IS_BLACK.- Parameters:
theArray- Underlying array.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null.
-
-
Method Detail
-
getArray
public byte[] getArray()
Obtain this image row's underlying array.- Returns:
- Underlying array.
-
setArray
public void setArray(byte[] theArray)
Set this image row's underlying array.- Parameters:
theArray- Underlying array.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArray is null.
-
getInterpretation
public PJGGrayImage.Interpretation getInterpretation()
Get this image row's interpretation.- Returns:
ZERO_IS_WHITEorZERO_IS_BLACK.
-
setInterpretation
public void setInterpretation(PJGGrayImage.Interpretation theInterpretation)
Set this image row's interpretation. If this method is not called, this image row's default interpretation isZERO_IS_BLACK.- Parameters:
theInterpretation-ZERO_IS_WHITEorZERO_IS_BLACK.
-
getIntPixel
public int getIntPixel(int c)
Obtain the pixel at the given column in this image row.- Parameters:
c- Column index.- Returns:
- Pixel[c] as an integer in the range 0 .. 255.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.java.lang.ArrayIndexOutOfBoundsException- (unchecked exception) Thrown if c is out of bounds.
-
getPixel
public float getPixel(int c)
Obtain the pixel at the given column in this image row.- Parameters:
c- Column index.- Returns:
- Pixel[c] as a floating point number in the range 0.0 .. 1.0.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.java.lang.ArrayIndexOutOfBoundsException- (unchecked exception) Thrown if c is out of bounds.
-
setIntPixel
public void setIntPixel(int c, int val)Set the pixel at the given column in this image row. If val is outside the range 0 .. 255, it is pinned to the appropriate boundary.- Parameters:
c- Column index.val- New pixel value as an integer in the range 0 .. 255.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.java.lang.ArrayIndexOutOfBoundsException- (unchecked exception) Thrown if c is out of bounds.
-
setPixel
public void setPixel(int c, float val)Set the pixel at the given column in this image row. If val is outside the range 0.0 .. 1.0, it is pinned to the appropriate boundary.- Parameters:
c- Column index.val- New pixel value as a floating point number in the range 0.0 .. 1.0.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.java.lang.ArrayIndexOutOfBoundsException- (unchecked exception) Thrown if c is out of bounds.
-
fill
public void fill(int val)
Set all pixels in this image row to the given value. If val is outside the range 0 .. 255, it is pinned to the appropriate boundary.- Parameters:
val- New pixel value as an integer in the range 0 .. 255.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.
-
fill
public void fill(float val)
Set all pixels in this image row to the given value. If val is outside the range 0.0 .. 1.0, it is pinned to the appropriate boundary.- Parameters:
val- New pixel value as a floating point number in the range 0.0 .. 1.0.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if the underlying matrix row has not been specified.
-
-
DMelt 3.0 © DataMelt by jWork.ORG