-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtexture.hh
181 lines (156 loc) · 4.84 KB
/
texture.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// ============================================================================
//
// Texture channel, with its operators
//
// ============================================================================
#ifndef TEXTURE_CHANNEL_HH
# define TEXTURE_CHANNEL_HH
#define TWO_PI (2 * 3.14159265358979f)
namespace Texture
{
class Channel
{
public:
// Constructors and destructor
Channel();
Channel(unsigned int width, unsigned int height);
Channel(unsigned int width, unsigned int height, unsigned char * data, int stride = 1);
Channel(const Channel &);
~Channel();
// Data index
unsigned int UnsecureGetIndex(unsigned int x, unsigned int y) const;
unsigned int GetIndex(int x, int y) const;
unsigned int GetClampedIndex(int x, int y) const;
// Accessors
unsigned int Width() const;
unsigned int Height() const;
unsigned int Size() const;
const float * operator () () const;
const float operator [] (unsigned int i) const;
float & operator [] (unsigned int i);
float & Pixel(int i, int j);
float Pixel(int i, int j) const;
float Bilinear(float i, float j) const;
// Generators
void ApplyFunction(float (*f)(unsigned int width,
unsigned int height,
unsigned int i,
unsigned int j,
float x,
unsigned char hparam,
unsigned char vparam),
unsigned char hparam,
unsigned char vparam);
// void operator () (const unsigned int, const float);
void Clear();
void Flat(float v);
void Gradient(float a, float b, float c, float d);
void AddCuts(float density, float length);
void Cells(unsigned int cells);
void Cells2(unsigned int cells);
void Conic();
void Radial();
void Square();
void Diamond();
void Fade(float angle);
void Perlin(unsigned char frequency,
unsigned char stretch,
unsigned char,
float time);
void Sinus(unsigned char hfrequency,
unsigned char vfrequency);
void Cosinus(unsigned char hfrequency,
unsigned char vfrequency);
void Random();
// Filters
void Cut(int n = 1);
void Abs();
void Pow(float exp);
void Clamp(float min, float max);
void Scale(float min, float max);
void ClampAndScale(float min, float max);
void Mod();
void Sin();
void NegativeNormalized();
void Segment(float);
void ApplyFilter(const float * filter,
unsigned int size,
float factor);
// Painting
void FloodFill(unsigned x, unsigned y, float newColor);
void Line(float x0, float y0, float x1, float y1);
void Linei(int x0, int y0, int x1, int y1);
void Bump();
void Blur();
void Sharpen();
void Emboss();
void EdgeDetect();
void GaussianBlur();
void Dilate(float radius);
void HorizontalMotionBlur(float length);
void VerticalMotionBlur(float length);
void VerticalDribble();
// Matrix
void Translate(float hshift, float vshift);
void Translatei(int hshift, int vshift);
void ClampedTranslatei(int hshift, int vshift);
void HorizontalFlip();
void VerticalFlip();
void Transpose();
void Rotate90();
void HorizontalWave(float frequency, float amplitude);
void VerticalWave(float frequency, float amplitude);
void Waves(float angle, float amplitude, const Channel& waves);
void AverageScale(unsigned int n, float coef);
void ZoomOut(float zx, float zy);
// Operators
void Mix(float factor, const Channel & a);
void Mask(const Channel & mask, const Channel & a);
void MinimizeTo(const Channel & a);
void MaximizeTo(const Channel & a);
void subCopy(const Channel & a,
unsigned int srcx, unsigned int srcy,
unsigned int dstx, unsigned int dsty,
unsigned int width, unsigned int height);
void operator += (const Channel & a);
void operator -= (const Channel & a);
void operator *= (const Channel & a);
void operator *= (float a);
void operator /= (float a);
void Mult (float a) { *this *= a; }
// Channel Min(const Channel &) const;
// Channel Max(const Channel &) const;
// Channel operator + (const Channel &) const;
// Channel operator - (const Channel &) const;
// Channel operator * (const Channel &) const;
Channel& operator = (const Channel &);
private:
unsigned int _size;
unsigned int _width;
unsigned int _height;
float * _data;
void CellsGen(unsigned int cells, unsigned int n);
};
inline unsigned int Channel::Width() const
{
return _width;
}
inline unsigned int Channel::Height() const
{
return _height;
}
inline unsigned int Channel::Size() const
{
return _size;
}
inline const float * Channel::operator () () const
{
return _data;
}
inline float & Channel::operator [] (unsigned int i)
{
// assert(i < _size);
return _data[i];
}
}
#endif // TEXTURE_CHANNEL_HH