--- gtk+-2.10.6/gdk/Makefile.am	2006-10-17 10:38:21.366679000 +0200
+++ ../SUNWgnome-base-libs-2.16.1/gtk+-2.10.6/gdk/Makefile.am	2006-10-17 10:41:42.704983000 +0200
@@ -45,6 +45,15 @@ LDADD = \
 	$(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
@@ -84,11 +93,13 @@ gdk_public_h_sources =				\
 
 gdk_headers =                     \
 	$(gdk_public_h_sources)   \
+	$(medialib_h_sources)     \
 	gdkenumtypes.h		  \
 	gdkprivate.h		  \
 	gdkalias.h
 
 gdk_c_sources =                 \
+	$(medialib_sources)     \
 	gdk.c			\
 	gdkcairo.c		\
 	gdkcolor.c		\
diff -Nrup gtk+-2.10.6/gdk/gdkprivate.h ../SUNWgnome-base-libs-2.16.1/gtk+-2.10.6/gdk/gdkprivate.h
--- gtk+-2.10.6/gdk/gdkprivate.h	2006-10-17 10:38:21.274403000 +0200
+++ ../SUNWgnome-base-libs-2.16.1/gtk+-2.10.6/gdk/gdkprivate.h	2006-10-17 10:41:42.707895000 +0200
@@ -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
 
diff -Nrup gtk+-2.10.6/gdk-pixbuf/pixops/Makefile.am ../SUNWgnome-base-libs-2.16.1/gtk+-2.10.6/gdk-pixbuf/pixops/Makefile.am
--- gtk+-2.10.6/gdk-pixbuf/pixops/Makefile.am	2006-10-17 10:38:21.011748000 +0200
+++ ../SUNWgnome-base-libs-2.16.1/gtk+-2.10.6/gdk-pixbuf/pixops/Makefile.am	2006-10-17 10:41:42.709103000 +0200
@@ -9,7 +9,7 @@ INCLUDES = \
 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.10.6/gdk-pixbuf/pixops/timescale.c-orig	2007-01-08 03:28:48.225189000 -0600
+++ gtk+-2.10.6/gdk-pixbuf/pixops/timescale.c	2007-01-08 03:50:43.376094000 -0600
@@ -200,9 +200,13 @@ int main (int argc, char **argv)
 		start_timing ();
 		for (i = 0; i < ITERS; i++)
 		  {
-		    _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,
+		    _pixops_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, 0, 0, 0, 0,
+				   (double)dest_width / src_width,
+				   (double)dest_height / src_height,
 				   filter_level);
 		  }
 		scale_times[src_index][dest_index][filter_level] =
@@ -212,21 +216,32 @@ int main (int argc, char **argv)
 	    start_timing ();
 	    for (i = 0; i < ITERS; i++)
 	      {
-		_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,
+		_pixops_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, 0, 0, 0, 0,
+				   (double)dest_width / src_width,
+				   (double)dest_height / src_height,
 				   filter_level, 255);
 	      }
 	    composite_times[src_index][dest_index][filter_level] =
-	      stop_timing ("   composite\t\t", ITERS, dest_height * dest_width);
+	      stop_timing ("   composite\t\t", ITERS,
+			   dest_height * dest_width);
 
 	    start_timing ();
 	    for (i = 0; i < ITERS; i++)
 	      {
-		_pixops_composite_color (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, 0, 0, 16, 0xaaaaaa, 0x555555);
+		_pixops_composite_color (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,
+					 0, 0, 0, 0,
+					 (double)dest_width / src_width,
+					 (double)dest_height / src_height,
+					 filter_level, 255, 0, 0, 16,
+					 0xaaaaaa, 0x555555);
 	      }
 	    composite_color_times[src_index][dest_index][filter_level] =
 	      stop_timing ("   composite color\t", ITERS, dest_height * dest_width);
+#endif
--- gtk+-2.10.6/gdk-pixbuf/pixops/pixops.h-orig	2007-01-08 03:28:57.453429000 -0600
+++ gtk+-2.10.6/gdk-pixbuf/pixops/pixops.h	2007-01-08 03:30:03.413215000 -0600
@@ -21,8 +21,6 @@
 
 #include <glib.h>
 
