Class RGBAPixel
- java.lang.Object
-
- edu.illinois.cs.cs125.mp4.lib.RGBAPixel
-
public class RGBAPixel extends java.lang.Object
Class representing a RGBA pixel.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.
- See Also:
- MP4 Documentation, RGBA pixel documentation
-
-
Constructor Summary
Constructors 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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()
-
-
-
Constructor Detail
-
RGBAPixel
public RGBAPixel(int redValue, int greenValue, int blueValue, int alphaValue)
Complete constructor for the RGBA pixel class.Note that valid RGBA values are between 0 and 255, inclusive. Parameters that are too large or too small will be trimmed appropriately.
- Parameters:
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 value
-
RGBAPixel
public RGBAPixel(byte redValue, byte greenValue, byte blueValue, byte alphaValue)
Complete constructor for the RGBA pixel class.This differs from the int constructor because bytes have to be converted to unsigned int values.
- Parameters:
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 value
-
RGBAPixel
public RGBAPixel(int setData)
Constructor for the RGBAPixel class that uses a single int.- Parameters:
setData
- data to set.
-
RGBAPixel
public RGBAPixel(RGBAPixel other)
Copy constructor for the RGBA pixel class.- Parameters:
other
- the other RGBAPixel to copy
-
-
Method Detail
-
getFillValue
public static RGBAPixel getFillValue()
Return a new copied fill value. You should use this to get a fill value for your transformation functions. This is because we test your output array to make sure that it is not a copy of the input, and if you use the same fill pixel for all fill values this test will fail.- Returns:
- a new fill value RGBAPixel
-
getData
public int getData()
Return the data for this pixel as an int.- Returns:
- the data for this pixel as an int.
-
getRed
public int getRed()
Get this pixel's red value.- Returns:
- this pixel's red value
-
getGreen
public int getGreen()
Get this pixel's green value.- Returns:
- this pixel's green value
-
getBlue
public int getBlue()
Get this pixel's blue value.- Returns:
- this pixel's blue value
-
getAlpha
public int getAlpha()
Get this pixel's alpha value.- Returns:
- this pixel's alpha value
-
setRed
public int setRed(int setValue)
Set this pixel's red value.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.
- Parameters:
setValue
- the new red value- Returns:
- this pixel's new red value
-
setGreen
public int setGreen(int setValue)
Set this pixel's green value.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.
- Parameters:
setValue
- the new green value- Returns:
- this pixel's new green value
-
setBlue
public int setBlue(int setValue)
Set this pixel's blue value.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.
- Parameters:
setValue
- the new blue value- Returns:
- this pixel's new blue value
-
setAlpha
public int setAlpha(int setValue)
Set this pixel's alpha value.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.
- Parameters:
setValue
- the new alpha value- Returns:
- this pixel's new alpha value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
fromIntArray
public static RGBAPixel[][] fromIntArray(int[][] inputArray)
Convert an array of ints to an array of RGBAPixels.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.
- Parameters:
inputArray
- array of ints to convert to an array of RGBAPixel objects- Returns:
- the array of RGBAPixel objects, or null on failure.
-
toIntArray
public static int[][] toIntArray(RGBAPixel[][] inputArray)
Convert an array of RGBAPixels to an array of ints.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.
- Parameters:
inputArray
- array of RGBAPixels to convert to an array of ints- Returns:
- the array of ints, or null on failure.
-
copyArray
public static RGBAPixel[][] copyArray(RGBAPixel[][] inputArray)
Perform a deep copy of a two-dimensional RGBAPixel array.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.
- Parameters:
inputArray
- array of RGBAPixel objects to copy- Returns:
- copied array of RGBAPixel objects, or null on failure.
-
printArray
public static java.lang.String printArray(RGBAPixel[][] inputArray)
Nicely format an two-dimensional array of RGBAPixels.Primarily intended for debugging.
- Parameters:
inputArray
- the two-dimensional RGBAPixel array to format- Returns:
- the array nicely formatted as a String for printing
-
diffArrays
public static java.lang.String diffArrays(RGBAPixel[][] firstArray, RGBAPixel[][] secondArray)
Testing helper function to explain differences between two arrays.- Parameters:
firstArray
- the first array to comparesecondArray
- the second array to compare- Returns:
- a String explaining differences between the two arrays
-
-