Implement runtime coding

I wrote a program to do run length coding. Typically, if the text

AAAAAABBCDEEEEGGHJ

run length will make it

A6B2C1D1E4G2H1J1

but he added an extra 1 for each non-repeating character. Since I am compressing BMP files with it, I went with the idea of ​​placing a “$” token to indicate the occurrence of a repeating character (assuming that the image files have a huge amount of repeating text).

So it will look like

$A6$B2CD$E4$G2HJ

In the current example, the length is the same, but there is a noticeable difference for BMP files. Now my problem is decryption. It so happened that some BMP files have an $<char><num>ie template $I9in the source file, so I would also contain the same text in the compressed file. $I9however, when decoding, it will consider it as a repeating I that repeats 9 times! Thus, it produces the wrong conclusion. I want to know which character I can use to mark the beginning of a repeating character (run) so that it does not contradict the original source.

+3
source share
6 answers

$ $$ ?

/ $ - , BMP.

, BMP RLE - , - " ".

, , , "" bmp, .

+6

AAAAAABBCDEEEEGGHJ $IIIIIIIII == > $A6 $B2CD $E4 $G2HJ $$ I9

, . , ,

$A6 $B2CD $E4 $G2HJ $$ I9 == > AAAAAABBCDEEEEGGHJ $IIIIIIIII

+2

, , - , , escape-.

, , :

^[].*+{}()$

, , .

, , , , , escape-. , $ $, , \$, escape-. (1)

\$. (2)

  • NB: grep .

  • $as $$ , $ BMP .

+1

, escape. , :

AAAABBCCCCDDEEEEEEEFFG

"G" escape- ( "H", ) , escape. , , , :

GGA4BBGC4DDGE7FFGG

:

HHA4BBHC4DDHE7FFG

, "" , "" (, HD2) (DD).

, !

+1

, , $ , "BMP"?

, , $('$$'), , "$" , "$" . , , , "$" ( 1), .

'$', : $$$ 5 - '$' '$$' = $, '5' - 5 .

0

, - RLE, . BMP .

, $ , ascii 0 9, 0 9, , 9 , . , $I34 34 $I3 + 4 4 3.

, 0 255, .

$, 1 ($$1) , , -, , $<length><data>; $0 "just $". 0 a $ . 0 , , , , , .

0

Source: https://habr.com/ru/post/1705392/


All Articles