📄 golomb.h
字号:
/*
* exp golomb vlc stuff
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2004 Alex Beregszaszi
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* @file golomb.h
* @brief
* exp golomb vlc stuff
* @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
*/
#define INVALID_VLC 0x80000000
extern const uint8_t ff_golomb_vlc_len[512];
extern const uint8_t ff_ue_golomb_vlc_code[512];
extern const int8_t ff_se_golomb_vlc_code[512];
extern unsigned int g_buf;
/**
* read unsigned exp golomb code.
*/
#define GET_UE_GOLOMB(gb)\
{\
int log;\
\
OPEN_READER(re, gb);\
UPDATE_CACHE(re, gb);\
g_buf=GET_CACHE(re, gb);\
\
if(g_buf >= (1<<27))\
{\
g_buf >>= 32 - 9;\
LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[g_buf]);\
CLOSE_READER(re, gb);\
\
g_buf = ff_ue_golomb_vlc_code[g_buf];\
}\
else\
{\
log= 2*av_log2(g_buf) - 31;\
g_buf>>= log;\
g_buf--;\
LAST_SKIP_BITS(re, gb, 32 - log);\
CLOSE_READER(re, gb);\
}\
}
/**
* read unsigned truncated exp golomb code.
*/
static always_inline int get_te0_golomb(GetBitContext *gb, int range)
{
assert(range >= 1);
if(range==1) return 0;
else if(range==2) return get_bits1(gb)^1;
else
{
GET_UE_GOLOMB(gb);
return g_buf;
}
}
/**
* read signed exp golomb code.
*/
static always_inline int get_se_golomb(GetBitContext *gb)
{
unsigned int buf;
int log;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf=GET_CACHE(re, gb);
if(buf >= (1<<27)){
buf >>= 32 - 9;
LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
CLOSE_READER(re, gb);
return ff_se_golomb_vlc_code[buf];
}else{
log= (av_log2(buf)<<1) - 31;
buf>>= log;
LAST_SKIP_BITS(re, gb, 32 - log);
CLOSE_READER(re, gb);
if(buf&1) buf= -((int)(buf>>1));
else buf= (buf>>1);
return buf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -