Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

SQ9MEV
Hi All

I spent last day struggling with crippled images produced by tilecache
run with mapscript Mapserver bindings. It was hard to find out what's
happening due to quite complicated toolchain (its all run via django).

The essence of my problem is standard PIL (1.1.7) which does not cope to
well with paletted PNG. Subimages cropped from metatile are crippled then.

I've found discussion about this issue:
<
http://osgeo-org.1803224.n2.nabble.com/Meta-Tiled-paletted-images-PIL-issue-td3848319.html 
 >

I didn't wanto to stay with 32 bit PNG nor turn metatiling off due to
edge effects. So... I've found this fork of PIL, which works well with
paleted PNG:

https://bitbucket.org/olt/pil-117-fastpng/

TileCache needs to be patched a little to make things cooperating well,
and it breaks Tilecache with standard PIL. pil-fastpng seems to be
incompatible with standard PIL.

Any better idea how to make things working as expected?


--
Bartek

_______________________________________________
Tilecache mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/tilecache

pil-fastpng.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

SQ9MEV
W dniu 18.11.2011 20:42, SQ9MEV pisze:

> and it breaks Tilecache with standard PIL. pil-fastpng seems to be
> incompatible with standard PIL.
My mistake.
As for now pil-fastpng seems to replace standard PIL without problem
(not tested!).

--
Bartek
_______________________________________________
Tilecache mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

SQ9MEV
In reply to this post by SQ9MEV
W dniu 18.11.2011 20:42, SQ9MEV pisze:

> https://bitbucket.org/olt/pil-117-fastpng/
>
> TileCache needs to be patched a little to make things cooperating well,
> and it breaks Tilecache with standard PIL. pil-fastpng seems to be
> incompatible with standard PIL.

I'm not mastermind in PNG and PIL, but standard PIL sets
Image.info['transparency'] as int, while pil-fastpng set is as string
representation of tRNS aligned to 256 positions with 0xff, this patch
makes deciosion how to save subimage on that ground.

Works well, and (hope) does not break standard PIL.

Anyway, there's at least one drawback of using paletted PNGs:
32bit RGBA PNG empty tile size is 334B while png8 "P" mode paletted PNG
is 1768B. It's obvoius, as in paletted mode PNG contians PLTE chunk
(768B in my case) and tRNS 256B, altogether 1KB i my case (isn't it
compressed?).

--
Bartek

_______________________________________________
Tilecache mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/tilecache

pil_fastpng.patch (994 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

Ivan Mincik
In reply to this post by SQ9MEV
Hi, all improvements for paletted PNGs (great work be Oliver
Tonnhofer) are now merged in development version of PIL.  As far as I
know, there is no better way how to work with paletted PNGs, than to
use latest dev PIL. To be safe, You can always build PIL-dev localy,
without installing and set python path for TileCache to use it.

Ivan
_______________________________________________
Tilecache mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

SQ9MEV
W dniu 20.11.2011 22:18, Ivan Mincik pisze:


> Tonnhofer) are now merged in development version of PIL.  As far as I
> know, there is no better way how to work with paletted PNGs, than to
> use latest dev PIL. To be safe, You can always build PIL-dev localy,

Works well with http://hg.effbot.org/pil-2009-raclette/overview which is
PIL-dev branch i thing, but Layers.py still needs to be patched (second
patch).

The reason is:
im = Image.open('static/tiles/facility/01/000/000/001/000/000/001.png')
im.info['transparency'].__class__
<type 'list'> # 256 ints

 >>> subimage = im.crop((2,2,254,254))
 >>> subimage
<PIL.Image._ImageCrop image mode=P size=252x252 at 0x93DADEC>
 >>> subimage.info
{} #info is empty, but saved PNG (transparency channel is saved)
Reopening subimage shows info with transparency.

In subimage saved with transparency set to im.info['transparency']
transparency is stripped, and subimage saved that way cannot be reopened:

   File "[...]/site-packages/PIL/Image.py", line 2006, in open
     raise DecodeError("cannot identify image file")
DecodeError: cannot identify image file
 >>> Image.open('static/saved_w_transparency.png')

Saying "transparency is stripped" i meen background of
saved_w_transparency.png is black - its obovoius looking at
  PngImageFile._save(), line 541 in PIL/PngImagePlugin.py pil-2009-raclette.

Pngcheck says both files are OK, but saved_w_transparency.png has all
0xff in tRNS. Strange, that saved_w_transparency.png


Its too much for me as for today, but i think TileCache needs some
improovement to work with paletted png8 with transparency, it can not
call save vith transparency, as it will be degraded do 0xff - in my case
resulting black background, which is ofcourse unacceptable.

--
Bartek
_______________________________________________
Tilecache mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/tilecache