Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
1c6c1026
Commit
1c6c1026
authored
Aug 11, 2016
by
LEFEBVREJP email
Browse files
Addition matrix and color work.
parent
d70c7148
Changes
5
Hide whitespace changes
Inline
Side-by-side
radixcolor/color.cc
View file @
1c6c1026
#include "radixcolor/color.hh"
#include "radixmath/matrix.hh"
namespace
radix
{
TMatrix
<
3
,
3
>
Color
::
bradford_matrix
=
TMatrix
<
3
,
3
>
({{
1.047835
,
0.022897
,
-
0.050147
}
,{
0.029556
,
0.990481
,
-
0.017056
}
,{
-
0.009238
,
0.015050
,
0.752034
}});
TMatrix
<
3
,
3
>
Color
::
srgb_matrix
=
TMatrix
<
3
,
3
>
({{
0.412424
,
0.357579
,
0.180464
}
,{
0.212656
,
0.715158
,
0.072186
}
,{
0.019332
,
0.119193
,
0.950444
}});
TMatrix
<
3
,
3
>
Color
::
bradford_srgb_matrix
=
Color
::
bradford_matrix
*
Color
::
srgb_matrix
;
Color
::
Color
()
:
mR
(
255
)
,
mG
(
255
)
...
...
@@ -48,4 +57,60 @@ void Color::setB(int b)
mB
=
b
;
}
LAB
Color
::
toLAB
()
const
{
LAB
r
;
Real
fXX0
=
0
;
Real
fYY0
=
0
;
Real
fZZ0
=
0
;
TMatrix
<
3
,
1
>
gMat
({{
Color
::
g
(
mR
/
255.0
)}
,{
Color
::
g
(
mG
/
255.0
)}
,{
Color
::
g
(
mG
/
255.0
)}});
TMatrix
<
3
,
1
>
XYZ
=
Color
::
bradford_srgb_matrix
*
gMat
;
tmatrix_value_t
X0
=
0.964221
;
tmatrix_value_t
Y0
=
1.0
;
tmatrix_value_t
Z0
=
0.825213
;
fXX0
=
Color
::
f
(
XYZ
.
data
()[
0
][
0
]
/
X0
);
fYY0
=
Color
::
f
(
XYZ
.
data
()[
1
][
0
]
/
Y0
);
fZZ0
=
Color
::
f
(
XYZ
.
data
()[
2
][
0
]
/
Z0
);
r
.
setL
(
116.0
*
fYY0
-
16.0
);
r
.
setA
(
500.0
*
(
fXX0
-
fYY0
));
r
.
setB
(
200.0
*
(
fYY0
-
fZZ0
));
return
r
;
}
Real
Color
::
f
(
Real
z
)
{
if
(
z
>
0.008856
)
{
return
std
::
pow
(
z
,
1.0
/
3.0
);
}
else
{
return
7.787
*
z
+
16.0
/
116.0
;
}
}
Real
Color
::
g
(
Real
z
)
{
if
(
z
>
0.04045
)
{
return
std
::
pow
((
z
+
0.055
)
/
1.055
,
2.4
);
}
else
{
return
z
/
12.92
;
}
}
LAB
::
LAB
()
:
mL
(
0
)
,
mA
(
0
)
,
mB
(
0
)
{
}
LAB
::
LAB
(
int
l
,
int
a
,
int
b
)
:
mL
(
l
)
,
mA
(
a
)
,
mB
(
b
)
{
}
}
// namespace radix
radixcolor/color.hh
View file @
1c6c1026
#ifndef RADIX_RADIXCOLOR_COLOR_HH_
#define RADIX_RADIXCOLOR_COLOR_HH_
#include "radixmath/constants.hh"
#include "radixmath/matrix.hh"
namespace
radix
{
class
LAB
{
Real
mL
,
mA
,
mB
;
public:
LAB
();
LAB
(
int
l
,
int
a
,
int
b
);
int
l
()
const
{
return
mL
;
}
void
setL
(
int
v
)
{
mL
=
v
;
}
int
a
()
const
{
return
mA
;
}
void
setA
(
int
v
)
{
mA
=
v
;
}
int
b
()
const
{
return
mB
;
}
void
setB
(
int
v
)
{
mB
=
v
;
}
};
/**
* @brief The Color(rgb) class
*/
class
Color
{
int
mR
,
mG
,
mB
;
...
...
@@ -26,6 +45,13 @@ public:
void
setG
(
int
g
);
int
b
()
const
;
void
setB
(
int
b
);
LAB
toLAB
()
const
;
static
TMatrix
<
3
,
3
>
bradford_matrix
;
static
TMatrix
<
3
,
3
>
srgb_matrix
;
static
TMatrix
<
3
,
3
>
bradford_srgb_matrix
;
private:
static
Real
f
(
Real
z
);
static
Real
g
(
Real
z
);
};
// class Color
}
// namespace radix
#endif
/** RADIX_RADIXCOLOR_COLOR_HH_ */
radixcolor/tests/tstColor.cc
View file @
1c6c1026
#include "gtest/gtest.h"
TEST
(
Radix
,
Color
)
#include "radixcolor/color.hh"
using
namespace
radix
;
TEST
(
Radix
,
DISABLED_RGBtoLAB
)
{
{
Color
rgb
(
255
,
255
,
255
);
LAB
lab
=
rgb
.
toLAB
();
EXPECT_EQ
(
100
,
lab
.
l
());
EXPECT_EQ
(
0.00526049995830391
,
lab
.
a
());
EXPECT_EQ
(
-
0.010408184525267927
,
lab
.
b
());
}
{
Color
rgb
(
100
,
255
,
1
);
LAB
lab
=
rgb
.
toLAB
();
EXPECT_EQ
(
89.0317899987809
,
lab
.
l
());
EXPECT_EQ
(
-
74.86753281894853
,
lab
.
a
());
EXPECT_EQ
(
84.68384242989339
,
lab
.
b
());
}
}
radixmath/matrix.hh
View file @
1c6c1026
...
...
@@ -2,6 +2,7 @@
#define RADIX_RADIXMATH_MATRIX_H
#include <string>
#include <array>
#include <initializer_list>
#include "radixmath/constants.hh"
namespace
radix
{
...
...
@@ -25,6 +26,7 @@ private:
public:
TMatrix
();
TMatrix
(
const
std
::
initializer_list
<
std
::
initializer_list
<
value_t
>>&
l
);
bool
equals
(
const
TMatrix
<
N
,
M
>&
m
,
Real
eps
=
kEpsilon
)
const
;
value_array_t
&
operator
[](
size_t
i
)
{
return
mData
[
i
];}
const
value_array_t
&
operator
[](
size_t
i
)
const
{
return
mData
[
i
];}
...
...
radixmath/matrix.i.hh
View file @
1c6c1026
#include <algorithm>
#include <cmath>
#include "radixbug/bug.hh"
#include "radixmath/matrix.hh"
namespace
radix
{
...
...
@@ -13,6 +14,24 @@ TMatrix<N,M>::TMatrix()
}
}
template
<
tmatrix_index_t
N
,
tmatrix_index_t
M
>
TMatrix
<
N
,
M
>::
TMatrix
(
const
std
::
initializer_list
<
std
::
initializer_list
<
tmatrix_value_t
>>&
l
)
{
radix_check
(
N
==
l
.
size
());
radix_check
(
M
==
l
.
begin
()
->
size
());
size_t
i
=
0
;
for
(
auto
&
subl
:
l
)
{
size_t
j
=
0
;
for
(
auto
v
:
subl
)
{
mData
[
i
][
j
]
=
v
;
++
j
;
}
++
i
;
}
}
template
<
tmatrix_index_t
N
,
tmatrix_index_t
M
>
bool
TMatrix
<
N
,
M
>::
equals
(
const
TMatrix
<
N
,
M
>&
m
,
Real
eps
)
const
{
...
...
@@ -122,4 +141,5 @@ TMatrix<N,M> TMatrix<N,M>::pow(int k) const
return
r
;
}
}
// namespace radix
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment