1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp8/decoder/dboolhuff.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 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 +#include "dboolhuff.h" 1.16 + 1.17 +int vp8dx_start_decode(BOOL_DECODER *br, 1.18 + const unsigned char *source, 1.19 + unsigned int source_sz, 1.20 + vp8_decrypt_cb *decrypt_cb, 1.21 + void *decrypt_state) 1.22 +{ 1.23 + br->user_buffer_end = source+source_sz; 1.24 + br->user_buffer = source; 1.25 + br->value = 0; 1.26 + br->count = -8; 1.27 + br->range = 255; 1.28 + br->decrypt_cb = decrypt_cb; 1.29 + br->decrypt_state = decrypt_state; 1.30 + 1.31 + if (source_sz && !source) 1.32 + return 1; 1.33 + 1.34 + /* Populate the buffer */ 1.35 + vp8dx_bool_decoder_fill(br); 1.36 + 1.37 + return 0; 1.38 +} 1.39 + 1.40 +void vp8dx_bool_decoder_fill(BOOL_DECODER *br) 1.41 +{ 1.42 + const unsigned char *bufptr = br->user_buffer; 1.43 + VP8_BD_VALUE value = br->value; 1.44 + int count = br->count; 1.45 + int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8); 1.46 + size_t bytes_left = br->user_buffer_end - bufptr; 1.47 + size_t bits_left = bytes_left * CHAR_BIT; 1.48 + int x = (int)(shift + CHAR_BIT - bits_left); 1.49 + int loop_end = 0; 1.50 + unsigned char decrypted[sizeof(VP8_BD_VALUE) + 1]; 1.51 + 1.52 + if (br->decrypt_cb) { 1.53 + size_t n = bytes_left > sizeof(decrypted) ? sizeof(decrypted) : bytes_left; 1.54 + br->decrypt_cb(br->decrypt_state, bufptr, decrypted, (int)n); 1.55 + bufptr = decrypted; 1.56 + } 1.57 + 1.58 + if(x >= 0) 1.59 + { 1.60 + count += VP8_LOTS_OF_BITS; 1.61 + loop_end = x; 1.62 + } 1.63 + 1.64 + if (x < 0 || bits_left) 1.65 + { 1.66 + while(shift >= loop_end) 1.67 + { 1.68 + count += CHAR_BIT; 1.69 + value |= (VP8_BD_VALUE)*bufptr << shift; 1.70 + ++bufptr; 1.71 + ++br->user_buffer; 1.72 + shift -= CHAR_BIT; 1.73 + } 1.74 + } 1.75 + 1.76 + br->value = value; 1.77 + br->count = count; 1.78 +}