-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel_helper.cpp
More file actions
93 lines (80 loc) · 1.84 KB
/
pixel_helper.cpp
File metadata and controls
93 lines (80 loc) · 1.84 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
#include <iostream>
#include "pixel_helper.hpp"
using std::cout;
using std::endl;
using std::ostream;
namespace ORGB
{
RGB_point to_RGB_point(const Pixel pixel)
{
assert((pixel.x <= 255) && (pixel.y <= 255) && (pixel.z <= 255)
&& (pixel.x >= 0) && (pixel.y >= 0) && (pixel.z >= 0));
RGB_point p;
p.r = static_cast<double>(pixel.z)/255;
p.g = static_cast<double>(pixel.y)/255;
p.b = static_cast<double>(pixel.x)/255;
return p;
//return RGB_point{static_cast<double>(pixel.z/255), static_cast<double>(pixel.y/255, pixel.x/255};
}
/*
Pixel.z is Red channel
Pixel.x is Blue channel
Pixel.y is Green channel
*/
Pixel to_Pixel(const RGB_point& rgb)
{
assert( (rgb.r <= 1) && (rgb.r >= 0) &&
(rgb.b <= 1) && (rgb.b >= 0) &&
(rgb.g <= 1) && (rgb.g >= 0) );
Pixel p;
p.x = round(rgb.b* 255);
p.y = round(rgb.g* 255);
p.z = round(rgb.r* 255);
return p;
}
ostream& operator<<(ostream& os, const Pixel p)
{
os<<(int)p.x<<'\t'<<(int)p.y<<'\t'<<(int)p.z;
return os;
}
ostream& operator<<(ostream& os, const RGB_point p)
{
os<<p.r<<'\t'<<p.g<<'\t'<<p.b;
return os;
}
ostream& operator<<(ostream& os, const LCC_point p)
{
os<<p.l<<'\t'<<p.c1<<'\t'<<p.c2;
return os;
}
double clamp_to_absolute_val(double val, const int ref)
{
assert( ref>= 0);
if (val > ref)
return ref;
else if (val < -ref)
return -ref;
return val;
}
LCC_point& LCC_point::clamp() {
if (l <0)
l = 0;
else if (l > 1)
l = 1;
c1 = clamp_to_absolute_val(c1, 1);
c2 = clamp_to_absolute_val(c2, 1);
return *this;
}
RGB_point& RGB_point::clamp() {
auto clamp = [] (double& d) {
if (d < 0)
d = 0;
else if (d > 1)
d = 1;
};
clamp(r);
clamp(g);
clamp(b);
return *this;
}
}