增加对比度调整
This commit is contained in:
parent
e5c6ce2013
commit
702ebf9372
|
@ -11,4 +11,6 @@
|
|||
### 1.2 新增导入图形
|
||||
### 1.1 新增灰度和反色
|
||||

|
||||

|
||||

|
||||
# 参考
|
||||
Color与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757
|
|
@ -636,7 +636,6 @@ void ImageWidget::moveImgbuf()
|
|||
|
||||
void ImageWidget::undo()
|
||||
{
|
||||
qDebug() << "undo" << cundo;
|
||||
if (cundo < 10) {
|
||||
imgtemp = imgbuf[cundo];
|
||||
image = imgtemp;
|
||||
|
@ -648,7 +647,6 @@ void ImageWidget::undo()
|
|||
|
||||
void ImageWidget::redo()
|
||||
{
|
||||
qDebug() << "redo" << cundo;
|
||||
if (cundo==10) cundo--;
|
||||
if (cundo >= 0) {
|
||||
imgtemp = imgbuf[cundo];
|
||||
|
@ -885,6 +883,70 @@ void ImageWidget::adjustBrightness(int v, bool b)
|
|||
update();
|
||||
}
|
||||
|
||||
int ImageWidget::avarageGray()
|
||||
{
|
||||
int sum = 0;
|
||||
int w = image.width();
|
||||
int h = image.height();
|
||||
for (int x=0; x<w; x++) {
|
||||
for (int y=0; y<h; y++) {
|
||||
QRgb RGB = image.pixel(x, y);
|
||||
int gray = qGray(RGB);
|
||||
sum += gray;
|
||||
}
|
||||
}
|
||||
int avg = sum / (w * h);
|
||||
return avg;
|
||||
}
|
||||
|
||||
void ImageWidget::adjustContrast(int v, bool b)
|
||||
{
|
||||
//https://www.cnblogs.com/justany/archive/2013/01/02/2842234.html
|
||||
int avg = avarageGray();
|
||||
qDebug() << "灰度平均值:" << avg;
|
||||
int w = image.width();
|
||||
int h = image.height();
|
||||
QImage image1(w, h, QImage::Format_ARGB32);
|
||||
for (int x=0; x<w; x++) {
|
||||
for (int y=0; y<h; y++) {
|
||||
QRgb RGB = image.pixel(x, y);
|
||||
int R = qRed(RGB);
|
||||
int G = qGreen(RGB);
|
||||
int B = qBlue(RGB);
|
||||
//线性
|
||||
/*
|
||||
R *= v;
|
||||
G *= v;
|
||||
B *= v;
|
||||
*/
|
||||
//非线性
|
||||
if (v >= 0) {
|
||||
R = R + (R - avg) * (1 / (1 - v / 255.0) - 1);
|
||||
G = G + (G - avg) * (1 / (1 - v / 255.0) - 1);
|
||||
B = B + (B - avg) * (1 / (1 - v / 255.0) - 1);
|
||||
} else {
|
||||
R = R + (R - avg) * v / 255;
|
||||
G = G + (G - avg) * v / 255;
|
||||
B = B + (B - avg) * v / 255;
|
||||
}
|
||||
if (R < 0) R = 0;
|
||||
if (G < 0) G = 0;
|
||||
if (B < 0) B = 0;
|
||||
if (R > 255) R = 255;
|
||||
if (G > 255) G = 255;
|
||||
if (B > 255) B = 255;
|
||||
image1.setPixel(x, y, qRgb(R, G, B));
|
||||
}
|
||||
}
|
||||
if (b) {
|
||||
image = image1;
|
||||
moveImgbuf();
|
||||
} else {
|
||||
imgtemp = image1;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidget::clip(int x1, int y1, int x2, int y2, bool isConfirm)
|
||||
{
|
||||
imgtemp = image.copy(x1, y1, x2 - x1, y2 - y1);
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
QString text;
|
||||
QFont font;
|
||||
QPainterPath painterPath;
|
||||
int cundo;
|
||||
bool boolBorder, boolFill;
|
||||
void load(QString fileName);
|
||||
void save(QString path);
|
||||
|
@ -82,10 +83,19 @@ public:
|
|||
void mosaic(int p);
|
||||
void adjustRGB(int vr, int vg, int vb, bool b);
|
||||
void adjustBrightness(int v, bool b);
|
||||
void adjustContrast(int v, bool b);
|
||||
void clip(int x1, int y1, int x2, int y2, bool isConfirm);
|
||||
void clipPath(int x, int y, int width, int height, bool isConfirm);
|
||||
void deleteBlackBorder(BorderType border_type, int d);
|
||||
|
||||
private:
|
||||
QImage imgload,imgpaste;
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
int avarageGray();
|
||||
|
||||
public slots:
|
||||
void newfile();
|
||||
void drawPoint();
|
||||
|
@ -126,18 +136,10 @@ private slots:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QImage imgload,imgpaste;
|
||||
int cundo;
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
signals:
|
||||
void statusBar1Message(QString);
|
||||
void statusBar2Message(QString);
|
||||
void pick(QColor color);
|
||||
};
|
||||
|
||||
#endif // IMAGEWIDGET_H
|
||||
#endif // IMAGEWIDGET_H
|
|
@ -34,7 +34,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
//LSB2->setFrameShape(QFrame::WinPanel);
|
||||
//LSB2->setFrameShadow(QFrame::Sunken);
|
||||
ui->statusBar->addWidget(LSB1);
|
||||
ui->statusBar->addWidget(LSB2);
|
||||
ui->statusBar->addWidget(LSB2);
|
||||
|
||||
text = "文字内容";
|
||||
path = "";
|
||||
|
@ -223,7 +223,7 @@ QColor MainWindow::intToColor(int intColor)
|
|||
|
||||
void MainWindow::on_action_changelog_triggered()
|
||||
{
|
||||
QString s = "1.20\n(2022-05)\n关闭时保存设置,打开时读取设置。\n\n1.19\n(2021-04)\n修复缩放锯齿问题。\n\n1.18\n(2020-12)\n如果粘贴的图片比当前图片大,询问是否扩张,然后处理。\n\n1.17\n(2020-04)\n修复:上个选区残留问题。\n增加:第一次全选可以填充颜色(因路径不能清空只能填充一次,再次填充需要关闭再打开)。\n\n1.16\n(2020-03)\n增加:圆形路径裁剪。\n背景文字改成了描边文字。\n\n1.15\n(2019-11)\n增加:文字工具可以绘制矩形背景。\n\n1.14\n(2019-08)\n增加:颜色调节。\n修复:选择颜色取消时颜色变黑色。\n\n1.13\n(2019-06)\n修复:选区裁剪大小微差。删除选区操作后没有设置回到框选工具。\n优化:信息内容、选区裁剪。群组工具栏Action,实现互斥Checked。\n增加:画线长度信息,画框长、宽信息,微调显示信息,裁剪后滚动条回到0。\n\n1.12\n(2019-05)\n修复:PNG转灰度图透明度丢失。\n\n1.11\n(2019-04)\n修改:删除选取填充,白色改成透明色。\n增加:棋盘背景。\n增加:鼠标移动定位文字。\n增加:Ctrl+鼠标滚轮 改变线粗或字体大小。\n\n1.10\n(2018-12)\n增加:选区马赛克。\n\n1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号,简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题,致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件,没引用资源文件,引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条,增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能,有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。";
|
||||
QString s = "1.21\n(2022-10)\n增加对比度调整。\n\n1.20\n(2022-05)\n关闭时保存设置,打开时读取设置。\n\n1.19\n(2021-04)\n修复缩放锯齿问题。\n\n1.18\n(2020-12)\n如果粘贴的图片比当前图片大,询问是否扩张,然后处理。\n\n1.17\n(2020-04)\n修复:上个选区残留问题。\n增加:第一次全选可以填充颜色(因路径不能清空只能填充一次,再次填充需要关闭再打开)。\n\n1.16\n(2020-03)\n增加:圆形路径裁剪。\n背景文字改成了描边文字。\n\n1.15\n(2019-11)\n增加:文字工具可以绘制矩形背景。\n\n1.14\n(2019-08)\n增加:颜色调节。\n修复:选择颜色取消时颜色变黑色。\n\n1.13\n(2019-06)\n修复:选区裁剪大小微差。删除选区操作后没有设置回到框选工具。\n优化:信息内容、选区裁剪。群组工具栏Action,实现互斥Checked。\n增加:画线长度信息,画框长、宽信息,微调显示信息,裁剪后滚动条回到0。\n\n1.12\n(2019-05)\n修复:PNG转灰度图透明度丢失。\n\n1.11\n(2019-04)\n修改:删除选取填充,白色改成透明色。\n增加:棋盘背景。\n增加:鼠标移动定位文字。\n增加:Ctrl+鼠标滚轮 改变线粗或字体大小。\n\n1.10\n(2018-12)\n增加:选区马赛克。\n\n1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号,简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题,致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件,没引用资源文件,引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条,增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能,有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。";
|
||||
QDialog *dialog = new QDialog;
|
||||
dialog->setWindowTitle("更新历史");
|
||||
dialog->setFixedSize(400,300);
|
||||
|
@ -253,7 +253,7 @@ void MainWindow::on_action_aboutQt_triggered()
|
|||
|
||||
void MainWindow::on_action_about_triggered()
|
||||
{
|
||||
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.20\n一款基于 Qt 的画图程序。\n作者:海天鹰\nE-mail: sonichy@163.com\n主页:https://gitee.com/sonichy/HTYPaint\n参考文献:\n绘图:\nhttp://tzc.is-programmer.com/posts/534.html\nhttp://lizhigg.love.blog.163.com/blog/static/62611781201222105550184/\n滚动条:http://down.51cto.com/data/233634\n灰度图:http://www.cnblogs.com/xianglan/archive/2010/12/24/1915905.html\n拖放打开文件:http://blog.csdn.net/rl529014/article/details/53057577");
|
||||
QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰画图 1.21\n一款基于 Qt 的画图程序。\n作者:海天鹰\nE-mail: sonichy@163.com\n主页:https://gitlink.org.cn/sonichy/HTYPaint\n参考文献:\n绘图:\nhttp://tzc.is-programmer.com/posts/534.html\nhttp://lizhigg.love.blog.163.com/blog/static/62611781201222105550184/\n滚动条:http://down.51cto.com/data/233634\n灰度图:http://www.cnblogs.com/xianglan/archive/2010/12/24/1915905.html\n拖放打开文件:http://blog.csdn.net/rl529014/article/details/53057577\nColor与Int类型相互转换:https://blog.csdn.net/snowdream86/article/details/5273757");
|
||||
aboutMB.setIconPixmap(QPixmap(":/icon/HTYPaint.png"));
|
||||
aboutMB.exec();
|
||||
}
|
||||
|
@ -370,11 +370,13 @@ void MainWindow::on_actionFont_triggered()
|
|||
void MainWindow::on_action_undo_triggered()
|
||||
{
|
||||
imageWidget->undo();
|
||||
LSB1->setText("撤销" + QString::number(imageWidget->cundo));
|
||||
}
|
||||
|
||||
void MainWindow::on_action_redo_triggered()
|
||||
{
|
||||
imageWidget->redo();
|
||||
LSB1->setText("重做" + QString::number(imageWidget->cundo));
|
||||
}
|
||||
|
||||
void MainWindow::on_action_setWallpaper_triggered()
|
||||
|
@ -868,6 +870,55 @@ void MainWindow::on_action_brightness_triggered()
|
|||
dialog->setLayout(vbox);
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
imageWidget->adjustBrightness(slider->value(), true);
|
||||
} else {
|
||||
imageWidget->imgtemp = imageWidget->image;
|
||||
imageWidget->update();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_contrast_triggered()
|
||||
{
|
||||
QDialog *dialog = new QDialog(this);
|
||||
dialog->setWindowTitle("对比度");
|
||||
dialog->setFixedWidth(400);
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
QLabel *label = new QLabel("0");
|
||||
hbox->addWidget(label);
|
||||
QSlider *slider = new QSlider(Qt::Horizontal);
|
||||
slider->setRange(-100, 100);
|
||||
connect(slider, &QSlider::valueChanged, [&](int v){
|
||||
label->setText(QString::number(v));
|
||||
});
|
||||
connect(slider, &QSlider::sliderReleased, [&](){
|
||||
imageWidget->adjustContrast(slider->value(), false);
|
||||
});
|
||||
hbox->addWidget(slider);
|
||||
QPushButton *pushButton_reset = new QPushButton;
|
||||
pushButton_reset->setIcon(QIcon::fromTheme("view-refresh"));
|
||||
connect(pushButton_reset, &QPushButton::clicked, [&](){
|
||||
slider->setValue(0);
|
||||
label->setText("0");
|
||||
imageWidget->adjustContrast(0, false);
|
||||
});
|
||||
hbox->addWidget(pushButton_reset);
|
||||
vbox->addLayout(hbox);
|
||||
QPushButton *pushButton_confirm = new QPushButton("确定");
|
||||
QPushButton *pushButton_cancel = new QPushButton("取消");
|
||||
connect(pushButton_confirm, SIGNAL(clicked()), dialog, SLOT(accept()));
|
||||
connect(pushButton_cancel, SIGNAL(clicked()), dialog, SLOT(reject()));
|
||||
hbox = new QHBoxLayout;
|
||||
hbox->addStretch();
|
||||
hbox->addWidget(pushButton_confirm);
|
||||
hbox->addWidget(pushButton_cancel);
|
||||
hbox->addStretch();
|
||||
vbox->addLayout(hbox);
|
||||
dialog->setLayout(vbox);
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
imageWidget->adjustContrast(slider->value(), true);
|
||||
} else {
|
||||
imageWidget->imgtemp = imageWidget->image;
|
||||
imageWidget->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ private slots:
|
|||
void on_action_transparent_triggered();
|
||||
void on_action_adjustRGB_triggered();
|
||||
void on_action_brightness_triggered();
|
||||
void on_action_contrast_triggered();
|
||||
void on_action_clip_triggered();
|
||||
void on_action_clipPath_triggered();
|
||||
void on_action_deleteBlackBorder_triggered();
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1050</width>
|
||||
<height>36</height>
|
||||
<height>27</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_file">
|
||||
|
@ -69,6 +69,7 @@
|
|||
<addaction name="action_matting"/>
|
||||
<addaction name="action_adjustRGB"/>
|
||||
<addaction name="action_brightness"/>
|
||||
<addaction name="action_contrast"/>
|
||||
<addaction name="action_clip"/>
|
||||
<addaction name="action_clipPath"/>
|
||||
<addaction name="action_deleteBlackBorder"/>
|
||||
|
@ -726,6 +727,11 @@
|
|||
<string>亮度</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_contrast">
|
||||
<property name="text">
|
||||
<string>对比度</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
Loading…
Reference in New Issue