-
-
 /* Interpolation modes; must match GdkInterpType */ 
 typedef enum {
 	PIXOPS_INTERP_NEAREST,
@@ -36,24 +34,28 @@ typedef enum {
  * render_x, render_y, render_width, render_height in the new
  * coordinate system into dest_buf starting at 0, 0
  */
-void _pixops_composite (guchar         *dest_buf,
-			int             render_x0,
-			int             render_y0,
-			int             render_x1,
-			int             render_y1,
-			int             dest_rowstride,
-			int             dest_channels,
-			int             dest_has_alpha,
-			const guchar   *src_buf,
-			int             src_width,
-			int             src_height,
-			int             src_rowstride,
-			int             src_channels,
-			int             src_has_alpha,
-			double          scale_x,
-			double          scale_y,
-			PixopsInterpType   interp_type,
-			int             overall_alpha);
+void _pixops_composite (guchar          *dest_buf,
+                        int              dest_width,
+                        int              dest_height,
+                        int              dest_rowstride,
+                        int              dest_channels,
+                        int              dest_has_alpha,
+                        const guchar    *src_buf,
+                        int              src_width,
+                        int              src_height,
+                        int              src_rowstride,
+                        int              src_channels,
+                        int              src_has_alpha,
+                        int              dest_x,
+                        int              dest_y,
+                        int              dest_region_width,
+                        int              dest_region_height,
+                        double           offset_x,
+                        double           offset_y,
+                        double           scale_x,
+                        double           scale_y,
+                        PixopsInterpType interp_type,
+                        int              overall_alpha);
 
 /* Scale src_buf from src_width / src_height by factors scale_x, scale_y
  * and composite the portion corresponding to
@@ -61,53 +63,58 @@ void _pixops_composite (guchar         *
  * coordinate system against a checkboard with checks of size check_size
  * of the colors color1 and color2 into dest_buf starting at 0, 0
  */
-void _pixops_composite_color (guchar         *dest_buf,
-			      int             render_x0,
-			      int             render_y0,
-			      int             render_x1,
-			      int             render_y1,
-			      int             dest_rowstride,
-			      int             dest_channels,
-			      int             dest_has_alpha,
-			      const guchar   *src_buf,
-			      int             src_width,
-			      int             src_height,
-			      int             src_rowstride,
-			      int             src_channels,
-			      int             src_has_alpha,
-			      double          scale_x,
-			      double          scale_y,
-			      PixopsInterpType   interp_type,
-			      int             overall_alpha,
-			      int             check_x,
-			      int             check_y,
-			      int             check_size,
-			      guint32         color1,
-			      guint32         color2);
+void _pixops_composite_color (guchar          *dest_buf,
+                              int              dest_width,
+                              int              dest_height,
+                              int              dest_rowstride,
+                              int              dest_channels,
+                              int              dest_has_alpha,
+                              const guchar    *src_buf,
+                              int              src_width,
+                              int              src_height,
+                              int              src_rowstride,
+                              int              src_channels,
+                              int              src_has_alpha,
+                              int              dest_x,
+                              int              dest_y,
+                              int              dest_region_width,
+                              int              dest_region_height,
+                              double           offset_x,
+                              double           offset_y,
+                              double           scale_x,
+                              double           scale_y,
+                              PixopsInterpType interp_type,
+                              int              overall_alpha,
+                              int              check_x,
+                              int              check_y,
+                              int              check_size,
+                              guint32          color1,
+                              guint32          color2);
 
 /* Scale src_buf from src_width / src_height by factors scale_x, scale_y
  * and composite the portion corresponding to
  * render_x, render_y, render_width, render_height in the new
  * coordinate system into dest_buf starting at 0, 0
  */
-void _pixops_scale    (guchar         *dest_buf,
-		       int             render_x0,
-		       int             render_y0,
-		       int             render_x1,
-		       int             render_y1,
-		       int             dest_rowstride,
-		       int             dest_channels,
-		       int             dest_has_alpha,
-		       const guchar   *src_buf,
-		       int             src_width,
-		       int             src_height,
-		       int             src_rowstride,
-		       int             src_channels,
-		       int             src_has_alpha,
-		       double          scale_x,
-		       double          scale_y,
-		       PixopsInterpType   interp_type);
-
-
-
+void _pixops_scale    (guchar          *dest_buf,
+                       int              dest_width,
+                       int              dest_height,
+                       int              dest_rowstride,
+                       int              dest_channels,
+                       int              dest_has_alpha,
+                       const guchar    *src_buf,
+                       int              src_width,
+                       int              src_height,
+                       int              src_rowstride,
+                       int              src_channels,
+                       int              src_has_alpha,
+                       int              dest_x,
+                       int              dest_y,
+                       int              dest_region_width,
+                       int              dest_region_height,
+                       double           offset_x,
+                       double           offset_y,
+                       double           scale_x,
+                       double           scale_y,
+                       PixopsInterpType interp_type);
 #endif
--- gtk+-2.10.6/gdk-pixbuf/gdk-pixbuf-scale.c-orig	2007-01-08 03:28:30.638499000 -0600
+++ gtk+-2.10.6/gdk-pixbuf/gdk-pixbuf-scale.c	2007-01-04 19:05:39.547159000 -0600
@@ -73,14 +73,12 @@ gdk_pixbuf_scale (const GdkPixbuf *src,
 
   offset_x = floor (offset_x + 0.5);
   offset_y = floor (offset_y + 0.5);
-  
-  _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,
-		 dest->rowstride, dest->n_channels, dest->has_alpha,
-		 src->pixels, src->width, src->height,
-		 src->rowstride, src->n_channels, src->has_alpha,
-		 scale_x, scale_y, (PixopsInterpType)interp_type);
+
+  _pixops_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);
 }
 
 /**
@@ -136,13 +134,13 @@ gdk_pixbuf_composite (const GdkPixbuf *s
 
   offset_x = floor (offset_x + 0.5);
   offset_y = floor (offset_y + 0.5);
-  _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,
-		     dest->rowstride, dest->n_channels, dest->has_alpha,
-		     src->pixels, src->width, src->height,
-		     src->rowstride, src->n_channels, src->has_alpha,
-		     scale_x, scale_y, (PixopsInterpType)interp_type, overall_alpha);
+
+  _pixops_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);
 }
 
 /**
@@ -204,14 +202,14 @@ gdk_pixbuf_composite_color (const GdkPix
   offset_x = floor (offset_x + 0.5);
   offset_y = floor (offset_y + 0.5);
   
-  _pixops_composite_color (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,
+  _pixops_composite_color (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,
-			   scale_x, scale_y, (PixopsInterpType)interp_type, overall_alpha, check_x, check_y,
-			   check_size, color1, color2);
+			   dest_x, dest_y, dest_width, dest_height, offset_x,
+			   offset_y, scale_x, scale_y,
+			   (PixopsInterpType)interp_type, overall_alpha,
+			   check_x, check_y, check_size, color1, color2);
 }
 
 /**
--- /tmp/acconfig.h	2007-01-30 12:32:31.805525006 +0800
+++ gtk+-2.10.9/acconfig.h	2007-01-30 12:22:30.346256000 +0800
@@ -46,6 +46,8 @@
 
 #undef USE_GMODULE
 #undef USE_MMX
+#undef USE_MEDIALIB
+#undef USE_MEDIALIB25
 
 /* Define to use XKB extension */
 #undef HAVE_XKB
--- /dev/null	2007-01-30 12:23:32.000000000 +0800
+++ gtk+-2.10.9/gdk/gdkmedialib.h	2007-01-30 11:56:55.846168000 +0800
@@ -0,0 +1,58 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2001-2007 Sun Microsystems, Inc.  All rights reserved.
+ * (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#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__ */
+
--- /tmp/configure.in	2007-01-30 13:25:17.602349629 +0800
+++ gtk+-2.10.9/configure.in	2007-01-30 13:24:06.924793000 +0800
@@ -986,6 +986,29 @@ else
   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)
+use_mlib25=no
+# 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
+
+    AC_MSG_CHECKING(for mediaLib 2.5)
+    # Check for a mediaLib 2.5 function since that is what is needed for
+    # gdk_rgb_convert integration.
+    AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib25=yes, use_mlib25=no)
+    if test $use_mlib25 = yes; then
+        AC_DEFINE(USE_MEDIALIB25)
+    fi
+fi
+AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes)
+AM_CONDITIONAL(USE_MEDIALIB25, test $use_mlib25 = 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.)
@@ -1054,7 +1077,7 @@ fi
 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"
