maindecode.m

来自「压缩包中的内容用matlab语言对算术码进行描述」· M 代码 · 共 46 行

M
46
字号
%Arithmetic Coding Programme!
% This is the main program for decoding!
%Copy right of XUJIE 2008
%If you have any question,please contact me
%   xujie1984@gmail.com
%*******************************************
%The input file is test.txt.
%The main programme for encoding is mainencode.m!
%The main programme for decoding is maindecode.m!
%To caculate the compression ratio,you can run compressionratio.m!
%**************************************************************************
clear all
clear global
global prob no_of_symbols in_bit_file
% ---------------------------------------------------------------------------------------
K=16;
no_of_symbols=256;
output=[];
%Initialize prob!
prob=ones(1,no_of_symbols);
fid=fopen('test.txt','r');
while(1~=0)
    ch = fread(fid,1);
    if(feof(fid)),break;end
    i=ch;
    prob(i)=prob(i)+1;
end
%Start decoding!
OpenInputBitFile('compressed.txt');
initialize_arithmetic_decoder;
fid=fopen('decompressed.txt','w');
while(1~=0)
    symbol=decode_symbol(prob,no_of_symbols);
    if(feof(in_bit_file.file)),break;end
    ch=char(symbol);
    output=[output ch];
end
for ii=1:length(output)
    fprintf(fid,'%c',output(ii));
end
fclose(fid);
CloseInputBitFile;
disp('******************************');
disp('***DECOMPRESSING COMPLETE!****');
disp('******************************');

⌨️ 快捷键说明

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