decode_symbol.m

来自「这是一个基于c++的算术编码源代码」· M 代码 · 共 40 行

M
40
字号
function symbol=decode_symbol(cum_freq)

global high low half first_qtr third_qtr value

format long
code_value_bits=16;
top_value=2^code_value_bits-1;
first_qtr=fix(top_value / 4) +1;
half=fix(2*first_qtr);
third_qtr=fix(3*first_qtr);


range=fix(high-low+1);
cum=fix((((value-low)+1)*cum_freq(1)-1)/range);
symbol=1;
while cum_freq(symbol)>cum
    symbol=symbol+1;  
end
xy=cum_freq(symbol-1);
yx=cum_freq(symbol);
high=low+fix(((range*xy)/cum_freq(1)))-1;
low=low+fix(((range*yx)/cum_freq(1)));
while(1~=0)
    if(high<half)
        % Nothing to be done        
    elseif (low>=half)
        value=value-half;
        low=low-half;
        high=high-half;
    elseif (low>=first_qtr & high<third_qtr)
        value=value-first_qtr;
        low=low-first_qtr;
        high=high-first_qtr;
    else
        break;
    end
    low=fix(2*low);
    high=fix(2*high)+1;
    value=2*value+input_bit;
end   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?