encode_symbol.m

来自「多值自适应算数编码」· M 代码 · 共 37 行

M
37
字号
function encode_symbol(symbol,cum_freq)

global top_value first_qtr half third_qtr high low bits_to_follow code_value_bits no_of_symbols no_of_chars

format long ;

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);
no_of_chars=256;
eof_symbol=no_of_chars+1;
no_of_symbols=no_of_chars+1;

range=fix(high-low)+1;
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
    if(high<half)
        bit_plus_follow(0);
    elseif (low>=half)
        bit_plus_follow(1);
        low=low-half;
        high=high-half;
    elseif (low>=first_qtr & high<third_qtr)
        bits_to_follow=bits_to_follow+1;
        low=low-first_qtr;
        high=high-first_qtr;
    else
        break;
    end
    low=fix(2*low);
    high=fix(2*high)+1;    
end

⌨️ 快捷键说明

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