1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/encoder/vp9_boolhuff.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +/**************************************************************************** 1.16 +* 1.17 +* Module Title : vp9_boolhuff.h 1.18 +* 1.19 +* Description : Bool Coder header file. 1.20 +* 1.21 +****************************************************************************/ 1.22 +#ifndef VP9_ENCODER_VP9_BOOLHUFF_H_ 1.23 +#define VP9_ENCODER_VP9_BOOLHUFF_H_ 1.24 + 1.25 +#include "vpx_ports/mem.h" 1.26 + 1.27 +typedef struct { 1.28 + unsigned int lowvalue; 1.29 + unsigned int range; 1.30 + unsigned int value; 1.31 + int count; 1.32 + unsigned int pos; 1.33 + uint8_t *buffer; 1.34 + 1.35 + // Variables used to track bit costs without outputing to the bitstream 1.36 + unsigned int measure_cost; 1.37 + unsigned long bit_counter; 1.38 +} vp9_writer; 1.39 + 1.40 +extern const unsigned int vp9_prob_cost[256]; 1.41 + 1.42 +void vp9_start_encode(vp9_writer *bc, uint8_t *buffer); 1.43 +void vp9_stop_encode(vp9_writer *bc); 1.44 + 1.45 +DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]); 1.46 + 1.47 +static void vp9_write(vp9_writer *br, int bit, int probability) { 1.48 + unsigned int split; 1.49 + int count = br->count; 1.50 + unsigned int range = br->range; 1.51 + unsigned int lowvalue = br->lowvalue; 1.52 + register unsigned int shift; 1.53 + 1.54 +#ifdef ENTROPY_STATS 1.55 +#if defined(SECTIONBITS_OUTPUT) 1.56 + 1.57 + if (bit) 1.58 + Sectionbits[active_section] += vp9_prob_cost[255 - probability]; 1.59 + else 1.60 + Sectionbits[active_section] += vp9_prob_cost[probability]; 1.61 + 1.62 +#endif 1.63 +#endif 1.64 + 1.65 + split = 1 + (((range - 1) * probability) >> 8); 1.66 + 1.67 + range = split; 1.68 + 1.69 + if (bit) { 1.70 + lowvalue += split; 1.71 + range = br->range - split; 1.72 + } 1.73 + 1.74 + shift = vp9_norm[range]; 1.75 + 1.76 + range <<= shift; 1.77 + count += shift; 1.78 + 1.79 + if (count >= 0) { 1.80 + int offset = shift - count; 1.81 + 1.82 + if ((lowvalue << (offset - 1)) & 0x80000000) { 1.83 + int x = br->pos - 1; 1.84 + 1.85 + while (x >= 0 && br->buffer[x] == 0xff) { 1.86 + br->buffer[x] = 0; 1.87 + x--; 1.88 + } 1.89 + 1.90 + br->buffer[x] += 1; 1.91 + } 1.92 + 1.93 + br->buffer[br->pos++] = (lowvalue >> (24 - offset)); 1.94 + lowvalue <<= offset; 1.95 + shift = count; 1.96 + lowvalue &= 0xffffff; 1.97 + count -= 8; 1.98 + } 1.99 + 1.100 + lowvalue <<= shift; 1.101 + br->count = count; 1.102 + br->lowvalue = lowvalue; 1.103 + br->range = range; 1.104 +} 1.105 + 1.106 +static void vp9_write_bit(vp9_writer *w, int bit) { 1.107 + vp9_write(w, bit, 128); // vp9_prob_half 1.108 +} 1.109 + 1.110 +static void vp9_write_literal(vp9_writer *w, int data, int bits) { 1.111 + int bit; 1.112 + 1.113 + for (bit = bits - 1; bit >= 0; bit--) 1.114 + vp9_write_bit(w, 1 & (data >> bit)); 1.115 +} 1.116 + 1.117 + 1.118 +#endif // VP9_ENCODER_VP9_BOOLHUFF_H_