-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.h
105 lines (89 loc) · 1.95 KB
/
image.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
#ifndef IMAGE_H
#define IMAGE_H
#if 0
#include <assert.h>
template<class BaseType, unsigned char Dimension>
class Sample
{
public:
BaseType v[Dimension];
void set (const BaseType *buffer)
{
for (int i=0; i<Dimension; i++, buffer++)
v[i] = *buffer;
}
void set (const unsigned char d, BaseType t)
{
v[d] = t;
}
void get (BaseType *buffer) const
{
for (int i=0; i<Dimension; i++, buffer++)
*buffer = v[i];
}
BaseType get (unsigned char d) const
{
return v[d];
}
};
template<class BaseType, unsigned char ImageDimension, unsigned char SampleDimension>
class Image
{
public:
typedef enum Dimensions
{
WIDTH = 0, HEIGHT = 1, DEPTH = 2
};
protected:
unsigned int size[ImageDimension]; // 1D = length, 2D = <width, height>, 3D = <width, height, depth>
unsigned int sampleCnt;
void allocSamples ()
{
assert (samples == NULL);
if (sampleCnt > 0)
samples = new Sample<BaseType, SampleDimension>[sampleCnt];
}
void cleanSamples ()
{
if (samples != NULL)
{
delete[] samples;
samples = NULL;
}
}
public:
Sample<BaseType, SampleDimension> *samples;
Image (unsigned int sampleCount)
: sampleCnt (sampleCount), samples (NULL)
{
setSampleCount (sampleCnt);
}
~Image ()
{
setSampleCount (0);
assert (samples == NULL);
}
void setSampleCount (const unsigned int sampleCount)
{
if (sampleCount != sampleCnt)
{
cleanSamples ();
sampleCnt = sampleCount;
allocSamples ();
}
}
void setSize (Dimensions dimension, const unsigned int dsize)
{
size[dimension] = dsize;
}
const unsigned int getSize (Dimensions dimension) const
{
return size[dimension];
}
Sample<BaseType, SampleDimension>& getSample (const unsigned int sampleIndex)
{
return samples[sampleIndex];
}
};
#endif
#endif