diff --git a/include/mapnik/image.hpp b/include/mapnik/image.hpp index e9796e3db..b7eed4da1 100644 --- a/include/mapnik/image.hpp +++ b/include/mapnik/image.hpp @@ -340,7 +340,8 @@ enum image_dtype : std::uint8_t image_dtype_gray64, image_dtype_gray64s, image_dtype_gray64f, - image_dtype_null + image_dtype_null, + IMAGE_DTYPE_MAX }; } // end ns diff --git a/include/mapnik/image_any.hpp b/include/mapnik/image_any.hpp index 55e75d1f2..b432227fd 100644 --- a/include/mapnik/image_any.hpp +++ b/include/mapnik/image_any.hpp @@ -306,6 +306,7 @@ inline image_any create_image_any(int width, case image_dtype_null: return image_any(std::move(image_null())); case image_dtype_rgba8: + case IMAGE_DTYPE_MAX: default: return image_any(std::move(image_rgba8(width, height, initialize, premultiplied, painted))); } diff --git a/src/image_copy.cpp b/src/image_copy.cpp index e686576db..312b51dda 100644 --- a/src/image_copy.cpp +++ b/src/image_copy.cpp @@ -340,6 +340,10 @@ MAPNIK_DECL image_any image_copy(image_any const& data, image_dtype type, double return image_any(std::move(image_copy(data, offset, scaling))); case image_dtype_null: throw std::runtime_error("Can not cast a null image"); + case IMAGE_DTYPE_MAX: + default: + throw std::runtime_error("Can not cast unknown type"); + } throw std::runtime_error("Unknown image type passed"); } diff --git a/src/image_util_jpeg.cpp b/src/image_util_jpeg.cpp index 6ee8efa10..61c11245f 100644 --- a/src/image_util_jpeg.cpp +++ b/src/image_util_jpeg.cpp @@ -46,16 +46,32 @@ jpeg_saver::jpeg_saver(std::ostream & stream, std::string const& t): stream_(stream), t_(t) {} template -void process_rgba8_jpeg(T const& image, std::string const& t, std::ostream & stream) +void process_rgba8_jpeg(T const& image, std::string const& type, std::ostream & stream) { #if defined(HAVE_JPEG) int quality = 85; - std::string val = t.substr(5); - if (!val.empty()) + //std::string val = type.substr(4); + if (type != "jpeg") { - if (!mapnik::util::string2int(val,quality) || quality < 0 || quality > 100) + boost::char_separator sep(":"); + boost::tokenizer< boost::char_separator > tokens(type, sep); + for (auto const& t : tokens) { - throw ImageWriterException("invalid jpeg quality: '" + val + "'"); + if (t == "jpeg") + { + continue; + } + else if (boost::algorithm::starts_with(t, "quality=")) + { + std::string val = t.substr(8); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,quality) || quality < 0 || quality > 100) + { + throw ImageWriterException("invalid jpeg quality: '" + val + "'"); + } + } + } } } save_as_jpeg(stream, quality, image);