bad quality with 8bit AGG PNG images and metaTile=true

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

bad quality with 8bit AGG PNG images and metaTile=true

Ivan Mincik
I am using UMN Mapserver WMS server version 5.2.1 which is rendering PNG images using AGG backend. They are reduced to 8bit.
When the Tilecache option "metaTile" is set to false, I have nice looking tiles. For the layers containing  labeIs I need to use option "metaTile=true".

Using the option "metaTile=true" for 8bit AGG PNG images gets visibly worse looking results. Can it be some problem with combination PIL and reduced 8bit images ?

Tilecache version is 2.03-1.

MapFile options are:

       OUTPUTFORMAT
                NAME "PNG_AGGAQ"
                DRIVER "AGG/PNG"
                MIMETYPE "image/png"
                IMAGEMODE RGBA
                FORMATOPTION "QUANTIZE_FORCE=ON"
                FORMATOPTION "QUANTIZE_DITHER=OFF"
                FORMATOPTION "QUANTIZE_COLORS=256"
                FORMATOPTION  "INTERLACE=OFF"
                TRANSPARENT ON
        END

Tilecache config:
[layername]
type=WMSLayer
url=http://server/cgi-bin/mapserv?map=map.map&transparent=true
layers=layername
extension=png
debug=on
metaTile=true
extent_type=loose
srs=EPSG:2065
bbox=-273393.437500, -1256155.375000, -255811.593750, -1227652.250000
resolutions=176.38879363894028529, 88.19439681947014265, 35.27775872778806132, 17.63887936389403066, 8.81943968194701533, 3.52777587277880578, 1.76388793638940289, 0.88194396819470144, 0.35277758727788061, 0.17638879363894031


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

Re: bad quality with 8bit AGG PNG images and metaTile=true

