星期一, 10月 08, 2007

[日誌]衝了

掙扎了很久
終於決定把程式碼重寫一遍
為了以後程式的發展著想
還是寫一下比較好
不然debug都要超久的!!!

X的 今天我就要衝了
徹夜跟他奮戰
小黑幫我加油!!!
以下是噁心的舊的程式碼
(我貼來衝字數的....)
沒事千萬不要看
會頭暈的!!!!
敬請期待新的程式碼!!

//---------------------------------------------------------------------------
#include
#include
#include
#include //檔案處理需要用到
#include
#include
#include "IdGlobal.hpp"//IntToBin()函數要用到
using namespace std;
int size;
int* memblock;
int i,j;
int tempI1;
int tempLength;
int Bits[17];//L1~L16
int LastK[2][2],Tc,Th;
int *Huffsize[2][2],*Huffcode[2][2],**Huffcodebin[2][2],*eHufco[2][2],*eHufsize[2][2],huffmancode_number = 0;
int *HuffVal[2][2];
String tempS1,tempS2,sFileName,*sHuffcode[2][2];
ifstream input;
ofstream output;
int treesize;
int NodeNum = 0;
int num = 0;
class node
{
public:
int data;
int Number;
node *left;
node *right;
node();
/*
if data == -1 表示這只是個中間節點
else data == symbol value;
*/
};
node::node()
{
left=NULL;
right=NULL;
}
class Tree
{
private:
node *root;
int *KeyBin;
public:
Tree();
void insert(int Symbol,int huffmancode,int codelength);
String Print();
String visit(node *s);
};
Tree::Tree()
{
root=NULL;
}
void Tree::insert(int Symbol,int huffmancode,int codelength)
{
if(root == NULL)
{
//表示沒有任何節點->建立一個新的節點
root = new node;
root->Number = NodeNum;
NodeNum++;
root->right = NULL;
root->left = NULL;
}
node *p,*r;
if(codelength != 0)
{
p = root; //p 現在的Node
int bit;
int tempTCode,Ta,length,i = 0;
tempTCode = huffmancode;
int *huffBin;
huffBin = new int[codelength];
length = codelength;
while(length > 0)
{
Ta = tempTCode / 2;
bit = tempTCode - 2 * Ta; // b = 判斷bit
huffBin[codelength - i -1] = bit;
tempTCode = Ta; // 取下一個判斷的bit
length--;
i++;
}
for(i = 0;i < codelength;i++)
{
bit = huffBin[i];
if(bit == 0)//判斷要往左邊(bit == 0)
{
if(p->left != NULL)
{
p->data = -1;
p = p->left;
}
else
{
p->data = -1;
r = new node;
r->Number = NodeNum;
NodeNum++;
r->right = NULL;
r->left = NULL;
p->left = r;
p = r;
r = NULL;
}
}
else if(bit == 1)//判斷要往右邊(bit == 1)
{
if(p->right != NULL)
{
p->data = -1;
p = p->right;
}
else
{
p->data = -1;
r = new node;
r->Number = NodeNum;
NodeNum++;
r->right = NULL;
r->left = NULL;
p->right = r;
p = r;
r = NULL;
}
}
}
p->data = Symbol; //p->Number
p = NULL;
}
}
String Tree::visit(node* s)
{
String VisitS,LeftS,RightS;
VisitS += "節點編號 = " + AnsiString(s->Number);
VisitS += ",data = " + AnsiString(s->data);
if (s->left != NULL)
VisitS += ",左節點=" + AnsiString(s->left->Number);
if (s->right != NULL)
VisitS += ",右節點 =" + AnsiString(s->right->Number);
VisitS += " \n";
if (s->left != NULL)
LeftS = visit(s->left);
if (s->right != NULL)
RightS = visit(s->right);
return VisitS + LeftS + RightS ;
}
String Tree::Print()
{
node *p;
p = root;
String tempS ="";
int i = 0;
tempS += visit(p);
return tempS;
}
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Tree DC0,DC1,AC0,AC1;
//---------------------------------------------------------------------------
void itob(int Tc,int Th,int GCT)
{
int tempindex = Huffsize[Tc][Th][GCT] - 1;
int tempLength = Huffsize[Tc][Th][GCT];
int tempCode = Huffcode[Tc][Th][GCT];
int tempbin = 0;
String tempSSS;
sHuffcode[Tc][Th][GCT] = " ";
while( tempindex >= 0)
{
if(tempCode >= 0)
tempbin = tempCode % 2;
else
tempbin = 0;
Huffcodebin[Tc][Th][GCT][tempindex] = tempbin;
tempCode = tempCode / 2;
tempindex = tempindex - 1;
}
}
void aaa(int begQ)
{
int aaai;
tempS2 += "PqTq=" + IntToHex(memblock[begQ],2) + "\n";
for(aaai = 1; aaai < 65; aaai++)
{
tempS2 += "Q(";
if(aaai < 11)
tempS2 += "0";
tempS2 += AnsiString(aaai-1) + ")=" + IntToHex(memblock[begQ+aaai],2) + " ";
if((aaai-1) % 8 == 7)
tempS2 +="\n";
}
}
int huffLi(int begH)
{
int temoLiCount,countreturn = 0;
tempS2 += "TcTh=" + IntToHex(memblock[begH],2) + "\n";
if(memblock[begH]/16 ==0) //Tc == 0
{
Tc = 0;
tempS2 += "Tc = 0 - - - - - - > DC Table or lossless table. ";
}
else if(memblock[begH]/16 ==1) //Tc == 1
{
Tc = 1;
tempS2 += "Tc = 1 - - - - - - > AC Table. ";
}
if(memblock[begH]%16 == 0) //Th == 0
{
Th = 0;
tempS2 += "Th = 0\n";
}
else if(memblock[begH]%16 == 1) //Th == 0
{
Th = 1;
tempS2 += "Th = 1\n";
}
for(temoLiCount = 1; temoLiCount < 17; temoLiCount++)
{
Bits[temoLiCount] = memblock[begH+temoLiCount];
tempS2 += "L(";
if(temoLiCount < 10)
tempS2 += "0";
tempS2 += AnsiString(temoLiCount) + ")= ";
tempS2 += "(Hex) " + IntToHex(memblock[begH+temoLiCount],2) +" = (DEC) "+ AnsiString(memblock[begH+temoLiCount])+"   ";
countreturn += memblock[begH+temoLiCount];
if(temoLiCount % 2 == 0)
tempS2 += "\n";
}
return countreturn;
}
void Generate_size_table(int LiCount,int Tc,int Th)
{
int GSTK = 0, GSTL = 1,GSTJ = 1;

Huffsize[Tc][Th] = new int[LiCount+1];
for(GSTL = 1;GSTL < 17;GSTL++)
{
while(GSTJ <= Bits[GSTL])
{
Huffsize[Tc][Th][GSTK] = GSTL;
//tempS2 += "Huffsize(" + AnsiString(GSTK) + ")=" + AnsiString(GSTL) +"\n";
GSTJ++;
GSTK++;
}
GSTJ = 1;
}
Huffsize[Tc][Th][GSTK] = 0;
//tempS2 += "Huffsize(" + AnsiString(GSTK) + ")= 0, ";
LastK[Tc][Th]= GSTK;
tempS2 += "根據L1~L16產生的huffcode在隔壁頁囉,這裡的LASTK = "+ AnsiString(LastK[Tc][Th]) + "\n";
}
void Generate_code_table(int LiCount,int Tc,int Th)
{
int GCTK = 0, GCTSI = Huffsize[Tc][Th][0],GCTCODE = 0;
Huffcode[Tc][Th] = new int [LiCount+1];
sHuffcode[Tc][Th] = new String [LiCount+1];
Huffcodebin[Tc][Th] = new int* [LiCount+1];
HuffVal[Tc][Th] = new int[LiCount+1];
while(Huffsize[Tc][Th][GCTK] != 0)
{
while(Huffsize[Tc][Th][GCTK] == GCTSI)
{
Huffcode[Tc][Th][GCTK] = GCTCODE;
//tempS2 += "Huffcode(" + AnsiString(GCTK) + ")=" + AnsiString(GCTCODE) +"\n";
Huffcode[Tc][Th][GCTK] = GCTCODE;
Huffcodebin[Tc][Th][GCTK] = new int [Huffsize[Tc][Th][GCTK]];//為了每個Huffcode準備好相對應的陣列
itob(Tc,Th,GCTK);
GCTCODE = GCTCODE +1;
GCTK = GCTK +1;
}
if(Huffsize[Tc][Th][GCTK] != 0)
{
while(Huffsize[Tc][Th][GCTK] != GCTSI)
{
GCTCODE = GCTCODE *2;
GCTSI = GCTSI + 1;
}
}
}
Huffcode[Tc][Th][GCTK] = GCTCODE;
}
void Order_codes(int LiCount,int Tc,int Th)
{

}
void HuffmanTable(int begH,int LiCount,int Tc,int Th)
{
int tempLi,tempi,tempj,tempcount = LiCount;
int HMTK = 0;
for(tempi = 0;tempi < 16;tempi++)
{
tempLi = memblock[begH + tempi];
tempj =1;
while(tempj <= tempLi)
{
tempS2 += "V(" + AnsiString(tempi + 1) + "," + AnsiString(tempj)+") = " + IntToHex(memblock[begH + 16 + LiCount - tempcount],2) + " ";
HuffVal[Tc][Th][HMTK] = memblock[begH + 16 + LiCount - tempcount];
if(tempj == tempLi)
tempS2 += "\n";
HMTK++;
tempj++;
tempcount--;
}

}
}
void DQT(int begQ,int qLength)
{
int tempDQT = 0;
tempS2 += "Lq = 16進位的" + IntToHex(qLength,4) + " = 十進位的 " + AnsiString(qLength) + "\n";
qLength -= 2; //扣掉 qLength 的2個byte;
begQ +=2; //skip掉 qLength 的2個byte;
while(qLength > 1 )
{
tempS2 += " - - - - - -- - - - - - - - Qt- - - - - - - - - - - - - - - - - - \n";
aaa(begQ);
begQ = begQ + 65;//一組量化表 = 65個BYTE (PqTq + 64 個element)
qLength = qLength - 65;
}
}
void SOS(int begS,int sLength)
{
int Ns,tempSi = 1,TdTa,Td,Ta;
tempS2 += "Ls = " + IntToHex(sLength,4) + "(十六進位) = 十進位的 " + AnsiString(sLength) + "\n";
tempS2 += "Ns = " + IntToHex(memblock[begS+2],2) + "\n";
Ns = memblock[begS+2];
sLength -= 3; //扣掉 sLength 的2個byte;
begS += 3; //skip掉 sLength 的2個byte;
int wahaha = 0;
// while(sLength > 0)
// {
while(tempSi <= Ns)
{

tempS2 += "Cs" + AnsiString(tempSi)+ " = " + IntToHex(memblock[begS],2)+ " ";
tempS2 += "Td" + AnsiString(tempSi) + "Ta" + AnsiString(tempSi) +" = "+ IntToHex(memblock[begS+1],2)+"\n";
TdTa = memblock[begS+1];
Td = TdTa /16;
Ta = TdTa %16;
tempS2 += "Td" + AnsiString(tempSi) +" = " + AnsiString(Td)+ " --> 選擇了第"+ AnsiString(Td) + "個 DC Entropy table\n";
tempS2 += "Ta" + AnsiString(tempSi) +" = " + AnsiString(Ta)+ " --> 選擇了第"+ AnsiString(Ta) + "個 AC Entropy table\n";
sLength -=2;
begS +=2;
tempSi++;
}
tempS2 += "Ss = " +IntToHex(memblock[begS],2) +"\n";
tempS2 += "Se = " +IntToHex(memblock[begS+1],2) +"\n";
tempS2 += "AhAl = " +IntToHex(memblock[begS+2],2) +"\n";
begS = begS +3;
sLength = sLength +3;
//}
tempS2 += "- - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - \n";
}
void DHT(int begH,int hLength)
{
int tempDHT = 0,LiCount;
tempS2 += "Lh = 16進位的 " + IntToHex(hLength,4) + " = 十進位的 " + AnsiString(hLength) + "\n";
hLength -= 2;
begH += 2;
//tempS2 += "\nbegH = " + AnsiString(begH) + "\nhLength = " + AnsiString(hLength);
while(hLength > 1)
{
//算L1~L16的數量
tempS2 += "第" + AnsiString(huffmancode_number + 1) + "個huffmantable.\n";
LiCount = 0;
LiCount = huffLi(begH); //Licount = L1 ~ L16 的值相加
Generate_size_table( LiCount,Tc,Th);
Generate_code_table(LiCount,Tc,Th);
Order_codes(LiCount,Tc,Th);
huffmancode_number++;
HuffmanTable(begH+1,LiCount,Tc,Th);//根據Li的數量去產生Vij.加上1是因為TcTh佔了1byte;
begH += (LiCount+17); //用來skip上面那行指令--> HuffmanTable(begH)
hLength -=(17 + LiCount);
hLength = hLength;
//tempS2 += "\nbegH = " + AnsiString(begH) + "\nhLength = " + AnsiString(hLength) + "\nLiCount = " + AnsiString(LiCount);
}

}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Open1Click(TObject *Sender)
{
if(OpenPictureDialog1->Execute())
{
String tempT;
char ch;
tempI1 = 0;
int tempI2 = 0,tempget;
sFileName = OpenPictureDialog1->FileName;
TJPEGImage* Jpg = new TJPEGImage;
Jpg->LoadFromFile(sFileName);
Image1->Picture->Bitmap->Assign(Jpg);
input.open(sFileName.c_str(),ios::binary|ios::in|ios::ate);
if(!input)
{
ShowMessage(" ");
}
size = input.tellg();
memblock = new int [size];
input.seekg (0, ios::beg);
tempget = input.get();
tempT = IntToHex(tempget,2);
while(!input.eof())
{
tempS1 += tempT + " ";
memblock[tempI2] = tempget;
tempI1++;
tempI2++;
tempget = input.get();
tempT = IntToHex(tempget,2);
/*if(tempget == 0xff)
tempget = tempget;
*/
if(tempI1 == 16)
{
tempS1 += "\n";
tempI1 = 0;
}
}
input.close();
Label1->Caption = AnsiString(tempS1);
Label2->Caption = AnsiString(tempI2);
}
Button1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
tempS2 = "-我是翻譯分隔線------------------------------------------------------------\n";
i = 0;
tempI1 = 0;
while(i < size)
{
if(memblock[i]== 0xff)
{
tempLength = 0;
if((memblock[i+1] >= 0xc0)&&(memblock[i+1] < 0xc4))
{
//(Start of Frame markers,non-differential,Huffman coding)
if(memblock[i+1] == 0xc0)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Baseline DCT(SOF0)";
if(memblock[i+1] == 0xc1)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Extended sequential DCT";
else if(memblock[i+1] == 0xc2)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Progressive DCT";
else if(memblock[i+1] == 0xc3)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Lossless(Sequential)\n";
tempS2 += "(Start of Frame markers,non-differential,Huffman coding)\n\n";
}
else if(memblock[i+1] == 0xcc)
{
//define arithmetic coding conditioning(s)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"--> Define arithmetic coding conditioning(s).";
tempS2 += "Arithmetic coding conditioning specification\n";
}
else if(memblock[i+1] == 0xc4)
{
//----FFC4:define Huffman table(s)
tempS2 += "\n"+ IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"--> Define Huffman table(s).\n";
tempLength = memblock[i+2]*256 + memblock[i+3];
tempS2 += "- - - - - - - - Huffman table 開始 - - - - - - - -\n";
DHT(i+2,tempLength);
tempS2 += "-- - - - - - - - Huffman table 結束 - - - - - - - -\n";
}
else if((memblock[i+1] >= 0xc5)&& (memblock[i+1] <= 0xC7))
{
if(memblock[i+1] == 0xc5)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential sequential DCT";
else if(memblock[i+1] == 0xc6)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential progressive DCT";
else if(memblock[i+1] == 0xc7)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential lossless(Sequential)";
tempS2 += "(Start of Frame markers,differential,Huffman coding)\n";
}
else if((memblock[i+1] >= 0xc8)&&(memblock[i+1] <= 0xcb))
{
if(memblock[i+1] == 0xc8)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->JPG:Reserved for JPEG extensions";
else if(memblock[i+1] == 0xc9)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Extended sequential DCT";
else if(memblock[i+1] == 0xca)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Extended sequential DCT";
else if(memblock[i+1] == 0xcb)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Lossless(Sequential)";
tempS2 += "(Start of Frame markers,non-differential,arithmetic coding)\n";
}
else if((memblock[i+1] >= 0xcd)&&(memblock[i+1] <= 0xcf))
{
if(memblock[i+1] == 0xcd)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential sequential DCT";
else if(memblock[i+1] == 0xce)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential progressive DCT";
else if(memblock[i+1] == 0xcf)
tempS2 += "\n" + IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Differential lossless(Sequential)";
tempS2 += "(Start of Frame markers,differential,arithmetic coding)\n";
}
else if((memblock[i+1] >= 0xd0)&&(memblock[i+1] <= 0xd7))
{
tempS2 += "RSTm*:Restart with modulo 8 count m\n";
}
else if(memblock[i+1] == 0xd8)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->Start of Image\n";
else if(memblock[i+1] == 0xd9)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->EOI:End of Image\n";
else if(memblock[i+1] == 0xda)
{
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->SOS:Start of Scan\n";
tempLength = memblock[i+2]*256 + memblock[i+3];
SOS(i+2,tempLength);
}
else if(memblock[i+1] == 0xdb)
{
//--FFDB:定義量化表-------------------------
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->DQT:Define quantization table\n";
tempLength = memblock[i+2]*256 + memblock[i+3];
tempS2 += "- - - - - - -- - - - - - - - Quqntization Table開始 - - - - - - - - - - - - - - - \n";
DQT(i+2,tempLength);
tempS2 += "- - - - - -- - - - - - - - Quqntization Table結束 - - - - - - - - - - - - - - \n";

}
else if(memblock[i+1] == 0xdc)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->DNL:Define number of line\n";
else if(memblock[i+1] == 0xdd)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->DRI:Define restart interval\n";
else if(memblock[i+1] == 0xde)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->DHP:Define hierarchical progression\n";
else if(memblock[i+1] == 0xdf)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->EXP:Expand reference component.\n";
else if((memblock[i+1] >= 0xe0)&&(memblock[i+1] <= 0xef))
{
//--我是給application的tag------------------------
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->我是給application的tag.\n";
tempLength = memblock[i+2]*256 + memblock[i+3];
tempS2 += " 要跳過" + AnsiString(tempLength)+ "個byte\n";
}
else if((memblock[i+1] >= 0xf0)&&(memblock[i+1] <= 0xfd))
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->reserved for JPEG extensions.\n";
else if(memblock[i+1] == 0xfe)
tempS2 += IntToHex((memblock[i]),2) + IntToHex((memblock[i+1]),2)+"-->COM:comment\n";
i = i + 2 + tempLength;
tempI1 = 0;
}
else
{
tempS2 += IntToHex((memblock[i]),2) + " ";
i++;
tempI1++;
if(tempI1 == 10)
{
tempS2 += "\n";
tempI1 = 0;
}
}
}
Label3->Caption = AnsiString(tempS2);
Button2->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//int aaaaa = 127;
String sss;
StringGridDC_0->RowCount = LastK[0][0] + 1;
StringGridDC_1->RowCount = LastK[0][1] + 1;
StringGridAC_0->RowCount = LastK[1][0] + 1;
StringGridAC_1->RowCount = LastK[1][1] + 1;
int intCodeLength,intSymbol,intHuffcode;
int btnTemp= 0,btnTc,btnTh;
String tempSSS;
while( btnTemp< 4)
{
btnTc = btnTemp / 2;
btnTh = btnTemp % 2;
for(i = 0; i <= LastK[btnTc][btnTh];i++)
{
tempSSS = " ";
for(j = 0; j < Huffsize[btnTc][btnTh][i] ;j++)
{
tempSSS += AnsiString(Huffcodebin[btnTc][btnTh][i][j]);
}
sHuffcode[btnTc][btnTh][i] = tempSSS;
if(btnTemp == 0)//TcTh = 00--->DC0
{
StringGridDC_0->Cells[0][i+1] = AnsiString(i);
StringGridDC_0->Cells[1][i+1] = AnsiString(Huffsize[btnTc][btnTh][i]);
StringGridDC_0->Cells[2][i+1] = AnsiString(Huffcode[btnTc][btnTh][i]);
StringGridDC_0->Cells[3][i+1] = AnsiString(sHuffcode[btnTc][btnTh][i]);
StringGridDC_0->Cells[4][i+1] = AnsiString(HuffVal[btnTc][btnTh][i]);
DC0.insert(HuffVal[btnTc][btnTh][i],Huffcode[btnTc][btnTh][i],Huffsize[btnTc][btnTh][i]);
}
if(btnTemp == 1)//TcTh = 01--->DC1
{
StringGridDC_1->Cells[0][i+1] = AnsiString(i);
StringGridDC_1->Cells[1][i+1] = AnsiString(Huffsize[btnTc][btnTh][i]);
StringGridDC_1->Cells[2][i+1] = AnsiString(Huffcode[btnTc][btnTh][i]);
StringGridDC_1->Cells[3][i+1] = AnsiString(sHuffcode[btnTc][btnTh][i]);
StringGridDC_1->Cells[4][i+1] = AnsiString(HuffVal[btnTc][btnTh][i]);
DC1.insert(HuffVal[btnTc][btnTh][i],Huffcode[btnTc][btnTh][i],Huffsize[btnTc][btnTh][i]);
}
if(btnTemp == 2)//TcTh = 10---->AC0
{
StringGridAC_0->Cells[0][i+1] = AnsiString(i);
StringGridAC_0->Cells[1][i+1] = AnsiString(Huffsize[btnTc][btnTh][i]);
StringGridAC_0->Cells[2][i+1] = AnsiString(Huffcode[btnTc][btnTh][i]);
StringGridAC_0->Cells[3][i+1] = AnsiString(sHuffcode[btnTc][btnTh][i]);
StringGridAC_0->Cells[4][i+1] = AnsiString(HuffVal[btnTc][btnTh][i]);
AC0.insert(HuffVal[btnTc][btnTh][i],Huffcode[btnTc][btnTh][i],Huffsize[btnTc][btnTh][i]);
}
if(btnTemp == 3)//TcTh = 11--->AC1
{
StringGridAC_1->Cells[0][i+1] = AnsiString(i);
StringGridAC_1->Cells[1][i+1] = AnsiString(Huffsize[btnTc][btnTh][i]);
StringGridAC_1->Cells[2][i+1] = AnsiString(Huffcode[btnTc][btnTh][i]);
StringGridAC_1->Cells[3][i+1] = AnsiString(sHuffcode[btnTc][btnTh][i]);
StringGridAC_1->Cells[4][i+1] = AnsiString(HuffVal[btnTc][btnTh][i]);
AC1.insert(HuffVal[btnTc][btnTh][i],Huffcode[btnTc][btnTh][i],Huffsize[btnTc][btnTh][i]);
}
}
btnTemp++;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGridDC_0->ColWidths[0] = 35;
StringGridDC_1->ColWidths[0] = 35;
StringGridAC_0->ColWidths[0] = 35;
StringGridAC_1->ColWidths[0] = 35;
//--------------------------------------
StringGridDC_0->ColWidths[1] = 45;
StringGridDC_1->ColWidths[1] = 45;
StringGridAC_0->ColWidths[1] = 45;
StringGridAC_1->ColWidths[1] = 45;
//----------------------------------------
StringGridDC_0->ColWidths[2] = 50;
StringGridDC_1->ColWidths[2] = 50;
StringGridAC_0->ColWidths[2] = 50;
StringGridAC_1->ColWidths[2] = 50;
//----------------------------------------
StringGridDC_0->ColWidths[3] = 110;
StringGridDC_1->ColWidths[3] = 110;
StringGridAC_0->ColWidths[3] = 110;
StringGridAC_1->ColWidths[3] = 110;
//------------------------------------------
StringGridDC_0->ColWidths[4] = 120;
StringGridDC_1->ColWidths[4] = 120;
StringGridAC_0->ColWidths[4] = 120;
StringGridAC_1->ColWidths[4] = 120;
//------------------------------------------
StringGridDC_0->Cells[0][0] = "DC_0";
StringGridDC_0->Cells[1][0] = "Huffsize";
StringGridDC_0->Cells[2][0] = "Huffcode";
StringGridDC_0->Cells[3][0] = "Huffcode(binary)";
StringGridDC_0->Cells[4][0] = "HuffVal";
//------------------------------------------
StringGridDC_1->Cells[0][0] = "DC_1";
StringGridDC_1->Cells[1][0] = "Huffsize";
StringGridDC_1->Cells[2][0] = "Huffcode";
StringGridDC_1->Cells[3][0] = "Huffcode(binary)";
StringGridDC_1->Cells[4][0] = "HuffVal";
//------------------------------------------
StringGridAC_0->Cells[0][0] = "AC_0";
StringGridAC_0->Cells[1][0] = "Huffsize";
StringGridAC_0->Cells[2][0] = "Huffcode";
StringGridAC_0->Cells[3][0] = "Huffcode(binary)";
StringGridAC_0->Cells[4][0] = "HuffVal";
//------------------------------------------
StringGridAC_1->Cells[0][0] = "AC_1";
StringGridAC_1->Cells[1][0] = "Huffsize";
StringGridAC_1->Cells[2][0] = "Huffcode";
StringGridAC_1->Cells[3][0] = "Huffcode(binary)";
StringGridAC_1->Cells[4][0] = "HuffVal";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button3Click(TObject *Sender)
{
String resultDC0,resultDC1,resultAC0,resultAC1;
resultDC0 = DC0.Print();
resultDC1 = DC1.Print();
resultAC0 = AC0.Print();
resultAC1 = AC1.Print();
Label5->Caption = resultDC0;
Label6->Caption = resultDC1;
Label7->Caption = resultAC0;
Label8->Caption = resultAC1;
}
//---------------------------------------------------------------------------