From 541fe79d33058629b3131179b478eeab9347eec2 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Sat, 8 Aug 2026 13:26:05 +0900
Subject: kuickshow: migrate from imlib1 to imlib2

Co-authored-by: Opencode/DeepSeek V4 Flash Free
Co-authored-by: Opencode/Big Pickle
Co-authored-by: Opencode/MiMo 2.6 Flash Free
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 doc/kuickshow/index.docbook      |  14 ---
 kuickshow/CMakeLists.txt         |   1 -
 kuickshow/ConfigureChecks.cmake  |   6 +-
 kuickshow/Makefile.am            |   2 +-
 kuickshow/configure.in.bot       |   6 +-
 kuickshow/configure.in.in        |  62 +----------
 kuickshow/misc/CMakeLists.txt    |  12 ---
 kuickshow/misc/Makefile.am       |   2 -
 kuickshow/misc/im_palette.pal    |  64 -----------
 kuickshow/src/defaultswidget.cpp |   4 +-
 kuickshow/src/generalwidget.cpp  |  20 ----
 kuickshow/src/generalwidget.h    |   6 +-
 kuickshow/src/imagewindow.cpp    |  98 +++++++++--------
 kuickshow/src/imagewindow.h      |   2 -
 kuickshow/src/imdata.cpp         |   9 --
 kuickshow/src/imdata.h           |   4 -
 kuickshow/src/imlibwidget.cpp    | 222 +++++++++++++++++++++++---------------
 kuickshow/src/imlibwidget.h      |  78 ++++++--------
 kuickshow/src/kuickimage.cpp     | 225 +++++++++++++--------------------------
 kuickshow/src/kuickimage.h       |  27 ++---
 kuickshow/src/kuickshow.cpp      |  66 ++----------
 kuickshow/src/kuickshow.h        |   8 +-
 22 files changed, 328 insertions(+), 610 deletions(-)
 delete mode 100644 kuickshow/misc/CMakeLists.txt
 delete mode 100644 kuickshow/misc/Makefile.am
 delete mode 100644 kuickshow/misc/im_palette.pal

diff --git a/doc/kuickshow/index.docbook b/doc/kuickshow/index.docbook
index ba245c60..c0ad6766 100644
--- a/doc/kuickshow/index.docbook
+++ b/doc/kuickshow/index.docbook
@@ -239,20 +239,6 @@ types it is capable of.</para>
 </listitem>
 </varlistentry>
 
-<varlistentry>
-<term><guilabel>Use own color palette</guilabel></term>
-<listitem><para><!-- and this one -->
-</para>
-</listitem>
-</varlistentry>
-
-<varlistentry>
-<term><guilabel>Fast palette remapping</guilabel></term>
-<listitem>
-<para><!-- and this one -->
-</para></listitem>
-</varlistentry>
-
 <varlistentry>
 <term><guilabel>Maximum cache size (MB):</guilabel></term>
 <listitem>
diff --git a/kuickshow/CMakeLists.txt b/kuickshow/CMakeLists.txt
index 57f95734..4250f87a 100644
--- a/kuickshow/CMakeLists.txt
+++ b/kuickshow/CMakeLists.txt
@@ -12,5 +12,4 @@
 include( ConfigureChecks.cmake )
 
 add_subdirectory( src )
-add_subdirectory( misc )
 add_subdirectory( pics )
diff --git a/kuickshow/ConfigureChecks.cmake b/kuickshow/ConfigureChecks.cmake
index 61b36454..988a5982 100644
--- a/kuickshow/ConfigureChecks.cmake
+++ b/kuickshow/ConfigureChecks.cmake
@@ -9,8 +9,8 @@
 #
 #################################################
 
-# imlib
-pkg_search_module( IMLIB imlib )
+# imlib2
+pkg_search_module( IMLIB imlib2 )
 if( NOT IMLIB_FOUND )
-  tde_message_fatal( "imlib is required, but was not found on your system" )
+  tde_message_fatal( "imlib2 is required, but was not found on your system" )
 endif( )
diff --git a/kuickshow/Makefile.am b/kuickshow/Makefile.am
index e53fd831..a409d428 100644
--- a/kuickshow/Makefile.am
+++ b/kuickshow/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = src misc pics
+SUBDIRS = src pics
 
 kuickshow-package:
 	@export CVSROOT=`cat CVS/Root`; \
diff --git a/kuickshow/configure.in.bot b/kuickshow/configure.in.bot
index ef8aaf93..05223d49 100644
--- a/kuickshow/configure.in.bot
+++ b/kuickshow/configure.in.bot
@@ -1,9 +1,7 @@
 if test -z "$LIB_IMLIB"; then
   echo ""
-  echo "You're missing Imlib 1.x. The graphics browser/viewer KuickShow"
-  echo "won't be compiled without Imlib."
-  echo "You can download it from"
-  echo "http://freshmeat.net/redir/imlib/4385/url_tgz/imlib-1.9.10.tar.gz"
+  echo "You're missing imlib2. The graphics browser/viewer KuickShow"
+  echo "won't be compiled without imlib2."
   echo ""
   all_tests=bad
 fi
diff --git a/kuickshow/configure.in.in b/kuickshow/configure.in.in
index fb1f0432..cbf1d0be 100644
--- a/kuickshow/configure.in.in
+++ b/kuickshow/configure.in.in
@@ -1,69 +1,17 @@
 #MIN_CONFIG
 
 #AM_INIT_AUTOMAKE(kuickshow,0.8.2)
- 
-# my own additions to KDE's version
-#
-# checking for Imlib...
 
