8 #ifndef BOOST_GIL_IMAGE_VIEW_FACTORY_HPP 9 #define BOOST_GIL_IMAGE_VIEW_FACTORY_HPP 11 #include <boost/gil/color_convert.hpp> 12 #include <boost/gil/dynamic_step.hpp> 13 #include <boost/gil/gray.hpp> 14 #include <boost/gil/metafunctions.hpp> 15 #include <boost/gil/point.hpp> 17 #include <boost/assert.hpp> 20 #include <type_traits> 34 namespace boost {
namespace gil {
35 struct default_color_converter;
41 template <
typename View>
46 template <
typename View>
52 template <
typename Iterator>
55 Iterator pixels, std::ptrdiff_t rowsize_in_bytes) {
57 return RView(width, height,
typename RView::locator(pixels, rowsize_in_bytes));
62 template <
typename Iterator>
64 std::ptrdiff_t rowsize_in_bytes)
68 return RView(dim,
typename RView::locator(pixels, rowsize_in_bytes));
76 template <
typename View,
bool IsMutable>
struct channel_pointer_type_impl;
78 template <
typename View>
struct channel_pointer_type_impl<View, true> {
81 template <
typename View>
struct channel_pointer_type_impl<View, false> {
85 template <
typename View>
struct channel_pointer_type
86 :
public channel_pointer_type_impl<View, view_is_mutable<View>::value> {};
91 template <
typename HomogeneousView>
94 static_assert(std::is_pointer<typename HomogeneousView::x_iterator>::value,
"");
96 return &gil::at_c<0>(
view(0,0));
101 template <
typename HomogeneousView>
104 return dynamic_at_c(view.row_begin(0),plane_index);
116 template <
typename SrcConstRefP,
typename DstP,
typename CC=default_color_converter >
124 DstP operator()(SrcConstRefP srcP)
const {
133 template <
typename SrcView,
typename CC,
typename DstP,
typename SrcP>
134 struct _color_converted_view_type {
137 using add_ref_t =
typename SrcView::template add_deref<deref_t>;
139 using type =
typename add_ref_t::type;
140 static type make(
const SrcView& sv,CC cc) {
return add_ref_t::make(sv,deref_t(cc));}
144 template <
typename SrcView,
typename CC,
typename DstP>
145 struct _color_converted_view_type<SrcView,CC,DstP,DstP> {
146 using type = SrcView;
147 static type make(
const SrcView& sv,CC) {
return sv;}
154 template <
typename SrcView,
typename DstP,
typename CC=default_color_converter>
158 typename SrcView::value_type> {
165 template <
typename DstP,
typename View,
typename CC>
172 template <
typename DstP,
typename View>
173 inline typename color_converted_view_type<View,DstP>::type
183 template <
typename View>
186 return RView(src.dimensions(),
typename RView::xy_locator(src.xy_at(0,src.height()-1),-1));
194 template <
typename View>
197 return RView(src.dimensions(),
typename RView::xy_locator(src.xy_at(src.width()-1,0),-1,1));
205 template <
typename View>
208 return RView(src.height(),src.width(),
typename RView::xy_locator(src.xy_at(0,0),1,1,
true));
216 template <
typename View>
219 return RView(src.height(),src.width(),
typename RView::xy_locator(src.xy_at(0,src.height()-1),-1,1,
true));
227 template <
typename View>
230 return RView(src.height(),src.width(),
typename RView::xy_locator(src.xy_at(src.width()-1,0),1,-1,
true));
238 template <
typename View>
241 return RView(src.dimensions(),
typename RView::xy_locator(src.xy_at(src.width()-1,src.height()-1),-1,-1));
249 template <
typename View>
250 inline View subimage_view(
const View& src,
const typename View::point_t& topleft,
const typename View::point_t& dimensions) {
251 return View(dimensions,src.xy_at(topleft));
255 template <
typename View>
256 inline View subimage_view(
const View& src,
int xMin,
int yMin,
int width,
int height) {
257 return View(width,height,src.xy_at(xMin,yMin));
265 template <
typename View>
268 BOOST_ASSERT(xStep > 0 && yStep > 0);
270 return RView((src.width()+(xStep-1))/xStep,(src.height()+(yStep-1))/yStep,
271 typename RView::xy_locator(src.xy_at(0,0),xStep,yStep));
275 template <
typename View>
277 return subsampled_view(src,step.x,step.y);
285 template <
typename View,
bool AreChannelsTogether>
struct __nth_channel_view_basic;
289 template <
typename View>
290 struct __nth_channel_view_basic<View,false> {
293 static type make(
const View& src,
int n) {
294 using locator_t =
typename type::xy_locator;
295 using x_iterator_t =
typename type::x_iterator;
297 x_iterator_t sit(x_iterator_base_t(&(src(0,0)[n])),src.pixels().pixel_size());
298 return type(src.dimensions(),locator_t(sit, src.pixels().row_size()));
303 template <
typename View>
304 struct __nth_channel_view_basic<View,true> {
306 static type make(
const View& src,
int n) {
307 using x_iterator_t =
typename type::x_iterator;
308 return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size());
312 template <
typename View,
bool IsBasic>
struct __nth_channel_view;
315 template <
typename View>
316 struct __nth_channel_view<View,true>
319 using src_x_iterator =
typename View::x_iterator;
323 static constexpr
bool adjacent =
328 using type =
typename __nth_channel_view_basic<View,adjacent>::type;
330 static type make(
const View& src,
int n) {
331 return __nth_channel_view_basic<View,adjacent>::make(src,n);
339 template <
typename SrcP>
343 static constexpr
bool is_mutable =
346 using src_pixel_t =
typename remove_reference<SrcP>::type;
348 using const_ref_t =
typename src_pixel_t::const_reference;
354 using argument_type = SrcP;
355 using reference =
typename mpl::if_c<is_mutable, ref_t, value_type>::type;
356 using result_type = reference;
363 result_type operator()(argument_type srcP)
const {
364 return result_type(srcP[_n]);
368 template <
typename View>
struct __nth_channel_view<View,false> {
371 using AD =
typename View::template add_deref<deref_t>;
373 using type =
typename AD::type;
374 static type make(
const View& src,
int n) {
375 return AD::make(src, deref_t(n));
386 template <
typename View>
390 using VB = detail::__nth_channel_view<View,view_is_basic<View>::value>;
392 using type =
typename VB::type;
393 static type make(
const View& src,
int n) {
return VB::make(src,n); }
398 template <
typename View>
399 typename nth_channel_view_type<View>::type nth_channel_view(
const View& src,
int n) {
414 template <
int K,
typename View,
bool AreChannelsTogether>
struct __kth_channel_view_basic;
418 template <
int K,
typename View>
419 struct __kth_channel_view_basic<K,View,false> {
421 using channel_t =
typename kth_element_type<typename View::value_type,K>::type;
425 static type make(
const View& src) {
426 using locator_t =
typename type::xy_locator;
427 using x_iterator_t =
typename type::x_iterator;
429 x_iterator_t sit(x_iterator_base_t(&gil::at_c<K>(src(0,0))),src.pixels().pixel_size());
430 return type(src.dimensions(),locator_t(sit, src.pixels().row_size()));
435 template <
int K,
typename View>
436 struct __kth_channel_view_basic<K,View,true> {
438 using channel_t =
typename kth_element_type<typename View::value_type, K>::type;
441 static type make(
const View& src) {
442 using x_iterator_t =
typename type::x_iterator;
443 return interleaved_view(src.width(),src.height(),(x_iterator_t)&gil::at_c<K>(src(0,0)), src.pixels().row_size());
447 template <
int K,
typename View,
bool IsBasic>
struct __kth_channel_view;
450 template <
int K,
typename View>
struct __kth_channel_view<K,View,true>
453 using src_x_iterator =
typename View::x_iterator;
457 static constexpr
bool adjacent =
462 using type =
typename __kth_channel_view_basic<K,View,adjacent>::type;
464 static type make(
const View& src) {
465 return __kth_channel_view_basic<K,View,adjacent>::make(src);
475 template <
int K,
typename SrcP>
478 static constexpr
bool is_mutable =
482 using src_pixel_t =
typename remove_reference<SrcP>::type;
483 using channel_t =
typename kth_element_type<src_pixel_t, K>::type;
484 using const_ref_t =
typename src_pixel_t::const_reference;
491 using argument_type = SrcP;
492 using reference =
typename mpl::if_c<is_mutable, ref_t, value_type>::type;
493 using result_type = reference;
498 result_type operator()(argument_type srcP)
const {
499 return result_type(gil::at_c<K>(srcP));
503 template <
int K,
typename View>
struct __kth_channel_view<K,View,false> {
506 using AD =
typename View::template add_deref<deref_t>;
508 using type =
typename AD::type;
509 static type make(
const View& src) {
510 return AD::make(src, deref_t());
521 template <
int K,
typename View>
525 using VB = detail::__kth_channel_view<K,View,view_is_basic<View>::value>;
527 using type =
typename VB::type;
528 static type make(
const View& src) {
return VB::make(src); }
532 template <
int K,
typename View>
533 typename kth_channel_view_type<K,View>::type kth_channel_view(
const View& src) {
Definition: algorithm.hpp:30
Returns the type of a transposed view that has a dynamic step along both X and Y. ...
Definition: image_view_factory.hpp:47
Returns the type of a homogeneous view given the channel type, layout, whether it operates on planar ...
Definition: metafunctions.hpp:414
Definition: algorithm.hpp:30
A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept.
Definition: image_view.hpp:51
returns the base iterator for a given iterator adaptor. Provide an specialization when introducing ne...
Definition: metafunctions.hpp:43
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept, PixelValueConcept, HomogeneousPixelBasedConcept.
Definition: metafunctions.hpp:31
Function object that given a source pixel, returns it converted to a given color space and channel de...
Definition: image_view_factory.hpp:117
Returns the type of a view that has a dynamic step along both X and Y.
Definition: dynamic_step.hpp:27
Given a source image view type View, returns the type of an image view over a single channel of ViewI...
Definition: image_view_factory.hpp:387
Helper base class for pixel dereference adaptors.
Definition: utilities.hpp:90
Function object that returns a grayscale reference of the K-th channel (specified as a template param...
Definition: image_view_factory.hpp:476
Returns the type of a view that does color conversion upon dereferencing its pixels.
Definition: image_view_factory.hpp:155
Determines if the given pixel reference is mutable (i.e. its channels can be changed) ...
Definition: metafunctions.hpp:171
Represents a color space and ordering of channels in memory.
Definition: utilities.hpp:247
Definition: image_view_factory.hpp:37
Function object that returns a grayscale reference of the N-th channel of a given reference...
Definition: image_view_factory.hpp:341
detail::channel_pointer_type< HomogeneousView >::type planar_view_get_raw_data(const HomogeneousView &view, int plane_index)
Returns C pointer to the the channels of a given color plane of a planar homogeneous view...
Definition: image_view_factory.hpp:102
auto interleaved_view(point< std::size_t > dim, Iterator pixels, std::ptrdiff_t rowsize_in_bytes) -> typename type_from_x_iterator< Iterator >::view_t
Constructing image views from raw interleaved pixel data.
Definition: image_view_factory.hpp:63
Pixel concept that allows for changing its channels.
Definition: concepts/pixel.hpp:102
Returns the type of a homogeneous pixel reference given the channel type, layout, whether it operates...
Definition: metafunctions.hpp:204
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
detail::channel_pointer_type< HomogeneousView >::type interleaved_view_get_raw_data(const HomogeneousView &view)
Returns C pointer to the the channels of an interleaved homogeneous view.
Definition: image_view_factory.hpp:92
Determines if the given view is mutable (i.e. its pixels can be changed)
Definition: metafunctions.hpp:180
Definition: color_convert.hpp:30
GIL's 2-dimensional view over immutable GIL pixels.
Definition: concepts/image_view.hpp:373
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:460
Given a model of a pixel, determines whether the model represents a pixel reference (as opposed to pi...
Definition: metafunctions.hpp:161
class for color-converting one pixel to another
Definition: color_convert.hpp:282
Returns the number of channels of a pixel-based GIL construct.
Definition: locator.hpp:38
Basic views must be over basic locators.
Definition: metafunctions.hpp:101
Given a source image view type View, returns the type of an image view over a given channel of View...
Definition: image_view_factory.hpp:522
Determines if the given iterator has a step that could be set dynamically.
Definition: metafunctions.hpp:114
2D point both axes of which have the same dimension typeModels: Point2DConcept
Definition: locator.hpp:28
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17