2 // Copyright 2005-2007 Adobe Systems Incorporated
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
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
13 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
15 #include <boost/core/lightweight_test.hpp>
22 #include <type_traits>
25 using namespace boost::gil
;
27 using namespace boost
;
29 ///////////////////////////////////////////////////////////////
31 std::size_t is_planar_impl( const std::size_t size_in_units
32 , const std::size_t channels_in_image
36 return size_in_units
* channels_in_image
;
39 std::size_t is_planar_impl( const std::size_t size_in_units
47 template< typename View
>
48 std::size_t get_row_size_in_memunits( typename
View::x_coord_t width
)
49 { // number of units per row
50 std::size_t size_in_memunits
= width
* memunit_step( typename
View::x_iterator() );
52 return size_in_memunits
;
56 template< typename View
59 std::size_t total_allocated_size_in_bytes( const typename
View::point_t
& dimensions
)
62 using x_iterator
= typename
View::x_iterator
;
64 // when value_type is a non-pixel, like int or float, num_channels< ... > doesn't work.
65 const std::size_t _channels_in_image
= mp11::mp_eval_if
< is_pixel
< typename
View::value_type
>
66 , num_channels
< View
>
67 , std::integral_constant
<int, 1>
70 std::size_t size_in_units
= is_planar_impl( get_row_size_in_memunits
< View
>( dimensions
.x
) * dimensions
.y
72 , typename
std::conditional
< IsPlanar
, std::true_type
, std::false_type
>::type()
75 // return the size rounded up to the nearest byte
76 std::size_t btm
= byte_to_memunit
< typename
View::x_iterator
>::value
;
79 return ( size_in_units
+ btm
- 1 )
84 void test_recreate_image()
86 auto tasib_1
= total_allocated_size_in_bytes
<rgb8_view_t
, false>({640, 480});
87 auto tasib_2
= total_allocated_size_in_bytes
<rgb8_view_t
, false>({320, 200});
89 rgb8_image_t
img( 640, 480 );
90 img
.recreate( 320, 200 );
95 test_recreate_image();
97 return ::boost::report_errors();
101 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
102 #pragma warning(push)
103 #pragma warning(disable:4127) //conditional expression is constant
106 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)