📄 mainencode.m
字号:
%Arithmetic Coding Programme!
% This is the main program for encode!
%Copy right of XUJIE 2008
%If you have any question,please contact me
% xujie1984@gmail.com
%*******************************************
% Almost all the variables in the program are GLOBAL, this makes the program easier
% to understand!
%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!
%**************************************************************************
clc
clear all
clear global
global prob no_of_symbols
% ---------------------------------------------------------------------------------------
K=16;
no_of_symbols=256;
prob=ones(1,no_of_symbols);
%Initialize prob!
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 compressing!
OpenOutputBitFile('compressed.txt');
fid=fopen('test.txt','r');
initialize_arithmetic_encoder;
while (1~=0)
ch = fread(fid,1);
if(feof(fid)),break;end
symbol=ch;
encode_symbol(symbol,prob,no_of_symbols);
end
flush_arithmetic_encoder;
fclose(fid);
CloseOutputBitFile;
disp('******************************');
disp('*****COMPRESSING COMPLETE!****');
disp('******************************');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -