• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/core/lightweight_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 
is_planar_impl(const std::size_t size_in_units,const std::size_t channels_in_image,std::true_type)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 
is_planar_impl(const std::size_t size_in_units,const std::size_t,std::false_type)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 >
get_row_size_in_memunits(typename View::x_coord_t width)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         >
total_allocated_size_in_bytes(const typename View::point_t & dimensions)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 
test_recreate_image()84 void test_recreate_image()
85 {
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});
88 
89     rgb8_image_t img( 640, 480 );
90     img.recreate( 320, 200 );
91 }
92 
main()93 int main()
94 {
95     test_recreate_image();
96 
97     return ::boost::report_errors();
98 }
99 
100 
101 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
102 #pragma warning(push)
103 #pragma warning(disable:4127) //conditional expression is constant
104 #endif
105 
106 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
107 #pragma warning(pop)
108 #endif
109