Методы арифметического кодирования информации и сравнение их коэффициентов сжатия

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование

>

FibOneDecoding(s_tmp:string):integer;i,kol:integer;:=0;i:=1 to length(s_tmp)-1 do(s_tmp[i]=1) then:=kol+ Fib_arr[i];:=kol;;

FibDecoding(name:string):string;_temp:string;:textfile;:char;(f,name);(f);_temp:=;not(eof(f)) do(f,c);_temp:=s_temp+c;(length(s_temp)>1) and (s_temp[length(s_temp)]=1) and (s_temp[length(s_temp)-1]=1) then:=result+Code_table[FibOneDecoding(s_temp)];_temp:=;;;(f);;

 

/////////////////////////////////Elias Gamma/////////////////////////////////

GetBinary(numb:integer):string;t,k:integer;:=numb;:=;(t>1) do:=t mod 2;:=result+inttostr(k);:=t div 2;;:=result+inttostr(t);:=ReverseString(result);;

BinToInt(bin:string):integer;i:integer;_bin:string;:=0;_bin:=ReverseString(bin);i:=1 to length(t_bin) do(t_bin[i]=1)then:=result+strtoint(floattostr(power(2,i-1)));;

ElGammaCodingOne(one:integer):string;kol,temp,i:integer;:string;:=one;:=0;(temp>0)do:=temp div 2;:=kol+1;;:=kol-1;:=;i:=1 to kol do:=result+0;

:=GetBinary(one mod strtoint(floattostr((power(2,kol)))));:=result+1;i:=1 to kol-length(bin) do:=result+0;one>1 then:=result+bin;;

0then(f,ElGammaCodingOne(CT_ord(s_str[i])));">ElGammaCoding(s_str:string);i:integer;:textfile;(f,GammaElias.txt);(f);i:=1 to length(s_str) dos_str[i]<>0 then(f,ElGammaCodingOne(CT_ord(s_str[i])));

(f);;

ElGammaDecoding(name:string):string;kol,i:integer;_temp:string;:textfile;:char;(f,name);(f);_temp:=;:=;not(eof(f)) do:=0;(f,c);c<>1 do(f,c);:=kol+1;;_temp:=;i:=1 to kol do(f,c);_temp:=s_temp+c;;:=result+Code_table[BinToInt(s_temp)+strtoint(floattostr(power(2,kol)))];;(f);;

 

///////////////////////////////Elias delta///////////////////////////////////

ElDeltaCodingOne(one:integer):string;kol,temp,i:integer;:string;one=1 then:=1;;;:=one;:=0;(temp>0)do:=temp div 2;:=kol+1;;:=ElGammaCodingOne(kol);:=GetBinary(one mod strtoint(floattostr((power(2,kol-1)))));i:=1 to kol-length(bin)-1 do:=result+0;one>1 then:=result+bin;

;

0then(f,ElDeltaCodingOne(CT_ord(s_str[i])));(f);;">ElDeltaCoding(s_str:string);i:integer;:textfile;(f,DeltaElias.txt);(f);i:=1 to length(s_str) dos_str[i]<>0 then(f,ElDeltaCodingOne(CT_ord(s_str[i]))); (f);;

ElDeltaDecoding(name:string):string;kol,i,pow:integer;_temp:string;:textfile;:char;(f,name);(f);_temp:=;:=;not(eof(f)) do:=0;(f,c);c<>1 do(f,c);:=kol+1;;_temp:=;i:=1 to kol do(f,c);_temp:=s_temp+c;;:= BinToInt(s_temp)+strtoint(floattostr(power(2,kol)));_temp:=;i:=1 to pow-1 do(f,c);_temp:=s_temp+c;;:=result+ Code_table[BinToInt(s_temp)+strtoint(floattostr(power(2,pow-1)))];;(f);;

 

///////////////////////////////////Golomb////////////////////////////////////UnaringCode(n:integer):string;i:integer;:=;i:=1 to n do:=result+1;:=result+0;;

GolombCodingOne(n:integer):string;q,r,b,cutoff,i:integer;:string;:= n div Golomb_M;:= n mod Golomb_M;:=UnaringCode(q);:= ceil(math.Log2(Golomb_M));:=round(power(2,b))-Golomb_M;(r<cutoff) then:=GetBinary(r);i:=1 to (b-1)-length(bin) do:=result+0;:=result+bin;:=GetBinary(r+cutoff);i:=1 to (b)-length(bin) do:=result+0;:=result+bin;;

// Showmessage(result);

//skolko volka ne kormi vse ravno v les smotrit431;

 

0then(f,GolombCodingOne(CT_ord(s_str[i])));(f);;">GolombCoding(s_str:string);i:integer;:textfile;(f,Golomb.txt);(f);(f, GLOMB_M_INFO);(f, Golomb_M);i:=1 to length(s_str) dos_str[i]<>0 then(f,GolombCodingOne(CT_ord(s_str[i])));(f);;

0do(f,c);:=kol+1;;//q:=kol;_temp:=;i:=1tob-1do(f,c);_temp:=s_temp+c;;:=BinToInt(s_temp);(f,c);_temp:=s_temp+c;:=BinToInt(s_temp);(b2=M)or(b2-cutoff<=cutoff-1) then:=result+Code_table[q*M+b1];:=result+Code_table[q*M+b2-cutoff];(f,c);;;(f);;

 

