-
Notifications
You must be signed in to change notification settings - Fork 10
/
rgbline.h
112 lines (92 loc) · 2.06 KB
/
rgbline.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
#ifndef RGBLINE_H
#define RGBLINE_H
#include <ostream>
#include <iostream>
// A simple class to hold six arrays of numbers:
class rgbLine {
private:
float * r_raw;
float * g_raw;
float * b_raw;
unsigned char* red;
unsigned char* green;
unsigned char* blue;
int size;
void allocate()
{
r_raw = (float*)calloc(size, sizeof(float));
g_raw = (float*)calloc(size, sizeof(float));
b_raw = (float*)calloc(size, sizeof(float));
red = (unsigned char*)calloc(size, sizeof(char));
green = (unsigned char*)calloc(size, sizeof(char));
blue = (unsigned char*)calloc(size, sizeof(char));
}
void quick_allocate()
{
r_raw = (float*)malloc(size * sizeof(float));
g_raw = (float*)malloc(size * sizeof(float));
b_raw = (float*)malloc(size * sizeof(float));
red = (unsigned char*)malloc(size * sizeof(char));
green = (unsigned char*)malloc(size * sizeof(char));
blue = (unsigned char*)malloc(size * sizeof(char));
}
public:
rgbLine(int size, bool quick)
{
this->size = size;
if(quick)
quick_allocate();
else
allocate();
}
// Default to quick mode
rgbLine(int size)
{
this->size = size;
quick_allocate();
}
rgbLine()
{
}
~rgbLine()
{
//std::cout << "destructor running" << std::endl;
free(r_raw);
free(g_raw);
free(b_raw);
free(red);
free(blue);
free(green);
//std::cout << "destructor finished" << std::endl;
}
void setSize(int size)
{
this->size = size;
this->allocate();
}
float* getr_raw()
{
return r_raw;
}
float* getg_raw()
{
return g_raw;
}
float* getb_raw()
{
return b_raw;
}
unsigned char* getRed()
{
return red;
}
unsigned char* getGreen()
{
return green;
}
unsigned char* getBlue()
{
return blue;
}
};
#endif // RGBLINE_H