ImageconvertTool.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "ImageconvertTool.h"
  2. imageconverttool::imageconverttool(QWidget *parent) : ToolInterface(parent), ui(new Ui::imageconverttool)
  3. {
  4. ui->setupUi(this);
  5. ui->label2->setVisible(false);
  6. ui->comboBox_port->setVisible(false);
  7. ui->comboBox->setView(new QListView());
  8. ui->comboBox_port->setView(new QListView());
  9. }
  10. imageconverttool::~imageconverttool()
  11. {
  12. delete ui;
  13. }
  14. bool imageconverttool::Serialized(QDataStream& ar, bool bIsOut)
  15. {
  16. int paranum;//参数数量
  17. if (bIsOut)//保存参数流程
  18. {
  19. paranum = 1;
  20. ar << paranum;//先保存参数数量
  21. ar << (int)1 << ui->comboBox->currentIndex();
  22. }
  23. else//加载参数流程,参数加载顺序一定要跟保存顺序一致
  24. {
  25. int nCurrentIndex = 0;
  26. int para;
  27. ar >> paranum;//读取参数数量
  28. for (int i = 0; i < paranum; i++)
  29. {
  30. ar >> para;
  31. switch (para)
  32. {
  33. case 1: ar >> nCurrentIndex; break;
  34. default:
  35. {
  36. qWarning() << "Serialized(In) Error";
  37. return false;
  38. }
  39. break;
  40. }
  41. }
  42. {
  43. ui->comboBox->setCurrentIndex(nCurrentIndex);
  44. emit updateParameter(ShowParameter());
  45. }
  46. }
  47. return true;
  48. }
  49. QString imageconverttool::ShowParameter()
  50. {
  51. QString str;
  52. str += ui->comboBox->currentText();
  53. if(ui->comboBox_port->currentIndex() >= 0)
  54. {
  55. str += ",";
  56. str += ui->comboBox_port->currentText();
  57. }
  58. return str;
  59. }
  60. int imageconverttool::Execute()
  61. {
  62. int result = 1;
  63. try
  64. {
  65. if(ui->comboBox->currentIndex() == 0)
  66. {
  67. Rgb1ToGray(m_InImage, &m_OutImage);
  68. }
  69. if(ui->comboBox->currentIndex() == 1)
  70. {
  71. HObject result1, result2;
  72. if(ui->comboBox_port->currentIndex() == 0)
  73. {
  74. Decompose3(m_InImage, &m_OutImage, &result1, &result2);
  75. }
  76. if(ui->comboBox_port->currentIndex() == 1)
  77. {
  78. Decompose3(m_InImage, &result1, &m_OutImage, &result2);
  79. }
  80. if(ui->comboBox_port->currentIndex() == 2)
  81. {
  82. Decompose3(m_InImage, &result1, &result2, &m_OutImage);
  83. }
  84. }
  85. if(ui->comboBox->currentIndex() == 2)
  86. {
  87. HObject result1, result2;
  88. if(ui->comboBox_port->currentIndex() == 0)
  89. {
  90. TransToRgb(m_InImage, m_InImage, m_InImage, &m_OutImage, &result1, &result2, "hsv");
  91. }
  92. if(ui->comboBox_port->currentIndex() == 1)
  93. {
  94. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &m_OutImage, &result2, "hsv");
  95. }
  96. if(ui->comboBox_port->currentIndex() == 2)
  97. {
  98. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &result2, &m_OutImage, "hsv");
  99. }
  100. }
  101. if(ui->comboBox->currentIndex() == 3)
  102. {
  103. HObject result1, result2;
  104. if(ui->comboBox_port->currentIndex() == 0)
  105. {
  106. TransToRgb(m_InImage, m_InImage, m_InImage, &m_OutImage, &result1, &result2, "hsi");
  107. }
  108. if(ui->comboBox_port->currentIndex() == 1)
  109. {
  110. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &m_OutImage, &result2, "hsi");
  111. }
  112. if(ui->comboBox_port->currentIndex() == 2)
  113. {
  114. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &result2, &m_OutImage, "hsi");
  115. }
  116. }
  117. if(ui->comboBox->currentIndex() == 4)
  118. {
  119. HObject result1, result2;
  120. if(ui->comboBox_port->currentIndex() == 0)
  121. {
  122. TransToRgb(m_InImage, m_InImage, m_InImage, &m_OutImage, &result1, &result2, "yuv");
  123. }
  124. if(ui->comboBox_port->currentIndex() == 1)
  125. {
  126. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &m_OutImage, &result2, "yuv");
  127. }
  128. if(ui->comboBox_port->currentIndex() == 2)
  129. {
  130. TransToRgb(m_InImage, m_InImage, m_InImage, &result1, &result2, &m_OutImage, "yuv");
  131. }
  132. }
  133. }
  134. catch(...)
  135. {
  136. }
  137. return result;
  138. }
  139. void imageconverttool::on_comboBox_currentIndexChanged(int index)
  140. {
  141. ui->comboBox_port->setCurrentIndex(0);
  142. if(index > 0)
  143. {
  144. ui->label2->setVisible(true);
  145. ui->comboBox_port->setVisible(true);
  146. }
  147. else
  148. {
  149. ui->label2->setVisible(false);
  150. ui->comboBox_port->setVisible(false);
  151. }
  152. emit updateParameter(ShowParameter());
  153. }
  154. void imageconverttool::on_comboBox_port_currentIndexChanged(int index)
  155. {
  156. emit updateParameter(ShowParameter());
  157. }