public class RGBAPixel
extends java.lang.Object
This class stores 32-bit red, green, blue, and alpha pixel data according to the RGBA standard. Red is stored in the lowest bits, followed by green, blue, and the alpha channel. 8 bits are used for each value, resulting in a unsigned range of 0 to 255.
You may modify this class in certain ways, but should not make changes that could affect testing.
Constructor | Description |
---|---|
RGBAPixel(byte redValue,
byte greenValue,
byte blueValue,
byte alphaValue) |
Complete constructor for the RGBA pixel class.
|
RGBAPixel(int setData) |
Constructor for the RGBAPixel class that uses a single int.
|
RGBAPixel(int redValue,
int greenValue,
int blueValue,
int alphaValue) |
Complete constructor for the RGBA pixel class.
|
RGBAPixel(RGBAPixel other) |
Copy constructor for the RGBA pixel class.
|
Modifier and Type | Method | Description |
---|---|---|
static RGBAPixel[][] |
copyArray(RGBAPixel[][] inputArray) |
Perform a deep copy of a two-dimensional RGBAPixel array.
|
static java.lang.String |
diffArrays(RGBAPixel[][] firstArray,
RGBAPixel[][] secondArray) |
Testing helper function to explain differences between two arrays.
|
boolean |
equals(java.lang.Object o) |
|
static RGBAPixel[][] |
fromIntArray(int[][] inputArray) |
Convert an array of ints to an array of RGBAPixels.
|
int |
getAlpha() |
Get this pixel's alpha value.
|
int |
getBlue() |
Get this pixel's blue value.
|
int |
getData() |
Return the data for this pixel as an int.
|
static RGBAPixel |
getFillValue() |
Return a new copied fill value.
|
int |
getGreen() |
Get this pixel's green value.
|
int |
getRed() |
Get this pixel's red value.
|
int |
hashCode() |
|
static java.lang.String |
printArray(RGBAPixel[][] inputArray) |
Nicely format an two-dimensional array of RGBAPixels.
|
int |
setAlpha(int setValue) |
Set this pixel's alpha value.
|
int |
setBlue(int setValue) |
Set this pixel's blue value.
|
int |
setGreen(int setValue) |
Set this pixel's green value.
|
int |
setRed(int setValue) |
Set this pixel's red value.
|
static int[][] |
toIntArray(RGBAPixel[][] inputArray) |
Convert an array of RGBAPixels to an array of ints.
|
java.lang.String |
toString() |
public RGBAPixel(int redValue, int greenValue, int blueValue, int alphaValue)
Note that valid RGBA values are between 0 and 255, inclusive. Parameters that are too large or too small will be trimmed appropriately.
redValue
- the new pixel's red channel valuegreenValue
- the new pixel's green channel valueblueValue
- the new pixel's blue channel valuealphaValue
- the new pixel's alpha channel valuepublic RGBAPixel(byte redValue, byte greenValue, byte blueValue, byte alphaValue)
This differs from the int constructor because bytes have to be converted to unsigned int values.
redValue
- the new pixel's red channel valuegreenValue
- the new pixel's green channel valueblueValue
- the new pixel's blue channel valuealphaValue
- the new pixel's alpha channel valuepublic RGBAPixel(int setData)
setData
- data to set.public RGBAPixel(RGBAPixel other)
other
- the other RGBAPixel to copypublic static RGBAPixel getFillValue()
public int getData()
public int getRed()
public int getGreen()
public int getBlue()
public int getAlpha()
public int setRed(int setValue)
If a value less than zero is passed, the new value is set to 0. If a value larger than 255 is passed, the new value is set to 255.
setValue
- the new red valuepublic int setGreen(int setValue)
If a value less than zero is passed, the new value is set to 0. If a value larger than 255 is passed, the new value is set to 255.
setValue
- the new green valuepublic int setBlue(int setValue)
If a value less than zero is passed, the new value is set to 0. If a value larger than 255 is passed, the new value is set to 255.
setValue
- the new blue valuepublic int setAlpha(int setValue)
If a value less than zero is passed, the new value is set to 0. If a value larger than 255 is passed, the new value is set to 255.
setValue
- the new alpha valuepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static RGBAPixel[][] fromIntArray(int[][] inputArray)
This is a convenience method for use by the testing suite. Fails and returns null if top-level array has length 0, or if any inner array has length 0, or if the two-dimensional array is not square.
inputArray
- array of ints to convert to an array of RGBAPixel objectspublic static int[][] toIntArray(RGBAPixel[][] inputArray)
This is a convenience method for use by the testing suite. Fails and returns null if top-level array has length 0, or if any inner array has length 0, or if the two-dimensional array is not square.
inputArray
- array of RGBAPixels to convert to an array of intspublic static RGBAPixel[][] copyArray(RGBAPixel[][] inputArray)
This is a convenience method largely for use by the testing suite. Fails and returns null if top-level array has length 0, or if any inner array has length 0, or if the two-dimensional array is not square.
inputArray
- array of RGBAPixel objects to copypublic static java.lang.String printArray(RGBAPixel[][] inputArray)
Primarily intended for debugging.
inputArray
- the two-dimensional RGBAPixel array to formatpublic static java.lang.String diffArrays(RGBAPixel[][] firstArray, RGBAPixel[][] secondArray)
firstArray
- the first array to comparesecondArray
- the second array to compare