-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinearimage.cpp
46 lines (40 loc) · 1.13 KB
/
linearimage.cpp
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
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "linearimage.h"
template<typename T>
LinearImage<T>::LinearImage (int w, int h) : Image<T>(w, h)
{
this->data = new T[w * h];
memset (this->data, 0, w * h * sizeof(T));
}
template<typename T>
LinearImage<T>::~LinearImage ()
{
delete[] this->data;
}
template<typename T>
void LinearImage<T>::get (T *buf, rectangle r)
{
size_t offset = (r.y * this->width + r.x);
for (int y = r.y; y < r.y + r.height; y++)
{
memcpy (buf, this->data + offset, r.width * sizeof(T));
buf += r.width;
offset += this->width;
}
}
template<typename T>
void LinearImage<T>::set (T *buf, rectangle r)
{
size_t offset = (r.y * this->width + r.x);
for (int y = r.y; y < r.y + r.height; y++)
{
memcpy (this->data + offset, buf, r.width * sizeof(T));
buf += r.width;
offset += this->width;
}
}
static LinearImage<unsigned char> a (0, 0);
static LinearImage<float> b (0, 0);
static LinearImage<rgbaf> c (0, 0);