Recent

Author Topic: RLE: Run Length Encode Text Compression App (Simple)  (Read 698 times)

Boleeman

  • Sr. Member
  • ****
  • Posts: 253
RLE: Run Length Encode Text Compression App (Simple)
« on: September 20, 2023, 04:51:33 pm »
An RLE Text Compression sample program (originally listed by DreamVB)

Nice lossless text compression.


Bart

  • Hero Member
  • *****
  • Posts: 5137
    • Bart en Mariska's Webstek
Re: RLE: Run Length Encode Text Compression App (Simple)
« Reply #1 on: September 20, 2023, 05:55:34 pm »
For the average text RLE is not very suitable, since normal text doesn't have many repeating characters in it.
Since you put a number (at least 1 byte) in front of every token, it'll make the "compressed" text larger than the original.
This:
Code: [Select]
The quick brown fox jumps over the lazy dog.will be "compressed" into this:
Code: [Select]
1T1h1e1 1q1u1i1c1k1 1b1r1o1w1n1 1f1o1x1 1j1u1m1p1s1 1o1v1e1r1 1t1h1e1 1l1a1z1y1 1d1o1g1.
Also, your compression routine crashes if the input string is empty.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 5840
Re: RLE: Run Length Encode Text Compression App (Simple)
« Reply #2 on: September 20, 2023, 11:25:54 pm »
RLE is pretty much useless for text. In most cases, it will make the final bin larger.
The only true wisdom is knowing you know nothing

Boleeman

  • Sr. Member
  • ****
  • Posts: 253
Re: RLE: Run Length Encode Text Compression App (Simple)
« Reply #3 on: September 21, 2023, 12:01:55 am »
Just an example of how to collect and add up character tallies. Not meant to be a serious type of compression, although it is used in BMP images, where the pixels may repeat a bit more than in text.

The program does not crash when the 1st Memo is empty (as shown in the attached gif) when running on Windows10.

Would love to see a simple  example of RLE image compression for say a small Pixel editor.
« Last Edit: September 21, 2023, 12:11:21 am by Boleeman »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1719
  • Fifty shades of code.
    • Delphi & FreePascal
Re: RLE: Run Length Encode Text Compression App (Simple)
« Reply #4 on: September 21, 2023, 12:35:40 am »
compression in general should not lead to anything that you could display visual. (the "compressed" i mean)
just use binary and/or take a look at zLib for example. easy to handle, way better compressed.
so in your case it ends as bytes like "0x0130" (2 byteset that decode to 1x "0") while your current doing would be visual "10" and maybe it break at that point since "10" is a number and "accidently" decode to the next non-number like 10x "??????????"
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 5137
    • Bart en Mariska's Webstek
Re: RLE: Run Length Encode Text Compression App (Simple)
« Reply #5 on: September 21, 2023, 06:39:00 pm »
The program does not crash when the 1st Memo is empty (as shown in the attached gif) when running on Windows10.
I did not say that it does.
The compression routine will crash with an empty string.
You just don't call it when the memo is empty.
It's nevertheless a bug in the compression code.

Bart

 

TinyPortal © 2005-2018