-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdim.h
130 lines (99 loc) · 2.24 KB
/
dim.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
///
/// @file Predefined images constants and enumerations
///
/// @author Alex Karev
///
#ifndef _DIMS_INC_
#define _DIMS_INC_
#include <utility>
#include <cstdlib>
namespace vid {
enum BytesPerPixel {
GRAYSCALE = 1,
COLORFULL = 3
};
enum ColorOrder {
RGB,
BGR,
G
};
/// @note In case you udate this enum don't forget to add to get_size table new field
enum class ImageType {
// 640x480
SIZE640x480c, // color
SIZE640x480g, // grayscale
// 320x240
SIZE320x240c,
SIZE320x240g,
Undefined,
IMAGE_TYPES_NUM
};
enum class Fps {
FPS3 = 3,
FPS7 = 7,
FPS10 = 10,
FPS15 = 15,
FPS20 = 20,
FPS25 = 25,
FPS30 = 30,
FPS60 = 60,
FPS_NUM
};
template<size_t W, size_t H, BytesPerPixel S, ColorOrder C=ColorOrder::G> struct Dim;
class DecImgParams;
ImageType itype(const DecImgParams &);
/// Help functions
const size_t get_size(ImageType type);
const unsigned get_width(ImageType &);
const unsigned get_height(ImageType &);
const size_t get_size(unsigned type);
unsigned get_fps(Fps fps);
}
///
/// @struct Dim
///
/// @brief Conventional struct to get some constant image parameters
///
/// @param W width
/// @param H height
/// @param S bytes per pixel
///
template<size_t W, size_t H, vid::BytesPerPixel S, vid::ColorOrder C>
struct vid::Dim {
static constexpr size_t size() { ///< returns pure raw, decompressed image size in bytes
return W * H * S;
}
static size_t height() {
return H;
}
static size_t width() {
return W;
}
static unsigned bytes_per_pixel() {
return static_cast<unsigned>(S);
}
};
///
/// @struct DecImgParams
///
/// @brief used in incoming image decompression
///
struct vid::DecImgParams {
unsigned width;
unsigned height;
unsigned out_colors;
};
namespace vid {
///< Some predifined common image demensions
typedef Dim<640,480, vid::BytesPerPixel::COLORFULL> Dim640x480c;
typedef Dim<640,480, vid::BytesPerPixel::GRAYSCALE> Dim640x480g;
typedef Dim<320,240, vid::BytesPerPixel::COLORFULL> Dim320x240c;
typedef Dim<320,240, vid::BytesPerPixel::GRAYSCALE> Dim320x240g;
enum VideoModeFields {
ImageTypeField,
FpsField
};
typedef std::tuple<ImageType, Fps> VideoMode;
const vid::DecImgParams get_geom(ImageType &t);
}
#endif