Commit f7c9763a authored by Davis King's avatar Davis King

Fixed a bug in the png_loader. If you loaded an image with an

alpha channel into something without an alpha channel there were
uninitialized values being alpha blended into the image.
parent ba08e283
......@@ -100,6 +100,9 @@ namespace dlib
}
else if (is_rgba() && bit_depth_ == 8)
{
if (!pixel_traits<typename T::type>::has_alpha)
assign_all_pixels(t,0);
for ( unsigned n = 0; n < height_;n++ )
{
const unsigned char* v = get_row( n );
......@@ -116,6 +119,9 @@ namespace dlib
}
else if (is_rgba() && bit_depth_ == 16)
{
if (!pixel_traits<typename T::type>::has_alpha)
assign_all_pixels(t,0);
for ( unsigned n = 0; n < height_;n++ )
{
const uint16* v = (uint16*)get_row( n );
......
......@@ -166,7 +166,10 @@ namespace
#ifdef DLIB_PNG_SUPPORT
{
array2d<rgb_alpha_pixel> img;
array2d<rgb_pixel> img2, img3;
img.set_size(14,15);
img2.set_size(img.nr(),img.nc());
img3.set_size(img.nr(),img.nc());
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
......@@ -189,6 +192,11 @@ namespace
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
assign_all_pixels(img2, 255);
assign_all_pixels(img3, 0);
load_png(img2, "test.png");
assign_image(img3, img);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
......@@ -197,6 +205,10 @@ namespace
DLIB_TEST(img[r][c].green == r*14 + c + 2);
DLIB_TEST(img[r][c].blue == r*14 + c + 3);
DLIB_TEST(img[r][c].alpha == r*14 + c + 4);
DLIB_TEST(img2[r][c].red == img3[r][c].red);
DLIB_TEST(img2[r][c].green == img3[r][c].green);
DLIB_TEST(img2[r][c].blue == img3[r][c].blue);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment