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
2f7196db
Commit
2f7196db
authored
May 29, 2011
by
Davis King
Browse files
Fixed a bug in assign_pixel_intensity() that happened when
the target pixel was an RGB pixel with an alpha channel.
parent
32e1d0b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
dlib/pixel.h
dlib/pixel.h
+14
-6
dlib/test/pixel.cpp
dlib/test/pixel.cpp
+12
-0
No files found.
dlib/pixel.h
View file @
2f7196db
...
...
@@ -255,9 +255,14 @@ namespace dlib
- pixel_traits<P> must be defined
- pixel_traits<T> must be defined
ensures
- #get_pixel_intensity(dest) == get_pixel_intensity(new_intensity)
(or if get_pixel_intensity(new_intensity) can't be represented by
dest then the closest value representable by dest is used)
- This function changes the intensity of the dest pixel. So if the pixel in
question is a grayscale pixel then it simply assigns that pixel with the
value of get_pixel_intensity(new_intensity). However, if the pixel is not
a grayscale pixel then it converts the pixel to the HSI color space and sets
the I channel to the given intensity and then converts this HSI value back to
the original pixel's color space.
- Note that we don't necessarily have #get_pixel_intensity(dest) == get_pixel_intensity(new_intensity)
due to vagaries of how converting to and from HSI works out.
- if (the dest pixel has an alpha channel) then
- #dest.alpha == dest.alpha
!*/
...
...
@@ -984,12 +989,15 @@ namespace dlib
const
T
&
new_intensity
)
{
unsigned
long
alpha
=
dest
.
alpha
;
hsi_pixel
p
;
assign_pixel
(
p
,
dest
);
const
unsigned
long
old_alpha
=
dest
.
alpha
;
dest
.
alpha
=
255
;
rgb_pixel
temp
;
assign_pixel
(
temp
,
dest
);
// put dest into an rgb_pixel to avoid the somewhat complicated assign_pixel(hsi,rgb_alpha).
assign_pixel
(
p
,
temp
);
assign_pixel
(
p
.
i
,
new_intensity
);
assign_pixel
(
dest
,
p
);
dest
.
alpha
=
alpha
;
dest
.
alpha
=
old_
alpha
;
}
template
<
...
...
dlib/test/pixel.cpp
View file @
2f7196db
...
...
@@ -467,6 +467,18 @@ namespace
assign_pixel_intensity
(
p_int
,
-
10000
);
assign_pixel_intensity
(
p_gray
,
-
100
);
p_rgba
.
red
=
10
;
p_rgba
.
green
=
10
;
p_rgba
.
blue
=
10
;
p_rgba
.
alpha
=
0
;
DLIB_TEST_MSG
(
get_pixel_intensity
(
p_rgba
)
==
10
,
(
int
)
get_pixel_intensity
(
p_rgba
));
assign_pixel_intensity
(
p_rgba
,
2
);
DLIB_TEST_MSG
(
p_rgba
.
red
==
2
,
(
int
)
p_rgba
.
red
);
DLIB_TEST_MSG
(
p_rgba
.
green
==
2
,
(
int
)
p_rgba
.
green
);
DLIB_TEST_MSG
(
p_rgba
.
blue
==
2
,
(
int
)
p_rgba
.
blue
);
DLIB_TEST_MSG
(
p_rgba
.
alpha
==
0
,
(
int
)
p_rgba
.
alpha
);
DLIB_TEST_MSG
(
get_pixel_intensity
(
p_rgba
)
==
2
,
(
int
)
get_pixel_intensity
(
p_rgba
));
DLIB_TEST
(
p_float
==
-
1000
);
DLIB_TEST
(
get_pixel_intensity
(
p_float
)
==
-
1000
);
DLIB_TEST
(
p_schar
==
-
100
);
...
...
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