diff --git a/.gitignore b/.gitignore index c969b36..fb1435f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,13 @@ __pycache__/ *.py[co] *$py.class +debug +release +.qmake.stash +Makefile +Makefile.Debug +Makefile.Release + Tmp Tmp/* diff --git a/Test/C++中修改PyQt对象/Cold.dll b/Test/C++中修改PyQt对象/Cold.dll new file mode 100644 index 0000000..18e5c2c Binary files /dev/null and b/Test/C++中修改PyQt对象/Cold.dll differ diff --git a/Test/C++中修改PyQt对象/Cold/Cold.pro b/Test/C++中修改PyQt对象/Cold/Cold.pro new file mode 100644 index 0000000..cb2bf64 --- /dev/null +++ b/Test/C++中修改PyQt对象/Cold/Cold.pro @@ -0,0 +1,30 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2020-03-02T16:57:48 +# +#------------------------------------------------- + +TARGET = Cold +TEMPLATE = lib + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + cold.cpp + +HEADERS += \ + cold.h + +unix { + target.path = /usr/lib + INSTALLS += target +} diff --git a/Test/C++中修改PyQt对象/Cold/build.bat b/Test/C++中修改PyQt对象/Cold/build.bat new file mode 100644 index 0000000..2bdf9e0 --- /dev/null +++ b/Test/C++中修改PyQt对象/Cold/build.bat @@ -0,0 +1,2 @@ +qmake +nmake \ No newline at end of file diff --git a/Test/C++中修改PyQt对象/Cold/cold.cpp b/Test/C++中修改PyQt对象/Cold/cold.cpp new file mode 100644 index 0000000..e940cae --- /dev/null +++ b/Test/C++中修改PyQt对象/Cold/cold.cpp @@ -0,0 +1,19 @@ +#include "cold.h" + +void cold(QImage &src, int delta) +{ + int rows = src.height(); + int cols = src.width(); + for (int i = 0; i < rows; i++) + { + QRgb *line = (QRgb *)src.scanLine(i); + for (int j = 0; j < cols; j++) + { + int r = qRed(line[j]); + int g = qGreen(line[j]); + int b = qBlue(line[j]) + delta; + b = qBound(0, b, 255); + src.setPixel(j, i, qRgb(r, g, b)); + } + } +} diff --git a/Test/C++中修改PyQt对象/Cold/cold.h b/Test/C++中修改PyQt对象/Cold/cold.h new file mode 100644 index 0000000..3ca42a4 --- /dev/null +++ b/Test/C++中修改PyQt对象/Cold/cold.h @@ -0,0 +1,4 @@ +#include +#include + +extern "C" __declspec(dllexport) void cold(QImage &src, int delta); \ No newline at end of file diff --git a/Test/C++中修改PyQt对象/Test.py b/Test/C++中修改PyQt对象/Test.py new file mode 100644 index 0000000..f8be27f --- /dev/null +++ b/Test/C++中修改PyQt对象/Test.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +''' +Created on 2020年3月2日 +@author: Irony +@site: https://pyqt.site https://github.com/PyQt5 +@email: 892768447@qq.com +@file: +@description: 冷色调 +''' + +import sys +from ctypes import CDLL +from time import time + +# For PyQt5 +try: + from PyQt5 import sip +except: + import sip +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QImage, QPixmap +from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout + +# For PySide2 +# import shiboken2 +# from PySide2.QtCore import Qt +# from PySide2.QtGui import QImage, QPixmap +# from PySide2.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout + + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + layout = QVBoxLayout(self) + self.imgLabel = QLabel(self) + self.coldSlider = QSlider(Qt.Horizontal, self) + self.coldSlider.valueChanged.connect(self.doChange) + self.coldSlider.setRange(0, 255) + layout.addWidget(self.imgLabel) + layout.addWidget(self.coldSlider) + + # 加载图片 + self.srcImg = QImage('src.jpg') + self.imgLabel.setPixmap(QPixmap.fromImage(self.srcImg).scaledToWidth(800, Qt.SmoothTransformation)) + # DLL库 + self.dll = CDLL('Cold.dll') + print(self.dll) + + def doChange(self, value): + t = time() + img = self.srcImg.copy() # 复制一份 + # For PyQt5 + self.dll.cold(sip.unwrapinstance(img), value) + # For PySide2 + # self.dll.cold(shiboken2.getCppPointer(img)[0], value) + self.imgLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(800, Qt.SmoothTransformation)) + print('use time:', time() - t) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + view = Window() + view.show() + sys.exit(app.exec_()) diff --git a/Test/C++中修改PyQt对象/src.jpg b/Test/C++中修改PyQt对象/src.jpg new file mode 100644 index 0000000..2b113b0 Binary files /dev/null and b/Test/C++中修改PyQt对象/src.jpg differ