增加区域裁剪功能和gamma曲线功能
This commit is contained in:
parent
934df5524d
commit
ff106104a6
|
@ -2,12 +2,35 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QLatin1String>
|
||||
#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<QPoint> 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<QPoint> 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<QPoint> 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<QPoint> 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<QPoint> 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<QList<QPoint>> 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<QPoint> 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<QList<QPoint>> 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<QComboBox*>(sender());
|
||||
|
@ -891,6 +1180,11 @@ void hg_settingdialog::slot_sliderClicked(int value)
|
|||
QSlider *slider = qobject_cast<QSlider*>(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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue