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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
// This file defines the host and device utilities for representing pixel arrays.
//
#ifndef COLOR_ARRAY_HPP_
#define COLOR_ARRAY_HPP_
#include "gpu/buffer.hpp"
#include "gpu/vectorTypes.hpp"
#include <stdint.h>
#include <vector>
namespace VideoStitch {
namespace Image {
template <typename T>
inline std::string typeName(void) {
return "unknown";
}
// See below for details.
struct MonoYPixel;
struct ConstMonoYPixel;
struct RGBSolidPixel;
struct ConstRGBSolidPixel;
struct RGB210Pixel;
struct ConstRGB210Pixel;
struct RGBAPixel;
struct ConstRGBAPixel;
struct RGBASolidPixel;
struct ConstRGBASolidPixel;
struct RGBA64Pixel;
struct ConstRGBA64Pixel;
template <>
inline std::string typeName<MonoYPixel>(void) {
return "MonoY";
}
template <>
inline std::string typeName<RGBSolidPixel>(void) {
return "RGBSolid";
}
template <>
inline std::string typeName<ConstRGBSolidPixel>(void) {
return "RGBSolid";
}
template <>
inline std::string typeName<RGB210Pixel>(void) {
return "RGB210";
}
template <>
inline std::string typeName<ConstRGB210Pixel>(void) {
return "RGB210";
}
template <>
inline std::string typeName<RGBAPixel>(void) {
return "RGBA";
}
template <>
inline std::string typeName<ConstRGBAPixel>(void) {
return "RGBA";
}
template <>
inline std::string typeName<RGBASolidPixel>(void) {
return "RGBASolid";
}
template <>
inline std::string typeName<ConstRGBASolidPixel>(void) {
return "RGBASolid";
}
template <>
inline std::string typeName<RGBA64Pixel>(void) {
return "RGBA64";
}
/**
* Tag for an 8bits grayscale pixel.
*/
struct MonoYPixel {
typedef unsigned char value_type;
typedef unsigned char buffer_value_type;
typedef MonoYPixel NonConst;
typedef ConstMonoYPixel Const;
};
/**
* Tag for an 8bits grayscale pixel.
*/
struct ConstMonoYPixel {
typedef const unsigned char value_type;
typedef const unsigned char buffer_value_type;
typedef MonoYPixel NonConst;
typedef ConstMonoYPixel Const;
};
/**
* Tag for a 24bits solid (no alpha) RGB pixel.
*/
struct RGBSolidPixel {
typedef uchar3 value_type;
typedef uchar3 buffer_value_type;
typedef RGBSolidPixel NonConst;
typedef ConstRGBSolidPixel Const;
};
/**
* Tag for a 24bits solid (no alpha) RGB pixel.
*/
struct ConstRGBSolidPixel {
typedef const uchar3 value_type;
typedef const uchar3 buffer_value_type;
typedef RGBSolidPixel NonConst;
typedef ConstRGBSolidPixel Const;
};
/**
* Tag for a 32bits-packed RGB210 pixel.
* This has alpha on one bit and each color on 9 bits.
*/
struct RGB210Pixel {
typedef uint32_t value_type;
typedef uint32_t buffer_value_type;
typedef RGB210Pixel NonConst;
typedef ConstRGB210Pixel Const;
};
/**
* Tag for a const 32bits-packed RGB210 pixel.
*/
struct ConstRGB210Pixel {
typedef const uint32_t value_type;
typedef const uint32_t buffer_value_type;
typedef RGB210Pixel NonConst;
typedef ConstRGB210Pixel Const;
};
/**
* Tag for a 32bits RGBA pixel. This has each component on 8 bits.
*/
struct RGBAPixel {
typedef uint32_t value_type;
typedef uint32_t buffer_value_type;
typedef RGBAPixel NonConst;
typedef ConstRGBAPixel Const;
};
/**
* Tag for a const 32bits RGBA pixel.
*/
struct ConstRGBAPixel {
typedef const uint32_t value_type;
typedef const uint32_t buffer_value_type;
typedef RGBAPixel NonConst;
typedef ConstRGBAPixel Const;
};
/**
* Tag for a 32bits RGBA pixel. This has each component on 8 bits.
*/
struct RGBASolidPixel {
typedef uint32_t value_type;
typedef uint32_t buffer_value_type;
typedef RGBASolidPixel NonConst;
typedef ConstRGBASolidPixel Const;
};
/**
* Tag for a const 32bits RGBA pixel.
*/
struct ConstRGBASolidPixel {
typedef const uint32_t value_type;
typedef const uint32_t buffer_value_type;
typedef RGBASolidPixel NonConst;
typedef ConstRGBASolidPixel Const;
};
/**
* Tag for a 64bits RGBA pixel. This has each component on 16 bits.
*/
struct RGBA64Pixel {
typedef uint64_t value_type;
typedef uint64_t buffer_value_type;
typedef RGBA64Pixel NonConst;
typedef ConstRGBA64Pixel Const;
};
/**
* Tag for a const 64bits RGBA pixel.
*/
struct ConstRGBA64Pixel {
typedef const uint64_t value_type;
typedef const uint64_t buffer_value_type;
typedef RGBA64Pixel NonConst;
typedef ConstRGBA64Pixel Const;
};
/**
* The arrays don't own the data, they are just wrappers to type a device buffer.
*/
template <class PixelTag>
struct PixelArray {
public:
typedef PixelTag PixelT;
typedef typename PixelTag::value_type value_type;
typedef typename PixelTag::buffer_value_type buffer_value_type;
/**
* Builds an array.
* @param width array width in pixels
* @param height array height in pixels
* @param buffer array data, of size width * height elements. Ownership is not taken.
*/
PixelArray(int64_t width, int64_t height, GPU::Buffer<buffer_value_type> buffer)
: width(width), height(height), buffer(buffer) {}
// PixelArray(int64_t width, int64_t height, buffer_value_type *buffer)
// : width(width), height(height), buffer(GPU::Buffer<buffer_value_type>(buffer, width * height *
// sizeof(buffer_value_type))) {}
/**
* Const pixel arrays can be converted fron non-const ones.
*/
PixelArray(const PixelArray<typename PixelTag::NonConst>& other)
: width(other.width), height(other.height), buffer(other.buffer) {}
/**
* Returns a const version of this array;
*/
PixelArray<typename PixelTag::Const> constify() const { return PixelArray<typename PixelTag::Const>(*this); }
/**
* The width of the array.
*/
const int64_t width;
/**
* The height of the array.
*/
const int64_t height;
/**
* The data of the array.
*/
GPU::Buffer<buffer_value_type> buffer;
};
} // namespace Image
} // namespace VideoStitch
#endif