add parse_jpeg_quality method + uint test parsing jpegXX and jpeg:quality=XX options
ref #3024
This commit is contained in:
parent
bf009489d7
commit
751abba262
3 changed files with 32 additions and 6 deletions
|
@ -28,7 +28,9 @@
|
|||
#include <iostream>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace detail {
|
||||
int parse_jpeg_quality(std::string params);
|
||||
}
|
||||
struct jpeg_saver
|
||||
{
|
||||
jpeg_saver(std::ostream &, std::string const&);
|
||||
|
|
|
@ -41,14 +41,14 @@ namespace mapnik
|
|||
jpeg_saver::jpeg_saver(std::ostream & stream, std::string const& t)
|
||||
: stream_(stream), t_(t) {}
|
||||
|
||||
template <typename T>
|
||||
void process_rgba8_jpeg(T const& image, std::string const& type, std::ostream & stream)
|
||||
namespace detail {
|
||||
|
||||
int parse_jpeg_quality(std::string params)
|
||||
{
|
||||
#if defined(HAVE_JPEG)
|
||||
int quality = 85;
|
||||
if (type != "jpeg")
|
||||
if (params != "jpeg")
|
||||
{
|
||||
for (auto const& kv : parse_image_options(type))
|
||||
for (auto const& kv : parse_image_options(params))
|
||||
{
|
||||
auto const& key = kv.first;
|
||||
auto const& val = kv.second;
|
||||
|
@ -73,6 +73,16 @@ void process_rgba8_jpeg(T const& image, std::string const& type, std::ostream &
|
|||
}
|
||||
}
|
||||
}
|
||||
return quality;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void process_rgba8_jpeg(T const& image, std::string const& type, std::ostream & stream)
|
||||
{
|
||||
#if defined(HAVE_JPEG)
|
||||
int quality = detail::parse_jpeg_quality(type);
|
||||
save_as_jpeg(stream, quality, image);
|
||||
#else
|
||||
throw image_writer_exception("jpeg output is not enabled in your build of Mapnik");
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <mapnik/image.hpp>
|
||||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/image_util_jpeg.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -41,6 +42,7 @@ SECTION("readers") {
|
|||
{
|
||||
REQUIRE( std::string(ex.what()) == std::string("JPEG Reader: libjpeg could not read image: Not a JPEG file: starts with 0x89 0x50") );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
REQUIRE_THROWS(mapnik::image_rgba8 im(-10,-10)); // should throw rather than overflow
|
||||
|
@ -95,5 +97,17 @@ SECTION("readers") {
|
|||
|
||||
} // END SECTION
|
||||
|
||||
SECTION("writers options")
|
||||
{
|
||||
#if defined(HAVE_JPEG)
|
||||
// test we can parse both jpegXX and quality=XX options
|
||||
REQUIRE_THROWS(mapnik::detail::parse_jpeg_quality("jpegXX"));
|
||||
REQUIRE_THROWS(mapnik::detail::parse_jpeg_quality("jpeg:quality=XX"));
|
||||
int q0 = mapnik::detail::parse_jpeg_quality("jpeg50");
|
||||
int q1 = mapnik::detail::parse_jpeg_quality("jpeg:quality=50");
|
||||
REQUIRE(q0 == q1);
|
||||
#endif
|
||||
|
||||
} // END SECTION
|
||||
|
||||
} // END TEST_CASE
|
||||
|
|
Loading…
Reference in a new issue