News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

RLE - encoding/decoding program and source

Started by drarem, March 11, 2005, 07:09:58 PM

Previous topic - Next topic

gabor

Hi!

I'm still having problems with my encoder/decoder. I want to make it possible to adjust code word length and entry string length...
As soon as I'm finished, I post my code and test results.

Greets, Gábor

Tedd

The problem is that LZW is supposed to be streamed, so you have to decide on your codeword size beforehand because once you start writing the compressed data you can't go back and change it. If your dictionary gets full, then that's it, you just have to keep on munching and spit out 'badly' compressed data.

Of course, you could be unconventional and compress the whole file once - find out how many entries are required - and then recompress it with the appropriate 'optimal' codeword size.
No snowflake in an avalanche feels responsible.

gabor

Hi Dude!

Huhh, it took me lot of time till I understood what you have done there. Maybe I wasn't reading your post correctly, but I can't remember for that solution you applied. You use 2 byte long strings that's almost true: more precisely you use a hibrid - a directory index for the first characters and another for the last character. Why iddn't come this on MY mind! :)) I must bow before this thinking. And yes, when handling the entries this way, longer entries doesn't seem to have any effect...

After this I feel a bit ashamed for my solution, it is very slow, wastes memory and seems to be buggy as well...
What really knocked me off and turned me away of packing things was when tried to compress windows.inc with rar. The result was only 183kB and lasted a few seconds only. Well, there is still much work...

Greets, Gábor

Marko

Due too i am still learning ASM when i came to this thread i triedto give an implemetation of rle algo based on some document on the net.
When we encounter to simbols that are the same we write the pair and after count how many there are after and write this count so if we have a string like that:

aaaabcdeee
the output string will be
aa2bcdee1

The program actally still read from a static buffer ( i am going to make it read from a file oninput) and have still a problem (or maybe more than one :lol  i am still trying to enter in an asm mind) due too i write the occurence in a byte if a simbol appear more than 256 time this algo fail


include \masm32\include\masm32rt.inc

.data
szInput db "aaaaaaabcdfffffghilmooooppqr",0
OutBuffer db 128 dup(0ffh)

.code
start:

call main

exit

main PROC

lea esi, szInput
lea edi, OutBuffer
lodsw

the_loop:
test ah,ah
jz SHORT eos
test al,al
jz SHORT eos
cmp ah,al
je SHORT the_same

not_the_same:
stosb
dec esi
lodsw
jmp SHORT the_loop

the_same:
stosw
call ContaBytes
mov eax, ecx
stosb ;scrivi il risultato del conteggio della procedura nel buffer
dec esi
lodsw
jmp SHORT the_loop

eos:

ret

main endp


ContaBytes PROC
xor ecx,ecx

the_loop:
lodsb
cmp ah,al
jnz the_end
inc ecx
jmp SHORT the_loop

the_end:
ret
ContaBytes endp

end start


I am wrinting the decoder as i finished it i will post it up.

Any suggestions are welcome

Marko

Ps i dunno if anyone has done this type of implemetation because i dunno i can't access the code in this thread if anyone did forgive me