lagarithrac.c
Go to the documentation of this file.
1 /*
2  * Lagarith range decoder
3  * Copyright (c) 2009 Nathan Caldwell <saintdev (at) gmail.com>
4  * Copyright (c) 2009 David Conrad
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * Lagarith range decoder
26  * @author Nathan Caldwell
27  * @author David Conrad
28  */
29 
30 #include "get_bits.h"
31 #include "lagarithrac.h"
32 
34 {
35  int i, j, left;
36 
37  /* According to reference decoder "1st byte is garbage",
38  * however, it gets skipped by the call to align_get_bits()
39  */
40  align_get_bits(gb);
41  left = get_bits_left(gb) >> 3;
42  l->bytestream_start =
43  l->bytestream = gb->buffer + get_bits_count(gb) / 8;
44  l->bytestream_end = l->bytestream_start + left;
45 
46  l->range = 0x80;
47  l->low = *l->bytestream >> 1;
48  l->hash_shift = FFMAX((int)l->scale - 8, 0);
49 
50  for (i = j = 0; i < 256; i++) {
51  unsigned r = i << l->hash_shift;
52  while (l->prob[j + 1] <= r)
53  j++;
54  l->range_hash[i] = j;
55  }
56 
57  /* Add conversion factor to hash_shift so we don't have to in lag_get_rac. */
58  l->hash_shift += 23;
59 }
void ff_lag_rac_init(lag_rac *l, GetBitContext *gb, int length)
Definition: lagarithrac.c:33
const uint8_t * buffer
Definition: get_bits.h:55
uint8_t range_hash[256]
Hash table mapping upper byte to approximate symbol.
Definition: lagarithrac.h:51
const uint8_t * bytestream_end
End position of input bytestream.
Definition: lagarithrac.h:48
Lagarith range decoder.
const uint8_t * bytestream_start
Start of input bytestream.
Definition: lagarithrac.h:46
unsigned scale
Number of bits of precision in range.
Definition: lagarithrac.h:43
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:193
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:557
const char * r
Definition: vf_curves.c:94
#define FFMAX(a, b)
Definition: common.h:56
uint32_t prob[258]
Table of cumulative probability for each symbol.
Definition: lagarithrac.h:50
synthesis window for stochastic i
unsigned hash_shift
Number of bits to shift to calculate hash for radix search.
Definition: lagarithrac.h:44
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:418
unsigned low
Definition: lagarithrac.h:41
unsigned range
Definition: lagarithrac.h:42
const char int length
Definition: avisynth_c.h:668
const uint8_t * bytestream
Current position in input bytestream.
Definition: lagarithrac.h:47