From ff106104a6e31676ce145d77e3a28e28ccd2ed08 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 6 May 2022 17:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=BA=E5=9F=9F=E8=A3=81?= =?UTF-8?q?=E5=89=AA=E5=8A=9F=E8=83=BD=E5=92=8Cgamma=E6=9B=B2=E7=BA=BF?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/hg_settingdialog.cpp | 294 +++++++++++++++++++++++++++++++ app/scanner/hg_settingdialog.h | 22 +++ app/scanner/setpicclrtool.cpp | 6 +- 3 files changed, 320 insertions(+), 2 deletions(-) diff --git a/app/scanner/hg_settingdialog.cpp b/app/scanner/hg_settingdialog.cpp index e0b720cc..46a9e9d3 100644 --- a/app/scanner/hg_settingdialog.cpp +++ b/app/scanner/hg_settingdialog.cpp @@ -2,12 +2,35 @@ #include #include +#include "cutpapertool.h" +#include "setpicclrtool.h" +#include "base/HGDef.h" +#include "../../utility/HGString.h" hg_settingdialog::hg_settingdialog(void *handle, QWidget *parent , DEVCFG* cfg) : QDialog(parent) , schemes_(cfg), cur_ind_(cfg->cur_scheme), changed_count_(0), save_(false) { + m_dpiId = -1; + m_dpiValue = 200; + m_paperSizeId = -1; + m_paperSizeValue.clear(); + m_cutLeftId = -1; + m_cutTopId = -1; + m_cutRightId = -1; + m_cutBottomId = -1; + m_cutWidth = 210; + m_cutHeight = 297; + m_cutLeftValue = 0; + m_cutTopValue = 0; + m_cutRightValue = 210; + m_cutBottomValue = 297; + + m_colorModeId = -1; + m_colorModeValue.clear(); + memset(&m_gammaData, 0, sizeof(m_gammaData)); + m_handle = handle; initUi(); on_select_scheme(cur_ind_, false); @@ -560,6 +583,73 @@ void hg_settingdialog::createUI() break; } } //switch(opt->type) + + if (Utf8ToStdString(opt->title) == "分辨率") + { + m_dpiId = i + 1; + m_dpiValue = m_list_defaultOptions.at(i).second.toInt(); + } + + if (Utf8ToStdString(opt->title) == "纸张尺寸") + { + m_paperSizeId = i + 1; + m_paperSizeValue = m_list_defaultOptions.at(i).second.toString(); + } + + if (0 == strcmp(opt->name, "tl-x")) + { + m_cutLeftId = i + 1; + m_cutLeftValue = m_list_defaultOptions.at(i).second.toInt(); + if (opt->constraint_type == SANE_CONSTRAINT_RANGE) + m_cutWidth = opt->constraint.range->max; + } + else if (0 == strcmp(opt->name, "tl-y")) + { + m_cutTopId = i + 1; + m_cutTopValue = m_list_defaultOptions.at(i).second.toInt(); + if (opt->constraint_type == SANE_CONSTRAINT_RANGE) + m_cutHeight = opt->constraint.range->max; + } + else if (0 == strcmp(opt->name, "br-x")) + { + m_cutRightId = i + 1; + m_cutRightValue = m_list_defaultOptions.at(i).second.toInt(); + } + else if (0 == strcmp(opt->name, "br-y")) + { + m_cutBottomId = i + 1; + m_cutBottomValue = m_list_defaultOptions.at(i).second.toInt(); + } + + if (Utf8ToStdString(opt->title) == "分辨率") + { + QPushButton* pushButton = new QPushButton(this); + pushButton->setText(StdStringToUtf8("区域裁剪").c_str()); + pushButton->setFixedWidth(120); + widget->layout()->addWidget(pushButton); + + connect(pushButton, SIGNAL(clicked(bool)), this, SLOT(slot_cutButtonClicked())); + } + + if (Utf8ToStdString(opt->title) == "颜色模式") + { + m_colorModeId = i + 1; + m_colorModeValue = m_list_defaultOptions.at(i).second.toString(); + } + + if (Utf8ToStdString(opt->title) == "伽玛") + { + unsigned int len = sizeof(SANE_Gamma); + sane_io_control(m_handle, IO_CTRL_CODE_GET_CUSTOM_GAMMA, &m_gammaData, &len); + + QPushButton* pushButton = new QPushButton(this); + pushButton->setText(StdStringToUtf8("伽马设置").c_str()); + pushButton->setFixedWidth(120); + widget->layout()->addWidget(pushButton); + + connect(pushButton, SIGNAL(clicked(bool)), this, SLOT(slot_gammaButtonClicked())); + } + if(init.opt != -1) init_vals_.push_back(init); } //for @@ -800,6 +890,15 @@ void hg_settingdialog::slot_string_list_comboBoxClicked() SANE_Int id = comboBox->property("controls_id").toInt(); std::string comboBoxcurrentItem(comboBox->currentText().toUtf8()); + if (id == m_paperSizeId) + { + m_paperSizeValue = comboBoxcurrentItem.c_str(); + } + else if (id == m_colorModeId) + { + m_colorModeValue = comboBoxcurrentItem.c_str(); + } + const SANE_Option_Descriptor* opt = nullptr; for(int i = 0; i < m_list_getOpt.size(); i++) if (m_list_getOpt.at(i).first == id) @@ -845,6 +944,196 @@ void hg_settingdialog::slot_pushButtonClicked() updateUIStatus(); } +void hg_settingdialog::slot_cutButtonClicked() +{ + //int width = 0.03937 * m_cutWidth * m_dpiValue; + //int height = 0.03937 * m_cutHeight * m_dpiValue; + int left = 0.03937 * m_cutLeftValue * m_dpiValue; + int top = 0.03937 * m_cutTopValue * m_dpiValue; + int right = 0.03937 * m_cutRightValue * m_dpiValue; + int bottom = 0.03937 * m_cutBottomValue * m_dpiValue; + + CutPaperTool dlg(this); + dlg.setPaperType(m_dpiValue, m_paperSizeValue, m_cutWidth); + QRectF rc(left, top, right - left, bottom - top); + dlg.setCutRect(rc); + if (dlg.exec()) + { + QRectF rcRet = dlg.getCutRectPixel(); + + m_cutLeftValue = rcRet.left() / (0.03937 * m_dpiValue); + m_cutTopValue = rcRet.top() / (0.03937 * m_dpiValue); + m_cutRightValue = rcRet.right() / (0.03937 * m_dpiValue); + m_cutBottomValue = rcRet.bottom() / (0.03937 * m_dpiValue); + + SANE_Int info; + sane_control_option(m_handle, m_cutLeftId, SANE_ACTION_SET_VALUE, &m_cutLeftValue, &info); + sane_control_option(m_handle, m_cutTopId, SANE_ACTION_SET_VALUE, &m_cutTopValue, &info); + sane_control_option(m_handle, m_cutRightId, SANE_ACTION_SET_VALUE, &m_cutRightValue, &info); + sane_control_option(m_handle, m_cutBottomId, SANE_ACTION_SET_VALUE, &m_cutBottomValue, &info); + } +} + +void hg_settingdialog::slot_gammaButtonClicked() +{ + setPicClrTool dlg(this); + + int colorMode; // 0-彩色, 1-灰度 + if (Utf8ToStdString(m_colorModeValue.toUtf8()) == "256级灰度" + || Utf8ToStdString(m_colorModeValue.toUtf8()) == "黑白") + { + colorMode = 1; + + QList keyTable; + for (int i = 0; i < m_gammaData.pt_count; ++i) + { + QPoint pt(m_gammaData.keypoint[i].x, m_gammaData.keypoint[i].y); + keyTable.append(pt); + } + + if (!keyTable.empty()) + { + dlg.setGrayKeyTable(keyTable); + } + } + else + { + colorMode = 0; + + QList keyTable; + for (int i = 0; i < m_gammaData.pt_count; ++i) + { + QPoint pt(m_gammaData.keypoint[i].x, m_gammaData.keypoint[i].y); + keyTable.append(pt); + } + + QList rKeyTable; + for (int i = 0; i < m_gammaData.pt_count_r; ++i) + { + QPoint pt(m_gammaData.keypoint_r[i].x, m_gammaData.keypoint_r[i].y); + rKeyTable.append(pt); + } + + QList gKeyTable; + for (int i = 0; i < m_gammaData.pt_count_g; ++i) + { + QPoint pt(m_gammaData.keypoint_g[i].x, m_gammaData.keypoint_g[i].y); + gKeyTable.append(pt); + } + + QList bKeyTable; + for (int i = 0; i < m_gammaData.pt_count_b; ++i) + { + QPoint pt(m_gammaData.keypoint_b[i].x, m_gammaData.keypoint_b[i].y); + bKeyTable.append(pt); + } + + QVector> keyTableList; + if (!keyTable.empty() && !rKeyTable.empty() && !gKeyTable.empty() && !bKeyTable.empty()) + { + keyTableList.append(keyTable); + keyTableList.append(rKeyTable); + keyTableList.append(gKeyTable); + keyTableList.append(bKeyTable); + dlg.setRGBKeyTable(keyTableList); + } + } + + dlg.setColorMode(colorMode); + if (dlg.exec()) + { + memset(&m_gammaData, 0, sizeof(m_gammaData)); + + if (1 == colorMode) + { + QList keyTable = dlg.getGrayKeyTable(); + + m_gammaData.pt_count = HGMIN(4, keyTable.size()); + int i = 0; + for (QPoint pt : keyTable) + { + if (i >= 4) + break; + + m_gammaData.keypoint[i].x = pt.x(); + m_gammaData.keypoint[i].y = pt.y(); + ++i; + } + + uchar data[256]; + dlg.getGrayTable(data, 256); + for (int i = 0; i < 256; ++i) + { + m_gammaData.table[i] = data[i]; + } + } + else + { + QVector> keyTableList = dlg.getRGBKeyTable(); + + m_gammaData.pt_count = HGMIN(4, keyTableList[0].size()); + int i = 0; + for (QPoint pt : keyTableList[0]) + { + if (i >= 4) + break; + + m_gammaData.keypoint[i].x = pt.x(); + m_gammaData.keypoint[i].y = pt.y(); + ++i; + } + + m_gammaData.pt_count_r = HGMIN(4, keyTableList[1].size()); + i = 0; + for (QPoint pt : keyTableList[1]) + { + if (i >= 4) + break; + + m_gammaData.keypoint_r[i].x = pt.x(); + m_gammaData.keypoint_r[i].y = pt.y(); + ++i; + } + + m_gammaData.pt_count_g = HGMIN(4, keyTableList[2].size()); + i = 0; + for (QPoint pt : keyTableList[2]) + { + if (i >= 4) + break; + + m_gammaData.keypoint_g[i].x = pt.x(); + m_gammaData.keypoint_g[i].y = pt.y(); + ++i; + } + + m_gammaData.pt_count_b = HGMIN(4, keyTableList[3].size()); + i = 0; + for (QPoint pt : keyTableList[3]) + { + if (i >= 4) + break; + + m_gammaData.keypoint_b[i].x = pt.x(); + m_gammaData.keypoint_b[i].y = pt.y(); + ++i; + } + + uchar data[256 * 3]; + dlg.getRGBTable(data, 256 * 3); + for (int i = 0; i < 256; ++i) + { + m_gammaData.table[i] = data[i * 3 + 2]; + m_gammaData.table[i + 256] = data[i * 3 + 1]; + m_gammaData.table[i + 512] = data[i * 3 + 0]; + } + } + + unsigned int len = sizeof(SANE_Gamma); + sane_io_control(m_handle, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &m_gammaData, &len); + } +} + void hg_settingdialog::slot_word_list_comboBoxClicked(int value) { QComboBox *comboBox = qobject_cast(sender()); @@ -891,6 +1180,11 @@ void hg_settingdialog::slot_sliderClicked(int value) QSlider *slider = qobject_cast(sender()); SANE_Int id = slider->property("controls_id").toInt(); + if (id == m_dpiId) + { + m_dpiValue = value; + } + const SANE_Option_Descriptor* opt = nullptr; for(int i = 0; i < m_list_getOpt.size(); i++) if (m_list_getOpt.at(i).first == id) diff --git a/app/scanner/hg_settingdialog.h b/app/scanner/hg_settingdialog.h index 5287ef03..b7a3799d 100644 --- a/app/scanner/hg_settingdialog.h +++ b/app/scanner/hg_settingdialog.h @@ -99,12 +99,34 @@ private slots: void slot_doubleSpinboxClicked(double value); void slot_string_list_comboBoxClicked(); void slot_pushButtonClicked(); + void slot_cutButtonClicked(); + void slot_gammaButtonClicked(); void slot_word_list_comboBoxClicked(int value); void slot_lineEditInput(); void slot_buttonOkClicked(); void slot_buttonCancelClicked(); void on_scheme_triggered(QAction*); void slot_pushButton_scheme_management(void); + +private: + int m_dpiId; + int m_dpiValue; + int m_paperSizeId; + QString m_paperSizeValue; + int m_cutLeftId; + int m_cutTopId; + int m_cutRightId; + int m_cutBottomId; + int m_cutWidth; // 单位是毫米 + int m_cutHeight; // 单位是毫米 + int m_cutLeftValue; // 单位是毫米 + int m_cutTopValue; // 单位是毫米 + int m_cutRightValue; // 单位是毫米 + int m_cutBottomValue; // 单位是毫米 + + int m_colorModeId; + QString m_colorModeValue; + SANE_Gamma m_gammaData; }; #endif // HG_SETTING_DIALOG_H diff --git a/app/scanner/setpicclrtool.cpp b/app/scanner/setpicclrtool.cpp index fb7c5bc2..78597d89 100644 --- a/app/scanner/setpicclrtool.cpp +++ b/app/scanner/setpicclrtool.cpp @@ -303,11 +303,13 @@ void setPicClrTool::on_pushButton_clicked() void setPicClrTool::on_buttonBox_accepted() { - close(); + //close(); + accept(); } void setPicClrTool::on_buttonBox_rejected() { ui->widget->initAllLstPnt(); - close(); + //close(); + reject(); }