Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
aom-rav1e
Commits
aea29cd2
Commit
aea29cd2
authored
Apr 30, 2013
by
Dmitry Kovalev
Browse files
General code cleanup inside treewriter-related files.
Change-Id: Ifaa40612a9c054d96112ba350c6f4adb46b1bd5b
parent
ad689031
Changes
5
Hide whitespace changes
Inline
Side-by-side
vp9/common/vp9_treecoder.c
View file @
aea29cd2
...
...
@@ -14,7 +14,6 @@
#if defined(CONFIG_DEBUG) && CONFIG_DEBUG
#include
<assert.h>
#endif
#include
<stdio.h>
#include
"vp9/common/vp9_treecoder.h"
...
...
@@ -57,12 +56,12 @@ static unsigned int convert_distribution(unsigned int i,
left
=
convert_distribution
(
tree
[
i
],
tree
,
probs
,
branch_ct
,
num_events
,
tok0_offset
);
}
if
(
tree
[
i
+
1
]
<=
0
)
{
if
(
tree
[
i
+
1
]
<=
0
)
right
=
num_events
[
-
tree
[
i
+
1
]
-
tok0_offset
];
}
else
{
else
right
=
convert_distribution
(
tree
[
i
+
1
],
tree
,
probs
,
branch_ct
,
num_events
,
tok0_offset
);
}
num_events
,
tok0_offset
);
probs
[
i
>>
1
]
=
get_binary_prob
(
left
,
right
);
branch_ct
[
i
>>
1
][
0
]
=
left
;
branch_ct
[
i
>>
1
][
1
]
=
right
;
...
...
vp9/encoder/vp9_boolhuff.c
View file @
aea29cd2
...
...
@@ -39,7 +39,7 @@ const unsigned int vp9_prob_cost[256] = {
22
,
21
,
19
,
18
,
16
,
15
,
13
,
12
,
10
,
9
,
7
,
6
,
4
,
3
,
1
,
1
};
void
vp9_start_encode
(
BOOL_CODER
*
br
,
unsigned
char
*
source
)
{
void
vp9_start_encode
(
vp9_writer
*
br
,
uint8_t
*
source
)
{
br
->
lowvalue
=
0
;
br
->
range
=
255
;
br
->
value
=
0
;
...
...
@@ -48,7 +48,7 @@ void vp9_start_encode(BOOL_CODER *br, unsigned char *source) {
br
->
pos
=
0
;
}
void
vp9_stop_encode
(
BOOL_CODER
*
br
)
{
void
vp9_stop_encode
(
vp9_writer
*
br
)
{
int
i
;
for
(
i
=
0
;
i
<
32
;
i
++
)
...
...
@@ -60,14 +60,14 @@ void vp9_stop_encode(BOOL_CODER *br) {
}
void
vp9_encode_value
(
BOOL_CODER
*
br
,
int
data
,
int
bits
)
{
void
vp9_encode_value
(
vp9_writer
*
br
,
int
data
,
int
bits
)
{
int
bit
;
for
(
bit
=
bits
-
1
;
bit
>=
0
;
bit
--
)
encode_bool
(
br
,
(
1
&
(
data
>>
bit
)),
0x80
);
}
void
vp9_encode_unsigned_max
(
BOOL_CODER
*
br
,
int
data
,
int
max
)
{
void
vp9_encode_unsigned_max
(
vp9_writer
*
br
,
int
data
,
int
max
)
{
assert
(
data
<=
max
);
while
(
max
)
{
encode_bool
(
br
,
data
&
1
,
128
);
...
...
@@ -92,7 +92,7 @@ static int get_unsigned_bits(unsigned num_values) {
return
cat
;
}
void
vp9_encode_uniform
(
BOOL_CODER
*
br
,
int
v
,
int
n
)
{
void
vp9_encode_uniform
(
vp9_writer
*
br
,
int
v
,
int
n
)
{
int
l
=
get_unsigned_bits
(
n
);
int
m
;
if
(
l
==
0
)
return
;
...
...
@@ -116,7 +116,7 @@ int vp9_count_uniform(int v, int n) {
return
l
;
}
void
vp9_encode_term_subexp
(
BOOL_CODER
*
br
,
int
word
,
int
k
,
int
num_syms
)
{
void
vp9_encode_term_subexp
(
vp9_writer
*
br
,
int
word
,
int
k
,
int
num_syms
)
{
int
i
=
0
;
int
mk
=
0
;
while
(
1
)
{
...
...
vp9/encoder/vp9_boolhuff.h
View file @
aea29cd2
...
...
@@ -27,30 +27,34 @@ typedef struct {
unsigned
int
value
;
int
count
;
unsigned
int
pos
;
u
nsigned
char
*
buffer
;
u
int8_t
*
buffer
;
// Variables used to track bit costs without outputing to the bitstream
unsigned
int
measure_cost
;
unsigned
long
bit_counter
;
}
BOOL_CODER
;
extern
void
vp9_start_encode
(
BOOL_CODER
*
bc
,
unsigned
char
*
buffer
)
;
typedef
BOOL_CODER
vp9_writer
;
extern
void
vp9_encode_value
(
BOOL_CODER
*
br
,
int
data
,
int
bits
);
extern
void
vp9_encode_unsigned_max
(
BOOL_CODER
*
br
,
int
data
,
int
max
);
extern
void
vp9_stop_encode
(
BOOL_CODER
*
bc
);
extern
const
unsigned
int
vp9_prob_cost
[
256
];
extern
void
vp9_encode_uniform
(
BOOL_CODER
*
bc
,
int
v
,
int
n
);
extern
void
vp9_encode_term_subexp
(
BOOL_CODER
*
bc
,
int
v
,
int
k
,
int
n
);
extern
int
vp9_count_uniform
(
int
v
,
int
n
);
extern
int
vp9_count_term_subexp
(
int
v
,
int
k
,
int
n
);
extern
int
vp9_recenter_nonneg
(
int
v
,
int
m
);
void
vp9_start_encode
(
vp9_writer
*
bc
,
uint8_t
*
buffer
);
void
vp9_encode_value
(
vp9_writer
*
br
,
int
data
,
int
bits
);
void
vp9_encode_unsigned_max
(
vp9_writer
*
br
,
int
data
,
int
max
);
void
vp9_stop_encode
(
vp9_writer
*
bc
);
void
vp9_encode_uniform
(
vp9_writer
*
bc
,
int
v
,
int
n
);
void
vp9_encode_term_subexp
(
vp9_writer
*
bc
,
int
v
,
int
k
,
int
n
);
int
vp9_count_uniform
(
int
v
,
int
n
);
int
vp9_count_term_subexp
(
int
v
,
int
k
,
int
n
);
int
vp9_recenter_nonneg
(
int
v
,
int
m
);
DECLARE_ALIGNED
(
16
,
extern
const
unsigned
char
,
vp9_norm
[
256
]);
static
void
encode_bool
(
BOOL_CODER
*
br
,
int
bit
,
int
probability
)
{
static
void
encode_bool
(
vp9_writer
*
br
,
int
bit
,
int
probability
)
{
unsigned
int
split
;
int
count
=
br
->
count
;
unsigned
int
range
=
br
->
range
;
...
...
@@ -89,7 +93,7 @@ static void encode_bool(BOOL_CODER *br, int bit, int probability) {
int
x
=
br
->
pos
-
1
;
while
(
x
>=
0
&&
br
->
buffer
[
x
]
==
0xff
)
{
br
->
buffer
[
x
]
=
(
unsigned
char
)
0
;
br
->
buffer
[
x
]
=
0
;
x
--
;
}
...
...
vp9/encoder/vp9_treewriter.c
View file @
aea29cd2
...
...
@@ -8,35 +8,31 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include
"vp9/encoder/vp9_treewriter.h"
#include
"vp9/common/vp9_common.h"
static
void
cost
(
int
*
const
C
,
vp9_tree
T
,
const
vp9_prob
*
const
P
,
int
i
,
int
c
)
{
const
vp9_prob
p
=
P
[
i
>>
1
];
static
void
cost
(
int
*
costs
,
vp9_tree
tree
,
const
vp9_prob
*
probs
,
int
i
,
int
c
)
{
const
vp9_prob
prob
=
probs
[
i
/
2
];
int
b
;
do
{
const
vp9_tree_index
j
=
T
[
i
]
;
const
int
d
=
c
+
vp9_cost_bit
(
p
,
i
&
1
)
;
for
(
b
=
0
;
b
<=
1
;
++
b
)
{
const
int
cc
=
c
+
vp9_cost_bit
(
prob
,
b
)
;
const
vp9_tree_index
ii
=
tree
[
i
+
b
]
;
if
(
j
<=
0
)
C
[
-
j
]
=
d
;
if
(
ii
<=
0
)
costs
[
-
ii
]
=
cc
;
else
cost
(
C
,
T
,
P
,
j
,
d
);
}
while
(
++
i
&
1
);
cost
(
costs
,
tree
,
probs
,
ii
,
cc
);
}
}
void
vp9_cost_tokens
(
int
*
c
,
const
vp9_prob
*
p
,
vp9_tree
t
)
{
cost
(
c
,
t
,
p
,
0
,
0
);
void
vp9_cost_tokens
(
int
*
costs
,
const
vp9_prob
*
probs
,
vp9_tree
tree
)
{
cost
(
costs
,
tree
,
probs
,
0
,
0
);
}
void
vp9_cost_tokens_skip
(
int
*
c
,
const
vp9_prob
*
p
,
vp9_tree
t
)
{
assert
(
t
[
1
]
>
0
&&
t
[
0
]
<=
0
);
c
[
-
t
[
0
]]
=
vp9_cost_bit
(
p
[
0
],
0
);
cost
(
c
,
t
,
p
,
2
,
0
);
void
vp9_cost_tokens_skip
(
int
*
costs
,
const
vp9_prob
*
probs
,
vp9_tree
tree
)
{
assert
(
tree
[
0
]
<=
0
&&
tree
[
1
]
>
0
);
costs
[
-
tree
[
0
]]
=
vp9_cost_bit
(
probs
[
0
],
0
);
cost
(
costs
,
tree
,
probs
,
2
,
0
);
}
vp9/encoder/vp9_treewriter.h
View file @
aea29cd2
...
...
@@ -19,8 +19,6 @@
#include
"vp9/encoder/vp9_boolhuff.h"
/* for now */
typedef
BOOL_CODER
vp9_writer
;
#define vp9_write encode_bool
#define vp9_write_literal vp9_encode_value
#define vp9_write_bit(w, v) vp9_write((w), (v), vp9_prob_half)
...
...
@@ -39,66 +37,53 @@ typedef BOOL_CODER vp9_writer;
/* Both of these return bits, not scaled bits. */
static
INLINE
unsigned
int
cost_branch256
(
const
unsigned
int
ct
[
2
],
vp9_prob
p
)
{
/* Imitate existing calculation */
return
ct
[
0
]
*
vp9_cost_zero
(
p
)
+
ct
[
1
]
*
vp9_cost_one
(
p
);
}
static
INLINE
unsigned
int
cost_branch
(
const
unsigned
int
ct
[
2
],
vp9_prob
p
)
{
/* Imitate existing calculation */
return
cost_branch256
(
ct
,
p
)
>>
8
;
}
/* Small functions to write explicit values and tokens, as well as
estimate their lengths. */
static
INLINE
void
treed_write
(
vp9_writer
*
const
w
,
vp9_tree
t
,
const
vp9_prob
*
const
p
,
int
v
,
/* number of bits in v, assumed nonzero */
int
n
)
{
static
INLINE
void
treed_write
(
vp9_writer
*
w
,
vp9_tree
tree
,
const
vp9_prob
*
probs
,
int
bits
,
int
len
)
{
vp9_tree_index
i
=
0
;
do
{
const
int
b
=
(
v
>>
--
n
)
&
1
;
vp9_write
(
w
,
b
,
p
[
i
>>
1
]);
i
=
t
[
i
+
b
];
}
while
(
n
);
const
int
b
it
=
(
bits
>>
--
le
n
)
&
1
;
vp9_write
(
w
,
b
it
,
p
robs
[
i
>>
1
]);
i
=
t
ree
[
i
+
b
it
];
}
while
(
le
n
);
}
static
INLINE
void
write_token
(
vp9_writer
*
w
,
vp9_tree
t
,
const
vp9_prob
*
p
,
const
struct
vp9_token
*
x
)
{
treed_write
(
w
,
t
,
p
,
x
->
value
,
x
->
len
);
static
INLINE
void
write_token
(
vp9_writer
*
w
,
vp9_tree
tree
,
const
vp9_prob
*
probs
,
const
struct
vp9_token
*
token
)
{
treed_write
(
w
,
tree
,
probs
,
token
->
value
,
token
->
len
);
}
static
INLINE
int
treed_cost
(
vp9_tree
t
,
const
vp9_prob
*
const
p
,
int
v
,
/* number of bits in v, assumed nonzero */
int
n
)
{
int
c
=
0
;
static
INLINE
int
treed_cost
(
vp9_tree
tree
,
const
vp9_prob
*
probs
,
int
bits
,
int
len
)
{
int
cost
=
0
;
vp9_tree_index
i
=
0
;
do
{
const
int
b
=
(
v
>>
--
n
)
&
1
;
c
+=
vp9_cost_bit
(
p
[
i
>>
1
],
b
);
i
=
t
[
i
+
b
];
}
while
(
n
);
const
int
b
it
=
(
bits
>>
--
le
n
)
&
1
;
c
ost
+=
vp9_cost_bit
(
p
robs
[
i
>>
1
],
b
it
);
i
=
t
ree
[
i
+
b
it
];
}
while
(
le
n
);
return
c
;
return
c
ost
;
}
static
INLINE
int
cost_token
(
vp9_tree
t
,
const
vp9_prob
*
p
,
const
struct
vp9_token
*
x
)
{
return
treed_cost
(
t
,
p
,
x
->
value
,
x
->
len
);
static
INLINE
int
cost_token
(
vp9_tree
t
ree
,
const
vp9_prob
*
p
robs
,
const
struct
vp9_token
*
token
)
{
return
treed_cost
(
t
ree
,
probs
,
token
->
value
,
token
->
len
);
}
/* Fill array of costs for all possible token values. */
void
vp9_cost_tokens
(
int
*
Costs
,
const
vp9_prob
*
,
vp9_tree
);
void
vp9_cost_tokens_skip
(
int
*
c
,
const
vp9_prob
*
p
,
vp9_tree
t
);
void
vp9_cost_tokens
(
int
*
costs
,
const
vp9_prob
*
probs
,
vp9_tree
tree
);
void
vp9_cost_tokens_skip
(
int
*
costs
,
const
vp9_prob
*
probs
,
vp9_tree
tree
);
#endif // VP9_ENCODER_VP9_TREEWRITER_H_
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment