Commit 715e19dd authored by Davis King's avatar Davis King

Added some unit tests for the save_png() and load_png() functions.

parent eaa0b45c
......@@ -144,6 +144,45 @@ namespace
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d<rgb_alpha_pixel> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c].red = static_cast<unsigned char>(r*14 + c + 1);
img[r][c].green = static_cast<unsigned char>(r*14 + c + 2);
img[r][c].blue = static_cast<unsigned char>(r*14 + c + 3);
img[r][c].alpha = static_cast<unsigned char>(r*14 + c + 4);
}
}
save_png(img, "test.png");
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_png(img, "test.png");
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c].red == r*14 + c + 1);
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);
}
}
}
#endif // DLIB_PNG_SUPPORT
{
......@@ -207,7 +246,138 @@ namespace
}
}
}
{
array2d<bgr_pixel> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c].red = static_cast<unsigned char>(r*14 + c + 1);
img[r][c].green = static_cast<unsigned char>(r*14 + c + 2);
img[r][c].blue = static_cast<unsigned char>(r*14 + c + 3);
}
}
ostringstream sout;
save_dng(img, sout);
save_bmp(img, sout);
save_dng(img, sout);
save_bmp(img, sout);
istringstream sin(sout.str());
for (int i = 0; i < 2; ++i)
{
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_dng(img, sin);
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c].red == r*14 + c + 1);
DLIB_TEST(img[r][c].green == r*14 + c + 2);
DLIB_TEST(img[r][c].blue == r*14 + c + 3);
}
}
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_bmp(img, sin);
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST_MSG(img[r][c].red == r*14 + c + 1, "got " << (int)img[r][c].red << " but expected " << r*14 + c + 1);
DLIB_TEST(img[r][c].green == r*14 + c + 2);
DLIB_TEST(img[r][c].blue == r*14 + c + 3);
}
}
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d<rgb_pixel> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c].red = static_cast<unsigned char>(r*14 + c + 1);
img[r][c].green = static_cast<unsigned char>(r*14 + c + 2);
img[r][c].blue = static_cast<unsigned char>(r*14 + c + 3);
}
}
save_png(img, "test.png");
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_png(img, "test.png");
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c].red == r*14 + c + 1);
DLIB_TEST(img[r][c].green == r*14 + c + 2);
DLIB_TEST(img[r][c].blue == r*14 + c + 3);
}
}
}
{
array2d<bgr_pixel> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c].red = static_cast<unsigned char>(r*14 + c + 1);
img[r][c].green = static_cast<unsigned char>(r*14 + c + 2);
img[r][c].blue = static_cast<unsigned char>(r*14 + c + 3);
}
}
save_png(img, "test.png");
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_png(img, "test.png");
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c].red == r*14 + c + 1);
DLIB_TEST(img[r][c].green == r*14 + c + 2);
DLIB_TEST(img[r][c].blue == r*14 + c + 3);
}
}
}
#endif // DLIB_PNG_SUPPORT
......@@ -218,7 +388,7 @@ namespace
{
for (long c = 0; c < 15; ++c)
{
img[r][c] = static_cast<unsigned short>(r*14 + c + 0xFF);
img[r][c] = static_cast<unsigned short>(r*14 + c + 0xF0);
}
}
......@@ -239,10 +409,44 @@ namespace
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c] == r*14 + c + 0xFF);
DLIB_TEST(img[r][c] == r*14 + c + 0xF0);
}
}
}
#ifdef DLIB_PNG_SUPPORT
{
array2d<unsigned short> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c] = static_cast<unsigned short>(r*14 + c + 0xF0);
}
}
save_png(img, "test.png");
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_png(img, "test.png");
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c] == r*14 + c + 0xF0);
}
}
}
#endif // DLIB_PNG_SUPPORT
......@@ -304,6 +508,40 @@ namespace
}
#ifdef DLIB_PNG_SUPPORT
{
array2d<unsigned char> img;
img.set_size(14,15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
img[r][c] = static_cast<unsigned char>(r*14 + c);
}
}
save_png(img, "test.png");
img.clear();
DLIB_TEST(img.nr() == 0);
DLIB_TEST(img.nc() == 0);
load_png(img, "test.png");
DLIB_TEST(img.nr() == 14);
DLIB_TEST(img.nc() == 15);
for (long r = 0; r < 14; ++r)
{
for (long c = 0; c < 15; ++c)
{
DLIB_TEST(img[r][c] == r*14 + c);
}
}
}
#endif // DLIB_PNG_SUPPORT
{
// in this test we will only assign pixel values that can be
......
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