123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PaintDotNet.Base.SettingModel;
- using TUCamera;
- using System.Threading;
- namespace PaintDotNet.ImageCollect.CameraComponent
- {
- public partial class AdjustWhiteBalanceControl : UserControl
- {
- private TUCamera.TUCamera m_camera;
- private CameraParamModel m_cameraParamModel;
- private bool m_use;
- private void InitializeLanguageText()
- {
- this.groupBox3.Text = PdnResources.GetString("Menu.Image.WhiteBalance.Text");
- this.button1.Text = PdnResources.GetString("Menu.Primarywhitebalance.Text");
- this.label12.Text = PdnResources.GetString("Menu.Blue.text");
- this.label11.Text = PdnResources.GetString("Menu.green.text");
- this.label10.Text = PdnResources.GetString("Menu.red.text");
- this.label9.Text = PdnResources.GetString("Menu.yellow.text");
- this.label8.Text = PdnResources.GetString("Menu.Magenta.text");
- this.label7.Text = PdnResources.GetString("Menu.aqua.text");
- this.ColourCheckBox.Text = PdnResources.GetString("Menu.Displaycolorvaluechannel.text");
- this.button3.Text = PdnResources.GetString("Menu.auto.text");
- this.button2.Text = PdnResources.GetString("Menu.Manual.text");
- }
- public AdjustWhiteBalanceControl(CameraParamModel model, bool use)
- {
- InitializeComponent();
- InitializeLanguageText();
- m_use = use;
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- m_cameraParamModel = model;
- InitializeControlData();
- }
- public void ReLoad(CameraParamModel model, bool use)
- {
- m_cameraParamModel = model;
- m_use = use;
- InitializeControlData();
- }
- private void InitializeControlData()
- {
- if (m_camera.IsOpen())
- {
- // Get red channel range
- int minVal = 0;
- int maxVal = 0;
- m_camera.GetColorChannelRang(ColorChannel.RED, ref minVal, ref maxVal);
- redChannelTB.SetRange(minVal, maxVal);
- // Get green channel range
- m_camera.GetColorChannelRang(ColorChannel.GREEN, ref minVal, ref maxVal);
- greenChannelTB.SetRange(minVal, maxVal);
- // Get blue channel range
- m_camera.GetColorChannelRang(ColorChannel.BLUE, ref minVal, ref maxVal);
- blueChannelTB.SetRange(minVal, maxVal);
- }
- // 颜色值
- int redChannelValue = (int)m_cameraParamModel.parame.RedChannel;
- if (redChannelValue >= this.redChannelTB.Minimum && redChannelValue <= this.redChannelTB.Maximum)
- {
- this.redChannelTB.Value = redChannelValue;
- }
- int greenChannelValue = (int)m_cameraParamModel.parame.GreenChannel;
- if (greenChannelValue >= this.greenChannelTB.Minimum && greenChannelValue <= this.greenChannelTB.Maximum)
- {
- this.greenChannelTB.Value = greenChannelValue;
- }
- int blueChannelValue = (int)m_cameraParamModel.parame.BlueChannel;
- if (blueChannelValue >= this.blueChannelTB.Minimum && blueChannelValue <= this.blueChannelTB.Maximum)
- {
- this.blueChannelTB.Value = blueChannelValue;
- }
- // 白平衡
- if (m_cameraParamModel.parame.WhiteBalance == 1)
- {
- AutoWhiteBalance(true);
- }
- else
- {
- if (m_cameraParamModel.parame.FMExposure == 1)
- {
- m_camera.SetColorTemperatureByString("3200K");
- }
- else if (m_cameraParamModel.parame.FMExposure == 2)
- {
- m_camera.SetColorTemperatureByString("5500K");
- }
- AutoWhiteBalance(false);
- }
- // 显示颜色值通道
- if (m_cameraParamModel.parame.ShowColorPBoxFlag == 1)
- {
- this.ColourCheckBox.Checked = true;
- }
- else
- {
- this.ColourCheckBox.Checked = false;
- }
- }
- /// <summary>
- /// 是否自动白平衡 修改显示样式
- /// </summary>
- /// <param name="s"></param>
- private void AutoWhiteBalance(Boolean isWhiteBalance)
- {
- if (isWhiteBalance)
- {
- this.redChannelTB.Enabled = false;
- this.greenChannelTB.Enabled = false;
- this.blueChannelTB.Enabled = false;
- m_cameraParamModel.parame.WhiteBalance = 1;
- if (m_use)
- {
- // 自动白平衡
- m_camera.SetWhiteBalanceMode(WhiteBalanceMode.AUTO);
- }
- }
- else
- {
- m_cameraParamModel.parame.WhiteBalance = 0;
- if (m_use)
- {
- // 手动白平衡
- m_camera.SetWhiteBalanceMode(WhiteBalanceMode.MANUAL);
- }
- }
- try
- {
- this.Invoke(new Action(UpdateColorTemperature));
- }
- catch
- { }
- }
- private void UpdateColorTemperature()
- {
- button2.Enabled = true;
- button3.Enabled = true;
- button4.Enabled = true;
- button5.Enabled = true;
- uint cct = 0;
- double redChannel = 0;
- double greenChannel = 0;
- double blueChannel = 0;
- int rst = m_camera.GetColorTemperature(ref redChannel, ref greenChannel, ref blueChannel, ref cct);
- m_cameraParamModel.parame.RedChannel = redChannel;
- m_cameraParamModel.parame.GreenChannel = greenChannel;
- m_cameraParamModel.parame.BlueChannel = blueChannel;
- // 颜色值
- this.redChannelTB.Value = (int)m_cameraParamModel.parame.RedChannel;
- this.greenChannelTB.Value = (int)m_cameraParamModel.parame.GreenChannel;
- this.blueChannelTB.Value = (int)m_cameraParamModel.parame.BlueChannel;
- ////string colorTemperatureString = m_camera.GetColorTemperatureString(cct);
- this.redChannelTB.Enabled = false;
- this.greenChannelTB.Enabled = false;
- this.blueChannelTB.Enabled = false;
- if (m_cameraParamModel.parame.WhiteBalance == 1)
- {
- button3.Enabled = false;
- }
- else
- {
- switch (m_cameraParamModel.parame.FMExposure)
- {
- case 0:
- button2.Enabled = false;
- this.redChannelTB.Enabled = true;
- this.greenChannelTB.Enabled = true;
- this.blueChannelTB.Enabled = true;
- break;
- case 1:
- button4.Enabled = false;
- break;
- case 2:
- button5.Enabled = false;
- break;
- }
- }
- ColourCheckBox.Focus();
- }
- /// <summary>
- /// 手动白平衡
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 0;
- AutoWhiteBalance(false);
- }
- /// <summary>
- /// 自动白平衡按钮点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- AutoWhiteBalance(true);
- Thread.Sleep(1500);
- UpdateColorTemperature();
- }
- /// <summary>
- /// 自动一次按钮点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- AutoWhiteBalance(true);
- new Task(() =>
- {
- Thread.Sleep(500);
- m_cameraParamModel.parame.FMExposure = 0;
- AutoWhiteBalance(false);
- }).Start();
- }
- /// <summary>
- /// 色温3200K
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 1;
- m_camera.SetColorTemperatureByString("3200K");
- AutoWhiteBalance(false);
- }
- /// <summary>
- /// 色温5500K
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 2;
- m_camera.SetColorTemperatureByString("5500K");
- AutoWhiteBalance(false);
- }
- private void redChannelTB_ValueChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.RedChannel = ((TrackBar)sender).Value;
- // 设置到相机
- if (m_use)
- {
- m_camera.SetRedGain(m_cameraParamModel.parame.RedChannel); //usec
- }
- }
- private void greenChannelTB_ValueChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.GreenChannel = ((TrackBar)sender).Value;
- // 设置到相机
- if (m_use)
- {
- m_camera.SetGreeGain(m_cameraParamModel.parame.GreenChannel); //usec
- }
- }
- private void blueChannelTB_ValueChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.BlueChannel = ((TrackBar)sender).Value;
- // 设置到相机
- if (m_use)
- {
- m_camera.SetBlueGain(m_cameraParamModel.parame.BlueChannel); //usec
- }
- }
- private void xianshiColourCheckBox_CheckedChanged(object sender, EventArgs e)
- {
- CheckBox cb = (CheckBox)sender;
- this.yanghongsepictureBox.Visible = cb.Checked;
- this.yanghongsepictureBox.Visible = cb.Checked; ;
- this.lansepictureBox.Visible = cb.Checked;
- this.hongsepictureBox.Visible = cb.Checked;
- this.lansepictureBox.Visible = cb.Checked;
- this.huangsepictureBox.Visible = cb.Checked;
- this.lanlvpictureBox.Visible = cb.Checked;
- this.lvsepictureBox.Visible = cb.Checked;
- this.m_cameraParamModel.parame.ShowColorPBoxFlag = cb.Checked ? 1 : 0;
- }
- }
- }
|