jitcv.h
4.27 KB
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
#ifndef __JITCV_H
#define __JITCV_H
#include <stddef.h>
#include <stdint.h>
#include <openbr.h>
/*!
* \brief jitcv matrix
* \author Josh Klontz \cite jklontz
* \note Not part of the core SDK
*/
struct Matrix
{
uint8_t *data; /*!< Data */
uint32_t channels; /*!< Channels */
uint32_t columns; /*!< Columns */
uint32_t rows; /*!< Rows */
uint32_t frames; /*!< Frames */
uint16_t hash; /*!< Bits : 8
Floating : 1
Signed : 1
(Reserved) : 2
Single-channel : 1
Single-column : 1
Single-row : 1
Single-frame : 1 */
enum Hash { Bits = 0x00FF,
Floating = 0x0100,
Signed = 0x0200,
SingleChannel = 0x1000,
SingleColumn = 0x2000,
SingleRow = 0x4000,
SingleFrame = 0x8000,
u1 = 1,
u8 = 8,
u16 = 16,
u32 = 32,
u64 = 64,
s8 = 8 + Signed,
s16 = 16 + Signed,
s32 = 32 + Signed,
s64 = 64 + Signed,
f16 = 16 + Floating + Signed,
f32 = 32 + Floating + Signed,
f64 = 64 + Floating + Signed };
Matrix() : data(NULL), channels(0), columns(0), rows(0), frames(0), hash(0) {}
Matrix(uint32_t _channels, uint32_t _columns, uint32_t _rows, uint32_t _frames, uint16_t _hash)
: data(NULL), channels(_channels), columns(_columns), rows(_rows), frames(_frames), hash(_hash)
{
setSingleChannel(channels == 1);
setSingleColumn(columns == 1);
setSingleRow(rows == 1);
setSingleFrame(frames == 1);
}
inline void copyHeader(const Matrix &other) { channels = other.channels; columns = other.columns; rows = other.rows; frames = other.frames; hash = other.hash; }
inline void allocate() { deallocate(); data = new uint8_t[bytes()]; }
inline void deallocate() { delete[] data; data = NULL; }
inline int bits() const { return hash & Bits; }
inline void setBits(int bits) { hash &= ~Bits; hash |= bits & Bits; }
inline bool isFloating() const { return hash & Floating; }
inline void setFloating(bool isFloating) { isFloating ? setSigned(true), hash |= Floating : hash &= ~Floating; }
inline bool isSigned() const { return hash & Signed; }
inline void setSigned(bool isSigned) { isSigned ? hash |= Signed : hash &= ~Signed; }
inline int type() const { return hash & (Bits + Floating + Signed); }
inline void setType(int type) { hash &= ~(Bits + Floating + Signed); hash |= type & (Bits + Floating + Signed); }
inline bool singleChannel() const { return hash & SingleChannel; }
inline void setSingleChannel(bool singleChannel) { singleChannel ? hash |= SingleChannel : hash &= ~SingleChannel; }
inline bool singleColumn() const { return hash & SingleColumn; }
inline void setSingleColumn(bool singleColumn) { singleColumn ? hash |= SingleColumn : hash &= ~SingleColumn; }
inline bool singleRow() const { return hash & SingleRow; }
inline void setSingleRow(bool singleRow) { singleRow ? hash |= SingleRow : hash &= ~SingleRow; }
inline bool singleFrame() const { return hash & SingleFrame; }
inline void setSingleFrame(bool singleFrame) { singleFrame ? hash |= SingleFrame : hash &= ~SingleFrame; }
inline uint32_t elements() const { return channels * columns * rows * frames; }
inline uint32_t bytes() const { return bits() / 8 * elements(); }
};
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*UnaryFunction)(const Matrix *src, Matrix *dst);
typedef void (*BinaryFunction)(const Matrix *srcA, const Matrix *srcB, Matrix *dst);
BR_EXPORT UnaryFunction makeUnaryFunction(const char *description);
BR_EXPORT BinaryFunction makeBinaryFunction(const char *description);
typedef void (*UnaryKernel)(const Matrix *src, Matrix *dst, uint32_t size);
typedef void (*BinaryKernel)(const Matrix *srcA, const Matrix *srcB, Matrix *dst, uint32_t size);
BR_EXPORT UnaryKernel makeUnaryKernel(const char *description, const Matrix *src);
BR_EXPORT BinaryKernel makeBinaryKernel(const char *description, const Matrix *srcA, const Matrix *srcB);
#ifdef __cplusplus
}
#endif
#endif // __JITCV_H