feat: Added resizing option to preview window to reduce lag.

This commit is contained in:
Mr Finchum 2025-02-12 15:43:53 +01:00
parent 9000702636
commit 2c633d6dc4
4 changed files with 120 additions and 41 deletions

View file

@ -1,17 +1,23 @@
# Changelog # Changelog
### 0.14.x ## 0.15.0: Preview Image Resizing Update
#### 0.14.1: Patch changelog - Added the ability to change the preview image size dynamically.
- Previously, the image was processed and displayed at its original size, causing lag or unresponsiveness when adjusting the slider.
- Reducing the processed image size should help improve performance.
- Default preview image size is now **25%**, but users can adjust it between **10% and 100%**.
## 0.14.x
### 0.14.1: Patch changelog
- Updated the changelog to include missing entries. - Updated the changelog to include missing entries.
#### 0.14.0: Code refactor (by Mr. Finch) ### 0.14.0: Code refactor (by Mr. Finch)
- Introduced constants and optimized the code. - Introduced constants and optimized the code.
### 0.13.x ## 0.13.x
#### 0.13.1: Fixed image processing ### 0.13.1: Fixed image processing
- Fixed a bug that made it impossible to process images. - Fixed a bug that made it impossible to process images.
#### 0.13.0: Requirements file (by Mr. Finch) ### 0.13.0: Requirements file (by Mr. Finch)
- Added a requirements file. - Added a requirements file.
## 0.12.x ## 0.12.x

View file

@ -858,12 +858,13 @@ class PreviewWindow(QMainWindow, Ui_Preview_Window):
path = self.ui.image_path_lineEdit.text() path = self.ui.image_path_lineEdit.text()
worker = ImageProcessorWorker( worker = ImageProcessorWorker(
path=path, path = path,
optima_manager=self.o, optima_manager = self.o,
brightness=int(self.ui.brightness_spinBox.text()), brightness = int(self.ui.brightness_spinBox.text()),
contrast=int(self.ui.contrast_spinBox.text()), contrast = int(self.ui.contrast_spinBox.text()),
grayscale=self.ui.grayscale_checkBox.isChecked(), grayscale = self.ui.grayscale_checkBox.isChecked(),
callback=self.display_image # Callback to update UI resize = self.ui.scale_Slider.value(),
callback = self.display_image # Callback to update UI
) )
self.threadpool.start(worker) # Run worker in a thread self.threadpool.start(worker) # Run worker in a thread
@ -943,13 +944,14 @@ class ImageProcessorRunnable(QRunnable):
class ImageProcessorWorker(QRunnable): class ImageProcessorWorker(QRunnable):
"""Worker class to load and process the image in a separate thread.""" """Worker class to load and process the image in a separate thread."""
# ChatGPT # ChatGPT
def __init__(self, path, optima_manager, brightness, contrast, grayscale, callback): def __init__(self, path, optima_manager, brightness, contrast, grayscale, resize, callback):
super().__init__() super().__init__()
self.path = path self.path = path
self.optima_manager = optima_manager self.optima_manager = optima_manager
self.brightness = brightness self.brightness = brightness
self.contrast = contrast self.contrast = contrast
self.grayscale = grayscale self.grayscale = grayscale
self.resize = resize
self.callback = callback # Function to call when processing is done self.callback = callback # Function to call when processing is done
@Slot() @Slot()
@ -961,12 +963,12 @@ class ImageProcessorWorker(QRunnable):
try: try:
img = self.optima_manager.process_image_object( img = self.optima_manager.process_image_object(
image_input_file=self.path, image_input_file = self.path,
watermark="PREVIEW", watermark = "PREVIEW",
resize=100, resize = self.resize,
grayscale=self.grayscale, grayscale = self.grayscale,
brightness=self.brightness, brightness = self.brightness,
contrast=self.contrast contrast = self.contrast
) )
pixmap = QPixmap.fromImage(img) pixmap = QPixmap.fromImage(img)
self.callback(pixmap) self.callback(pixmap)

View file

@ -43,8 +43,8 @@ class Ui_Preview_Window(object):
self.widget.setObjectName(u"widget") self.widget.setObjectName(u"widget")
self.widget.setMinimumSize(QSize(160, 628)) self.widget.setMinimumSize(QSize(160, 628))
self.widget.setMaximumSize(QSize(150, 16777215)) self.widget.setMaximumSize(QSize(150, 16777215))
self.verticalLayout_5 = QVBoxLayout(self.widget) self.verticalLayout_4 = QVBoxLayout(self.widget)
self.verticalLayout_5.setObjectName(u"verticalLayout_5") self.verticalLayout_4.setObjectName(u"verticalLayout_4")
self.groupBox_3 = QGroupBox(self.widget) self.groupBox_3 = QGroupBox(self.widget)
self.groupBox_3.setObjectName(u"groupBox_3") self.groupBox_3.setObjectName(u"groupBox_3")
self.verticalLayout_3 = QVBoxLayout(self.groupBox_3) self.verticalLayout_3 = QVBoxLayout(self.groupBox_3)
@ -60,7 +60,7 @@ class Ui_Preview_Window(object):
self.verticalLayout_3.addWidget(self.load_Button) self.verticalLayout_3.addWidget(self.load_Button)
self.verticalLayout_5.addWidget(self.groupBox_3) self.verticalLayout_4.addWidget(self.groupBox_3)
self.groupBox_2 = QGroupBox(self.widget) self.groupBox_2 = QGroupBox(self.widget)
self.groupBox_2.setObjectName(u"groupBox_2") self.groupBox_2.setObjectName(u"groupBox_2")
@ -87,7 +87,7 @@ class Ui_Preview_Window(object):
self.verticalLayout.addWidget(self.reset_brightness_Button) self.verticalLayout.addWidget(self.reset_brightness_Button)
self.verticalLayout_5.addWidget(self.groupBox_2) self.verticalLayout_4.addWidget(self.groupBox_2)
self.groupBox = QGroupBox(self.widget) self.groupBox = QGroupBox(self.widget)
self.groupBox.setObjectName(u"groupBox") self.groupBox.setObjectName(u"groupBox")
@ -114,7 +114,7 @@ class Ui_Preview_Window(object):
self.verticalLayout_2.addWidget(self.reset_contrast_Button) self.verticalLayout_2.addWidget(self.reset_contrast_Button)
self.verticalLayout_5.addWidget(self.groupBox) self.verticalLayout_4.addWidget(self.groupBox)
self.groupBox_5 = QGroupBox(self.widget) self.groupBox_5 = QGroupBox(self.widget)
self.groupBox_5.setObjectName(u"groupBox_5") self.groupBox_5.setObjectName(u"groupBox_5")
@ -126,43 +126,58 @@ class Ui_Preview_Window(object):
self.gridLayout.addWidget(self.grayscale_checkBox, 0, 0, 1, 1) self.gridLayout.addWidget(self.grayscale_checkBox, 0, 0, 1, 1)
self.verticalLayout_5.addWidget(self.groupBox_5) self.verticalLayout_4.addWidget(self.groupBox_5)
self.verticalSpacer = QSpacerItem(20, 219, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) self.verticalSpacer = QSpacerItem(20, 219, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
self.verticalLayout_5.addItem(self.verticalSpacer) self.verticalLayout_4.addItem(self.verticalSpacer)
self.groupBox_4 = QGroupBox(self.widget) self.groupBox_4 = QGroupBox(self.widget)
self.groupBox_4.setObjectName(u"groupBox_4") self.groupBox_4.setObjectName(u"groupBox_4")
self.verticalLayout_4 = QVBoxLayout(self.groupBox_4) self.gridLayout_2 = QGridLayout(self.groupBox_4)
self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.gridLayout_2.setObjectName(u"gridLayout_2")
self.live_update = QCheckBox(self.groupBox_4) self.live_update = QCheckBox(self.groupBox_4)
self.live_update.setObjectName(u"live_update") self.live_update.setObjectName(u"live_update")
self.live_update.setChecked(True) self.live_update.setChecked(True)
self.verticalLayout_4.addWidget(self.live_update) self.gridLayout_2.addWidget(self.live_update, 0, 0, 1, 1)
self.scale_label = QLabel(self.groupBox_4)
self.scale_label.setObjectName(u"scale_label")
self.gridLayout_2.addWidget(self.scale_label, 0, 1, 1, 1)
self.scale_Slider = QSlider(self.groupBox_4)
self.scale_Slider.setObjectName(u"scale_Slider")
self.scale_Slider.setMinimum(10)
self.scale_Slider.setMaximum(100)
self.scale_Slider.setPageStep(10)
self.scale_Slider.setValue(25)
self.scale_Slider.setOrientation(Qt.Horizontal)
self.gridLayout_2.addWidget(self.scale_Slider, 1, 0, 1, 2)
self.update_Button = QPushButton(self.groupBox_4) self.update_Button = QPushButton(self.groupBox_4)
self.update_Button.setObjectName(u"update_Button") self.update_Button.setObjectName(u"update_Button")
self.update_Button.setEnabled(False) self.update_Button.setEnabled(False)
self.update_Button.setAutoFillBackground(False) self.update_Button.setAutoFillBackground(False)
self.verticalLayout_4.addWidget(self.update_Button) self.gridLayout_2.addWidget(self.update_Button, 2, 0, 1, 2)
self.checkBox = QCheckBox(self.groupBox_4) self.checkBox = QCheckBox(self.groupBox_4)
self.checkBox.setObjectName(u"checkBox") self.checkBox.setObjectName(u"checkBox")
self.checkBox.setLayoutDirection(Qt.LeftToRight) self.checkBox.setLayoutDirection(Qt.LeftToRight)
self.checkBox.setChecked(True) self.checkBox.setChecked(True)
self.verticalLayout_4.addWidget(self.checkBox) self.gridLayout_2.addWidget(self.checkBox, 3, 0, 1, 2)
self.close_Button = QPushButton(self.groupBox_4) self.close_Button = QPushButton(self.groupBox_4)
self.close_Button.setObjectName(u"close_Button") self.close_Button.setObjectName(u"close_Button")
self.verticalLayout_4.addWidget(self.close_Button) self.gridLayout_2.addWidget(self.close_Button, 4, 0, 1, 2)
self.verticalLayout_5.addWidget(self.groupBox_4) self.verticalLayout_4.addWidget(self.groupBox_4)
self.horizontalLayout.addWidget(self.widget) self.horizontalLayout.addWidget(self.widget)
@ -170,7 +185,7 @@ class Ui_Preview_Window(object):
Preview_Window.setCentralWidget(self.centralwidget) Preview_Window.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(Preview_Window) self.menubar = QMenuBar(Preview_Window)
self.menubar.setObjectName(u"menubar") self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 875, 27)) self.menubar.setGeometry(QRect(0, 0, 875, 22))
Preview_Window.setMenuBar(self.menubar) Preview_Window.setMenuBar(self.menubar)
self.retranslateUi(Preview_Window) self.retranslateUi(Preview_Window)
@ -179,6 +194,7 @@ class Ui_Preview_Window(object):
self.contrast_Slider.valueChanged.connect(self.contrast_spinBox.setValue) self.contrast_Slider.valueChanged.connect(self.contrast_spinBox.setValue)
self.contrast_spinBox.valueChanged.connect(self.contrast_Slider.setValue) self.contrast_spinBox.valueChanged.connect(self.contrast_Slider.setValue)
self.live_update.toggled.connect(self.update_Button.setDisabled) self.live_update.toggled.connect(self.update_Button.setDisabled)
self.scale_Slider.valueChanged.connect(self.scale_label.setNum)
QMetaObject.connectSlotsByName(Preview_Window) QMetaObject.connectSlotsByName(Preview_Window)
# setupUi # setupUi
@ -212,6 +228,13 @@ class Ui_Preview_Window(object):
self.live_update.setToolTip(QCoreApplication.translate("Preview_Window", u"Live update applies changes instantly. If the app becomes unresponsive or lags, disable this option.", None)) self.live_update.setToolTip(QCoreApplication.translate("Preview_Window", u"Live update applies changes instantly. If the app becomes unresponsive or lags, disable this option.", None))
#endif // QT_CONFIG(tooltip) #endif // QT_CONFIG(tooltip)
self.live_update.setText(QCoreApplication.translate("Preview_Window", u"Live refresh", None)) self.live_update.setText(QCoreApplication.translate("Preview_Window", u"Live refresh", None))
#if QT_CONFIG(tooltip)
self.scale_label.setToolTip(QCoreApplication.translate("Preview_Window", u"Sets the resize value for the preview image. A high value may cause the application to freeze.", None))
#endif // QT_CONFIG(tooltip)
self.scale_label.setText(QCoreApplication.translate("Preview_Window", u"25", None))
#if QT_CONFIG(tooltip)
self.scale_Slider.setToolTip(QCoreApplication.translate("Preview_Window", u"Sets the resize value for the preview image. A high value may cause the application to freeze.", None))
#endif // QT_CONFIG(tooltip)
#if QT_CONFIG(tooltip) #if QT_CONFIG(tooltip)
self.update_Button.setToolTip(QCoreApplication.translate("Preview_Window", u"Apply Changes to Preview", None)) self.update_Button.setToolTip(QCoreApplication.translate("Preview_Window", u"Apply Changes to Preview", None))
#endif // QT_CONFIG(tooltip) #endif // QT_CONFIG(tooltip)

