14 #ifndef LIBCARLA_IMAGE_WITH_PNG_SUPPORT 15 # if defined(__has_include) && __has_include("png.h") 16 # define LIBCARLA_IMAGE_WITH_PNG_SUPPORT true 18 # define LIBCARLA_IMAGE_WITH_PNG_SUPPORT false 22 #ifndef LIBCARLA_IMAGE_WITH_JPEG_SUPPORT 23 # if defined(__has_include) && __has_include("jpeglib.h") 24 # define LIBCARLA_IMAGE_WITH_JPEG_SUPPORT true 26 # define LIBCARLA_IMAGE_WITH_JPEG_SUPPORT false 30 #ifndef LIBCARLA_IMAGE_WITH_TIFF_SUPPORT 31 # if defined(__has_include) && __has_include("tiffio.h") 32 # define LIBCARLA_IMAGE_WITH_TIFF_SUPPORT true 34 # define LIBCARLA_IMAGE_WITH_TIFF_SUPPORT false 38 #if defined(__clang__) 39 # pragma clang diagnostic push 40 # pragma clang diagnostic ignored "-Wunused-parameter" 43 #if LIBCARLA_IMAGE_WITH_PNG_SUPPORT == true 44 # ifndef png_infopp_NULL 45 # define png_infopp_NULL (png_infopp)NULL 46 # endif // png_infopp_NULL 48 # define int_p_NULL (int*)NULL 50 # if defined(__clang__) 51 # pragma clang diagnostic push 52 # pragma clang diagnostic ignored "-Wignored-qualifiers" 53 # pragma clang diagnostic ignored "-Wparentheses" 55 # include <boost/gil/extension/io/png.hpp> 56 # if defined(__clang__) 57 # pragma clang diagnostic pop 61 #if LIBCARLA_IMAGE_WITH_JPEG_SUPPORT == true 62 # include <boost/gil/extension/io/jpeg.hpp> 65 #if LIBCARLA_IMAGE_WITH_TIFF_SUPPORT == true 66 # include <boost/gil/extension/io/tiff.hpp> 69 #if defined(__clang__) 70 # pragma clang diagnostic pop 90 "No image format supported, please compile with at least one of " 91 "LIBCARLA_IMAGE_WITH_PNG_SUPPORT, LIBCARLA_IMAGE_WITH_JPEG_SUPPORT, " 92 "or LIBCARLA_IMAGE_WITH_TIFF_SUPPORT");
96 template <
typename ViewT,
typename IOTag>
98 static constexpr
bool value = boost::gil::is_write_supported<typename boost::gil::get_pixel_type<ViewT>::type, IOTag>
::value;
105 #if LIBCARLA_IMAGE_WITH_PNG_SUPPORT 107 static constexpr
const char *get_default_extension() {
111 template <
typename Str>
112 static bool match_extension(
const Str &str) {
116 template <
typename Str,
typename ImageT>
117 static void read_image(Str &&in_filename, ImageT &image) {
118 boost::gil::read_and_convert_image(std::forward<Str>(in_filename), image, boost::gil::png_tag());
121 template <
typename Str,
typename ViewT>
122 static void write_view(Str &&out_filename,
const ViewT &view) {
123 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::png_tag());
126 #endif // LIBCARLA_IMAGE_WITH_PNG_SUPPORT 133 #if LIBCARLA_IMAGE_WITH_JPEG_SUPPORT 135 static constexpr
const char *get_default_extension() {
139 template <
typename Str>
140 static bool match_extension(
const Str &str) {
145 template <
typename Str,
typename ImageT>
146 static void read_image(Str &&in_filename, ImageT &image) {
147 boost::gil::read_image(std::forward<Str>(in_filename), image, boost::gil::jpeg_tag());
150 template <
typename Str,
typename ViewT>
151 static typename std::enable_if<is_write_supported<ViewT, boost::gil::jpeg_tag>::value>::type
152 write_view(Str &&out_filename,
const ViewT &view) {
153 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::jpeg_tag());
156 template <
typename Str,
typename ViewT>
157 static typename std::enable_if<!is_write_supported<ViewT, boost::gil::jpeg_tag>::value>::type
158 write_view(Str &&out_filename,
const ViewT &view) {
159 boost::gil::write_view(
160 std::forward<Str>(out_filename),
161 boost::gil::color_converted_view<boost::gil::rgb8_pixel_t>(view),
162 boost::gil::jpeg_tag());
165 #endif // LIBCARLA_IMAGE_WITH_JPEG_SUPPORT 172 #if LIBCARLA_IMAGE_WITH_TIFF_SUPPORT 174 static constexpr
const char *get_default_extension() {
178 template <
typename Str>
179 static bool match_extension(
const Str &str) {
183 template <
typename Str,
typename ImageT>
184 static void read_image(Str &&in_filename, ImageT &image) {
185 boost::gil::read_and_convert_image(std::forward<Str>(in_filename), image, boost::gil::tiff_tag());
188 template <
typename Str,
typename ViewT>
189 static typename std::enable_if<is_write_supported<ViewT, boost::gil::tiff_tag>::value>::type
190 write_view(Str &&out_filename,
const ViewT &view) {
191 boost::gil::write_view(std::forward<Str>(out_filename), view, boost::gil::tiff_tag());
194 template <
typename Str,
typename ViewT>
195 static typename std::enable_if<!is_write_supported<ViewT, boost::gil::tiff_tag>::value>::type
196 write_view(Str &&out_filename,
const ViewT &view) {
197 boost::gil::write_view(
198 std::forward<Str>(out_filename),
199 boost::gil::color_converted_view<boost::gil::rgb8_pixel_t>(view),
200 boost::gil::tiff_tag());
203 #endif // LIBCARLA_IMAGE_WITH_TIFF_SUPPORT 208 template <
typename IO,
typename Str>
209 static typename std::enable_if<IO::is_supported, bool>::type
match_extension(
const Str &str) {
210 return IO::match_extension(str);
213 template <
typename IO,
typename Str>
214 static typename std::enable_if<!IO::is_supported, bool>::type
match_extension(
const Str &) {
218 template <
typename IO,
typename Str,
typename... Args>
219 static typename std::enable_if<IO::is_supported>::type
read_image(
const Str &path, Args &&... args) {
220 log_debug(
"reading", path,
"as", IO::get_default_extension());
221 IO::read_image(path, std::forward<Args>(args)...);
224 template <
typename IO,
typename... Args>
225 static typename std::enable_if<!IO::is_supported>::type
read_image(Args &&...) {
229 template <
typename IO,
typename... Args>
230 static typename std::enable_if<IO::is_supported>::type
write_view(std::string &path, Args &&... args) {
232 log_debug(
"writing", path,
"as", IO::get_default_extension());
233 IO::write_view(path, std::forward<Args>(args)...);
236 template <
typename IO,
typename... Args>
237 static typename std::enable_if<!IO::is_supported>::type
write_view(Args &&...) {
242 template <
typename... IOs>
245 template <
typename IO>
247 constexpr
static bool is_supported = IO::is_supported;
249 template <
typename... Args>
251 io_resolver::read_image<IO>(std::forward<Args>(args)...);
254 template <
typename... Args>
256 io_resolver::write_view<IO>(std::forward<Args>(args)...);
259 template <
typename Str,
typename... Args>
261 if (io_resolver::match_extension<IO>(filename)) {
262 io_resolver::read_image<IO>(filename, std::forward<Args>(args)...);
268 template <
typename Str,
typename... Args>
270 if (io_resolver::match_extension<IO>(filename)) {
271 io_resolver::write_view<IO>(filename, std::forward<Args>(args)...);
278 template <
typename IO,
typename... IOs>
285 constexpr
static bool is_supported = self::is_supported || recursive::is_supported;
287 template <
typename... Args>
289 if (!recursive::try_read_image(args...)) {
290 self::read_image(args...);
294 template <
typename... Args>
296 return recursive::try_read_image(args...) || self::try_read_image(args...);
299 template <
typename... Args>
301 if (!recursive::try_write_view(args...)) {
302 self::write_view(args...);
306 template <
typename... Args>
308 return recursive::try_write_view(args...) || self::try_write_view(args...);
312 template <
typename DefaultIO,
typename... IOs>
314 static_assert(DefaultIO::is_supported,
"Default IO needs to be supported.");
325 #if LIBCARLA_IMAGE_WITH_PNG_SUPPORT 327 struct any :
detail::io_any<detail::io_png, detail::io_tiff, detail::io_jpeg> {};
329 #elif LIBCARLA_IMAGE_WITH_TIFF_SUPPORT 333 #else // Then for sure this one is available. 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 void write_view(Args &... args)
static bool EndsWith(const Range1T &input, const Range2T &test)
static std::enable_if<!IO::is_supported >::type write_view(Args &&...)
static std::enable_if<!IO::is_supported, bool >::type match_extension(const Str &)
static void write_view(Args &&... args)
static void ValidateFilePath(std::string &filepath, const std::string &default_extension="")
Convenient function to validate a path before creating a file.
static constexpr bool value
#define LIBCARLA_IMAGE_WITH_PNG_SUPPORT
This file contains definitions of common data structures used in traffic manager. ...
static std::enable_if< IO::is_supported >::type write_view(std::string &path, Args &&... args)
static void log_debug(Args &&...)
constexpr bool has_jpeg_support()
#define DEBUG_ASSERT(predicate)
static std::enable_if< IO::is_supported, bool >::type match_extension(const Str &str)
#define LIBCARLA_IMAGE_WITH_TIFF_SUPPORT
#define LIBCARLA_IMAGE_WITH_JPEG_SUPPORT
constexpr bool has_tiff_support()
static void read_image(Args &... args)
static void read_image(Args &&... args)
static bool try_write_view(Args &... args)
static bool try_read_image(const Str &filename, Args &&... args)
static bool try_read_image(Args &... args)
static bool try_write_view(Str &filename, Args &&... args)
constexpr bool has_png_support()