rangecoder: K&R formatting cosmetics

This commit is contained in:
Diego Biurrun
2012-10-05 19:05:00 +02:00
parent ca411fc1d3
commit 90558e848a
2 changed files with 104 additions and 96 deletions

View File

@@ -37,26 +37,27 @@
#include "rangecoder.h"
#include "bytestream.h"
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size)
{
c->bytestream_start =
c->bytestream = buf;
c->bytestream_end = buf + buf_size;
c->low = 0;
c->range = 0xFF00;
c->outstanding_count = 0;
c->outstanding_byte = -1;
}
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size)
{
/* cast to avoid compiler warning */
ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
c->low = bytestream_get_be16(&c->bytestream);
}
void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
void ff_build_rac_states(RangeCoder *c, int factor, int max_p)
{
const int64_t one = 1LL << 32;
int64_t p;
int last_p8, p8, i;
@@ -67,8 +68,9 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
last_p8 = 0;
p = one / 2;
for (i = 0; i < 128; i++) {
p8= (256*p + one/2) >> 32; //FIXME try without the one
if(p8 <= last_p8) p8= last_p8+1;
p8 = (256 * p + one / 2) >> 32; // FIXME: try without the one
if (p8 <= last_p8)
p8 = last_p8 + 1;
if (last_p8 && last_p8 < 256 && p8 <= max_p)
c->one_state[last_p8] = p8;
@@ -82,9 +84,11 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
p = (i * one + 128) >> 8;
p += ((one - p) * factor + one / 2) >> 32;
p8= (256*p + one/2) >> 32; //FIXME try without the one
if(p8 <= i) p8= i+1;
if(p8 > max_p) p8= max_p;
p8 = (256 * p + one / 2) >> 32; // FIXME: try without the one
if (p8 <= i)
p8 = i + 1;
if (p8 > max_p)
p8 = max_p;
c->one_state[i] = p8;
}
@@ -92,11 +96,9 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
c->zero_state[i] = 256 - c->one_state[256 - i];
}
/**
*
* @return the number of bytes written
*/
int ff_rac_terminate(RangeCoder *c){
/* Return the number of bytes written. */
int ff_rac_terminate(RangeCoder *c)
{
c->range = 0xFF;
c->low += 0xFF;
renorm_encoder(c);
@@ -114,7 +116,8 @@ int ff_rac_terminate(RangeCoder *c){
#include "libavutil/lfg.h"
int main(void){
int main(void)
{
RangeCoder c;
uint8_t b[9 * SIZE];
uint8_t r[9 * SIZE];
@@ -129,9 +132,8 @@ int main(void){
memset(state, 128, sizeof(state));
for(i=0; i<SIZE; i++){
for (i = 0; i < SIZE; i++)
r[i] = av_lfg_get(&prng) % 7;
}
for (i = 0; i < SIZE; i++) {
START_TIMER

View File

@@ -29,6 +29,7 @@
#include <stdint.h>
#include <assert.h>
#include "libavutil/common.h"
typedef struct RangeCoder {
@@ -48,8 +49,9 @@ void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
int ff_rac_terminate(RangeCoder *c);
void ff_build_rac_states(RangeCoder *c, int factor, int max_p);
static inline void renorm_encoder(RangeCoder *c){
//FIXME optimize
static inline void renorm_encoder(RangeCoder *c)
{
// FIXME: optimize
while (c->range < 0x100) {
if (c->outstanding_byte < 0) {
c->outstanding_byte = c->low >> 8;
@@ -72,14 +74,16 @@ static inline void renorm_encoder(RangeCoder *c){
}
}
static inline int get_rac_count(RangeCoder *c){
static inline int get_rac_count(RangeCoder *c)
{
int x = c->bytestream - c->bytestream_start + c->outstanding_count;
if (c->outstanding_byte >= 0)
x++;
return 8 * x - av_log2(c->range);
}
static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){
static inline void put_rac(RangeCoder *c, uint8_t *const state, int bit)
{
int range1 = (c->range * (*state)) >> 8;
assert(*state);
@@ -97,7 +101,8 @@ static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){
renorm_encoder(c);
}
static inline void refill(RangeCoder *c){
static inline void refill(RangeCoder *c)
{
if (c->range < 0x100) {
c->range <<= 8;
c->low <<= 8;
@@ -107,7 +112,8 @@ static inline void refill(RangeCoder *c){
}
}
static inline int get_rac(RangeCoder *c, uint8_t * const state){
static inline int get_rac(RangeCoder *c, uint8_t *const state)
{
int range1 = (c->range * (*state)) >> 8;
int av_unused one_mask;