Opened 16 years ago

Last modified 15 years ago

#2440 new enhancement

[PATCH] Improves raster 8-bit output rendering

Reported by: rouault Owned by: warmerdam
Priority: normal Milestone:
Component: MapServer C Library Version: unspecified
Severity: normal Keywords: raster 8-bit output
Cc: warmerdam

Description

Currently, 8-bit output rendering can lead to bad looking visual results when the WMS request matches several source raster products.

If there are 2 paletted source raster products, the palette of the first one is used to fill the output palette. When the second product is rendered, there's often not enough room for its colors and it is badly rendered.

If there are 2 24-bit source raster products, the color cube palette is used and leads to bad visual results with smoothly changing images. This can be improved with using DITHER=ON.

The attached patch adds a new processing option, "PALETTE_PRELOAD=ON", that greatly improves the rendering in the 2 above cases. It adds a function msPreallocateColorTable that is run before rendering layers. This function loops on all layers, and on all raster products in each layers that will be rendered and collects all the colors that are going to be used. Then it uses the algorithm taken from gdalmediancut.cpp to reduce the colors to 256 and allocate them to the output image. In the case of source 24-bit images, the function reads a text file that contains the optimal 8-bit palette for the 24-bit image. This text file is of the form :

R1 G1 B1
R2 G2 B2
...

This can be obtained in pre-processing by GDALComputeMedianCutPCT for example. Of course, for 24-bit input images, the use of "DITHER=ON" is highly encouraged in addition to the use of "PALETTE_PRELOAD=ON"

I'm also attaching a mapfile and a set of 24-bit images and their 8-bit reduced equivalent that demonstrate the improvements.

Attachments (6)

degrade.tar.gz (43.4 KB ) - added by rouault 16 years ago.
Set of input raster and mapfile to demonstrate the improvements of the patch
result_8bit_no_preload.gif (8.5 KB ) - added by rouault 16 years ago.
Output of 3 8-bit images, without the new option
result_8bit_preload.gif (9.5 KB ) - added by rouault 16 years ago.
Output of 3 8-bit images, with the new option
result_24bit_no_preload.gif (8.4 KB ) - added by rouault 16 years ago.
Output of 2 24-bit images, without the new option
result_24bit_preload.gif (8.8 KB ) - added by rouault 16 years ago.
Output of 2 24-bit images, with the new option
mapserver_svn_trunk_improves_8bit_output.patch (25.1 KB ) - added by rouault 16 years ago.

Download all attachments as: .zip

Change History (12)

by rouault, 16 years ago

Attachment: degrade.tar.gz added

Set of input raster and mapfile to demonstrate the improvements of the patch

by rouault, 16 years ago

Attachment: result_8bit_no_preload.gif added

Output of 3 8-bit images, without the new option

by rouault, 16 years ago

Attachment: result_8bit_preload.gif added

Output of 3 8-bit images, with the new option

by rouault, 16 years ago

Attachment: result_24bit_no_preload.gif added

Output of 2 24-bit images, without the new option

by rouault, 16 years ago

Attachment: result_24bit_preload.gif added

Output of 2 24-bit images, with the new option

comment:1 by rouault, 16 years ago

Type: defectenhancement

comment:2 by sdlime, 16 years ago

Cc: warmerdam added

comment:3 by sdlime, 16 years ago

Milestone: 5.2 release

comment:4 by sdlime, 16 years ago

Frank: Any feedback for this work?

Steve

comment:5 by sdlime, 16 years ago

Owner: changed from sdlime to warmerdam

Reassigning to warmerdam... (raster stuff is really his baby) I'd hate to see a contribution like this not make it in assuming it's a good idea.

Steve

comment:6 by warmerdam, 15 years ago

Milestone: 5.6 release
Note: See TracTickets for help on using tickets.