From 22ab62f16d29a3d157ff64ebfce0ae1f9e149623 Mon Sep 17 00:00:00 2001 From: Sara Metz Date: Fri, 30 Jan 2015 10:40:50 +1300 Subject: [PATCH] Fixes bugs that cause tests in PR #2599 to fail --- include/mapnik/hextree.hpp | 2 +- include/mapnik/png_io.hpp | 2 +- .../support/encoding-opts/png8-17cols.png | Bin 0 -> 192 bytes .../support/encoding-opts/png8-9cols.png | Bin 0 -> 171 bytes tests/python_tests/png_encoding_test.py | 36 ++++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/python_tests/images/support/encoding-opts/png8-17cols.png create mode 100644 tests/python_tests/images/support/encoding-opts/png8-9cols.png diff --git a/include/mapnik/hextree.hpp b/include/mapnik/hextree.hpp index 299945a11..1e04941fe 100644 --- a/include/mapnik/hextree.hpp +++ b/include/mapnik/hextree.hpp @@ -408,7 +408,7 @@ private: // clip extreme alfa values void create_palette_rek(std::vector & palette, node * itr) const { - if (itr->count >= 3) + if (itr->count != 0) { unsigned count = itr->count; byte a = byte(itr->alphas/float(count)); diff --git a/include/mapnik/png_io.hpp b/include/mapnik/png_io.hpp index 4e3a1fa46..b4f3f0de9 100644 --- a/include/mapnik/png_io.hpp +++ b/include/mapnik/png_io.hpp @@ -541,7 +541,7 @@ void save_as_png8_oct(T1 & file, trees[j].create_palette(pal); leftovers = cols[j] - static_cast(pal.size()); cols[j] = static_cast(pal.size()); - palette.insert(palette.begin(), pal.begin(), pal.end()); + palette.insert(palette.end(), pal.begin(), pal.end()); } } diff --git a/tests/python_tests/images/support/encoding-opts/png8-17cols.png b/tests/python_tests/images/support/encoding-opts/png8-17cols.png new file mode 100644 index 0000000000000000000000000000000000000000..22f4c35421c2cfe5744c8edd48d626d2c7b3d20a GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^+#t-s1|(OmDOUqhY)RhkE9i(`ny<+bNF@;WgJ9KMh)_CM*< zg*yx$6HZN?d&c2bVWwHd&(gD*C(Cwz`VoF;@6xhc_a6P!`^fl2NtAir+&Fch84RAT KelF{r5}E*`oHeEZ literal 0 HcmV?d00001 diff --git a/tests/python_tests/png_encoding_test.py b/tests/python_tests/png_encoding_test.py index 240459fc3..a38edb0b2 100644 --- a/tests/python_tests/png_encoding_test.py +++ b/tests/python_tests/png_encoding_test.py @@ -159,6 +159,42 @@ if mapnik.has_png(): eq_(len(im.tostring('png8:t=0')) == len(im_in.tostring('png8')), True) eq_(len(im.tostring('png8:t=0:m=o')) == len(im_in.tostring('png8:m=o')), True) + def test_9_colors_hextree(): + expected = './images/support/encoding-opts/png8-9cols.png' + im = mapnik.Image.open(expected) + t0 = tmp_dir + 'png-encoding-9-colors.result-hextree.png' + im.save(t0, 'png8:m=h') + eq_(mapnik.Image.open(t0).tostring(), + mapnik.Image.open(expected).tostring(), + '%s (actual) not == to %s (expected)' % (t0, expected)) + + def test_9_colors_octree(): + expected = './images/support/encoding-opts/png8-9cols.png' + im = mapnik.Image.open(expected) + t0 = tmp_dir + 'png-encoding-9-colors.result-octree.png' + im.save(t0, 'png8:m=o') + eq_(mapnik.Image.open(t0).tostring(), + mapnik.Image.open(expected).tostring(), + '%s (actual) not == to %s (expected)' % (t0, expected)) + + def test_17_colors_hextree(): + expected = './images/support/encoding-opts/png8-17cols.png' + im = mapnik.Image.open(expected) + t0 = tmp_dir + 'png-encoding-17-colors.result-hextree.png' + im.save(t0, 'png8:m=h') + eq_(mapnik.Image.open(t0).tostring(), + mapnik.Image.open(expected).tostring(), + '%s (actual) not == to %s (expected)' % (t0, expected)) + + def test_17_colors_octree(): + expected = './images/support/encoding-opts/png8-17cols.png' + im = mapnik.Image.open(expected) + t0 = tmp_dir + 'png-encoding-17-colors.result-octree.png' + im.save(t0, 'png8:m=o') + eq_(mapnik.Image.open(t0).tostring(), + mapnik.Image.open(expected).tostring(), + '%s (actual) not == to %s (expected)' % (t0, expected)) + def test_2px_regression_hextree(): im = mapnik.Image.open('./images/support/encoding-opts/png8-2px.A.png') expected = './images/support/encoding-opts/png8-2px.png'