--- /tmp/pixops.c	2007-02-13 10:40:45.424754612 +0800
+++ gtk+-2.10.9/gdk-pixbuf/pixops/pixops.c	2007-02-13 10:38:47.167475000 +0800
@@ -1,5 +1,8 @@
 /*
  * Copyright (C) 2000 Red Hat, Inc
+ * mediaLib integration Copyright (c) 2001-2007 Sun Microsystems, Inc.
+ * All rights reserved.  (Brian Cameron, Dmitriy Demin, James Cheng,
+ * Padraig O'Briain)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -28,6 +31,25 @@
 #define SUBSAMPLE_MASK ((1 << SUBSAMPLE_BITS)-1)
 #define SCALE_SHIFT 16
 
+static void
+_pixops_scale_real (guchar        *dest_buf,
+                    int            render_x0,
+                    int            render_y0,
+                    int            render_x1,
+                    int            render_y1,
+                    int            dest_rowstride,
+                    int            dest_channels,
+                    gboolean       dest_has_alpha,
+                    const guchar  *src_buf,
+                    int            src_width,
+                    int            src_height,
+                    int            src_rowstride,
+                    int            src_channels,
+                    gboolean       src_has_alpha,
+                    double         scale_x,
+                    double         scale_y,
+                    PixopsInterpType  interp_type);
+
 typedef struct _PixopsFilter PixopsFilter;
 typedef struct _PixopsFilterDimension PixopsFilterDimension;
 
@@ -46,15 +68,175 @@ struct _PixopsFilter
 }; 
 
 typedef guchar *(*PixopsLineFunc) (int *weights, int n_x, int n_y,
-				   guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-				   guchar **src, int src_channels, gboolean src_has_alpha,
-				   int x_init, int x_step, int src_width,
-				   int check_size, guint32 color1, guint32 color2);
-
-typedef void (*PixopsPixelFunc) (guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,
-				 int src_has_alpha, int check_size, guint32 color1,
-				 guint32 color2,
-				 guint r, guint g, guint b, guint a);
+				   guchar *dest, int dest_x, guchar *dest_end,
+				   int dest_channels, int dest_has_alpha,
+				   guchar **src, int src_channels,
+				   gboolean src_has_alpha, int x_init,
+				   int x_step, int src_width, int check_size,
+				   guint32 color1, guint32 color2);
+typedef void (*PixopsPixelFunc)   (guchar *dest, int dest_x, int dest_channels,
+				   int dest_has_alpha, int src_has_alpha,
+				   int check_size, guint32 color1,
+				   guint32 color2,
+				   guint r, guint g, guint b, guint a);
+
+#ifdef USE_MEDIALIB
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <mlib_image.h>
+
+#if defined (__sun)
+#include <strings.h>
+#include <sys/systeminfo.h>
+#elif defined(__linux__)
+#include <string.h>
+#include <sys/sysinfo.h>
+#endif
+
+static void pixops_medialib_composite    (guchar          *dest_buf,
+                                          int              dest_width,
+                                          int              dest_height,
+                                          int              dest_rowstride,
+                                          int              dest_channels,
+                                          int              dest_has_alpha,
+                                          const guchar    *src_buf,
+                                          int              src_width,
+                                          int              src_height,
+                                          int              src_rowstride,
+                                          int              src_channels,
+                                          int              src_has_alpha,
+                                          int              dest_x,
+                                          int              dest_y,
+                                          int              dest_region_width,
+                                          int              dest_region_height,
+                                          double           offset_x,
+                                          double           offset_y,
+                                          double           scale_x,
+                                          double           scale_y,
+                                          PixopsInterpType interp_type,
+                                          int              overall_alpha);
+
+static void pixops_medialib_scale        (guchar          *dest_buf,
+                                          int              dest_width,
+                                          int              dest_height,
+                                          int              dest_rowstride,
+                                          int              dest_channels,
+                                          int              dest_has_alpha,
+                                          const guchar    *src_buf,
+                                          int              src_width,
+                                          int              src_height,
+                                          int              src_rowstride,
+                                          int              src_channels,
+                                          int              src_has_alpha,
+                                          int              dest_x,
+                                          int              dest_y,
+                                          int              dest_region_width,
+                                          int              dest_region_height,
+                                          double           offset_x,
+                                          double           offset_y,
+                                          double           scale_x,
+                                          double           scale_y,
+                                          PixopsInterpType interp_type);
+
+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);
+typedef struct _mlInterp mlInterp;
+
+struct _mlInterp
+{
+  double       tx;
+  double       ty;
+  PixopsFilter po_filter;
+  void         *interp_table;
+};
+
+static gboolean medialib_initialized = FALSE;
+static gboolean use_medialib         = FALSE;
+
+/*
+ * Sun mediaLib(tm) support.
+ *
+ *   http://www.sun.com/processors/vis/mlib.html
+ *
+ */
+static void
+_pixops_use_medialib ()
+{
+  char *mlib_version_string;
+  char  sys_info[257];
+  long  count;
+
+  medialib_initialized = TRUE; 
+
+  if (getenv ("GTK_DISABLE_MEDIALIB"))
+    {
+      use_medialib = FALSE;
+      return;
+    }
+
+  /*
+   * 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
+   * is 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 ();
+
+  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
+           * does not give any performance advantage so disable it
+           */
+          if (strncmp (mlib_target_isa, "sse", 3) != 0)
+            {
+              use_medialib = FALSE;
+              return;
+            }
+
+          /*
+           * For x86 processors use of libumem conflicts with
+           * mediaLib, so avoid using 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 = FALSE;
+              return;
+            }
+        }
+    }
+  else
+    {
+      /* Failed to get system architecture, disable mediaLib anyway */
+      use_medialib = FALSE;
+      return;
+    }
+}
+#endif
 
 static int
 get_check_shift (int check_size)
@@ -241,7 +423,7 @@ pixops_composite_nearest (guchar        
                 }
               break;
             }
-	);	      
+	);
     }
 }
 
@@ -509,7 +691,8 @@ composite_line_22_4a4 (int *weights, int
       q0 = src0 + x_scaled * 4;
       q1 = src1 + x_scaled * 4;
       
-      pixel_weights = (int *)((char *)weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS - 4)) & (SUBSAMPLE_MASK << 4)));
+      pixel_weights = (int *)((char *)weights +
+	((x >> (SCALE_SHIFT - SUBSAMPLE_BITS - 4)) & (SUBSAMPLE_MASK << 4)));
       
       w1 = pixel_weights[0];
       w2 = pixel_weights[1];
@@ -553,11 +736,13 @@ composite_line_22_4a4 (int *weights, int
 
 #ifdef USE_MMX
 static guchar *
-composite_line_22_4a4_mmx_stub (int *weights, int n_x, int n_y,
-				guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-				guchar **src, int src_channels, gboolean src_has_alpha,
-				int x_init, int x_step, int src_width,
-				int check_size, guint32 color1, guint32 color2)
+composite_line_22_4a4_mmx_stub (int *weights, int n_x, int n_y, guchar *dest,
+				int dest_x, guchar *dest_end,
+				int dest_channels, int dest_has_alpha,
+				guchar **src, int src_channels,
+				gboolean src_has_alpha, int x_init,
+				int x_step, int src_width, int check_size,
+				guint32 color1, guint32 color2)
 {
   guint32 mmx_weights[16][8];
   int j;
@@ -574,14 +759,16 @@ composite_line_22_4a4_mmx_stub (int *wei
       mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8);
     }
 
-  return _pixops_composite_line_22_4a4_mmx (mmx_weights, dest, src[0], src[1], x_step, dest_end, x_init);
+  return _pixops_composite_line_22_4a4_mmx (mmx_weights, dest, src[0], src[1],
+					    x_step, dest_end, x_init);
 }
 #endif /* USE_MMX */
 
 static void
