Comment 1 for bug 1803167

Revision history for this message
Selene ToyKeeper (toykeeper) wrote :

This is an interesting idea. I wonder if it should use run-length encoding to decrease the size even more. It's pretty simple to implement, and can compress any number of runs within each table.

The basic idea there is to use a special marker, a counter, and a value. Optionally, the marker and counter can be combined into a single byte, like how the PCX image format works.

For example, with a marker value of 254, the following table...

0, 0, 0, 0, 0, 0, 50, 100, 150, 250, 255, 255, 255, 255, 255, 255

... could be compressed to this:

254, 6, 0, 50, 100, 150, 250, 254, 6, 255

Each repetitive string takes 3 bytes instead of its original length. Or, using the PCX method, values from 192 to 255 act as both a marker and a counter, with a maximum count of 64. This can work, but then actual ramp values in that range require two bytes -- 192, then the original number.

  PWM2_LVL = RLE(pwm2_levels, level);

The downside is, while looking up values, it is necessary to iterate from the beginning of the table all the way to the requested index value. It could potentially turn a 10-instruction operation into ~450, in the worst case. But the code for this should be pretty small and simple, at least. And CPU cycles are not typically a bottleneck here.

Also, to keep the config files simple and straightforward, it might be nice to "compile" the config into a compressed form at compile time. I'm considering doing this in the build script.