14#ifndef LIBCARLA_IMAGE_SUPPORT_PNG
15 #define LIBCARLA_IMAGE_SUPPORT_PNG false
18#ifndef LIBCARLA_IMAGE_SUPPORT_JPEG
19 #define LIBCARLA_IMAGE_SUPPORT_JPEG false
22#ifndef LIBCARLA_IMAGE_SUPPORT_TIFF
23 #define LIBCARLA_IMAGE_SUPPORT_TIFF false
27# pragma clang diagnostic push
28# pragma clang diagnostic ignored "-Wunused-parameter"
31#if LIBCARLA_IMAGE_SUPPORT_PNG
32# ifndef png_infopp_NULL
33# define png_infopp_NULL (png_infopp)NULL
36# define int_p_NULL (int*)NULL
38# if defined(__clang__)
39# pragma clang diagnostic push
40# pragma clang diagnostic ignored "-Wignored-qualifiers"
41# pragma clang diagnostic ignored "-Wparentheses"
43# include <boost/gil/extension/io/png.hpp>
44# if defined(__clang__)
45# pragma clang diagnostic pop
49#if LIBCARLA_IMAGE_WITH_JPEG_SUPPORT
50# include <boost/gil/extension/io/jpeg.hpp>
53#if LIBCARLA_IMAGE_WITH_TIFF_SUPPORT
54# include <boost/gil/extension/io/tiff.hpp>
58# pragma clang diagnostic pop
79 "No image format supported, please compile with at least one of "
80 "LIBCARLA_IMAGE_SUPPORT_PNG, "
81 "LIBCARLA_IMAGE_SUPPORT_JPEG "
82 "or LIBCARLA_IMAGE_SUPPORT_TIFF");
86 template <
typename ViewT,
typename IOTag>
88 static constexpr bool value = boost::gil::is_write_supported<typename boost::gil::get_pixel_type<ViewT>::type, IOTag>
::value;
95#if LIBCARLA_IMAGE_SUPPORT_PNG
97 static constexpr const char *get_default_extension() {
101 template <
typename Str>
102 static bool match_extension(
const Str &str) {
106 template <
typename Str,
typename ImageT>
107 static void read_image(Str &&in_filename, ImageT &image) {
108 boost::gil::read_and_convert_image(std::forward<Str>(in_filename), image, boost::gil::png_tag());
111 template <
typename Str,
typename ViewT>
112 static void write_view(Str &&out_filename,
const ViewT &view) {
113 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::png_tag());
123#if LIBCARLA_IMAGE_WITH_JPEG_SUPPORT
125 static constexpr const char *get_default_extension() {
129 template <
typename Str>
130 static bool match_extension(
const Str &str) {
135 template <
typename Str,
typename ImageT>
136 static void read_image(Str &&in_filename, ImageT &image) {
137 boost::gil::read_image(std::forward<Str>(in_filename), image, boost::gil::jpeg_tag());
140 template <
typename Str,
typename ViewT>
141 static typename std::enable_if<is_write_supported<ViewT, boost::gil::jpeg_tag>::value>::type
142 write_view(Str &&out_filename,
const ViewT &view) {
143 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::jpeg_tag());
146 template <
typename Str,
typename ViewT>
147 static typename std::enable_if<!is_write_supported<ViewT, boost::gil::jpeg_tag>::value>::type
148 write_view(Str &&out_filename,
const ViewT &view) {
149 boost::gil::write_view(
150 std::forward<Str>(out_filename),
151 boost::gil::color_converted_view<boost::gil::rgb8_pixel_t>(view),
152 boost::gil::jpeg_tag());
162#if LIBCARLA_IMAGE_SUPPORT_TIFF
164 static constexpr const char *get_default_extension() {
168 template <
typename Str>
169 static bool match_extension(
const Str &str) {
173 template <
typename Str,
typename ImageT>
174 static void read_image(Str &&in_filename, ImageT &image) {
175 boost::gil::read_and_convert_image(std::forward<Str>(in_filename), image, boost::gil::tiff_tag());
178 template <
typename Str,
typename ViewT>
179 static typename std::enable_if<is_write_supported<ViewT, boost::gil::tiff_tag>::value>::type
180 write_view(Str &&out_filename,
const ViewT &view) {
181 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::tiff_tag());
184 template <
typename Str,
typename ViewT>
185 static typename std::enable_if<!is_write_supported<ViewT, boost::gil::tiff_tag>::value>::type
186 write_view(Str &&out_filename,
const ViewT &view) {
187 boost::gil::write_view(
188 std::forward<Str>(out_filename),
189 boost::gil::color_converted_view<boost::gil::rgb8_pixel_t>(view),
190 boost::gil::tiff_tag());
198 template <
typename IO,
typename Str>
199 static typename std::enable_if<IO::is_supported, bool>::type
match_extension(
const Str &str) {
200 return IO::match_extension(str);
203 template <
typename IO,
typename Str>
204 static typename std::enable_if<!IO::is_supported, bool>::type
match_extension(
const Str &) {
208 template <
typename IO,
typename Str,
typename... Args>
209 static typename std::enable_if<IO::is_supported>::type
read_image(
const Str &path, Args &&... args) {
210 log_debug(
"reading", path,
"as", IO::get_default_extension());
211 IO::read_image(path, std::forward<Args>(args)...);
214 template <
typename IO,
typename... Args>
215 static typename std::enable_if<!IO::is_supported>::type
read_image(Args &&...) {
219 template <
typename IO,
typename... Args>
220 static typename std::enable_if<IO::is_supported>::type
write_view(std::string &path, Args &&... args) {
222 log_debug(
"writing", path,
"as", IO::get_default_extension());
223 IO::write_view(path, std::forward<Args>(args)...);
226 template <
typename IO,
typename... Args>
227 static typename std::enable_if<!IO::is_supported>::type
write_view(Args &&...) {
232 template <
typename... IOs>
235 template <
typename IO>
237 constexpr static bool is_supported = IO::is_supported;
239 template <
typename... Args>
241 io_resolver::read_image<IO>(std::forward<Args>(args)...);
244 template <
typename... Args>
246 io_resolver::write_view<IO>(std::forward<Args>(args)...);
249 template <
typename Str,
typename... Args>
251 if (io_resolver::match_extension<IO>(filename)) {
252 io_resolver::read_image<IO>(filename, std::forward<Args>(args)...);
258 template <
typename Str,
typename... Args>
260 if (io_resolver::match_extension<IO>(filename)) {
261 io_resolver::write_view<IO>(filename, std::forward<Args>(args)...);
268 template <
typename IO,
typename... IOs>
275 constexpr static bool is_supported = self::is_supported || recursive::is_supported;
277 template <
typename... Args>
279 if (!recursive::try_read_image(args...)) {
280 self::read_image(args...);
284 template <
typename... Args>
286 return recursive::try_read_image(args...) || self::try_read_image(args...);
289 template <
typename... Args>
291 if (!recursive::try_write_view(args...)) {
292 self::write_view(args...);
296 template <
typename... Args>
298 return recursive::try_write_view(args...) || self::try_write_view(args...);
302 template <
typename DefaultIO,
typename... IOs>
304 static_assert(DefaultIO::is_supported,
"Default IO needs to be supported.");
315#if LIBCARLA_IMAGE_SUPPORT_PNG
317 struct any :
detail::io_any<detail::io_png, detail::io_tiff, detail::io_jpeg> {};
319#elif LIBCARLA_IMAGE_SUPPORT_TIFF
321 struct any : detail::io_any<detail::io_tiff, detail::io_jpeg> {};
#define DEBUG_ASSERT(predicate)
#define LIBCARLA_IMAGE_SUPPORT_JPEG
#define LIBCARLA_IMAGE_SUPPORT_TIFF
#define LIBCARLA_IMAGE_SUPPORT_PNG
static void ValidateFilePath(std::string &filepath, const std::string &default_extension="")
Convenient function to validate a path before creating a file.
static bool EndsWith(const Range1T &input, const Range2T &test)
constexpr bool has_jpeg_support()
constexpr bool has_tiff_support()
constexpr bool has_png_support()
This file contains definitions of common data structures used in traffic manager.
static void log_debug(Args &&... args)
static void read_image(Args &... args)
static void write_view(Args &... args)
static bool try_write_view(Args &... args)
static bool try_read_image(Args &... args)
static bool try_write_view(Str &filename, Args &&... args)
static bool try_read_image(const Str &filename, Args &&... args)
static void write_view(Args &&... args)
static void read_image(Args &&... args)
static constexpr bool is_supported
static constexpr bool is_supported
static std::enable_if< IO::is_supported >::type read_image(const Str &path, Args &&... args)
static std::enable_if<!IO::is_supported >::type read_image(Args &&...)
static std::enable_if<!IO::is_supported >::type write_view(Args &&...)
static std::enable_if< IO::is_supported >::type write_view(std::string &path, Args &&... args)
static std::enable_if< IO::is_supported, bool >::type match_extension(const Str &str)
static std::enable_if<!IO::is_supported, bool >::type match_extension(const Str &)
static constexpr bool is_supported
static constexpr bool value