Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / legacy / recreate_image.cpp
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
13 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
14
15 #include <boost/test/unit_test.hpp>
16
17 #include <ios>
18 #include <iostream>
19 #include <fstream>
20 #include <map>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24
25 using namespace boost::gil;
26 using namespace std;
27 using namespace boost;
28
29 ///////////////////////////////////////////////////////////////
30
31 std::size_t is_planar_impl( const std::size_t size_in_units
32                             , const std::size_t channels_in_image
33                             , std::true_type
34                             )
35 {
36     return size_in_units * channels_in_image;
37 }
38
39 std::size_t is_planar_impl( const std::size_t size_in_units
40                           , const std::size_t
41                           , std::false_type
42                           )
43 {
44     return size_in_units;
45 }
46
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() );
51
52     return size_in_memunits;
53 }
54
55
56 template< typename View
57         , bool IsPlanar
58         >
59 std::size_t total_allocated_size_in_bytes( const typename View::point_t& dimensions )
60 {
61
62     using x_iterator = typename View::x_iterator;
63
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>
68                                                         >::type::value;
69
70     std::size_t size_in_units = is_planar_impl( get_row_size_in_memunits< View >( dimensions.x ) * dimensions.y
71                                                 , _channels_in_image
72                                                 , typename std::conditional< IsPlanar, std::true_type, std::false_type >::type()
73                                                 );
74
75     // return the size rounded up to the nearest byte
76     std::size_t btm = byte_to_memunit< typename View::x_iterator >::value;
77
78
79     return ( size_in_units + btm - 1 )
80            / btm;
81 }
82
83
84 BOOST_AUTO_TEST_SUITE(GIL_Tests)
85
86 BOOST_AUTO_TEST_CASE(recreate_image_test)
87 {
88     auto tasib_1 = total_allocated_size_in_bytes<rgb8_view_t, false>({640, 480});
89     auto tasib_2 = total_allocated_size_in_bytes<rgb8_view_t, false>({320, 200});
90
91     rgb8_image_t img( 640, 480 );
92     img.recreate( 320, 200 );
93
94 }
95
96 BOOST_AUTO_TEST_SUITE_END()
97
98 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
99 #pragma warning(push)
100 #pragma warning(disable:4127) //conditional expression is constant
101 #endif
102
103 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
104 #pragma warning(pop)
105 #endif