| 398 | } |
| 399 | |
| 400 | void test_serialization() |
| 401 | { |
| 402 | // Do these tests because there are overloads of the serialize routines |
| 403 | // specifically for these types of pixel (except for unsigned short, |
| 404 | // we do that because you can never have too many tests). |
| 405 | { |
| 406 | array2d<rgb_alpha_pixel> img, img2; |
| 407 | img.set_size(3,2); |
| 408 | assign_all_pixels(img, 5); |
| 409 | img[1][1].red = 9; |
| 410 | img[1][1].green = 8; |
| 411 | img[1][1].blue = 7; |
| 412 | img[1][1].alpha = 3; |
| 413 | ostringstream sout; |
| 414 | serialize(img, sout); |
| 415 | istringstream sin(sout.str()); |
| 416 | deserialize(img2, sin); |
| 417 | |
| 418 | DLIB_TEST(img2.nr() == 3); |
| 419 | DLIB_TEST(img2.nc() == 2); |
| 420 | |
| 421 | for (long r = 0; r < img.nr(); ++r) |
| 422 | { |
| 423 | for (long c = 0; c < img.nc(); ++c) |
| 424 | { |
| 425 | DLIB_TEST(img[r][c].red == img2[r][c].red); |
| 426 | DLIB_TEST(img[r][c].green == img2[r][c].green); |
| 427 | DLIB_TEST(img[r][c].blue == img2[r][c].blue); |
| 428 | DLIB_TEST(img[r][c].alpha == img2[r][c].alpha); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | { |
| 433 | array2d<hsi_pixel> img, img2; |
| 434 | img.set_size(3,2); |
| 435 | assign_all_pixels(img, 5); |
| 436 | img[1][1].h = 9; |
| 437 | img[1][1].s = 2; |
| 438 | img[1][1].i = 3; |
| 439 | ostringstream sout; |
| 440 | serialize(img, sout); |
| 441 | istringstream sin(sout.str()); |
| 442 | deserialize(img2, sin); |
| 443 | |
| 444 | DLIB_TEST(img2.nr() == 3); |
| 445 | DLIB_TEST(img2.nc() == 2); |
| 446 | |
| 447 | for (long r = 0; r < img.nr(); ++r) |
| 448 | { |
| 449 | for (long c = 0; c < img.nc(); ++c) |
| 450 | { |
| 451 | DLIB_TEST(img[r][c].h == img2[r][c].h); |
| 452 | DLIB_TEST(img[r][c].s == img2[r][c].s); |
| 453 | DLIB_TEST(img[r][c].i == img2[r][c].i); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | { |
no test coverage detected