View file

@ -54,7 +54,7 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
@ -202,8 +202,8 @@
<property name="title"> <property name="title">
<string>Behavior</string> <string>Behavior</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QGridLayout" name="gridLayout_2">
<item> <item row="0" column="0">
<widget class="QCheckBox" name="live_update"> <widget class="QCheckBox" name="live_update">
<property name="toolTip"> <property name="toolTip">
<string>Live update applies changes instantly. If the app becomes unresponsive or lags, disable this option.</string> <string>Live update applies changes instantly. If the app becomes unresponsive or lags, disable this option.</string>
@ -216,7 +216,39 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QLabel" name="scale_label">
<property name="toolTip">
<string>Sets the resize value for the preview image. A high value may cause the application to freeze.</string>
</property>
<property name="text">
<string>25</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QSlider" name="scale_Slider">
<property name="toolTip">
<string>Sets the resize value for the preview image. A high value may cause the application to freeze.</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>10</number>
</property>
<property name="value">
<number>25</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="update_Button"> <widget class="QPushButton" name="update_Button">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -232,7 +264,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox"> <widget class="QCheckBox" name="checkBox">
<property name="toolTip"> <property name="toolTip">
<string>Enable to copy adjustments to the main window upon closing</string> <string>Enable to copy adjustments to the main window upon closing</string>
@ -248,7 +280,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="4" column="0" colspan="2">
<widget class="QPushButton" name="close_Button"> <widget class="QPushButton" name="close_Button">
<property name="toolTip"> <property name="toolTip">
<string/> <string/>
@ -272,7 +304,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>875</width> <width>875</width>
<height>27</height> <height>22</height>
</rect> </rect>
</property> </property>
</widget> </widget>
@ -359,5 +391,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>scale_Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>scale_label</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>783</x>
<y>644</y>
</hint>
<hint type="destinationlabel">
<x>831</x>
<y>619</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>