📄 decompressdoc.cpp
字号:
}
}
else
break;
}
time--;
}
//重排重要系数表的系数
//length=zhycoeff.GetSize();
int min,max;//每个区间的左,右值
int index=0;
int iindex=0;
int tempcoeff;
time=TT;
while(time>=1)
{
//index=0;
//iindex=0;
min=time*T;
max=min+T;
while(index<zhycoeffIndex)
{
if(abs(zhycoeff.GetAt(index))>=min && abs(zhycoeff.GetAt(index))<max)
{
if(abs(zhycoeff.GetAt(index))>=(min+max)/2)
index++;
else
{
iindex=index;//找到的当前的第一个比1.5T小的系数
tempcoeff=zhycoeff.GetAt(iindex);
index++; //从下一个系数开始找第一个比1.5T大的系数
while(index<zhycoeffIndex)
{
if(abs(zhycoeff.GetAt(index))>=min && abs(zhycoeff.GetAt(index))<max)
{
if(abs(zhycoeff.GetAt(index))<(min+max)/2) //仍是比1.5T小的系数
index++;
else
{
if(iindex+1==index) //直接交换的情况
{
zhycoeff.SetAtGrow(iindex,zhycoeff.GetAt(index)); //找到的两个位置交换系数,实现重排
zhycoeff.SetAtGrow(index,tempcoeff);
iindex=index; //这时第一个比1.5T小的系数被放到了后面index处
index++;
}
else //要把找到的第一个比1.5T大的系数前的所有比1.5T小的系数往后移
{
int kk=index-iindex;
int tt=index;
tempcoeff=zhycoeff.GetAt(index);
for(z=1;z<=kk;z++)
{
zhycoeff.SetAtGrow(tt,zhycoeff.GetAt(tt-1));
tt--;
}
zhycoeff.SetAtGrow(iindex,tempcoeff);
iindex++;
index++;
}
}
}//if
else
break;
}//while
}//else
}//if
else
break;
}//while
time--;
}//while
return zhycoeffIndex;
}
/*
//对经EZW扫描过的主表辅表中的符号进行无损编码
void CDecompressDoc::EZWEncode(int T, CArray <BYTE,BYTE> &zhubiao, CArray <BYTE,BYTE> &fubiao)
{
BYTE tempTG=0;//用来暂时存放T的高8位或低8位
tempTG=T;
code.SetAtGrow(codeId,tempTG);
codeId++;
tempTG=T>>8;
code.SetAtGrow(codeId,tempTG);//至此已把T写入code中
codeId++;
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
//实现zhubiao的无损编码:游程编码
RunLength_En(zhubiao);
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
//实现fubiao的无损编码:游程编码
RunLength_En(fubiao);
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
}*/
//对经EZW扫描过的主表辅表中的符号进行无损编码
void CDecompressDoc::EZWEncode(int T, CArray <BYTE,BYTE> &zhubiao, CArray <BYTE,BYTE> &fubiao)
{
BYTE tempTG=0;//用来暂时存放T的高8位或低8位
tempTG=T;
code.SetAtGrow(codeId,tempTG);
codeId++;
tempTG=T>>8;
code.SetAtGrow(codeId,tempTG);//至此已把T写入code中
codeId++;
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
//实现zhubiao的无损编码:游程编码
ZhBAC_Code_En(zhubiao);
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
//实现fubiao的无损编码:游程编码
FBAC_Code_En(fubiao);
//加个分隔符区分:/
code.SetAtGrow(codeId,255);
codeId++;
}
void CDecompressDoc::ZhBAC_Code_En(CArray <BYTE,BYTE> &biao)
{
CString yuan;
yuan=CString("PNZT");
CAC_Code EnCode(yuan);
int length=biao.GetSize();
int k;
for(k=0;k<length-1;k++)
EnCode.Four_Encode(biao.GetAt(k));
//对最后一个符号进行编码
EnCode.Four_EncodeLast(biao.GetAt(k));
for(k=0;k<EnCode.NewCodeId;k++)
{
code.SetAtGrow(codeId,EnCode.NewCode.GetAt(k));
codeId++;
}
}
void CDecompressDoc::FBAC_Code_En(CArray <BYTE,BYTE> &biao)
{
CString yuan;
yuan=CString("01");
CAC_Code EnCode(yuan);
int length=biao.GetSize();
int k;
for(k=0;k<length-1;k++)
EnCode.Four_Encode(biao.GetAt(k));
//对最后一个符号进行编码
EnCode.Four_EncodeLast(biao.GetAt(k));
for(k=0;k<EnCode.NewCodeId;k++)
{
code.SetAtGrow(codeId,EnCode.NewCode.GetAt(k));
codeId++;
}
}
//游程长度编码
void CDecompressDoc::RunLength_En(CArray <BYTE,BYTE> &biao)
{
int length=biao.GetSize();
int ItemLength=0;
BYTE p=biao.GetAt(0);
int ff=0;
int flag=0;
//int number=0;
for(int i=0;i<length;i++)
{
if(p==biao.GetAt(i))
ItemLength++;
else
{
code.SetAtGrow(codeId,p);
codeId++;
if(ItemLength>255)
{
code.SetAtGrow(codeId,ItemLength);//先放低位再放高位
codeId++;
ItemLength=ItemLength>>8;
code.SetAtGrow(codeId,ItemLength);
codeId++;
ff=1;
}
else
{
if(ItemLength==255)
flag=1;
code.SetAtGrow(codeId,ItemLength);
codeId++;
}
p=biao.GetAt(i);
ItemLength=1;
}
}
code.SetAtGrow(codeId,p);
codeId++;
if(ItemLength>255)
{
code.SetAtGrow(codeId,ItemLength);//先放低位再放高位
codeId++;
ItemLength=ItemLength>>8;
code.SetAtGrow(codeId,ItemLength);
codeId++;
ff=1;
}
else
{
if(ItemLength==255)
flag=1;
code.SetAtGrow(codeId,ItemLength);
codeId++;
}
}
void CDecompressDoc::OnEZWDecode()
{
// TODO: Add your command handler code here
clock_t start,finish;
double duration;
start=clock();
int linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
CNode** AllNode=new CNode*[pbi->bmiHeader.biHeight];
for(int k=0;k<pbi->bmiHeader.biHeight;k++)
{
AllNode[k]=new CNode[linewidth];
}
int i,j,tt;
char chartemp;
for(i=0;i<pbi->bmiHeader.biHeight;i++)
{
for(j=0;j<linewidth;j++)
{
AllNode[i][j].x=i;
AllNode[i][j].y=j;
AllNode[i][j].importflag=0;
AllNode[i][j].flag=0;
AllNode[i][j].coef=0;
if(i<pbi->bmiHeader.biHeight>>scale && j<linewidth>>scale)
AllNode[i][j].scale=scale+1;
for(int l=scale-1;l>=0;l--)
{
if(i<pbi->bmiHeader.biHeight>>l && i>=pbi->bmiHeader.biHeight>>(l+1) && j<linewidth>>(l+1))
{
AllNode[i][j].orientation=2;
AllNode[i][j].scale=l+1;
}
else if(i<pbi->bmiHeader.biHeight>>l && i>=pbi->bmiHeader.biHeight>>(l+1) && j<linewidth>>l && j>=linewidth>>(l+1))
{
AllNode[i][j].orientation=3;
AllNode[i][j].scale=l+1;
}
else if(i<pbi->bmiHeader.biHeight>>(l+1) && j<linewidth>>l && j>=linewidth>>(l+1))
{
AllNode[i][j].orientation=1;
AllNode[i][j].scale=l+1;
}
}
}
}
unsigned length=code.GetSize();
int T; //阈值
int t=1;//第几次扫描
CArray <BYTE,BYTE> zhubiao;
zhubiao.SetSize(100,50);
CArray <BYTE,BYTE> fubiao;
fubiao.SetSize(20,50);
int NewCodeId;
int times;
int zhubiaoIndex=-1;
int fubiaoIndex=-1;
//int coefflag=0; //code中主表或辅表的符号标志或个数标志
int flag=0; //是否是T的高位的标志
int nTimes=0; //'/n'出现的次数
BYTE PNZTflag;
ofstream ofile;
zhubiao.RemoveAll();
fubiao.RemoveAll();
for(i=0;i<codeId;i++)
{
if(code.GetAt(i)!=255)
{
if(nTimes==0) //出现的是阈值
{
if(flag==0) //出现的是阈值的低位
{
T=code.GetAt(i);
if(T!=0)
{
i++;
flag=0;
}
else
flag=1;
}
else //出现的是阈值的高位
{
T=code.GetAt(i);
T=T<<8;
flag=0;
}
}
else if(nTimes==1)
{
CString yuan;
yuan=CString("PNZT");
CAC_Code DeCode(yuan);
CArray <BYTE,BYTE> NewCode;
NewCode.SetSize(10,10);
NewCodeId=0;
while(code.GetAt(i)!=255)
{
NewCode.SetAtGrow(NewCodeId,code.GetAt(i));
i++;
NewCodeId++;
}
DeCode.Four_Decode(NewCode);
zhubiao.Copy(DeCode.DecodeFuHao);
i--;
ofile.open("d:\\zhubiao2.txt");
ofile<<"the size is"<<zhubiao.GetSize()<<endl;
for(tt=0;tt<zhubiao.GetSize();tt++)
{
ofile<<zhubiao.GetAt(tt);
if(((tt+1)%10)==0)
ofile<<" ";
if(((tt+1)%100)==0)
ofile<<endl;
}
ofile.close();
/*
zhubiaoIndex++;
zhubiao.SetAtGrow(zhubiaoIndex,code.GetAt(i));
//coefflag++;
i++;
PNZTflag=code.GetAt(i+1);
if(PNZTflag!='P' && PNZTflag!='N' && PNZTflag!='Z' && PNZTflag!='T' && PNZTflag!=255)
{ //符号个数大于255
times=code.GetAt(i+1);
times=times<<8;
times=times+code.GetAt(i);
for(j=1;j<times;j++)
{
zhubiaoIndex++;
zhubiao.SetAtGrow(zhubiaoIndex,code.GetAt(i-1));
}
//coefflag++;
i++;
}
else //符号个数小于255
{
times=code.GetAt(i);
if(times==1)
;
else
{
for(j=1;j<times;j++)
{
zhubiaoIndex++;
zhubiao.SetAtGrow(zhubiaoIndex,code.GetAt(i-1));
}
}
//coefflag++;
}*/
}
else if(nTimes==2)
{
CString yuan;
yuan=CString("01");
CAC_Code DeCode(yuan);
CArray <BYTE,BYTE> NewCode;
NewCode.SetSize(10,10);
NewCodeId=0;
while(code.GetAt(i)!=255)
{
NewCode.SetAtGrow(NewCodeId,code.GetAt(i));
i++;
NewCodeId++;
}
DeCode.Four_Decode(NewCode);
fubiao.Copy(DeCode.DecodeFuHao);
i--;
ofile.open("d:\\fubiao2.txt");
ofile<<"the size is"<<fubiao.GetSize()<<endl;
for(tt=0;tt<fubiao.GetSize();tt++)
{
ofile<<fubiao.GetAt(tt);
if(((tt+1)%10)==0)
ofile<<" ";
if(((tt+1)%100)==0)
ofile<<endl;
}
ofile.close();
/*
fubiaoIndex++;
fubiao.SetAtGrow(fubiaoIndex,code.GetAt(i));
//coefflag++;
i++;
PNZTflag=code.GetAt(i+1);
if(PNZTflag!=88 && PNZTflag!=89 && PNZTflag!=255)
{ //符号个数大于255
times=code.GetAt(i+1);
times=times<<8;
times=times+code.GetAt(i);
for(j=1;j<times;j++)
{
fubiaoIndex++;
fubiao.SetAtGrow(fubiaoIndex,code.GetAt(i-1));
}
//coefflag++;
i++;
}
else //符号个数小于255
{
times=code.GetAt(i);
if(times==1)
;
else
{
for(j=1;j<times;j++)
{
fubiaoIndex++;
fubiao.SetAtGrow(fubiaoIndex,code.GetAt(i-1));
}
}
//coefflag++;
}*/
}//else if
}//if
else
{
nTimes++;
if(nTimes==3)
{
//逆量化
EZWDecode(T,AllNode,zhubiao,fubiao,t);
t++; //扫描次数加1
nTimes=0;
zhubiaoIndex=-1;
fubiaoIndex=-1;
zhubiao.RemoveAll();
fubiao.RemoveAll();
}
}
}//for
//所有经扫描所
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -