-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcImage.hh
75 lines (63 loc) · 1.47 KB
/
cImage.hh
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
#pragma once
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gd.h>
#include <gdfontg.h>
#include <gdfontl.h>
#include <gdfontmb.h>
#include <gdfonts.h>
#include <gdfontt.h>
#include <gdfx.h>
/**
* @brief class to hold and modify the image
*
*/
class cImage
{
private:
gdImagePtr m_img; // the image
int m_colors[5]; // the colors
void initColors();
public:
int m_width; // width of the image
int m_height; // height of the image
std::string m_imgFileName;
cImage();
cImage(int t_w, int t_h);
~cImage();
void setWidthHeight(int t_w, int t_h);
bool saveImage(int t_i, int t_grains);
std::string getImgFileName();
/**
* @brief Set the Pixel at x,y to color t_cc
*
* @param t_x
* @param t_y
* @param t_cc value 0-4
*/
inline void setPixel(int t_x, int t_y, int t_cc)
{
// check for out of bounds
if (t_x < 0 || t_y < 0 || t_x > m_width - 1 || t_y > m_height - 1)
return;
// check for out of bounds color
if (t_cc < 0)
t_cc = 0;
if (t_cc > 4)
t_cc = 4;
// check for no image
if (m_img == NULL)
{
std::cout << "setPixel, img==NULL" << std::endl;
return;
}
// set the pixel
gdImageSetPixel(m_img, t_x, t_y, m_colors[t_cc]);
}
};