CARLA
ImageView.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/image/BoostGil.h"
13 
14 #include <type_traits>
15 
16 namespace carla {
17 namespace image {
18 
19  class ImageView {
20  private:
21 
22  template <typename SrcViewT>
23  using GrayPixelLayout = boost::gil::pixel<typename boost::gil::channel_type<SrcViewT>::type, boost::gil::gray_layout_t>;
24 
25  template <typename DstPixelT, typename ImageT>
26  static auto MakeViewFromSensorImage(ImageT &image) {
27  using namespace boost::gil;
28  namespace sd = carla::sensor::data;
29  static_assert(
30  std::is_same<typename ImageT::pixel_type, sd::Color>::value,
31  "Invalid pixel type");
32  static_assert(
33  sizeof(sd::Color) == sizeof(DstPixelT),
34  "Invalid pixel size");
35  return interleaved_view(
36  image.GetWidth(),
37  image.GetHeight(),
38  reinterpret_cast<DstPixelT*>(image.data()),
39  sizeof(sd::Color) * image.GetWidth()); // row length in bytes.
40  }
41 
42  public:
43 
44  template <typename ImageT>
45  static auto MakeView(ImageT &image) {
46  return boost::gil::view(image);
47  }
48 
50  return MakeViewFromSensorImage<boost::gil::bgra8_pixel_t>(image);
51  }
52 
54  return MakeViewFromSensorImage<boost::gil::bgra8c_pixel_t>(image);
55  }
56 
57  template <typename SrcViewT, typename DstPixelT, typename CC>
58  static auto MakeColorConvertedView(const SrcViewT &src, CC cc) {
59  return _MakeColorConvertedView<DstPixelT>(src, cc);
60  }
61 
62  template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
63  static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::Depth cc) {
64  return _MakeColorConvertedView<DstPixelT>(src, cc);
65  }
66 
67  template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
68  static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::LogarithmicDepth) {
69  auto intermediate_view = _MakeColorConvertedView<boost::gil::gray32f_pixel_t>(src, ColorConverter::Depth());
70  return _MakeColorConvertedView<DstPixelT>(intermediate_view, ColorConverter::LogarithmicLinear());
71  }
72 
73  template <typename SrcViewT, typename DstPixelT = typename SrcViewT::value_type>
74  static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::CityScapesPalette cc) {
75  return _MakeColorConvertedView<DstPixelT>(src, cc);
76  }
77 
78  private:
79 
80  template <typename SrcView, typename DstP, typename CC>
82  private:
83  typedef boost::gil::color_convert_deref_fn<typename SrcView::const_t::reference, DstP, CC> deref_t;
84  typedef typename SrcView::template add_deref<deref_t> add_ref_t;
85  public:
86  typedef typename add_ref_t::type type;
87  static type make(const SrcView &sv, CC cc) { return add_ref_t::make(sv, deref_t(cc)); }
88  };
89 
90  template <typename DstPixelT, typename SrcViewT, typename CC>
91  static auto _MakeColorConvertedView(const SrcViewT &src, CC cc) {
93  }
94  };
95 
96 } // namespace image
97 } // namespace carla
Templated image for any type of pixel.
Definition: ImageTmpl.h:24
static auto MakeView(sensor::data::ImageTmpl< sensor::data::Color > &image)
Definition: ImageView.h:49
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::CityScapesPalette cc)
Definition: ImageView.h:74
sensor::data::Color Color
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::LogarithmicDepth)
Definition: ImageView.h:68
static shared_buffer make(const T &buffer)
Definition: test/Buffer.h:33
static auto MakeView(const sensor::data::ImageTmpl< sensor::data::Color > &image)
Definition: ImageView.h:53
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
SrcView::template add_deref< deref_t > add_ref_t
Definition: ImageView.h:84
static auto MakeViewFromSensorImage(ImageT &image)
Definition: ImageView.h:26
static double sd[6]
Definition: odrSpiral.cpp:55
static type make(const SrcView &sv, CC cc)
Definition: ImageView.h:87
boost::gil::pixel< typename boost::gil::channel_type< SrcViewT >::type, boost::gil::gray_layout_t > GrayPixelLayout
Definition: ImageView.h:23
static auto MakeView(ImageT &image)
Definition: ImageView.h:45
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::Depth cc)
Definition: ImageView.h:63
static auto MakeColorConvertedView(const SrcViewT &src, CC cc)
Definition: ImageView.h:58
static auto _MakeColorConvertedView(const SrcViewT &src, CC cc)
Definition: ImageView.h:91
boost::gil::color_convert_deref_fn< typename SrcView::const_t::reference, DstP, CC > deref_t
Definition: ImageView.h:83