mp_traversals
Terrible Traversals
cs225::PNG Class Reference
Collaboration diagram for cs225::PNG:
[legend]

Public Member Functions

 PNG ()
 Creates an empty PNG image. More...
 
 PNG (unsigned int width, unsigned int height)
 Creates a PNG image of the specified dimensions. More...
 
 PNG (PNG const &other)
 Copy constructor: creates a new PNG image that is a copy of another. More...
 
 ~PNG ()
 Destructor: frees all memory associated with a given PNG object. More...
 
PNG const & operator= (PNG const &other)
 Assignment operator for setting two PNGs equal to one another. More...
 
bool operator== (PNG const &other) const
 Equality operator: checks if two images are the same. More...
 
bool operator!= (PNG const &other) const
 Inequality operator: checks if two images are different. More...
 
bool readFromFile (string const &fileName)
 Reads in a PNG image from a file. More...
 
bool writeToFile (string const &fileName)
 Writes a PNG image to a file. More...
 
HSLAPixelgetPixel (unsigned int x, unsigned int y)
 Pixel access operator. More...
 
const HSLAPixelgetPixel (unsigned int x, unsigned int y) const
 Pixel access operator. More...
 
unsigned int width () const
 Gets the width of this image. More...
 
unsigned int height () const
 Gets the height of this image. More...
 
void resize (unsigned int newWidth, unsigned int newHeight)
 Resizes the image to the given coordinates. More...
 

Private Member Functions

void _copy (PNG const &other)
 Copies the contents of other to self. More...
 
HSLAPixel_getPixelHelper (unsigned int x, unsigned int y) const
 Common function for powering the following signature stubs. More...
 

Private Attributes

unsigned int width_
 
unsigned int height_
 
HSLAPixelimageData_
 

Constructor & Destructor Documentation

◆ PNG() [1/3]

cs225::PNG::PNG ( )

Creates an empty PNG image.

◆ PNG() [2/3]

cs225::PNG::PNG ( unsigned int  width,
unsigned int  height 
)

Creates a PNG image of the specified dimensions.

Parameters
widthWidth of the new image.
heightHeight of the new image.

◆ PNG() [3/3]

cs225::PNG::PNG ( PNG const &  other)

Copy constructor: creates a new PNG image that is a copy of another.

Parameters
otherPNG to be copied.

◆ ~PNG()

cs225::PNG::~PNG ( )

Destructor: frees all memory associated with a given PNG object.

Invoked by the system.

Member Function Documentation

◆ _copy()

void cs225::PNG::_copy ( PNG const &  other)
private

Copies the contents of other to self.

◆ _getPixelHelper()

HSLAPixel & cs225::PNG::_getPixelHelper ( unsigned int  x,
unsigned int  y 
) const
private

Common function for powering the following signature stubs.

HSLAPixel & getPixel(unsigned int x, unsigned int y); const HSLAPixel & getPixel(unsigned int x, unsigned int y) const;

◆ getPixel() [1/2]

HSLAPixel & cs225::PNG::getPixel ( unsigned int  x,
unsigned int  y 
)

Pixel access operator.

Gets a reference to the pixel at the given coordinates in the image. (0,0) is the upper left corner. This reference allows the image to be changed.

Parameters
xX-coordinate for the pixel reference to be grabbed from.
yY-coordinate for the pixel reference to be grabbed from.
Returns
A reference to the pixel at the given coordinates.

◆ getPixel() [2/2]

const HSLAPixel & cs225::PNG::getPixel ( unsigned int  x,
unsigned int  y 
) const

Pixel access operator.

Gets a const reference to the pixel at the given coordinates in the image. (0,0) is the upper left corner. This const reference DOES NOT allow the image to be changed.

Parameters
xX-coordinate for the const pixel reference to be grabbed from.
yY-coordinate for the const pixel reference to be grabbed from.
Returns
A const reference to the pixel at the given coordinates.

◆ height()

unsigned int cs225::PNG::height ( ) const

Gets the height of this image.

Returns
Height of the image.

◆ operator!=()

bool cs225::PNG::operator!= ( PNG const &  other) const

Inequality operator: checks if two images are different.

Parameters
otherImage to be checked.
Returns
Whether the current image differs from the other image.

◆ operator=()

PNG const & cs225::PNG::operator= ( PNG const &  other)

Assignment operator for setting two PNGs equal to one another.

Parameters
otherImage to copy into the current image.
Returns
The current image for assignment chaining.

◆ operator==()

bool cs225::PNG::operator== ( PNG const &  other) const

Equality operator: checks if two images are the same.

Parameters
otherImage to be checked.
Returns
Whether the current image is equal to the other image.

◆ readFromFile()

bool cs225::PNG::readFromFile ( string const &  fileName)

Reads in a PNG image from a file.

Overwrites any current image content in the PNG.

Parameters
fileNameName of the file to be read from.
Returns
true, if the image was successfully read and loaded.

◆ resize()

void cs225::PNG::resize ( unsigned int  newWidth,
unsigned int  newHeight 
)

Resizes the image to the given coordinates.

Attempts to preserve existing pixel data in the image when doing so, but will crop if necessary. No pixel interpolation is done.

Parameters
newWidthNew width of the image.
newHeightNew height of the image.

◆ width()

unsigned int cs225::PNG::width ( ) const

Gets the width of this image.

Returns
Width of the image.

◆ writeToFile()

bool cs225::PNG::writeToFile ( string const &  fileName)

Writes a PNG image to a file.

Parameters
fileNameName of the file to be written.
Returns
true, if the image was successfully written.

The documentation for this class was generated from the following files: