📄 decompressdoc.cpp
字号:
{
// TODO: Add your command handler code here
int linewidth;
int max, min; //记录变换后像素的最大最小值
int** image; //用于变换的整型图象数据
int** secondimage; //存放用于第二层变换的图象数据
//int temp; //临时存放映射后的值,再转化为BYTE型
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
JiFlag=0; //Haar小波
//生成对lpBuf的二维数组索引
image=new int*[pbi->bmiHeader.biHeight];
for(int i=0;i<pbi->bmiHeader.biHeight;i++)
{
image[i]=new int[linewidth];
// image[i]=(int*)(lpBuf+i*linewidth);
}
for(int ii=pbi->bmiHeader.biHeight-1; ii>=0; ii--)
{
for(int jj=0; jj<linewidth; jj++)
image[ii][jj]=*(lpBuf+(pbi->bmiHeader.biHeight-1-ii)*linewidth+jj);
}
max=min=image[0][0];
HaarTrans(pbi->bmiHeader.biHeight,linewidth,image,&max,&min);
GetCoefficient(image,pbi->bmiHeader.biHeight,linewidth);
secondimage=new int*[pbi->bmiHeader.biHeight>>1];
for(int h=0;h<pbi->bmiHeader.biHeight>>1;h++)
{
secondimage[h]=new int[linewidth>>1];
}
for(int m=0;m<pbi->bmiHeader.biHeight>>1;m++)
{
for(int n=0;n<linewidth>>1;n++)
secondimage[m][n]=image[2*m][2*n];
}
HaarTrans(pbi->bmiHeader.biHeight>>1,linewidth>>1,secondimage,&max,&min);
GetCoefficient(secondimage,pbi->bmiHeader.biHeight>>1,linewidth>>1);
Two_ToLpshowbuf(image,secondimage, &max, &min);
scale=2;
//释放内存
for(int z=0;z<pbi->bmiHeader.biHeight>>1;z++)
{
delete [] image[2*z];
delete [] image[2*z+1];
delete [] secondimage[z];
}
delete [] image;
delete [] secondimage;
UpdateAllViews(NULL, 0, NULL);
}
void CDecompressDoc::Two_ToLpshowbuf(int **OneImage, int **SecondImage, int *max, int *min)
{
int temp;
int linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
//把所有变换后的系数映射到0-255
for(int mm=0;mm<(pbi->bmiHeader.biHeight>>1);mm++)
{
for(int nn=0;nn<(linewidth>>1);nn++)
{
SecondImage[mm][nn]=(SecondImage[mm][nn]-*min)*255/(*max-*min);
OneImage[mm][nn]=(OneImage[mm][nn]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+mm][nn]=(OneImage[(pbi->bmiHeader.biHeight>>1)+mm][nn]-*min)*255/(*max-*min);
OneImage[mm][(linewidth>>1)+nn]=(OneImage[mm][(linewidth>>1)+nn]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+mm][(linewidth>>1)+nn]=(OneImage[(pbi->bmiHeader.biHeight>>1)+mm][(linewidth>>1)+nn]-*min)*255/(*max-*min);
}
}
//把所有系数放入lpshowbuf中显示出来
for(int x=0;x<pbi->bmiHeader.biHeight>>2;x++)
{
for(int y=0;y<linewidth>>2;y++)
{
temp=SecondImage[2*x][2*y];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
}
}
for(int xx=0;xx<pbi->bmiHeader.biHeight>>1;xx++)
{
for(int yy=0;yy<linewidth>>1;yy++)
{
temp=OneImage[2*xx][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy];
lpshowbuf[(pbi->bmiHeader.biHeight-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
}
}
}
void CDecompressDoc::OnHaarThree()
{
// TODO: Add your command handler code here
//pbi->bmiHeader.biHeight=8;
//pbi->bmiHeader.biWidth=8;
int linewidth;
int max, min; //记录变换后像素的最大最小值
int** image; //用于变换的整型图象数据
int** secondimage; //存放用于第二层变换的图象数据
int** threeimage; //存放用于第三层变换的图象数据
//int temp; //临时存放映射后的值,再转化为BYTE型
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
JiFlag=0; //Haar小波
//生成对lpBuf的二维数组索引
image=new int*[pbi->bmiHeader.biHeight];
for(int i=0;i<pbi->bmiHeader.biHeight;i++)
{
image[i]=new int[linewidth];
// image[i]=(int*)(lpBuf+i*linewidth);
}
for(int ii=pbi->bmiHeader.biHeight-1; ii>=0; ii--)
{
for(int jj=0; jj<linewidth; jj++)
image[ii][jj]=*(lpBuf+(pbi->bmiHeader.biHeight-1-ii)*linewidth+jj);
}
//ChangeImage(image);
max=min=image[0][0];
HaarTrans(pbi->bmiHeader.biHeight,linewidth,image,&max,&min);
GetCoefficient(image,pbi->bmiHeader.biHeight,linewidth);
secondimage=new int*[pbi->bmiHeader.biHeight>>1];
for(int h=0;h<pbi->bmiHeader.biHeight>>1;h++)
{
secondimage[h]=new int[linewidth>>1];
}
for(int m=0;m<pbi->bmiHeader.biHeight>>1;m++)
{
for(int n=0;n<linewidth>>1;n++)
secondimage[m][n]=image[2*m][2*n];
}
HaarTrans(pbi->bmiHeader.biHeight>>1,linewidth>>1,secondimage,&max,&min);
GetCoefficient(secondimage,pbi->bmiHeader.biHeight>>1,linewidth>>1);
threeimage=new int*[pbi->bmiHeader.biHeight>>2];
for(int hh=0;hh<pbi->bmiHeader.biHeight>>2;hh++)
{
threeimage[hh]=new int[linewidth>>2];
}
for(int mm=0;mm<pbi->bmiHeader.biHeight>>2;mm++)
{
for(int nn=0;nn<linewidth>>2;nn++)
threeimage[mm][nn]=secondimage[2*mm][2*nn];
}
HaarTrans(pbi->bmiHeader.biHeight>>2,linewidth>>2,threeimage,&max,&min);
GetCoefficient(threeimage,pbi->bmiHeader.biHeight>>2,linewidth>>2);
Three_ToLpshowbuf(image,secondimage,threeimage,&max,&min);
scale=3;
//释放内存
for(int z=0;z<pbi->bmiHeader.biHeight>>2;z++)
{
delete [] image[4*z];
delete [] image[4*z+1];
delete [] image[4*z+2];
delete [] image[4*z+3];
delete [] secondimage[2*z];
delete [] secondimage[2*z+1];
delete [] threeimage[z];
}
delete [] image;
delete [] secondimage;
delete [] threeimage;
UpdateAllViews(NULL, 0, NULL);
}
void CDecompressDoc::OnHaarFour()
{
// TODO: Add your command handler code here
//pbi->bmiHeader.biHeight=16;
//pbi->bmiHeader.biWidth=16;
int linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
int max,min;
int** image; //用于变换的整型图象数据
int** secondimage; //存放用于第二层变换的图象数据
int** threeimage; //存放用于第三层变换的图象数据
int** fourimage; //存放用于第四层变换的图象数据
JiFlag=0; //Haar小波
//生成对lpBuf的二维数组索引
image=new int*[pbi->bmiHeader.biHeight];
for(int i=0;i<pbi->bmiHeader.biHeight;i++)
{
image[i]=new int[linewidth];
// image[i]=(int*)(lpBuf+i*linewidth);
}
for(int ii=pbi->bmiHeader.biHeight-1; ii>=0; ii--)
{
for(int jj=0; jj<linewidth; jj++)
image[ii][jj]=*(lpBuf+(pbi->bmiHeader.biHeight-1-ii)*linewidth+jj);
}
//ChangeImage(image);
max=min=image[0][0];
HaarTrans(pbi->bmiHeader.biHeight,linewidth,image,&max,&min);
GetCoefficient(image,pbi->bmiHeader.biHeight,linewidth);
secondimage=new int*[pbi->bmiHeader.biHeight>>1];
for(int h=0;h<pbi->bmiHeader.biHeight>>1;h++)
{
secondimage[h]=new int[linewidth>>1];
}
for(int m=0;m<pbi->bmiHeader.biHeight>>1;m++)
{
for(int n=0;n<linewidth>>1;n++)
secondimage[m][n]=image[2*m][2*n];
}
HaarTrans(pbi->bmiHeader.biHeight>>1,linewidth>>1,secondimage,&max,&min);
GetCoefficient(secondimage,pbi->bmiHeader.biHeight>>1,linewidth>>1);
threeimage=new int*[pbi->bmiHeader.biHeight>>2];
for(int hh=0;hh<pbi->bmiHeader.biHeight>>2;hh++)
{
threeimage[hh]=new int[linewidth>>2];
}
for(int mm=0;mm<pbi->bmiHeader.biHeight>>2;mm++)
{
for(int nn=0;nn<linewidth>>2;nn++)
threeimage[mm][nn]=secondimage[2*mm][2*nn];
}
HaarTrans(pbi->bmiHeader.biHeight>>2,linewidth>>2,threeimage,&max,&min);
GetCoefficient(threeimage,pbi->bmiHeader.biHeight>>2,linewidth>>2);
fourimage=new int*[pbi->bmiHeader.biHeight>>3];
for(hh=0;hh<pbi->bmiHeader.biHeight>>3;hh++)
{
fourimage[hh]=new int[linewidth>>3];
}
for(mm=0;mm<pbi->bmiHeader.biHeight>>3;mm++)
{
for(int nn=0;nn<linewidth>>3;nn++)
fourimage[mm][nn]=threeimage[2*mm][2*nn];
}
HaarTrans(pbi->bmiHeader.biHeight>>3,linewidth>>3,fourimage,&max,&min);
GetCoefficient(fourimage,pbi->bmiHeader.biHeight>>3,linewidth>>3);
Four_ToLpshowbuf(image,secondimage,threeimage,fourimage,&max,&min);
scale=4;
//释放内存
for(int z=0;z<pbi->bmiHeader.biHeight>>3;z++)
{
delete [] image[8*z];
delete [] image[8*z+1];
delete [] image[8*z+2];
delete [] image[8*z+3];
delete [] image[8*z+4];
delete [] image[8*z+5];
delete [] image[8*z+6];
delete [] image[8*z+7];
delete [] secondimage[4*z];
delete [] secondimage[4*z+1];
delete [] secondimage[4*z+2];
delete [] secondimage[4*z+3];
delete [] threeimage[2*z];
delete [] threeimage[2*z+1];
delete [] fourimage[z];
}
delete [] image;
delete [] secondimage;
delete [] threeimage;
delete [] fourimage;
UpdateAllViews(NULL, 0, NULL);
}
void CDecompressDoc::Three_ToLpshowbuf(int **OneImage, int **SecondImage, int **ThreeImage, int *max, int *min)
{
int temp;
int linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
//把所有变换后的系数映射到0-255
for(int i3=0;i3<(pbi->bmiHeader.biHeight>>2);i3++)
{
for(int j3=0;j3<(linewidth>>2);j3++)
ThreeImage[i3][j3]=(ThreeImage[i3][j3]-*min)*255/(*max-*min);
}
for(int m3=0;m3<(pbi->bmiHeader.biHeight>>1);m3++)
{
for(int n3=0;n3<(linewidth>>1);n3++)
{
SecondImage[m3][n3]=(SecondImage[m3][n3]-*min)*255/(*max-*min);
OneImage[m3][n3]=(OneImage[m3][n3]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+m3][n3]=(OneImage[(pbi->bmiHeader.biHeight>>1)+m3][n3]-*min)*255/(*max-*min);
OneImage[m3][(linewidth>>1)+n3]=(OneImage[m3][(linewidth>>1)+n3]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+m3][(linewidth>>1)+n3]=(OneImage[(pbi->bmiHeader.biHeight>>1)+m3][(linewidth>>1)+n3]-*min)*255/(*max-*min);
}
}
//把所有系数放入lpshowbuf中显示出来
for(int x3=0;x3<pbi->bmiHeader.biHeight>>3;x3++)
{
for(int y3=0;y3<linewidth>>3;y3++)
{
temp=ThreeImage[2*x3][2*y3];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3)*linewidth+y3]=(BYTE)temp;
temp=ThreeImage[2*x3][2*y3+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3-(pbi->bmiHeader.biHeight>>3))*linewidth+y3]=(BYTE)temp;
temp=ThreeImage[2*x3+1][2*y3];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3)*linewidth+(linewidth>>3)-1+y3]=BYTE(temp);
temp=ThreeImage[2*x3+1][2*y3+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3-(pbi->bmiHeader.biHeight>>3))*linewidth+(linewidth>>3)-1+y3]=(BYTE)temp;
}
}
for(int x=0;x<pbi->bmiHeader.biHeight>>2;x++)
{
for(int y=0;y<linewidth>>2;y++)
{
//temp=secondimage[2*x][2*y];
//lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
}
}
for(int xx=0;xx<pbi->bmiHeader.biHeight>>1;xx++)
{
for(int yy=0;yy<linewidth>>1;yy++)
{
temp=OneImage[2*xx][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy];
lpshowbuf[(pbi->bmiHeader.biHeight-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
}
}
}
void CDecompressDoc::Four_ToLpshowbuf(int **OneImage, int **SecondImage, int **ThreeImage, int **FourImage, int *max, int *min)
{
int temp;
int linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
int i4,j4;
//把所有变换后的系数映射到0-255
for(i4=0;i4<(pbi->bmiHeader.biHeight>>3);i4++)
{
for(j4=0;j4<(linewidth>>3);j4++)
{
FourImage[i4][j4]=(FourImage[i4][j4]-*min)*255/(*max-*min);
ThreeImage[i4][j4]=(ThreeImage[i4][j4]-*min)*255/(*max-*min);
ThreeImage[(pbi->bmiHeader.biHeight>>3)+i4][j4]=(ThreeImage[(pbi->bmiHeader.biHeight>>3)+i4][j4]-*min)*255/(*max-*min);
ThreeImage[i4][(linewidth>>3)+j4]=(ThreeImage[i4][(linewidth>>3)+j4]-*min)*255/(*max-*min);
ThreeImage[(pbi->bmiHeader.biHeight>>3)+i4][(linewidth>>3)+j4]=(ThreeImage[(pbi->bmiHeader.biHeight>>3)+i4][(linewidth>>3)+j4]-*min)*255/(*max-*min);
}
}
for(i4=0;i4<(pbi->bmiHeader.biHeight>>1);i4++)
{
for(j4=0;j4<(linewidth>>1);j4++)
{
SecondImage[i4][j4]=(SecondImage[i4][j4]-*min)*255/(*max-*min);
OneImage[i4][j4]=(OneImage[i4][j4]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+i4][j4]=(OneImage[(pbi->bmiHeader.biHeight>>1)+i4][j4]-*min)*255/(*max-*min);
OneImage[i4][(linewidth>>1)+j4]=(OneImage[i4][(linewidth>>1)+j4]-*min)*255/(*max-*min);
OneImage[(pbi->bmiHeader.biHeight>>1)+i4][(linewidth>>1)+j4]=(OneImage[(pbi->bmiHeader.biHeight>>1)+i4][(linewidth>>1)+j4]-*min)*255/(*max-*min);
}
}
//把所有系数放入lpshowbuf中显示出来
for(i4=0;i4<pbi->bmiHeader.biHeight>>4;i4++)
{
for(j4=0;j4<linewidth>>4;j4++)
{
temp=FourImage[2*i4][2*j4];
lpshowbuf[(pbi->bmiHeader.biHeight-1-i4)*linewidth+j4]=(BYTE)temp;
temp=FourImage[2*i4][2*j4+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-i4-(pbi->bmiHeader.biHeight>>4))*linewidth+j4]=(BYTE)temp;
temp=FourImage[2*i4+1][2*j4];
lpshowbuf[(pbi->bmiHeader.biHeight-1-i4)*linewidth+(linewidth>>4)-1+j4]=BYTE(temp);
temp=FourImage[2*i4+1][2*j4+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-i4-(pbi->bmiHeader.biHeight>>4))*linewidth+(linewidth>>4)-1+j4]=(BYTE)temp;
}
}
for(int x3=0;x3<pbi->bmiHeader.biHeight>>3;x3++)
{
for(int y3=0;y3<linewidth>>3;y3++)
{
temp=ThreeImage[2*x3][2*y3+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3-(pbi->bmiHeader.biHeight>>3))*linewidth+y3]=(BYTE)temp;
temp=ThreeImage[2*x3+1][2*y3];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3)*linewidth+(linewidth>>3)-1+y3]=BYTE(temp);
temp=ThreeImage[2*x3+1][2*y3+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x3-(pbi->bmiHeader.biHeight>>3))*linewidth+(linewidth>>3)-1+y3]=(BYTE)temp;
}
}
for(int x=0;x<pbi->bmiHeader.biHeight>>2;x++)
{
for(int y=0;y<linewidth>>2;y++)
{
//temp=secondimage[2*x][2*y];
//lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x)*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
temp=SecondImage[2*x+1][2*y+1];
lpshowbuf[(pbi->bmiHeader.biHeight-1-x-(pbi->bmiHeader.biHeight>>2))*linewidth+(linewidth>>2)-1+y]=(BYTE)temp;
}
}
for(int xx=0;xx<pbi->bmiHeader.biHeight>>1;xx++)
{
for(int yy=0;yy<linewidth>>1;yy++)
{
temp=OneImage[2*xx][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy];
lpshowbuf[(pbi->bmiHeader.biHeight-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
temp=OneImage[2*xx+1][2*yy+1];
lpshowbuf[((pbi->bmiHeader.biHeight>>1)-1-xx)*linewidth+(linewidth>>1)-1+yy]=(BYTE)temp;
}
}
}
void CDecompressDoc::OnD97One()
{
// TODO: Add your command handler code here
int linewidth;
int max, min; //记录变换后像素的最大最小值
int** image; //用于变换的整型图象数据
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
JiFlag=1; //D97小波
//生成对lpBuf的二维数组索引
image=new int*[pbi->bmiHeader.biHeight];
for(int i=0;i<pbi->bmiHeader.biHeight;i++)
{
image[i]=new int[linewidth];
// image[i]=(int*)(lpBuf+i*linewidth);
}
for(int ii=pbi->bmiHeader.biHeight-1; ii>=0; ii--)
{
for(int jj=0; jj<linewidth; jj++)
image[ii][jj]=*(lpBuf+(pbi->bmiHeader.biHeight-1-ii)*linewidth+jj);
}
max=min=image[0][0];
D97Trans(pbi->bmiHeader.biHeight,linewidth,image,&max,&min);
GetCoefficient(image,pbi->bmiHeader.biHeight,linewidth);
One_ToLpshowbuf(image, &max, &min);
scale=1;
//释放内存
for(int z=0;z<pbi->bmiHeader.biHeight;z++)
{
delete [] image[z];
}
delete [] image;
UpdateAllViews(NULL, 0, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -