package CamVideo;

import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Composite;

public class VideoCtrl {
	
	static OleAutomation oleAutomation;
	static OleControlSite oleControl;
	static OleFrame oleFrame ;
	private int OpenFormat=1;
	private int ResolutionCount=0;
	private int cam_id=0;
	

	public int InitOcx(Composite  parent)
	{
	     oleFrame = new OleFrame(parent, SWT.NONE);
	     oleControl = new OleControlSite(oleFrame, SWT.NONE, "BAUCHEOCX.BaucheOcxCtrl.1");
		//OleAutomation类用来执行ActiveX中的方法
		 oleAutomation = new OleAutomation(oleControl);
		 oleControl.doVerb(OLE.OLEIVERB_SHOW);
		 		 
	    return 0;
	}
	
	public  void SetFrameSize(int w,int h)
	{
		oleFrame.setSize(w,h);
	}
	public  void SetClientSize(int w,int h)
	{
		oleControl.setSize(w,h);
	}
	
	public  void SetCamID(int id)
	{
		cam_id=id;
	    int SupportFormat=1;
		int FormatSum  = 0;  //设备支持的视频格式代号总和
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetFormatCount" });
		int dispIdMember = regspid[0];
		Variant[] var_arg = new Variant[1];
		var_arg[0] = new Variant(cam_id);
		Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
		int scount=result.getInt();
		

        	regspid=oleAutomation.getIDsOfNames(new String[] { "GetFormatCount" });
        	dispIdMember = regspid[0];
        	var_arg = new Variant[1];
        	var_arg[0] = new Variant(cam_id);
        	result=oleAutomation.invoke(dispIdMember,var_arg);	
            FormatSum = result.getInt();    //GetFormatNumber（）获取设备支持的视频格式代号
		
           
        //判断视频格式代号总和的值
        switch(FormatSum)
        {
            case 1:   //（设备只支持MJPG格式）
                OpenFormat = 1 ;     //打开格式为MJPG
                SupportFormat = 1;
                break;
            case 2:   //（设备只支持YUY2格式）
                OpenFormat = 0 ;     //打开格式为YUY
                SupportFormat = 2;
                break;
            case 3:   //（设备支持MJPG与YUY2两种格式）
                OpenFormat = 1 ;     //默认打开格式为MJPG
                SupportFormat = 1;
                break;
        }
        regspid=oleAutomation.getIDsOfNames(new String[] { "GetResolutionCount" });
    	dispIdMember = regspid[0];
    	var_arg = new Variant[2];
    	var_arg[0] = new Variant(cam_id);
    	var_arg[1] = new Variant(SupportFormat);
    	result=oleAutomation.invoke(dispIdMember,var_arg);
        ResolutionCount = result.getInt(); //获取设备支持的分辨率数目
	}
	
	//获取分辨率数目	
	public  int GetResolutionCount()
	{		
		return this.ResolutionCount;
	}
	
	//获取分辨率
	public  String GetResolutionStr(int index)
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetResolution" });
		int dispIdMember = regspid[0];
		Variant[] var_arg = new Variant[1];
		var_arg[0] = new Variant(index);
		Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
		return result.getString();
	}
	
	//获取设备数目
	public int GetDeviceCount()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetDevCount" });
		int dispIdMember = regspid[0];
		Variant result=oleAutomation.invoke(dispIdMember);	
		return result.getInt();
	}
	
	//获取设备名称
	public String GetDeviceName(int index)
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetDevFriendName" });
		int dispIdMember = regspid[0];
		Variant[] var_arg = new Variant[1];
		var_arg[0] = new Variant(index);
		Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
		return result.getString();
	}
	
	
	//开启设备
	public  int StartPreview(int width,int height)
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_Open" });
		int dispIdMember = regspid[0];
		
		//Variant数组的长度为方法参数的个数
		Variant[] var_arg = new Variant[4];
		var_arg[0] = new Variant(cam_id);
		var_arg[1] = new Variant(OpenFormat);
		var_arg[2] = new Variant(width);
		var_arg[3] = new Variant(height);
		
		Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
		return result.getInt();
	}
	
	//关闭设备
	public  void StopPreview()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_Close" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//放大
	public void ZoomOut()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_ZoomOut" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//缩小
	public void ZoomIn()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_ZoomIn" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//真实大小
	public void TrueSize()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "TrueSize" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//适合大小
	public void BestSize()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "BestSize" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//左旋
	public void LeftRoate()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_RotateL" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//右旋
	public void RightRoate()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CAM_RotateR" });
		int dispIdMember = regspid[0];
		oleAutomation.invoke(dispIdMember);
	}
	
	//启动身份证模块功能
	public int StartIDCard()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "StartIDCard" });
		int dispIdMember = regspid[0];
		Variant result=oleAutomation.invoke(dispIdMember);	
		return result.getInt();
	}
	
	//读卡
	public int GetOneIC()
	{
		int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetOneIC" });
		int dispIdMember = regspid[0];
		Variant result=oleAutomation.invoke(dispIdMember);	
		return result.getInt();
	}
	
	//获取身份证的具体信息
		public String GetICValues(String index)
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetICValues" });
			int dispIdMember = regspid[0];
			Variant[] var_arg = new Variant[1];
			var_arg[0] = new Variant(index);
			Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
			return result.getString();
		}
		
	//获取身份证的图片的base64码
		public String GetICPicture()
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetICPicture" });
			int dispIdMember = regspid[0];
			Variant result=oleAutomation.invoke(dispIdMember);	
			return result.getString();
		}	
		
		
		public int setFilePath(String index)
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "setFilePath" });
			int dispIdMember = regspid[0];
			Variant[] var_arg = new Variant[1];
			var_arg[0] = new Variant(index);
			Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
			return result.getInt();
		}
		
		public int GetMainCameraID(int index)
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "GetMainCameraID" });
			int dispIdMember = regspid[0];
			Variant[] var_arg = new Variant[1];
			var_arg[0] = new Variant(index);
			Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
			return result.getInt();
		}
		
		public String CaptureImageJava()
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "CaptureImageJava" });
			int dispIdMember = regspid[0];
			Variant result=oleAutomation.invoke(dispIdMember);	
			return result.getString();
		}	
		
		
		public void IsImageBase64(int index)
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "IsImageBase64" });
			int dispIdMember = regspid[0];
			Variant[] var_arg = new Variant[1];
			var_arg[0] = new Variant(index);
			oleAutomation.invoke(dispIdMember,var_arg);	
		}

		public int IsImageBase64(int index)
		{
			int[] regspid = oleAutomation.getIDsOfNames(new String[] { "IsImageBase64" });
			int dispIdMember = regspid[0];
			Variant[] var_arg = new Variant[1];
			var_arg[0] = new Variant(index);
			Variant result=oleAutomation.invoke(dispIdMember,var_arg);	
			return result.getInt();
		}
		
		

}
