-
Notifications
You must be signed in to change notification settings - Fork 0
/
PNG.h
125 lines (104 loc) · 3.66 KB
/
PNG.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef CS225_PNG_H_
#define CS225_PNG_H_
#include <string>
#include <vector>
#include "HSLAPixel.h"
using namespace std;
class PNG {
public:
/**
* Creates an empty PNG image.
*/
PNG();
/**
* Creates a PNG image of the specified dimensions.
* @param width Width of the new image.
* @param height Height of the new image.
*/
PNG(unsigned int width, unsigned int height);
/**
* Copy constructor: creates a new PNG image that is a copy of
* another.
* @param other PNG to be copied.
*/
PNG(PNG const & other);
/**
* Destructor: frees all memory associated with a given PNG object.
* Invoked by the system.
*/
~PNG();
/**
* Assignment operator for setting two PNGs equal to one another.
* @param other Image to copy into the current image.
* @return The current image for assignment chaining.
*/
PNG const & operator= (PNG const & other);
/**
* Equality operator: checks if two images are the same.
* @param other Image to be checked.
* @return Whether the current image is equal to the other image.
*/
bool operator== (PNG const & other) const;
/**
* Inequality operator: checks if two images are different.
* @param other Image to be checked.
* @return Whether the current image differs from the other image.
*/
bool operator!= (PNG const & other) const;
/**
* Reads in a PNG image from a file.
* Overwrites any current image content in the PNG.
* @param fileName Name of the file to be read from.
* @return true, if the image was successfully read and loaded.
*/
bool readFromFile(string const & fileName);
/**
* Writes a PNG image to a file.
* @param fileName Name of the file to be written.
* @return true, if the image was successfully written.
*/
bool writeToFile(string const & fileName);
/**
* 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.
* @param x X-coordinate for the pixel pointer to be grabbed from.
* @param y Y-coordinate for the pixel pointer to be grabbed from.
* @return A pointer to the pixel at the given coordinates.
*/
HSLAPixel & getPixel(unsigned int x, unsigned int y) const;
/**
* Gets the width of this image.
* @return Width of the image.
*/
unsigned int width() const;
/**
* Gets the height of this image.
* @return Height of the image.
*/
unsigned int height() const;
/**
* 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.
* @param newWidth New width of the image.
* @param newHeight New height of the image.
*/
void resize(unsigned int newWidth, unsigned int newHeight);
/**
* Computes a hash of the contents of the image.
*/
std::size_t computeHash() const;
private:
unsigned int width_; /*< Width of the image */
unsigned int height_; /*< Height of the image */
HSLAPixel *imageData_; /*< Array of pixels */
HSLAPixel defaultPixel_; /*< Default pixel, returned in cases of errors */
/**
* Copeies the contents of `other` to self
*/
void _copy(PNG const & other);
};
std::ostream & operator<<(std::ostream & out, PNG const & pixel);
std::stringstream & operator<<(std::stringstream & out, PNG const & pixel);
#endif