media/libvpx/vp9/encoder/vp9_boolhuff.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     3  *
     4  *  Use of this source code is governed by a BSD-style license
     5  *  that can be found in the LICENSE file in the root of the source
     6  *  tree. An additional intellectual property rights grant can be found
     7  *  in the file PATENTS.  All contributing project authors may
     8  *  be found in the AUTHORS file in the root of the source tree.
     9  */
    12 /****************************************************************************
    13 *
    14 *   Module Title :     vp9_boolhuff.h
    15 *
    16 *   Description  :     Bool Coder header file.
    17 *
    18 ****************************************************************************/
    19 #ifndef VP9_ENCODER_VP9_BOOLHUFF_H_
    20 #define VP9_ENCODER_VP9_BOOLHUFF_H_
    22 #include "vpx_ports/mem.h"
    24 typedef struct {
    25   unsigned int lowvalue;
    26   unsigned int range;
    27   unsigned int value;
    28   int count;
    29   unsigned int pos;
    30   uint8_t *buffer;
    32   // Variables used to track bit costs without outputing to the bitstream
    33   unsigned int  measure_cost;
    34   unsigned long bit_counter;
    35 } vp9_writer;
    37 extern const unsigned int vp9_prob_cost[256];
    39 void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
    40 void vp9_stop_encode(vp9_writer *bc);
    42 DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]);
    44 static void vp9_write(vp9_writer *br, int bit, int probability) {
    45   unsigned int split;
    46   int count = br->count;
    47   unsigned int range = br->range;
    48   unsigned int lowvalue = br->lowvalue;
    49   register unsigned int shift;
    51 #ifdef ENTROPY_STATS
    52 #if defined(SECTIONBITS_OUTPUT)
    54   if (bit)
    55     Sectionbits[active_section] += vp9_prob_cost[255 - probability];
    56   else
    57     Sectionbits[active_section] += vp9_prob_cost[probability];
    59 #endif
    60 #endif
    62   split = 1 + (((range - 1) * probability) >> 8);
    64   range = split;
    66   if (bit) {
    67     lowvalue += split;
    68     range = br->range - split;
    69   }
    71   shift = vp9_norm[range];
    73   range <<= shift;
    74   count += shift;
    76   if (count >= 0) {
    77     int offset = shift - count;
    79     if ((lowvalue << (offset - 1)) & 0x80000000) {
    80       int x = br->pos - 1;
    82       while (x >= 0 && br->buffer[x] == 0xff) {
    83         br->buffer[x] = 0;
    84         x--;
    85       }
    87       br->buffer[x] += 1;
    88     }
    90     br->buffer[br->pos++] = (lowvalue >> (24 - offset));
    91     lowvalue <<= offset;
    92     shift = count;
    93     lowvalue &= 0xffffff;
    94     count -= 8;
    95   }
    97   lowvalue <<= shift;
    98   br->count = count;
    99   br->lowvalue = lowvalue;
   100   br->range = range;
   101 }
   103 static void vp9_write_bit(vp9_writer *w, int bit) {
   104   vp9_write(w, bit, 128);  // vp9_prob_half
   105 }
   107 static void vp9_write_literal(vp9_writer *w, int data, int bits) {
   108   int bit;
   110   for (bit = bits - 1; bit >= 0; bit--)
   111     vp9_write_bit(w, 1 & (data >> bit));
   112 }
   115 #endif  // VP9_ENCODER_VP9_BOOLHUFF_H_

mercurial