kutsurak / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

Support for interleaved exp-Golumb codes #104

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Interleaved exp-Golumb codes are variable length codes related to exp-Golumb 
codes. They have the exponent zeros interleaved with the code bits allowing the 
number to be read with a single loop and a shift register. Signed versions just 
have a sign bit appended to the end.

They are used in the Dirac video specification.

Attached is a patch which adds support for unsigned interleaved exp-golumb 
(uie) & signed interleaved exp-golumb (sie) types.

Example:

>>> import bitstring
>>> for x in xrange(10):
...     a = bitstring.ConstBitStream(uie=x)
...     b = a.read('uie')
...     print x,"=",a.bin,"=",b
... 
0 = 0b1 = 0
1 = 0b001 = 1
2 = 0b011 = 2
3 = 0b00001 = 3
4 = 0b00011 = 4
5 = 0b01001 = 5
6 = 0b01011 = 6
7 = 0b0000001 = 7
8 = 0b0000011 = 8
9 = 0b0001001 = 9

>>> for x in xrange(-10,10):
...     a = bitstring.ConstBitStream(sie=x)
...     b = a.read('sie')
...     print x,"=",a.bin,"=",b
... 
-10 = 0b00010111 = -10
-9 = 0b00010011 = -9
-8 = 0b00000111 = -8
-7 = 0b00000011 = -7
-6 = 0b010111 = -6
-5 = 0b010011 = -5
-4 = 0b000111 = -4
-3 = 0b000011 = -3
-2 = 0b0111 = -2
-1 = 0b0011 = -1
0 = 0b1 = 0
1 = 0b0010 = 1
2 = 0b0110 = 2
3 = 0b000010 = 3
4 = 0b000110 = 4
5 = 0b010010 = 5
6 = 0b010110 = 6
7 = 0b00000010 = 7
8 = 0b00000110 = 8
9 = 0b00010010 = 9

Original issue reported on code.google.com by psa...@gmail.com on 20 Feb 2011 at 11:59

Attachments:

GoogleCodeExporter commented 9 years ago
Hi, thanks for the feature request and the patch. I'm in two minds about it as 
I suspect that this is quite a niche feature (I can't find it anywhere except 
in Dirac) but on the other hand the patch does look thorough so it's relatively 
little work for me. (The ue and se decoding is also pretty niche but I was 
working on H.264 when I developed the module so they made sense to me!)

I'm going to target it for version 2.2, though it might get added as a hidden 
feature in 2.1.1 (due in the next week or so) and only become official in 2.2.

Cheers,

Scott

Original comment by dr.scott...@gmail.com on 21 Feb 2011 at 9:23

GoogleCodeExporter commented 9 years ago
I know. I've never seen it anywhere else, but you never know.

I debated writing it as an extension in my own code, but the code screamed for 
it to be put at that level. Once I'd done that it made sense to send it to you. 
Then I wouldn't have to keep my own version of the library. (I know... Purely 
selfish!)

I think I got all the hooks, but grepping for 'se' and 'ue' brings up a lot of 
spurious results. Apart from that I'm pretty confident with the patch.

Paul

Original comment by psa...@gmail.com on 21 Feb 2011 at 12:06

GoogleCodeExporter commented 9 years ago
This is now in as a hidden feature in 2.1.1 which has just been released.

OK, it's not that well hidden, but it's not in the release notes or manual 
(mainly because I can't be bothered to update the manual yet).

TODO: Update manual for 2.2.

Original comment by dr.scott...@gmail.com on 23 Feb 2011 at 12:15

GoogleCodeExporter commented 9 years ago
Done in 2.2.

Original comment by dr.scott...@gmail.com on 18 Jun 2011 at 6:12