-
Notifications
You must be signed in to change notification settings - Fork 2
/
bitmap.h
102 lines (84 loc) · 2.62 KB
/
bitmap.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
/**
* @file bitmap.h
*
* @author Kevin Buffardi
* @author Joshua Petrin
*/
#ifndef BITMAP_H_
#define BITMAP_H_
#include <string>
#include <vector>
/**
* @brief Represents a single Pixel in the image.
*
* A Pixel has a single bit value that is a zero (white) or a one (black). So,
* this class essentially encapsulates a 2D array of bools.
**/
struct Pixel
{
/// Stores on/off status.
bool on;
/// Initializes a Pixel with a default off.
Pixel() : on(false) { }
/// Initializes a color Pixel with the specified on/off value.
Pixel(bool set) : on(set) { }
};
///To abbreviate a pixel matrix built as a vector of vectors
typedef std::vector < std::vector <Pixel> > PixelMatrix;
/**
* @brief Represents a bitmap where a grid of pixels (in row-major order)
* describes the color of each pixel within the image.
* Functionality limited to Windows BMP formatted images with no compression
* and 24 bit color depth.
**/
class Bitmap
{
private:
PixelMatrix pixels;
public:
/**
* @brief Opens a file as its name is provided and reads pixel-by-pixel
* the data into a matrix of on/off pixels. Any errors will cout but will
* result in an empty matrix (with no rows and no columns).
*
* @param file name of the filename to be opened and read as a matrix of pixels
**/
void open(std::string file);
/**
* @brief Saves the current image, represented by the matrix of pixels, as
* a Windows BMP file with the name provided by the parameter.
*
* File extension is not forced but should be .bmp. Any errors will cout
* and will NOT attempt to save the file.
*
* @param file name of the filename to be written as a bmp image
**/
void save(std::string file) const;
/**
* @brief Validates whether or not the current matrix of pixels represents a
* proper image.
*
* Tests for non-zero-size rows and consistent non-zero-size columns for each
* row.
*
* @return boolean value of whether or not the matrix is a valid image
**/
bool isImage() const;
/**
* @brief Provides a vector of vector of pixels representing the bitmap
*
* @return the bitmap image, represented by a matrix of RGB pixels
**/
PixelMatrix toPixelMatrix() const;
/**
* @brief Overwrites the current bitmap with that represented by a matrix
* of pixels.
*
* Does _not_ validate that the new matrix of pixels is a proper image.
*
* @param m a matrix of pixels to represent a bitmap
**/
void fromPixelMatrix(const PixelMatrix &m);
};
#include "bitmap.cpp"
#endif