[GRASS5] zlib compression for CELL maps

Glynn Clements glynn at gclements.plus.com
Fri Jan 13 20:23:11 EST 2006


Markus Neteler wrote:

> the ZLIB compression is broken in GRASS 6.
> Please don't use it.

Snip.

> At least small map are not handled correctly.

Aha!

Because the compressed data can be larger than the input data (which
would overflow the output buffer), zlib compression can fail. If this
happens, the uncompressed data is written instead.

If the code to read a row notices that the stored data takes up as
much space as an uncompressed row, it assumes that the data was
written uncompressed, and doesn't bother decompressing it.

get_row.c:read_data_compressed:

    if (fcb->cellhd.compressed < 0 || readamount < n * fcb->cellhd.cols)
    {
	if (fcb->cellhd.compressed == 2)
	    G_zlib_expand(cmp, readamount, data_buf, n * fcb->cellhd.cols);
	else
	    rle_decompress(data_buf, cmp, n, readamount);
    }
    else
	memcpy(data_buf, cmp, readamount);

What's happening for very small maps is that the zlib-compressed data
is the same size as the raw data. This causes the compressed data to
be written (as the compression succeeds), but the data is read as if
it was uncompressed.

Unfortunately, I'm a bit busy right now; if I don't report any progress
within the next few days, please remind me.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list