$extrastylesheet
Olena
User documentation 2.1
An Image Processing Platform
Scribo
Modules
Namespaces
Classes
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
compute_text_colour.hh
1
// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
// Olena is free software: you can redistribute it and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, version 2 of the License.
8
//
9
// Olena is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
16
//
17
// As a special exception, you may use this file as part of a free
18
// software project without restriction. Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
// file, or you compile this file and link it with other files to produce
21
// an executable, this file does not by itself cause the resulting
22
// executable to be covered by the GNU General Public License. This
23
// exception does not however invalidate any other reasons why the
24
// executable file might be covered by the GNU General Public License.
25
26
#ifndef SCRIBO_IO_XML_INTERNAL_COMPUTE_TEXT_COLOUR_HH
27
# define SCRIBO_IO_XML_INTERNAL_COMPUTE_TEXT_COLOUR_HH
28
32
33
# include <mln/value/rgb8.hh>
34
# include <mln/value/int_u8.hh>
35
# include <mln/make/vec.hh>
36
# include <mln/norm/l2.hh>
37
38
39
namespace
scribo
40
{
41
42
namespace
io
43
{
44
45
namespace
xml
46
{
47
48
namespace
internal
49
{
50
51
using namespace
mln;
52
53
const
char
*
54
compute_text_colour(
const
value::rgb8& v);
55
56
57
struct
color_t
58
{
59
const
algebra::vec<3, value::int_u8>
v;
60
const
char
*name;
61
float
res;
62
};
63
64
65
# ifndef MLN_INCLUDE_ONLY
66
67
68
inline
69
const
char
*
70
compute_text_colour(
const
value::rgb8
& v)
71
{
72
static
color_t
colors[] = {
73
{
mln::make::vec
(0, 0, 0),
"black"
, 0 },
74
{
mln::make::vec
(255, 0, 0),
"red"
, 0 },
75
{
mln::make::vec
(255, 255, 255),
"white"
, 0 },
76
{
mln::make::vec
(0, 255, 0),
"green"
, 0 },
77
{
mln::make::vec
(0, 0, 255),
"blue"
, 0 },
78
{
mln::make::vec
(255, 255, 0),
"yellow"
, 0 },
79
{
mln::make::vec
(255, 165, 0),
"orange"
, 0 },
80
{
mln::make::vec
(255, 192, 203),
"pink"
, 0 },
81
{
mln::make::vec
(192, 192, 192),
"grey"
, 0 },
82
{
mln::make::vec
(64, 224, 208),
"turquoise"
, 0 },
83
{
mln::make::vec
(75, 0, 130),
"indigo"
, 0 },
84
{
mln::make::vec
(238, 130, 238),
"violet"
, 0 },
85
{
mln::make::vec
(0, 255, 255),
"cyan"
, 0 },
86
{
mln::make::vec
(255, 0, 255),
"magenta"
, 0 },
87
{
mln::make::vec
(0, 0, 0), 0, 0 }
// Invalid
88
};
89
90
unsigned
closest = 0;
91
for
(
unsigned
i = 0; colors[i].name; ++i)
92
{
93
colors[i].res =
norm::l2_distance
(colors[i].v, v.
to_equiv
());
94
if
(colors[closest].res > colors[i].res)
95
closest = i;
96
}
97
98
return
colors[closest].name;
99
}
100
101
#endif // MLN_INCLUDE_ONLY
102
103
}
// end of namespace scribo::io::xml::internal
104
105
}
// end of namespace scribo::io::xml
106
107
}
// end of namespace scribo::io
108
109
}
// end of namespace scribo
110
111
112
#endif // ! SCRIBO_IO_XML_INTERNAL_COMPUTE_TEXT_COLOUR_HH
scribo
scribo
io
xml
internal
compute_text_colour.hh
Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)