MP3
Linked Lists
PNG Class Reference

Represents an entire png formatted image. More...

#include "png.h"

Inherited by BlockPNG.

+ Collaboration diagram for PNG:

Public Member Functions

 PNG ()
 Creates a default PNG image (that is, a 1x1 opaque white image). More...
 
 PNG (size_t width, size_t height)
 Creates a default PNG image of the desired dimensions (that is, a width x height opaque white image). More...
 
 PNG (string const &file_name)
 Creates a PNG image by reading a file in from disk. 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...
 
RGBAPixeloperator() (size_t x, size_t y)
 Non-const pixel access operator. More...
 
RGBAPixel const * operator() (size_t x, size_t y) const
 Const pixel access operator. More...
 
bool readFromFile (string const &file_name)
 Reads in a PNG image from a file. More...
 
bool writeToFile (string const &file_name)
 Writes a PNG image to a file. More...
 
size_t width () const
 Gets the width of this image. More...
 
size_t height () const
 Gets the height of this image. More...
 
void resize (size_t width, size_t height)
 Resizes the image to the given coordinates. More...
 

Detailed Description

Represents an entire png formatted image.

Constructor & Destructor Documentation

◆ PNG() [1/4]

PNG::PNG ( )

Creates a default PNG image (that is, a 1x1 opaque white image).

◆ PNG() [2/4]

PNG::PNG ( size_t  width,
size_t  height 
)

Creates a default PNG image of the desired dimensions (that is, a width x height opaque white image).

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

◆ PNG() [3/4]

PNG::PNG ( string const &  file_name)

Creates a PNG image by reading a file in from disk.

Parameters
file_nameName of the file to be read in to the image.

◆ PNG() [4/4]

PNG::PNG ( PNG const &  other)

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

Parameters
otherPNG to be copied.

◆ ~PNG()

PNG::~PNG ( )

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

Invoked by the system.

Member Function Documentation

◆ operator=()

PNG const & 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 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.

◆ operator!=()

bool 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()() [1/2]

RGBAPixel * PNG::operator() ( size_t  x,
size_t  y 
)

Non-const pixel access operator.

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

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

◆ operator()() [2/2]

RGBAPixel const * PNG::operator() ( size_t  x,
size_t  y 
) const

Const pixel access operator.

Const version of the previous operator(). Does not allow the image to be changed via the pointer.

Parameters
xX-coordinate for the pixel pointer to be grabbed from.
yY-cooridnate for the pixel pointer to be grabbed from.
Returns
A pointer to the pixel at the given coordinates (can't change the pixel through this pointer).

◆ readFromFile()

bool PNG::readFromFile ( string const &  file_name)

Reads in a PNG image from a file.

Overwrites any current image content in the PNG. In the event of failure, the image's contents are undefined.

Parameters
file_nameName of the file to be read from.
Returns
Whether the image was successfully read in or not.

◆ writeToFile()

bool PNG::writeToFile ( string const &  file_name)

Writes a PNG image to a file.

Parameters
file_nameName of the file to write to.
Returns
Whether the file was written successfully or not.

◆ width()

size_t PNG::width ( ) const

Gets the width of this image.

Returns
Width of the image.

◆ height()

size_t PNG::height ( ) const

Gets the height of this image.

Returns
Height of the image.

◆ resize()

void PNG::resize ( size_t  width,
size_t  height 
)

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
widthNew width of the image.
heightNew height of the image.

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