/////////////////////////////Haffman/////////////////////////////////////////Tree.Create;;

Tree.Create( character:integer; weight:integer; leaf:boolean);.leaf := leaf;.character := character;.weight := weight;;

nil)thenchild0.traverse(code+0,h);(child1 nil) then child1.traverse(code + 1, h);;

Huffman.getLowestTree( used: integer):integer;min,i:integer;:=0;i:=1 to used-1 do(Gtree[i].weight < Gtree[min].weight )then min := i;:= min;;

0)thenbegin[used]:=Tree.Create(c,w,true);:=used+1;;;(used>1)do:=getLowestTree(used);:=Gtree[min].weight;:=Tree.Create;.child0:=Gtree[min];:=used-1;[min]:=Gtree[used];:=getLowestTree(used);.child1:=Gtree[min];.weight:=weight0+Gtree[min].weight;[min]:=temp;;;">Huffman.growTree( data:array of integer );i,used,c,w,min,weight0:integer ;:Tree;i:=0 to length(data)-1 do[data[i]]:= weights[data[i]]+1;:= 0;c:=0 to ALPHABETSIZE-1 do:= weights[c];(w 1)do:= getLowestTree( used );:= Gtree[min].weight;:= Tree.Create;.child0 := Gtree[min];:=used-1;[min] := Gtree[used];:= getLowestTree( used );.child1 := Gtree[min];.weight := weight0 + Gtree[min].weight;[min] := temp;; ;

Huffman.makeCode;[0].traverse(, self);;

Huffman.coder( data:array of integer ):string;str:string;:integer;:= ;i:=0 to length(data)-1 do:=str+ code[data[i]];:=str;;

0)doc:=0toALPHABETSIZE-1do(weights[c]>0)then(weights[c]>0)and(Pos(code[c],data)=1)then:=copy(data,Length(code[c])+1,length(data));:=str+chr(c);;;;:=str;;">Huffman.decoder(data:String):string;str:string;:integer;:=;(length(data) > 0)doc:=0 to ALPHABETSIZE-1 do(weights[c]>0)then(weights[c]>0) and (Pos(code[c],data)=1) then:= copy(data,Length(code[c])+1,length(data));:= str+chr(c);;;;:=str;;

HuffmanCoding(s_str:string);i:integer;:textfile;:array of integer;:string;(f,Huffman.txt);(f);:= Huffman.Create;(data,length(s_str));i:=0 to length(data)-1 do[i]:= ord(s_str[i+1]);.growTree(data);.makeCode;:= Gh.coder(data);(f, str); (Gf);(f);;

HuffmanDecoding(f_name:string):string;f: textfile;_temp:string;:char;(f,f_name);(f);_temp:=;not eof(f) do(f,c);_temp:=s_temp+c;;:= Gh.decoder(s_temp);(f);;

 

/////////////////////////////////////////////////////////////////////////////

 

DoCoding(code_id: integer);

code_id of

: begin(Form1.Edit1.Text);.Memo1.Lines.LoadFromFile(FibCoding.txt);

// Showmessage(Size of code +inttostr(length(Form1.Memo1.Lines.GetText)));;

: // Elias Gamma(Form1.Edit1.Text);.Memo1.Lines.LoadFromFile(GammaElias.txt);;

: // Ellias delta(Form1.Edit1.Text);.Memo1.Lines.LoadFromFile(DeltaElias.txt);;

: // Golomb.Form2.ShowModal;_M:=Golomb.Form2.SpinEdit1.Value;(Form1.Edit1.Text);.Memo1.Lines.LoadFromFile(Golomb.txt);;

: // Huffman(Form1.Edit1.Text);.Memo1.Lines.LoadFromFile(Huffman.txt);;

: ;(Err_str_NotSuchMeth);;.Label6.Caption:=inttostr(length(Form1.Memo1.Lines.GetText));;

DoDecoding(code_id: integer);code_id of

: begin.Edit2.Text:=FibDecoding(FibCoding.txt);;

: begin.Edit2.Text:= ElGammaDecoding(GammaElias.txt);;

: begin.Edit2.Text:=ElDeltaDecoding(DeltaElias.txt);;

: begin.Edit2.Text:=GolombDecoding(Golomb.txt);;

: begin.Edit2.Text:=HuffmanDecoding(Huffman.txt);;

: ;(Err_str_NotSuchMeth);;;

TForm1.FormCreate(Sender: TObject);_meth:=0;_table;(Gf,HuffmanTemp.txt);(Gf);;TForm1.ComboBox1Select(Sender: TObject);_meth:=ComboBox1.ItemIndex;

//ShowMessage(inttostr(Coding_meth));;TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);not((Key in [0..9])or (Key in [a..z])or (Key in [ ,#13,#10])) then(Err_str_WrongSymbols);:=#0;;

;TForm1.Button1Click(Sender: TObject);(Coding_meth);

;TForm1.Button2Click(Sender: TObject);(Coding_meth);;

TForm1.Button3Click(Sender: TObject);i:integer;

//Golomb_M:=8;

// for i:=1 to 10 do

// GolombCodingOne(42);(inttostr(CT_ord(v)));

end;

.