-AC_DEFUN([KDE_FIND_IMLIB_CONFIG],
-   [AC_MSG_CHECKING([for imlib-config])
+# checking for imlib2...
 
-imlib_config_given=NO
-ac_imlib_config=""
-
-AC_ARG_WITH(imlib-config,
-AC_HELP_STRING([--with-imlib-config=DIR],[directory where "imlib-config" is located]),
-[  ac_imlib_config="$withval/imlib-config"
-   imlib_config_given=yes
-])
-
-if test "$imlib_config_given" = "yes"; then
-  if test ! -r $ac_imlib_config; then
-    AC_MSG_RESULT(wrong file specified)
-    ac_imlib_config=""
-  else
-    AC_MSG_RESULT($ac_imlib_config)
-    LIB_IMLIB=`$ac_imlib_config --libs`
-    AC_SUBST(LIB_IMLIB)
-  fi
-else
-  ac_imlib_config=`which imlib-config 2>/dev/null`
-  if test -z "$ac_imlib_config"; then
-    AC_MSG_RESULT(no)
-  else
-    dummy=`echo "$ac_imlib_config" | grep '/imlib-config'`
-    if test -z "$dummy"; then
-      AC_MSG_RESULT(no)
-      ac_imlib_config=""
-    else
-      LIB_IMLIB=`$ac_imlib_config --libs`
-      IMLIB_CFLAGS=`$ac_imlib_config --cflags`
-      imlib_config=`echo "$LIB_IMLIB" | grep lImlib`
-      if test -z "$imlib_config"; then
-        AC_MSG_RESULT(no)
-        ac_imlib_config=""
-      else
-        AC_SUBST(LIB_IMLIB)
-        AC_SUBST(IMLIB_CFLAGS)
-        AC_MSG_RESULT($ac_imlib_config)
-      fi
-    fi
-  fi
-fi
-
-])
-
-dnl #### now some kuickshow stuff ###
-dnl Check if Imlib is installed properly
-KDE_PKG_CHECK_MODULES(IMLIB, imlib >= 1.9.10, 
+KDE_PKG_CHECK_MODULES(IMLIB, imlib2 >= 1.0,
   LIB_IMLIB=$IMLIB_LIBS
   AC_SUBST(LIB_IMLIB)
 ,
-KDE_FIND_IMLIB_CONFIG
+  :
 )
- 
+
 if test -z "$LIB_IMLIB"; then
-dnl  AC_MSG_ERROR([You need to install Imlib 1.x, e.g. http://freshmeat.net/redir/imlib/4385/url_tgz/imlib-1.9.10.tar.gz if your distributor doesn't have a package])
+dnl  AC_MSG_ERROR([You need to install Imlib2])
   DO_NOT_COMPILE="$DO_NOT_COMPILE kuickshow"
 fi
diff --git a/kuickshow/misc/CMakeLists.txt b/kuickshow/misc/CMakeLists.txt
deleted file mode 100644
index 6eaa92fd..00000000
--- a/kuickshow/misc/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-#################################################
-#
-#  (C) 2010-2011 Serghei Amelian
-#  serghei (DOT) amelian (AT) gmail.com
-#
-#  Improvements and feedback are welcome
-#
-#  This file is released under GPL >= 2
-#
-#################################################
-
-install( FILES im_palette.pal DESTINATION ${DATA_INSTALL_DIR}/kuickshow )
diff --git a/kuickshow/misc/Makefile.am b/kuickshow/misc/Makefile.am
deleted file mode 100644
index caea8ab1..00000000
--- a/kuickshow/misc/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-pal_DATA = im_palette.pal
-paldir = $(kde_datadir)/kuickshow
diff --git a/kuickshow/misc/im_palette.pal b/kuickshow/misc/im_palette.pal
deleted file mode 100644
index 9a243f73..00000000
--- a/kuickshow/misc/im_palette.pal
+++ /dev/null
@@ -1,64 +0,0 @@
-0x0 0x0 0x0
-0xff 0xff 0xff
-0xff 0x0 0x0
-0xff 0xff 0x0
-0x0 0xff 0x0
-0x0 0x0 0xff
-0x0 0xff 0xff
-0x99 0x99 0x99
-0xff 0x88 0x0
-0x88 0x0 0x0
-0x0 0x88 0x88
-0x88 0x88 0x0
-0xff 0xcc 0x97
-0xbb 0xbb 0xbb
-0x9f 0x6b 0x42
-0x55 0x55 0x55
-0xdd 0xdd 0xdd
-0x77 0x77 0x77
-0x33 0x33 0x33
-0xcc 0x0 0x0
-0xff 0x44 0x0
-0xff 0xcc 0x0
-0xcc 0xcc 0x0
-0x60 0x60 0x0
-0x0 0x43 0x0
-0x0 0x7f 0x0
-0x0 0xcc 0x0
-0x0 0x44 0x44
-0x0 0x0 0x44
-0x0 0x0 0x88
-0xef 0xb1 0x7b
-0xdf 0x98 0x5f
-0xbf 0x87 0x56
-0x7f 0x57 0x26
-0x5f 0x39 0xc
-0x3f 0x1c 0x0
-0x21 0x0 0x0
-0x0 0x43 0x87
-0x2d 0x70 0xaf
-0x5a 0x9e 0xd7
-0x87 0xcc 0xff
-0xff 0xe0 0xba
-0x21 0x43 0xf
-0x3d 0x5d 0x25
-0x59 0x78 0x3a
-0x75 0x93 0x4f
-0x91 0xae 0x64
-0xad 0xc8 0x7a
-0xf0 0xa8 0xef
-0xd0 0x88 0xd0
-0xaf 0x66 0xaf
-0x8e 0x44 0x8e
-0x6d 0x22 0x6d
-0x4b 0x0 0x4b
-0xff 0xc0 0xbc
-0xff 0x93 0x91
-0xff 0x66 0x67
-0xd8 0xf2 0xbf
-0xff 0xc9 0x68
-0xff 0x96 0x67
-0xa5 0x60 0xff
-0x51 0xff 0x99
-0x3f 0xa5 0x63
-0x98 0x90 0x67
diff --git a/kuickshow/src/defaultswidget.cpp b/kuickshow/src/defaultswidget.cpp
index c590d1f4..0d798bd3 100644
--- a/kuickshow/src/defaultswidget.cpp
+++ b/kuickshow/src/defaultswidget.cpp
@@ -98,7 +98,7 @@ DefaultsWidget::DefaultsWidget( TQWidget *parent, const char *name)
   imOrig = new ImlibWidget( 0L, gbPreview, "original image" );
 
   lbImFiltered = new TQLabel( i18n("Modified"), gbPreview );
-  imFiltered = new ImlibWidget( 0L, imOrig->getImlibData(), gbPreview, "" );
+  imFiltered = new ImlibWidget( 0L, gbPreview, "" );
   connect( imFiltered, TQ_SIGNAL( destroyed() ), TQ_SLOT( slotNoImage() ));
 
   ////
@@ -190,8 +190,6 @@ DefaultsWidget::DefaultsWidget( TQWidget *parent, const char *name)
 
 DefaultsWidget::~DefaultsWidget()
 {
-    // those need to be deleted in the right order, as imFiltered
-    // references ImlibData from imOrig
     delete imFiltered;
     delete imOrig;
 }
diff --git a/kuickshow/src/generalwidget.cpp b/kuickshow/src/generalwidget.cpp
index 5289c8e7..f6d883e0 100644
--- a/kuickshow/src/generalwidget.cpp
+++ b/kuickshow/src/generalwidget.cpp
@@ -83,19 +83,12 @@ GeneralWidget::GeneralWidget( TQWidget *parent, const char *name )
   layout->addStretch();
 
   cbSmoothScale = new TQCheckBox( i18n("Smooth scaling"), gbox2, "smoothscale" );
-  cbFastRender = new TQCheckBox( i18n("Fast rendering"), gbox2, "fastrender" );
   cbDither16bit = new TQCheckBox( i18n("Dither in HiColor (15/16bit) modes"),
 				 gbox2, "dither16bit" );
 
   cbDither8bit = new TQCheckBox( i18n("Dither in LowColor (<=8bit) modes"),
 				gbox2, "dither8bit" );
 
-  cbOwnPalette = new TQCheckBox( i18n("Use own color palette"),
-                                gbox2, "pal");
-  connect( cbOwnPalette, TQ_SIGNAL( clicked() ), this, TQ_SLOT( useOwnPalette() ) );
-
-  cbFastRemap = new TQCheckBox( i18n("Fast palette remapping"), gbox2, "remap");
-
   maxCacheSpinBox = new KIntNumInput( gbox2, "editmaxcache" );
   maxCacheSpinBox->setLabel( i18n("Maximum cache size: "), AlignVCenter );
   maxCacheSpinBox->setSuffix( i18n( " MB" ) );
@@ -124,15 +117,10 @@ void GeneralWidget::loadSettings( const KuickData& data )
     cbFullscreen->setChecked( data.fullScreen );
     cbPreload->setChecked( data.preloadImage );
     cbLastdir->setChecked( data.startInLastDir );
-    cbFastRemap->setChecked( idata->fastRemap );
-    cbOwnPalette->setChecked( idata->ownPalette );
     cbSmoothScale->setChecked( idata->smoothScale );
-    cbFastRender->setChecked( idata->fastRender );
     cbDither16bit->setChecked( idata->dither16bit );
     cbDither8bit->setChecked( idata->dither8bit );
     maxCacheSpinBox->setValue( idata->maxCache / 1024 );
-
-    useOwnPalette(); // enable/disable remap-checkbox
 }
 
 void GeneralWidget::applySettings( KuickData& data)
@@ -146,18 +134,10 @@ void GeneralWidget::applySettings( KuickData& data)
     data.startInLastDir   = cbLastdir->isChecked();
 
     idata->smoothScale    = cbSmoothScale->isChecked();
-    idata->fastRemap 	  = cbFastRemap->isChecked();
-    idata->ownPalette 	  = cbOwnPalette->isChecked();
-    idata->fastRender 	  = cbFastRender->isChecked();
     idata->dither16bit 	  = cbDither16bit->isChecked();
     idata->dither8bit 	  = cbDither8bit->isChecked();
 
     idata->maxCache	  = (uint) maxCacheSpinBox->value() * 1024;
 }
 
-void GeneralWidget::useOwnPalette()
-{
-    cbFastRemap->setEnabled( cbOwnPalette->isChecked() );
-}
-
 #include "generalwidget.moc"
diff --git a/kuickshow/src/generalwidget.h b/kuickshow/src/generalwidget.h
index f5970e2a..505ebfdf 100644
--- a/kuickshow/src/generalwidget.h
+++ b/kuickshow/src/generalwidget.h
@@ -42,9 +42,8 @@ public:
     void 	applySettings( KuickData& data );
 
 private:
-    TQCheckBox 	*cbFullscreen, *cbActiveWindow, *cbPreload, *cbLastdir;
-    TQCheckBox   *cbSmoothScale, *cbFastRemap, *cbFastRender;
-    TQCheckBox 	*cbDither16bit, *cbDither8bit, *cbOwnPalette;
+    TQCheckBox *cbFullscreen, *cbActiveWindow, *cbPreload, *cbLastdir;
+    TQCheckBox *cbSmoothScale, *cbDither16bit, *cbDither8bit;
 
     KLineEdit   	*editFilter;
     KIntNumInput 	*maxCacheSpinBox;
@@ -55,7 +54,6 @@ private:
     KColorButton        *colorButton;
 
 private slots:
-    void 	useOwnPalette();
     void slotURLClicked( const TQString & );
 
 };
