Merge commit '90558e848a29ef1e85ecb1832ad9a26eebe958e0'

* commit '90558e848a29ef1e85ecb1832ad9a26eebe958e0':
  rangecoder: K&R formatting cosmetics

Conflicts:
	libavcodec/rangecoder.c
	libavcodec/rangecoder.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2012-10-13 15:35:05 +02:00
2 changed files with 103 additions and 95 deletions

View File

@@ -38,26 +38,27 @@
#include "rangecoder.h" #include "rangecoder.h"
#include "bytestream.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_start =
c->bytestream = buf; c->bytestream = buf;
c->bytestream_end = buf + buf_size; c->bytestream_end = buf + buf_size;
c->low = 0; c->low = 0;
c->range = 0xFF00; c->range = 0xFF00;
c->outstanding_count = 0; c->outstanding_count = 0;
c->outstanding_byte = -1; 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 */ /* cast to avoid compiler warning */
ff_init_range_encoder(c, (uint8_t *)buf, buf_size); ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
c->low = bytestream_get_be16((const uint8_t **)&c->bytestream); c->low = bytestream_get_be16((const uint8_t **)&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; const int64_t one = 1LL << 32;
int64_t p; int64_t p;
int last_p8, p8, i; int last_p8, p8, i;
@@ -68,8 +69,9 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
last_p8 = 0; last_p8 = 0;
p = one / 2; p = one / 2;
for (i = 0; i < 128; i++) { for (i = 0; i < 128; i++) {
p8= (256*p + one/2) >> 32; //FIXME try without the one p8 = (256 * p + one / 2) >> 32; // FIXME: try without the one
if(p8 <= last_p8) p8= last_p8+1; if (p8 <= last_p8)
p8 = last_p8 + 1;
if (last_p8 && last_p8 < 256 && p8 <= max_p) if (last_p8 && last_p8 < 256 && p8 <= max_p)
c->one_state[last_p8] = p8; c->one_state[last_p8] = p8;
@@ -83,9 +85,11 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
p = (i * one + 128) >> 8; p = (i * one + 128) >> 8;
p += ((one - p) * factor + one / 2) >> 32; p += ((one - p) * factor + one / 2) >> 32;
p8= (256*p + one/2) >> 32; //FIXME try without the one p8 = (256 * p + one / 2) >> 32; // FIXME: try without the one
if(p8 <= i) p8= i+1; if (p8 <= i)
if(p8 > max_p) p8= max_p; p8 = i + 1;
if (p8 > max_p)
p8 = max_p;
c->one_state[i] = p8; c->one_state[i] = p8;
} }
@@ -93,11 +97,9 @@ void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
c->zero_state[i] = 256 - c->one_state[256 - i]; 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->range = 0xFF;
c->low += 0xFF; c->low += 0xFF;
renorm_encoder(c); renorm_encoder(c);
@@ -115,7 +117,8 @@ int ff_rac_terminate(RangeCoder *c){
#include "libavutil/lfg.h" #include "libavutil/lfg.h"
int main(void){ int main(void)
{
RangeCoder c; RangeCoder c;
uint8_t b[9 * SIZE]; uint8_t b[9 * SIZE];
uint8_t r[9 * SIZE]; uint8_t r[9 * SIZE];
@@ -130,9 +133,8 @@ int main(void){
memset(state, 128, sizeof(state)); memset(state, 128, sizeof(state));
for(i=0; i<SIZE; i++){ for (i = 0; i < SIZE; i++)
r[i] = av_lfg_get(&prng) % 7; r[i] = av_lfg_get(&prng) % 7;
}
for (i = 0; i < SIZE; i++) { for (i = 0; i < SIZE; i++) {
START_TIMER START_TIMER

View File

@@ -28,6 +28,7 @@
#define AVCODEC_RANGECODER_H #define AVCODEC_RANGECODER_H
#include <stdint.h> #include <stdint.h>
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
@@ -48,8 +49,9 @@ void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
int ff_rac_terminate(RangeCoder *c); int ff_rac_terminate(RangeCoder *c);
void ff_build_rac_states(RangeCoder *c, int factor, int max_p); void ff_build_rac_states(RangeCoder *c, int factor, int max_p);
static inline void renorm_encoder(RangeCoder *c){ static inline void renorm_encoder(RangeCoder *c)
//FIXME optimize {
// FIXME: optimize
while (c->range < 0x100) { while (c->range < 0x100) {
if (c->outstanding_byte < 0) { if (c->outstanding_byte < 0) {
c->outstanding_byte = c->low >> 8; 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; int x = c->bytestream - c->bytestream_start + c->outstanding_count;
if (c->outstanding_byte >= 0) if (c->outstanding_byte >= 0)
x++; x++;
return 8 * x - av_log2(c->range); 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; int range1 = (c->range * (*state)) >> 8;
av_assert2(*state); av_assert2(*state);
@@ -97,7 +101,8 @@ static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){
renorm_encoder(c); renorm_encoder(c);
} }
static inline void refill(RangeCoder *c){ static inline void refill(RangeCoder *c)
{
if (c->range < 0x100) { if (c->range < 0x100) {
c->range <<= 8; c->range <<= 8;
c->low <<= 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 range1 = (c->range * (*state)) >> 8;
int av_unused one_mask; int av_unused one_mask;