Exemple #1
0
void __fastcall TForm1::Button4Click(TObject *Sender)
{
        int flag=StrToInt(Edit1->Text);
        TrackBar1Update();
        Image1->Picture->Bitmap=map;
        Image2->Visible=true;
        Image2->Picture->Bitmap=map;
        for(int x=0;x<map->Width;x++)
        for(int y=0;y<map->Height;y++){
                double *buff=new double[3];
                double *N=new double[3];
                buff[0]=GetRValue(map->Canvas->Pixels[x][y]);
                buff[1]=GetGValue(map->Canvas->Pixels[x][y]);
                buff[2]=GetBValue(map->Canvas->Pixels[x][y]);

                if(ComboBox1->Text=="RGB"){
                                N[0]=N[1]=N[2]=256/flag;
                                buff=Quantization(buff,N);
                }
                else if(ComboBox1->Text=="YUV"){
                                buff=RtoY(buff,0);
                                buff[1]+=(222.36/2);
                                buff[2]+=(313.65/2);
                                N[0]=256/flag;
                                N[1]=222.36/flag;
                                N[2]=313.65/flag;
                                buff[1]-=(222.36/2);
                                buff[2]-=(313.65/2);
                                buff=Quantization(buff,N);
                                buff=YtoR(buff,0);
                }
                else if(ComboBox1->Text=="YIQ"){
                                buff=RtoY(buff,1);
                                buff[1]+=(303.96/2);
                                buff[2]+=(266.22/2);
                                N[0]=256/flag;
                                N[1]=303.96/flag;
                                N[2]=266.22/flag;
                                buff[1]-=(303.96/2);
                                buff[2]-=(266.22/2);
                                buff=Quantization(buff,N);
                                buff=YtoR(buff,1);
                }
                for(int i=0;i<3;i++){
                        if(buff[i]>255)        buff[i]=255;
                        else if(buff[i]<0)     buff[i]=0;
                }
                Image2->Canvas->Pixels[x][y]=(TColor)RGB((int)buff[0],(int)buff[1],(int)buff[2]);

                delete buff;
        }
}
int main( int argc, char **argv )  
{  
	bmpreader pict(argv[1]);//实例一个bmp读取类,获得相应的信息头和像素数据,并根据不同大小的像素位进行填充图像
	BYTE KeyInput[16];//输入的密钥,传送走的密钥
	double pk[16];//迭代前的各个盒子值
	double nk[16];//迭代后的各个盒子值
	int picH = pict.picH;
	int picW = pict.picW;//原始图的高宽
	int picS = pict.csize;//填充后的整体大小
	int bnum = pict.Bnum;//分块数
	int eachtime = picS/bnum;
	printf("each time = %d Num = %d\n",eachtime,bnum);
	//BYTE RL[eachtime];//每次的随机序列
	//RL 得变成double的了。。方便运算么
	cout<<"Please input a Keyline...(16byte-128bit)"<<endl;
	cout<<"1234567890123456<-Here the ending is.."<<endl;
	cin>>KeyInput;
	//获得x初始盒子,迭代times次,消除。。
	Xprod(KeyInput,pk);
	NKProd(pk,nk,500);
	//然后产生随机序列并映射到(-0.5,0.5)直接利用混沌盒子的值!?yes!!(8x4-8x2+1)~(-1,1)的,直接处理出来就好了
	BYTE BK[eachtime];
	double YUV[eachtime];
	double rla[eachtime];
	double rlb[eachtime];
	double L[eachtime];
	double R[eachtime];
	MatrixXd Lym(8,8);
	MatrixXd Rym(8,8);
	MatrixXd Lum(8,8);
	MatrixXd Rum(8,8);
	MatrixXd Lvm(8,8);
	MatrixXd Rvm(8,8);
	MatrixXd Xym(8,8);
	MatrixXd Xum(8,8);
	MatrixXd Xvm(8,8);
	MatrixXd Yym(8,8);
	MatrixXd Yum(8,8);
	MatrixXd Yvm(8,8);
	
	for(int k = 0 ; k < bnum ; k++){
		memcpy(BK,pict.PicS+k*eachtime,eachtime);
		//RGB to YUV
		RtoY(BK,YUV,eachtime);
		//一次产生a b 以计算出L & R
		rlProd(pk,nk,rla,eachtime);
		rlProd(pk,nk,rlb,eachtime);
		//L&R 
		LProd(rla,L);
		RProd(rlb,R);
		for(int i=0;i<8;i++){
		    for(int j=0;j<8;j++){
		    	Xym(i,j) = YUV[3*(8*i+j)+0];
			Xum(i,j) = YUV[3*(8*i+j)+1];
			Xvm(i,j) = YUV[3*(8*i+j)+2];
			Lym(i,j) = L[3*(8*i+j)+0];
			Lum(i,j) = L[3*(8*i+j)+1];
			Lvm(i,j) = L[3*(8*i+j)+2];
			Rym(i,j) = R[3*(8*i+j)+0];
			Rum(i,j) = R[3*(8*i+j)+1];
			Rvm(i,j) = R[3*(8*i+j)+2];

		    }
		}//得到YUV三个分量的X矩阵,3个L&R
		Yym = Lym*Xym*Rym;
		Yum = Lum*Xum*Rum;
		Yvm = Lvm*Xvm*Rvm;
		/*if(k%100 == 0){
		    	cout<<Lym<<endl<<Lum<<endl<<Lvm<<endl<<Rym<<endl<<Rum<<endl<<Rvm<<endl;
			cout<<k<<"::"<<endl<<"yym:"<<endl<<Yym<<endl<<"yum:"<<endl<<Yum<<endl<<"yvm:"<<endl<<Yvm<<endl;
		}*/

	}
	
	return 0;  
}