media/libvpx/vp8/decoder/dboolhuff.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11
michael@0 12 #include "dboolhuff.h"
michael@0 13
michael@0 14 int vp8dx_start_decode(BOOL_DECODER *br,
michael@0 15 const unsigned char *source,
michael@0 16 unsigned int source_sz,
michael@0 17 vp8_decrypt_cb *decrypt_cb,
michael@0 18 void *decrypt_state)
michael@0 19 {
michael@0 20 br->user_buffer_end = source+source_sz;
michael@0 21 br->user_buffer = source;
michael@0 22 br->value = 0;
michael@0 23 br->count = -8;
michael@0 24 br->range = 255;
michael@0 25 br->decrypt_cb = decrypt_cb;
michael@0 26 br->decrypt_state = decrypt_state;
michael@0 27
michael@0 28 if (source_sz && !source)
michael@0 29 return 1;
michael@0 30
michael@0 31 /* Populate the buffer */
michael@0 32 vp8dx_bool_decoder_fill(br);
michael@0 33
michael@0 34 return 0;
michael@0 35 }
michael@0 36
michael@0 37 void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
michael@0 38 {
michael@0 39 const unsigned char *bufptr = br->user_buffer;
michael@0 40 VP8_BD_VALUE value = br->value;
michael@0 41 int count = br->count;
michael@0 42 int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8);
michael@0 43 size_t bytes_left = br->user_buffer_end - bufptr;
michael@0 44 size_t bits_left = bytes_left * CHAR_BIT;
michael@0 45 int x = (int)(shift + CHAR_BIT - bits_left);
michael@0 46 int loop_end = 0;
michael@0 47 unsigned char decrypted[sizeof(VP8_BD_VALUE) + 1];
michael@0 48
michael@0 49 if (br->decrypt_cb) {
michael@0 50 size_t n = bytes_left > sizeof(decrypted) ? sizeof(decrypted) : bytes_left;
michael@0 51 br->decrypt_cb(br->decrypt_state, bufptr, decrypted, (int)n);
michael@0 52 bufptr = decrypted;
michael@0 53 }
michael@0 54
michael@0 55 if(x >= 0)
michael@0 56 {
michael@0 57 count += VP8_LOTS_OF_BITS;
michael@0 58 loop_end = x;
michael@0 59 }
michael@0 60
michael@0 61 if (x < 0 || bits_left)
michael@0 62 {
michael@0 63 while(shift >= loop_end)
michael@0 64 {
michael@0 65 count += CHAR_BIT;
michael@0 66 value |= (VP8_BD_VALUE)*bufptr << shift;
michael@0 67 ++bufptr;
michael@0 68 ++br->user_buffer;
michael@0 69 shift -= CHAR_BIT;
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 br->value = value;
michael@0 74 br->count = count;
michael@0 75 }

mercurial