line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::BitStream::Code::ExponentialGolomb; |
2
|
28
|
|
|
28
|
|
24118
|
use strict; |
|
28
|
|
|
|
|
59
|
|
|
28
|
|
|
|
|
1025
|
|
3
|
28
|
|
|
28
|
|
161
|
use warnings; |
|
28
|
|
|
|
|
59
|
|
|
28
|
|
|
|
|
1560
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
28
|
|
|
28
|
|
95
|
$Data::BitStream::Code::ExponentialGolomb::AUTHORITY = 'cpan:DANAJ'; |
6
|
28
|
|
|
|
|
2690
|
$Data::BitStream::Code::ExponentialGolomb::VERSION = '0.08'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $CODEINFO = { package => __PACKAGE__, |
10
|
|
|
|
|
|
|
name => 'ExpGolomb', |
11
|
|
|
|
|
|
|
universal => 1, |
12
|
|
|
|
|
|
|
params => 1, |
13
|
|
|
|
|
|
|
encodesub => sub {shift->put_expgolomb(@_)}, |
14
|
|
|
|
|
|
|
decodesub => sub {shift->get_expgolomb(@_)}, }; |
15
|
|
|
|
|
|
|
|
16
|
28
|
|
|
28
|
|
171
|
use Moo::Role; |
|
28
|
|
|
|
|
68
|
|
|
28
|
|
|
|
|
250
|
|
17
|
|
|
|
|
|
|
requires qw(put_rice put_gamma get_rice get_gamma); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Basic put implementation: |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# my $k = shift; |
22
|
|
|
|
|
|
|
# foreach my $val (@_) { |
23
|
|
|
|
|
|
|
# $self->put_gamma($val >> $k); |
24
|
|
|
|
|
|
|
# $self->write($k, $val); |
25
|
|
|
|
|
|
|
# } |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub put_expgolomb { |
29
|
822
|
|
|
822
|
1
|
31911
|
my $self = shift; |
30
|
822
|
|
|
3496
|
|
5290
|
$self->put_rice( sub { shift->put_gamma(@_); }, @_ ); |
|
3496
|
|
|
|
|
11403
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_expgolomb { |
34
|
846
|
|
|
846
|
1
|
11659
|
my $self = shift; |
35
|
846
|
|
|
3546
|
|
5919
|
$self->get_rice( sub { shift->get_gamma(@_); }, @_ ); |
|
3546
|
|
|
|
|
11591
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
28
|
|
|
28
|
|
18669
|
no Moo::Role; |
|
28
|
|
|
|
|
70
|
|
|
28
|
|
|
|
|
152
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# ABSTRACT: A Role implementing Exponential-Golomb codes |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Data::BitStream::Code::ExponentialGolomb - A Role implementing Exponential-Golomb codes |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 VERSION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
version 0.08 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
A role written for L that provides get and set methods for |
56
|
|
|
|
|
|
|
Exponential-Golomb codes. The role applies to a stream object. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Exponential-Golomb codes are Rice codes using an Elias Gamma code instead of |
59
|
|
|
|
|
|
|
a Unary code for the upper bits. Rice codes in turn are Golomb codes |
60
|
|
|
|
|
|
|
where the parameter m is a power of two. Hence: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Rice(k) ~ Golomb(2^k) |
63
|
|
|
|
|
|
|
ExponentialGolomb(k) ~ GammaGolomb(2^k) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 Provided Object Methods |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over 4 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item B< put_expgolomb($k, $value) > |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item B< put_expgolomb($k, @values) > |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Insert one or more values as Exponential-Golomb codes with parameter k. |
76
|
|
|
|
|
|
|
Returns 1. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item B< get_expgolomb($k) > |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item B< get_expgolomb($k, $count) > |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Decode one or more Exponential-Golomb codes from the stream. If count is |
83
|
|
|
|
|
|
|
omitted, one value will be read. If count is negative, values will be read |
84
|
|
|
|
|
|
|
until the end of the stream is reached. In scalar context it returns the |
85
|
|
|
|
|
|
|
last code read; in array context it returns an array of all codes read. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 Parameters |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The parameter C must be an integer greater than or equal to 0. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
The quotient CE k> is encoded using an Elias Gamma code, |
94
|
|
|
|
|
|
|
followed by the lowest C bits. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Note: if C then the result will be coded purely using gamma coding. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Note: this is a special case of a C code where C. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Required Methods |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item B< put_rice > |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item B< put_gamma > |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item B< get_rice > |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item B< get_gamma > |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
These methods are required for the role. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHORS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Dana Jacobsen |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright 2011 by Dana Jacobsen |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |