Search code examples
ccompressiondeltalossless

Compression Ratio Calculation in Delta Encoding


I am new to use Delta encoding to compress Hex data, I used the C implementation in wiki, so if my data is like 0xFFFFFFF,0xFFFFFFF,0xFFFFFFF,0xFFFFFFF,0xFFFFFFF the encoding result will be as follows : 0xFFFFFFF,0x0000000,0x0000000,0x0000000,0x0000000 , unlike rest of lossless algorithms which compression ratio = origial size / compressed size , i found that size of data will be fixed like before the compression, so how could i calculate compression ratio in delta encoding ? and how could i compress redundant delta ? The code is :

{
    unsigned char last = 0;
    for (int i = 0; i < length; i++)
    {
        unsigned char current = buffer[i];
        buffer[i] = current - last;
        last = current;
    }
}

void delta_decode(unsigned char *buffer, int length)
{
    unsigned char last = 0;
    for (int i = 0; i < length; i++)
    {
        unsigned char delta = buffer[i];
        buffer[i] = delta + last;
        last = buffer[i];
    }
} ```
 

Solution

  • Delta encoding is a step before compression that does not, itself, compress. It enables the subsequent compression. You should then take the result of delta encoding and feed it to a standard lossless compressor to see how much it compresses.

    Your question in the comments "but will Huffman or RLE work with Hex data in numeric format?" suggests some confusion on your part. The result of the delta encoding is the contents of the array in binary. Not the hexadecimal and text representation of that binary data.