1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp8/encoder/boolhuff.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 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 : boolhuff.h 1.18 +* 1.19 +* Description : Bool Coder header file. 1.20 +* 1.21 +****************************************************************************/ 1.22 +#ifndef __INC_BOOLHUFF_H 1.23 +#define __INC_BOOLHUFF_H 1.24 + 1.25 +#include "vpx_ports/mem.h" 1.26 +#include "vpx/internal/vpx_codec_internal.h" 1.27 + 1.28 +typedef struct 1.29 +{ 1.30 + unsigned int lowvalue; 1.31 + unsigned int range; 1.32 + int count; 1.33 + unsigned int pos; 1.34 + unsigned char *buffer; 1.35 + unsigned char *buffer_end; 1.36 + struct vpx_internal_error_info *error; 1.37 + 1.38 + /* Variables used to track bit costs without outputing to the bitstream */ 1.39 + unsigned int measure_cost; 1.40 + unsigned long bit_counter; 1.41 +} BOOL_CODER; 1.42 + 1.43 +extern void vp8_start_encode(BOOL_CODER *bc, unsigned char *buffer, unsigned char *buffer_end); 1.44 + 1.45 +extern void vp8_encode_value(BOOL_CODER *br, int data, int bits); 1.46 +extern void vp8_stop_encode(BOOL_CODER *bc); 1.47 +extern const unsigned int vp8_prob_cost[256]; 1.48 + 1.49 + 1.50 +DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]); 1.51 + 1.52 +static int validate_buffer(const unsigned char *start, 1.53 + size_t len, 1.54 + const unsigned char *end, 1.55 + struct vpx_internal_error_info *error) 1.56 +{ 1.57 + if (start + len > start && start + len < end) 1.58 + return 1; 1.59 + else 1.60 + vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME, 1.61 + "Truncated packet or corrupt partition "); 1.62 + 1.63 + return 0; 1.64 +} 1.65 +static void vp8_encode_bool(BOOL_CODER *br, int bit, int probability) 1.66 +{ 1.67 + unsigned int split; 1.68 + int count = br->count; 1.69 + unsigned int range = br->range; 1.70 + unsigned int lowvalue = br->lowvalue; 1.71 + register unsigned int shift; 1.72 + 1.73 +#ifdef VP8_ENTROPY_STATS 1.74 +#if defined(SECTIONBITS_OUTPUT) 1.75 + 1.76 + if (bit) 1.77 + Sectionbits[active_section] += vp8_prob_cost[255-probability]; 1.78 + else 1.79 + Sectionbits[active_section] += vp8_prob_cost[probability]; 1.80 + 1.81 +#endif 1.82 +#endif 1.83 + 1.84 + split = 1 + (((range - 1) * probability) >> 8); 1.85 + 1.86 + range = split; 1.87 + 1.88 + if (bit) 1.89 + { 1.90 + lowvalue += split; 1.91 + range = br->range - split; 1.92 + } 1.93 + 1.94 + shift = vp8_norm[range]; 1.95 + 1.96 + range <<= shift; 1.97 + count += shift; 1.98 + 1.99 + if (count >= 0) 1.100 + { 1.101 + int offset = shift - count; 1.102 + 1.103 + if ((lowvalue << (offset - 1)) & 0x80000000) 1.104 + { 1.105 + int x = br->pos - 1; 1.106 + 1.107 + while (x >= 0 && br->buffer[x] == 0xff) 1.108 + { 1.109 + br->buffer[x] = (unsigned char)0; 1.110 + x--; 1.111 + } 1.112 + 1.113 + br->buffer[x] += 1; 1.114 + } 1.115 + 1.116 + validate_buffer(br->buffer + br->pos, 1, br->buffer_end, br->error); 1.117 + br->buffer[br->pos++] = (lowvalue >> (24 - offset)); 1.118 + 1.119 + lowvalue <<= offset; 1.120 + shift = count; 1.121 + lowvalue &= 0xffffff; 1.122 + count -= 8 ; 1.123 + } 1.124 + 1.125 + lowvalue <<= shift; 1.126 + br->count = count; 1.127 + br->lowvalue = lowvalue; 1.128 + br->range = range; 1.129 +} 1.130 + 1.131 +#endif