media/libvpx/vp8/encoder/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 :     boolhuff.h
    15 *
    16 *   Description  :     Bool Coder header file.
    17 *
    18 ****************************************************************************/
    19 #ifndef __INC_BOOLHUFF_H
    20 #define __INC_BOOLHUFF_H
    22 #include "vpx_ports/mem.h"
    23 #include "vpx/internal/vpx_codec_internal.h"
    25 typedef struct
    26 {
    27     unsigned int lowvalue;
    28     unsigned int range;
    29     int count;
    30     unsigned int pos;
    31     unsigned char *buffer;
    32     unsigned char *buffer_end;
    33     struct vpx_internal_error_info *error;
    35     /* Variables used to track bit costs without outputing to the bitstream */
    36     unsigned int  measure_cost;
    37     unsigned long bit_counter;
    38 } BOOL_CODER;
    40 extern void vp8_start_encode(BOOL_CODER *bc, unsigned char *buffer, unsigned char *buffer_end);
    42 extern void vp8_encode_value(BOOL_CODER *br, int data, int bits);
    43 extern void vp8_stop_encode(BOOL_CODER *bc);
    44 extern const unsigned int vp8_prob_cost[256];
    47 DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
    49 static int validate_buffer(const unsigned char *start,
    50                            size_t               len,
    51                            const unsigned char *end,
    52                            struct vpx_internal_error_info *error)
    53 {
    54     if (start + len > start && start + len < end)
    55         return 1;
    56     else
    57         vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
    58             "Truncated packet or corrupt partition ");
    60     return 0;
    61 }
    62 static void vp8_encode_bool(BOOL_CODER *br, int bit, int probability)
    63 {
    64     unsigned int split;
    65     int count = br->count;
    66     unsigned int range = br->range;
    67     unsigned int lowvalue = br->lowvalue;
    68     register unsigned int shift;
    70 #ifdef VP8_ENTROPY_STATS
    71 #if defined(SECTIONBITS_OUTPUT)
    73     if (bit)
    74         Sectionbits[active_section] += vp8_prob_cost[255-probability];
    75     else
    76         Sectionbits[active_section] += vp8_prob_cost[probability];
    78 #endif
    79 #endif
    81     split = 1 + (((range - 1) * probability) >> 8);
    83     range = split;
    85     if (bit)
    86     {
    87         lowvalue += split;
    88         range = br->range - split;
    89     }
    91     shift = vp8_norm[range];
    93     range <<= shift;
    94     count += shift;
    96     if (count >= 0)
    97     {
    98         int offset = shift - count;
   100         if ((lowvalue << (offset - 1)) & 0x80000000)
   101         {
   102             int x = br->pos - 1;
   104             while (x >= 0 && br->buffer[x] == 0xff)
   105             {
   106                 br->buffer[x] = (unsigned char)0;
   107                 x--;
   108             }
   110             br->buffer[x] += 1;
   111         }
   113         validate_buffer(br->buffer + br->pos, 1, br->buffer_end, br->error);
   114         br->buffer[br->pos++] = (lowvalue >> (24 - offset));
   116         lowvalue <<= offset;
   117         shift = count;
   118         lowvalue &= 0xffffff;
   119         count -= 8 ;
   120     }
   122     lowvalue <<= shift;
   123     br->count = count;
   124     br->lowvalue = lowvalue;
   125     br->range = range;
   126 }
   128 #endif

mercurial