mirror of https://github.com/davisking/dlib.git
Fixed a bug in assign_pixel_intensity() that happened when
the target pixel was an RGB pixel with an alpha channel.
This commit is contained in:
parent
32e1d0b66c
commit
2f7196db7c
20
dlib/pixel.h
20
dlib/pixel.h
|
@ -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 <
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue