lanczos_scaling.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright 2019 Olzhas Zhumabek <anonymous.from.applecity@gmail.com>
  3. //
  4. // Use, modification and distribution are subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #include <boost/gil/image_processing/scaling.hpp>
  9. #include <boost/gil/image.hpp>
  10. #include <boost/core/lightweight_test.hpp>
  11. #include <iostream>
  12. namespace gil = boost::gil;
  13. bool are_equal(gil::rgb8_view_t expected, gil::rgb8_view_t actual) {
  14. if (expected.dimensions() != actual.dimensions())
  15. return false;
  16. for (long int y = 0; y < expected.height(); ++y)
  17. {
  18. for (long int x = 0; x < expected.width(); ++x)
  19. {
  20. if (expected(x, y) != actual(x, y))
  21. {
  22. return false;
  23. }
  24. }
  25. }
  26. return true;
  27. }
  28. void test_lanczos_black_image()
  29. {
  30. const gil::point_t input_dimensions(20, 20);
  31. const gil::point_t output_dimensions(input_dimensions.x / 2, input_dimensions.y / 2);
  32. gil::rgb8_image_t image(input_dimensions, gil::rgb8_pixel_t(0, 0, 0), 0);
  33. // fill with values other than 0
  34. gil::rgb8_image_t output_image(
  35. output_dimensions,
  36. gil::rgb8_pixel_t(100, 100, 100),
  37. 0
  38. );
  39. gil::rgb8_image_t expected(
  40. output_dimensions,
  41. gil::rgb8_pixel_t(0, 0, 0),
  42. 0
  43. );
  44. auto view = gil::view(image);
  45. auto output_view = gil::view(output_image);
  46. auto expected_view = gil::view(expected);
  47. gil::scale_lanczos(view, output_view, 5);
  48. BOOST_TEST(are_equal(expected_view,output_view));
  49. }
  50. void test_lanczos_response_on_zero()
  51. {
  52. //random value for a
  53. BOOST_TEST(gil::lanczos(0, 2) == 1);
  54. }
  55. int main()
  56. {
  57. test_lanczos_black_image();
  58. test_lanczos_response_on_zero();
  59. return boost::report_errors();
  60. }