Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
0b5cb827
Commit
0b5cb827
authored
Aug 17, 2014
by
Davis King
Browse files
Made the version of draw_line() that draws onto a regular image use alpha
blending for drawing diagonal lines.
parent
41309698
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
32 deletions
+48
-32
dlib/image_transforms/draw.h
dlib/image_transforms/draw.h
+48
-32
No files found.
dlib/image_transforms/draw.h
View file @
0b5cb827
...
@@ -68,6 +68,13 @@ namespace dlib
...
@@ -68,6 +68,13 @@ namespace dlib
}
}
else
else
{
{
// This part is a little more complicated because we are going to perform alpha
// blending so the diagonal lines look nice.
const
rectangle
valid_area
=
get_rect
(
c
);
rgb_alpha_pixel
alpha_pixel
;
assign_pixel
(
alpha_pixel
,
val
);
const
unsigned
char
max_alpha
=
alpha_pixel
.
alpha
;
const
long
rise
=
(((
long
)
y2
)
-
((
long
)
y1
));
const
long
rise
=
(((
long
)
y2
)
-
((
long
)
y1
));
const
long
run
=
(((
long
)
x2
)
-
((
long
)
x1
));
const
long
run
=
(((
long
)
x2
)
-
((
long
)
x1
));
if
(
std
::
abs
(
rise
)
<
std
::
abs
(
run
))
if
(
std
::
abs
(
rise
)
<
std
::
abs
(
run
))
...
@@ -80,13 +87,13 @@ namespace dlib
...
@@ -80,13 +87,13 @@ namespace dlib
if
(
x1
>
x2
)
if
(
x1
>
x2
)
{
{
first
=
x2
;
first
=
std
::
max
(
x2
,
valid_area
.
left
())
;
last
=
x1
;
last
=
std
::
min
(
x1
,
valid_area
.
right
())
;
}
}
else
else
{
{
first
=
x1
;
first
=
std
::
max
(
x1
,
valid_area
.
left
())
;
last
=
x2
;
last
=
std
::
min
(
x2
,
valid_area
.
right
())
;
}
}
long
y
;
long
y
;
...
@@ -95,18 +102,23 @@ namespace dlib
...
@@ -95,18 +102,23 @@ namespace dlib
const
double
y1f
=
y1
;
const
double
y1f
=
y1
;
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
{
{
y
=
static_cast
<
long
>
(
slope
*
(
i
-
x1f
)
+
y1f
);
const
double
dy
=
slope
*
(
i
-
x1f
)
+
y1f
;
x
=
static_cast
<
long
>
(
i
);
const
double
dx
=
i
;
y
=
static_cast
<
long
>
(
dy
);
if
(
y
<
0
||
y
>=
c
.
nr
())
x
=
static_cast
<
long
>
(
dx
);
continue
;
if
(
x
<
0
||
x
>=
c
.
nc
())
if
(
y
>=
valid_area
.
top
()
&&
y
<=
valid_area
.
bottom
())
continue
;
{
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
1.0
-
(
dy
-
y
))
*
max_alpha
);
assign_pixel
(
c
[
y
][
x
],
alpha_pixel
);
assign_pixel
(
c
[
y
][
x
]
,
val
);
}
if
(
y
+
1
>=
valid_area
.
top
()
&&
y
+
1
<=
valid_area
.
bottom
())
{
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
dy
-
y
)
*
max_alpha
);
assign_pixel
(
c
[
y
+
1
][
x
],
alpha_pixel
);
}
}
}
}
}
else
else
...
@@ -119,33 +131,37 @@ namespace dlib
...
@@ -119,33 +131,37 @@ namespace dlib
if
(
y1
>
y2
)
if
(
y1
>
y2
)
{
{
first
=
y2
;
first
=
std
::
max
(
y2
,
valid_area
.
top
())
;
last
=
y1
;
last
=
std
::
min
(
y1
,
valid_area
.
bottom
())
;
}
}
else
else
{
{
first
=
y1
;
first
=
std
::
max
(
y1
,
valid_area
.
top
())
;
last
=
y2
;
last
=
std
::
min
(
y2
,
valid_area
.
bottom
())
;
}
}
long
x
;
long
x
;
long
y
;
long
y
;
const
double
x1f
=
x1
;
const
double
x1f
=
x1
;
const
double
y1f
=
y1
;
const
double
y1f
=
y1
;
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
{
{
x
=
static_cast
<
long
>
(
slope
*
(
i
-
y1f
)
+
x1f
);
const
double
dx
=
slope
*
(
i
-
y1f
)
+
x1f
;
y
=
static_cast
<
long
>
(
i
);
const
double
dy
=
i
;
y
=
static_cast
<
long
>
(
dy
);
if
(
x
<
0
||
x
>=
c
.
nc
())
x
=
static_cast
<
long
>
(
dx
);
continue
;
if
(
x
>=
valid_area
.
left
()
&&
x
<=
valid_area
.
right
())
if
(
y
<
0
||
y
>=
c
.
nr
())
{
continue
;
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
1.0
-
(
dx
-
x
))
*
max_alpha
);
assign_pixel
(
c
[
y
][
x
],
alpha_pixel
);
assign_pixel
(
c
[
y
][
x
]
,
val
);
}
if
(
x
+
1
>=
valid_area
.
left
()
&&
x
+
1
<=
valid_area
.
right
())
{
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
dx
-
x
)
*
max_alpha
);
assign_pixel
(
c
[
y
][
x
+
1
],
alpha_pixel
);
}
}
}
}
}
}
}
...
...
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