-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_types.h
119 lines (101 loc) · 3.53 KB
/
base_types.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
/* Developed by Jimmy Hu */
#ifndef TINYDIP_BASE_TYPES_H // base_types.h header guard, follow the suggestion from https://codereview.stackexchange.com/a/293832/231235
#define TINYDIP_BASE_TYPES_H
#include <cstdint>
#include <filesystem>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
namespace TinyDIP
{
// RGB struct implementation
struct RGB
{
std::uint8_t channels[3];
inline RGB operator+(const RGB& input) const
{
return RGB{
static_cast<std::uint8_t>(input.channels[0] + channels[0]),
static_cast<std::uint8_t>(input.channels[1] + channels[1]),
static_cast<std::uint8_t>(input.channels[2] + channels[2]) };
}
inline RGB operator-(const RGB& input) const
{
return RGB{
static_cast<std::uint8_t>(channels[0] - input.channels[0]),
static_cast<std::uint8_t>(channels[1] - input.channels[1]),
static_cast<std::uint8_t>(channels[2] - input.channels[2]) };
}
friend std::ostream& operator<<(std::ostream& out, const RGB& _myStruct)
{
out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}';
return out;
}
};
struct RGB_DOUBLE
{
double channels[3];
};
using GrayScale = std::uint8_t;
struct HSV
{
double channels[3]; // Range: 0 <= H < 360, 0 <= S <= 1, 0 <= V <= 255
inline HSV operator+(const HSV& input) const
{
return HSV{
input.channels[0] + channels[0],
input.channels[1] + channels[1],
input.channels[2] + channels[2] };
}
inline HSV operator-(const HSV& input) const
{
return HSV{
channels[0] - input.channels[0],
channels[1] - input.channels[1],
channels[2] - input.channels[2] };
}
friend std::ostream& operator<<(std::ostream& out, const HSV& _myStruct)
{
out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}';
return out;
}
};
// MultiChannel struct implementation
template<class ElementT, std::size_t channel_count = 3>
struct MultiChannel
{
std::array<ElementT, channel_count> channels;
inline MultiChannel operator+(const MultiChannel& input) const
{
std::array<ElementT, channel_count> channels_output;
for(std::size_t i = 0; i < channels.size(); ++i)
{
channels_output[i] = channels[i] + input.channels[i];
}
return MultiChannel{channels_output};
}
inline MultiChannel operator-(const MultiChannel& input) const
{
return MultiChannel{
channels[0] - input.channels[0],
channels[1] - input.channels[1],
channels[2] - input.channels[2] };
}
friend std::ostream& operator<<(std::ostream& out, const MultiChannel& _myStruct)
{
out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}';
return out;
}
};
struct BMPIMAGE
{
std::filesystem::path FILENAME;
unsigned int XSIZE;
unsigned int YSIZE;
std::uint8_t FILLINGBYTE;
std::uint8_t* IMAGE_DATA;
};
}
#endif