Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
cd568483
Commit
cd568483
authored
Sep 11, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added one more function to convert colors.
parent
7d4aed10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
gr_basic.cpp
common/gr_basic.cpp
+10
-10
colors.h
include/colors.h
+8
-0
No files found.
common/gr_basic.cpp
View file @
cd568483
...
...
@@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T aColor )
EDA_COLOR_T
ColorFindNearest
(
const
wxColour
&
aColor
)
{
EDA_COLOR_T
candidate
=
BLACK
;
return
ColorFindNearest
(
aColor
.
Red
(),
aColor
.
Green
(),
aColor
.
Blue
()
);
}
// These are ints because we will subtract them later
int
r
=
aColor
.
Red
();
int
g
=
aColor
.
Green
();
int
b
=
aColor
.
Blue
();
EDA_COLOR_T
ColorFindNearest
(
int
aR
,
int
aG
,
int
aB
)
{
EDA_COLOR_T
candidate
=
BLACK
;
/* Find the 'nearest' color in the palette. This is fun. There is
a gazilion of metrics for the color space and no one of the
...
...
@@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
for
(
EDA_COLOR_T
trying
=
BLACK
;
trying
<
NBCOLORS
;
trying
=
NextColor
(
trying
)
)
{
const
StructColors
&
c
=
g_ColorRefs
[
trying
];
int
distance
=
(
r
-
c
.
m_Red
)
*
(
r
-
c
.
m_Red
)
+
(
g
-
c
.
m_Green
)
*
(
g
-
c
.
m_Green
)
+
(
b
-
c
.
m_Blue
)
*
(
b
-
c
.
m_Blue
);
if
(
distance
<
nearest_distance
&&
c
.
m_Red
>=
r
&&
c
.
m_Green
>=
g
&&
c
.
m_Blue
>=
b
)
int
distance
=
(
aR
-
c
.
m_Red
)
*
(
aR
-
c
.
m_Red
)
+
(
aG
-
c
.
m_Green
)
*
(
aG
-
c
.
m_Green
)
+
(
aB
-
c
.
m_Blue
)
*
(
aB
-
c
.
m_Blue
);
if
(
distance
<
nearest_distance
&&
c
.
m_Red
>=
aR
&&
c
.
m_Green
>=
aG
&&
c
.
m_Blue
>=
aB
)
{
nearest_distance
=
distance
;
candidate
=
trying
;
...
...
include/colors.h
View file @
cd568483
...
...
@@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName );
/// Find the nearest color match
EDA_COLOR_T
ColorFindNearest
(
const
wxColour
&
aColor
);
/**
* Find the nearest color match
* @param aR is the red component of the color to be matched (in range 0-255)
* @param aG is the green component of the color to be matched (in range 0-255)
* @param aG is the blue component of the color to be matched (in range 0-255)
*/
EDA_COLOR_T
ColorFindNearest
(
int
aR
,
int
aG
,
int
aB
);
/**
* Check if a color is light i.e. if black would be more readable than
* white on it
...
...
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