diff --git a/kuickshow/src/imagewindow.cpp b/kuickshow/src/imagewindow.cpp
index ce4b365c..b0e751eb 100644
--- a/kuickshow/src/imagewindow.cpp
+++ b/kuickshow/src/imagewindow.cpp
@@ -73,13 +73,6 @@
 
 TQCursor *ImageWindow::s_handCursor = 0L;
 
-ImageWindow::ImageWindow( ImData *_idata, ImlibData *id, TQWidget *parent,
-			  const char *name )
-    : ImlibWidget( _idata, id, parent, name )
-{
-    init();
-}
-
 ImageWindow::ImageWindow( ImData *_idata, TQWidget *parent, const char *name )
     : ImlibWidget( _idata, parent, name )
 {
@@ -459,8 +452,7 @@ void ImageWindow::addBrightness( int factor )
     if ( factor == 0 )
 	return;
 
-    int oldValue = mod.brightness - ImlibOffset;
-    setBrightness( oldValue + (idata->brightnessFactor * (int) factor) );
+    setBrightness( colMod.brightness + (idata->brightnessFactor * (int) factor) );
 }
 
 void ImageWindow::addContrast( int factor )
@@ -468,8 +460,7 @@ void ImageWindow::addContrast( int factor )
     if ( factor == 0 )
 	return;
 
-    int oldValue = mod.contrast - ImlibOffset;
-    setContrast( oldValue + (idata->contrastFactor * (int) factor) );
+    setContrast( colMod.contrast + (idata->contrastFactor * (int) factor) );
 }
 
 void ImageWindow::addGamma( int factor )
@@ -477,8 +468,7 @@ void ImageWindow::addGamma( int factor )
     if ( factor == 0 )
 	return;
 
-    int oldValue = mod.gamma - ImlibOffset;
-    setGamma( oldValue + (idata->gammaFactor * (int) factor) );
+    setGamma( colMod.gamma + (idata->gammaFactor * (int) factor) );
 }
 
 
@@ -948,7 +938,10 @@ void ImageWindow::saveImage()
             {
                 if ( url.equals( m_kuim->url() ))
                 {
-                    Imlib_apply_modifiers_to_rgb( id, m_kuim->imlibImage() );
+                    imlib_context_push( context );
+                    imlib_context_set_image( m_kuim->imlibImage() );
+                    imlib_apply_color_modifier();
+                    imlib_context_pop();
                     resetImageModifier();
                 }
             }
@@ -965,47 +958,52 @@ bool ImageWindow::saveImage( const KURL& dest, bool keepOriginalSize )
     int w = keepOriginalSize ? m_kuim->originalWidth()  : m_kuim->width();
     int h = keepOriginalSize ? m_kuim->originalHeight() : m_kuim->height();
     if ( keepOriginalSize && (m_kuim->absRotation() == ROT_90 || m_kuim->absRotation() == ROT_270 ) )
-        tqSwap( w, h );
+	tqSwap( w, h );
 
-    ImlibImage *saveIm = Imlib_clone_scaled_image( id, m_kuim->imlibImage(), w, h );
-    bool success = false;
+    TQString saveFile;
+    if ( dest.isLocalFile() )
+	saveFile = dest.path();
+    else
+    {
+	TQString extension = TQFileInfo( dest.fileName() ).extension();
+	if ( !extension.isEmpty() )
+	    extension.prepend( '.' );
+
+	KTempFile tmpFile( TQString(), extension );
+	if ( tmpFile.status() != 0 )
+	    return false;
+	tmpFile.close();
+	if ( tmpFile.status() != 0 )
+	    return false;
+	saveFile = tmpFile.name();
+    }
 
-	TQString saveFile;
-	if ( dest.isLocalFile() )
-		saveFile = dest.path();
-	else 
+    bool success = false;
+    imlib_context_push( context );
+    imlib_context_set_image( m_kuim->originalImage() );
+    int oriW = imlib_image_get_width();
+    int oriH = imlib_image_get_height();
+    Imlib_Image saveIm = imlib_create_cropped_scaled_image( 0, 0, oriW, oriH, w, h );
+    if ( saveIm )
+    {
+	imlib_context_set_image( saveIm );
+	imlib_apply_color_modifier();
+	int err = 0;
+	imlib_save_image_with_errno_return( TQFile::encodeName( saveFile ).data(), &err );
+	success = ( err == 0 );
+	if ( success && !dest.isLocalFile() )
 	{
-		TQString extension = TQFileInfo( dest.fileName() ).extension();
-		if ( !extension.isEmpty() )
-			extension.prepend( '.' );
-		
-		KTempFile tmpFile( TQString(), extension );
-		if ( tmpFile.status() != 0 )
-			return false;
-		tmpFile.close();
-		if ( tmpFile.status() != 0 )
-			return false;
-		saveFile = tmpFile.name();		
+	    if ( isFullscreen() )
+		toggleFullscreen(); // otherwise upload window would block us invisibly
+	    success = TDEIO::NetAccess::upload( saveFile, dest, const_cast<ImageWindow*>( this ) );
 	}
-	
-    if ( saveIm ) 
-    {
-        Imlib_apply_modifiers_to_rgb( id, saveIm );
-        success = Imlib_save_image( id, saveIm,
-                                    TQFile::encodeName( saveFile ).data(),
-                                    NULL );
-        if ( success && !dest.isLocalFile() ) 
-        {
-        	if ( isFullscreen() )
-        		toggleFullscreen(); // otherwise upload window would block us invisibly
-        	success = TDEIO::NetAccess::upload( saveFile, dest, const_cast<ImageWindow*>( this ) );
-        }
-                                    
-        // 'saveIm' contains a copy made out of 'myIm' in 'm_kuim', there is no point
-        // in keeping 'saveIm' in the imlib cache, so use 'Imlib_kill_image' for it
-        Imlib_kill_image( id, saveIm );
-    }
 
+	// 'saveIm' contains a copy made out of 'myIm' in 'm_kuim', there is no point
+	// in keeping 'saveIm' in the imlib cache, so use 'imlib_free_image_and_decache'
+	imlib_context_set_image( saveIm );
+	imlib_free_image_and_decache();
+    }
+    imlib_context_pop();
     return success;
 }
 
diff --git a/kuickshow/src/imagewindow.h b/kuickshow/src/imagewindow.h
index 30d2c00e..61e3efb5 100644
--- a/kuickshow/src/imagewindow.h
+++ b/kuickshow/src/imagewindow.h
@@ -41,8 +41,6 @@ class ImageWindow : public ImlibWidget
   
 
 public:
-  ImageWindow( ImData *_idata, ImlibData *id, TQWidget *parent=0,
-	       const char *name=0 );
   ImageWindow( ImData *_idata=0, TQWidget *parent=0, const char *name=0 );
 
   bool 		showNextImage( KuickFile * file );
