Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
0b5cb827
Commit
0b5cb827
authored
Aug 17, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the version of draw_line() that draws onto a regular image use alpha
blending for drawing diagonal lines.
parent
41309698
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
32 deletions
+48
-32
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
}
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
run
=
(((
long
)
x2
)
-
((
long
)
x1
));
if
(
std
::
abs
(
rise
)
<
std
::
abs
(
run
))
...
...
@@ -80,13 +87,13 @@ namespace dlib
if
(
x1
>
x2
)
{
first
=
x2
;
last
=
x1
;
first
=
std
::
max
(
x2
,
valid_area
.
left
())
;
last
=
std
::
min
(
x1
,
valid_area
.
right
())
;
}
else
{
first
=
x1
;
last
=
x2
;
first
=
std
::
max
(
x1
,
valid_area
.
left
())
;
last
=
std
::
min
(
x2
,
valid_area
.
right
())
;
}
long
y
;
...
...
@@ -95,18 +102,23 @@ namespace dlib
const
double
y1f
=
y1
;
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
{
y
=
static_cast
<
long
>
(
slope
*
(
i
-
x1f
)
+
y1f
);
x
=
static_cast
<
long
>
(
i
);
if
(
y
<
0
||
y
>=
c
.
nr
())
continue
;
if
(
x
<
0
||
x
>=
c
.
nc
())
continue
;
assign_pixel
(
c
[
y
][
x
]
,
val
);
const
double
dy
=
slope
*
(
i
-
x1f
)
+
y1f
;
const
double
dx
=
i
;
y
=
static_cast
<
long
>
(
dy
);
x
=
static_cast
<
long
>
(
dx
);
if
(
y
>=
valid_area
.
top
()
&&
y
<=
valid_area
.
bottom
())
{
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
1
.
0
-
(
dy
-
y
))
*
max_alpha
);
assign_pixel
(
c
[
y
][
x
],
alpha_pixel
);
}
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
...
...
@@ -119,33 +131,37 @@ namespace dlib
if
(
y1
>
y2
)
{
first
=
y2
;
last
=
y1
;
first
=
std
::
max
(
y2
,
valid_area
.
top
())
;
last
=
std
::
min
(
y1
,
valid_area
.
bottom
())
;
}
else
{
first
=
y1
;
last
=
y2
;
first
=
std
::
max
(
y1
,
valid_area
.
top
())
;
last
=
std
::
min
(
y2
,
valid_area
.
bottom
())
;
}
long
x
;
long
y
;
const
double
x1f
=
x1
;
const
double
y1f
=
y1
;
for
(
double
i
=
first
;
i
<=
last
;
++
i
)
{
x
=
static_cast
<
long
>
(
slope
*
(
i
-
y1f
)
+
x1f
);
y
=
static_cast
<
long
>
(
i
);
if
(
x
<
0
||
x
>=
c
.
nc
())
continue
;
if
(
y
<
0
||
y
>=
c
.
nr
())
continue
;
assign_pixel
(
c
[
y
][
x
]
,
val
);
const
double
dx
=
slope
*
(
i
-
y1f
)
+
x1f
;
const
double
dy
=
i
;
y
=
static_cast
<
long
>
(
dy
);
x
=
static_cast
<
long
>
(
dx
);
if
(
x
>=
valid_area
.
left
()
&&
x
<=
valid_area
.
right
())
{
alpha_pixel
.
alpha
=
static_cast
<
unsigned
char
>
((
1
.
0
-
(
dx
-
x
))
*
max_alpha
);
assign_pixel
(
c
[
y
][
x
],
alpha_pixel
);
}
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