-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buffer.h
107 lines (87 loc) · 1.66 KB
/
Buffer.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
#ifndef MANDELBROT_BUFFER_H
#define MANDELBROT_BUFFER_H
#include "Point.h"
#include "Sample.h"
#include <cstdlib>
namespace MB
{
class Buffer {
public:
/**
* Create a new empty buffer.
*
* @param width The width
* @param height The height
*/
Buffer(int width, int height)
{
m_width = width;
m_height = height;
m_data = (float*) malloc(sizeof(float) * width * height * 3);
}
/**
* Delete the buffer
*/
~Buffer()
{
free(m_data);
}
/**
* Put rgb values at coordinates.
*
* @param i, j The buffer coordinates
* @param r, g, b The color values
*/
inline void put(int i, int j, float r, float g, float b)
{
m_data[3 * (j * m_width + i) + 0] = r;
m_data[3 * (j * m_width + i) + 1] = g;
m_data[3 * (j * m_width + i) + 2] = b;
}
/**
* Put a sample into the buffer.
*
* @param sample The sample
*/
inline void put(const Sample &sample)
{
for (int i = 0; i < sample.size; i++) {
for (int j = 0; j < sample.size; j++) {
put(sample.screen.x + i, sample.screen.y + j, sample.r, sample.g, sample.b);
}
}
}
/**
* The width of the buffer.
*
* @return The width
*/
const int &width() const
{
return m_width;
}
/**
* The height of the buffer.
*
* @return The height
*/
const int &height() const
{
return m_height;
}
/**
* The underlying buffer structure.
*
* @return The buffer
*/
const float *data()
{
return m_data;
}
private:
int m_width;
int m_height;
float *m_data;
};
}
#endif