diff --git a/kuickshow/src/imdata.cpp b/kuickshow/src/imdata.cpp
index c580f7e3..68336b84 100644
--- a/kuickshow/src/imdata.cpp
+++ b/kuickshow/src/imdata.cpp
@@ -25,9 +25,6 @@
 
 ImData::ImData()
 {
-  ownPalette     = true;
-  fastRemap      = true;
-  fastRender  	 = true;
   dither16bit    = false;
   dither8bit     = true;
   smoothScale    = false;
@@ -49,9 +46,6 @@ void ImData::load( TDEConfig *kc )
 
   kc->setGroup( "ImlibConfiguration" );
 
-  ownPalette  = kc->readBoolEntry( "UseOwnPalette", def.ownPalette );
-  fastRemap   = kc->readBoolEntry( "FastRemapping", def.fastRemap );
-  fastRender  = kc->readBoolEntry( "FastRendering", def.fastRender );
   dither16bit = kc->readBoolEntry( "Dither16Bit", def.dither16bit );
   dither8bit  = kc->readBoolEntry( "Dither8Bit", def.dither8bit );
   smoothScale = kc->readBoolEntry( "SmoothScaling", def.smoothScale );
@@ -72,9 +66,6 @@ void ImData::save( TDEConfig *kc )
 {
   kc->setGroup( "ImlibConfiguration" );
 
-  kc->writeEntry( "UseOwnPalette", ownPalette );
-  kc->writeEntry( "FastRemapping", fastRemap );
-  kc->writeEntry( "FastRendering", fastRender );
   kc->writeEntry( "Dither16Bit", dither16bit );
   kc->writeEntry( "Dither8Bit", dither8bit );
   kc->writeEntry( "MaxCacheSize", maxCache );
diff --git a/kuickshow/src/imdata.h b/kuickshow/src/imdata.h
index 9ef5faa0..c4afd101 100644
--- a/kuickshow/src/imdata.h
+++ b/kuickshow/src/imdata.h
@@ -37,13 +37,9 @@ public:
 
   // -----------------------
 
-  bool 		ownPalette		:1;
-  bool 		fastRemap		:1;
-  bool 		fastRender		:1;
   bool		dither16bit		:1;
   bool 		dither8bit		:1;
   bool		smoothScale		:1;
-  
 
   uint          gammaFactor;
   uint          brightnessFactor;
diff --git a/kuickshow/src/imlibwidget.cpp b/kuickshow/src/imlibwidget.cpp
index 1e683d26..ddafd472 100644
--- a/kuickshow/src/imlibwidget.cpp
+++ b/kuickshow/src/imlibwidget.cpp
@@ -41,82 +41,53 @@
 #include "kuickimage.h"
 #include "imlibwidget.h"
 
-const int ImlibWidget::ImlibOffset = 256;
-
 ImlibWidget::ImlibWidget( ImData *_idata, TQWidget *parent, const char *name ) :
   TQWidget( parent, name, WDestructiveClose )
 {
-    idata 		= _idata;
-    deleteImData 	= false;
-    deleteImlibData 	= true;
-
-    if ( !idata ) { // if no imlib configuration was given, create one ourself
+    idata = _idata;
+    deleteImData = false;
+    if ( !idata ) {
+	// if no imlib configuration was given, create one ourself
 	idata = new ImData;
 	deleteImData = true;
     }
 
-    ImlibInitParams par;
-
-    // PARAMS_PALETTEOVERRIDE taken out because of segfault in imlib :o(
-    par.flags = ( PARAMS_REMAP | PARAMS_VISUALID |
-		  PARAMS_FASTRENDER | PARAMS_HIQUALITY | PARAMS_DITHER |
-		  PARAMS_IMAGECACHESIZE | PARAMS_PIXMAPCACHESIZE );
-
-    Visual* defaultvis = DefaultVisual(x11Display(), x11Screen());
-
-    par.paletteoverride = idata->ownPalette ? 1 : 0;
-    par.remap           = idata->fastRemap ? 1 : 0;
-    par.fastrender      = idata->fastRender ? 1 : 0;
-    par.hiquality       = idata->dither16bit ? 1 : 0;
-    par.dither          = idata->dither8bit ? 1 : 0;
-    par.visualid        = defaultvis->visualid;
-    uint maxcache       = idata->maxCache;
-
-    // 0 == no cache
-    par.imagecachesize  = maxcache * 1024;
-    par.pixmapcachesize = maxcache * 1024;
+    // Initialize Imlib2 context
+    context = imlib_context_new();
+    imlib_context_push(context);
 
-    id = Imlib_init_with_params( x11Display(), &par );
+    // Set display, visual and drawable
+    Display *dpy = x11Display();
+    imlib_context_set_display(dpy);
+    imlib_context_set_visual(DefaultVisual(dpy, x11Screen()));
+    imlib_context_set_drawable(DefaultRootWindow(dpy));
 
-    init();
-}
+    // Set rendering quality
+    int depth = DefaultDepth(dpy, x11Screen());
+    imlib_context_set_dither( depth <= 8 ? idata->dither8bit :
+                             (depth <= 16 ? idata->dither16bit : false));
+    imlib_context_set_anti_alias(1);
 
-
-ImlibWidget::ImlibWidget( ImData *_idata, ImlibData *_id, TQWidget *parent,
-			  const char *name )
-    : TQWidget( parent, name, WDestructiveClose )
-{
-    id              = _id;
-    idata           = _idata;
-    deleteImData    = false;
-    deleteImlibData = false;
-
-    if ( !idata ) {
-	idata = new ImData;
-	deleteImData = true;
-    }
+    imlibColMod = imlib_create_color_modifier();
+    imlib_context_pop();
 
     init();
 }
 
-
 void ImlibWidget::init()
 {
     int w = 1; // > 0 for XCreateWindow
     int h = 1;
     myBackgroundColor = TQt::black;
-    m_kuim              = 0L;
+    m_kuim      = 0L;
     m_kuickFile = 0L;
 
-    if ( !id )
-	tqFatal("ImlibWidget: Imlib not initialized, aborting.");
-
     setAutoRender( true );
 
     setPalette( TQPalette( myBackgroundColor ));
     setBackgroundMode( PaletteBackground );
 
-    imageCache = new ImageCache( id, 4 ); // cache 4 images (FIXME?)
+    imageCache = new ImageCache( context, 4 ); // cache 4 images (FIXME?)
     connect( imageCache, TQ_SIGNAL( sigBusy() ), TQ_SLOT( setBusyCursor() ));
     connect( imageCache, TQ_SIGNAL( sigIdle() ), TQ_SLOT( restoreCursor() ));
 
@@ -126,7 +97,13 @@ void ImlibWidget::init()
 ImlibWidget::~ImlibWidget()
 {
     delete imageCache;
-    if ( deleteImlibData && id ) free ( id );
+
+    imlib_context_push(context);
+    imlib_context_set_color_modifier(imlibColMod);
+    imlib_free_color_modifier();
+    imlib_context_pop();
+    imlib_context_free(context);
+
     if ( win ) XDestroyWindow( x11Display(), win );
     if ( deleteImData ) delete idata;
 }
@@ -158,9 +135,9 @@ KuickImage * ImlibWidget::loadImageInternal( KuickFile * file )
     }
 
     // apply default image modifications
-    mod.brightness = idata->brightness + ImlibOffset;
-    mod.contrast = idata->contrast + ImlibOffset;
-    mod.gamma = idata->gamma + ImlibOffset;
+    colMod.brightness = idata->brightness;
+    colMod.contrast = idata->contrast;
+    colMod.gamma = idata->gamma;
     applyImageModifier( kuim );
 
     loaded( kuim ); // maybe upscale/downscale/rotate in subclasses
@@ -168,11 +145,6 @@ KuickImage * ImlibWidget::loadImageInternal( KuickFile * file )
     return kuim;
 }
 
-// overridden in subclass
-void ImlibWidget::loaded( KuickImage * )
-{
-}
-
 bool ImlibWidget::loadImage( const KURL& url )
 {
     return loadImage( FileCache::self()->getFile( url ));
@@ -234,7 +206,7 @@ void ImlibWidget::showImage()
 // -256..256
 void ImlibWidget::setBrightness( int factor )
 {
-    mod.brightness = factor + ImlibOffset;
+    colMod.brightness = factor;
     applyImageModifier( m_kuim );
 
     autoUpdate();
@@ -244,7 +216,7 @@ void ImlibWidget::setBrightness( int factor )
 // -256..256
 void ImlibWidget::setContrast( int factor )
 {
-    mod.contrast = factor + ImlibOffset;
+    colMod.contrast = factor;
     applyImageModifier( m_kuim );
 
     autoUpdate();
@@ -254,7 +226,7 @@ void ImlibWidget::setContrast( int factor )
 // -256..256
 void ImlibWidget::setGamma( int factor )
 {
-    mod.gamma = factor + ImlibOffset;
+    colMod.gamma = factor;
     applyImageModifier( m_kuim );
 
     autoUpdate();
@@ -430,9 +402,6 @@ void ImlibWidget::updateWidget( bool geometryUpdate )
     if ( !m_kuim )
 	return;
 
-//     if ( geometryUpdate )
-//         XUnmapWindow( x11Display(), win );// remove the old image -> no flicker
-
     XSetWindowBackgroundPixmap( x11Display(), win, m_kuim->pixmap() );
 
     if ( geometryUpdate )
@@ -477,15 +446,47 @@ void ImlibWidget::applyImageModifier( KuickImage *kuim )
     if ( !kuim )
 	return;
 
-    Imlib_set_image_modifier( id, kuim->imlibImage(), &mod );
+    imlib_context_push(context);
+    imlib_context_set_color_modifier(imlibColMod);
+    imlib_reset_color_modifier();
+
+    // The brightness/contrast/gamma modifiers affects the alpha table as well,
+    // so save the current alpha lookup table first and restore it afterwards.
+    // This to prevent RGB settings from changing the transparency of the image.
+    uint8_t alphaLUT[256];
+    imlib_get_color_modifier_tables(NULL, NULL, NULL, alphaLUT);
+
+    // brightness: -256..256 -> -1.0..1.0 (0.0 = identity)
+    double bval = colMod.brightness / 256.0;
+    if (bval != 0.0)
+    {
+	imlib_modify_color_modifier_brightness(bval);
+    }
+    // contrast: -256..256 -> 0.0..2.0 (1.0 = identity)
+    double cval = 1.0 + (colMod.contrast / 256.0);
+    if (cval != 1.0)
+    {
+	imlib_modify_color_modifier_contrast(cval);
+    }
+    // gamma: -256..256 -> 0.0..2.0 (1.0 = identity)
+    double gval = 1.0 + (colMod.gamma / 256.0);
+    if (gval != 1.0)
+    {
+	imlib_modify_color_modifier_gamma(gval);
+    }
+
+    // Restore the original alpha table
+    imlib_set_color_modifier_tables(NULL, NULL, NULL, alphaLUT);
+
+    imlib_context_pop();
     kuim->setDirty( true );
 }
 
 void ImlibWidget::resetImageModifier()
 {
-    mod.brightness = ImlibOffset;
-    mod.contrast = ImlibOffset;
-    mod.gamma = ImlibOffset;
+    colMod.brightness = 0;
+    colMod.contrast = 0;
+    colMod.gamma = 0;
     applyImageModifier( m_kuim );
 }
 
@@ -533,17 +534,14 @@ void ImlibWidget::reparent( TQWidget* parent, WFlags f, const TQPoint& p, bool s
         XMapWindow( x11Display(), win );
 }
 
-void ImlibWidget::rotated( KuickImage *, int )
-{
-}
 
 //----------
 
 
 // uhh ugly, we have two lists to map from filename to KuickImage :-/
-ImageCache::ImageCache( ImlibData *id, int maxImages )
+ImageCache::ImageCache( Imlib_Context ctx, int maxImages )
 {
-    myId        = id;
+    context     = ctx;
     idleCount   = 0;
     myMaxImages = maxImages;
     kuickList.setAutoDelete( true );
@@ -583,7 +581,53 @@ void ImageCache::slotIdle()
     idleCount--;
 
     if ( idleCount == 0 )
-	emit sigIdle();
+        emit sigIdle();
+}
+
+
+Imlib_Image ImageCache::fromTQImage( const TQString& fileName ) const
+{
+    KImageIO::registerFormats();
+    TQImage image( TQFile::encodeName( fileName ).data() );
+    if ( image.isNull() )
+        return 0L;
+
+    bool hasAlpha = image.hasAlphaBuffer();
+    if ( image.depth() != 32 )
+    {
+        image = image.convertDepth( 32 );
+        if ( image.isNull() )
+            return 0L;
+    }
+
+    int w = image.width();
+    int h = image.height();
+    int numPixels = w * h;
+    uint32_t *newImageData = new uint32_t[numPixels];
+    uint32_t *newData = newImageData;
+
+    for ( int y = 0; y < h; y++ )
+    {
+        TQRgb *scanLine = reinterpret_cast<TQRgb *>( image.scanLine( y ) );
+        for ( int x = 0; x < w; x++ )
+        {
+            const TQRgb& pixel = scanLine[x];
+            uint32_t alpha = hasAlpha ? tqAlpha( pixel ) : 0xFF;
+            *(newData++) = ( alpha << 24 ) | ( tqRed( pixel ) << 16 ) |
+                ( tqGreen( pixel ) << 8 ) | tqBlue( pixel );
+        }
+    }
+
+    Imlib_Image im = imlib_create_image_using_copied_data( w, h, newImageData );
+    delete [] newImageData;
+    if ( im && hasAlpha )
+    {
+        imlib_context_push( context );
+        imlib_context_set_image( im );
+        imlib_image_set_has_alpha( 1 );
+        imlib_context_pop();
+    }
+    return im;
 }
 
 
@@ -596,40 +640,48 @@ KuickImage * ImageCache::getKuimage( KuickFile * file )
     if ( file->waitForDownload( 0L ) != KuickFile::OK ) // and for users
     	return 0L;
 
-    KuickImage *kuim = 0L;
+    KuickImage *kuim = nullptr;
     int index = fileList.findIndex( file );
     if ( index != -1 ) {
-        if ( index == 0 )
-            kuim = kuickList.at( 0 );
+        kuim = kuickList.at( index );
 
+        // Drop the cached image if the file was modified on the disk
+        if ( kuim && kuim->fileChangedOnDisk() ) {
+            kuickList.remove( index );
+            fileList.remove( file );
+            kuim = nullptr;
+        }
         // need to reorder the lists, otherwise we might delete the current
         // image when a new one is cached and the current one is the last!
-        else {
+        else if ( index != 0 ) {
             kuim = kuickList.take( index );
             kuickList.insert( 0, kuim );
             fileList.remove( file );
             fileList.prepend( file );
         }
 
-        return kuim;
+        if ( kuim ) {
+            return kuim;
+        }
     }
 
     if ( !kuim ) {
 	slotBusy();
 
-	ImlibImage *im = Imlib_load_image( myId, TQFile::encodeName( file->localFile() ).data() );
+	imlib_context_push(context);
+	Imlib_Image im = imlib_load_image( TQFile::encodeName( file->localFile() ).data() );
+	imlib_context_pop();
+
 	if ( !im )
 	{
 	    // Try loading using TQImage
-	    KImageIO::registerFormats();
-	    TQImage image(TQFile::encodeName(file->localFile()).data());
-	    im = KuickImage::fromTQImage(myId, image);
+	    im = fromTQImage( file->localFile() );
 	}
 	slotIdle();
 	if ( !im )
 	    return 0L;
 
-	kuim = new KuickImage( file, im, myId );
+	kuim = new KuickImage( file, im, context );
 	connect( kuim, TQ_SIGNAL( startRendering() ),   TQ_SLOT( slotBusy() ));
 	connect( kuim, TQ_SIGNAL( stoppedRendering() ), TQ_SLOT( slotIdle() ));
 
diff --git a/kuickshow/src/imlibwidget.h b/kuickshow/src/imlibwidget.h
index e26094b9..d0281055 100644
--- a/kuickshow/src/imlibwidget.h
+++ b/kuickshow/src/imlibwidget.h
@@ -1,5 +1,4 @@
 /****************************************************************************
-** $Id$
 **
 ** ImlibWidget: maps an Xlib window with Imlib's contents on a TQWidget
 **
@@ -22,65 +21,57 @@
 
 #include <kurl.h>
 
-// #include those AFTER TQt-includes!
-#include <Imlib.h>
+#include <Imlib2.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
-// #include <X11/extensions/shape.h>
 
 #include "imdata.h"
 #include "kuickdata.h"
 
 class KuickFile;
 class KuickImage;
+class TQColor;
 
 class ImageCache : public TQObject
 {
   TQ_OBJECT
   
-
 public:
-  ImageCache( ImlibData *id, int maxImages=1 );
+  ImageCache( Imlib_Context ctx, int maxImages=1 );
   ~ImageCache();
 
-  void 			setMaxImages( int maxImages );
-  int 			maxImages() 		const { return myMaxImages; }
+  void setMaxImages( int maxImages );
+  int  maxImages() const { return myMaxImages; }
 
-  KuickImage *		getKuimage( KuickFile * file );
+  KuickImage* getKuimage( KuickFile * file );
 
 private:
-  int 			myMaxImages;
-  TQValueList<KuickFile*>fileList;
-  TQPtrList<KuickImage>	kuickList;
-  //  TQPtrList<ImlibImage>	imList;
-  ImlibData * 		myId;
-  int 			idleCount;
+  Imlib_Image fromTQImage( const TQString& fileName ) const;
+
+  int myMaxImages;
+  TQValueList<KuickFile*> fileList;
+  TQPtrList<KuickImage> kuickList;
+  Imlib_Context context;
+  int idleCount;
 
 private slots:
-  void 			slotBusy();
-  void 			slotIdle();
+  void slotBusy();
+  void slotIdle();
 
 signals:
-  void			sigBusy();
-  void 			sigIdle();
-
+  void sigBusy();
+  void sigIdle();
 };
 
-
 // ------------------------------------------
 
-class TQColor;
-
 class ImlibWidget : public TQWidget
 {
   TQ_OBJECT
   
-
 public:
 
   ImlibWidget( ImData *_idata=0, TQWidget *parent=0, const char *name=0 );
-  ImlibWidget( ImData *_idata, ImlibData *id, TQWidget *parent=0,
-	       const char *name=0 );
   virtual ~ImlibWidget();
 
   KURL          url()                   const;
@@ -95,17 +86,11 @@ public:
   void 		setRotation( Rotation );
   void 		setFlipMode( int mode );
 
-  int 		brightness() 		 const; // ### no impl!
-  int 		contrast()		 const; // ### no impl!
-  int 		gamma() 		 const; // ### no impl!
-
-  int 		imageWidth() 		 const;
-  int 		imageHeight() 		 const;
+  int 		imageWidth()  const;
+  int 		imageHeight() const;
 
   void 		setAutoRender( bool enable )   { isAutoRendering = enable;}
   bool 		isAutoRenderEnabled() 	const  { return isAutoRendering;  }
-  void 		setMaxImageCache( int );
-  int 		maxImageCache() 	const  { return myMaxImageCache;  }
   const TQColor& backgroundColor() 	const;
   void 		setBackgroundColor( const TQColor& );
 
@@ -115,8 +100,6 @@ public:
    */
   virtual bool  autoRotate( KuickImage *kuim );
 
-  ImlibData*	getImlibData() const 	       { return id; 		  }
-
   virtual void  reparent( TQWidget* parent, WFlags f, const TQPoint& p, bool showIt = false );
 
 public slots:
@@ -137,9 +120,9 @@ protected:
   void 		rotate( int );
   void 		updateWidget( bool geometryUpdate=true );
   virtual void 	updateGeometry( int width, int height );
-  virtual void  loaded( KuickImage * );
+  virtual void  loaded( KuickImage * ) {}
   virtual bool  canZoomTo( int newWidth, int newHeight );
-  virtual void  rotated( KuickImage *kuim, int rotation );
+  virtual void  rotated( KuickImage *kuim, int rotation ) {}
 
   void 		closeEvent( TQCloseEvent * );
 
@@ -148,26 +131,32 @@ protected:
       updateWidget( geometryUpdate );
   }
 
-  bool		stillResizing, deleteImData, deleteImlibData;
-  bool          imlibModifierChanged;
+  bool		deleteImData;
 
   KuickImage 	*m_kuim;
   ImageCache 	*imageCache;
-  ImlibData     *id;
   ImData    	*idata;
   Window        win;
-  ImlibColorModifier mod;
+  Imlib_Context  context;
 
   KuickFile *m_kuickFile;
   TQCursor m_oldCursor;
 
-  static const int ImlibOffset;
+  // Small utility class to keep track of the current modifiers
+  struct ColorModifiers {
+    int brightness;
+    int contrast;
+    int gamma;
+
+    ColorModifiers() : brightness(0), contrast(0), gamma(0) {}
+  };
 
+  ColorModifiers colMod;
+  Imlib_Color_Modifier imlibColMod;
 
 private:
   void 		init();
   bool 		isAutoRendering;
-  int 		myMaxImageCache;
   TQColor 	myBackgroundColor;
 
 
@@ -182,5 +171,4 @@ signals:
 
 };
 
-
 #endif
diff --git a/kuickshow/src/kuickimage.cpp b/kuickshow/src/kuickimage.cpp
index 1a5dc61e..67136291 100644
--- a/kuickshow/src/kuickimage.cpp
+++ b/kuickshow/src/kuickimage.cpp
@@ -1,13 +1,25 @@
 #include "kuickimage.h"
 
-KuickImage::KuickImage( const KuickFile * file, ImlibImage *im, ImlibData *id)
+#include <tqfileinfo.h>
+
+KuickImage::KuickImage( const KuickFile *file, Imlib_Image im, Imlib_Context context )
     : TQObject( 0L, 0L )
 {
-    myFile       = file;
-    myId         = id;
-    myPixmap     = 0L;
-    myWidth      = im->rgb_width;
-    myHeight     = im->rgb_height;
+    myFile   = file;
+    myPixmap = 0L;
+
+    TQFileInfo fi(file->localFile());
+    myFileDateTime = fi.lastModified();
+    myFileSize     = fi.size();
+
+    myContext  = context;
+    imlib_context_push(myContext);
+    imlib_context_set_image(im);
+    // Ask imlib2 to re-check for file changes on subsequent imlib_load_image() calls.
+    imlib_image_set_changes_on_disk();
+    myWidth    = imlib_image_get_width();
+    myHeight   = imlib_image_get_height();
+    imlib_context_pop();
 
     myOrigWidth  = myWidth;
     myOrigHeight = myHeight;
@@ -18,26 +30,30 @@ KuickImage::KuickImage( const KuickFile * file, ImlibImage *im, ImlibData *id)
 
 KuickImage::~KuickImage()
 {
+    imlib_context_push(myContext);
     if ( myPixmap )
     {
-	Imlib_free_pixmap( myId, myPixmap );
-	myPixmap = 0L;
+	imlib_free_pixmap_and_mask( myPixmap );
+	myPixmap = 0;
     }
-
     if ( mySavedIm.im )
     {
 	// In this case, the original image loaded from file is in 'mySavedIm.im' while
 	// 'myIm.im' contains a copy made out of it. There is no point in keeping
-	// 'myIm.im' in the imlib cache, so use 'Imlib_kill_image' for it
-	Imlib_destroy_image( myId, mySavedIm.im );
-	Imlib_kill_image( myId, myIm.im );
+	// 'myIm.im' in the imlib cache, so use 'imlib_free_image_and_decache' for it
+	imlib_context_set_image(mySavedIm.im);
+	imlib_free_image();
+	imlib_context_set_image(myIm.im);
+	imlib_free_image_and_decache();
     }
     else
     {
 	// In this case, the original image loaded from file is in 'myIm.im'.
 	// Keep in the internal 'imlib' cache in case we need to reload it.
-	Imlib_destroy_image( myId, myIm.im );
+	imlib_context_set_image(myIm.im);
+	imlib_free_image();
     }
+    imlib_context_pop();
 }
 
 Pixmap& KuickImage::pixmap()
@@ -53,74 +69,39 @@ void KuickImage::renderPixmap()
     if ( !myIsDirty )
 	return;
 
-//     tqDebug("### rendering: %s", myFilename.latin1());
-
+    imlib_context_push( myContext );
     if ( myPixmap )
     {
-	Imlib_free_pixmap( myId, myPixmap );
-	myPixmap = 0L;
+	imlib_free_pixmap_and_mask( myPixmap );
+        myPixmap = 0;
     }
 
     emit startRendering();
 
-// #ifndef NDEBUG
-//     struct timeval tms1, tms2;
-//     gettimeofday( &tms1, NULL );
-// #endif
-
-    Imlib_render( myId, myIm.im, myWidth, myHeight );
-    myPixmap = Imlib_move_image( myId, myIm.im );
-
-// #ifndef NDEBUG
-//     gettimeofday( &tms2, NULL );
-//     tqDebug("*** rendering image: %s, took %ld ms", myFilename.latin1(),
-//            (tms2.tv_usec - tms1.tv_usec)/1000);
-// #endif
+    imlib_context_set_image(myIm.im);
+    imlib_render_pixmaps_for_whole_image_at_size(&myPixmap, 0L, myWidth, myHeight);
 
     emit stoppedRendering();
-
+    imlib_context_pop();
     myIsDirty = false;
 }
 
-void KuickImage::flipRotateImage(ImOrientedImage *image, FlipRotation fr) {
-    // Note: 'Imlib_rotate_image' does not rotate an image but actually
-    //       transpose it against the top-left/bottom-right diagonal.
-    if (!fr.flip) {
-	switch (fr.rot) {
-	case ROT_0:
-	    break;
-	case ROT_90:
-	    Imlib_rotate_image(myId, image->im, 0);
-	    Imlib_flip_image_horizontal(myId, image->im);
-	    break;
-	case ROT_180:
-	    Imlib_flip_image_horizontal(myId, image->im);
-	    Imlib_flip_image_vertical(myId, image->im);
-	    break;
-	case ROT_270:
-	    Imlib_rotate_image(myId, image->im, 0);
-	    Imlib_flip_image_vertical(myId, image->im);
-	    break;
-	}
-    } else {
-	switch (fr.rot) {
-	case ROT_0:
-	    Imlib_flip_image_horizontal(myId, image->im);
-	    break;
-	case ROT_90:
-	    Imlib_rotate_image(myId, image->im, 0);
-	    Imlib_flip_image_horizontal(myId, image->im);
-	    Imlib_flip_image_vertical(myId, image->im);
-	    break;
-	case ROT_180:
-	    Imlib_flip_image_vertical(myId, image->im);
-	    break;
-	case ROT_270:
-	    Imlib_rotate_image(myId, image->im, 0);
-	    break;
-	}
-    }
+bool KuickImage::fileChangedOnDisk() const
+{
+    TQFileInfo fi(myFile->localFile());
+    return (fi.lastModified() != myFileDateTime) || (fi.size() != myFileSize);
+}
 
+void KuickImage::flipRotateImage(ImOrientedImage *image, FlipRotation fr)
+{
+    imlib_context_push(myContext);
+    imlib_context_set_image(image->im);
+    if (fr.flip)
+    {
+	imlib_image_flip_horizontal();
+    }
+    imlib_image_orientate((int)fr.rot);
+    imlib_context_pop();
     image->orient *= fr;
 }
 
@@ -182,33 +163,33 @@ void KuickImage::fastResize( int width, int height )
 
 bool KuickImage::smoothResize( int newWidth, int newHeight )
 {
-    // Save the current color modifier, this will need to be reapplied to the new image copy
-    ImlibColorModifier savedMod = myIm.im->mod;
-
     // Save original image to enhance quality of multiple smooth resizing
     saveOrigImage();
     // Orient original image to match current image state
     orientSavedImage();
 
-    TQImage *image = toTQImage();
-    // Note: TQImage::ScaleMin seems to have a bug (off-by-one, sometimes results in width being 1 pixel too small)
-    TQImage scaledImage = image->smoothScale(newWidth, newHeight, TQImage::ScaleFree);
-    delete image;
+    imlib_context_push(myContext);
+    imlib_context_set_image(mySavedIm.im);
+    int w = imlib_image_get_width();
+    int h = imlib_image_get_height();
+    Imlib_Image newIm = imlib_create_cropped_scaled_image(0, 0, w, h, newWidth, newHeight);
+    imlib_context_pop();
 
-    ImlibImage *newIm = fromTQImage(myId, scaledImage);
     if (newIm)
     {
-	if ( myIm.im )
+	if (myIm.im)
 	{
 	    // Make sure to correctly deallocate previous copies of the image in
 	    // case of repeated scaling operations. There is no point in keeping
-	    // 'myIm.im' in the imlib cache, so use 'Imlib_kill_image' for it
-	    Imlib_kill_image( myId, myIm.im );
+	    // 'myIm.im' in the imlib cache, so use 'imlib_free_image_and_decache'
+	    imlib_context_push(myContext);
+	    imlib_context_set_image(myIm.im);
+	    imlib_free_image_and_decache();
+	    imlib_context_pop();
 	}
 	myIm.im = newIm;
 	myWidth = newWidth;
 	myHeight = newHeight;
-	Imlib_set_image_modifier( myId, myIm.im, &savedMod );
 	myIsDirty = true;
 	return true;
     }
@@ -238,9 +219,14 @@ void KuickImage::restoreSavedImage()
 	return;
     }
     orientSavedImage();
+
     // 'myIm.im' contains a copy made out of 'mySavedIm.im', there is no point in keeping
-    // 'myIm.im' in the imlib cache, so use 'Imlib_kill_image' for it
-    Imlib_kill_image(myId, myIm.im);
+    // 'myIm.im' in the imlib cache, so use 'imlib_free_image_and_decache'
+    imlib_context_push(myContext);
+    imlib_context_set_image(myIm.im);
+    imlib_free_image_and_decache();
+    imlib_context_pop();
+
     myIm = mySavedIm;
     mySavedIm.im = nullptr;
 }
@@ -255,77 +241,14 @@ void KuickImage::orientSavedImage()
     flipRotateImage(&mySavedIm, mySavedIm.orient.transitionTo(myIm.orient));
 }
 
-TQImage* KuickImage::toTQImage() const
+Imlib_Image KuickImage::originalImage()
 {
-    ImlibImage *im = mySavedIm.im;
-    int w = im->rgb_width;
-    int h = im->rgb_height;
-
-    TQImage *image = new TQImage(w, h, 32);
-    uchar *rgb = im->rgb_data;
-    TQRgb **destImageData = reinterpret_cast<TQRgb**>(image->jumpTable());
-
-    int byteIndex = 0;
-    int destLineIndex = 0;
-    int destByteIndex = 0;
-    for (int pixel = 0; pixel < (w * h); pixel++)
-    {
-	if (pixel != 0 && (pixel % w) == 0)
-	{
-	    destLineIndex++;
-	    destByteIndex = 0;
-	}
-
-	uchar r = rgb[byteIndex++];
-	uchar g = rgb[byteIndex++];
-	uchar b = rgb[byteIndex++];
-	destImageData[destLineIndex][destByteIndex++] = tqRgb(r, g, b);
-    }
-
-    return image;
-}
-
-ImlibImage * KuickImage::fromTQImage( ImlibData *id, TQImage& image )
-{
-    if ( image.isNull() )
-	return 0L;
-
-    if ( image.depth() != 32 )
-    {
-	image.setAlphaBuffer(false);
-	image = image.convertDepth(32);
-
-	if ( image.isNull() )
-	    return 0L;
-    }
-
-    // convert to 24 bpp (discard alpha)
-    int numPixels = image.width() * image.height();
-    const int NUM_BYTES_NEW  = 3; // 24 bpp
-    uchar *newImageData = new uchar[numPixels * NUM_BYTES_NEW];
-    uchar *newData = newImageData;
-
-    int w = image.width();
-    int h = image.height();
-
-    for (int y = 0; y < h; y++)
+    if (mySavedIm.im)
     {
-	TQRgb *scanLine = reinterpret_cast<TQRgb *>( image.scanLine(y) );
-	for (int x = 0; x < w; x++)
-	{
-	    const TQRgb& pixel = scanLine[x];
-	    *(newData++) = tqRed(pixel);
-	    *(newData++) = tqGreen(pixel);
-	    *(newData++) = tqBlue(pixel);
-	}
+	orientSavedImage();
+	return mySavedIm.im;
     }
-
-    ImlibImage *im = Imlib_create_image_from_data( id, newImageData, NULL,
-                                                   image.width(), image.height() );
-
-    delete [] newImageData;
-
-    return im;
+    return myIm.im;
 }
 
 #include "kuickimage.moc"
diff --git a/kuickshow/src/kuickimage.h b/kuickshow/src/kuickimage.h
index c077e313..163a5bb1 100644
--- a/kuickshow/src/kuickimage.h
+++ b/kuickshow/src/kuickimage.h
@@ -1,5 +1,4 @@
 /****************************************************************************
-** $Id: .emacs,v 1.3 2002/02/20 15:06:53 gis Exp $
 **
 ** Created : 2002
 **
@@ -10,20 +9,18 @@
 #ifndef KUICKIMAGE_H
 #define KUICKIMAGE_H
 
-#include <tqimage.h>
-#include <tqobject.h>
+#include <tqdatetime.h>
 
 #include <kurl.h>
 
 #include "kuickdata.h"
 #include "kuickfile.h"
 
-// #include those AFTER TQt-includes!
-#include <Imlib.h>
+#include <Imlib2.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
-// #include <X11/extensions/shape.h>
 
+class KuickFile;
 
 class KuickImage : public TQObject
 {
@@ -33,7 +30,7 @@ class KuickImage : public TQObject
 public:
   enum ResizeMode { FAST, SMOOTH };
 
-  KuickImage( const KuickFile * file, ImlibImage *im, ImlibData *id );
+  KuickImage( const KuickFile * file, Imlib_Image im, Imlib_Context context );
   ~KuickImage();
 
   int 		width() 	const { return myWidth;   }
@@ -47,7 +44,8 @@ public:
   void 		flip( FlipMode flipMode ) { flipRotate( FlipRotation::fromFlipMode(flipMode) ); }
   void 		flipRotate( FlipRotation fr );
   bool 		flipRotateAbs( FlipRotation fr );
-  ImlibImage *	imlibImage()	const { return myIm.im; }
+  Imlib_Image	imlibImage()	const { return myIm.im; }
+  Imlib_Image	originalImage();
   Pixmap& 	pixmap();
   void 		renderPixmap();
   const KuickFile& file()       const { return *myFile; }
@@ -55,17 +53,15 @@ public:
 
   void		setDirty( bool d )    { myIsDirty = d;    }
   bool		isDirty()       const { return myIsDirty; }
+  bool		fileChangedOnDisk() const;
   Rotation	absRotation()   const { return myIm.orient.rot; }
   bool		flipMode()      const { return myIm.orient.flip; }
 
-  TQImage* toTQImage() const; // Note: caller must delete returned image
-  static ImlibImage* fromTQImage(ImlibData *id, TQImage &image);
-
 private:
   // Image with its attached dihedral state, to track rotation and flipping
   struct ImOrientedImage
   {
-    ImlibImage *im;
+    Imlib_Image  im;
     FlipRotation orient;
   };
 
@@ -83,10 +79,15 @@ private:
   int 		myOrigWidth;
   int 		myOrigHeight;
 
-  ImlibData  * 	myId;
+  Imlib_Context myContext;
   Pixmap 	myPixmap;
   bool 		myIsDirty;
 
+  // On-disk fingerprint of the file at the time this image was loaded,
+  // used to detect stale cache entries when a file is replaced
+  TQDateTime	myFileDateTime;
+  uint		myFileSize;
+
   ImOrientedImage myIm;
   ImOrientedImage mySavedIm;
 
diff --git a/kuickshow/src/kuickshow.cpp b/kuickshow/src/kuickshow.cpp
index 44c3d9d4..3dc8681f 100644
--- a/kuickshow/src/kuickshow.cpp
+++ b/kuickshow/src/kuickshow.cpp
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <assert.h>
+#include <cstdlib>
 
 #include <tqdir.h>
 #include <tqdesktopwidget.h>
@@ -58,9 +59,10 @@
 #include <kurldrag.h>
 #include <twin.h>
 #include <kstdguiitem.h>
-
 #include <kdebug.h>
 
+#include <Imlib2.h>
+
 #include "aboutwidget.h"
 #include "filewidget.h"
 #include "filecache.h"
@@ -95,7 +97,6 @@ KuickShow::KuickShow( const char *name )
       m_slideshowCycle( 1 ),
       fileWidget( 0L ),
       dialog( 0L ),
-      id( 0L ),
       m_viewer( 0L ),
       oneWindowAction( 0L ),
       m_accel( 0L ),
@@ -210,7 +211,6 @@ KuickShow::~KuickShow()
         m_viewer->close( true );
 
     FileCache::shutdown();
-    free( id );
     tdeApp->quit();
 
     delete kdata;
@@ -532,7 +532,7 @@ bool KuickShow::showImage( const KFileItem *fi,
     if ( FileWidget::isImage( fi ) ) {
 
         if ( newWindow ) {
-            m_viewer = new ImageWindow( kdata->idata, id, 0L, "image window" );
+            m_viewer = new ImageWindow( kdata->idata, 0L, "image window" );
             m_viewer->setFullscreen( fullscreen );
             s_viewers.append( m_viewer );
 
@@ -778,7 +778,7 @@ void KuickShow::slotPrint()
     KFileItemListIterator it( *items );
 
     // don't show the image, just print
-    ImageWindow *iw = new ImageWindow( 0, id, this, "printing image" );
+    ImageWindow *iw = new ImageWindow( 0, this, "printing image" );
     KFileItem *item;
     while ( (item = it.current()) ) {
         if (FileWidget::isImage( item ) && iw->loadImage( item->url() ))
@@ -1215,60 +1215,8 @@ void KuickShow::messageCantLoadImage( const KuickFile *, const TQString& message
 
 void KuickShow::initImlib()
 {
-    ImData *idata = kdata->idata;
-    ImlibInitParams par;
-    initImlibParams( idata, &par );
-
-    id = Imlib_init_with_params( x11Display(), &par );
-    if ( !id ) {
-        initImlibParams( idata, &par );
-
-        tqWarning("*** KuickShow: Whoops, can't initialize imlib, trying my own palettefile now.");
-        TQString paletteFile = locate( "data", "kuickshow/im_palette.pal" );
-        // ### - does the tqstrdup() cure the segfault in imlib eventually?
-        char *file = tqstrdup( paletteFile.local8Bit() );
-        par.palettefile = file;
-        par.flags |= PARAMS_PALETTEFILE;
-
-        tqWarning("Palettefile: %s", par.palettefile );
-
-        id = Imlib_init_with_params( x11Display(), &par );
-
-        if ( !id ) {
-            TQString tmp = i18n("Unable to initialize \"Imlib\".\n"
-                               "Start kuickshow from the command line "
-                               "and look for error messages.\n"
-                               "The program will now quit.");
-            KMessageBox::error( this, tmp, i18n("Fatal Imlib Error") );
-
-            FileCache::shutdown();
-            ::exit(1);
-        }
-    }
-}
-
-
-void KuickShow::initImlibParams( ImData *idata, ImlibInitParams *par )
-{
-    par->flags = ( PARAMS_REMAP | PARAMS_VISUALID | PARAMS_SHAREDMEM | PARAMS_SHAREDPIXMAPS |
-                   PARAMS_FASTRENDER | PARAMS_HIQUALITY | PARAMS_DITHER |
-                   PARAMS_IMAGECACHESIZE | PARAMS_PIXMAPCACHESIZE );
-
-    Visual* defaultvis = DefaultVisual(x11Display(), x11Screen());
-
-    par->paletteoverride = idata->ownPalette  ? 1 : 0;
-    par->remap           = idata->fastRemap   ? 1 : 0;
-    par->fastrender      = idata->fastRender  ? 1 : 0;
-    par->hiquality       = idata->dither16bit ? 1 : 0;
-    par->dither          = idata->dither8bit  ? 1 : 0;
-    par->sharedmem       = 1;
-    par->sharedpixmaps   = 1;
-    par->visualid	 = defaultvis->visualid;
-    uint maxcache        = idata->maxCache;
-
-    // 0 == no cache
-    par->imagecachesize  = maxcache * 1024;
-    par->pixmapcachesize = maxcache * 1024;
+    // Global library init
+    imlib_set_cache_size(kdata->idata->maxCache * 1024);
 }
 
 bool KuickShow::haveBrowser() const
diff --git a/kuickshow/src/kuickshow.h b/kuickshow/src/kuickshow.h
index dd8e34f2..046f93ef 100644
--- a/kuickshow/src/kuickshow.h
+++ b/kuickshow/src/kuickshow.h
@@ -28,13 +28,10 @@
 #include <tdemainwindow.h>
 #include <kurl.h>
 
-#include <Imlib.h>
-
 #include "aboutwidget.h"
 
 class FileWidget;
 class ImageWindow;
-class ImData;
 class KuickConfigDialog;
 
 class TDEAccel;
@@ -98,7 +95,6 @@ public:
 
 protected:
     virtual void	readProperties( TDEConfig * );
-    void 		initImlibParams( ImData *, ImlibInitParams * );
     void                tryShowNextImage();
 
 private slots:
@@ -133,7 +129,6 @@ private slots:
     void                slotOpenURL();
     void		slotSetURL( const KURL& );
     void		slotURLComboReturnPressed();
-//     void                invalidateImages( const KFileItemList& items );
     void		slotDeleteCurrentImage(ImageWindow *viewer);
     void		slotTrashCurrentImage(ImageWindow *viewer);
     void                slotDeleteCurrentImage();
@@ -143,7 +138,7 @@ private slots:
 
 private:
     void 		initGUI( const KURL& startDir );
-    bool	       	eventFilter( TQObject *, TQEvent * );
+    bool 		eventFilter( TQObject *, TQEvent * );
     void 		initImlib();
     void 		saveProperties( TDEConfig * );
     void 		saveSettings();
@@ -165,7 +160,6 @@ private:
     FileWidget   	*fileWidget;
     KURLComboBox	*cmbPath;
     KuickConfigDialog 	*dialog;
-    ImlibData           *id;
     ImageWindow 	*m_viewer;
     TDEToggleAction 	*oneWindowAction;
     TDEAccel 		*m_accel;
-- 
cgit v1.2.3