-composite_pixel_color (guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,
-		       int src_has_alpha, int check_size, guint32 color1, guint32 color2,
-		       guint r, guint g, guint b, guint a)
+composite_pixel_color (guchar *dest, int dest_x, int dest_channels,
+		       int dest_has_alpha, int src_has_alpha, int check_size,
+		       guint32 color1, guint32 color2, guint r, guint g,
+		       guint b, guint a)
 {
   int dest_r, dest_g, dest_b;
   int check_shift = get_check_shift (check_size);
@@ -610,11 +797,12 @@ composite_pixel_color (guchar *dest, int
 }
 
 static guchar *
-composite_line_color (int *weights, int n_x, int n_y,
-		      guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-		      guchar **src, int src_channels, gboolean src_has_alpha,
-		      int x_init, int x_step, int src_width,
-		      int check_size, guint32 color1, guint32 color2)
+composite_line_color (int *weights, int n_x, int n_y, guchar *dest,
+		      int dest_x, guchar *dest_end, int dest_channels,
+		      int dest_has_alpha, guchar **src, int src_channels,
+		      gboolean src_has_alpha, int x_init, int x_step,
+		      int src_width, int check_size, guint32 color1,
+		      guint32 color2)
 {
   int x = x_init;
   int i, j;
@@ -692,10 +880,13 @@ composite_line_color (int *weights, int 
 #ifdef USE_MMX
 static guchar *
 composite_line_color_22_4a4_mmx_stub (int *weights, int n_x, int n_y,
-				      guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-				      guchar **src, int src_channels, gboolean src_has_alpha,
+				      guchar *dest, int dest_x,
+				      guchar *dest_end, int dest_channels,
+				      int dest_has_alpha, guchar **src,
+				      int src_channels, gboolean src_has_alpha,
 				      int x_init, int x_step, int src_width,
-				      int check_size, guint32 color1, guint32 color2)
+				      int check_size, guint32 color1,
+				      guint32 color2)
 {
   guint32 mmx_weights[16][8];
   int check_shift = get_check_shift (check_size);
@@ -719,8 +910,8 @@ composite_line_color_22_4a4_mmx_stub (in
   colors[2] = (color2 & 0xff00) << 8 | (color2 & 0xff);
   colors[3] = (color2 & 0xff0000) >> 16;
 
-  return _pixops_composite_line_color_22_4a4_mmx (mmx_weights, dest, src[0], src[1], x_step, dest_end, x_init,
-						  dest_x, check_shift, colors);
+  return _pixops_composite_line_color_22_4a4_mmx (mmx_weights, dest, src[0],
+    src[1], x_step, dest_end, x_init, dest_x, check_shift, colors);
 }
 #endif /* USE_MMX */
 
@@ -758,11 +949,11 @@ scale_pixel (guchar *dest, int dest_x, i
 }
 
 static guchar *
-scale_line (int *weights, int n_x, int n_y,
-	    guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-	    guchar **src, int src_channels, gboolean src_has_alpha,
-	    int x_init, int x_step, int src_width,
-	    int check_size, guint32 color1, guint32 color2)
+scale_line (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
+	    guchar *dest_end, int dest_channels, int dest_has_alpha,
+	    guchar **src, int src_channels, gboolean src_has_alpha, int x_init,
+	    int x_step, int src_width, int check_size, guint32 color1,
+	    guint32 color2)
 {
   int x = x_init;
   int i, j;
@@ -772,7 +963,8 @@ scale_line (int *weights, int n_x, int n
       int x_scaled = x >> SCALE_SHIFT;
       int *pixel_weights;
 
-      pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y;
+      pixel_weights = weights +
+        ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y;
 
       if (src_has_alpha)
 	{
@@ -849,11 +1041,12 @@ scale_line (int *weights, int n_x, int n
 
 #ifdef USE_MMX 
 static guchar *
-scale_line_22_33_mmx_stub (int *weights, int n_x, int n_y,
-			   guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
-			   guchar **src, int src_channels, gboolean src_has_alpha,
-			   int x_init, int x_step, int src_width,
-			   int check_size, guint32 color1, guint32 color2)
+scale_line_22_33_mmx_stub (int *weights, int n_x, int n_y, guchar *dest,
+			   int dest_x, guchar *dest_end, int dest_channels,
+			   int dest_has_alpha, guchar **src, int src_channels,
+			   gboolean src_has_alpha, int x_init, int x_step,
+			   int src_width, int check_size, guint32 color1,
+			   guint32 color2)
 {
   guint32 mmx_weights[16][8];
   int j;
@@ -870,13 +1063,14 @@ scale_line_22_33_mmx_stub (int *weights,
       mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8);
     }
 
-  return _pixops_scale_line_22_33_mmx (mmx_weights, dest, src[0], src[1], x_step, dest_end, x_init);
+  return _pixops_scale_line_22_33_mmx (mmx_weights, dest, src[0], src[1],
+				       x_step, dest_end, x_init);
 }
 #endif /* USE_MMX */
 
 static guchar *
-scale_line_22_33 (int *weights, int n_x, int n_y,
-		  guchar *dest, int dest_x, guchar *dest_end, int dest_channels, int dest_has_alpha,
+scale_line_22_33 (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
+		  guchar *dest_end, int dest_channels, int dest_has_alpha,
 		  guchar **src, int src_channels, gboolean src_has_alpha,
 		  int x_init, int x_step, int src_width,
 		  int check_size, guint32 color1, guint32 color2)
@@ -896,7 +1090,8 @@ scale_line_22_33 (int *weights, int n_x,
       q0 = src0 + x_scaled * 3;
       q1 = src1 + x_scaled * 3;
       
-      pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * 4;
+      pixel_weights = weights +
+        ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * 4;
 
       w1 = pixel_weights[0];
       w2 = pixel_weights[1];
@@ -931,11 +1126,10 @@ scale_line_22_33 (int *weights, int n_x,
 }
 
 static void
-process_pixel (int *weights, int n_x, int n_y,
-	       guchar *dest, int dest_x, int dest_channels, int dest_has_alpha,
-	       guchar **src, int src_channels, gboolean src_has_alpha,
-	       int x_start, int src_width,
-	       int check_size, guint32 color1, guint32 color2,
+process_pixel (int *weights, int n_x, int n_y, guchar *dest, int dest_x,
+	       int dest_channels, int dest_has_alpha, guchar **src,
+	       int src_channels, gboolean src_has_alpha, int x_start,
+	       int src_width, int check_size, guint32 color1, guint32 color2,
 	       PixopsPixelFunc pixel_func)
 {
   unsigned int r = 0, g = 0, b = 0, a = 0;
@@ -969,7 +1163,8 @@ process_pixel (int *weights, int n_x, in
 	}
     }
 
-  (*pixel_func) (dest, dest_x, dest_channels, dest_has_alpha, src_has_alpha, check_size, color1, color2, r, g, b, a);
+  (*pixel_func) (dest, dest_x, dest_channels, dest_has_alpha, src_has_alpha,
+    check_size, color1, color2, r, g, b, a);
 }
 
 static void 
@@ -1071,12 +1266,13 @@ pixops_process (guchar         *dest_buf
 
   int scaled_x_offset = floor (filter->x.offset * (1 << SCALE_SHIFT));
 
-  /* Compute the index where we run off the end of the source buffer. The furthest
-   * source pixel we access at index i is:
+  /* Compute the index where we run off the end of the source buffer. The
+   * furthest source pixel we access at index i is:
    *
    *  ((render_x0 + i) * x_step + scaled_x_offset) >> SCALE_SHIFT + filter->x.n - 1
    *
-   * So, run_end_index is the smallest i for which this pixel is src_width, i.e, for which:
+   * So, run_end_index is the smallest i for which this pixel is src_width,
+   * i.e, for which:
    *
    *  (i + render_x0) * x_step >= ((src_width - filter->x.n + 1) << SCALE_SHIFT) - scaled_x_offset
    *
@@ -1144,11 +1340,12 @@ pixops_process (guchar         *dest_buf
 	}
 
       new_outbuf = (*line_func) (run_weights, filter->x.n, filter->y.n,
-				 outbuf, dest_x,
-				 dest_buf + dest_rowstride * i + run_end_index * dest_channels,
+				 outbuf, dest_x, dest_buf + dest_rowstride *
+				 i + run_end_index * dest_channels,
 				 dest_channels, dest_has_alpha,
 				 line_bufs, src_channels, src_has_alpha,
-				 x, x_step, src_width, check_size, tcolor1, tcolor2);
+				 x, x_step, src_width, check_size, tcolor1,
+				 tcolor2);
 
       dest_x += (new_outbuf - outbuf) / dest_channels;
 
@@ -1384,30 +1581,30 @@ make_weights (PixopsFilter     *filter,
     }
 }
 
-void
-_pixops_composite_color (guchar         *dest_buf,
-			 int             render_x0,
-			 int             render_y0,
-			 int             render_x1,
-			 int             render_y1,
-			 int             dest_rowstride,
-			 int             dest_channels,
-			 gboolean        dest_has_alpha,
-			 const guchar   *src_buf,
-			 int             src_width,
-			 int             src_height,
-			 int             src_rowstride,
-			 int             src_channels,
-			 gboolean        src_has_alpha,
-			 double          scale_x,
-			 double          scale_y,
-			 PixopsInterpType   interp_type,
-			 int             overall_alpha,
-			 int             check_x,
-			 int             check_y,
-			 int             check_size,
-			 guint32         color1,
-			 guint32         color2)
+static void
+_pixops_composite_color_real (guchar          *dest_buf,
+			      int              render_x0,
+			      int              render_y0,
+			      int              render_x1,
+			      int              render_y1,
+			      int              dest_rowstride,
+			      int              dest_channels,
+			      gboolean         dest_has_alpha,
+			      const guchar    *src_buf,
+			      int              src_width,
+			      int              src_height,
+			      int              src_rowstride,
+			      int              src_channels,
+			      gboolean         src_has_alpha,
+			      double           scale_x,
+			      double           scale_y,
+			      PixopsInterpType interp_type,
+			      int              overall_alpha,
+			      int              check_x,
+			      int              check_y,
+			      int              check_size,
+			      guint32          color1,
+			      guint32          color2)
 {
   PixopsFilter filter;
   PixopsLineFunc line_func;
@@ -1422,22 +1619,15 @@ _pixops_composite_color (guchar         
   if (scale_x == 0 || scale_y == 0)
     return;
 
-  if (!src_has_alpha && overall_alpha == 255)
-    {
-      _pixops_scale (dest_buf, render_x0, render_y0, render_x1, render_y1,
-		     dest_rowstride, dest_channels, dest_has_alpha,
-		     src_buf, src_width, src_height, src_rowstride, src_channels,
-		     src_has_alpha, scale_x, scale_y, interp_type);
-      return;
-    }
-
   if (interp_type == PIXOPS_INTERP_NEAREST)
     {
-      pixops_composite_color_nearest (dest_buf, render_x0, render_y0, render_x1, render_y1,
-				      dest_rowstride, dest_channels, dest_has_alpha,
-				      src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
-				      scale_x, scale_y, overall_alpha,
-				      check_x, check_y, check_size, color1, color2);
+      pixops_composite_color_nearest (dest_buf, render_x0, render_y0,
+				      render_x1, render_y1, dest_rowstride,
+				      dest_channels, dest_has_alpha, src_buf,
+				      src_width, src_height, src_rowstride,
+				      src_channels, src_has_alpha, scale_x,
+				      scale_y, overall_alpha, check_x, check_y,
+				      check_size, color1, color2);
       return;
     }
   
@@ -1446,7 +1636,8 @@ _pixops_composite_color (guchar         
 
 #ifdef USE_MMX
   if (filter.x.n == 2 && filter.y.n == 2 &&
-      dest_channels == 4 && src_channels == 4 && src_has_alpha && !dest_has_alpha && found_mmx)
+      dest_channels == 4 && src_channels == 4 &&
+      src_has_alpha && !dest_has_alpha && found_mmx)
     line_func = composite_line_color_22_4a4_mmx_stub;
   else
 #endif
@@ -1462,8 +1653,69 @@ _pixops_composite_color (guchar         
   g_free (filter.y.weights);
 }
 
+void
+_pixops_composite_color (guchar          *dest_buf,
+			 int              dest_width,
+			 int              dest_height,
+			 int              dest_rowstride,
+			 int              dest_channels,
+			 gboolean         dest_has_alpha,
+			 const guchar    *src_buf,
+			 int              src_width,
+			 int              src_height,
+			 int              src_rowstride,
+			 int              src_channels,
+			 gboolean         src_has_alpha,
+			 int              dest_x,
+			 int              dest_y,
+			 int              dest_region_width,
+			 int              dest_region_height,
+			 double           offset_x,
+			 double           offset_y,
+			 double           scale_x,
+			 double           scale_y,
+			 PixopsInterpType interp_type,
+			 int              overall_alpha,
+			 int              check_x,
+			 int              check_y,
+			 int              check_size,
+			 guint32          color1,
+			 guint32          color2)
+{
+  guchar *new_dest_buf;
+  int render_x0;
+  int render_y0;
+  int render_x1;
+  int render_y1;
+
+  if (!src_has_alpha && overall_alpha == 255)
+    {
+      _pixops_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,
+		     dest_x, dest_y, dest_region_width, dest_region_height,
+		     offset_x, offset_y, scale_x, scale_y, interp_type);
+      return;
+    }
+
+  new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x *
+                 dest_channels;
+  render_x0 = dest_x - offset_x;
+  render_y0 = dest_y - offset_y;
+  render_x1 = dest_x + dest_region_width  - offset_x;
+  render_y1 = dest_y + dest_region_height - offset_y;
+
+  _pixops_composite_color_real (new_dest_buf, render_x0, render_y0, render_x1,
+				render_y1, dest_rowstride, dest_channels,
+				dest_has_alpha, src_buf, src_width,
+				src_height, src_rowstride, src_channels,
+				src_has_alpha, scale_x, scale_y,
+				(PixopsInterpType)interp_type, overall_alpha,
+				check_x, check_y, check_size, color1, color2);
+}
+
 /**
- * _pixops_composite:
+ * _pixops_composite_real:
  * @dest_buf: pointer to location to store result
  * @render_x0: x0 of region of scaled source to store into @dest_buf
  * @render_y0: y0 of region of scaled source to store into @dest_buf
@@ -1486,25 +1738,25 @@ _pixops_composite_color (guchar         
  * Scale source buffer by scale_x / scale_y, then composite a given rectangle
  * of the result into the destination buffer.
  **/
-void
-_pixops_composite (guchar        *dest_buf,
-		   int            render_x0,
-		   int            render_y0,
-		   int            render_x1,
-		   int            render_y1,
-		   int            dest_rowstride,
-		   int            dest_channels,
-		   gboolean       dest_has_alpha,
-		   const guchar  *src_buf,
-		   int            src_width,
-		   int            src_height,
-		   int            src_rowstride,
-		   int            src_channels,
-		   gboolean       src_has_alpha,
-		   double         scale_x,
-		   double         scale_y,
-		   PixopsInterpType  interp_type,
-		   int            overall_alpha)
+static void
+_pixops_composite_real (guchar          *dest_buf,
+			int              render_x0,
+			int              render_y0,
+			int              render_x1,
+			int              render_y1,
+			int              dest_rowstride,
+			int              dest_channels,
+			gboolean         dest_has_alpha,
+			const guchar    *src_buf,
+			int              src_width,
+			int              src_height,
+			int              src_rowstride,
+			int              src_channels,
+			gboolean         src_has_alpha,
+			double           scale_x,
+			double           scale_y,
+			PixopsInterpType interp_type,
+			int              overall_alpha)
 {
   PixopsFilter filter;
   PixopsLineFunc line_func;
@@ -1519,29 +1771,21 @@ _pixops_composite (guchar        *dest_b
   if (scale_x == 0 || scale_y == 0)
     return;
 
-  if (!src_has_alpha && overall_alpha == 255)
-    {
-      _pixops_scale (dest_buf, render_x0, render_y0, render_x1, render_y1,
-		     dest_rowstride, dest_channels, dest_has_alpha,
-		     src_buf, src_width, src_height, src_rowstride, src_channels,
-		     src_has_alpha, scale_x, scale_y, interp_type);
-      return;
-    }
-
   if (interp_type == PIXOPS_INTERP_NEAREST)
     {
-      pixops_composite_nearest (dest_buf, render_x0, render_y0, render_x1, render_y1,
-				dest_rowstride, dest_channels, dest_has_alpha,
-				src_buf, src_width, src_height, src_rowstride, src_channels,
-				src_has_alpha, scale_x, scale_y, overall_alpha);
+      pixops_composite_nearest (dest_buf, render_x0, render_y0, render_x1,
+				render_y1, dest_rowstride, dest_channels,
+				dest_has_alpha, src_buf, src_width, src_height,
+				src_rowstride, src_channels, src_has_alpha,
+				scale_x, scale_y, overall_alpha);
       return;
     }
   
   filter.overall_alpha = overall_alpha / 255.;
   make_weights (&filter, interp_type, scale_x, scale_y);
 
-  if (filter.x.n == 2 && filter.y.n == 2 &&
-      dest_channels == 4 && src_channels == 4 && src_has_alpha && !dest_has_alpha)
+  if (filter.x.n == 2 && filter.y.n == 2 && dest_channels == 4 &&
+      src_channels == 4 && src_has_alpha && !dest_has_alpha)
     {
 #ifdef USE_MMX
       if (found_mmx)
@@ -1564,23 +1808,357 @@ _pixops_composite (guchar        *dest_b
 }
 
 void
-_pixops_scale (guchar        *dest_buf,
-	       int            render_x0,
-	       int            render_y0,
-	       int            render_x1,
-	       int            render_y1,
-	       int            dest_rowstride,
-	       int            dest_channels,
-	       gboolean       dest_has_alpha,
-	       const guchar  *src_buf,
-	       int            src_width,
-	       int            src_height,
-	       int            src_rowstride,
-	       int            src_channels,
-	       gboolean       src_has_alpha,
-	       double         scale_x,
-	       double         scale_y,
-	       PixopsInterpType  interp_type)
+_pixops_composite (guchar          *dest_buf,
+                   int              dest_width,
+                   int              dest_height,
+                   int              dest_rowstride,
+                   int              dest_channels,
+                   int              dest_has_alpha,
+                   const guchar    *src_buf,
+                   int              src_width,
+                   int              src_height,
+                   int              src_rowstride,
+                   int              src_channels,
+                   int              src_has_alpha,
+                   int              dest_x,
+                   int              dest_y,
+                   int              dest_region_width,
+                   int              dest_region_height,
+                   double           offset_x,
+                   double           offset_y,
+                   double           scale_x,
+                   double           scale_y,
+                   PixopsInterpType interp_type,
+                   int              overall_alpha)
+{
+  guchar *new_dest_buf;
+  int render_x0;
+  int render_y0;
+  int render_x1;
+  int render_y1;
+
+  if (!src_has_alpha && overall_alpha == 255)
+    {
+      _pixops_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,
+		     dest_x, dest_y, dest_region_width, dest_region_height,
+		     offset_x, offset_y, scale_x, scale_y, interp_type);
+      return;
+    }
+
+#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, dest_x, dest_y,
+                             dest_region_width, dest_region_height, offset_x,
+			     offset_y, scale_x, scale_y,
+                             (PixopsInterpType)interp_type, overall_alpha);
+  return;
+#endif
+
+  new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x * dest_channels;
+  render_x0 = dest_x - offset_x;
+  render_y0 = dest_y - offset_y;
+  render_x1 = dest_x + dest_region_width  - offset_x;
+  render_y1 = dest_y + dest_region_height - offset_y;
+
+  _pixops_composite_real (new_dest_buf, render_x0, render_y0, render_x1,
+			  render_y1, dest_rowstride, dest_channels,
+			  dest_has_alpha, src_buf, src_width, src_height,
+			  src_rowstride, src_channels, src_has_alpha, scale_x,
+			  scale_y, (PixopsInterpType)interp_type,
+			  overall_alpha);
+}
+
+#ifdef USE_MEDIALIB
+static 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);  
+}
+
+static void
+pixops_medialib_composite (guchar          *dest_buf,
+                           int              dest_width,
+                           int              dest_height,
+                           int              dest_rowstride,
+                           int              dest_channels,
+                           int              dest_has_alpha,
+                           const guchar    *src_buf,
+                           int              src_width,
+                           int              src_height,
+                           int              src_rowstride,
+                           int              src_channels,
+                           int              src_has_alpha,
+                           int              dest_x,
+                           int              dest_y,
+                           int              dest_region_width,
+                           int              dest_region_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)
+    _pixops_use_medialib ();
+
+  if (!use_medialib)
+    {
+      /* Use non-mediaLib version */
+      _pixops_composite_real (dest_buf + dest_y * dest_rowstride + dest_x *
+			      dest_channels, dest_x - offset_x, dest_y -
+			      offset_y, dest_x + dest_region_width - offset_x,
+			      dest_y + dest_region_height - offset_y,
+			      dest_rowstride, dest_channels, dest_has_alpha,
+			      src_buf, src_width, src_height, 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_region_width,
+				 dest_region_height, dest_rowstride,
+				 dest_channels, dest_has_alpha, src_buf,
+				 src_width, src_height, src_rowstride,
+				 src_channels, src_has_alpha, dest_x, dest_y,
+				 dest_region_width, dest_region_height,
+				 offset_x, offset_y, scale_x, scale_y,
+				 interp_type);
+          return;
+        }
+
+      mlib_ImageSet (&img_src, MLIB_BYTE, src_channels, src_width,
+		     src_height, src_rowstride, src_buf);
+      mlib_ImageSet (&img_orig_dest, MLIB_BYTE, dest_channels, dest_width,
+		     dest_height, dest_rowstride, dest_buf);
+
+      if (dest_x == 0 && dest_y == 0 &&
+          dest_width == dest_region_width &&
+          dest_height == dest_region_height)
+        {
+          img_dest = img_orig_dest;
+        }
+      else
+        {
+          mlib_ImageSetSubimage (&img_dest, &img_orig_dest, dest_x, dest_y,
+                                 dest_region_width, dest_region_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 - Use non-mediaLib version */
+                  _pixops_composite_real (dest_buf + dest_y * dest_rowstride +
+                                          dest_x * dest_channels,
+                                          dest_x - offset_x, dest_y - offset_y,
+                                          dest_x + dest_region_width - offset_x,
+                                          dest_y + dest_region_height - offset_y,
+                                          dest_rowstride, dest_channels,
+                                          dest_has_alpha, src_buf, src_width,
+                                          src_height, src_rowstride,
+                                          src_channels, src_has_alpha, scale_x,
+                                          scale_y, interp_type, overall_alpha);
+                }
+            }
+        }
+    }
+}
+#endif
+
+static void
+_pixops_scale_real (guchar        *dest_buf,
+		    int            render_x0,
+		    int            render_y0,
+		    int            render_x1,
+		    int            render_y1,
+		    int            dest_rowstride,
+		    int            dest_channels,
+		    gboolean       dest_has_alpha,
+		    const guchar  *src_buf,
+		    int            src_width,
+		    int            src_height,
+		    int            src_rowstride,
+		    int            src_channels,
+		    gboolean       src_has_alpha,
+		    double         scale_x,
+		    double         scale_y,
+		    PixopsInterpType  interp_type)
 {
   PixopsFilter filter;
   PixopsLineFunc line_func;
@@ -1598,9 +2176,10 @@ _pixops_scale (guchar        *dest_buf,
 
   if (interp_type == PIXOPS_INTERP_NEAREST)
     {
-      pixops_scale_nearest (dest_buf, render_x0, render_y0, render_x1, render_y1,
-			    dest_rowstride, dest_channels, dest_has_alpha,
-			    src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
+      pixops_scale_nearest (dest_buf, render_x0, render_y0, render_x1,
+			    render_y1, dest_rowstride, dest_channels,
+			    dest_has_alpha, src_buf, src_width, src_height,
+			    src_rowstride, src_channels, src_has_alpha,
 			    scale_x, scale_y);
       return;
     }
@@ -1630,3 +2209,334 @@ _pixops_scale (guchar        *dest_buf,
   g_free (filter.y.weights);
 }
 
+void
+_pixops_scale (guchar          *dest_buf,
+               int              dest_width,
+               int              dest_height,
+               int              dest_rowstride,
+               int              dest_channels,
+               int              dest_has_alpha,
+               const guchar    *src_buf,
+               int              src_width,
+               int              src_height,
+               int              src_rowstride,
+               int              src_channels,
+               int              src_has_alpha,
+               int              dest_x,
+               int              dest_y,
+               int              dest_region_width,
+               int              dest_region_height,
+               double           offset_x,
+               double           offset_y,
+               double           scale_x,
+               double           scale_y,
+               PixopsInterpType interp_type)
+{
+  guchar *new_dest_buf;
+  int render_x0;
+  int render_y0;
+  int render_x1;
+  int render_y1;
+
+#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, dest_x, dest_y, dest_region_width,
+			 dest_region_height, offset_x, offset_y, scale_x,
+			 scale_y, (PixopsInterpType)interp_type);
+  return;
+#endif
+
+  new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x * dest_channels;
+  render_x0    = dest_x - offset_x;
+  render_y0    = dest_y - offset_y;
+  render_x1    = dest_x + dest_region_width  - offset_x;
+  render_y1    = dest_y + dest_region_height - offset_y;
+
+  _pixops_scale_real (new_dest_buf, render_x0, render_y0, render_x1,
+                      render_y1, dest_rowstride, dest_channels,
+                      dest_has_alpha, src_buf, src_width, src_height,
+                      src_rowstride, src_channels, src_has_alpha,
+                      scale_x, scale_y, (PixopsInterpType)interp_type);
+}
+
+#ifdef USE_MEDIALIB
+static void
+pixops_medialib_scale     (guchar          *dest_buf,
+                           int              dest_width,
+                           int              dest_height,
+                           int              dest_rowstride,
+                           int              dest_channels,
+                           int              dest_has_alpha,
+                           const guchar    *src_buf,
+                           int              src_width,
+                           int              src_height,
+                           int              src_rowstride,
+                           int              src_channels,
+                           int              src_has_alpha,
+                           int              dest_x,
+                           int              dest_y,
+                           int              dest_region_width,
+                           int              dest_region_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)
+    _pixops_use_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)
+    {
+      _pixops_scale_real (dest_buf + dest_y * dest_rowstride + dest_x *
+			  dest_channels, dest_x - offset_x, dest_y - offset_y, 
+			  dest_x + dest_region_width - offset_x,
+			  dest_y + dest_region_height - offset_y,
+			  dest_rowstride, dest_channels, dest_has_alpha,
+			  src_buf, src_width, src_height, 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_width, 
+                     src_height, src_rowstride, src_buf);
+      mlib_ImageSet (&img_orig_dest, MLIB_BYTE, dest_channels, dest_width,
+                    dest_height, dest_rowstride, dest_buf);
+
+      if (dest_x == 0 && dest_y == 0 &&
+          dest_width == dest_region_width &&
+          dest_height == dest_region_height)
+        {
+          img_dest = img_orig_dest;
+        }
+      else
+        {
+          mlib_ImageSetSubimage (&img_dest, &img_orig_dest, dest_x, dest_y,
+                                 dest_region_width, dest_region_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_width + 3) & ~3;
+        
+              tmp_buf = g_malloc (src_rowstride * src_height);
+
+              if (src_buf != NULL)
+                {
+                  src_channels  = channels;
+                  src_rowstride = rowstride;
+          
+                  mlib_ImageSet (&img_src, MLIB_BYTE, src_channels,
+				 src_width, src_height, 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);
+                }
+            }
+        }
+
+      /* Deal 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
--- /dev/null	2007-02-13 10:33:32.000000000 +0800
+++ gtk+-2.10.9/gdk/gdkmedialib.c	2007-02-13 10:38:37.904635000 +0800
@@ -0,0 +1,115 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2001-2007 Sun Microsystems, Inc.  All rights reserved.
+ * (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2007.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#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)
+{
+  char *mlib_version_string;
+  char sys_info[257];
+  long count;
+
+  /*
+   * Sun mediaLib(tm) support.
+   *
+   *   http://www.sun.com/processors/vis/mlib.html
+   *
+   */
+  if (getenv ("GTK_DISABLE_MEDIALIB"))
+    return FALSE;
+
+  /*
+   * 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
+   * is 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 ();
+
+   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
+            * does not 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, so avoid using 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 */
+       return FALSE;
+     }
+
+  return TRUE;
+}
--- /tmp/gdkdraw.c	2007-02-13 17:15:43.896461386 +0800
+++ gtk+-2.10.9/gdk/gdkdraw.c	2007-02-13 17:17:06.877851000 +0800
@@ -1357,6 +1357,44 @@ composite_0888 (guchar      *src_buf,
     }
 }
 
+#ifdef USE_MEDIALIB
+static void
+composite_0888_medialib (guchar      *src_buf,
+			 gint         src_rowstride,
+			 guchar      *dest_buf,
+			 gint         dest_rowstride,
+			 GdkByteOrder dest_byte_order,
+			 gint         width,
+			 gint         height)
+{
+  guchar *src  = src_buf;
+  guchar *dest = dest_buf;
+
+  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);
+}
+#endif
+
 static void
 composite_565 (guchar      *src_buf,
 	       gint         src_rowstride,
@@ -1554,7 +1592,16 @@ gdk_drawable_real_draw_pixbuf (GdkDrawab
 		   visual->red_mask   == 0xff0000 &&
 		   visual->green_mask == 0x00ff00 &&
 		   visual->blue_mask  == 0x0000ff)
-	    composite_func = composite_0888;
+	    {
+#ifdef USE_MEDIALIB
+	      if (_gdk_use_medialib ())
+	        composite_func = composite_0888_medialib;
+	      else
+	        composite_func = composite_0888;
+#else
+	      composite_func = composite_0888;
+#endif
+	    }
 	}
 
       /* We can't use our composite func if we are required to dither
--- /tmp/gdkrgb.c	2007-02-13 17:15:46.432731274 +0800
+++ gtk+-2.10.9/gdk/gdkrgb.c	2007-02-13 17:13:49.035957000 +0800
@@ -2161,6 +2161,29 @@ gdk_rgb_convert_0888 (GdkRgbInfo *image_
     }
 }
 
+#ifdef USE_MEDIALIB25
+/* convert 24-bit packed to 32-bit unpacked */
+static void
+gdk_rgb_convert_0888_medialib (GdkRgbInfo *image_info, GdkImage *image,
+			       gint x0, gint y0, gint width, gint height,
+			       guchar *buf, int rowstride,
+			       gint x_align, gint y_align, GdkRgbCmap *cmap)
+{
+  int y, w;
+  guchar *obuf, *p;
+  gint bpl;
+  guchar *bptr, *bp2;
+
+  bptr = buf;
+  bpl = image->bpl;
+  obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
+
+  mlib_VideoColorRGBint_to_BGRAint (obuf, bptr, NULL, 0xff,
+                                    width, height, bpl, 
+                                    rowstride, 0);
+}
+#endif
+
 static void
 gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image,
 			 gint x0, gint y0, gint width, gint height,
@@ -3134,7 +3157,17 @@ gdk_rgb_select_conv (GdkRgbInfo *image_i
 	   (depth == 24 || depth == 32) &&
 	   vtype == GDK_VISUAL_TRUE_COLOR &&
 	   (mask_rgb && byte_order == GDK_LSB_FIRST))
-    conv = gdk_rgb_convert_0888;
+    {
+#ifdef USE_MEDIALIB25
+      if (_gdk_use_medialib ())
+        conv = gdk_rgb_convert_0888_medialib;
+      else
+        conv = gdk_rgb_convert_0888;
+#else
+      conv = gdk_rgb_convert_0888;
+#endif
+    }
+  
 #if G_BYTE_ORDER == G_BIG_ENDIAN
   else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
 	   (mask_bgr && byte_order == GDK_MSB_FIRST))
@@ -3151,7 +3184,16 @@ gdk_rgb_select_conv (GdkRgbInfo *image_i
     conv = gdk_rgb_convert_8880_br;
   else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR &&
 	   (mask_rgb && byte_order == GDK_LSB_FIRST))
-    conv = gdk_rgb_convert_0888;
+    {
+#ifdef USE_MEDIALIB25
+      if (_gdk_use_medialib ())
+        conv = gdk_rgb_convert_0888_medialib;
+      else
+        conv = gdk_rgb_convert_0888;
+#else
+      conv = gdk_rgb_convert_0888;
+#endif
+    }
 #endif
   else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST)
     {
