main_decode.m

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

M
58
字号
% Program main decode

clc
clear all
clear global
format long
% outarry=[];
global no_of_chars no_of_symbols cum_freq char_to_index bits_to_go low high top_value code_value_bits first_qtr third_qtr bits_to_go buffer fid max_frequency index_to_char symbol
% ---------------------------------------------------------------------------------------

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

% ---------------------------------------------------------------------------------------
% Read the input file from text.txt
choice=2;
output=[];
fid=fopen('compressed.txt','r');
fid2=fopen('decompressed.txt','w');

if (choice==1)
    start_model_fixed;
else 
    start_model_adaptive;
end

start_inputting_bits;
start_decoding;
while (1~=0)
    symbol=decode_symbol(cum_freq);
    if(feof(fid)),break;end
    ch=index_to_char(symbol);
    output=[output ch];
    
    if choice~=1
        update_model_adaptive(symbol);        
    end
    
end

for ii=1:length(output)
    fprintf(fid2,'%c',output(ii));   
    
 %   outarry=[outarry fid];
  
end

fclose(fid);
fclose(fid2);
%output
disp('COMPLETE Decompressing')

⌨️ 快捷键说明

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