Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garbled icons in png256 tiles #445

Closed
artemp opened this issue Oct 11, 2011 · 7 comments
Closed

Garbled icons in png256 tiles #445

artemp opened this issue Oct 11, 2011 · 7 comments
Milestone

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

I'm creating transparent tiles with a bunch of markers (PointSymbolizer) which I plan to overlay onto google maps. I'm using the generate_tiles.py script from osm, which by default creates 'png256' tiles. The icons are garbled. This doesn't happen with 'png' format.

I tried this on windows using latest mapnik 0.6.1 and imagemagick 6.5.6.8-Q8 binaries. I also tried on Debian following the DebianInstall instructions from the wiki to build from svn sources. I got the same results on both machines.

I'm attaching the files needed to reproduce this.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[altaurog] The icons are garbled even when the background is not transparent.

However I did successfully generate png256 tiles with the osm map including these icons, and they were not garbled.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[altaurog] I tried compressing the icons with pngnq to 8-bit palette mode before running through mapnik and got the same results.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] see also #447.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] images inlined:

[[BR]]
||[[Image(test-png256.png)]] || [[Image(test-png.png)]]||

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] see also #202

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[mar_rud] Cause of problem is reduce_4 function in png_io.hpp. When number of colors in computed palette is less then 16, more packed format is selected, that saves two pixels per byte bits are swapped up. Same goes for #447 where adding outline just increased number of colors, so reduce_8 was used instead.

Solution (against trunk):
{{{
--- include.old/mapnik/png_io.hpp 2009-12-30 21:31:50.589649710 +0100
+++ include/mapnik/png_io.hpp 2009-12-30 21:32:15.637646168 +0100
@@ -134,12 +134,12 @@
#ifdef MAPNIK_BIG_ENDIAN
mapnik::rgb c((val>>24)&0xff, (val>>16)&0xff, (val>>8) & 0xff);
byte index = tree.quantize(c);

  •        if (x%2 >  0) index = index<<4;
    
  •        if (x%2 == 0) index = index<<4;
         if (!(val&0x80)) index = 0;//alfa
    
    #else
    mapnik::rgb c((val)&0xff, (val>>8)&0xff, (val>>16) & 0xff);
    byte index = tree.quantize(c);
  •        if (x%2 >  0) index = index<<4;
    
  •        if (x%2 == 0) index = index<<4;
         if (!((val>>24)&0x80)) index = 0;//alfa
    
    #endif
    row_out[x>>1] |= index;
    }}}

Discovered it while trying to implement solution for semitransparent png256 support (#202).

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] great, thanks Marcin!, applied to the 0.7 branch in r1503 and trunk in r1504

@artemp artemp closed this as completed Oct 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant