--- gtk+-2.6.7/acconfig.h-orig	Thu Apr 21 00:49:23 2005
+++ gtk+-2.6.7/acconfig.h	Thu Apr 21 00:59:49 2005
@@ -46,6 +46,7 @@
 
 #undef USE_GMODULE
 #undef USE_MMX
+#undef USE_MEDIALIB
 
 /* Define to use XKB extension */
 #undef HAVE_XKB
--- gtk+-2.6.7/configure.in-orig	Thu Apr 21 00:51:07 2005
+++ gtk+-2.6.7/configure.in	Thu Apr 21 00:47:25 2005
@@ -908,6 +908,20 @@
   STATIC_LIB_DEPS="$LIBTIFF $LIBJPEG $LIBPNG"
 fi
 
+# Checks to see if we should compile in VIS/MediaLib Sparc
+# architecture support.
+#
+AC_MSG_CHECKING(for mediaLib 2.2)
+# Check for a mediaLib 2.2 function since that is what the GTK+ mediaLib
+# patch requires.
+AC_CHECK_LIB(mlib, mlib_ImageZoomTranslateBlend, use_mlib=yes, use_mlib=no)
+if test $use_mlib = yes; then
+    AC_DEFINE(USE_MEDIALIB)
+    MEDIA_LIB=-lmlib
+fi
+
+AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes)
+
 # Checks to see if we should compile in MMX support (there will be
 # a runtime test when the code is actually run to see if it should
 # be used - this just checks if we can compile it.)
@@ -975,7 +989,7 @@
 AC_SUBST(REBUILD_PNGS)
 
 GDK_PIXBUF_PACKAGES="gmodule-no-export-2.0 gobject-2.0"
-GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB"
+GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB $MEDIA_LIB"
 GDK_PIXBUF_EXTRA_CFLAGS= 
 GDK_PIXBUF_DEP_LIBS="`$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES` $GDK_PIXBUF_EXTRA_LIBS"
 GDK_PIXBUF_DEP_CFLAGS="`$PKG_CONFIG --cflags  gthread-2.0 $GDK_PIXBUF_PACKAGES $PNG_DEP_CFLAGS_PACKAGES` $GDK_PIXBUF_EXTRA_CFLAGS"
--- gtk+-2.6.7/gdk/gdkdraw.c-orig	Thu Apr 21 00:55:23 2005
+++ gtk+-2.6.7/gdk/gdkdraw.c	Thu Apr 21 00:54:26 2005
@@ -1259,6 +1259,11 @@
     }
 }
 
+#ifdef USE_MEDIALIB
+static gboolean medialib_initialized = FALSE;
+static gboolean gdk_use_medialib     = TRUE;
+#endif
+
 static void
 composite_0888 (guchar      *src_buf,
 		gint         src_rowstride,
@@ -1271,6 +1276,38 @@
   guchar *src = src_buf;
   guchar *dest = dest_buf;
 
+#ifdef USE_MEDIALIB
+  if (!medialib_initialized)
+    gdk_use_medialib = _gdk_use_medialib ();
+
+  if (gdk_use_medialib)
+    {
+      mlib_image img_src, img_dst;
+
+      mlib_ImageSet (&img_dst,
+                          MLIB_BYTE,
+                          4,
+                          width,
+                          height,
+                          dest_rowstride,
+                          dest_buf);
+
+      mlib_ImageSet (&img_src,
+                          MLIB_BYTE,
+                          4,
+                          width,
+                          height,
+                          src_rowstride,
+                          src_buf);
+
+      if (dest_byte_order == GDK_LSB_FIRST)
+          mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src);
+      else
+          mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src);
+    }
+  else
+    {
+#endif
   while (height--)
     {
       gint twidth = width;
@@ -1363,6 +1400,9 @@
       src += src_rowstride;
       dest += dest_rowstride;
     }
+#ifdef USE_MEDIALIB
+    }
+#endif
 }
 
 static void
--- /dev/null	2004-11-10 11:52:20.000000000 -0800
+++ gtk+-2.4.7/gdk/gdkmedialib.c	2004-11-10 11:55:49.054229000 -0800
@@ -0,0 +1,102 @@
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <link.h>
+#if defined(sun)
+#include <strings.h>
+#include <sys/systeminfo.h>
+#elif defined(__linux__)
+#include <string.h>
+#include <sys/sysinfo.h>
+#endif
+
+#include "gdkmedialib.h"
+
+typedef char *      (*ml_version)         (void);
+
+static ml_version                 medialib_version = mlib_version;
+
+
+gboolean 
+_gdk_use_medialib (void)
+{
+  /*
+   * Sun mediaLib(tm) support.
+   *
+   *   http://www.sun.com/processors/vis/mlib.html
+   *
+   */
+      if (getenv ("DISABLE_MEDIALIB_GDK"))
+        return FALSE;
+
+            {
+              char *mlib_version_string;
+              int mlib_major_version;
+              char sys_info[257];
+              long count;
+              /*
+               * The imaging functions we want to use were added in
+               * mediaLib version 2.  So turn off mediaLib support if
+               * the user has an older version. mlib_version returns
+               * a string in this format:
+               *
+               * mediaLib:0210:20011101:v8plusa
+               * ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
+               * libname  vers build    ISALIST identifier
+               *               date     (in this case sparcv8plus+vis)
+               *
+               * The first 2 digits of the version are the major version.
+               * The 3rd digit it the minor version, and the 4th digit
+               * is the micro version. So the above string corresponds to
+               * version 2.1.0.In the following test we only care about
+               * the major version.
+               */
+              mlib_version_string = medialib_version ();
+              mlib_major_version = (mlib_version_string[9]  - '0') * 10 +
+                                   (mlib_version_string[10] - '0');
+
+              count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
+             
+              if (count != -1)
+                {
+                  if (strcmp (sys_info, "i386") == 0)
+                    {
+                      char *mlib_target_isa = &mlib_version_string[23];
+             
+                      /*
+                       * For x86 processors mediaLib generic C implementation
+                       * doesn't give any performance advantage so disable it
+                       */
+                      if (strncmp (mlib_target_isa, "sse", 3) != 0)
+                        {
+                          return FALSE;
+                        }
+
+                      /*
+                       * For x86 processors use of libumem conflicts with mediaLib
+                       * avoid it.
+                       */
+                      if ((dlsym (RTLD_DEFAULT, "umem_alloc") != NULL) ||
+                          (dlsym (RTLD_PROBE, "umem_alloc") != NULL) ||
+                          (dlsym (RTLD_NEXT, "umem_alloc") != NULL) ||
+                          (dlsym (RTLD_SELF, "umem_alloc") != NULL))
+                        {
+                          return FALSE;
+                        }
+                    }
+                }
+              else
+                {
+                  /*
+                   * Failed to get system architecture,
+                   * disable mediaLib anyway
+                   */
+                  return FALSE;
+                }
+          
+              if (mlib_major_version < 2)
+                {
+                  return FALSE;
+                }
+            }
+  return TRUE;
+}
--- /dev/null	2004-11-10 11:52:20.000000000 -0800
+++ gtk+-2.4.7/gdk/gdkmedialib.h	2004-10-26 09:58:33.498519000 -0700
@@ -0,0 +1,31 @@
+#ifndef __GDK_MEDIALIB_H__
+#define __GDK_MEDIALIB_H__
+
+#include <config.h>
+
+#ifdef USE_MEDIALIB
+#include <mlib_image.h>
+#include <mlib_video.h>
+
+extern mlib_image *mlib_ImageSet (mlib_image *image, mlib_type type, 
+                                  mlib_s32 channels, mlib_s32 width,
+                                  mlib_s32 height, mlib_s32 stride,
+                                  const void *data);
+
+#include <gdktypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+gboolean _gdk_use_medialib (void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* USE_MEDIALIB */
+
+#endif /* __GDK_MEDIALIB_H__ */
+
--- gtk+-2.6.7/gdk/gdkprivate.h-orig	Thu Apr 21 00:56:23 2005
+++ gtk+-2.6.7/gdk/gdkprivate.h	Thu Apr 21 00:59:49 2005
@@ -35,6 +35,9 @@
 #include <gdk/gdkregion.h>
 #include <gdk/gdkvisual.h>
 #include <gdk/gdkwindow.h>
+#ifdef USE_MEDIALIB
+#include <gdk/gdkmedialib.h>
+#endif
 
 G_BEGIN_DECLS
 
--- gtk+-2.6.7/gdk/Makefile.am-orig	Thu Apr 21 00:48:16 2005
+++ gtk+-2.6.7/gdk/Makefile.am	Thu Apr 21 00:49:03 2005
@@ -41,6 +41,15 @@
 	$(no_undefined)							\
 	$(LIBTOOL_EXPORT_OPTIONS)
 
+if USE_MEDIALIB
+medialib_sources =  \
+    gdkmedialib.c
+medialib_h_sources =    \
+    gdkmedialib.h
+else
+medialib_sources =
+medialib_h_sources =
+endif
 
 #
 # setup source file variables
@@ -79,11 +88,13 @@
 
 gdk_headers =                     \
 	$(gdk_public_h_sources)   \
+	$(medialib_h_sources)     \
 	gdkenumtypes.h		  \
 	gdkprivate.h		  \
 	gdkalias.h
 
 gdk_c_sources =                 \
+	$(medialib_sources)     \
 	gdk.c			\
 	gdkcolor.c		\
 	gdkcursor.c		\
--- gtk+-2.6.7/gdk-pixbuf/gdk-pixbuf-scale.c-orig	Thu Apr 21 00:56:54 2005
+++ gtk+-2.6.7/gdk-pixbuf/gdk-pixbuf-scale.c	Thu Apr 21 00:59:49 2005
@@ -73,7 +73,14 @@
 
   offset_x = floor (offset_x + 0.5);
   offset_y = floor (offset_y + 0.5);
-  
+
+#ifdef USE_MEDIALIB
+  pixops_medialib_scale (dest->pixels, dest->width, dest->height, dest->rowstride,
+                         dest->n_channels, dest->has_alpha, src->pixels, src->width,
+                         src->height, src->rowstride, src->n_channels, src->has_alpha,
+                         dest_x, dest_y, dest_width, dest_height, offset_x,
+                         offset_y, scale_x, scale_y, (PixopsInterpType)interp_type);
+#else
   _pixops_scale (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
 		 dest_x - offset_x, dest_y - offset_y, 
 		 dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
@@ -81,6 +88,7 @@
 		 src->pixels, src->width, src->height,
 		 src->rowstride, src->n_channels, src->has_alpha,
 		 scale_x, scale_y, (PixopsInterpType)interp_type);
+#endif
 }
 
 /**
@@ -136,6 +144,14 @@
 
   offset_x = floor (offset_x + 0.5);
   offset_y = floor (offset_y + 0.5);
+#ifdef USE_MEDIALIB
+  pixops_medialib_composite(dest->pixels, dest->width, dest->height, dest->rowstride,
+                        dest->n_channels, dest->has_alpha, src->pixels, src->width,
+                        src->height, src->rowstride, src->n_channels, src->has_alpha,
+                        dest_x, dest_y, dest_width, dest_height, offset_x,
+                        offset_y, scale_x, scale_y, (PixopsInterpType)interp_type, 
+                        overall_alpha);
+#else
   _pixops_composite (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
 		     dest_x - offset_x, dest_y - offset_y, 
 		     dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
@@ -143,6 +159,7 @@
 		     src->pixels, src->width, src->height,
 		     src->rowstride, src->n_channels, src->has_alpha,
 		     scale_x, scale_y, (PixopsInterpType)interp_type, overall_alpha);
+#endif
 }
 
 /**
--- gtk+-2.6.7/gdk-pixbuf/pixops/Makefile.am-orig	Thu Apr 21 00:57:29 2005
+++ gtk+-2.6.7/gdk-pixbuf/pixops/Makefile.am	Thu Apr 21 00:59:49 2005
@@ -10,7 +10,7 @@
 noinst_PROGRAMS = timescale
 
 timescale_SOURCES = timescale.c
-timescale_LDADD = libpixops.la $(GLIB_LIBS) -lm
+timescale_LDADD = libpixops.la $(GLIB_LIBS) $(GDK_PIXBUF_EXTRA_LIBS)
 
 if USE_MMX
 mmx_sources =				\
--- gtk+-2.6.7/gdk-pixbuf/pixops/pixops.c-orig	Thu Apr 21 00:57:06 2005
+++ gtk+-2.6.7/gdk-pixbuf/pixops/pixops.c	Thu Apr 21 00:59:49 2005
@@ -1,7 +1,16 @@
 #include <config.h>
+#include <dlfcn.h>
 #include <math.h>
 #include <glib.h>
 
+#if defined(sun)
+#include <strings.h>
+#include <sys/systeminfo.h>
+#elif defined(__linux__)
+#include <string.h>
+#include <sys/sysinfo.h>
+#endif
+
 #include "pixops.h"
 #include "pixops-internal.h"
 
@@ -38,6 +47,142 @@
 				 guint32 color2,
 				 guint r, guint g, guint b, guint a);
 
+#ifdef USE_MEDIALIB
+#include <mlib_image.h>
+
+extern mlib_image *mlib_ImageSet (mlib_image *image, mlib_type type, 
+                                  mlib_s32 channels, mlib_s32 width,
+                                  mlib_s32 height, mlib_s32 stride,
+                                  const void *data);
+extern mlib_image *mlib_ImageSetSubimage (mlib_image *dst, 
+                                          const mlib_image *src,
+                                          mlib_s32 x, mlib_s32 y,
+                                          mlib_s32 w, mlib_s32 h);
+
+static gboolean                 medialib_initialized = FALSE;
+
+static gboolean use_medialib_scale     = FALSE;
+static gboolean use_medialib_composite = FALSE;
+
+typedef struct _mlInterp mlInterp;
+
+struct _mlInterp
+{
+  double       tx;
+  double       ty;
+  PixopsFilter po_filter;
+  void         *interp_table;
+};
+
+/*
+ * Sun mediaLib(tm) support.
+ *
+ *   http://www.sun.com/processors/vis/mlib.html
+ *
+ */
+static void
+initialize_mediaLib ()
+{
+        {
+          char *mlib_version_string;
+          int mlib_major_version;
+          int mlib_minor_version;
+          char sys_info[257];
+          long count;
+
+         /*
+          * The imaging functions we want to use were added in 
+          * mediaLib version 2.  So turn off mediaLib support if
+          * the user has an older version.  mlib_version returns
+          * a string in this format:
+          *
+          * mediaLib:0210:20011101:v8plusa
+          * ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
+          * libname  vers  build   ISALIST identifier
+          *                date    (in this case sparcv8plus+vis)
+          * 
+          * The first 2 digits of the version are the major version.
+          * The 3rd digit it the minor version, and the 4th digit
+          * is the micro version.  So the above string corresponds to
+          * version 2.1.0.  In the following test we only care about
+          * the major version.
+          */
+          mlib_version_string = mlib_version ();
+          mlib_major_version = (mlib_version_string[9]  - '0') * 10 +
+                               (mlib_version_string[10] - '0');
+          mlib_minor_version = mlib_version_string[11] - '0';
+
+          count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
+
+          if (count != -1)
+            {
+              if (strcmp (sys_info, "i386") == 0)
+                {
+                  char *mlib_target_isa = &mlib_version_string[23];
+
+                  /*
+                   * For x86 processors mediaLib generic C implementation
+                   * doesn't give any performance advantage so disable it
+                   */
+                  if (strncmp (mlib_target_isa, "sse", 3) != 0)
+                    {
+                      use_medialib_scale = FALSE;
+                      use_medialib_composite = FALSE;
+                      medialib_initialized = TRUE;
+                      return;
+                    }
+
+                  /*
+                   * For x86 processors use of libumem conflicts with mediaLib
+                   * avoid it.
+                   */
+                  if ((dlsym (RTLD_DEFAULT, "umem_alloc") != NULL) ||
+                      (dlsym (RTLD_PROBE, "umem_alloc") != NULL) ||
+                      (dlsym (RTLD_NEXT, "umem_alloc") != NULL) ||
+                      (dlsym (RTLD_SELF, "umem_alloc") != NULL))
+                    {
+                      use_medialib_scale = FALSE;
+                      use_medialib_composite = FALSE;
+                      medialib_initialized = TRUE;
+                      return;
+                    }
+                }
+            }
+          else
+            {
+              /*
+               * Failed to get system architecture,
+               * disable mediaLib anyway
+               */
+              use_medialib_scale = FALSE;
+              use_medialib_composite = FALSE;
+              medialib_initialized = TRUE;
+              return;
+            }
+          
+          if (mlib_major_version < 2)
+            {
+              use_medialib_scale = FALSE;
+              use_medialib_composite = FALSE;
+              medialib_initialized = TRUE;
+              return;
+            }
+          else if (mlib_major_version > 2 ||
+             (mlib_major_version == 2 && mlib_minor_version >= 2))
+            {
+              use_medialib_scale     = TRUE;
+              use_medialib_composite = TRUE;
+            }
+        }
+
+  if (getenv ("DISABLE_MEDIALIB_SCALE"))
+     use_medialib_scale = FALSE;
+  if (getenv ("DISABLE_MEDIALIB_COMPOSITE"))
+     use_medialib_composite = FALSE;
+
+  medialib_initialized = TRUE;
+}
+#endif
 static int
 get_check_shift (int check_size)
 {
@@ -1545,6 +1690,270 @@
   g_free (filter.y.weights);
 }
 
+#ifdef USE_MEDIALIB
+
+void medialib_get_interpolation (mlInterp * ml_interp,
+                                 PixopsInterpType interp_type,
+                                 double scale_x,
+                                 double scale_y,
+                                 double overall_alpha)
+{
+  mlib_s32 leftPadding, topPadding;
+  ml_interp->interp_table = NULL;
+
+ /*
+  * medialib 2.1 and later supports scaling with user-defined interpolation
+  * tables, so this logic is used.  
+  *
+  * bilinear_magnify_make_weights builds an interpolation table of size
+  * 2x2 if the scale factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.
+  * These map most closely to MLIB_BILINEAR, which uses an interpolation
+  * table of size 2x2.
+  *
+  * tile_make_weights builds an interpolation table of size 2x2 if the
+  * scale factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.  These map
+  * most closely to MLIB_BILINEAR, which uses an interpolation table of
+  * size 2x2.
+  *
+  * bilinear_box_make_weights builds an interpolation table of size 4x4
+  * if the scale factor >= 1.0 and "ceil (1.0 + 1.0/scale)" otherwise.
+  * These map most closely to MLIB_BICUBIC, which uses an interpolation
+  * table of size 4x4.
+  *
+  * PIXOPS_INTERP_NEAREST calls pixops_scale_nearest which does not use
+  * an interpolation table.  This maps to MLIB_NEAREST.
+  */
+  switch (interp_type)
+    {
+    case PIXOPS_INTERP_BILINEAR:
+      bilinear_magnify_make_weights (&(ml_interp->po_filter.x), scale_x);
+      bilinear_magnify_make_weights (&(ml_interp->po_filter.y), scale_y);
+      leftPadding = 0;
+      topPadding  = 0;
+
+      if (scale_x <= 1.0)
+          ml_interp->tx = 0.5 * (1 - scale_x);
+      else
+          ml_interp->tx = 0.0;
+
+      if (scale_y <= 1.0)
+          ml_interp->ty = 0.5 * (1 - scale_y);
+      else
+          ml_interp->ty = 0.0;
+
+      break;
+
+    case PIXOPS_INTERP_TILES:
+      tile_make_weights (&(ml_interp->po_filter.x), scale_x);
+      tile_make_weights (&(ml_interp->po_filter.y), scale_y);
+      leftPadding   = 0;
+      topPadding    = 0;
+      ml_interp->tx = 0.5 * (1 - scale_x);
+      ml_interp->ty = 0.5 * (1 - scale_y);
+      break;
+
+    case PIXOPS_INTERP_HYPER:
+      bilinear_box_make_weights (&(ml_interp->po_filter.x), scale_x);
+      bilinear_box_make_weights (&(ml_interp->po_filter.y), scale_y);
+      leftPadding   = 1;
+      topPadding    = 1;
+      ml_interp->tx = 0.5 * (1 - scale_x);
+      ml_interp->ty = 0.5 * (1 - scale_y);
+      break;
+
+    case PIXOPS_INTERP_NEAREST:
+    default:
+      /*
+       * Note that this function should not be called in the
+       * PIXOPS_INTERP_NEAREST case since it does not use an interpolation
+       * table.
+       */
+      g_assert_not_reached ();
+      break;
+    }
+
+   /* 
+    * If overall_alpha is not 1.0, then multiply the vectors built by the
+    * sqrt (overall_alpha).  This will cause overall_alpha to get evenly
+    * blended across both axis.
+    *
+    * Note there is no need to multiply the vectors built by the various
+    * make-weight functions by sqrt (overall_alpha) since the make-weight
+    * functions are called with overall_alpha hardcoded to 1.0.
+    */
+    if (overall_alpha != 1.0)
+      {
+        double sqrt_alpha = sqrt (overall_alpha);
+        int i;
+
+        for (i=0; i < SUBSAMPLE * ml_interp->po_filter.x.n; i++)
+           ml_interp->po_filter.x.weights[i] *= sqrt_alpha;
+        for (i=0; i < SUBSAMPLE * ml_interp->po_filter.y.n; i++)
+           ml_interp->po_filter.y.weights[i] *= sqrt_alpha;
+      }
+      
+      ml_interp->interp_table = (void *) mlib_ImageInterpTableCreate (MLIB_DOUBLE,
+		ml_interp->po_filter.x.n, ml_interp->po_filter.y.n, leftPadding,
+		topPadding, SUBSAMPLE_BITS, SUBSAMPLE_BITS, 8,
+		ml_interp->po_filter.x.weights, ml_interp->po_filter.y.weights);
+
+      g_free (ml_interp->po_filter.x.weights);
+      g_free (ml_interp->po_filter.y.weights);  
+}
+
+void pixops_medialib_composite (guchar         *dest_buf,
+                                int              dest_pixwidth,
+                                int              dest_pixheight,
+                                int              dest_rowstride,
+                                int              dest_channels,
+                                int              dest_has_alpha,
+                                const guchar    *src_buf,
+                                int              src_pixwidth,
+                                int              src_pixheight,
+                                int              src_rowstride,
+                                int              src_channels,
+                                int              src_has_alpha,
+                                int              dest_x,
+                                int              dest_y,
+                                int              dest_width,
+                                int              dest_height,
+                                double           offset_x,
+                                double           offset_y,
+                                double           scale_x,
+                                double           scale_y,
+                                PixopsInterpType interp_type,
+                                int              overall_alpha)
+{
+  mlib_blend blend;
+  g_return_if_fail (!(dest_channels == 3 && dest_has_alpha));
+  g_return_if_fail (!(src_channels == 3 && src_has_alpha));
+
+  if (scale_x == 0 || scale_y == 0)
+    return;
+
+  if (!medialib_initialized)
+    initialize_mediaLib ();
+
+  if (!use_medialib_composite)
+  {
+    _pixops_composite (dest_buf + dest_y * dest_rowstride + dest_x * dest_channels,
+                      dest_x - offset_x, dest_y - offset_y,
+                      dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
+                      dest_rowstride, dest_channels, dest_has_alpha,
+                      src_buf, src_pixwidth, src_pixheight,
+                      src_rowstride, src_channels, src_has_alpha,
+                      scale_x, scale_y, interp_type, overall_alpha);
+  }
+  else
+  {
+    mlInterp ml_interp;
+    mlib_image img_src, img_orig_dest, img_dest;
+    double ml_offset_x, ml_offset_y;
+
+    if (!src_has_alpha && overall_alpha == 255 && dest_channels <= src_channels) 
+    {
+      pixops_medialib_scale (dest_buf, dest_width, dest_height,
+                             dest_rowstride, dest_channels,
+                             dest_has_alpha, src_buf, src_pixwidth,
+                             src_pixheight, src_rowstride,
+                             src_channels, src_has_alpha, dest_x, dest_y,
+                             dest_width, dest_height, offset_x, offset_y,
+                             scale_x,
+                             scale_y,
+                             interp_type);
+	    return;
+    }
+
+    mlib_ImageSet (&img_src, MLIB_BYTE, src_channels, src_pixwidth,
+                       src_pixheight, src_rowstride, src_buf);
+    mlib_ImageSet (&img_orig_dest, MLIB_BYTE, dest_channels,
+                       dest_pixwidth, dest_pixheight, dest_rowstride,
+                       dest_buf);
+
+    if (dest_x == 0 && dest_y == 0 &&
+        dest_pixwidth == dest_width &&
+        dest_pixheight == dest_height)
+    {
+      img_dest = img_orig_dest;
+    }
+    else
+    {
+      mlib_ImageSetSubimage (&img_dest, &img_orig_dest, dest_x, dest_y,
+                                 dest_width, dest_height);
+    }
+
+    ml_offset_x = floor (offset_x) - dest_x;
+    ml_offset_y = floor (offset_y) - dest_y;
+
+    if (interp_type == PIXOPS_INTERP_NEAREST)
+    {
+      blend = src_has_alpha ? MLIB_BLEND_GTK_SRC_OVER2 : MLIB_BLEND_GTK_SRC;
+
+      mlib_ImageZoomTranslateBlend (&img_dest,
+                                  &img_src,
+                                  scale_x,
+                                  scale_y,
+                                  ml_offset_x,
+                                  ml_offset_y,
+                                  MLIB_NEAREST,
+                                  MLIB_EDGE_SRC_EXTEND_INDEF,
+                                  blend,
+                                  overall_alpha,
+                                  1);
+    }
+    else
+    {
+      blend = src_has_alpha ? MLIB_BLEND_GTK_SRC_OVER : MLIB_BLEND_GTK_SRC;
+
+      if (interp_type == PIXOPS_INTERP_BILINEAR && scale_x > 1.0 && scale_y > 1.0)
+      {
+        mlib_ImageZoomTranslateBlend (&img_dest,
+                                     &img_src,
+                                     scale_x,
+                                     scale_y,
+                                     ml_offset_x,
+                                     ml_offset_y,
+                                     MLIB_BILINEAR,
+                                     MLIB_EDGE_SRC_EXTEND_INDEF,
+                                     blend,
+                                     overall_alpha,
+                                     1);
+      }
+      else
+      {
+        medialib_get_interpolation (&ml_interp, interp_type,
+                                   scale_x, scale_y, overall_alpha/255.0);
+
+        if (ml_interp.interp_table != NULL)
+        {
+          mlib_ImageZoomTranslateTableBlend (&img_dest,
+                                            &img_src,
+                                            scale_x,
+                                            scale_y,
+                                            ml_offset_x + ml_interp.tx,
+                                            ml_offset_y + ml_interp.ty,
+                                            ml_interp.interp_table,
+                                            MLIB_EDGE_SRC_EXTEND_INDEF,
+                                            blend,
+                                            1);
+          mlib_ImageInterpTableDelete (ml_interp.interp_table);
+        }
+        else
+        {
+          /* should not happen */
+          _pixops_composite (dest_buf + dest_y * dest_rowstride + dest_x * dest_channels,
+                            dest_x - offset_x, dest_y - offset_y,
+                            dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
+                            dest_rowstride, dest_channels, dest_has_alpha,
+                            src_buf, src_pixwidth, src_pixheight,
+                            src_rowstride, src_channels, src_has_alpha,
+                            scale_x, scale_y, interp_type, overall_alpha);
+        }
+      }
+    }
+  }
+}
+#endif
 void
 _pixops_scale (guchar        *dest_buf,
 	       int            render_x0,
@@ -1612,3 +2021,278 @@
   g_free (filter.y.weights);
 }
 
+#ifdef USE_MEDIALIB
+void pixops_medialib_scale     (guchar          *dest_buf,
+                                int              dest_pixwidth,
+                                int              dest_pixheight,
+                                int              dest_rowstride,
+                                int              dest_channels,
+                                int              dest_has_alpha,
+                                const guchar    *src_buf,
+                                int              src_pixwidth,
+                                int              src_pixheight,
+                                int              src_rowstride,
+                                int              src_channels,
+                                int              src_has_alpha,
+                                int              dest_x,
+                                int              dest_y,
+                                int              dest_width,
+                                int              dest_height,
+                                double           offset_x,
+                                double           offset_y,
+                                double           scale_x,
+                                double           scale_y,
+                                PixopsInterpType interp_type)
+{
+  if (scale_x == 0 || scale_y == 0)
+    return;
+
+  if (!medialib_initialized)
+    initialize_mediaLib ();
+ 
+  /*
+   * We no longer support mediaLib 2.1 because it has a core dumping problem
+   * in the mlib_ImageZoomTranslateTable function that has been corrected in
+   * 2.2.  Although the mediaLib_zoom function could be used, it does not
+   * work properly if the source and destination images have different 
+   * values for "has_alpha" or "num_channels".  The complicated if-logic
+   * required to support both versions is not worth supporting
+   * mediaLib 2.1 moving forward.
+   */
+  if (!use_medialib_scale)
+  {
+    _pixops_scale (dest_buf + dest_y * dest_rowstride + dest_x * dest_channels,
+                  dest_x - offset_x, dest_y - offset_y, 
+                  dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
+                  dest_rowstride, dest_channels, dest_has_alpha,
+                  src_buf, src_pixwidth, src_pixheight,
+                  src_rowstride, src_channels, src_has_alpha,
+                  scale_x, scale_y, interp_type);
+  }
+  else 
+  {
+    mlInterp ml_interp;
+    mlib_image img_orig_src, img_src, img_orig_dest, img_dest;
+    double ml_offset_x, ml_offset_y;
+    guchar *tmp_buf = NULL;
+
+    mlib_ImageSet (&img_orig_src, MLIB_BYTE, src_channels, src_pixwidth, 
+                       src_pixheight, src_rowstride, src_buf);
+    mlib_ImageSet (&img_orig_dest, MLIB_BYTE, dest_channels,
+                       dest_pixwidth, dest_pixheight, dest_rowstride,
+                       dest_buf);
+
+    if (dest_x == 0 && dest_y == 0 &&
+        dest_pixwidth == dest_width &&
+        dest_pixheight == dest_height)
+    {
+      img_dest = img_orig_dest;
+    }
+    else
+    {
+      mlib_ImageSetSubimage (&img_dest, &img_orig_dest, dest_x, dest_y,
+                                 dest_width, dest_height);
+    }
+
+    ml_offset_x = floor (offset_x) - dest_x;
+    ml_offset_y = floor (offset_y) - dest_y;
+
+    /*
+     * Note that zoomTranslate and zoomTranslateTable are faster
+     * than zoomTranslateBlend and zoomTranslateTableBlend.  However
+     * the faster functions only work in the following case:
+     *
+     *   if (src_channels == dest_channels &&
+     *       (!src_alpha && interp_table != PIXOPS_INTERP_NEAREST))
+     *
+     * We use the faster versions if we can.
+     *
+     * Note when the interp_type is BILINEAR and the interpolation
+     * table will be size 2x2 (when both x/y scale factors > 1.0),
+     * then we do not bother building the interpolation table.   In
+     * this case we can just use MLIB_BILINEAR, which is faster than
+     * using a specified interpolation table.
+     */
+    img_src = img_orig_src;
+    
+    if (!src_has_alpha)
+    {
+      if (src_channels > dest_channels)
+      {
+        int channels = 3;
+        int rowstride = (channels * src_pixwidth + 3) & ~3;
+        
+        tmp_buf = g_malloc (src_rowstride * src_pixheight);
+
+        if (src_buf != NULL)
+        {
+          src_channels = channels;
+          src_rowstride = rowstride;
+          
+          mlib_ImageSet (&img_src, MLIB_BYTE, src_channels, src_pixwidth, 
+                             src_pixheight, src_rowstride, tmp_buf);
+          mlib_ImageChannelExtract (&img_src, &img_orig_src, 0xE);  
+        }
+      }
+    }
+    
+    if (interp_type == PIXOPS_INTERP_NEAREST)
+    {
+      if (src_channels == dest_channels)
+      {
+        mlib_ImageZoomTranslate (&img_dest,
+                                &img_src,
+                                scale_x,
+                                scale_y,
+                                ml_offset_x,
+                                ml_offset_y,
+                                MLIB_NEAREST,
+                                MLIB_EDGE_SRC_EXTEND_INDEF);
+      }
+      else
+      {
+        mlib_ImageZoomTranslateBlend (&img_dest,
+                                     &img_src,
+                                     scale_x,
+                                     scale_y,
+                                     ml_offset_x,
+                                     ml_offset_y,
+                                     MLIB_NEAREST,
+                                     MLIB_EDGE_SRC_EXTEND_INDEF,
+                                     MLIB_BLEND_GTK_SRC,
+                                     1.0,
+                                     1);
+      }
+    }
+    else if (src_channels == dest_channels && !src_has_alpha)
+    {
+      if (interp_type == PIXOPS_INTERP_BILINEAR && scale_x > 1.0 && scale_y > 1.0)
+      {
+         mlib_ImageZoomTranslate (&img_dest,
+                                 &img_src,
+                                 scale_x,
+                                 scale_y,
+                                 ml_offset_x,
+                                 ml_offset_y,
+                                 MLIB_BILINEAR,
+                                 MLIB_EDGE_SRC_EXTEND_INDEF);
+      }
+      else
+      {
+        medialib_get_interpolation (&ml_interp, interp_type,
+                                    scale_x, scale_y, 1.0);
+
+        if (ml_interp.interp_table != NULL)
+        {
+          mlib_ImageZoomTranslateTable (&img_dest, 
+                                       &img_src,
+                                       scale_x,
+                                       scale_y,
+                                       ml_offset_x + ml_interp.tx,
+                                       ml_offset_y + ml_interp.ty,
+                                       ml_interp.interp_table,
+                                       MLIB_EDGE_SRC_EXTEND_INDEF);
+
+	        mlib_ImageInterpTableDelete (ml_interp.interp_table);
+        }
+        else
+        {
+          /* should not happen. */
+          mlib_filter  ml_filter;
+
+          switch (interp_type)
+          {
+            case PIXOPS_INTERP_BILINEAR:
+              ml_filter = MLIB_BILINEAR;
+              break;
+              
+            case PIXOPS_INTERP_TILES:
+              ml_filter = MLIB_BILINEAR;
+              break;
+              
+            case PIXOPS_INTERP_HYPER:
+              ml_filter = MLIB_BICUBIC;
+              break;
+          }
+
+          mlib_ImageZoomTranslate (&img_dest,
+                                  &img_src,
+                                  scale_x,
+                                  scale_y,
+                                  ml_offset_x,
+                                  ml_offset_y,
+                                  ml_filter,
+                                  MLIB_EDGE_SRC_EXTEND_INDEF);
+        }
+      }
+    }
+    /* dealing with case where src_channels != dest_channels || src_has_alpha */
+    else if (interp_type == PIXOPS_INTERP_BILINEAR && scale_x > 1.0 && scale_y > 1.0)
+    {
+      mlib_ImageZoomTranslateBlend (&img_dest,
+                                   &img_src,
+                                   scale_x,
+                                   scale_y,
+                                   ml_offset_x,
+                                   ml_offset_y,
+                                   MLIB_BILINEAR,
+                                   MLIB_EDGE_SRC_EXTEND_INDEF,
+                                   MLIB_BLEND_GTK_SRC,
+                                   1.0,
+                                   1);
+    }
+    else
+    {
+      medialib_get_interpolation (&ml_interp, interp_type,
+                                  scale_x, scale_y, 1.0);
+
+      if (ml_interp.interp_table != NULL)
+      {
+        mlib_ImageZoomTranslateTableBlend (&img_dest,
+                                          &img_src,
+                                          scale_x,
+                                          scale_y,
+                                          ml_offset_x + ml_interp.tx,
+                                          ml_offset_y + ml_interp.ty,
+                                          ml_interp.interp_table,
+                                          MLIB_EDGE_SRC_EXTEND_INDEF,
+                                          MLIB_BLEND_GTK_SRC,
+                                          1);
+        mlib_ImageInterpTableDelete (ml_interp.interp_table);
+      }
+      else
+      {
+        mlib_filter  ml_filter;
+
+        switch (interp_type)
+        {
+          case PIXOPS_INTERP_BILINEAR:
+            ml_filter = MLIB_BILINEAR;
+            break;
+            
+          case PIXOPS_INTERP_TILES:
+            ml_filter = MLIB_BILINEAR;
+            break;
+            
+          case PIXOPS_INTERP_HYPER:
+            ml_filter = MLIB_BICUBIC;
+            break;
+        }
+
+        mlib_ImageZoomTranslate (&img_dest,
+                                &img_src,
+                                scale_x,
+                                scale_y,
+                                ml_offset_x,
+                                ml_offset_y,
+                                ml_filter,
+                                MLIB_EDGE_SRC_EXTEND_INDEF);
+      }
+    }
+
+    if (tmp_buf != NULL)
+      g_free (tmp_buf);
+
+  }
+}
+#endif
--- gtk+-2.6.7/gdk-pixbuf/pixops/pixops.h-orig	Thu Apr 21 00:57:02 2005
+++ gtk+-2.6.7/gdk-pixbuf/pixops/pixops.h	Thu Apr 21 00:59:49 2005
@@ -90,6 +90,52 @@
 		       double          scale_y,
 		       PixopsInterpType   interp_type);
 
