Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
95aa7ed0
Commit
95aa7ed0
authored
Feb 13, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
automatic foreground/background color detection
parent
be339ff9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
src/data/format/image_to_symbol.cpp
src/data/format/image_to_symbol.cpp
+20
-5
No files found.
src/data/format/image_to_symbol.cpp
View file @
95aa7ed0
...
@@ -39,10 +39,11 @@ void greyscale(Image& img) {
...
@@ -39,10 +39,11 @@ void greyscale(Image& img) {
/// Thresholds an image, giving a black & white result
/// Thresholds an image, giving a black & white result
/** The threshold is determined automatically
/** The threshold is determined automatically
* The output is stored in the data array,
EMPTY for black, FULL for white
* The output is stored in the data array,
*
If invert is used, use EMPTY for white and FULL for black
*
EMPTY for the 'border' color, FULL for the interior
*/
*/
void
threshold
(
Byte
*
data
,
size_t
size
,
bool
invert
=
true
)
{
void
threshold
(
Byte
*
data
,
int
w
,
int
h
)
{
size_t
size
=
w
*
h
;
// make histogram of data
// make histogram of data
size_t
hist
[
256
];
size_t
hist
[
256
];
fill_n
(
hist
,
256
,
0
);
fill_n
(
hist
,
256
,
0
);
...
@@ -66,7 +67,21 @@ void threshold(Byte* data, size_t size, bool invert = true) {
...
@@ -66,7 +67,21 @@ void threshold(Byte* data, size_t size, bool invert = true) {
}
}
// threshold data
// threshold data
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
data
[
i
]
=
(
data
[
i
]
>=
threshold
)
!=
invert
?
FULL
:
EMPTY
;
data
[
i
]
=
data
[
i
]
>=
threshold
?
FULL
:
EMPTY
;
}
// should the colors be inverted?
int
border_count
=
0
;
for
(
int
x
=
0
;
x
<
w
;
++
x
)
{
border_count
+=
data
[
x
]
+
data
[
x
+
(
h
-
1
)
*
w
];
}
for
(
int
y
=
0
;
y
<
h
;
++
y
)
{
border_count
+=
data
[
y
*
w
]
+
data
[
w
-
1
+
y
*
w
];
}
if
(
border_count
>
w
+
h
)
{
// more then half the border if FULL, invert
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
data
[
i
]
=
data
[
i
]
==
FULL
?
EMPTY
:
FULL
;
}
}
}
}
}
...
@@ -187,7 +202,7 @@ SymbolP image_to_symbol(Image& img) {
...
@@ -187,7 +202,7 @@ SymbolP image_to_symbol(Image& img) {
int
w
=
img
.
GetWidth
(),
h
=
img
.
GetHeight
();
int
w
=
img
.
GetWidth
(),
h
=
img
.
GetHeight
();
// 1. threshold the image
// 1. threshold the image
greyscale
(
img
);
greyscale
(
img
);
threshold
(
img
.
GetData
(),
w
*
h
);
threshold
(
img
.
GetData
(),
w
,
h
);
// 2. read as many symbol parts as we can
// 2. read as many symbol parts as we can
ImageData
data
=
{
w
,
h
,
img
.
GetData
()};
ImageData
data
=
{
w
,
h
,
img
.
GetData
()};
SymbolP
symbol
(
new
Symbol
);
SymbolP
symbol
(
new
Symbol
);
...
...
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