Skip to main content
gamedev.net
🔒 Locked

Compression Alg: Numbers

Started by FirstStrike 4 replies 1.1k views
Original Post
FirstStrike
FirstStrike
Hi ! I have a height map and want to store its values (Range from 0 - 255) in a file. Does anyone know a good algorithm which I could use to compress the resulting file size? Thx in advance
crucifer
crucifer
I have the same in my current game.

I am currently using hoffman. Chances are the terrain will be flat at a few places ... wich will allow the compression rate to go through the roof.

if 100% of you terrain is unbalanced, you will still be able to get a pretty decent compression rate.

In my case, I get a compression ratio varying from 25% to 95%.
crucifer
crucifer
You might want to go on sourgeforge.net
and make a search for "BCL" (basic compression library).

It includes 4 very easy to use compression algo.

They are already coded in C, wich makes it compatible/fast in almost any project.
FirstStrike
FirstStrike
Thx a lot. I will have a look at these.
Puppet
Puppet
You don't need to resort to advanced compression schemes either. It's pretty likely that the differences in height aren't too big in limited areas. If you split your map up into cells (a balance between memory usage and quality) and you store the lowest/base height in each cell. Then for each cell height element store off delta heights from that base height, using a few bits,. In case you want ~50% compression, you'd make each delta height 4 bits (probably the most practical to implement). It might also be good to store a scalar (say a bit shift value) per cell, in case a cell contains deltas bigger than 15. If this happens you will obviously get some aliasing "compression" artifacts and a less smooth cell, but it'll depend on your map data and the number of delta bits you are using. This is a simple and pretty fast way to save memory, whilst still having rather fast access to individual height data elements. I presume this is the reason why you'd want to compress the map data anyways, to save space in RAM. Hoffman and so on is more of a way to save HDD storage space. Although you could de-/compress cell areas using Hoffman as they are needed as well. You can still compress the cell delta data using Hoffman for disk storage if you want..
iMalc
iMalc
This is essentially the same thing are compressing a 2D bitmap which only has one colour channel. i.e. greyscale instead of height.
As such, an excellent algorithm would be some kind of wavelet compression as used in jpeg2000.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.