Add 'iqd' parameter to enable configuring of Floyd-Steinberg dithering in libimagequant. Also, rename iq= to iqs=
This commit is contained in:
parent
d9ba2d006e
commit
c30bb11c8b
2 changed files with 15 additions and 3 deletions
|
@ -58,6 +58,7 @@ struct png_options {
|
||||||
int strategy;
|
int strategy;
|
||||||
int trans_mode;
|
int trans_mode;
|
||||||
int iq_speed;
|
int iq_speed;
|
||||||
|
double iq_dither;
|
||||||
double gamma;
|
double gamma;
|
||||||
bool paletted;
|
bool paletted;
|
||||||
quantization_type quantization;
|
quantization_type quantization;
|
||||||
|
@ -68,6 +69,7 @@ struct png_options {
|
||||||
strategy(Z_DEFAULT_STRATEGY),
|
strategy(Z_DEFAULT_STRATEGY),
|
||||||
trans_mode(-1),
|
trans_mode(-1),
|
||||||
iq_speed(3),
|
iq_speed(3),
|
||||||
|
iq_dither(-1),
|
||||||
gamma(-1),
|
gamma(-1),
|
||||||
paletted(true),
|
paletted(true),
|
||||||
quantization(HEXTREE),
|
quantization(HEXTREE),
|
||||||
|
@ -740,6 +742,9 @@ void save_as_png8_libimagequant(T1 & file,
|
||||||
liq_result *res = liq_quantize_image(attr, liq_image);
|
liq_result *res = liq_quantize_image(attr, liq_image);
|
||||||
|
|
||||||
// Store palettized version
|
// Store palettized version
|
||||||
|
if (opts.iq_dither != -1) {
|
||||||
|
liq_set_dithering_level(res, opts.iq_dither);
|
||||||
|
}
|
||||||
image_gray8 reduced_image(width, height);
|
image_gray8 reduced_image(width, height);
|
||||||
liq_write_remapped_image(res, liq_image, (void *)reduced_image.data(), width*height*sizeof(gray8_t));
|
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);
|
const liq_palette *liq_pal = liq_get_palette(res);
|
||||||
|
|
|
@ -91,11 +91,18 @@ void handle_png_options(std::string const& type,
|
||||||
opts.quantization = png_options::IMGQUANT;
|
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")
|
else if (t == "e=miniz")
|
||||||
|
|
Loading…
Reference in a new issue