+#ifdef USE_MEDIALIB
+void pixops_medialib_composite  (guchar         *dest_buf,
+                                 int              dest_pixwidth,
+                                 int              dest_pixheight,
+                                 int              dest_rowstride,
+                                 int              dest_channels,
+                                 int              dest_has_alpha,
+                                 const guchar    *src_buf,
+                                 int              src_pixwidth,
+                                 int              src_pixheight,
+                                 int              src_rowstride,
+                                 int              src_channels,
+                                 int              src_has_alpha,
+                                 int              dest_x,
+                                 int              dest_y,
+                                 int              dest_width,
+                                 int              dest_height,
+                                 double           offset_x,
+                                 double           offset_y,
+                                 double           scale_x,
+                                 double           scale_y,
+                                 PixopsInterpType interp_type,
+                                 int              overall_alpha);
+
+void pixops_medialib_scale      (guchar         *dest_buf,
+                                 int              dest_pixwidth,
+                                 int              dest_pixheight,
+                                 int              dest_rowstride,
+                                 int              dest_channels,
+                                 int              dest_has_alpha,
+                                 const guchar    *src_buf,
+                                 int              src_pixwidth,
+                                 int              src_pixheight,
+                                 int              src_rowstride,
+                                 int              src_channels,
+                                 int              src_has_alpha,
+                                 int              dest_x,
+                                 int              dest_y,
+                                 int              dest_width,
+                                 int              dest_height,
+                                 double           offset_x,
+                                 double           offset_y,
+                                 double           scale_x,
+                                 double           scale_y,
+                                 PixopsInterpType interp_type);
+#endif
 
 
 #endif
