[GRASSLIST:4339] Re: PNG memory usage

Glynn Clements glynn.clements at virgin.net
Tue Aug 20 17:07:16 EDT 2002


cheg01 at attbi.com wrote:

> I'm trying to understand how the PNG driver uses memory. I would like to
> save full 10 meter resolution images of 1:100000 quads in truecolor. I have
> gd 2.0. I'm running Solaris 8 Sparc with 384 megs memory and 512 megs swap.
> 
> Environment variables:
> GRASS_TRUECOLOR=TRUE
> GRASS_HEIGHT=5714
> GRASS_WIDTH=7469
> export GRASS_TRUECOLOR GRASS_HEIGHT GRASS_WIDTH
> 
> The memory usage looks like this (from "top"):
> 
> d.mon start=PNG
> PNG Size: 165M / Resident: 664K
> 
> d.erase
> PNG Size: 165M / Resident: 164M
> 
> d.rast geol
> PNG Size: 182 M /Resident 181 M
> 
> d.mon stop=PNG
> PNG builds to Size: 346M /Resident  299M and holds for several minutes
> before dropping to zero.
> File map.png written to disk, 1.41 megs.
> 
> 
> The following series does not work:
> d.mon start=PNG
> PNG Size: 165M / Resident: 664K
> 
> d.erase
> PNG Size: 165M / Resident: 164M
> 
> d.his h_map=geol i_map=aspect
> PNG runs until 30% complete, then Size exceeds 880 megs
> ERROR: G_malloc: out of memory
> 
> Why does the PNG driver use > 300M of memory to create a < 2M file?
> 
> Why does d.his consume so much more memory than d.rast when both have the
> same number of pixels at the same color depth?
> (BTW: no memory problems occur with the monitor driver or CELL driver.)

Note that the size of the raw image is 5714 * 7469 * 4 ~= 162Mb (GD
uses the fourth byte for an alpha channel). PNG files are compressed
with zlib ("gzip" compression) by default, so the resulting file will
normally be much smaller than the raw image data.

However:

1. There is a memory leak in the PNG driver's polygon-drawing routine
(see src/display/devices/PNGdriver/Polygn_abs.c).

2. The PNG driver only implements the line and polygon primitives, and
uses the default implementations for everything else; i.e. a filled
rectangle is drawn as a filled polygon, and a raster is drawn as lots
of filled rectangles.

Point 1 needs to be fixed, and is straightforward. Point 2 ought to be
dealt with (i.e. the PNG driver should implement its own, efficient,
routines for rectangles and rasters), but it's probably too late to
change it for the 5.0.0 release.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-user mailing list