2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
2012-11-27 22:59:17 +01:00
|
|
|
* Module Title : vp9_boolhuff.h
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
|
|
|
* Description : Bool Coder header file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-11-30 01:36:10 +01:00
|
|
|
#ifndef VP9_ENCODER_VP9_BOOLHUFF_H_
|
|
|
|
#define VP9_ENCODER_VP9_BOOLHUFF_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-07-19 15:17:25 +02:00
|
|
|
#include "vpx_ports/mem.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
typedef struct {
|
|
|
|
unsigned int lowvalue;
|
|
|
|
unsigned int range;
|
|
|
|
unsigned int value;
|
|
|
|
int count;
|
|
|
|
unsigned int pos;
|
2013-05-01 01:39:07 +02:00
|
|
|
uint8_t *buffer;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Variables used to track bit costs without outputing to the bitstream
|
|
|
|
unsigned int measure_cost;
|
|
|
|
unsigned long bit_counter;
|
2013-05-08 03:19:50 +02:00
|
|
|
} vp9_writer;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
extern const unsigned int vp9_prob_cost[256];
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-01 01:39:07 +02:00
|
|
|
void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
|
|
|
|
void vp9_stop_encode(vp9_writer *bc);
|
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]);
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2013-05-08 03:19:50 +02:00
|
|
|
static void vp9_write(vp9_writer *br, int bit, int probability) {
|
2012-07-14 00:21:29 +02:00
|
|
|
unsigned int split;
|
|
|
|
int count = br->count;
|
|
|
|
unsigned int range = br->range;
|
|
|
|
unsigned int lowvalue = br->lowvalue;
|
|
|
|
register unsigned int shift;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
|
|
|
#ifdef ENTROPY_STATS
|
|
|
|
#if defined(SECTIONBITS_OUTPUT)
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (bit)
|
2012-10-31 01:12:12 +01:00
|
|
|
Sectionbits[active_section] += vp9_prob_cost[255 - probability];
|
2012-07-14 00:21:29 +02:00
|
|
|
else
|
2012-10-31 01:12:12 +01:00
|
|
|
Sectionbits[active_section] += vp9_prob_cost[probability];
|
2011-07-19 15:17:25 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
split = 1 + (((range - 1) * probability) >> 8);
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
range = split;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (bit) {
|
|
|
|
lowvalue += split;
|
|
|
|
range = br->range - split;
|
|
|
|
}
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-10-31 01:12:12 +01:00
|
|
|
shift = vp9_norm[range];
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
range <<= shift;
|
|
|
|
count += shift;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (count >= 0) {
|
|
|
|
int offset = shift - count;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if ((lowvalue << (offset - 1)) & 0x80000000) {
|
|
|
|
int x = br->pos - 1;
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
while (x >= 0 && br->buffer[x] == 0xff) {
|
2013-05-01 01:39:07 +02:00
|
|
|
br->buffer[x] = 0;
|
2012-07-14 00:21:29 +02:00
|
|
|
x--;
|
|
|
|
}
|
2011-07-19 15:17:25 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
br->buffer[x] += 1;
|
2011-07-19 15:17:25 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
br->buffer[br->pos++] = (lowvalue >> (24 - offset));
|
|
|
|
lowvalue <<= offset;
|
|
|
|
shift = count;
|
|
|
|
lowvalue &= 0xffffff;
|
|
|
|
count -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
lowvalue <<= shift;
|
|
|
|
br->count = count;
|
|
|
|
br->lowvalue = lowvalue;
|
|
|
|
br->range = range;
|
2011-07-19 15:17:25 +02:00
|
|
|
}
|
|
|
|
|
2013-05-08 03:19:50 +02:00
|
|
|
static void vp9_write_bit(vp9_writer *w, int bit) {
|
|
|
|
vp9_write(w, bit, 128); // vp9_prob_half
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vp9_write_literal(vp9_writer *w, int data, int bits) {
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
for (bit = bits - 1; bit >= 0; bit--)
|
|
|
|
vp9_write_bit(w, 1 & (data >> bit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#endif // VP9_ENCODER_VP9_BOOLHUFF_H_
|