--- gtk+-2.6.7/gdk-pixbuf/pixops/timescale.c-orig	Thu Apr 21 01:07:52 2005
+++ gtk+-2.6.7/gdk-pixbuf/pixops/timescale.c	Thu Apr 21 00:59:49 2005
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include "config.h"
 
 #include "pixops.h"
 
@@ -182,10 +183,22 @@
 		start_timing ();
 		for (i = 0; i < ITERS; i++)
 		  {
+#ifdef USE_MEDIALIB
+                    pixops_medialib_scale(dest_buf, dest_width, dest_height,
+                                          dest_rowstride, dest_channels,
+                                          dest_has_alpha, src_buf, src_width,
+                                          src_height, src_rowstride,
+                                          src_channels, src_has_alpha, 0, 0,
+                                          dest_width, dest_height, 0.0, 0.0,
+                                          (double)dest_width / src_width,
+                                          (double)dest_height / src_height,
+                                          filter_level);
+#else
 		    _pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
 				   src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
 				   (double)dest_width / src_width, (double)dest_height / src_height,
 				   filter_level);
+#endif
 		  }
 		scale_times[src_index][dest_index][filter_level] =
 		  stop_timing ("   scale\t\t", ITERS, dest_height * dest_width);
@@ -194,10 +207,22 @@
 	    start_timing ();
 	    for (i = 0; i < ITERS; i++)
 	      {
+#ifdef USE_MEDIALIB
+                pixops_medialib_composite(dest_buf, dest_width, dest_height,
+                                          dest_rowstride, dest_channels,
+                                          dest_has_alpha, src_buf, src_width,
+                                          src_height, src_rowstride,
+                                          src_channels, src_has_alpha, 0, 0,
+                                          dest_width, dest_height, 0.0, 0.0,
+                                          (double)dest_width / src_width,
+                                          (double)dest_height / src_height,
+                                          filter_level, 255);
+#else
 		_pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
 				   src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
 				   (double)dest_width / src_width, (double)dest_height / src_height,
 				   filter_level, 255);
+#endif
 	      }
 	    composite_times[src_index][dest_index][filter_level] =
 	      stop_timing ("   composite\t\t", ITERS, dest_height * dest_width);
