diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index 7f2df798a..4ea1cc53e 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -58,6 +58,7 @@ struct png_options { int strategy; int trans_mode; int iq_speed; + double iq_dither; double gamma; bool paletted; quantization_type quantization; @@ -68,6 +69,7 @@ struct png_options { strategy(Z_DEFAULT_STRATEGY), trans_mode(-1), iq_speed(3), + iq_dither(-1), gamma(-1), paletted(true), quantization(HEXTREE), @@ -740,6 +742,9 @@ void save_as_png8_libimagequant(T1 & file, liq_result *res = liq_quantize_image(attr, liq_image); // Store palettized version + if (opts.iq_dither != -1) { + liq_set_dithering_level(res, opts.iq_dither); + } image_gray8 reduced_image(width, height); liq_write_remapped_image(res, liq_image, (void *)reduced_image.data(), width*height*sizeof(gray8_t)); const liq_palette *liq_pal = liq_get_palette(res); diff --git a/src/image_util_png.cpp b/src/image_util_png.cpp index d80ae269d..9b1f6c911 100644 --- a/src/image_util_png.cpp +++ b/src/image_util_png.cpp @@ -91,11 +91,18 @@ void handle_png_options(std::string const& type, opts.quantization = png_options::IMGQUANT; } - else if (boost::algorithm::starts_with(t, "iq=")) + else if (boost::algorithm::starts_with(t, "iqs=")) { - if (!mapnik::util::string2int(t.substr(3), opts.iq_speed) || opts.iq_speed < 1 || opts.iq_speed > 10) + if (!mapnik::util::string2int(t.substr(4), opts.iq_speed) || opts.iq_speed < 1 || opts.iq_speed > 10) { - throw ImageWriterException("invalid iq speed parameter: " + t.substr(3)); + throw ImageWriterException("invalid iq speed parameter: " + t.substr(4)); + } + } + else if (boost::algorithm::starts_with(t, "iqd=")) + { + if (!mapnik::util::string2double(t.substr(4), opts.iq_dither) || opts.iq_dither < 0 || opts.iq_dither > 1) + { + throw ImageWriterException("invalid iq dithering parameter: " + t.substr(4)); } } else if (t == "e=miniz")