Guillaume Sueur-2
I would suggest you output 24bits PNG and have them reduced to 8bits
overnight with the excellent pngnq lib. (http://pngnq.sourceforge.net/)


Ivan Mincik a écrit :

> I am using UMN Mapserver WMS server version 5.2.1 which is rendering PNG images using AGG backend. They are reduced to 8bit.
> When the Tilecache option "metaTile" is set to false, I have nice looking tiles. For the layers containing  labeIs I need to use option "metaTile=true".
>
> Using the option "metaTile=true" for 8bit AGG PNG images gets visibly worse looking results. Can it be some problem with combination PIL and reduced 8bit images ?
>
> Tilecache version is 2.03-1.
>
> MapFile options are:
>
>        OUTPUTFORMAT
>                 NAME "PNG_AGGAQ"
>                 DRIVER "AGG/PNG"
>                 MIMETYPE "image/png"
>                 IMAGEMODE RGBA
>                 FORMATOPTION "QUANTIZE_FORCE=ON"
>                 FORMATOPTION "QUANTIZE_DITHER=OFF"
>                 FORMATOPTION "QUANTIZE_COLORS=256"
>                 FORMATOPTION  "INTERLACE=OFF"
>                 TRANSPARENT ON
>         END
>
> Tilecache config:
> [layername]
> type=WMSLayer
> url=http://server/cgi-bin/mapserv?map=map.map&transparent=true
> layers=layername
> extension=png
> debug=on
> metaTile=true
> extent_type=loose
> srs=EPSG:2065
> bbox=-273393.437500, -1256155.375000, -255811.593750, -1227652.250000
> resolutions=176.38879363894028529, 88.19439681947014265, 35.27775872778806132, 17.63887936389403066, 8.81943968194701533, 3.52777587277880578, 1.76388793638940289, 0.88194396819470144, 0.35277758727788061, 0.17638879363894031
>
>
> Thanks
> Ivan
> _______________________________________________
> Tilecache mailing list
> [hidden email]
> http://openlayers.org/mailman/listinfo/tilecache
>
>
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: bad quality with 8bit AGG PNG images and metaTile=true

Ivan Mincik
Thanks for the reply. Using the pngnq is second possibility.
The problem is that 95 % of layers does not contain labels, so I can
use native 8bit  Mapserver/Tilecache rendering. I would prefer if I
could use it for the rest 5 percent.
Do You thing that PIL can spoil the image when cutting it in to tails,
or can it be some problem with Tilecache ?

Ivan


On Thu, Mar 5, 2009 at 7:11 PM, Guillaume Sueur
<[hidden email]> wrote:

> I would suggest you output 24bits PNG and have them reduced to 8bits
> overnight with the excellent pngnq lib. (http://pngnq.sourceforge.net/)
>
>
> Ivan Mincik a écrit :
>> I am using UMN Mapserver WMS server version 5.2.1 which is rendering PNG images using AGG backend. They are reduced to 8bit.
>> When the Tilecache option "metaTile" is set to false, I have nice looking tiles. For the layers containing  labeIs I need to use option "metaTile=true".
>>
>> Using the option "metaTile=true" for 8bit AGG PNG images gets visibly worse looking results. Can it be some problem with combination PIL and reduced 8bit images ?
>>
>> Tilecache version is 2.03-1.
>>
>> MapFile options are:
>>
>>        OUTPUTFORMAT
>>                 NAME "PNG_AGGAQ"
>>                 DRIVER "AGG/PNG"
>>                 MIMETYPE "image/png"
>>                 IMAGEMODE RGBA
>>                 FORMATOPTION "QUANTIZE_FORCE=ON"
>>                 FORMATOPTION "QUANTIZE_DITHER=OFF"
>>                 FORMATOPTION "QUANTIZE_COLORS=256"
>>                 FORMATOPTION  "INTERLACE=OFF"
>>                 TRANSPARENT ON
>>         END
>>
>> Tilecache config:
>> [layername]
>> type=WMSLayer
>> url=http://server/cgi-bin/mapserv?map=map.map&transparent=true
>> layers=layername
>> extension=png
>> debug=on
>> metaTile=true
>> extent_type=loose
>> srs=EPSG:2065
>> bbox=-273393.437500, -1256155.375000, -255811.593750, -1227652.250000
>> resolutions=176.38879363894028529, 88.19439681947014265, 35.27775872778806132, 17.63887936389403066, 8.81943968194701533, 3.52777587277880578, 1.76388793638940289, 0.88194396819470144, 0.35277758727788061, 0.17638879363894031
>>
>>
>> Thanks
>> Ivan
>> _______________________________________________
>> Tilecache mailing list
>> [hidden email]
>> http://openlayers.org/mailman/listinfo/tilecache
>>
>>
>
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: bad quality with 8bit AGG PNG images and metaTile=true

Gregor at HostGIS
In reply to this post by Guillaume Sueur-2
Guillaume Sueur wrote:
> I would suggest you output 24bits PNG and have them reduced to 8bits
> overnight with the excellent pngnq lib. (http://pngnq.sourceforge.net/)

We do similar, and we call it "reducing" the tiles. We generate them at
24 because it looks great, then run ImageMagick's convert to scale them
down to 8. No visible loss of quality, but a 40% reduction in file size
and therefore download time.

--
Gregor Mosheh / Greg Allensworth    BS, A+, Network+, Security+, Server+
System Administrator, Lead Programmer
HostGIS development & hosting services, http://www.HostGIS.com/

"Remember that no one cares if you can back up,
  only if you can restore." - AMANDA
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: bad quality with 8bit AGG PNG images and metaTile=true

Gregor at HostGIS
Gregor at HostGIS wrote:
> run ImageMagick's convert to scale them down to 8

How rude of me to share the idea but not be specific. :)

# watch that linewrap; there's only 1 line here
find /tmp/tilecache/parks_and_forests -name '*.png' -ls -exec convert
-depth 8 -colors 256 {} {} \;

Note that it can take a long time for large datasets. You may want to
run this in "screen" or take some other measure to prevent it from
stopping if you get disconnected.

--
Gregor Mosheh / Greg Allensworth    BS, A+, Network+, Security+, Server+
System Administrator, Lead Programmer
HostGIS development & hosting services, http://www.HostGIS.com/

"Remember that no one cares if you can back up,
  only if you can restore." - AMANDA
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: bad quality with 8bit AGG PNG images and metaTile=true

Mark Deneen-2
Gregor at HostGIS wrote:

> > Gregor at HostGIS wrote:
> >  
>  
>> >> run ImageMagick's convert to scale them down to 8
>> >>    
>>    
> >
> > How rude of me to share the idea but not be specific.  :)
> >
> > # watch that linewrap; there's only 1 line here
> > find /tmp/tilecache/parks_and_forests -name '*.png' -ls -exec convert
> > -depth 8 -colors 256 {} {} \;
> >
> > Note that it can take a long time for large datasets. You may want to
> > run this in "screen" or take some other measure to prevent it from
> > stopping if you get disconnected.
> >
> >  
>  
I do something similar, but using mod_wsgi, python and PythonMagick.

#!/usr/local/bin/python2.6

import PythonMagick
import urllib

def application(environ, start_response):
        status = '200 OK'
        query = environ["REQUEST_URI"][9:]
        data =
urllib.urlopen("<a href="http://www.example.com/cgi-bin/mapserv.fcgi?%s">http://www.example.com/cgi-bin/mapserv.fcgi?%s" %query)
        blob = PythonMagick.Blob(data.read())
        image = PythonMagick.Image(blob)
        image.quantizeColors(64)
        image.quantizeDither(False)
        image.quantize()
        image.write(blob)
        response_headers = [('Content-type', 'image/png'),
('Content-Length', str(blob.length()))]
        start_response(status, response_headers)
        return [blob.data]



We've found that 64 colors looks good for our data set.  It results in
much smaller png files.  The downside to this approach is that it
happens as the requests come in, so you have to have the CPU available
to handle the load.  mod_wsgi throttles this, os the server doesn't get
overwhelmed. The advantage it has over Gregor's solution is that it does
it on the fly.  Searching through the cache directory and converting the
images might corrupt an image if it is being written by tilecache as
convert converts it.  You can get around this by making sure that the
file has a time stamp of a certain age.

The final downside is that PythonMagick is a major pain in the ass to
build.  The dependencies are a bit crazy.   :-)

Mark


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

Re: bad quality with 8bit AGG PNG images and metaTile=true

papley
This post has NOT been accepted by the mailing list yet.
In reply to this post by Ivan Mincik
We made some effort to use 8bit PNG output, but also found the quality badly quantized in color space. It seemed to me that the color map might be selected for the entire map, rather than allowing 256 colors for each individual png image. Does anyone know if this is true? In any case we find that ImageMagick compression from 24bit PNG to JPG works well, but the process of writing the 24bit PNGs is so slowwwww. It takes us 60 hours to convert a single mapserver layer to 160,000 256x256 images. The compression step with GM takes  a few hours on top of that.

The core step where all the time is going in python mapscript looks like this:

    myMap.setExtent(minx, miny, maxx, maxy)
    mapImg = myMap.draw()
    mapImg.save(fileName + '.' + mapImg.format.extension)

Other than employing a cloud array, there must be a better way (such as figuring out how to make Mapscript write compressed images directly with a reasonable color map).

The fact that we have about 10 layers defined in our mapfile, with all but one with STATUS off, wouldn't be slowing us down a lot, would it?

Any ideas?