diff --git a/src/image_util.cpp b/src/image_util.cpp index 170c49a02..16329473f 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -149,7 +149,11 @@ void handle_png_options(std::string const& type, bool set_gamma = false; BOOST_FOREACH(std::string const& t, tokens) { - if (t == "png24" || t == "png32") + if (t == "png" || t == "png8") + { + opts.paletted = true; + } + else if (t == "png24" || t == "png32") { opts.paletted = false; } @@ -157,6 +161,10 @@ void handle_png_options(std::string const& type, { opts.use_hextree = false; } + else if (t == "m=h") + { + opts.use_hextree = true; + } else if (t == "e=miniz") { opts.use_miniz = true; @@ -227,6 +235,10 @@ void handle_png_options(std::string const& type, throw ImageWriterException("invalid compression strategy parameter: " + s); } } + else + { + throw ImageWriterException("unhandled png option: " + t); + } } // validation if (!opts.paletted && set_colors) @@ -258,7 +270,11 @@ void handle_webp_options(std::string const& type, boost::tokenizer< boost::char_separator > tokens(type, sep); BOOST_FOREACH(std::string const& t, tokens) { - if (boost::algorithm::starts_with(t, "quality=")) + if (t == "webp") + { + continue; + } + else if (boost::algorithm::starts_with(t, "quality=")) { std::string val = t.substr(8); if (!val.empty()) @@ -325,6 +341,177 @@ void handle_webp_options(std::string const& type, } } } + else if (boost::algorithm::starts_with(t, "target_size=")) + { + std::string val = t.substr(12); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.target_size)) + { + throw ImageWriterException("invalid webp target_size: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "target_psnr=")) + { + std::string val = t.substr(12); + if (!val.empty()) + { + double psnr = 0; + if (!mapnik::util::string2double(val,psnr)) + { + throw ImageWriterException("invalid webp target_psnr: '" + val + "'"); + } + config.target_PSNR = psnr; + } + } + else if (boost::algorithm::starts_with(t, "segments=")) + { + std::string val = t.substr(9); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.segments)) + { + throw ImageWriterException("invalid webp segments: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "sns_strength=")) + { + std::string val = t.substr(13); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.sns_strength)) + { + throw ImageWriterException("invalid webp sns_strength: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "filter_strength=")) + { + std::string val = t.substr(16); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.filter_strength)) + { + throw ImageWriterException("invalid webp filter_strength: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "filter_sharpness=")) + { + std::string val = t.substr(17); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.filter_sharpness)) + { + throw ImageWriterException("invalid webp filter_sharpness: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "filter_type=")) + { + std::string val = t.substr(12); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.filter_type)) + { + throw ImageWriterException("invalid webp filter_type: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "autofilter=")) + { + std::string val = t.substr(11); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.autofilter)) + { + throw ImageWriterException("invalid webp autofilter: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "alpha_compression=")) + { + std::string val = t.substr(18); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.alpha_compression)) + { + throw ImageWriterException("invalid webp alpha_compression: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "alpha_filtering=")) + { + std::string val = t.substr(16); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.alpha_filtering)) + { + throw ImageWriterException("invalid webp alpha_filtering: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "alpha_quality=")) + { + std::string val = t.substr(14); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.alpha_quality)) + { + throw ImageWriterException("invalid webp alpha_quality: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "pass=")) + { + std::string val = t.substr(5); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.pass)) + { + throw ImageWriterException("invalid webp pass: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "preprocessing=")) + { + std::string val = t.substr(14); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.preprocessing)) + { + throw ImageWriterException("invalid webp preprocessing: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "partitions=")) + { + std::string val = t.substr(11); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.partitions)) + { + throw ImageWriterException("invalid webp partitions: '" + val + "'"); + } + } + } + else if (boost::algorithm::starts_with(t, "partition_limit=")) + { + std::string val = t.substr(16); + if (!val.empty()) + { + if (!mapnik::util::string2int(val,config.partition_limit)) + { + throw ImageWriterException("invalid webp partition_limit: '" + val + "'"); + } + } + } + else + { + throw ImageWriterException("unhandled webp option: " + t); + } } } } diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_compression=0.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_compression=0.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_compression=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_filtering=2.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_filtering=2.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_filtering=2.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_quality=50.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_quality=50.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+alpha_quality=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+autofilter=0.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+autofilter=0.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+autofilter=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_sharpness=4.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_sharpness=4.webp new file mode 100644 index 000000000..34d92449c Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_sharpness=4.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_strength=50.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_strength=50.webp new file mode 100644 index 000000000..267c2526c Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_type=1+autofilter=1.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_type=1+autofilter=1.webp new file mode 100644 index 000000000..cbe2812be Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+filter_type=1+autofilter=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partition_limit=50.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partition_limit=50.webp new file mode 100644 index 000000000..c14675134 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partition_limit=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partitions=3.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partitions=3.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+partitions=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+pass=10.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+pass=10.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+pass=10.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+preprocessing=1.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+preprocessing=1.webp new file mode 100644 index 000000000..63ec79f70 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+preprocessing=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+segments=3.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+segments=3.webp new file mode 100644 index 000000000..c65f66427 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+segments=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+sns_strength=50.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+sns_strength=50.webp new file mode 100644 index 000000000..69829e529 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+sns_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_PSNR=.5.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_PSNR=.5.webp new file mode 100644 index 000000000..e63841d49 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_PSNR=.5.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_size=100.webp b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_size=100.webp new file mode 100644 index 000000000..e63841d49 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/aerial_rgba-webp+target_size=100.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_compression=0.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_compression=0.webp new file mode 100644 index 000000000..d2eb2bba4 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_compression=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_filtering=2.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_filtering=2.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_filtering=2.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_quality=50.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_quality=50.webp new file mode 100644 index 000000000..25e51cfd5 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+alpha_quality=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+autofilter=0.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+autofilter=0.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+autofilter=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+filter_sharpness=4.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_sharpness=4.webp new file mode 100644 index 000000000..548500242 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_sharpness=4.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+filter_strength=50.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_strength=50.webp new file mode 100644 index 000000000..c9136a5d7 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+filter_type=1+autofilter=1.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_type=1+autofilter=1.webp new file mode 100644 index 000000000..5c87c9e5e Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+filter_type=1+autofilter=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+partition_limit=50.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+partition_limit=50.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+partition_limit=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+partitions=3.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+partitions=3.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+partitions=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+pass=10.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+pass=10.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+pass=10.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+preprocessing=1.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+preprocessing=1.webp new file mode 100644 index 000000000..9b67423fa Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+preprocessing=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+quality=64.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+quality=64.webp index 7deb31bc1..e69de29bb 100644 Binary files a/tests/python_tests/images/support/encoding-opts/blank-webp+quality=64.webp and b/tests/python_tests/images/support/encoding-opts/blank-webp+quality=64.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+segments=3.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+segments=3.webp new file mode 100644 index 000000000..fb77fc44b Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+segments=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+sns_strength=50.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+sns_strength=50.webp new file mode 100644 index 000000000..ce65bf5df Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+sns_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+target_PSNR=.5.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+target_PSNR=.5.webp new file mode 100644 index 000000000..4f7bac365 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+target_PSNR=.5.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/blank-webp+target_size=100.webp b/tests/python_tests/images/support/encoding-opts/blank-webp+target_size=100.webp new file mode 100644 index 000000000..4f7bac365 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/blank-webp+target_size=100.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_compression=0.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_compression=0.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_compression=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_filtering=2.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_filtering=2.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_filtering=2.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_quality=50.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_quality=50.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+alpha_quality=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+autofilter=0.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+autofilter=0.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+autofilter=0.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+filter_sharpness=4.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_sharpness=4.webp new file mode 100644 index 000000000..17980675f Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_sharpness=4.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+filter_strength=50.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_strength=50.webp new file mode 100644 index 000000000..9365bc639 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+filter_type=1+autofilter=1.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_type=1+autofilter=1.webp new file mode 100644 index 000000000..ccef4a3cb Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+filter_type=1+autofilter=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+partition_limit=50.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+partition_limit=50.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+partition_limit=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+partitions=3.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+partitions=3.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+partitions=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+pass=10.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+pass=10.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+pass=10.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+preprocessing=1.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+preprocessing=1.webp new file mode 100644 index 000000000..900c47758 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+preprocessing=1.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+segments=3.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+segments=3.webp new file mode 100644 index 000000000..79eb27a12 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+segments=3.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+sns_strength=50.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+sns_strength=50.webp new file mode 100644 index 000000000..4d683d309 Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+sns_strength=50.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+target_PSNR=.5.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+target_PSNR=.5.webp new file mode 100644 index 000000000..9f4750b4a Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+target_PSNR=.5.webp differ diff --git a/tests/python_tests/images/support/encoding-opts/solid-webp+target_size=100.webp b/tests/python_tests/images/support/encoding-opts/solid-webp+target_size=100.webp new file mode 100644 index 000000000..9f4750b4a Binary files /dev/null and b/tests/python_tests/images/support/encoding-opts/solid-webp+target_size=100.webp differ diff --git a/tests/python_tests/webp_encoding_test.py b/tests/python_tests/webp_encoding_test.py index 685ce461c..c512b1a71 100644 --- a/tests/python_tests/webp_encoding_test.py +++ b/tests/python_tests/webp_encoding_test.py @@ -20,7 +20,22 @@ if mapnik.has_webp(): opts = [ 'webp', 'webp:quality=64', - 'webp:alpha=false' + 'webp:alpha=false', + 'webp:partitions=3', + 'webp:preprocessing=1', + 'webp:partition_limit=50', + 'webp:pass=10', + 'webp:alpha_quality=50', + 'webp:alpha_filtering=2', + 'webp:alpha_compression=0', + 'webp:autofilter=0', + 'webp:filter_type=1:autofilter=1', + 'webp:filter_sharpness=4', + 'webp:filter_strength=50', + 'webp:sns_strength=50', + 'webp:segments=3', + 'webp:target_PSNR=.5', + 'webp:target_size=100' ]