recreate_image.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifdef _MSC_VER
  9. //#pragma warning(disable : 4244) // conversion from 'gil::image<V,Alloc>::coord_t' to 'int', possible loss of data (visual studio compiler doesn't realize that the two types are the same)
  10. #pragma warning(disable : 4503) // decorated name length exceeded, name was truncated
  11. #endif
  12. #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include <ios>
  15. #include <iostream>
  16. #include <fstream>
  17. #include <map>
  18. #include <string>
  19. #include <type_traits>
  20. #include <vector>
  21. using namespace boost::gil;
  22. using namespace std;
  23. using namespace boost;
  24. ///////////////////////////////////////////////////////////////
  25. std::size_t is_planar_impl( const std::size_t size_in_units
  26. , const std::size_t channels_in_image
  27. , std::true_type
  28. )
  29. {
  30. return size_in_units * channels_in_image;
  31. }
  32. std::size_t is_planar_impl( const std::size_t size_in_units
  33. , const std::size_t
  34. , std::false_type
  35. )
  36. {
  37. return size_in_units;
  38. }
  39. template< typename View >
  40. std::size_t get_row_size_in_memunits( typename View::x_coord_t width)
  41. { // number of units per row
  42. std::size_t size_in_memunits = width * memunit_step( typename View::x_iterator() );
  43. return size_in_memunits;
  44. }
  45. template< typename View
  46. , bool IsPlanar
  47. >
  48. std::size_t total_allocated_size_in_bytes( const typename View::point_t& dimensions )
  49. {
  50. using x_iterator = typename View::x_iterator;
  51. // when value_type is a non-pixel, like int or float, num_channels< ... > doesn't work.
  52. const std::size_t _channels_in_image = mp11::mp_eval_if< is_pixel< typename View::value_type >
  53. , num_channels< View >
  54. , std::integral_constant<int, 1>
  55. >::type::value;
  56. std::size_t size_in_units = is_planar_impl( get_row_size_in_memunits< View >( dimensions.x ) * dimensions.y
  57. , _channels_in_image
  58. , typename std::conditional< IsPlanar, std::true_type, std::false_type >::type()
  59. );
  60. // return the size rounded up to the nearest byte
  61. std::size_t btm = byte_to_memunit< typename View::x_iterator >::value;
  62. return ( size_in_units + btm - 1 )
  63. / btm;
  64. }
  65. BOOST_AUTO_TEST_SUITE(GIL_Tests)
  66. BOOST_AUTO_TEST_CASE(recreate_image_test)
  67. {
  68. auto tasib_1 = total_allocated_size_in_bytes<rgb8_view_t, false>({640, 480});
  69. auto tasib_2 = total_allocated_size_in_bytes<rgb8_view_t, false>({320, 200});
  70. rgb8_image_t img( 640, 480 );
  71. img.recreate( 320, 200 );
  72. }
  73. BOOST_AUTO_TEST_SUITE_END()
  74. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  75. #pragma warning(push)
  76. #pragma warning(disable:4127) //conditional expression is constant
  77. #endif
  78. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  79. #pragma warning(pop)
  80. #endif