CI130X SDK API手册  2.2.0
本手册用于描述CI130X SDK各个组件和驱动API
golomb.h
浏览该文件的文档.
1 /*
2  * exp golomb vlc stuff
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4  * Copyright (c) 2004 Alex Beregszaszi
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include <limits.h>
23 #include "bitstreamf.h"
24 
25 /* From libavutil/common.h */
26 extern const uint8_t ff_log2_tab[256];
27 
28 __STATIC_INLINE int av_log2(unsigned int v)
29 {
30  int n;
31 
32  n = 0;
33  if (v & 0xffff0000) {
34  v >>= 16;
35  n += 16;
36  }
37  if (v & 0xff00) {
38  v >>= 8;
39  n += 8;
40  }
41  n += ff_log2_tab[v];
42 
43  return n;
44 }
45 
57 __STATIC_INLINE int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){
58  unsigned int buf;
59  int log;
60 
61  OPEN_READER(re, gb);
62  UPDATE_CACHE(re, gb);
63  buf=GET_CACHE(re, gb);
64 
65  log= av_log2(buf);
66 
67  if(log > 31-11){
68  buf >>= log - k;
69  buf += (30-log)<<k;
70  LAST_SKIP_BITS(re, gb, 32 + k - log);
71  CLOSE_READER(re, gb);
72 
73  return buf;
74  }else{
75  int i;
76  for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){
77  LAST_SKIP_BITS(re, gb, 1);
78  UPDATE_CACHE(re, gb);
79  }
80  SKIP_BITS(re, gb, 1);
81 
82  if(i < limit - 1){
83  if(k){
84  buf = SHOW_UBITS(re, gb, k);
85  LAST_SKIP_BITS(re, gb, k);
86  }else{
87  buf=0;
88  }
89 
90  CLOSE_READER(re, gb);
91  return buf + (i<<k);
92  }else if(i == limit - 1){
93  buf = SHOW_UBITS(re, gb, esc_len);
94  LAST_SKIP_BITS(re, gb, esc_len);
95  CLOSE_READER(re, gb);
96 
97  return buf + 1;
98  }else
99  return -1;
100  }
101 }
102 
106 __STATIC_INLINE int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){
107  int v= get_ur_golomb_jpegls(gb, k, limit, esc_len);
108  return (v>>1) ^ -(v&1);
109 }
110 
114 #define get_ur_golomb_shorten(gb, k) get_ur_golomb_jpegls(gb, k, INT_MAX, 0)
115 /*
116 __STATIC_INLINE unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){
117  return get_ur_golomb_jpegls(gb, k, INT_MAX, 0);
118 }
119 */
120 
125 {
126  int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0);
127  if (uvar & 1)
128  return ~(uvar >> 1);
129  else
130  return uvar >> 1;
131 }
static int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len)
Definition: golomb.h:106
const uint8_t ff_log2_tab[256]
Definition: tables.c:4
#define SKIP_BITS(name, gb, num)
Definition: bitstreamf.h:177
#define LAST_SKIP_BITS(name, gb, num)
Definition: bitstreamf.h:183
static int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len)
Definition: golomb.h:57
#define GET_CACHE(name, gb)
Definition: bitstreamf.h:192
#define SHOW_UBITS(name, gb, num)
Definition: bitstreamf.h:186
Definition: bitstreamf.h:71
#define OPEN_READER(name, gb)
Definition: bitstreamf.h:159
static int av_log2(unsigned int v)
Definition: golomb.h:28
#define __STATIC_INLINE
Definition: bitstreamf.h:16
#define UPDATE_CACHE(name, gb)
Definition: bitstreamf.h:166
#define CLOSE_READER(name, gb)
Definition: bitstreamf.h:163
static int get_sr_golomb_shorten(GetBitContext *gb, int k)
Definition: golomb.h:124