RLE Decompress
RLE (Run-length encoding) is a very simple form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. This is most useful on data that contains many such runs.
For RLE Compress algorithm click here.
Public Shared Sub Decompress(input As Byte(), output As Byte(), inputSize As UInteger)
Dim marker As Byte, symbol As Byte
Dim i As UInteger, inputPosition As UInteger, outputPosition As UInteger, count As UInteger
If inputSize < 1 Then
Return
End If
inputPosition = 0
marker = input(inputPosition)
inputPosition += 1
outputPosition = 0
Do
symbol = input(inputPosition)
inputPosition += 1
If symbol = marker Then
count = input(inputPosition)
inputPosition += 1
If count <= 2 Then
For i = 0 To count
output(outputPosition) = marker
outputPosition += 1
Next
Else
If Convert.ToBoolean(count And &H80) Then
count = ((count And &H7F) << 8) + input(inputPosition)
inputPosition += 1
End If
symbol = input(inputPosition)
inputPosition += 1
For i = 0 To count
output(outputPosition) = symbol
outputPosition += 1
Next
End If
Else
output(outputPosition) = symbol
outputPosition += 1
End If
Loop While inputPosition < inputSize
End Sub
Example
Dim decompressedData As Byte() = New Byte(originalDataSize - 1) {}
Decompress(compressedData, decompressedData, CUInt(compressedDataSize))