Range coder algorithm details
- From: "Rasmus Møller" <gcomp.rasemil@xxxxxxxxxxxxxxx>
- Date: 22 Dec 2005 15:12:29 -0800
Hello to the group,
please comment if I have made any obvious error below.
I want to code a sequence of 1-bit flags.
Each flag has p in the range [1,255] (out of 256).
Initialization is L=0x00000000 and R=0x01000000
(24 bit range, 8 bit free for multiplication)
Coding each bit :
r = (R*p)>>8
if (bit) { R = r } else { L = L+r ; R = R-r }
When R < 256 /* flush and check for underflow */ {
H = L+R ;
M = ((L+H)>>1)) & 0x00FF0000 , output byte M>>16
if (L & 0x00FF0000)<>(H & 0x00FF0000) /*underflow*/ {
if (H-M) > (M-L) /*shrink upper*/ { L = M ; R = H-M }
else /*shrink to lower interval*/ { R = H-M }
}
L = (L & 0x0000FFFF) << 8
R = ((R & 0x0000FFFF) << 8) + 0x000000FF
}
Details about termination left out on purpose.
I am a little insecure about a few things:
- is it okay to start with R of 0x01000000 instead of 0x00FFFFFF
- is it okay to add FF to the range R after shifting left
- is it okay to always flush only once, as R >0 before R<<8
- when decoding, if the value is exactly equal to L+((R*p)>>8),
it belongs in upper interval (in this case value=false) doesn't it?
TIA and please be gentle
Rasmus
.
- Follow-Ups:
- Re: Range coder algorithm details
- From: cr88192
- Re: Range coder algorithm details
- Prev by Date: Re: Question about mmap wrt compressed files
- Next by Date: Re: Question about mmap wrt compressed files
- Previous by thread: Question about mmap wrt compressed files
- Next by thread: Re: Range coder algorithm details
- Index(es):
Relevant Pages
|
|