abhijit mohanta Posted February 23, 2013 Posted February 23, 2013 Does anyone have a idea on how aplib algo works? This is a derivation of lz78 decompression.I want to know the meanings of the routines like getbit getgamma and how it is used to read the dictionary. Below is the code ==================aP_depack_asm: ; aP_depack_asm(const void *source, void *destination) _ret$ equ 7*4 _src$ equ 8*4 + 4 _dst$ equ 8*4 + 8 pushad mov esi, [esp + _src$] ; C calling convention mov edi, [esp + _dst$] cld mov dl, 80h xor ebx,ebxliteral: movsb mov bl, 2nexttag: call getbit jnc literal xor ecx, ecx call getbit jnc codepair xor eax, eax call getbit jnc shortmatch mov bl, 2 inc ecx mov al, 10h .getmorebits: call getbit adc al, al jnc .getmorebits jnz domatch stosb jmp nexttag codepair: call getgamma_no_ecx sub ecx, ebx jnz normalcodepair call getgamma jmp domatch_lastpos shortmatch: lodsb shr eax, 1 jz donedepacking adc ecx, ecx jmp domatch_with_2incnormalcodepair: xchg eax, ecx dec eax shl eax, 8 lodsb call getgamma cmp eax, 32000 jae domatch_with_2inc cmp ah, 5 jae domatch_with_inc cmp eax, 7fh ja domatch_new_lastposdomatch_with_2inc: inc ecxdomatch_with_inc: inc ecxdomatch_new_lastpos: xchg eax, ebpdomatch_lastpos: mov eax, ebp mov bl, 1domatch: push esi mov esi, edi sub esi, eax rep movsb pop esi jmp nexttaggetbit: add dl, dl jnz .stillbitsleft mov dl, [esi] inc esi adc dl, dl .stillbitsleft: retgetgamma: xor ecx, ecx getgamma_no_ecx: inc ecx .getgammaloop: call getbit adc ecx, ecx call getbit jc .getgammaloop retdonedepacking: sub edi, [esp + _dst$] mov [esp + _ret$], edi ; return unpacked length in eax popad ret
kao Posted February 23, 2013 Posted February 23, 2013 1) It's not a derivation of LZ78, but LZ77. 2) Once you understand the theory behind data compression, meanings of getbit() and getgamma() will be obvious to you. Check some tutorials or read "The Data Compression Book" (http://forum.eviloctal.com/attachment.php?aid=322 ).
abhijit mohanta Posted February 24, 2013 Author Posted February 24, 2013 1) It's not a derivation of LZ78, but LZ77. 2) Once you understand the theory behind data compression, meanings of getbit() and getgamma() will be obvious to you. Check some tutorials or read "The Data Compression Book" (http://forum.eviloctal.com/attachment.php?aid=322 ). Hi Kao, Can you give me some idea on this. I would help me learn a little faster. I went through lz77 and and some reading. Getbit seems to get a flag value from stream 0 or one according to which it is going to decide whether next bytes are literal or codeword(index,length) pair. What does the getgamma ,nexttag used for?
kao Posted February 24, 2013 Posted February 24, 2013 Look at APLib source in C - it's much more readable and has some comments. getgamma() decodes integer number. APLib uses simple compression scheme to store integers, similar to (but not the same as) http://en.wikipedia.org/wiki/Elias_gamma_coding . nexttag is just a label for a main loop.
abhijit mohanta Posted February 24, 2013 Author Posted February 24, 2013 Look at APLib source in C - it's much more readable and has some comments. getgamma() decodes integer number. APLib uses simple compression scheme to store integers, similar to (but not the same as) http://en.wikipedia.org/wiki/Elias_gamma_coding . nexttag is just a label for a main loop. thanks i ll find it out
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now