Run-length Encoding
Algorithm
30311 송현식
30312 신석준
Why?
Just for fun.
RLE (Run-Length Encoding)
- Lossless Data Compression.
- Data are stored as a single data value and count.
- Using an ‘escape’ symbol to identify runs.
Huffman Coding
Run-length Encoding
Golomb Coding
LZW(Lempel-Ziv-Welch)
Lossless Data Compression
Lossless Versus Lossy
Lossless VS Lossy
Sentences, ... Audio, Picture, Video
What is RLE?
Before: HelloWorld!!!!!!!I’mAHuman.
After: HelloWorld*6!I’mAHuman.
HelloWorld*6!I’mAHuman.
Escape
Run times
Word
Codes
class RLEConverter(object):
def __init__(self, s):
self.s = s
def convert(self):
if len(self.s) < 2:
print("올바르지 않은 문자열입니다.")
return ""
else:
count = 1
previous_word = ''
result = ""
for character in self.s:
# 현재 가르키는 단어가 이전의 단어와 같지 않을 때
if character != previous_word:
# 이전의 단어가 존재 할때
if previous_word:
# 이전단어가 존재하지만 이전의 단어와 현재 가르키는 단어가 같지 않아 카운트가 1일때
if count == 1:
# 결과에 이전 단어를 추가
result += previous_word
# count가 1이 아닐 때, 즉 이전 단어와 현재 단어가 다르지만 이전에 같았으므로 카운트 추가
else:
# 결과에 형식을 맞춰 추가
result += ("*" + str(count) + previous_word)
count = 1
previous_word = character
else:
count += 1
else:
# 카운트가 1일때
if count == 1:
# 결과에 단어 추가
result += character
else:
# 결과에 형식을 맞춰 추가
result += ("*" + str(count) + character)
return result
if __name__ == "__main__":
s = input()
rleConverter = RLEConverter(s)
print(rleConverter.convert())
https://github.co
m/blogcin/RLECo
nverter
Principle
HelloWorld!!!!!!!I’mAHuman.
NowPrev
variables:
counter = 3
Prev = !
Now = !
Advantages
most useful on data that contains many such runs
Weakness
not useful with files that don’t have many runs as it could
greatly increase the file size
Case of Application, PCX(PiCture eXchange)
Starcraft
~ 1.16.1 version
PCX File Format
- 128 byte File header
- Image Data ( <- RLE Compressed )
- (Optional) 256-color palette
- Little Endian
Case of Application, RLE(file) and TGA (Truevision TGA)
Android boot logo
Android Boot Stage
- Bootloader Logo (tga, rle)
- Kernel Logo (rle)
- Android Init Logo (rle)
- BootAnimation (png)
RLE (file)
https://github.com/ashwinr64/
android_kernel_oneplus_onyx/bl
ob/cm-14.1/drivers/video/msm
/msm_fb.h#L254
Truevision TGA
https://github.com/littleke
rnel/lk/blob/master/lib/tg
a/tga.c#L180
End

Run-Length Encoding algorithm