8 #ifndef BOOST_GIL_IO_ROW_BUFFER_HELPER_HPP 9 #define BOOST_GIL_IO_ROW_BUFFER_HELPER_HPP 12 #include <boost/gil/extension/toolbox/metafunctions/is_bit_aligned.hpp> 13 #include <boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp> 14 #include <boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp> 16 #include <boost/gil/detail/mp11.hpp> 17 #include <boost/gil/io/typedefs.hpp> 20 #include <type_traits> 23 namespace boost {
namespace gil {
namespace detail {
25 template<
typename Pixel
26 ,
typename DummyT =
void 28 struct row_buffer_helper
30 using element_t = Pixel;
31 using buffer_t = std::vector<element_t>;
32 using iterator_t =
typename buffer_t::iterator;
34 row_buffer_helper( std::size_t width
37 : _row_buffer( width )
40 element_t* data() {
return &_row_buffer[0]; }
42 iterator_t begin() {
return _row_buffer.begin(); }
43 iterator_t end() {
return _row_buffer.end(); }
45 buffer_t& buffer() {
return _row_buffer; }
52 template <
typename Pixel>
53 struct row_buffer_helper
56 typename std::enable_if
58 is_bit_aligned<Pixel>::value
62 using element_t = byte_t;
63 using buffer_t = std::vector<element_t>;
64 using pixel_type = Pixel;
65 using iterator_t = bit_aligned_pixel_iterator<pixel_type>;
67 row_buffer_helper(std::size_t width,
bool in_bytes)
68 : _c{( width * pixel_bit_size< pixel_type >::value) >> 3}
69 , _r{width * pixel_bit_size< pixel_type >::value - (_c << 3)}
73 _row_buffer.resize(width);
78 _row_buffer.resize(_c + (_r != 0));
82 element_t* data() {
return &_row_buffer[0]; }
84 iterator_t begin() {
return iterator_t( &_row_buffer.front(),0 ); }
85 iterator_t end() {
return _r == 0 ? iterator_t( &_row_buffer.back() + 1, 0 )
86 : iterator_t( &_row_buffer.back() , (int) _r );
89 buffer_t& buffer() {
return _row_buffer; }
101 buffer_t _row_buffer;
104 template<
typename Pixel>
105 struct row_buffer_helper
108 typename std::enable_if
112 typename is_bit_aligned<Pixel>::type,
113 typename is_homogeneous<Pixel>::type
118 using element_t = byte_t;
119 using buffer_t = std::vector<element_t>;
120 using pixel_type = Pixel;
121 using iterator_t = bit_aligned_pixel_iterator<pixel_type>;
123 row_buffer_helper( std::size_t width
127 * num_channels< pixel_type >::value
128 * channel_type< pixel_type >::type::num_bits
134 * num_channels< pixel_type >::value
135 * channel_type< pixel_type >::type::num_bits
141 _row_buffer.resize( width );
146 _row_buffer.resize( _c + ( _r!=0 ));
150 element_t* data() {
return &_row_buffer[0]; }
152 iterator_t begin() {
return iterator_t( &_row_buffer.front(),0 ); }
153 iterator_t end() {
return _r == 0 ? iterator_t( &_row_buffer.back() + 1, 0 )
154 : iterator_t( &_row_buffer.back() , (int) _r );
157 buffer_t& buffer() {
return _row_buffer; }
169 buffer_t _row_buffer;
172 template <
typename View,
typename D =
void>
173 struct row_buffer_helper_view : row_buffer_helper<typename View::value_type>
175 row_buffer_helper_view(std::size_t width,
bool in_bytes)
176 : row_buffer_helper<typename View::value_type>(width, in_bytes)
180 template <
typename View>
181 struct row_buffer_helper_view
184 typename std::enable_if
186 is_bit_aligned<typename View::value_type>::value
188 > : row_buffer_helper<typename View::reference>
190 row_buffer_helper_view(std::size_t width,
bool in_bytes)
191 : row_buffer_helper<typename View::reference>(width, in_bytes)