hextree - avoid quantizing images with less than 3 pixels (hextree implementation requirement)
This commit is contained in:
parent
a4cd4821a0
commit
8db68fc5e3
1 changed files with 33 additions and 28 deletions
|
@ -654,40 +654,45 @@ void save_as_png8_hex(T1 & file,
|
||||||
{
|
{
|
||||||
unsigned width = image.width();
|
unsigned width = image.width();
|
||||||
unsigned height = image.height();
|
unsigned height = image.height();
|
||||||
|
if (width + height > 3) // at least 3 pixels (hextree implementation requirement)
|
||||||
// structure for color quantization
|
|
||||||
hextree<mapnik::rgba> tree(opts.colors);
|
|
||||||
if (opts.trans_mode >= 0)
|
|
||||||
{
|
{
|
||||||
tree.setTransMode(opts.trans_mode);
|
// structure for color quantization
|
||||||
}
|
hextree<mapnik::rgba> tree(opts.colors);
|
||||||
if (opts.gamma > 0)
|
if (opts.trans_mode >= 0)
|
||||||
{
|
|
||||||
tree.setGamma(opts.gamma);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned y = 0; y < height; ++y)
|
|
||||||
{
|
|
||||||
typename T2::pixel_type const * row = image.getRow(y);
|
|
||||||
for (unsigned x = 0; x < width; ++x)
|
|
||||||
{
|
{
|
||||||
unsigned val = row[x];
|
tree.setTransMode(opts.trans_mode);
|
||||||
tree.insert(mapnik::rgba(U2RED(val), U2GREEN(val), U2BLUE(val), U2ALPHA(val)));
|
}
|
||||||
|
if (opts.gamma > 0)
|
||||||
|
{
|
||||||
|
tree.setGamma(opts.gamma);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//transparency values per palette index
|
for (unsigned y = 0; y < height; ++y)
|
||||||
std::vector<mapnik::rgba> pal;
|
{
|
||||||
tree.create_palette(pal);
|
typename T2::pixel_type const * row = image.getRow(y);
|
||||||
std::vector<mapnik::rgb> palette;
|
for (unsigned x = 0; x < width; ++x)
|
||||||
std::vector<unsigned> alphaTable;
|
{
|
||||||
for (unsigned i=0; i<pal.size(); ++i)
|
unsigned val = row[x];
|
||||||
|
tree.insert(mapnik::rgba(U2RED(val), U2GREEN(val), U2BLUE(val), U2ALPHA(val)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//transparency values per palette index
|
||||||
|
std::vector<mapnik::rgba> pal;
|
||||||
|
tree.create_palette(pal);
|
||||||
|
std::vector<mapnik::rgb> palette;
|
||||||
|
std::vector<unsigned> alphaTable;
|
||||||
|
for (unsigned i=0; i<pal.size(); ++i)
|
||||||
|
{
|
||||||
|
palette.push_back(rgb(pal[i].r, pal[i].g, pal[i].b));
|
||||||
|
alphaTable.push_back(pal[i].a);
|
||||||
|
}
|
||||||
|
save_as_png8<T1, T2, hextree<mapnik::rgba> >(file, image, tree, palette, alphaTable, opts);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
palette.push_back(rgb(pal[i].r, pal[i].g, pal[i].b));
|
throw std::runtime_error("Can't quantize images with less than 3 pixels");
|
||||||
alphaTable.push_back(pal[i].a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
save_as_png8<T1, T2, hextree<mapnik::rgba> >(file, image, tree, palette, alphaTable, opts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
|
|
Loading…
Reference in a new issue