From ec5e1708db7a809b39eee56281a3bb86cf3bfbca Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Fri, 10 Jul 2026 18:06:52 +0900
Subject: kuickshow: avoid double application of modifiers when saving

When applying B/C/G modifiers to an image and saving it onto the original file, kuickshow was de facto applying the modifiers twice to the in memory image, though not to the file saved on the disk.
This resolves issue #164.

Co-authored-by: Opencode/Big Pickle
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 kuickshow/src/imagewindow.cpp | 12 +++++++-----
 kuickshow/src/imlibwidget.cpp |  9 ++++++++-
 kuickshow/src/imlibwidget.h   |  3 ++-
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/kuickshow/src/imagewindow.cpp b/kuickshow/src/imagewindow.cpp
index 8b85a1cd..4f676bcc 100644
--- a/kuickshow/src/imagewindow.cpp
+++ b/kuickshow/src/imagewindow.cpp
@@ -944,11 +944,13 @@ void ImageWindow::saveImage()
                                    "have write permission to the file.");
                 KMessageBox::sorry( this, tmp, i18n("File Saving Failed"));
             }
-			else
-			{
-	            if ( url.equals( m_kuim->url() )) {
-	                Imlib_apply_modifiers_to_rgb( id, m_kuim->imlibImage() );
-	            }
+            else
+            {
+                if ( url.equals( m_kuim->url() ))
+                {
+                    Imlib_apply_modifiers_to_rgb( id, m_kuim->imlibImage() );
+                    resetImageModifier();
+                }
             }
         }
     }
diff --git a/kuickshow/src/imlibwidget.cpp b/kuickshow/src/imlibwidget.cpp
index 631e540d..0750c7cb 100644
--- a/kuickshow/src/imlibwidget.cpp
+++ b/kuickshow/src/imlibwidget.cpp
@@ -483,7 +483,6 @@ const TQColor& ImlibWidget::backgroundColor() const
     return myBackgroundColor;
 }
 
-
 void ImlibWidget::setImageModifier()
 {
     if ( !m_kuim )
@@ -493,6 +492,14 @@ void ImlibWidget::setImageModifier()
     m_kuim->setDirty( true );
 }
 
+void ImlibWidget::resetImageModifier()
+{
+    mod.brightness = ImlibOffset;
+    mod.contrast = ImlibOffset;
+    mod.gamma = ImlibOffset;
+    setImageModifier();
+}
+
 int ImlibWidget::imageWidth() const
 {
     return m_kuim ? m_kuim->width() : 0;
diff --git a/kuickshow/src/imlibwidget.h b/kuickshow/src/imlibwidget.h
index 76f01724..5aea06cd 100644
--- a/kuickshow/src/imlibwidget.h
+++ b/kuickshow/src/imlibwidget.h
@@ -136,7 +136,8 @@ public slots:
 protected:
   KuickImage *	loadImageInternal( KuickFile * file );
   void 		showImage();
-  void          setImageModifier();
+  void 		setImageModifier();
+  void 		resetImageModifier();
   void 		rotate( int );
   void 		updateWidget( bool geometryUpdate=true );
   virtual void 	updateGeometry( int width, int height );
-- 
cgit v1.2.3

