Bye bye Xprint. b=326716 r+sr=dbaron
authormats.palmgren@bredband.net
Wed, 13 Jun 2007 11:02:58 -0700
changeset 2356 ba33067773a5a0b763fe70e76e6624e041687d54
parent 2355 48e0f10ad99f38fe954d992b53a84587631318d2
child 2357 23051e1358751a604c0b9380663d391ceb5a716f
push idunknown
push userunknown
push dateunknown
bugs326716
milestone1.9a6pre
Bye bye Xprint. b=326716 r+sr=dbaron
allmakefiles.sh
build/unix/run-mozilla.sh
config/autoconf.mk.in
config/static-config.mk
configure.in
dom/locales/en-US/chrome/layout/printing.properties
embedding/config/basebrowser-qnx
embedding/config/basebrowser-unix
embedding/config/minimo-qnx
embedding/config/minimo-unix
gfx/public/nsIDeviceContext.h
gfx/src/Makefile.in
gfx/src/gtk/Makefile.in
gfx/src/gtk/nsDeviceContextGTK.cpp
gfx/src/nsDeviceContext.cpp
gfx/src/ps/nsDeviceContextPS.cpp
gfx/src/xlibrgb/Makefile.in
gfx/src/xlibrgb/xlibrgb.c
gfx/src/xlibrgb/xlibrgb.h
gfx/src/xlibrgb/xlibrgb.pkg
gfx/src/xprint/Makefile.in
gfx/src/xprint/nsDeviceContextXP.cpp
gfx/src/xprint/nsDeviceContextXP.h
gfx/src/xprint/nsGfxFactoryXP.cpp
gfx/src/xprint/nsGfxXPrintCID.h
gfx/src/xprint/nsIDeviceContextSpecXPrint.h
gfx/src/xprint/nsIDeviceContextXPrint.h
gfx/src/xprint/nsRenderingContextXp.cpp
gfx/src/xprint/nsRenderingContextXp.h
gfx/src/xprint/nsXPrintContext.cpp
gfx/src/xprint/nsXPrintContext.h
gfx/src/xprint/xprint.pkg
gfx/src/xprintutil/Makefile.in
gfx/src/xprintutil/xprintutil.c
gfx/src/xprintutil/xprintutil.h
gfx/src/xprintutil/xprintutil_printtofile.c
layout/printing/nsPrintEngine.cpp
modules/libpref/src/init/all.js
toolkit/components/printing/content/printPreviewBindings.xml
toolkit/library/Makefile.in
toolkit/library/libxul-config.mk
toolkit/library/nsStaticXULComponents.cpp
widget/src/gtk2/nsDeviceContextSpecG.cpp
widget/src/gtk2/nsDeviceContextSpecG.h
widget/src/os2/nsDeviceContextSpecOS2.cpp
widget/src/os2/nsDeviceContextSpecOS2.h
xpfe/communicator/resources/content/printPreviewBindings.xml
xpinstall/packager/packages-unix
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -156,17 +156,16 @@ gfx/public/Makefile
 gfx/src/Makefile
 gfx/src/beos/Makefile
 gfx/src/gtk/Makefile
 gfx/src/ps/Makefile
 gfx/src/psshared/Makefile
 gfx/src/photon/Makefile
 gfx/src/mac/Makefile
 gfx/src/os2/Makefile
-gfx/src/xlibrgb/Makefile
 gfx/src/windows/Makefile
 gfx/src/thebes/Makefile
 gfx/tests/Makefile
 "
 
 if [ "$MOZ_TREE_CAIRO" ] ; then
 MAKEFILES_gfx="$MAKEFILES_gfx
 gfx/cairo/Makefile
--- a/build/unix/run-mozilla.sh
+++ b/build/unix/run-mozilla.sh
@@ -386,26 +386,16 @@ ADDON_PATH=${MOZ_DIST_BIN}${ADDON_PATH+"
 #
 ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
 if [ "$XSUNTRANSPORT" = "" ]
 then 
         XSUNTRANSPORT="shmem" 
         XSUNSMESIZE="512"
         export XSUNTRANSPORT XSUNSMESIZE
 fi
-## Populate XPSERVERLIST if it was not set yet
-if [ "$XPSERVERLIST" = "" ]
-then
-    if [ -f /etc/init.d/xprint ] ; then
-        XPSERVERLIST="`/bin/sh /etc/init.d/xprint get_xpserverlist`"
-        if [ "$XPSERVERLIST" != "" ] ; then
-            export XPSERVERLIST
-        fi
-    fi
-fi
 
 if [ "$moz_debug" -eq 1 ]
 then
   echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
   echo "  LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
   if [ -n "$LD_LIBRARYN32_PATH" ]
   then
   	echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
@@ -418,19 +408,16 @@ then
   	echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
   fi
   if [ -n "$DISPLAY" ]; then
        echo "DISPLAY=$DISPLAY"
   fi
   if [ -n "$FONTCONFIG_PATH" ]; then
 	echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
   fi
-  if [ -n "$XPSERVERLIST" ]; then
-       echo "XPSERVERLIST=$XPSERVERLIST"
-  fi
   if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
        echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
   fi
   echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
   echo "     LIBRARY_PATH=$LIBRARY_PATH"
   echo "       SHLIB_PATH=$SHLIB_PATH"
   echo "          LIBPATH=$LIBPATH"
   echo "       ADDON_PATH=$ADDON_PATH"
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -463,20 +463,16 @@ MOZ_ENABLE_XREMOTE	= @MOZ_ENABLE_XREMOTE
 
 MOZ_GTK2_CFLAGS		= @MOZ_GTK2_CFLAGS@
 MOZ_GTK2_LIBS		= @MOZ_GTK2_LIBS@
 
 MOZ_DBUS_GLIB_CFLAGS    = @MOZ_DBUS_GLIB_CFLAGS@
 MOZ_DBUS_GLIB_LIBS      = @MOZ_DBUS_GLIB_LIBS@
 MOZ_ENABLE_DBUS         = @MOZ_ENABLE_DBUS@
 
-MOZ_XPRINT_CFLAGS	= @MOZ_XPRINT_CFLAGS@
-MOZ_XPRINT_LDFLAGS	= @MOZ_XPRINT_LDFLAGS@
-MOZ_ENABLE_XPRINT	= @MOZ_ENABLE_XPRINT@
-
 MOZ_ENABLE_FREETYPE2   = @MOZ_ENABLE_FREETYPE2@
 FT2_CFLAGS             = @FT2_CFLAGS@
 FT2_LIBS               = @FT2_LIBS@
 
 MOZ_ENABLE_XFT		= @MOZ_ENABLE_XFT@
 MOZ_XFT_CFLAGS		= @MOZ_XFT_CFLAGS@
 MOZ_XFT_LIBS		= @MOZ_XFT_LIBS@
 MOZ_ENABLE_COREXFONTS	= @MOZ_ENABLE_COREXFONTS@
--- a/config/static-config.mk
+++ b/config/static-config.mk
@@ -92,20 +92,16 @@ STATIC_EXTRA_LIBS	+= $(MOZ_CAIRO_LIBS)
 endif
 endif
 endif
 
 ifneq  (,$(MOZ_ENABLE_GTK2))
 STATIC_EXTRA_LIBS	+= $(XLDFLAGS) $(XT_LIBS)
 endif
 
-ifdef MOZ_ENABLE_XPRINT
-STATIC_EXTRA_LIBS	+= $(MOZ_XPRINT_LDFLAGS)
-endif
-
 ifdef MOZ_ENABLE_XFT
 STATIC_EXTRA_LIBS	+= $(MOZ_XFT_LIBS)
 endif
 
 ifdef MOZ_ENABLE_PANGO
 STATIC_EXTRA_LIBS	+= $(MOZ_PANGO_LIBS)
 endif
 
--- a/configure.in
+++ b/configure.in
@@ -4830,37 +4830,16 @@ dnl ====================================
 dnl = PostScript print module
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(postscript,
 [  --disable-postscript    Disable PostScript printing support ],
     MOZ_ENABLE_POSTSCRIPT=,
     MOZ_ENABLE_POSTSCRIPT=1 )
 
 dnl ========================================================
-dnl = Xprint print module
-dnl ========================================================
-if test "$MOZ_X11"
-then
-    _SAVE_LDFLAGS="$LDFLAGS"
-    LDFLAGS="$XLDFLAGS $LDFLAGS"
-    AC_CHECK_LIB(Xp, XpGetPrinterList, [XPRINT_LIBS="-lXp"],
-        MOZ_ENABLE_XPRINT=, $XEXT_LIBS $XLIBS)
-    LDFLAGS="$_SAVE_LDFLAGS"
-
-    MOZ_XPRINT_CFLAGS="$X_CFLAGS"
-    MOZ_XPRINT_LDFLAGS="$XLDFLAGS $XPRINT_LIBS"
-    MOZ_XPRINT_LDFLAGS="$MOZ_XPRINT_LDFLAGS $XEXT_LIBS $X11_LIBS"
-
-    MOZ_ARG_DISABLE_BOOL(xprint,
-    [  --disable-xprint        Disable Xprint printing support ],
-        MOZ_ENABLE_XPRINT=,
-        MOZ_ENABLE_XPRINT=1 )
-fi
-
-dnl ========================================================
 dnl = GnomeVFS support module
 dnl ========================================================
 
 if test "$MOZ_X11"
 then
     dnl build the gnomevfs extension by default only when the
     dnl GTK2 toolkit is in use.
     if test "$MOZ_ENABLE_GTK2"
@@ -5004,18 +4983,17 @@ dnl ====================================
 dnl = Setting MOZ_EXTRA_X11CONVERTERS turns on additional 
 dnl = converters in intl/uconv that are used only by X11 gfx 
 dnl = implementations. By default, it's undefined so that 
 dnl = those converters are not built on other platforms/toolkits. 
 dnl = (see bug 180851)
 dnl ========================================================
 
 if test "$MOZ_ENABLE_GTK2" \
-&& test "$MOZ_ENABLE_COREXFONTS" \
-|| test "$MOZ_ENABLE_XPRINT" 
+&& test "$MOZ_ENABLE_COREXFONTS"
 then
     AC_DEFINE(MOZ_EXTRA_X11CONVERTERS)
     MOZ_EXTRA_X11CONVERTERS=1
 fi
 AC_SUBST(MOZ_EXTRA_X11CONVERTERS)
 
 dnl ========================================================
 dnl = Build Personal Security Manager
@@ -7415,19 +7393,16 @@ AC_SUBST(JAR)
 
 AC_SUBST(MOZ_PROFILESHARING)
 AC_SUBST(MOZ_PROFILELOCKING)
 
 AC_SUBST(MOZ_IPCD)
 
 AC_SUBST(HAVE_XIE)
 AC_SUBST(MOZ_XIE_LIBS)
-AC_SUBST(MOZ_XPRINT_CFLAGS)
-AC_SUBST(MOZ_XPRINT_LDFLAGS)
-AC_SUBST(MOZ_ENABLE_XPRINT)
 AC_SUBST(MOZ_ENABLE_POSTSCRIPT)
 
 AC_SUBST(XPCOM_USE_LEA)
 AC_SUBST(BUILD_STATIC_LIBS)
 AC_SUBST(MOZ_ENABLE_LIBXUL)
 AC_SUBST(ENABLE_TESTS)
 AC_SUBST(IBMBIDI)
 AC_SUBST(SUNCTL)
--- a/dom/locales/en-US/chrome/layout/printing.properties
+++ b/dom/locales/en-US/chrome/layout/printing.properties
@@ -83,23 +83,21 @@ NS_ERROR_GFX_PRINTER_ENDDOC=Printing fai
 NS_ERROR_GFX_PRINTER_STARTPAGE=Printing failed when starting the page.
 NS_ERROR_GFX_PRINTER_ENDPAGE=Printing failed when completing the page.
 NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW=You cannot print while in print preview.
 NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED=There was a problem printing because the paper size you specified is not supported by your printer.
 NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED=There was a problem printing because the page orientation you specified is not supported by your printer.
 NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED=There was a problem printing because the print job requires color capabilities that your printer does not support.
 NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES=There was a problem printing because you requested too many copies.
 NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR=There was a problem printing. The printer driver is not properly configured.
-NS_ERROR_GFX_PRINTER_XPRINT_BROKEN_XPRT=A broken version of the X print server (Xprt) has been detected. Note that printing using this Xprt server may not work properly. Please contact the server vendor for a fixed version.
 NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP=The browser cannot print preview right now.\nPlease try again when the page has finished loading.
 NS_ERROR_GFX_PRINTER_DOC_WAS_DESTORYED=The page was replaced while you were trying to print.\nPlease try again.
 NS_ERROR_GFX_NO_PRINTDIALOG_IN_TOOLKIT=Either pluggable dialogs were not properly installed\nOr this GFX Toolkit no longer supports native Print Dialogs
 NS_ERROR_GFX_NO_PRINTROMPTSERVICE=The Printing Prompt Service is missing.
 NS_ERROR_GFX_PRINTER_NO_XUL=We are unable to Print or Print Preview this page.
-NS_ERROR_GFX_PRINTER_XPRINT_NO_XPRINT_SERVERS_FOUND=There was a problem printing. No Xprint server(s) could be found.\nCheck whether the XPSERVERLIST environment variable contains any valid Xprint servers.\nFor further information see http://xprint.mozdev.org/ or http://www.mozilla.org/projects/xprint/
 NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED=There was a problem printing because the plex mode you specified is not supported by your printer.
 NS_ERROR_GFX_PRINTER_DOC_IS_BUSY=The browser cannot print the document while it is being loaded.
 NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED=Printing is not implemented.
 NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE=The requested print module cannot be loaded.
 NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED=There was a problem printing because the resolution/quality mode you specified is not supported by your printer.
 
 # No printers available
 noprinter=No printers available.
--- a/embedding/config/basebrowser-qnx
+++ b/embedding/config/basebrowser-qnx
@@ -42,20 +42,18 @@ components/xpcom_obsolete.xpt
 components/libxpconnect.so
 components/xpconnect.xpt
 
 ; 
 ; XP widgets/graphics
 ; 
 
 libgkgfx.so 
-libxlibrgb.so
 libgfxpsshar.so
 components/libgfxps.so
-components/libgfxxprint.so
 components/gfx.xpt 
 components/widget.xpt
 
 ;
 ; qnx photon widget and gfx modules
 ;
 components/libwidget_photon.so
 components/libgfx_photon.so
--- a/embedding/config/basebrowser-unix
+++ b/embedding/config/basebrowser-unix
@@ -44,21 +44,19 @@ components/xpconnect.xpt
 
 ; 
 ; XP widgets/graphics
 ; 
 
 libgkgfx.so 
 libgtksuperwin.so 
 libgtkembedmoz.so 
-libxlibrgb.so
 libgfxpsshar.so
 components/libgfx_gtk.so
 components/libgfxps.so
-components/libgfxxprint.so
 components/gfx.xpt 
 components/libwidget_gtk.so
 components/libwidget_gtk2.so
 components/widget.xpt
 
 ; layout
 libmoz_art_lgpl.so
 res/dtd/xhtml11.dtd
--- a/embedding/config/minimo-qnx
+++ b/embedding/config/minimo-qnx
@@ -34,20 +34,18 @@ components/xpcom_xpti.xpt
 components/libxpconnect.so
 components/xpconnect.xpt
 
 ; 
 ; XP widgets/graphics
 ; 
 
 libgkgfx.so 
-libxlibrgb.so
 libgfxpsshar.so
 components/libgfxps.so
-components/libgfxxprint.so
 components/gfx.xpt 
 components/widget.xpt
 
 ;
 ; qnx photon widget and gfx modules
 ;
 components/libwidget_photon.so
 components/libgfx_photon.so
--- a/embedding/config/minimo-unix
+++ b/embedding/config/minimo-unix
@@ -36,21 +36,19 @@ components/xpconnect.xpt
 
 ; 
 ; XP widgets/graphics
 ; 
 
 libgkgfx.so 
 libgtksuperwin.so 
 libgtkembedmoz.so 
-libxlibrgb.so
 libgfxpsshar.so
 components/libgfx_gtk.so
 components/libgfxps.so
-components/libgfxxprint.so
 components/gfx.xpt 
 components/libwidget_gtk.so
 components/libwidget_gtk2.so
 components/widget.xpt
 
 ; layout
 libmoz_art_lgpl.so
 res/dtd/xhtml11.dtd
--- a/gfx/public/nsIDeviceContext.h
+++ b/gfx/public/nsIDeviceContext.h
@@ -119,52 +119,46 @@ typedef void * nsNativeDeviceContext;
 #define NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED \
   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+21)
 /* too many copies requested */
 #define NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES \
   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+22)
 /* driver configuration error */
 #define NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR \
   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+23)
-/* Xprint module specific: Xprt server broken */
-#define NS_ERROR_GFX_PRINTER_XPRINT_BROKEN_XPRT \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+24)
 /* The document is still being loaded, can't Print Preview */
 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+25)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+24)
 /* The document was asked to be destroyed while we were preparing printing */
 #define NS_ERROR_GFX_PRINTER_DOC_WAS_DESTORYED \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+26)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+25)
 /* Cannot Print or Print Preview XUL Documents */
 #define NS_ERROR_GFX_PRINTER_NO_XUL \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+27)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+26)
 /* The toolkit no longer supports the Print Dialog (for embedders) */
 #define NS_ERROR_GFX_NO_PRINTDIALOG_IN_TOOLKIT \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+28)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+27)
 /* The was wasn't any Print Prompt service registered (this shouldn't happen) */
 #define NS_ERROR_GFX_NO_PRINTROMPTSERVICE \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+29)
-/* Xprint module specific: No Xprint servers found */
-#define NS_ERROR_GFX_PRINTER_XPRINT_NO_XPRINT_SERVERS_FOUND \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+30)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+28)
 /* requested plex mode not supported by printer */
 #define NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+31)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+29)
 /* The document is still being loaded */
 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+32)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+30)
 /* Printing is not implemented */
 #define NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+33)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+31)
 /* Cannot load the matching print module */
 #define NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+34)   
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+32)   
 /* requested resolution/quality mode not supported by printer */
 #define NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED \
-  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+35)
+  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+33)
       
 /**
  * Conts need for Print Preview
  */
 #ifdef NS_PRINT_PREVIEW
 const PRUint8 kUseAltDCFor_NONE            = 0x00; // Do not use the AltDC for anything
 const PRUint8 kUseAltDCFor_FONTMETRICS     = 0x01; // Use it for only getting the font metrics
 const PRUint8 kUseAltDCFor_CREATERC_REFLOW = 0x02; // Use when creating RenderingContexts for Reflow
--- a/gfx/src/Makefile.in
+++ b/gfx/src/Makefile.in
@@ -69,25 +69,16 @@ endif
 
 ifdef MOZ_ENABLE_POSTSCRIPT
 DIRS        += psshared
 ifndef MOZ_ENABLE_CAIRO_GFX
 DIRS        += ps
 endif
 endif
 
-# Build xlibrgb only for X toolkits and/or Xprint
-ifneq (,$(MOZ_ENABLE_XPRINT))
-DIRS        += xlibrgb
-endif
-
-ifdef MOZ_ENABLE_XPRINT
-DIRS        += xprintutil xprint 
-endif
-
 ifdef MOZ_ENABLE_CAIRO_GFX
 DIRS        += thebes
 else
  ifdef MOZ_ENABLE_GTK2
  DIRS        += gtk
  endif
  ifdef MOZ_ENABLE_PHOTON
  DIRS        += photon
--- a/gfx/src/gtk/Makefile.in
+++ b/gfx/src/gtk/Makefile.in
@@ -63,21 +63,17 @@ REQUIRES	= xpcom \
 		  necko \
 		  $(NULL)
 
 # Sun's Complex Text Layout support
 ifdef SUNCTL
 REQUIRES	+= ctl
 endif
 
-ifdef MOZ_ENABLE_XPRINT
-REQUIRES	+= xprintutil
-endif
-
-# Code shared between GTK+, Xlib and Xprint gfx modules
+# Code used by the GTK+ gfx module
 X11SHARED_LCPPSRCS = \
 		nsAntiAliasedGlyph.cpp \
 		nsX11AlphaBlend.cpp \
 		nsXFontAAScaledBitmap.cpp \
 		nsXFontNormal.cpp \
 		$(NULL)
 
 ifdef MOZ_ENABLE_FREETYPE2
@@ -184,37 +180,24 @@ DEFINES		+= -DGENERIC_MOTIF_REDEFINES
 OS_CXXFLAGS	+= -Wc,warn=disa=NOSIMPINT 
 endif
 
 ifdef MOZ_ENABLE_POSTSCRIPT
 DEFINES         += -DUSE_POSTSCRIPT
 EXTRA_DSO_LDOPTS += -lgfxpsshar
 endif
 
-ifdef MOZ_ENABLE_XPRINT
-DEFINES         += -DUSE_XPRINT -DUSE_MOZILLA_TYPES
-EXTRA_DSO_LDOPTS += \
-		-lxprintutil \
-		$(MOZ_XPRINT_LDFLAGS)
-endif
-
 LOCAL_INCLUDES	= \
 		-I../.. \
 		-I$(srcdir)/. \
 		-I$(srcdir)/.. \
 		-I$(srcdir)/../shared \
 		-I$(srcdir)/../x11shared \
 		$(MOZ_XFT_CFLAGS) \
 		$(NULL)
 
 ifdef MOZ_ENABLE_FREETYPE2
 INCLUDES        += $(FT2_CFLAGS)
 LOCAL_INCLUDES        += -I$(srcdir)/../freetype
 endif
 
-ifdef MOZ_ENABLE_XPRINT
-export:: $(addprefix $(srcdir)/../xprint/,$(XPU_LCSRCS)) $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS))
-	$(INSTALL) $^ .
-else
 export:: $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS))
 	$(INSTALL) $^ .
-endif
-
--- a/gfx/src/gtk/nsDeviceContextGTK.cpp
+++ b/gfx/src/gtk/nsDeviceContextGTK.cpp
@@ -46,20 +46,16 @@
 
 #include "nsDeviceContextGTK.h"
 #include "nsGfxCIID.h"
 
 #ifdef USE_POSTSCRIPT
 #include "nsGfxPSCID.h"
 #include "nsIDeviceContextPS.h"
 #endif /* USE_POSTSCRIPT */
-#ifdef USE_XPRINT
-#include "nsGfxXPrintCID.h"
-#include "nsIDeviceContextXPrint.h"
-#endif /* USE_XPRINT */
 
 #include "nsFontMetricsUtils.h"
 
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 
 #ifdef MOZ_WIDGET_GTK2
 #include <pango/pango.h>
@@ -469,39 +465,16 @@ NS_IMETHODIMP nsDeviceContextGTK::GetDev
   PrintMethod              method;
 
   nsDeviceContextSpecGTK  *spec = NS_STATIC_CAST(nsDeviceContextSpecGTK *, aDevice);
   
   rv = spec->GetPrintMethod(method);
   if (NS_FAILED(rv)) 
     return rv;
 
-#ifdef USE_XPRINT
-  if (method == pmXprint) { // XPRINT
-    static NS_DEFINE_CID(kCDeviceContextXp, NS_DEVICECONTEXTXP_CID);
-    nsCOMPtr<nsIDeviceContextXp> dcxp(do_CreateInstance(kCDeviceContextXp, &rv));
-    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create Xp Device context.");    
-    if (NS_FAILED(rv)) 
-      return NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE;
-    
-    rv = dcxp->SetSpec(aDevice);
-    if (NS_FAILED(rv)) 
-      return rv;
-    
-    rv = dcxp->InitDeviceContextXP((nsIDeviceContext*)aContext,
-                                   (nsIDeviceContext*)this);
-    if (NS_FAILED(rv)) 
-      return rv;
-      
-    rv = dcxp->QueryInterface(NS_GET_IID(nsIDeviceContext),
-                              (void **)&aContext);
-    return rv;
-  }
-  else
-#endif /* USE_XPRINT */
 #endif
 #ifdef USE_POSTSCRIPT
 //  if (method == pmPostScript) // PostScript
   {
 
     // default/PS
     static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
   
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -554,17 +554,17 @@ nsFontCache::GetMetricsFor(const nsFont&
     NS_ADDREF(aMetrics);
     return NS_OK;
   }
 
   NS_POSTCONDITION(NS_SUCCEEDED(rv), "font metrics should not be null - bug 136248");
   return rv;
 }
 
-/* PostScript and Xprint module may override this method to create 
+/* PostScript module may override this method to create 
  * nsIFontMetrics objects with their own classes 
  */
 nsresult
 nsFontCache::CreateFontMetricsInstance(nsIFontMetrics** fm)
 {
   static NS_DEFINE_CID(kFontMetricsCID, NS_FONT_METRICS_CID);
   return CallCreateInstance(kFontMetricsCID, fm);
 }
--- a/gfx/src/ps/nsDeviceContextPS.cpp
+++ b/gfx/src/ps/nsDeviceContextPS.cpp
@@ -35,20 +35,20 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "gfx-config.h"
  
-/* PostScript/Xprint print modules do not support more than one object
+/* PostScript print module do not support more than one object
  * instance because they use global vars which cannot be shared between
  * multiple instances...
- * bug 119491 ("Cleanup global vars in PostScript and Xprint modules) will fix
+ * bug 119491 ("Cleanup global vars in PostScript module) will fix
  * that...
  */
 #define WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS 1
 
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #define PR_LOGGING 1
 #include "prlog.h"
 
deleted file mode 100644
--- a/gfx/src/xlibrgb/Makefile.in
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE		= xlibrgb
-LIBRARY_NAME	= xlibrgb
-EXPORT_LIBRARY = 1
-GRE_MODULE	= 1
-LIBXUL_LIBRARY = 1
-
-PACKAGE_FILE = xlibrgb.pkg
-
-CSRCS		= xlibrgb.c
-
-EXPORTS		= xlibrgb.h
-
-EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS)
-
-REQUIRES	= xpcom
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES		+= -DUSE_MOZILLA_TYPES -D_IMPL_XLIBRGB_API
-
-INCLUDES	+= $(TK_CFLAGS)
-
deleted file mode 100644
--- a/gfx/src/xlibrgb/xlibrgb.c
+++ /dev/null
@@ -1,4137 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org Code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * This code is derived from GdkRgb.
- * For more information on GdkRgb, see http://www.levien.com/gdkrgb/
- * Raph Levien <raph@acm.org>
- */
-
-/* Ported by Christopher Blizzard to Xlib.  With permission from the
- * original authors and the copyright holders of this file, the
- * contents of this file are also redistributable under the terms of
- * the Mozilla Public license.  For information about the Mozilla
- * Public License, please see the license information at
- * http://www.mozilla.org/MPL/ */
-
-/* This code is copyright the following authors:
- * Raph Levien          <raph@acm.org>
- * Manish Singh         <manish@gtk.org>
- * Tim Janik            <timj@gtk.org>
- * Peter Mattis         <petm@xcf.berkeley.edu>
- * Spencer Kimball      <spencer@xcf.berkeley.edu>
- * Josh MacDonald       <jmacd@xcf.berkeley.edu>
- * Christopher Blizzard <blizzard@redhat.com>
- * Owen Taylor          <otaylor@redhat.com>
- * Shawn T. Amundson    <amundson@gtk.org>
- * Roland Mainz         <roland.mainz@informatik.med.uni-giessen.de>
- */
-
-#include <math.h>
-
-#if HAVE_CONFIG_H
-#  include <config.h>
-#  if STDC_HEADERS
-#    include <stdio.h>
-#    include <stdlib.h>
-#    include <string.h>
-#  endif
-#else
-#  include <stdio.h>
-#  include <stdlib.h>
-#endif /* HAVE_CONFIG_H */
-
-#define ENABLE_GRAYSCALE
-
-#define G_LITTLE_ENDIAN 1
-#define G_BIG_ENDIAN    2
-
-/* include this before so that we can get endian definitions if
-   they are there... */
-
-#include "xlibrgb.h"
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <X11/extensions/XShm.h>
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-
-/* check our endianness */
-#ifdef USE_MOZILLA_TYPES
-
-/* check to make sure that we don't have both types defined. */
-#ifdef IS_LITTLE_ENDIAN
-#ifdef IS_BIG_ENDIAN
-#error what the hell?  both endian types are defined!
-#endif
-#endif
-
-#ifdef IS_LITTLE_ENDIAN
-#define G_BYTE_ORDER G_LITTLE_ENDIAN
-#else
-#define G_BYTE_ORDER G_BIG_ENDIAN
-#endif /* IS_LITTLE_ENDIAN */
-
-#else
-
-/* XXX fix this for an autodetect for endian-ness */
-#define G_BYTE_ORDER G_LITTLE_ENDIAN
-
-#endif /* USE_MOZILLA_TYPES */
-
-#ifndef MIN
-#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
-#endif
-
-#ifndef MAX
-#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
-#endif
-
-typedef enum {
-  LSB_FIRST,
-  MSB_FIRST
-} ByteOrder;
-
-static void xxlib_deregister_handle_by_handle(XlibRgbHandle *handle);
-
-typedef void (*XlibRgbConvFunc) (XlibRgbHandle *handle,
-                                 XImage *image,
-                                 int ax, int ay,
-                                 int width, int height,
-                                 unsigned char *buf, int rowstride,
-                                 int x_align, int y_align,
-                                 XlibRgbCmap *cmap);
-
-#define IMAGE_WIDTH 256
-#define STAGE_ROWSTRIDE (IMAGE_WIDTH * 3)
-#define IMAGE_HEIGHT 128
-#define N_IMAGES 6
-
-/* Some of these fields should go, as they're not being used at all.
-   Globals should generally migrate into here - it's very likely that
-   we'll want to run more than one GdkRgbInfo context at the same time
-   (i.e. some but not all windows have privately installed
-   colormaps). */
-
-struct _XlibRgbHandle
-{
-  Display          *display;
-  Screen           *screen;
-  int               screen_num;
-  XVisualInfo      *x_visual_info;
-  Colormap          cmap;
-  Visual           *default_visualid;
-  Colormap          default_colormap;
-
-  unsigned long    *color_pixels;
-  unsigned long    *gray_pixels;
-  unsigned long    *reserved_pixels;
-
-  unsigned long     red_shift;
-  unsigned long     red_prec;
-  unsigned long     blue_shift;
-  unsigned long     blue_prec;
-  unsigned long     green_shift;
-  unsigned long     green_prec;
-
-  unsigned int      nred_shades;
-  unsigned int      ngreen_shades;
-  unsigned int      nblue_shades;
-  unsigned int      ngray_shades;
-  unsigned int      nreserved;
-
-  unsigned int      bpp; /* bytes per pixel */
-  unsigned int      cmap_alloced;
-  double            gamma_val;
-
-  /* Generally, the stage buffer is used to convert 32bit RGB, gray,
-     and indexed images into 24 bit packed RGB. */
-  unsigned char *stage_buf;
-
-  XlibRgbCmap *gray_cmap;
-
-  Bool dith_default;
-
-  Bool bitmap; /* set true if in 1 bit per pixel mode */
-  GC own_gc;
-
-  /* Convert functions */
-  XlibRgbConvFunc conv;
-  XlibRgbConvFunc conv_d;
-
-  XlibRgbConvFunc conv_32;
-  XlibRgbConvFunc conv_32_d;
-
-  XlibRgbConvFunc conv_gray;
-  XlibRgbConvFunc conv_gray_d;
-
-  XlibRgbConvFunc conv_indexed;
-  XlibRgbConvFunc conv_indexed_d;
-
-  /* misc */
-  Bool            xlib_rgb_install_cmap; /* default: FALSE */
-  Bool            xlib_rgb_verbose;      /* default: FALSE */
-  XImage         *static_image[N_IMAGES];
-  int             static_image_idx;
-  char           *static_buffer;
-  
-  uint32         *DM_565;
-
-  unsigned char  *colorcube;
-  unsigned char  *colorcube_d;
- 
-  int             xlib_rgb_min_colors;
-
-  /* image tiling code... */
-  Bool            disallow_image_tiling; /* default: FALSE */
-  int             horiz_idx;
-  int             horiz_y;
-  int             vert_idx;
-  int             vert_x;
-  int             tile_idx;
-  int             tile_x;
-  int             tile_y1;
-  int             tile_y2;
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-  Bool            xlib_use_shm;
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-  long            max_request_size;
-};
-
-static XImage *
-xxlib_normal_ximage(XlibRgbHandle *handle)
-{
-  XImage *ximage;
-
-  if (handle->bitmap) {
-    ximage = XCreateImage(handle->display,
-                          handle->x_visual_info->visual,
-                          1,
-                          XYBitmap,
-                          0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
-                          8,
-                          0);
-  }
-  else 
-  {  
-    ximage = XCreateImage(handle->display,
-                          handle->x_visual_info->visual,
-                          (unsigned int)handle->x_visual_info->depth,
-                          ZPixmap,
-                          0, 0,
-                          IMAGE_WIDTH,
-                          IMAGE_HEIGHT,
-                          32, 0);
-  }
-
-  if (!ximage)
-    return NULL;
-    
-  ximage->data = malloc(ximage->height * ximage->bytes_per_line);
-  if (!ximage->data)
-  {
-    XDestroyImage(ximage);
-    return NULL;
-  }
-  
-  ximage->bitmap_bit_order = MSBFirst;
-  ximage->byte_order = MSBFirst;
-    
-  return ximage;
-}
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-static XImage *
-xshm_image_new(XlibRgbHandle *handle)
-{
-  XShmSegmentInfo *shm_info;
-  XImage          *ximage;
-    
-  shm_info = calloc(1, sizeof(XShmSegmentInfo));
-  if (!shm_info)
-    return NULL;
-    
-  shm_info->readOnly = True;
-
-  if (handle->bitmap)
-  {
-    ximage = XShmCreateImage(handle->display,
-                             handle->x_visual_info->visual,
-                             1,
-                             XYBitmap, NULL, shm_info, IMAGE_WIDTH, IMAGE_HEIGHT);
-  }
-  else
-  {
-    ximage = XShmCreateImage(handle->display,
-                             handle->x_visual_info->visual,
-                             (unsigned int)handle->x_visual_info->depth,
-                             ZPixmap, NULL, shm_info, IMAGE_WIDTH, IMAGE_HEIGHT);
-  }
-
-  /* most likely shm extension is not loaded */
-  if (!ximage)
-  {
-    free(shm_info);
-    return NULL;
-  }
-
-  /* allocate a shm chunk of desired size... */
-  shm_info->shmid = shmget(IPC_PRIVATE,
-                           ximage->height * ximage->bytes_per_line,
-                           IPC_CREAT | 0777);
-
-  /* image is probably > SHMMAX */
-  if (shm_info->shmid == -1)
-  {
-    XDestroyImage(ximage);
-    free(shm_info);
-    return NULL;
-  }
-
-  /* find out where in memory it was placed */
-  shm_info->shmaddr = shmat(shm_info->shmid, NULL, 0);
-
-  if (shm_info->shmaddr == (void *)-1) {
-    XDestroyImage(ximage);
-    shmctl(shm_info->shmid, IPC_RMID, NULL);
-    free(shm_info);
-    return NULL;
-  }
-
-  /* image data in shared memory */
-  ximage->data = shm_info->shmaddr;
-  XShmAttach(handle->display, shm_info);
-  XSync(handle->display, False);
-
-  /* set the shm segment as deleted so that it's deleted automatically */
-  shmctl(shm_info->shmid, IPC_RMID, NULL);
-  
-  return ximage;
-}
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-
-static void
-xxlib_image_put(XlibRgbHandle *handle,
-               Drawable drawable, GC gc,
-               XImage *image,
-               int xsrc, int ysrc,
-               int xdest, int ydest,
-               int width, int height)
-{
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-  if (handle->xlib_use_shm)
-  {
-    XShmPutImage(handle->display, drawable,
-                 gc, image,
-                 xsrc, ysrc, xdest, ydest, width, height, False);
-  }  
-  else
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */  
-  {
-    XPutImage(handle->display, drawable, gc, image,
-              xsrc, ysrc, xdest, ydest,
-              (unsigned int)width, (unsigned int)height);
-  }
-}
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-static void
-xshm_image_check(XlibRgbHandle *handle, XlibRgbArgs *args)
-{
-  int dummy; 
-  
-  handle->xlib_use_shm = False;
-
-  if(!args->disallow_mit_shmem)
-    /* XlibRGB MIT-SHM support requires the image tiling hack */
-    if(!args->disallow_image_tiling)
-      if (getenv("MOZILLA_XXLIBRGB_DISABLE_MIT_SHM") == NULL)
-        if (XShmQueryExtension(handle->display))
-          if (XShmQueryVersion(handle->display,
-                               &dummy, &dummy, &dummy) == True)
-            handle->xlib_use_shm = True;
-}
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-
-unsigned long
-xxlib_get_prec_from_mask(unsigned long val)
-{
-  unsigned long retval = 0;
-  unsigned int cur_bit = 0;
-  /* walk through the number, incrementing the value if
-     the bit in question is set. */
-  while (cur_bit < (sizeof(unsigned long) * 8)) {
-    if ((val >> cur_bit) & 0x1) {
-      retval++;
-    }
-    cur_bit++;
-  }
-  return retval;
-}
-
-unsigned long
-xxlib_get_shift_from_mask(unsigned long val)
-{
-  unsigned long cur_bit = 0;
-  /* walk through the number, looking for the first 1 */
-  while (cur_bit < (sizeof(unsigned long) * 8)) {
-    if ((val >> cur_bit) & 0x1) {
-      return cur_bit;
-    }
-    cur_bit++;
-  }
-  return cur_bit;
-}
-
-
-static int
-xxlib_rgb_cmap_fail (XlibRgbHandle *handle, const char *msg, Colormap cmap, unsigned long *pixels)
-{
-  unsigned long free_pixels[256];
-  int n_free;
-  int i;
-
-#ifdef VERBOSE
-  printf ("%s", msg);
-#endif
-  n_free = 0;
-  for (i = 0; i < 256; i++)
-    if (pixels[i] < 256)
-      free_pixels[n_free++] = pixels[i];
-  
-  if (n_free)
-    XFreeColors(handle->display,
-                cmap,
-                free_pixels,
-                n_free,
-                0);
-  return 0;
-}
-
-static void
-xxlib_rgb_make_colorcube (XlibRgbHandle *handle, unsigned long *pixels, int nr, int ng, int nb)
-{
-  unsigned char rt[16], gt[16], bt[16];
-  int i;
-
-  handle->colorcube = calloc(4096, 1);
-  for (i = 0; i < 16; i++)
-  {
-    rt[i] = ng * nb * ((i * 17 * (nr - 1) + 128) >> 8);
-    gt[i] = nb * ((i * 17 * (ng - 1) + 128) >> 8);
-    bt[i] = ((i * 17 * (nb - 1) + 128) >> 8);
-  }
-
-  for (i = 0; i < 4096; i++)
-  {
-    handle->colorcube[i] = pixels[rt[i >> 8] + gt[(i >> 4) & 0x0f] + bt[i & 0x0f]];
-#ifdef VERBOSE
-    printf ("%03x %02x %x %x %x\n", i, handle->colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
-#endif
-  }
-}
-
-/* this is the colorcube suitable for dithering */
-static void
-xxlib_rgb_make_colorcube_d (XlibRgbHandle *handle, unsigned long *pixels, int nr, int ng, int nb)
-{
-  int r, g, b;
-  int i;
-
-  handle->colorcube_d = calloc(512, 1);
-  for (i = 0; i < 512; i++)
-  {
-    r = MIN (nr - 1, i >> 6);
-    g = MIN (ng - 1, (i >> 3) & 7);
-    b = MIN (nb - 1, i & 7);
-    handle->colorcube_d[i] = pixels[(r * ng + g) * nb + b];
-  }
-}
-
-/* Try installing a color cube of the specified size.
-   Make the colorcube and return TRUE on success */
-static int
-xxlib_rgb_try_colormap (XlibRgbHandle *handle, int nr, int ng, int nb)
-{
-  int r, g, b;
-  int ri, gi, bi;
-  int r0, g0, b0;
-  Colormap     cmap;
-  XVisualInfo *visual;
-  XColor      *colors = NULL;
-  XColor       color;
-  unsigned long pixels[256];
-  unsigned long junk[256];
-  int i;
-  int d2;
-  unsigned int colors_needed;
-  int idx;
-  int best[256];
-
-  if (nr * ng * nb < handle->xlib_rgb_min_colors)
-    return FALSE;
-
-  if (handle->cmap_alloced) {
-    cmap = handle->cmap;
-    visual = handle->x_visual_info;
-  }
-  else {
-    cmap = handle->default_colormap;
-    visual = handle->x_visual_info;
-  }
-  colors_needed = nr * ng * nb;
-  for (i = 0; i < 256; i++)
-  {
-    best[i] = 192;
-    pixels[i] = 256;
-  }
-
-#ifndef GAMMA
-  if (!handle->xlib_rgb_install_cmap) {
-    /* go out and get the colors for this colormap. */
-    colors = malloc(sizeof(XColor) * visual->colormap_size);
-    for (i=0; i < visual->colormap_size; i++){
-      colors[i].pixel = i;
-    }
-    XQueryColors (handle->display,
-                  cmap,
-                  colors, visual->colormap_size);
-    /* find color cube colors that are already present */
-    for (i = 0; i < MIN (256, visual->colormap_size); i++)
-    {
-      r = colors[i].red >> 8;
-      g = colors[i].green >> 8;
-      b = colors[i].blue >> 8;
-      ri = (r * (nr - 1) + 128) >> 8;
-      gi = (g * (ng - 1) + 128) >> 8;
-      bi = (b * (nb - 1) + 128) >> 8;
-      r0 = ri * 255 / (nr - 1);
-      g0 = gi * 255 / (ng - 1);
-      b0 = bi * 255 / (nb - 1);
-      idx = ((ri * nr) + gi) * nb + bi;
-      d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0);
-      if (d2 < best[idx]) 
-      {
-        if (pixels[idx] < 256)
-        XFreeColors(handle->display,
-                    cmap,
-                    pixels + idx,
-                    1, 0);
-        else
-          colors_needed--;
-        color.pixel = colors[i].pixel;
-        color.red = colors[i].red;
-        color.green = colors[i].green;
-        color.blue = colors[i].blue;
-        color.flags = 0;
-        if (!XAllocColor(handle->display, cmap, &color))
-          return xxlib_rgb_cmap_fail (handle, "error allocating system color\n",
-        cmap, pixels);
-        pixels[idx] = color.pixel; /* which is almost certainly i */
-        best[idx] = d2;
-      }
-    }
-  }
-
-#endif /* !GAMMA */
-
-  if (colors_needed)
-  {
-    if (!XAllocColorCells(handle->display, cmap, 0, NULL, 0, junk, colors_needed))
-    {
-      char tmp_str[80];
-      
-      sprintf (tmp_str,
-               "%d %d %d colormap failed (in XAllocColorCells)\n",
-               nr, ng, nb);
-      return xxlib_rgb_cmap_fail (handle, tmp_str, cmap, pixels);
-    }
-    XFreeColors(handle->display, cmap, junk, (int)colors_needed, 0);
-  }
-
-  for (r = 0, i = 0; r < nr; r++)
-    for (g = 0; g < ng; g++)
-      for (b = 0; b < nb; b++, i++)
-      {
-        if (pixels[i] == 256)
-          {
-            color.red = r * 65535 / (nr - 1);
-            color.green = g * 65535 / (ng - 1);
-            color.blue = b * 65535 / (nb - 1);
-
-#ifdef GAMMA
-            color.red = 65535 * pow (color.red / 65535.0, 0.5);
-            color.green = 65535 * pow (color.green / 65535.0, 0.5);
-            color.blue = 65535 * pow (color.blue / 65535.0, 0.5);
-#endif /* GAMMA */
-
-            /* This should be a raw XAllocColor call */
-            if (!XAllocColor(handle->display, cmap, &color))
-            {
-              char tmp_str[80];
-
-              sprintf (tmp_str, "%d %d %d colormap failed\n",
-                       nr, ng, nb);
-              return xxlib_rgb_cmap_fail (handle, tmp_str,
-                                          cmap, pixels);
-            }
-            pixels[i] = color.pixel;
-          }
-#ifdef VERBOSE
-          printf ("%d: %lx\n", i, pixels[i]);
-#endif /* VERBOSE */
-        }
-
-  handle->nred_shades = nr;
-  handle->ngreen_shades = ng;
-  handle->nblue_shades = nb;
-  xxlib_rgb_make_colorcube (handle, pixels, nr, ng, nb);
-  xxlib_rgb_make_colorcube_d (handle, pixels, nr, ng, nb);
-  if (colors)
-    free(colors);
-  return TRUE;
-}
-
-/* Return TRUE on success. */
-static Bool
-xxlib_rgb_do_colormaps (XlibRgbHandle *handle)
-{
-  static const int sizes[][3] = 
-  {
-    /*    { 6, 7, 6 }, */
-    { 6, 6, 6 }, 
-    { 6, 6, 5 }, 
-    { 6, 6, 4 }, 
-    { 5, 5, 5 }, 
-    { 5, 5, 4 }, 
-    { 4, 4, 4 }, 
-    { 4, 4, 3 }, 
-    { 3, 3, 3 }, 
-    { 2, 2, 2 }
-  };
-  static const int n_sizes = sizeof(sizes) / (3 * sizeof(int));
-  int i;
-  
-  for (i = 0; i < n_sizes; i++)
-    if (xxlib_rgb_try_colormap (handle, sizes[i][0], sizes[i][1], sizes[i][2]))
-      return TRUE;
-  return FALSE;
-}
-
-/* Make a 2 x 2 x 2 colorcube */
-static void
-xxlib_rgb_colorcube_222 (XlibRgbHandle *handle)
-{
-  int i;
-  XColor color;
-  Colormap cmap;
-
-  if (handle->cmap_alloced)
-    cmap = handle->cmap;
-  else
-    cmap = handle->default_colormap;
-
-  handle->colorcube_d = malloc(sizeof(unsigned char) * 512);
-
-  for (i = 0; i < 8; i++)
-  {
-    color.red = ((i & 4) >> 2) * 65535;
-    color.green = ((i & 2) >> 1) * 65535;
-    color.blue = (i & 1) * 65535;
-    XAllocColor (handle->display, cmap, &color);
-    handle->colorcube_d[((i & 4) << 4) | ((i & 2) << 2) | (i & 1)] = color.pixel;
-  }
-}
-
-/* Make a 6 x 7 x 6 colorcube */
-static void
-xxlib_rgb_colorcube_676 (XlibRgbHandle *handle)
-{
-  int i = 0;
-  XColor color;
-  Colormap cmap;
-  int r, g, b, r_max, g_max, b_max;
-  unsigned long pixels[256];
-  
-  r_max = 6;
-  g_max = 7;
-  b_max = 6;
-
-  if (handle->cmap_alloced)
-    cmap = handle->cmap;
-  else
-    cmap = handle->default_colormap;
-
-  for (r = 0; r < r_max; r++)
-  {
-    for (g = 0; g < g_max; g++)
-    {
-      for (b = 0; b < b_max; b++)
-      {        
-        color.red   = r * 65535 / (r_max-1);
-        color.green = g * 65535 / (g_max-1);
-        color.blue  = b * 65535 / (b_max-1);
-        XAllocColor (handle->display, cmap, &color);
-        pixels[i++] = color.pixel;
-      }
-    }
-  }    
-      
-  handle->nred_shades   = r_max;
-  handle->ngreen_shades = g_max;
-  handle->nblue_shades  = b_max;
-  xxlib_rgb_make_colorcube   (handle, pixels, r_max, g_max, b_max);
-  xxlib_rgb_make_colorcube_d (handle, pixels, r_max, g_max, b_max);      
-}
-
-void
-xxlib_rgb_set_verbose (XlibRgbHandle *handle, Bool verbose)
-{
-  handle->xlib_rgb_verbose = verbose;
-}
-
-void
-xxlib_rgb_set_min_colors (XlibRgbHandle *handle, int min_colors)
-{
-  handle->xlib_rgb_min_colors = min_colors;
-}
-
-/* Return a "score" based on the following criteria (in hex):
-
-   x000 is the quality - 1 is 1bpp, 2 is 4bpp,
-                         4 is 8bpp,
-                         7 is 15bpp truecolor, 8 is 16bpp truecolor,
-                         9 is 24bpp truecolor.
-   0x00 is the speed - 1 is the normal case,
-                       2 means faster than normal
-   00x0 gets a point for being the system visual
-   000x gets a point for being pseudocolor
-
-   A caveat: in the 8bpp modes, being the system visual seems to be
-   quite important. Thus, all of the 8bpp modes should be ranked at
-   the same speed.
-*/
-
-static uint32
-xxlib_rgb_score_visual (XlibRgbHandle *handle, XVisualInfo *visual)
-{
-  uint32 quality, speed, pseudo, sys;
-#ifdef DEBUG
-  static const char* visual_names[] =
-  {
-    "static gray",
-    "grayscale",
-    "static color",
-    "pseudo color",
-    "true color",
-    "direct color",
-  };
-#endif /* DEBUG */
-  
-  quality = 0;
-  speed = 1;
-  sys = 0;
-  if (visual->class == TrueColor ||
-      visual->class == DirectColor)
-  {
-    if (visual->depth == 24)
-    {
-      quality = 9;
-      /* Should test for MSB visual here, and set speed if so. */
-    }
-    else if (visual->depth == 16)
-      quality = 8;
-    else if (visual->depth == 15)
-      quality = 7;
-    else if (visual->depth == 8)
-      quality = 4;
-    }
-    else if (visual->class == PseudoColor ||
-           visual->class == StaticColor)
-    {
-      if (visual->depth == 8)
-        quality = 4;
-      else if (visual->depth == 4)
-        quality = 2;
-      else if (visual->depth == 1)
-        quality = 1;
-    }
-  else if (visual->class == StaticGray
-#ifdef ENABLE_GRAYSCALE
-           || visual->class == GrayScale
-#endif /* ENABLE_GRAYSCALE */
-           )
-    {
-      if (visual->depth == 8)
-        quality = 4;
-      else if (visual->depth == 4)
-        quality = 2;
-      else if (visual->depth == 1)
-        quality = 1;
-    }
-
-  if (quality == 0)
-    return 0;
-
-  sys = (visual->visualid == handle->default_visualid->visualid);
-  
-  pseudo = (visual->class == PseudoColor || visual->class == TrueColor);
-
-#ifdef DEBUG
-  if (handle->xlib_rgb_verbose)
-    printf ("Visual 0x%x, type = %s, depth = %d, %ld:%ld:%ld%s; score=%x\n",
-            (int)visual->visualid,
-            visual_names[visual->class],
-            visual->depth,
-            visual->red_mask,
-            visual->green_mask,
-            visual->blue_mask,
-            sys ? " (system)" : "",
-            (quality << 12) | (speed << 8) | (sys << 4) | pseudo);
-#endif /* DEBUG */
-  return (quality << 12) | (speed << 8) | (sys << 4) | pseudo;
-}
-
-static Bool
-xxlib_rgb_choose_visual (XlibRgbHandle *handle, XVisualInfo *xtemplate, long xtemplate_mask)
-{
-  XVisualInfo *visuals;
-  XVisualInfo *visual;
-  XVisualInfo *best_visual;
-  XVisualInfo *final_visual;
-  int num_visuals;
-  uint32 score, best_score;
-  int cur_visual = 1;
-  int i;
-   
-  xtemplate_mask |= VisualScreenMask;
-  xtemplate->screen = handle->screen_num;
-  visuals = XGetVisualInfo(handle->display, xtemplate_mask,
-                           xtemplate, &num_visuals);
-  if (!visuals)
-    return False;
-    
-  best_visual = visuals;
-  best_score = xxlib_rgb_score_visual (handle, best_visual);
-
-  for (i = cur_visual; i < num_visuals; i++)
-  {
-    visual = &visuals[i];
-    score = xxlib_rgb_score_visual (handle, visual);
-    if (score > best_score)
-    {
-      best_score = score;
-      best_visual = visual;
-    }
-  }
-  /* make a copy of the visual so that we can free
-   * the allocated visual list above. */
-  final_visual = malloc(sizeof(XVisualInfo));
-  memcpy(final_visual, best_visual, sizeof(XVisualInfo));
-  handle->x_visual_info = final_visual;
-  XFree(visuals);
-  
-  return True;
-}
-
-static void xxlib_rgb_select_conv (XlibRgbHandle *handle, XImage *image, ByteOrder byte_order);
-
-static void
-xxlib_rgb_set_gray_cmap (XlibRgbHandle *handle, Colormap cmap)
-{
-  int i;
-  XColor color;
-  int status;
-  unsigned long pixels[256];
-  int r, g, b, gray;
-
-  for (i = 0; i < 256; i++)
-  {
-    color.pixel = i;
-    color.red   = i * 257;
-    color.green = i * 257;
-    color.blue  = i * 257;
-    status = XAllocColor(handle->display, cmap, &color);
-    pixels[i] = color.pixel;
-#ifdef VERBOSE
-    printf ("allocating pixel %d, %x %x %x, result %d\n",
-            color.pixel, color.red, color.green, color.blue, status);
-#endif /* VERBOSE */
-  }
-
-  /* Now, we make fake colorcubes - we ultimately just use the pseudocolor
-     methods. */
-
-  handle->colorcube = handle->colorcube_d = malloc(sizeof(unsigned char) * 4096);
-
-  for (i = 0; i < 4096; i++)
-  {
-    r = (i >> 4) & 0xf0;
-    r = r | r >> 4;
-    g = i & 0xf0;
-    g = g | g >> 4;
-    b = (i << 4 & 0xf0);
-    b = b | b >> 4;
-    gray = (g + ((r + b) >> 1)) >> 1;
-    handle->colorcube[i] = handle->colorcube_d[i] = pixels[gray];
-  }
-}
-
-void
-xxlib_rgb_destroy_handle (XlibRgbHandle *handle)
-{
-  int i;
-
-  for( i = 0 ; i < N_IMAGES ; i++ )
-  {
-    if (handle->static_image[i])
-      XDestroyImage(handle->static_image[i]);
-  }
-  
-  if (handle->cmap_alloced)
-  {
-    XFreeColormap(handle->display, handle->cmap);
-  }
-  
-  if (handle->own_gc)
-    XFreeGC(handle->display, handle->own_gc);
-  
-  if (handle->colorcube)
-    free(handle->colorcube);
-
-  if (handle->colorcube_d && (handle->colorcube_d != handle->colorcube))
-    free(handle->colorcube_d);
-  
-  if (handle->DM_565)
-    free(handle->DM_565);
-  
-  if (handle->stage_buf)
-    free(handle->stage_buf);
-
-  xxlib_deregister_handle_by_handle(handle);
-  
-#ifdef DEBUG
-    /* force crash if someone tries to touch the handle... */
-    memset(handle, 0, sizeof(XlibRgbHandle));
-#endif  
-            
-  /* done... */
-  free(handle); 
-}
-
-/* Create a XlibRgbHandle object
- * It is possible to register the handle automagically with a |name|.
- * Handle names must be unique, but it is possible to register a handle 
- * with more than one name via |xxlib_register_handle()|.
- */                     
-XlibRgbHandle *
-xxlib_rgb_create_handle(Display *display, Screen *screen,
-                        XlibRgbArgs *args)
-{
-  XlibRgbHandle *handle = NULL;
-  int i;
-  static const int byte_order[1] = { 1 };
-
-#ifdef DEBUG
-  printf("xxlib_rgb_create_handle: pseudogray=%d, install_colormap=%d, "
-         "disallow_image_tiling=%d, disallow_mit_shmem=%d, verbose=%d\n",
-         (int)args->pseudogray,
-         (int)args->install_colormap,
-         (int)args->disallow_image_tiling,
-         (int)args->disallow_mit_shmem,
-         (int)args->verbose);
-#endif /* DEBUG */
-
-  /* check endian sanity */
-#if G_BYTE_ORDER == G_BIG_ENDIAN
-  if (((char *)byte_order)[0] == 1) {
-    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "
-             "compiled for big endian, but this is a little endian machine.\n\n");
-    abort();
-  }
-#else
-  if (((char *)byte_order)[0] != 1) {
-    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "
-             "compiled for little endian, but this is a big endian machine.\n\n");
-    abort();
-  }
-#endif /* G_BYTE_ORDER == G_BIG_ENDIAN */
-
-#ifndef XLIBRGB_MIT_SHM_SUPPORT_HAS_BEEN_FIXED
-    /* We still have issues with MIT_SHM support on LSB platforms... ;-( */
-    args->disallow_mit_shmem = True;
-#endif /* XLIBRGB_MIT_SHM_SUPPORT_HAS_BEEN_FIXED */    
-       
-    if (!(handle = malloc(sizeof(XlibRgbHandle))))
-      return NULL;      
-    memset(handle, 0, sizeof(XlibRgbHandle));
-
-    /* should we register this handle ? */
-    if (args->handle_name)
-    {
-      if (!xxlib_register_handle(args->handle_name, handle))
-      {
-#ifdef DEBUG
-        puts("xxlib_rgb_create_handle: cannot register handle");
-#endif /* DEBUG */      
-        free(handle);
-        return NULL;
-      }  
-    }
-    
-    /* Emulate StaticGray via PseudoColor visual ? */
-    if (args->pseudogray)
-    {
-      args->xtemplate.class = PseudoColor;
-      args->xtemplate.depth = 8;
-      args->xtemplate_mask |= VisualClassMask|VisualDepthMask;
-    } 
-        
-    handle->display = display;
-    handle->screen = screen;
-    handle->screen_num = XScreenNumberOfScreen(screen);
-    handle->x_visual_info = NULL;
-    handle->cmap = None;
-    handle->default_visualid = XDefaultVisual(display, handle->screen_num);
-    handle->default_colormap = XDefaultColormap(display, handle->screen_num);
-    handle->max_request_size = XMaxRequestSize(display);
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-    xshm_image_check(handle, args);
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-    handle->disallow_image_tiling  = args->disallow_image_tiling;
-    handle->xlib_rgb_install_cmap  = args->install_colormap;
-    
-    handle->color_pixels = NULL;
-    handle->gray_pixels = NULL;
-    handle->reserved_pixels = NULL;
-
-    handle->nred_shades = 6;
-    handle->ngreen_shades = 6;
-    handle->nblue_shades = 4;
-    handle->ngray_shades = 24;
-    handle->nreserved = 0;
-
-    handle->bpp = 0;
-    handle->cmap_alloced = False;
-    handle->gamma_val = 1.0;
-
-    handle->stage_buf = NULL;
-
-    handle->own_gc = None;
-    
-    handle->red_shift = 0;
-    handle->red_prec = 0;
-    handle->green_shift = 0;
-    handle->green_prec = 0;
-    handle->blue_shift = 0;
-    handle->blue_prec = 0;
-
-    handle->xlib_rgb_min_colors = 5 * 5 * 5;
-
-    handle->horiz_y = IMAGE_HEIGHT;
-    handle->vert_x  = IMAGE_WIDTH;
-    handle->tile_x  = IMAGE_WIDTH;
-    handle->tile_y1 = IMAGE_HEIGHT;
-    handle->tile_y2 = IMAGE_HEIGHT;  
-
-    if (!xxlib_rgb_choose_visual (handle, &args->xtemplate, args->xtemplate_mask))
-    {
-#ifdef DEBUG
-      puts("xxlib_rgb_choose_visual failure");
-#endif /* DEBUG */
-      xxlib_rgb_destroy_handle(handle);
-      return NULL;
-    }
-
-    handle->bitmap = (handle->x_visual_info->depth == 1);
-      
-    /* set up the shift and the precision for the red, green and blue.
-       this only applies to cool visuals like true color and direct color. */
-    if (handle->x_visual_info->class == TrueColor ||
-        handle->x_visual_info->class == DirectColor) {
-      handle->red_shift   = xxlib_get_shift_from_mask(handle->x_visual_info->red_mask);
-      handle->red_prec    = xxlib_get_prec_from_mask(handle->x_visual_info->red_mask);
-      handle->green_shift = xxlib_get_shift_from_mask(handle->x_visual_info->green_mask);
-      handle->green_prec  = xxlib_get_prec_from_mask(handle->x_visual_info->green_mask);
-      handle->blue_shift  = xxlib_get_shift_from_mask(handle->x_visual_info->blue_mask);
-      handle->blue_prec   = xxlib_get_prec_from_mask(handle->x_visual_info->blue_mask);
-    }
-    
-    if (args->pseudogray)
-    {
-      if (handle->xlib_rgb_install_cmap)
-      {
-        handle->cmap = XCreateColormap(handle->display,
-                                       XRootWindow(handle->display, handle->screen_num),
-                                       handle->x_visual_info->visual,
-                                       AllocNone);
-        xxlib_rgb_set_gray_cmap (handle, handle->cmap);
-        handle->cmap_alloced = TRUE;
-      }
-      else
-      {
-        handle->cmap = handle->default_colormap;
-        xxlib_rgb_set_gray_cmap (handle, handle->cmap);
-      }  
-    }
-    else if ((handle->x_visual_info->class == PseudoColor ||
-           handle->x_visual_info->class == StaticColor) &&
-           handle->x_visual_info->depth < 8 &&
-           handle->x_visual_info->depth >= 3)
-    {
-      handle->cmap = handle->default_colormap;
-      xxlib_rgb_colorcube_222 (handle);
-    }
-    else if (handle->x_visual_info->class == StaticColor)
-    {
-      handle->cmap = XCreateColormap(handle->display,
-                                     XRootWindow(handle->display, handle->screen_num),
-                                     handle->x_visual_info->visual,
-                                     AllocNone);
-      handle->cmap_alloced = TRUE;
-      xxlib_rgb_colorcube_676(handle);
-    }
-    else if (handle->x_visual_info->class == PseudoColor)
-    {
-      if (handle->xlib_rgb_install_cmap ||
-          handle->x_visual_info->visualid != handle->default_visualid->visualid)
-      {
-        handle->cmap = XCreateColormap(handle->display,
-                                       XRootWindow(handle->display, handle->screen_num),
-                                       handle->x_visual_info->visual,
-                                       AllocNone);
-        handle->cmap_alloced = TRUE;
-      }
-      
-      if (!xxlib_rgb_do_colormaps (handle))
-      {
-        handle->cmap = XCreateColormap(handle->display,
-                                       XRootWindow(handle->display, handle->screen_num),
-                                       handle->x_visual_info->visual,
-                                       AllocNone);
-        handle->cmap_alloced = TRUE;
-        xxlib_rgb_do_colormaps (handle);
-      }
-      if (handle->xlib_rgb_verbose)
-        printf ("color cube: %d x %d x %d\n",
-                handle->nred_shades,
-                handle->ngreen_shades,
-                handle->nblue_shades);
-
-      if (!handle->cmap_alloced)
-        handle->cmap = handle->default_colormap;
-     }
-#ifdef ENABLE_GRAYSCALE
-    else if (handle->x_visual_info->class == GrayScale)
-    {
-      handle->cmap = XCreateColormap(handle->display,
-                                     XRootWindow(handle->display, handle->screen_num),
-                                     handle->x_visual_info->visual,
-                                     AllocNone);
-      xxlib_rgb_set_gray_cmap (handle, handle->cmap);
-      handle->cmap_alloced = TRUE;
-    }
-#endif /* ENABLE_GRAYSCALE */
-    else if (handle->x_visual_info->class != DirectColor && 
-             handle->x_visual_info->visualid == handle->default_visualid->visualid)
-    {
-      handle->cmap = handle->default_colormap;
-    }  
-    else
-    {
-      /* Always install colormap in direct color. */
-      handle->cmap = XCreateColormap(handle->display,
-                                     XRootWindow(handle->display, handle->screen_num),
-                                     handle->x_visual_info->visual,
-                                     AllocNone);
-      handle->cmap_alloced = TRUE;
-    }
-
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-    if (handle->xlib_use_shm)
-    {
-      /* try to allocate N_IMAGES shm X images */
-      for (i = 0; i < N_IMAGES; i++)
-      {
-        handle->static_image[i] = xshm_image_new(handle);
-        if (!handle->static_image[i])
-        {
-          handle->xlib_use_shm = False;
-          break;
-        }
-      }
-      
-      /* Failure ? Then clean-up and use the standard method below... */
-      if (!handle->xlib_use_shm)
-      {
-#ifdef DEBUG
-        printf("Failed to set-up MIT-SHMEM after %d images\n", i);
-#endif /* DEBUG */
-        for (i = 0; i < N_IMAGES; i++)
-        {
-          if (handle->static_image[i])
-          {
-            XDestroyImage(handle->static_image[i]);
-            handle->static_image[i] = NULL;
-          }  
-        } 
-      }
-    }  
-
-    /* Allocate "normal" images "*/
-    if (!handle->xlib_use_shm)
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-    {    
-      for (i = 0; i < N_IMAGES; i++) 
-      {
-        handle->static_image[i] = xxlib_normal_ximage(handle);
-      }
-    }  
-
-    /* ok, so apparently, handle->bpp is actually
-     * BYTES per pixel.  What fun! */
-    handle->bpp = (handle->static_image[0]->bits_per_pixel + 7) / 8;
-
-    xxlib_rgb_select_conv (handle, handle->static_image[0], MSB_FIRST);
-    
-    return handle;
-}
-
-/* convert an rgb value into an X pixel code */
-unsigned long
-xxlib_rgb_xpixel_from_rgb (XlibRgbHandle *handle, uint32 rgb)
-{
-  unsigned long pixel = 0;
-
-  if (handle->bitmap)
-  {
-    return ((rgb & 0xff0000) >> 16) +
-           ((rgb & 0xff00) >> 7) +
-            (rgb & 0xff) > 510;
-  }
-  else if (handle->x_visual_info->class == PseudoColor)
-    pixel = handle->colorcube[((rgb & 0xf00000) >> 12) |
-                              ((rgb & 0xf000) >> 8) |
-                              ((rgb & 0xf0) >> 4)];
-  else if (handle->x_visual_info->depth < 8 &&
-           handle->x_visual_info->class == StaticColor)
-  {
-    pixel = handle->colorcube_d[((rgb & 0x800000) >> 17) |
-                                ((rgb & 0x8000) >> 12) |
-                                ((rgb & 0x80) >> 7)];
-  }
-  else if (handle->x_visual_info->class == StaticColor)
-  {
-    pixel = handle->colorcube[((rgb & 0xf00000) >> 12) |
-                              ((rgb & 0xf000) >> 8) |
-                              ((rgb & 0xf0) >> 4)];  
-  }
-  else if (handle->x_visual_info->class == TrueColor ||
-           handle->x_visual_info->class == DirectColor)
-  {
-#ifdef VERBOSE
-    printf ("shift, prec: r %d %d g %d %d b %d %d\n",
-            handle->red_shift,
-            handle->red_prec,
-            handle->green_shift,
-            handle->green_prec,
-            handle->blue_shift,
-            handle->blue_prec);
-#endif
-
-    pixel = (((((rgb & 0xff0000) >> 16) >>
-               (8 - handle->red_prec)) <<
-              handle->red_shift) +
-             ((((rgb & 0xff00) >> 8)  >>
-               (8 - handle->green_prec)) <<
-              handle->green_shift) +
-             (((rgb & 0xff) >>
-               (8 - handle->blue_prec)) <<
-              handle->blue_shift));
-  }
-  else if (handle->x_visual_info->class == StaticGray ||
-           handle->x_visual_info->class == GrayScale)
-  {
-    int gray = ((rgb & 0xff0000) >> 16) +
-               ((rgb & 0xff00) >> 7) +
-                (rgb & 0xff);
-
-    return gray >> (10 - handle->x_visual_info->depth);
-  }
-
-  return pixel;
-}
-
-void
-xxlib_rgb_gc_set_foreground (XlibRgbHandle *handle, GC gc, uint32 rgb)
-{
-  unsigned long color;
-
-  color = xxlib_rgb_xpixel_from_rgb (handle, rgb);
-  XSetForeground(handle->display, gc, color);
-}
-
-void
-xxlib_rgb_gc_set_background (XlibRgbHandle *handle, GC gc, uint32 rgb)
-{
-  unsigned long color;
-
-  color = xxlib_rgb_xpixel_from_rgb (handle, rgb);
-  XSetBackground(handle->display, gc, color);
-}
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define HAIRY_CONVERT_8
-#endif
-
-#ifdef HAIRY_CONVERT_8
-static void
-xxlib_rgb_convert_8 (XlibRgbHandle *handle, XImage *image,
-                   int ax, int ay, int width, int height,
-                   unsigned char *buf, int rowstride,
-                   int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
-        {
-          for (x = 0; x < width; x++)
-            {
-              r = *bp2++;
-              g = *bp2++;
-              b = *bp2++;
-              obptr[0] = handle->colorcube[((r & 0xf0) << 4) |
-                                  (g & 0xf0) |
-                                  (b >> 4)];
-              obptr++;
-            }
-        }
-      else
-        {
-          for (x = 0; x < width - 3; x += 4)
-            {
-              uint32 r1b0g0r0;
-              uint32 g2r2b1g1;
-              uint32 b3g3r3b2;
-
-              r1b0g0r0 = ((uint32 *)bp2)[0];
-              g2r2b1g1 = ((uint32 *)bp2)[1];
-              b3g3r3b2 = ((uint32 *)bp2)[2];
-              ((uint32 *)obptr)[0] =
-                handle->colorcube[((r1b0g0r0 & 0xf0) << 4) | 
-                         ((r1b0g0r0 & 0xf000) >> 8) |
-                         ((r1b0g0r0 & 0xf00000) >> 20)] |
-                (handle->colorcube[((r1b0g0r0 & 0xf0000000) >> 20) |
-                          (g2r2b1g1 & 0xf0) |
-                          ((g2r2b1g1 & 0xf000) >> 12)] << 8) |
-                (handle->colorcube[((g2r2b1g1 & 0xf00000) >> 12) |
-                          ((g2r2b1g1 & 0xf0000000) >> 24) |
-                          ((b3g3r3b2 & 0xf0) >> 4)] << 16) |
-                (handle->colorcube[((b3g3r3b2 & 0xf000) >> 4) |
-                          ((b3g3r3b2 & 0xf00000) >> 16) |
-                          (b3g3r3b2 >> 28)] << 24);
-              bp2 += 12;
-              obptr += 4;
-            }
-          for (; x < width; x++)
-            {
-              r = *bp2++;
-              g = *bp2++;
-              b = *bp2++;
-              obptr[0] = handle->colorcube[((r & 0xf0) << 4) |
-                                  (g & 0xf0) |
-                                  (b >> 4)];
-              obptr++;
-            }
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#else
-static void
-xxlib_rgb_convert_8 (XlibRgbHandle *handle, XImage *image,
-                   int ax, int ay, int width, int height,
-                   unsigned char *buf, int rowstride,
-                   int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          obptr[0] = handle->colorcube[((r & 0xf0) << 4) |
-                              (g & 0xf0) |
-                              (b >> 4)];
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#endif
-
-#if 1
-
-/* This dither table was generated by Raph Levien using patented
-   technology (US Patent 5,276,535). The dither table itself is in the
-   public domain. */
-
-#define DM_WIDTH 128
-#define DM_WIDTH_SHIFT 7
-#define DM_HEIGHT 128
-static const unsigned char DM[128][128] =
-{
-  { 0, 41, 23, 5, 17, 39, 7, 15, 62, 23, 40, 51, 31, 47, 9, 32, 52, 27, 57, 25, 6, 61, 27, 52, 37, 7, 40, 63, 18, 36, 10, 42, 25, 62, 45, 34, 20, 42, 37, 14, 35, 29, 50, 10, 61, 2, 40, 8, 37, 12, 58, 22, 5, 41, 10, 39, 0, 60, 11, 46, 2, 55, 38, 17, 36, 59, 13, 54, 37, 56, 8, 29, 16, 13, 63, 22, 41, 55, 7, 20, 49, 14, 23, 55, 37, 23, 19, 36, 15, 49, 23, 63, 30, 14, 38, 27, 53, 13, 22, 41, 19, 31, 7, 19, 50, 30, 49, 16, 3, 32, 56, 40, 29, 34, 8, 48, 19, 45, 4, 51, 12, 46, 35, 49, 16, 42, 12, 62 },
-  { 30, 57, 36, 54, 47, 34, 52, 27, 43, 4, 28, 7, 17, 36, 62, 13, 44, 7, 18, 48, 33, 21, 44, 14, 30, 47, 12, 33, 5, 55, 31, 58, 13, 30, 4, 17, 52, 10, 60, 26, 46, 0, 39, 27, 42, 22, 47, 25, 60, 32, 9, 38, 48, 17, 59, 30, 49, 18, 34, 25, 51, 19, 5, 48, 21, 8, 28, 46, 1, 32, 41, 19, 54, 47, 37, 18, 28, 11, 44, 30, 39, 56, 2, 33, 8, 42, 61, 28, 58, 8, 46, 9, 41, 4, 58, 7, 21, 48, 59, 10, 52, 14, 42, 57, 12, 25, 7, 53, 42, 24, 11, 50, 17, 59, 42, 2, 36, 60, 32, 17, 63, 29, 21, 7, 59, 32, 24, 39 },
-  { 22, 8, 16, 32, 3, 25, 13, 57, 18, 45, 58, 39, 55, 20, 5, 42, 23, 34, 63, 1, 51, 10, 58, 4, 60, 23, 53, 27, 44, 21, 3, 48, 8, 50, 43, 54, 27, 32, 5, 55, 21, 58, 12, 53, 6, 36, 14, 50, 17, 29, 53, 15, 24, 52, 7, 36, 13, 42, 4, 53, 9, 35, 61, 26, 56, 32, 49, 15, 62, 23, 6, 60, 2, 31, 4, 48, 58, 38, 15, 61, 5, 25, 47, 28, 50, 15, 7, 40, 3, 32, 33, 52, 25, 50, 35, 42, 61, 3, 28, 36, 23, 63, 4, 33, 46, 62, 36, 23, 60, 6, 54, 28, 4, 37, 23, 55, 25, 8, 42, 54, 14, 6, 56, 38, 19, 52, 4, 46 },
-  { 48, 53, 43, 12, 45, 63, 30, 37, 9, 34, 21, 1, 25, 47, 29, 58, 3, 54, 15, 39, 29, 17, 38, 35, 20, 43, 1, 49, 15, 59, 29, 39, 22, 35, 16, 23, 1, 47, 39, 18, 8, 44, 25, 31, 57, 19, 63, 4, 45, 3, 42, 61, 1, 31, 45, 20, 57, 29, 62, 21, 32, 41, 14, 44, 3, 39, 5, 34, 10, 43, 51, 35, 23, 52, 40, 10, 21, 1, 53, 18, 51, 43, 12, 62, 18, 54, 26, 51, 20, 57, 14, 1, 62, 16, 11, 18, 32, 39, 17, 44, 1, 48, 26, 37, 18, 2, 51, 14, 28, 45, 35, 18, 57, 13, 47, 11, 51, 20, 2, 39, 31, 47, 25, 1, 50, 11, 60, 7 },
-  { 18, 28, 1, 56, 21, 10, 51, 2, 46, 54, 14, 61, 11, 50, 13, 38, 19, 31, 45, 9, 55, 24, 47, 5, 54, 9, 62, 11, 35, 8, 51, 14, 57, 6, 63, 40, 58, 14, 51, 28, 62, 34, 15, 48, 1, 41, 30, 35, 55, 21, 34, 11, 49, 37, 8, 52, 4, 23, 15, 43, 1, 58, 11, 23, 53, 16, 55, 26, 58, 18, 27, 12, 45, 14, 25, 63, 42, 33, 27, 35, 9, 31, 21, 38, 1, 44, 34, 12, 48, 38, 21, 44, 29, 47, 26, 53, 1, 46, 54, 8, 59, 29, 11, 55, 22, 41, 33, 20, 39, 1, 48, 9, 44, 32, 5, 62, 29, 44, 57, 23, 10, 58, 34, 43, 15, 37, 26, 33 },
-  { 51, 38, 59, 24, 35, 42, 19, 60, 5, 32, 41, 26, 43, 33, 7, 53, 48, 11, 59, 23, 42, 2, 61, 30, 16, 40, 32, 24, 56, 41, 19, 33, 37, 26, 47, 9, 31, 22, 2, 45, 9, 54, 4, 37, 21, 52, 11, 23, 7, 57, 16, 25, 55, 18, 63, 27, 46, 39, 56, 10, 50, 37, 29, 47, 19, 63, 24, 9, 46, 2, 39, 60, 9, 57, 30, 7, 49, 11, 59, 3, 45, 57, 5, 60, 29, 22, 5, 60, 30, 9, 59, 18, 40, 6, 57, 36, 30, 12, 24, 34, 15, 40, 52, 6, 49, 9, 58, 4, 63, 12, 26, 61, 22, 53, 38, 16, 35, 14, 28, 50, 42, 17, 5, 28, 62, 20, 54, 12 },
-  { 26, 6, 31, 15, 49, 6, 38, 27, 22, 49, 16, 56, 2, 62, 30, 21, 0, 36, 28, 6, 49, 32, 13, 52, 26, 50, 19, 46, 3, 26, 62, 0, 53, 12, 29, 3, 53, 41, 60, 24, 38, 13, 58, 16, 43, 9, 59, 39, 46, 28, 44, 40, 2, 33, 13, 41, 16, 6, 47, 31, 26, 17, 57, 6, 38, 0, 42, 36, 29, 52, 20, 31, 48, 0, 34, 56, 20, 36, 23, 54, 14, 41, 24, 37, 10, 55, 46, 25, 16, 45, 36, 4, 55, 23, 15, 8, 50, 62, 5, 56, 44, 20, 13, 28, 59, 31, 24, 47, 31, 52, 37, 17, 40, 0, 26, 49, 3, 60, 7, 33, 0, 61, 53, 40, 8, 45, 2, 41 },
-  { 16, 63, 43, 4, 61, 24, 56, 13, 53, 8, 36, 12, 24, 41, 16, 46, 60, 26, 52, 39, 14, 57, 21, 37, 0, 45, 7, 59, 38, 17, 43, 10, 45, 20, 61, 43, 19, 11, 33, 17, 50, 32, 23, 61, 28, 49, 26, 0, 18, 51, 5, 60, 22, 58, 29, 0, 59, 34, 19, 62, 3, 52, 7, 44, 30, 59, 13, 50, 15, 62, 7, 17, 38, 22, 44, 15, 40, 4, 47, 28, 33, 17, 49, 16, 51, 40, 10, 56, 0, 53, 13, 49, 28, 38, 60, 21, 43, 19, 37, 27, 3, 51, 34, 39, 0, 45, 15, 43, 10, 21, 3, 55, 8, 33, 59, 10, 41, 18, 52, 24, 46, 20, 30, 13, 58, 22, 36, 57 },
-  { 50, 34, 11, 47, 29, 17, 44, 0, 33, 63, 28, 46, 52, 5, 57, 10, 42, 18, 4, 63, 20, 8, 44, 10, 56, 34, 14, 29, 5, 54, 23, 59, 32, 49, 7, 34, 49, 27, 56, 0, 42, 7, 46, 3, 40, 6, 54, 32, 62, 13, 36, 10, 47, 8, 35, 49, 24, 51, 12, 40, 22, 35, 60, 12, 22, 51, 33, 4, 40, 25, 43, 55, 5, 54, 12, 61, 26, 51, 8, 62, 0, 53, 7, 63, 2, 32, 19, 34, 42, 24, 31, 63, 2, 10, 45, 33, 0, 48, 9, 61, 22, 47, 8, 62, 18, 56, 7, 54, 27, 57, 46, 30, 50, 19, 45, 30, 56, 36, 22, 47, 11, 38, 3, 51, 32, 48, 18, 9 },
-  { 0, 21, 40, 19, 52, 9, 37, 48, 20, 40, 3, 18, 27, 38, 35, 22, 31, 56, 13, 35, 46, 28, 60, 40, 27, 18, 61, 50, 41, 30, 7, 36, 2, 25, 16, 57, 5, 15, 47, 29, 55, 19, 30, 52, 15, 34, 20, 12, 43, 30, 20, 54, 25, 44, 53, 12, 38, 5, 55, 27, 48, 15, 33, 27, 45, 8, 19, 28, 56, 11, 33, 49, 18, 36, 29, 2, 45, 16, 39, 19, 31, 43, 27, 35, 20, 52, 26, 6, 61, 11, 41, 17, 29, 51, 20, 56, 25, 32, 41, 17, 53, 31, 25, 14, 42, 23, 35, 16, 38, 6, 34, 12, 15, 62, 6, 21, 13, 1, 63, 9, 55, 27, 43, 25, 14, 4, 31, 55 },
-  { 44, 29, 61, 2, 35, 58, 26, 15, 60, 10, 51, 59, 14, 55, 8, 50, 2, 44, 25, 51, 1, 33, 16, 4, 48, 36, 2, 21, 12, 57, 48, 13, 51, 55, 40, 28, 37, 62, 8, 39, 12, 63, 36, 10, 59, 24, 56, 47, 9, 50, 41, 1, 32, 17, 6, 21, 61, 30, 9, 43, 1, 54, 41, 2, 54, 37, 48, 61, 1, 46, 21, 3, 58, 24, 50, 32, 60, 10, 57, 25, 46, 12, 59, 4, 45, 13, 57, 47, 27, 39, 5, 58, 47, 14, 35, 4, 52, 13, 60, 6, 36, 10, 45, 55, 4, 50, 29, 2, 61, 50, 25, 58, 44, 24, 36, 42, 54, 28, 40, 32, 16, 56, 6, 62, 46, 39, 60, 23 },
-  { 7, 48, 14, 54, 23, 40, 4, 45, 30, 22, 42, 32, 1, 44, 20, 29, 58, 8, 37, 19, 41, 54, 24, 58, 9, 53, 25, 46, 34, 16, 23, 38, 27, 11, 18, 1, 52, 21, 35, 22, 48, 5, 25, 45, 18, 38, 2, 27, 35, 4, 57, 15, 62, 39, 57, 28, 42, 16, 36, 60, 24, 18, 10, 63, 20, 5, 16, 23, 37, 14, 59, 27, 41, 8, 13, 42, 21, 35, 6, 50, 3, 38, 15, 48, 30, 39, 17, 3, 49, 14, 53, 33, 24, 7, 61, 44, 11, 39, 23, 49, 19, 58, 1, 32, 36, 12, 60, 41, 20, 13, 41, 4, 39, 1, 48, 8, 18, 51, 14, 44, 5, 37, 21, 34, 1, 26, 10, 37 },
-  { 53, 36, 27, 9, 50, 12, 32, 55, 2, 57, 7, 17, 48, 34, 63, 15, 40, 26, 62, 11, 49, 6, 31, 39, 22, 42, 6, 63, 1, 39, 60, 4, 42, 61, 32, 45, 24, 44, 2, 60, 16, 41, 53, 1, 33, 61, 49, 17, 63, 23, 45, 26, 33, 3, 23, 46, 2, 50, 20, 4, 45, 34, 49, 30, 39, 58, 44, 31, 53, 34, 6, 52, 30, 47, 63, 1, 53, 22, 42, 31, 58, 23, 54, 22, 61, 8, 36, 59, 22, 35, 21, 1, 55, 40, 27, 16, 30, 54, 2, 29, 43, 16, 39, 63, 21, 46, 26, 10, 48, 32, 19, 53, 30, 56, 26, 60, 33, 4, 61, 23, 49, 59, 15, 53, 19, 58, 42, 16 },
-  { 20, 5, 59, 46, 25, 62, 7, 19, 43, 25, 37, 61, 11, 24, 4, 54, 12, 52, 3, 32, 17, 61, 12, 47, 15, 55, 18, 31, 53, 28, 9, 50, 21, 6, 55, 9, 58, 14, 54, 26, 33, 7, 31, 58, 13, 21, 8, 42, 29, 6, 37, 11, 48, 52, 14, 60, 11, 39, 56, 32, 14, 58, 7, 26, 17, 4, 42, 8, 11, 47, 19, 38, 10, 17, 26, 37, 9, 55, 28, 13, 18, 40, 6, 33, 1, 43, 25, 11, 51, 7, 62, 43, 18, 37, 3, 57, 45, 9, 38, 58, 5, 52, 27, 7, 17, 53, 5, 57, 37, 2, 63, 9, 22, 15, 11, 38, 25, 45, 35, 0, 28, 10, 41, 30, 50, 8, 31, 57 },
-  { 49, 33, 16, 38, 1, 42, 51, 34, 53, 14, 28, 49, 30, 56, 36, 23, 43, 20, 38, 56, 22, 45, 28, 0, 62, 35, 26, 44, 11, 19, 52, 35, 44, 15, 30, 38, 10, 31, 40, 4, 46, 50, 20, 40, 27, 44, 51, 14, 56, 53, 19, 59, 7, 29, 41, 19, 35, 25, 8, 52, 22, 44, 13, 53, 50, 32, 61, 24, 56, 25, 63, 0, 45, 57, 33, 59, 16, 46, 4, 62, 50, 11, 60, 37, 52, 19, 55, 29, 37, 46, 13, 26, 48, 10, 50, 34, 21, 63, 26, 13, 42, 33, 22, 55, 35, 28, 43, 15, 24, 51, 27, 34, 46, 49, 58, 3, 52, 9, 57, 19, 48, 55, 3, 35, 12, 45, 24, 3 },
-  { 41, 11, 56, 28, 18, 31, 22, 10, 37, 6, 47, 13, 3, 41, 9, 46, 0, 48, 29, 6, 34, 10, 55, 37, 20, 8, 49, 3, 41, 59, 14, 25, 0, 63, 19, 47, 27, 51, 17, 57, 23, 10, 61, 6, 54, 3, 38, 31, 0, 22, 34, 43, 20, 55, 31, 0, 49, 63, 29, 38, 3, 62, 28, 40, 0, 22, 14, 35, 2, 48, 15, 43, 23, 14, 3, 29, 49, 20, 39, 34, 0, 44, 29, 9, 15, 47, 5, 42, 0, 31, 58, 5, 31, 61, 23, 15, 0, 47, 19, 50, 24, 3, 59, 11, 44, 0, 31, 59, 6, 42, 17, 60, 0, 39, 20, 31, 43, 17, 29, 40, 12, 25, 60, 22, 52, 15, 63, 29 },
-  { 20, 52, 8, 44, 62, 4, 59, 49, 17, 63, 21, 39, 60, 18, 52, 27, 33, 59, 14, 51, 59, 43, 24, 5, 51, 30, 57, 17, 32, 5, 37, 56, 48, 34, 42, 3, 60, 5, 36, 13, 43, 37, 18, 34, 25, 12, 59, 24, 47, 36, 11, 50, 3, 38, 9, 58, 16, 5, 43, 18, 47, 10, 37, 18, 59, 46, 29, 52, 40, 12, 34, 28, 56, 36, 53, 7, 43, 8, 24, 52, 26, 17, 56, 43, 24, 32, 63, 20, 57, 16, 22, 52, 36, 8, 41, 56, 29, 32, 54, 7, 35, 57, 14, 48, 20, 62, 13, 39, 53, 29, 8, 45, 13, 29, 7, 61, 14, 54, 6, 63, 38, 32, 18, 43, 2, 39, 6, 47 },
-  { 0, 58, 23, 35, 13, 46, 12, 39, 0, 31, 55, 24, 5, 35, 15, 61, 17, 5, 39, 25, 18, 2, 50, 33, 41, 13, 39, 23, 62, 46, 29, 12, 22, 8, 56, 25, 20, 49, 32, 62, 0, 56, 11, 46, 63, 42, 9, 16, 55, 5, 60, 15, 62, 26, 45, 21, 36, 51, 13, 57, 31, 24, 55, 6, 35, 9, 57, 5, 20, 60, 7, 51, 5, 19, 40, 25, 61, 32, 56, 12, 36, 48, 21, 2, 58, 12, 39, 28, 9, 50, 40, 12, 44, 18, 25, 49, 6, 38, 11, 62, 18, 46, 30, 9, 40, 25, 49, 19, 10, 36, 55, 22, 33, 52, 41, 18, 37, 27, 49, 21, 2, 46, 7, 53, 33, 61, 27, 35 },
-  { 41, 31, 5, 39, 51, 26, 33, 57, 27, 41, 9, 44, 54, 29, 48, 7, 44, 36, 57, 10, 31, 63, 16, 45, 11, 60, 1, 47, 7, 20, 43, 3, 58, 36, 13, 52, 39, 7, 15, 28, 22, 48, 30, 21, 1, 29, 49, 44, 27, 17, 40, 30, 24, 42, 12, 53, 33, 7, 47, 20, 1, 42, 11, 49, 25, 43, 17, 32, 45, 27, 41, 21, 31, 62, 11, 49, 2, 15, 42, 5, 63, 7, 41, 27, 49, 6, 54, 23, 46, 34, 2, 28, 54, 3, 59, 12, 46, 17, 42, 28, 40, 1, 37, 51, 5, 55, 2, 34, 47, 16, 3, 62, 47, 5, 23, 56, 1, 44, 12, 34, 51, 16, 57, 11, 25, 17, 54, 13 },
-  { 60, 26, 55, 18, 3, 60, 20, 6, 52, 15, 50, 19, 32, 11, 23, 53, 26, 21, 1, 47, 42, 27, 8, 58, 21, 27, 53, 36, 26, 54, 31, 50, 17, 30, 45, 1, 29, 59, 44, 53, 41, 4, 35, 58, 51, 19, 32, 4, 52, 34, 48, 8, 51, 5, 56, 2, 25, 61, 27, 38, 54, 27, 62, 21, 51, 1, 39, 62, 10, 50, 1, 58, 13, 47, 38, 18, 35, 54, 22, 51, 30, 19, 59, 34, 14, 32, 44, 4, 60, 15, 52, 62, 20, 43, 30, 35, 21, 60, 4, 52, 12, 24, 61, 18, 30, 42, 23, 61, 25, 50, 27, 38, 11, 59, 12, 35, 50, 30, 59, 24, 8, 42, 28, 37, 48, 9, 44, 21 },
-  { 10, 47, 15, 50, 30, 43, 8, 45, 29, 2, 36, 59, 1, 58, 41, 3, 63, 31, 54, 20, 13, 55, 35, 38, 4, 44, 15, 9, 61, 2, 14, 38, 61, 10, 23, 54, 18, 12, 24, 2, 14, 55, 16, 8, 38, 14, 41, 60, 10, 23, 1, 58, 32, 17, 28, 37, 41, 15, 3, 60, 15, 33, 4, 36, 16, 59, 28, 14, 23, 55, 37, 18, 44, 28, 2, 57, 30, 10, 27, 46, 14, 38, 3, 53, 21, 61, 17, 35, 10, 41, 26, 7, 33, 9, 57, 1, 53, 37, 26, 20, 56, 48, 9, 33, 58, 16, 37, 7, 45, 1, 57, 15, 32, 26, 42, 23, 7, 20, 4, 54, 31, 62, 22, 1, 59, 30, 4, 51 },
-  { 36, 2, 38, 11, 24, 36, 54, 22, 62, 47, 25, 8, 28, 45, 16, 38, 12, 43, 9, 37, 49, 3, 23, 52, 18, 30, 50, 33, 19, 42, 49, 26, 6, 40, 47, 35, 63, 38, 50, 33, 60, 26, 36, 47, 24, 57, 6, 26, 39, 63, 19, 44, 14, 46, 61, 9, 50, 30, 45, 23, 10, 50, 44, 8, 31, 54, 6, 46, 36, 4, 30, 54, 8, 52, 22, 41, 4, 60, 40, 0, 58, 24, 45, 10, 37, 1, 48, 30, 56, 17, 38, 48, 24, 47, 19, 39, 14, 8, 45, 32, 2, 34, 27, 44, 4, 52, 11, 56, 31, 21, 40, 19, 44, 51, 2, 63, 46, 58, 36, 43, 14, 5, 50, 38, 14, 56, 40, 23 },
-  { 61, 46, 32, 63, 54, 1, 14, 34, 12, 40, 18, 49, 37, 10, 61, 30, 51, 24, 60, 7, 29, 40, 62, 11, 46, 58, 6, 56, 24, 10, 34, 52, 21, 59, 16, 3, 27, 5, 20, 46, 9, 40, 7, 62, 2, 30, 53, 15, 48, 10, 28, 35, 54, 6, 21, 34, 18, 55, 7, 40, 57, 19, 26, 60, 41, 13, 24, 51, 19, 61, 9, 25, 34, 15, 63, 11, 45, 17, 20, 47, 33, 8, 31, 62, 43, 26, 53, 7, 24, 59, 0, 13, 55, 4, 62, 27, 51, 31, 63, 15, 58, 7, 54, 14, 46, 22, 28, 43, 12, 63, 8, 54, 5, 17, 39, 33, 15, 10, 27, 17, 47, 34, 19, 45, 27, 12, 33, 17 },
-  { 5, 28, 21, 7, 17, 48, 42, 58, 23, 4, 63, 14, 55, 21, 34, 5, 19, 0, 45, 17, 52, 15, 25, 32, 0, 22, 40, 13, 45, 62, 18, 0, 43, 11, 33, 55, 30, 42, 57, 19, 51, 31, 22, 43, 18, 45, 34, 0, 43, 31, 56, 3, 23, 40, 59, 0, 44, 13, 48, 35, 2, 32, 46, 0, 21, 48, 35, 3, 40, 32, 43, 59, 0, 48, 33, 26, 53, 36, 55, 12, 51, 16, 55, 5, 18, 29, 11, 39, 51, 19, 45, 31, 42, 21, 35, 6, 22, 47, 10, 38, 23, 50, 20, 36, 0, 60, 38, 4, 50, 35, 48, 34, 24, 57, 9, 53, 28, 48, 61, 0, 56, 24, 53, 3, 63, 6, 42, 57 },
-  { 13, 53, 45, 40, 58, 27, 6, 16, 38, 51, 33, 30, 43, 2, 47, 56, 40, 50, 33, 57, 27, 5, 47, 42, 60, 36, 16, 54, 28, 4, 37, 57, 28, 51, 22, 8, 45, 14, 6, 39, 0, 54, 11, 59, 28, 12, 50, 21, 61, 13, 19, 38, 49, 11, 25, 37, 58, 29, 22, 63, 14, 56, 12, 53, 30, 63, 9, 57, 26, 12, 47, 16, 23, 39, 50, 6, 31, 2, 25, 6, 28, 41, 36, 22, 50, 57, 42, 3, 34, 8, 28, 61, 11, 50, 16, 54, 41, 0, 55, 43, 5, 29, 41, 63, 25, 16, 53, 18, 26, 10, 21, 0, 61, 30, 41, 22, 3, 38, 20, 39, 29, 8, 41, 16, 36, 52, 22, 19 },
-  { 55, 34, 0, 25, 10, 32, 56, 44, 28, 0, 57, 7, 26, 53, 23, 8, 13, 35, 22, 12, 36, 60, 20, 8, 14, 29, 48, 2, 41, 49, 23, 13, 39, 7, 48, 58, 25, 53, 34, 62, 28, 16, 48, 4, 37, 56, 27, 5, 36, 52, 46, 7, 62, 33, 52, 11, 17, 53, 5, 28, 41, 24, 38, 17, 5, 39, 20, 45, 15, 56, 5, 38, 60, 8, 14, 57, 21, 48, 62, 39, 59, 13, 1, 60, 9, 32, 16, 63, 44, 25, 52, 15, 36, 2, 60, 29, 12, 33, 25, 17, 59, 45, 13, 8, 49, 32, 6, 40, 59, 29, 45, 37, 13, 47, 6, 55, 30, 45, 9, 52, 13, 59, 25, 47, 32, 1, 49, 30 },
-  { 9, 39, 14, 61, 49, 37, 3, 20, 50, 13, 41, 19, 46, 17, 38, 59, 28, 62, 4, 44, 54, 1, 34, 51, 55, 7, 63, 32, 21, 8, 56, 31, 62, 19, 36, 1, 41, 17, 24, 12, 42, 35, 25, 52, 20, 8, 44, 59, 25, 2, 22, 42, 16, 29, 4, 46, 20, 36, 43, 9, 51, 8, 49, 26, 58, 33, 54, 1, 37, 29, 52, 20, 27, 45, 19, 35, 42, 16, 10, 32, 20, 49, 46, 27, 40, 4, 47, 22, 13, 55, 4, 47, 26, 44, 23, 40, 58, 19, 48, 13, 31, 2, 57, 34, 42, 19, 61, 32, 14, 55, 5, 51, 26, 19, 58, 16, 49, 14, 62, 5, 33, 44, 21, 7, 60, 26, 11, 41 },
-  { 62, 24, 47, 29, 8, 19, 53, 11, 60, 24, 32, 61, 4, 55, 31, 2, 49, 16, 39, 9, 31, 24, 43, 17, 26, 38, 11, 25, 58, 43, 12, 35, 3, 46, 15, 32, 63, 4, 49, 56, 2, 60, 10, 32, 63, 17, 39, 12, 55, 30, 57, 9, 48, 55, 39, 24, 60, 2, 58, 31, 19, 61, 34, 3, 42, 11, 22, 46, 7, 61, 10, 42, 3, 55, 32, 1, 58, 28, 44, 54, 4, 34, 23, 15, 56, 20, 37, 58, 6, 30, 38, 18, 63, 9, 32, 5, 51, 3, 62, 37, 52, 18, 39, 23, 3, 51, 9, 47, 1, 23, 43, 15, 60, 35, 11, 40, 1, 36, 31, 26, 57, 2, 37, 54, 18, 44, 58, 16 },
-  { 5, 51, 3, 33, 43, 62, 21, 42, 35, 9, 48, 15, 36, 10, 22, 42, 20, 46, 26, 56, 50, 12, 59, 3, 48, 19, 45, 53, 1, 27, 47, 17, 52, 24, 56, 11, 51, 21, 37, 30, 20, 46, 14, 41, 1, 47, 33, 7, 41, 17, 35, 27, 20, 1, 14, 54, 26, 33, 18, 47, 1, 44, 14, 59, 16, 52, 28, 18, 49, 31, 25, 34, 63, 13, 51, 24, 9, 50, 3, 23, 38, 63, 7, 52, 29, 46, 11, 33, 50, 22, 57, 36, 1, 57, 49, 17, 39, 28, 9, 35, 6, 27, 53, 15, 55, 30, 24, 58, 36, 41, 11, 52, 32, 3, 44, 25, 62, 23, 51, 15, 42, 22, 50, 10, 39, 4, 31, 35 },
-  { 46, 22, 57, 17, 12, 39, 26, 5, 31, 59, 1, 45, 27, 62, 52, 7, 58, 33, 6, 18, 39, 22, 33, 41, 57, 5, 35, 18, 40, 16, 60, 5, 29, 42, 7, 39, 27, 44, 9, 47, 8, 26, 54, 22, 51, 29, 24, 49, 15, 61, 4, 51, 31, 63, 43, 6, 50, 8, 39, 12, 53, 37, 23, 30, 40, 6, 62, 43, 14, 53, 2, 49, 7, 36, 17, 41, 61, 37, 18, 56, 11, 18, 44, 35, 2, 19, 61, 0, 41, 14, 8, 30, 43, 12, 24, 46, 14, 54, 42, 21, 44, 61, 10, 46, 37, 11, 44, 7, 18, 63, 20, 29, 7, 49, 28, 54, 8, 43, 4, 48, 18, 63, 12, 29, 48, 24, 59, 20 },
-  { 13, 36, 28, 54, 35, 2, 56, 46, 16, 49, 22, 40, 11, 34, 14, 43, 29, 12, 63, 48, 2, 61, 7, 15, 28, 30, 50, 9, 61, 33, 38, 23, 54, 13, 61, 33, 3, 59, 16, 35, 58, 40, 5, 38, 13, 57, 3, 58, 37, 21, 45, 12, 39, 7, 35, 30, 13, 56, 22, 62, 27, 6, 55, 10, 48, 21, 33, 2, 38, 23, 40, 20, 44, 29, 59, 4, 26, 12, 33, 47, 28, 53, 31, 13, 59, 41, 27, 49, 26, 54, 45, 16, 53, 21, 35, 7, 59, 26, 11, 56, 1, 24, 33, 4, 28, 62, 21, 49, 31, 2, 56, 39, 24, 58, 13, 17, 37, 21, 56, 10, 38, 0, 34, 55, 15, 43, 1, 52 },
-  { 42, 9, 50, 6, 25, 60, 14, 38, 10, 29, 53, 18, 57, 3, 25, 51, 0, 53, 25, 17, 29, 37, 52, 46, 0, 62, 14, 37, 4, 50, 10, 44, 0, 46, 20, 25, 50, 19, 55, 0, 23, 31, 62, 34, 11, 45, 19, 32, 0, 53, 10, 59, 23, 47, 18, 60, 42, 28, 37, 3, 50, 15, 35, 44, 0, 51, 27, 60, 9, 57, 16, 58, 11, 22, 46, 15, 53, 48, 7, 42, 0, 60, 5, 49, 24, 54, 9, 17, 39, 5, 34, 62, 3, 40, 60, 31, 0, 47, 29, 16, 49, 39, 59, 17, 50, 0, 40, 13, 53, 38, 16, 46, 0, 42, 34, 60, 2, 53, 29, 31, 58, 46, 27, 6, 61, 8, 37, 28 },
-  { 0, 63, 21, 40, 45, 18, 51, 23, 63, 34, 6, 43, 28, 38, 55, 19, 40, 35, 8, 41, 54, 10, 21, 32, 39, 23, 53, 26, 55, 28, 22, 63, 30, 34, 9, 48, 6, 38, 29, 43, 49, 6, 18, 52, 27, 61, 9, 43, 28, 42, 33, 26, 56, 3, 51, 23, 0, 48, 16, 45, 32, 25, 63, 20, 57, 17, 42, 12, 35, 47, 5, 31, 39, 56, 6, 30, 34, 21, 61, 25, 14, 40, 22, 38, 15, 6, 36, 56, 20, 60, 25, 12, 51, 27, 10, 56, 42, 20, 36, 63, 32, 6, 21, 41, 12, 34, 60, 26, 5, 48, 27, 10, 62, 19, 6, 47, 39, 14, 45, 7, 24, 17, 41, 32, 23, 51, 19, 56 },
-  { 45, 31, 15, 59, 4, 33, 7, 47, 0, 41, 13, 61, 4, 47, 9, 23, 60, 14, 57, 31, 4, 45, 59, 6, 58, 10, 44, 20, 8, 42, 15, 6, 55, 17, 58, 31, 53, 12, 61, 10, 15, 57, 43, 2, 23, 35, 48, 14, 54, 6, 18, 49, 15, 38, 11, 34, 62, 9, 21, 58, 11, 41, 4, 31, 38, 8, 29, 55, 19, 36, 27, 52, 0, 25, 50, 43, 1, 39, 8, 55, 35, 51, 10, 30, 45, 62, 29, 2, 46, 10, 32, 48, 18, 38, 5, 22, 33, 8, 51, 3, 14, 44, 54, 25, 57, 30, 18, 52, 33, 22, 59, 28, 36, 52, 32, 21, 26, 50, 5, 55, 35, 60, 14, 54, 4, 40, 16, 33 },
-  { 27, 3, 49, 10, 30, 40, 55, 27, 57, 24, 52, 21, 32, 17, 60, 30, 5, 44, 27, 49, 19, 34, 13, 24, 43, 36, 3, 49, 31, 59, 37, 48, 26, 41, 2, 41, 14, 36, 21, 32, 40, 26, 13, 49, 55, 5, 16, 40, 25, 60, 36, 1, 63, 29, 17, 44, 25, 40, 52, 5, 29, 47, 54, 13, 46, 24, 60, 4, 51, 22, 63, 14, 45, 18, 12, 62, 17, 57, 19, 42, 3, 26, 58, 48, 1, 21, 40, 52, 23, 37, 44, 1, 29, 58, 43, 50, 15, 61, 19, 45, 58, 28, 7, 48, 2, 46, 8, 42, 3, 55, 8, 50, 12, 4, 55, 10, 63, 33, 20, 40, 11, 3, 46, 20, 48, 26, 61, 11 },
-  { 44, 56, 24, 36, 53, 19, 12, 37, 16, 44, 7, 36, 49, 54, 11, 37, 48, 21, 15, 1, 62, 25, 47, 56, 16, 18, 51, 12, 40, 1, 24, 11, 52, 16, 23, 59, 28, 1, 45, 53, 4, 60, 37, 21, 39, 30, 63, 20, 52, 10, 30, 45, 8, 41, 54, 4, 57, 7, 34, 55, 36, 18, 23, 59, 2, 48, 11, 32, 44, 1, 41, 8, 33, 54, 38, 23, 30, 46, 6, 29, 62, 18, 32, 16, 55, 34, 14, 11, 61, 7, 55, 16, 53, 13, 23, 2, 55, 37, 26, 10, 33, 23, 36, 16, 38, 22, 56, 15, 24, 43, 35, 17, 44, 40, 25, 46, 16, 1, 57, 25, 49, 36, 28, 62, 9, 35, 7, 53 },
-  { 17, 38, 8, 61, 1, 50, 26, 62, 3, 31, 56, 15, 1, 26, 40, 2, 34, 51, 56, 36, 42, 9, 38, 2, 29, 60, 32, 57, 19, 62, 34, 47, 4, 57, 39, 7, 44, 63, 24, 18, 46, 28, 8, 54, 1, 34, 7, 46, 3, 37, 50, 23, 57, 21, 13, 46, 31, 20, 43, 15, 1, 61, 8, 33, 37, 17, 56, 26, 15, 49, 24, 59, 28, 3, 56, 9, 52, 32, 13, 49, 10, 43, 5, 45, 8, 25, 59, 42, 28, 33, 19, 40, 8, 63, 35, 47, 25, 4, 40, 52, 1, 60, 12, 53, 63, 9, 29, 60, 37, 19, 1, 62, 31, 20, 58, 12, 41, 30, 43, 9, 18, 52, 22, 1, 39, 30, 58, 21 },
-  { 13, 47, 29, 18, 43, 34, 5, 48, 20, 42, 10, 45, 30, 58, 20, 63, 24, 11, 6, 28, 54, 14, 22, 52, 41, 7, 26, 5, 45, 15, 53, 13, 35, 27, 18, 50, 12, 33, 5, 56, 10, 17, 45, 24, 59, 15, 50, 26, 56, 13, 19, 5, 32, 52, 27, 36, 2, 61, 12, 26, 49, 40, 27, 52, 13, 50, 6, 39, 61, 34, 10, 37, 48, 20, 41, 27, 2, 36, 59, 24, 54, 33, 63, 20, 38, 50, 3, 17, 52, 4, 58, 27, 45, 21, 32, 11, 48, 17, 57, 20, 46, 38, 25, 43, 4, 34, 51, 6, 13, 45, 57, 26, 6, 48, 2, 35, 53, 23, 61, 34, 59, 6, 42, 56, 13, 51, 2, 41 },
-  { 32, 5, 55, 23, 58, 14, 22, 52, 29, 15, 61, 25, 51, 8, 43, 13, 53, 41, 46, 20, 3, 33, 63, 11, 48, 21, 54, 38, 28, 3, 30, 43, 21, 62, 9, 31, 55, 22, 51, 29, 37, 62, 32, 12, 42, 29, 41, 9, 33, 44, 62, 28, 43, 1, 59, 19, 48, 30, 51, 39, 24, 4, 58, 19, 42, 29, 22, 43, 3, 18, 53, 5, 13, 50, 16, 60, 45, 21, 7, 40, 15, 0, 26, 53, 13, 31, 43, 24, 47, 31, 15, 49, 2, 41, 6, 59, 29, 42, 9, 30, 14, 7, 49, 18, 31, 47, 20, 39, 49, 32, 11, 41, 54, 15, 61, 18, 7, 38, 4, 13, 44, 28, 15, 32, 45, 19, 27, 49 },
-  { 63, 34, 11, 39, 2, 45, 37, 8, 59, 39, 33, 4, 36, 17, 48, 5, 29, 18, 32, 61, 39, 50, 5, 27, 35, 0, 46, 12, 22, 49, 60, 6, 54, 0, 38, 49, 2, 42, 15, 40, 0, 47, 20, 51, 3, 57, 18, 61, 22, 0, 39, 16, 55, 12, 35, 8, 41, 22, 6, 59, 16, 45, 10, 36, 0, 62, 9, 54, 30, 58, 21, 43, 63, 31, 7, 35, 12, 48, 58, 28, 47, 37, 41, 9, 57, 20, 61, 0, 36, 11, 57, 35, 23, 52, 37, 18, 0, 62, 22, 55, 35, 62, 27, 54, 0, 15, 61, 28, 2, 59, 22, 9, 37, 27, 33, 51, 29, 48, 19, 50, 25, 37, 10, 57, 5, 37, 60, 8 },
-  { 20, 25, 46, 52, 31, 60, 12, 55, 0, 19, 11, 46, 62, 35, 23, 38, 57, 0, 55, 10, 16, 30, 58, 44, 17, 59, 29, 63, 42, 8, 36, 20, 33, 46, 16, 61, 25, 35, 8, 54, 26, 7, 58, 22, 34, 6, 47, 14, 53, 31, 48, 9, 37, 25, 49, 63, 16, 55, 45, 14, 34, 63, 21, 53, 25, 33, 46, 16, 35, 7, 46, 29, 0, 39, 25, 55, 22, 34, 18, 4, 56, 11, 23, 51, 28, 6, 39, 14, 62, 44, 19, 8, 60, 12, 56, 28, 50, 34, 39, 5, 51, 3, 41, 12, 57, 35, 10, 53, 25, 17, 52, 30, 47, 0, 43, 14, 5, 57, 31, 55, 0, 63, 47, 23, 54, 24, 14, 43 },
-  { 0, 57, 16, 6, 26, 19, 35, 28, 49, 42, 54, 26, 21, 1, 59, 27, 9, 47, 26, 44, 50, 22, 13, 40, 8, 37, 10, 34, 17, 56, 25, 58, 13, 27, 44, 9, 20, 58, 31, 17, 60, 36, 10, 41, 53, 25, 36, 39, 4, 24, 58, 17, 60, 4, 22, 38, 10, 32, 0, 50, 31, 7, 28, 47, 12, 57, 5, 26, 52, 23, 14, 40, 57, 17, 47, 5, 53, 1, 44, 31, 19, 60, 46, 2, 35, 48, 30, 54, 22, 5, 51, 39, 25, 31, 4, 43, 14, 9, 45, 16, 24, 44, 19, 29, 40, 23, 44, 7, 38, 42, 4, 63, 12, 54, 23, 59, 22, 42, 8, 15, 40, 21, 8, 34, 3, 41, 30, 50 },
-  { 39, 10, 48, 33, 41, 54, 5, 47, 23, 13, 32, 7, 52, 44, 14, 39, 58, 18, 35, 6, 37, 2, 60, 24, 55, 19, 53, 2, 51, 32, 1, 41, 51, 4, 40, 29, 47, 3, 52, 44, 13, 49, 28, 16, 1, 62, 11, 27, 52, 35, 5, 42, 29, 47, 14, 56, 28, 53, 26, 38, 9, 56, 40, 3, 38, 15, 41, 60, 1, 37, 50, 25, 11, 28, 61, 19, 42, 62, 10, 52, 39, 6, 32, 14, 58, 17, 7, 26, 42, 34, 27, 10, 54, 40, 20, 63, 26, 53, 21, 61, 32, 7, 59, 48, 3, 56, 18, 31, 58, 14, 49, 21, 36, 16, 45, 9, 36, 24, 62, 45, 27, 31, 53, 17, 49, 12, 62, 18 },
-  { 28, 59, 21, 58, 2, 16, 38, 9, 62, 3, 56, 41, 10, 31, 50, 4, 32, 52, 12, 63, 23, 46, 33, 31, 4, 48, 25, 43, 14, 23, 47, 11, 22, 55, 14, 60, 23, 37, 11, 39, 23, 2, 45, 56, 31, 43, 19, 55, 16, 46, 21, 51, 11, 33, 44, 2, 41, 18, 5, 52, 23, 44, 17, 60, 27, 49, 11, 32, 44, 10, 54, 2, 56, 33, 8, 38, 13, 29, 36, 16, 24, 63, 27, 51, 21, 43, 56, 12, 49, 3, 59, 48, 1, 15, 46, 7, 36, 2, 47, 11, 50, 27, 37, 13, 33, 8, 51, 46, 1, 34, 28, 40, 3, 33, 60, 29, 47, 1, 35, 11, 59, 42, 2, 60, 26, 46, 6, 35 },
-  { 4, 43, 9, 29, 36, 63, 24, 44, 20, 50, 30, 17, 60, 22, 16, 43, 25, 3, 42, 19, 51, 15, 8, 54, 42, 15, 61, 5, 39, 57, 18, 61, 31, 48, 34, 2, 50, 19, 57, 5, 63, 33, 19, 38, 13, 27, 48, 7, 32, 61, 2, 26, 58, 6, 24, 50, 13, 61, 42, 20, 62, 2, 35, 20, 51, 4, 62, 18, 23, 58, 20, 31, 43, 15, 51, 45, 26, 50, 4, 55, 45, 3, 35, 9, 38, 1, 32, 61, 20, 45, 17, 33, 24, 57, 29, 51, 22, 58, 38, 30, 15, 1, 54, 21, 63, 43, 26, 12, 24, 56, 8, 60, 50, 19, 5, 52, 13, 54, 17, 50, 4, 16, 36, 12, 32, 56, 22, 54 },
-  { 51, 25, 40, 53, 12, 49, 15, 57, 34, 7, 38, 47, 2, 36, 55, 8, 61, 30, 56, 7, 28, 59, 48, 11, 27, 35, 21, 45, 28, 36, 9, 38, 6, 16, 24, 63, 10, 32, 28, 43, 21, 53, 5, 60, 8, 57, 3, 45, 11, 37, 15, 54, 40, 20, 62, 36, 27, 34, 11, 48, 30, 15, 54, 8, 30, 42, 22, 34, 48, 13, 35, 63, 4, 37, 22, 2, 59, 9, 41, 23, 13, 41, 49, 18, 59, 24, 40, 5, 37, 30, 9, 61, 44, 6, 37, 11, 33, 17, 5, 55, 41, 60, 23, 39, 17, 5, 30, 62, 41, 16, 46, 25, 11, 56, 39, 26, 20, 38, 29, 39, 22, 52, 44, 20, 48, 1, 38, 14 },
-  { 15, 33, 2, 18, 44, 6, 27, 0, 32, 61, 25, 12, 58, 28, 40, 20, 47, 13, 34, 43, 38, 1, 23, 62, 40, 0, 51, 10, 63, 3, 52, 26, 44, 30, 45, 6, 41, 54, 0, 51, 12, 30, 46, 24, 49, 22, 40, 33, 63, 23, 43, 30, 9, 47, 0, 17, 54, 7, 57, 3, 37, 47, 24, 46, 13, 55, 7, 52, 2, 42, 6, 26, 49, 18, 60, 34, 16, 57, 33, 20, 61, 30, 8, 54, 14, 46, 12, 53, 16, 55, 38, 13, 22, 53, 18, 59, 46, 27, 43, 19, 32, 10, 45, 6, 49, 36, 52, 2, 20, 55, 6, 39, 32, 15, 44, 3, 58, 10, 63, 6, 56, 30, 7, 58, 9, 40, 19, 63 },
-  { 10, 47, 61, 23, 55, 31, 52, 42, 17, 45, 4, 51, 27, 6, 15, 53, 0, 49, 26, 10, 56, 18, 36, 6, 20, 58, 32, 30, 13, 49, 19, 56, 0, 59, 12, 53, 27, 17, 38, 25, 48, 9, 15, 36, 14, 30, 59, 17, 0, 50, 8, 58, 18, 56, 31, 45, 21, 41, 29, 19, 60, 6, 32, 59, 0, 36, 29, 39, 19, 59, 46, 12, 55, 30, 10, 47, 24, 3, 28, 48, 0, 55, 44, 27, 33, 4, 63, 29, 49, 0, 26, 50, 34, 2, 42, 14, 0, 62, 9, 56, 3, 52, 28, 34, 58, 9, 20, 48, 37, 32, 22, 53, 0, 62, 27, 49, 34, 46, 21, 33, 41, 14, 25, 37, 53, 29, 31, 45 },
-  { 56, 28, 7, 37, 11, 36, 20, 9, 54, 14, 39, 19, 34, 63, 45, 37, 24, 17, 60, 31, 21, 45, 53, 29, 47, 15, 7, 55, 40, 23, 34, 14, 42, 20, 37, 35, 15, 59, 7, 62, 34, 40, 59, 1, 51, 42, 10, 28, 54, 21, 35, 5, 38, 13, 36, 4, 59, 12, 39, 53, 15, 43, 9, 21, 39, 62, 16, 56, 25, 9, 32, 38, 0, 41, 14, 51, 40, 53, 43, 11, 37, 17, 5, 22, 57, 39, 19, 7, 42, 21, 60, 10, 31, 63, 25, 52, 30, 49, 36, 25, 48, 17, 61, 14, 22, 42, 29, 13, 60, 11, 47, 18, 35, 41, 7, 23, 4, 16, 51, 11, 0, 48, 61, 3, 17, 50, 5, 24 },
-  { 0, 42, 21, 49, 60, 3, 57, 40, 29, 48, 23, 56, 42, 11, 22, 5, 59, 39, 4, 50, 3, 41, 12, 57, 25, 50, 44, 18, 4, 46, 7, 62, 33, 50, 4, 56, 21, 32, 43, 18, 3, 23, 55, 34, 20, 4, 53, 38, 12, 46, 29, 52, 25, 61, 23, 51, 26, 46, 1, 34, 25, 57, 28, 51, 26, 11, 50, 3, 44, 28, 53, 21, 57, 27, 62, 6, 31, 19, 8, 63, 26, 59, 36, 47, 15, 29, 50, 25, 35, 47, 18, 41, 4, 48, 8, 40, 12, 23, 6, 44, 13, 40, 1, 31, 55, 0, 61, 43, 4, 50, 26, 58, 9, 53, 24, 61, 42, 55, 31, 43, 57, 20, 34, 27, 43, 8, 59, 39 },
-  { 18, 51, 30, 13, 26, 16, 46, 22, 2, 59, 8, 30, 1, 48, 33, 51, 29, 9, 46, 16, 62, 14, 33, 2, 38, 9, 27, 60, 37, 26, 53, 17, 28, 10, 24, 46, 2, 49, 8, 57, 29, 45, 6, 26, 62, 44, 18, 25, 61, 3, 42, 14, 49, 10, 43, 6, 17, 32, 63, 10, 49, 4, 40, 14, 45, 33, 22, 37, 12, 61, 5, 17, 43, 7, 23, 37, 15, 58, 49, 13, 39, 21, 10, 52, 1, 62, 9, 56, 12, 2, 58, 28, 36, 16, 56, 28, 56, 35, 20, 63, 24, 37, 51, 8, 45, 25, 16, 33, 27, 38, 2, 44, 13, 30, 17, 36, 12, 26, 5, 18, 28, 47, 13, 60, 23, 45, 13, 33 },
-  { 55, 4, 62, 34, 52, 38, 7, 63, 32, 37, 13, 53, 25, 62, 18, 12, 55, 41, 27, 35, 24, 49, 31, 52, 17, 63, 34, 1, 56, 12, 41, 2, 48, 58, 39, 16, 61, 27, 41, 52, 13, 19, 50, 39, 11, 31, 57, 6, 32, 40, 20, 55, 1, 28, 33, 57, 48, 8, 37, 22, 44, 18, 53, 1, 61, 5, 54, 16, 47, 36, 50, 24, 55, 34, 48, 45, 1, 30, 33, 46, 2, 50, 32, 42, 25, 34, 43, 21, 38, 52, 23, 45, 14, 54, 21, 4, 44, 16, 53, 29, 10, 47, 19, 57, 12, 54, 39, 10, 51, 15, 63, 21, 57, 40, 51, 1, 48, 57, 37, 62, 2, 38, 9, 52, 1, 35, 58, 22 },
-  { 36, 46, 10, 42, 1, 27, 43, 15, 50, 21, 45, 16, 41, 3, 35, 44, 20, 1, 57, 11, 55, 7, 43, 8, 22, 42, 13, 46, 21, 39, 31, 60, 22, 5, 29, 44, 11, 35, 20, 4, 36, 58, 32, 15, 47, 2, 36, 48, 16, 60, 8, 35, 44, 63, 16, 2, 40, 26, 55, 14, 58, 35, 24, 31, 19, 42, 31, 58, 1, 29, 10, 40, 2, 19, 12, 54, 22, 61, 7, 24, 56, 5, 28, 16, 54, 3, 15, 58, 6, 30, 8, 62, 1, 43, 31, 47, 7, 59, 1, 38, 58, 4, 34, 27, 38, 5, 31, 59, 7, 46, 30, 3, 34, 6, 28, 59, 20, 8, 32, 15, 53, 24, 55, 31, 19, 49, 11, 26 },
-  { 2, 24, 16, 58, 19, 55, 5, 35, 10, 61, 4, 28, 57, 24, 58, 7, 31, 47, 22, 38, 19, 28, 61, 36, 54, 5, 59, 29, 6, 52, 15, 11, 43, 36, 8, 54, 52, 1, 62, 25, 47, 9, 1, 60, 28, 53, 24, 14, 46, 27, 51, 22, 12, 24, 38, 53, 20, 11, 51, 3, 29, 7, 48, 63, 8, 49, 9, 21, 52, 14, 63, 32, 46, 60, 35, 4, 41, 16, 52, 35, 18, 42, 59, 7, 36, 61, 45, 27, 33, 51, 19, 39, 34, 11, 61, 18, 33, 41, 28, 15, 54, 22, 42, 3, 49, 21, 47, 18, 36, 23, 55, 19, 48, 24, 45, 10, 33, 44, 50, 40, 7, 35, 15, 41, 63, 6, 40, 54 },
-  { 62, 41, 32, 8, 47, 28, 60, 24, 44, 30, 38, 49, 9, 33, 14, 40, 50, 14, 60, 2, 54, 40, 0, 20, 25, 39, 16, 49, 24, 35, 57, 47, 19, 61, 33, 18, 23, 37, 13, 55, 31, 43, 22, 41, 17, 8, 42, 58, 0, 37, 5, 56, 31, 54, 7, 30, 60, 33, 42, 17, 59, 39, 12, 27, 38, 17, 35, 41, 27, 45, 20, 7, 25, 15, 29, 58, 27, 47, 11, 40, 14, 54, 23, 46, 19, 31, 11, 40, 13, 49, 5, 58, 24, 51, 26, 6, 50, 20, 49, 9, 32, 46, 17, 60, 14, 63, 24, 1, 57, 41, 9, 43, 14, 62, 16, 52, 3, 27, 14, 22, 61, 45, 4, 28, 9, 47, 29, 17 },
-  { 5, 50, 12, 53, 38, 18, 11, 51, 0, 55, 17, 6, 47, 54, 19, 63, 5, 26, 34, 45, 13, 30, 47, 58, 10, 48, 32, 3, 62, 9, 26, 0, 25, 14, 50, 3, 47, 30, 42, 16, 6, 63, 12, 49, 33, 55, 21, 10, 34, 63, 18, 41, 3, 47, 19, 43, 0, 49, 8, 28, 46, 20, 52, 0, 56, 24, 60, 3, 59, 5, 39, 57, 48, 52, 9, 38, 3, 21, 26, 60, 0, 32, 12, 38, 4, 48, 53, 0, 60, 15, 29, 44, 18, 10, 38, 57, 13, 60, 2, 26, 62, 7, 50, 29, 35, 8, 40, 53, 28, 12, 60, 33, 38, 5, 37, 29, 60, 39, 56, 0, 30, 18, 50, 34, 59, 25, 14, 44 },
-  { 20, 31, 60, 22, 3, 49, 33, 25, 40, 13, 34, 59, 22, 36, 0, 28, 37, 56, 8, 18, 51, 16, 4, 45, 27, 12, 53, 42, 18, 44, 51, 31, 55, 40, 28, 58, 7, 60, 10, 51, 27, 37, 24, 56, 5, 26, 44, 29, 50, 23, 45, 11, 34, 15, 59, 27, 13, 23, 62, 37, 4, 57, 15, 32, 42, 6, 47, 11, 30, 43, 23, 13, 0, 36, 18, 44, 63, 51, 37, 29, 49, 20, 57, 27, 62, 9, 24, 35, 23, 53, 37, 3, 42, 55, 0, 36, 23, 39, 31, 43, 17, 37, 24, 11, 52, 43, 19, 32, 5, 50, 26, 0, 56, 21, 54, 11, 19, 6, 47, 25, 59, 42, 12, 54, 21, 3, 38, 57 },
-  { 48, 0, 35, 27, 44, 14, 59, 7, 57, 46, 26, 2, 42, 12, 52, 43, 10, 27, 53, 42, 32, 62, 37, 21, 34, 61, 7, 23, 36, 4, 38, 12, 41, 5, 17, 45, 22, 27, 39, 21, 59, 0, 45, 18, 39, 62, 3, 38, 14, 7, 54, 26, 61, 39, 9, 52, 45, 36, 18, 50, 10, 34, 44, 22, 50, 14, 36, 55, 17, 34, 53, 62, 33, 26, 56, 6, 31, 12, 6, 53, 9, 44, 2, 50, 20, 40, 55, 17, 47, 7, 26, 63, 22, 32, 48, 16, 46, 8, 52, 12, 57, 41, 0, 56, 25, 3, 61, 14, 45, 35, 18, 44, 12, 46, 23, 42, 32, 51, 35, 10, 17, 36, 23, 1, 45, 52, 32, 10 },
-  { 37, 15, 43, 8, 63, 39, 21, 31, 16, 37, 19, 62, 30, 46, 17, 60, 21, 48, 1, 23, 6, 25, 11, 56, 1, 40, 30, 58, 15, 54, 21, 59, 9, 63, 35, 56, 11, 51, 2, 46, 34, 14, 53, 7, 30, 11, 51, 19, 60, 40, 30, 1, 24, 50, 20, 32, 3, 56, 5, 25, 31, 13, 61, 2, 29, 60, 25, 20, 51, 2, 27, 8, 18, 42, 10, 45, 21, 34, 43, 17, 62, 29, 41, 14, 34, 6, 30, 43, 2, 57, 33, 13, 45, 12, 27, 62, 4, 55, 21, 35, 5, 27, 45, 33, 16, 47, 30, 54, 22, 10, 51, 27, 63, 7, 49, 1, 58, 22, 15, 43, 53, 7, 57, 39, 27, 12, 61, 24 },
-  { 56, 51, 26, 56, 19, 2, 41, 54, 5, 52, 9, 48, 6, 23, 39, 4, 32, 15, 63, 35, 59, 49, 43, 15, 52, 19, 50, 9, 46, 33, 1, 29, 48, 20, 32, 1, 38, 33, 19, 54, 9, 32, 24, 48, 58, 35, 16, 48, 4, 52, 13, 57, 33, 5, 45, 59, 15, 29, 41, 55, 47, 39, 23, 53, 9, 40, 4, 57, 10, 44, 48, 40, 50, 14, 61, 24, 55, 1, 59, 22, 33, 8, 51, 25, 58, 46, 11, 59, 20, 41, 17, 51, 6, 56, 35, 25, 42, 30, 15, 58, 48, 18, 61, 9, 58, 39, 13, 2, 37, 59, 40, 2, 31, 16, 34, 41, 8, 30, 62, 3, 29, 48, 33, 5, 63, 16, 41, 7 },
-  { 22, 4, 46, 11, 33, 51, 29, 10, 62, 24, 43, 27, 15, 58, 50, 25, 54, 44, 9, 38, 18, 3, 29, 57, 32, 5, 26, 43, 17, 61, 24, 52, 8, 42, 23, 53, 15, 61, 7, 28, 57, 43, 4, 40, 20, 2, 43, 25, 32, 35, 21, 43, 17, 48, 10, 22, 38, 54, 11, 21, 1, 58, 16, 30, 48, 18, 46, 32, 38, 13, 22, 4, 59, 35, 2, 51, 30, 39, 15, 47, 4, 56, 13, 37, 1, 28, 16, 52, 32, 9, 61, 29, 38, 19, 3, 52, 10, 48, 1, 32, 11, 40, 20, 36, 6, 22, 49, 29, 55, 6, 20, 56, 36, 52, 19, 60, 26, 46, 18, 54, 40, 13, 20, 46, 35, 19, 49, 29 },
-  { 61, 17, 34, 53, 23, 6, 48, 35, 20, 40, 1, 56, 36, 29, 11, 34, 7, 41, 14, 30, 55, 20, 46, 8, 24, 38, 63, 2, 37, 10, 45, 14, 34, 49, 6, 13, 44, 25, 49, 41, 21, 12, 61, 15, 54, 29, 63, 12, 56, 8, 49, 2, 62, 36, 28, 61, 0, 25, 41, 63, 35, 8, 44, 6, 37, 62, 7, 21, 63, 28, 55, 31, 16, 24, 41, 19, 9, 57, 27, 36, 18, 42, 31, 62, 22, 55, 38, 4, 27, 47, 1, 40, 14, 54, 43, 20, 60, 23, 38, 63, 25, 51, 2, 53, 26, 63, 10, 42, 17, 34, 47, 25, 13, 5, 44, 11, 55, 2, 38, 27, 6, 60, 52, 25, 9, 55, 1, 40 },
-  { 8, 30, 58, 3, 42, 61, 17, 38, 13, 59, 32, 10, 54, 3, 51, 20, 61, 26, 57, 2, 46, 33, 12, 60, 41, 13, 48, 29, 55, 20, 39, 27, 57, 18, 62, 29, 55, 2, 31, 16, 37, 50, 26, 36, 6, 46, 9, 41, 27, 57, 23, 39, 26, 6, 51, 12, 31, 46, 7, 16, 27, 52, 19, 56, 26, 12, 33, 53, 1, 41, 8, 57, 46, 7, 54, 32, 47, 5, 49, 11, 60, 23, 5, 48, 10, 43, 19, 63, 35, 24, 49, 21, 59, 5, 31, 37, 14, 44, 7, 42, 6, 30, 46, 13, 44, 32, 19, 50, 4, 58, 8, 30, 62, 38, 28, 53, 21, 36, 13, 50, 21, 33, 15, 2, 44, 31, 14, 47 },
-  { 37, 13, 39, 16, 28, 9, 57, 0, 25, 49, 21, 45, 18, 47, 12, 42, 0, 49, 22, 39, 16, 53, 25, 36, 0, 52, 22, 16, 6, 60, 4, 51, 0, 26, 37, 47, 10, 36, 63, 5, 57, 0, 18, 59, 23, 33, 51, 19, 0, 44, 15, 11, 54, 17, 42, 35, 53, 18, 58, 33, 49, 4, 34, 42, 0, 50, 43, 25, 16, 49, 34, 20, 37, 28, 12, 63, 16, 38, 25, 44, 0, 40, 52, 17, 35, 3, 50, 14, 8, 53, 11, 36, 25, 45, 9, 62, 0, 54, 28, 17, 50, 55, 15, 24, 57, 0, 53, 34, 23, 41, 15, 45, 0, 49, 16, 4, 48, 9, 63, 45, 0, 42, 58, 37, 61, 22, 54, 26 },
-  { 0, 50, 21, 47, 54, 36, 27, 45, 52, 4, 34, 15, 63, 29, 37, 59, 17, 31, 6, 61, 28, 5, 48, 18, 59, 27, 34, 56, 44, 31, 35, 12, 41, 59, 16, 3, 40, 20, 50, 22, 30, 40, 52, 10, 45, 3, 59, 22, 37, 61, 29, 46, 31, 58, 2, 22, 9, 43, 3, 39, 14, 61, 24, 54, 15, 29, 11, 60, 39, 17, 5, 61, 0, 44, 50, 3, 31, 14, 58, 21, 54, 28, 15, 45, 60, 26, 33, 58, 44, 22, 60, 2, 57, 34, 49, 27, 18, 34, 21, 59, 29, 4, 36, 41, 8, 39, 28, 11, 62, 26, 53, 20, 35, 24, 59, 32, 29, 39, 24, 31, 57, 23, 11, 28, 5, 36, 11, 59 },
-  { 44, 32, 63, 5, 20, 12, 41, 7, 30, 61, 42, 8, 39, 5, 33, 8, 24, 53, 45, 11, 37, 58, 7, 44, 10, 50, 3, 40, 8, 22, 53, 19, 46, 9, 33, 52, 24, 58, 8, 44, 13, 47, 8, 34, 38, 30, 14, 47, 7, 34, 4, 55, 9, 19, 40, 49, 56, 26, 60, 21, 30, 45, 10, 19, 40, 58, 23, 36, 3, 52, 45, 23, 54, 13, 22, 42, 53, 45, 7, 33, 10, 36, 57, 6, 29, 12, 41, 0, 30, 15, 41, 30, 17, 7, 16, 53, 40, 56, 2, 39, 12, 61, 10, 52, 31, 60, 16, 45, 1, 37, 7, 61, 40, 10, 43, 17, 58, 7, 54, 14, 4, 51, 39, 49, 18, 56, 42, 20 },
-  { 14, 6, 24, 36, 56, 49, 22, 60, 18, 14, 23, 51, 26, 57, 21, 52, 41, 14, 35, 50, 19, 31, 40, 23, 33, 14, 63, 17, 32, 47, 7, 62, 23, 30, 56, 11, 42, 27, 14, 60, 35, 19, 28, 61, 17, 55, 25, 39, 53, 17, 42, 21, 38, 63, 25, 5, 14, 36, 12, 50, 1, 37, 59, 32, 2, 51, 6, 56, 27, 32, 11, 30, 38, 26, 60, 8, 26, 19, 62, 39, 50, 2, 21, 39, 53, 23, 56, 19, 49, 39, 5, 46, 55, 23, 42, 4, 31, 11, 47, 26, 45, 22, 48, 18, 21, 5, 48, 25, 57, 14, 47, 30, 3, 56, 12, 50, 1, 42, 19, 47, 35, 17, 8, 30, 45, 25, 4, 51 },
-  { 28, 58, 43, 1, 31, 8, 33, 2, 44, 55, 32, 1, 60, 12, 46, 27, 4, 62, 23, 1, 56, 13, 62, 2, 54, 36, 25, 51, 1, 57, 26, 42, 3, 49, 17, 38, 1, 48, 31, 4, 54, 3, 50, 24, 1, 49, 5, 63, 13, 27, 52, 1, 48, 13, 45, 33, 52, 30, 46, 20, 55, 28, 6, 48, 24, 38, 20, 47, 14, 62, 48, 9, 58, 4, 36, 30, 56, 1, 34, 12, 18, 63, 25, 48, 4, 16, 37, 7, 62, 10, 52, 28, 13, 50, 36, 63, 24, 51, 15, 58, 8, 33, 1, 38, 56, 35, 42, 9, 33, 51, 22, 18, 48, 32, 27, 37, 23, 61, 33, 11, 59, 29, 62, 1, 53, 10, 60, 33 },
-  { 12, 39, 17, 52, 26, 46, 53, 38, 25, 11, 48, 36, 16, 43, 2, 35, 55, 17, 39, 29, 43, 9, 28, 45, 20, 5, 46, 12, 42, 28, 13, 52, 36, 6, 60, 22, 54, 17, 62, 39, 25, 42, 15, 55, 44, 20, 31, 10, 35, 57, 24, 32, 29, 6, 59, 18, 7, 62, 3, 41, 10, 44, 16, 54, 13, 62, 31, 9, 41, 1, 21, 43, 18, 47, 15, 40, 11, 49, 28, 55, 46, 30, 8, 43, 32, 61, 28, 47, 25, 34, 21, 61, 32, 1, 20, 9, 46, 6, 35, 19, 41, 54, 27, 63, 14, 3, 51, 20, 62, 2, 38, 55, 8, 21, 63, 6, 46, 9, 26, 51, 3, 24, 43, 34, 16, 41, 18, 48 },
-  { 62, 23, 55, 9, 15, 62, 19, 13, 58, 40, 6, 30, 54, 19, 50, 31, 10, 44, 6, 59, 21, 47, 51, 15, 60, 39, 30, 54, 21, 61, 19, 33, 14, 29, 43, 11, 34, 45, 7, 21, 10, 56, 36, 6, 38, 11, 58, 42, 2, 47, 11, 60, 50, 16, 41, 28, 38, 23, 47, 17, 35, 63, 22, 33, 42, 5, 45, 17, 53, 35, 25, 56, 33, 6, 51, 19, 60, 23, 43, 15, 5, 40, 58, 13, 51, 1, 45, 11, 54, 3, 43, 8, 37, 48, 59, 29, 39, 21, 61, 43, 3, 31, 10, 44, 24, 29, 60, 12, 28, 40, 11, 25, 43, 52, 14, 41, 16, 57, 44, 20, 40, 55, 12, 21, 57, 27, 35, 2 },
-  { 37, 6, 31, 42, 40, 4, 29, 50, 0, 20, 63, 28, 9, 58, 14, 24, 63, 26, 48, 16, 34, 4, 32, 38, 23, 11, 58, 4, 37, 9, 45, 5, 63, 48, 26, 57, 2, 28, 32, 51, 46, 29, 13, 62, 27, 46, 28, 18, 50, 15, 40, 4, 19, 34, 54, 0, 53, 9, 26, 58, 28, 5, 49, 0, 57, 27, 19, 60, 29, 8, 59, 12, 37, 63, 24, 46, 3, 37, 6, 52, 26, 32, 20, 36, 9, 22, 59, 18, 35, 51, 14, 57, 17, 24, 12, 44, 56, 0, 30, 13, 59, 20, 49, 17, 54, 43, 6, 34, 46, 17, 58, 36, 0, 34, 29, 54, 25, 2, 36, 15, 60, 6, 37, 46, 4, 50, 9, 45 },
-  { 19, 59, 48, 3, 24, 60, 44, 22, 34, 51, 15, 45, 41, 5, 33, 47, 0, 37, 12, 55, 25, 54, 8, 57, 0, 47, 18, 34, 49, 15, 55, 24, 40, 20, 8, 35, 53, 13, 41, 18, 0, 59, 22, 33, 4, 52, 8, 60, 24, 36, 31, 56, 45, 26, 10, 43, 15, 56, 36, 4, 51, 14, 39, 30, 12, 55, 36, 2, 39, 49, 4, 44, 17, 0, 32, 13, 53, 35, 59, 17, 62, 0, 55, 24, 52, 38, 31, 6, 42, 19, 29, 40, 4, 54, 33, 5, 16, 27, 52, 37, 23, 55, 7, 37, 0, 39, 23, 49, 4, 53, 31, 15, 59, 10, 50, 4, 60, 34, 48, 7, 31, 49, 27, 14, 62, 22, 53, 29 },
-  { 46, 21, 14, 51, 36, 17, 7, 57, 10, 32, 3, 37, 22, 60, 39, 18, 56, 20, 42, 3, 36, 10, 44, 26, 41, 29, 53, 27, 2, 39, 30, 52, 0, 59, 15, 48, 23, 61, 6, 58, 37, 12, 40, 49, 16, 39, 20, 44, 0, 62, 8, 21, 3, 59, 23, 32, 49, 31, 12, 44, 22, 59, 18, 50, 24, 7, 43, 52, 15, 23, 41, 26, 51, 28, 55, 39, 21, 27, 10, 42, 12, 45, 27, 47, 3, 15, 63, 26, 55, 0, 60, 26, 45, 18, 62, 38, 58, 49, 8, 47, 4, 33, 46, 29, 57, 13, 56, 16, 59, 21, 5, 47, 23, 39, 18, 44, 13, 22, 28, 53, 19, 0, 58, 32, 41, 7, 26, 13 },
-  { 0, 56, 34, 28, 11, 55, 31, 47, 26, 41, 56, 13, 53, 28, 11, 49, 7, 52, 32, 61, 50, 22, 63, 17, 13, 56, 7, 19, 43, 62, 10, 21, 37, 32, 43, 4, 38, 19, 44, 25, 31, 54, 5, 23, 61, 30, 53, 12, 35, 22, 43, 53, 37, 48, 7, 62, 20, 2, 61, 41, 8, 34, 47, 9, 63, 34, 28, 10, 55, 33, 14, 57, 7, 47, 9, 61, 4, 49, 31, 50, 21, 38, 8, 16, 57, 44, 33, 5, 49, 36, 12, 50, 7, 34, 10, 25, 2, 22, 36, 15, 26, 61, 18, 9, 22, 46, 32, 8, 27, 37, 44, 30, 55, 3, 62, 24, 38, 56, 5, 45, 38, 24, 43, 10, 19, 54, 39, 61 },
-  { 41, 30, 8, 63, 43, 23, 38, 3, 62, 19, 8, 49, 25, 1, 58, 30, 23, 40, 9, 28, 18, 40, 6, 38, 49, 22, 35, 59, 8, 27, 50, 5, 56, 17, 11, 50, 30, 9, 55, 2, 51, 19, 34, 47, 9, 41, 6, 26, 48, 57, 14, 28, 17, 12, 39, 13, 37, 46, 25, 19, 54, 27, 1, 37, 16, 45, 20, 60, 1, 48, 20, 38, 31, 22, 42, 15, 19, 44, 1, 61, 6, 34, 56, 40, 29, 10, 20, 46, 13, 22, 41, 23, 59, 42, 30, 51, 45, 13, 63, 53, 42, 12, 51, 38, 62, 2, 26, 41, 50, 1, 61, 10, 19, 42, 31, 8, 49, 32, 12, 63, 9, 52, 16, 56, 36, 2, 31, 16 },
-  { 52, 5, 47, 20, 1, 53, 12, 50, 16, 35, 43, 21, 33, 43, 16, 44, 3, 59, 14, 46, 1, 30, 60, 33, 2, 45, 12, 42, 31, 47, 14, 33, 46, 25, 55, 27, 60, 36, 16, 42, 14, 46, 26, 1, 55, 15, 63, 32, 2, 38, 5, 47, 33, 61, 30, 52, 4, 57, 6, 38, 11, 43, 61, 24, 52, 3, 31, 22, 42, 10, 62, 3, 59, 11, 35, 57, 33, 54, 24, 14, 29, 48, 18, 2, 60, 41, 53, 24, 32, 62, 3, 53, 15, 1, 55, 17, 32, 40, 6, 31, 1, 40, 28, 5, 35, 52, 19, 63, 13, 33, 17, 41, 52, 26, 15, 57, 1, 20, 42, 17, 35, 27, 48, 5, 25, 50, 44, 11 },
-  { 35, 25, 38, 57, 33, 17, 40, 6, 59, 27, 54, 5, 61, 10, 52, 26, 36, 19, 51, 35, 57, 48, 11, 20, 54, 25, 61, 16, 1, 58, 24, 61, 3, 39, 7, 47, 1, 22, 49, 28, 63, 10, 58, 32, 17, 36, 45, 19, 51, 29, 59, 10, 50, 1, 23, 42, 18, 29, 51, 21, 56, 32, 14, 5, 40, 58, 47, 13, 54, 35, 29, 45, 18, 52, 26, 2, 38, 8, 46, 36, 58, 11, 52, 35, 17, 28, 1, 58, 9, 39, 17, 28, 37, 48, 20, 9, 57, 24, 50, 19, 58, 16, 48, 25, 43, 11, 35, 6, 45, 24, 56, 4, 36, 7, 47, 35, 52, 28, 59, 30, 2, 61, 21, 33, 63, 12, 18, 59 },
-  { 3, 49, 15, 10, 27, 61, 25, 45, 30, 0, 14, 47, 31, 38, 17, 62, 7, 55, 27, 4, 15, 24, 42, 52, 10, 34, 5, 51, 36, 18, 41, 11, 35, 21, 62, 13, 33, 57, 8, 35, 5, 40, 21, 43, 52, 3, 24, 56, 11, 16, 33, 25, 41, 20, 55, 8, 60, 35, 15, 48, 2, 57, 30, 49, 18, 25, 6, 39, 17, 57, 7, 25, 43, 5, 49, 16, 62, 22, 55, 4, 25, 43, 23, 7, 50, 11, 37, 48, 14, 51, 33, 57, 7, 27, 39, 46, 4, 29, 11, 43, 34, 56, 7, 60, 20, 54, 30, 57, 22, 49, 9, 33, 54, 14, 63, 23, 6, 43, 10, 40, 50, 13, 44, 8, 38, 33, 46, 23 },
-  { 55, 39, 22, 50, 44, 4, 36, 9, 52, 23, 37, 59, 21, 2, 46, 13, 31, 41, 11, 45, 62, 29, 6, 37, 19, 48, 30, 23, 44, 7, 53, 28, 54, 16, 41, 29, 44, 18, 52, 24, 60, 15, 48, 7, 27, 59, 9, 34, 42, 54, 7, 63, 4, 46, 31, 27, 45, 0, 40, 26, 34, 17, 37, 10, 53, 29, 36, 50, 2, 27, 51, 11, 61, 37, 23, 41, 30, 7, 18, 50, 39, 14, 63, 32, 45, 61, 19, 30, 25, 44, 2, 47, 23, 63, 11, 34, 59, 37, 60, 3, 22, 14, 44, 30, 15, 0, 47, 15, 3, 38, 61, 20, 27, 45, 11, 39, 51, 16, 55, 3, 22, 54, 29, 58, 1, 57, 6, 29 },
-  { 9, 17, 60, 2, 34, 56, 20, 62, 39, 12, 49, 6, 29, 56, 34, 48, 0, 58, 22, 38, 18, 43, 56, 0, 63, 14, 55, 3, 59, 31, 15, 45, 0, 49, 6, 58, 3, 38, 12, 45, 0, 37, 29, 57, 13, 39, 30, 49, 0, 23, 44, 36, 16, 57, 13, 54, 11, 24, 63, 9, 53, 7, 62, 42, 0, 59, 15, 23, 63, 34, 40, 16, 32, 0, 53, 12, 48, 28, 59, 33, 0, 53, 9, 27, 3, 22, 54, 5, 56, 9, 61, 13, 42, 14, 52, 19, 0, 21, 47, 27, 53, 36, 3, 50, 39, 58, 25, 40, 53, 28, 12, 50, 0, 59, 32, 2, 21, 34, 26, 46, 37, 7, 18, 47, 24, 14, 53, 42 },
-  { 61, 32, 13, 54, 29, 7, 46, 13, 28, 57, 18, 41, 53, 15, 9, 39, 24, 49, 33, 3, 53, 9, 26, 32, 40, 28, 46, 39, 25, 9, 56, 21, 63, 37, 26, 22, 51, 27, 17, 56, 31, 53, 4, 43, 22, 46, 12, 18, 60, 40, 20, 26, 50, 21, 39, 5, 49, 33, 16, 44, 22, 46, 20, 32, 24, 45, 8, 43, 12, 46, 4, 48, 56, 20, 29, 58, 3, 40, 10, 42, 31, 21, 47, 41, 56, 38, 15, 42, 36, 27, 20, 33, 55, 3, 26, 44, 31, 54, 12, 35, 9, 63, 28, 10, 21, 32, 9, 60, 17, 8, 43, 29, 40, 16, 36, 48, 60, 7, 57, 14, 62, 31, 42, 15, 36, 40, 20, 26 },
-  { 0, 37, 47, 23, 41, 18, 32, 48, 1, 35, 8, 25, 4, 26, 63, 20, 54, 8, 16, 61, 35, 23, 51, 15, 58, 7, 12, 20, 50, 34, 42, 4, 38, 10, 32, 47, 8, 60, 41, 20, 9, 25, 50, 19, 62, 1, 37, 56, 28, 8, 53, 11, 3, 58, 34, 43, 19, 60, 38, 4, 58, 31, 3, 51, 11, 55, 38, 30, 21, 58, 19, 26, 9, 44, 36, 13, 46, 20, 62, 24, 13, 60, 5, 28, 12, 34, 7, 59, 0, 53, 45, 6, 38, 30, 50, 7, 62, 16, 41, 5, 46, 18, 55, 42, 51, 5, 45, 23, 34, 48, 19, 58, 5, 25, 54, 19, 13, 41, 28, 21, 0, 49, 10, 60, 4, 51, 9, 45 },
-  { 19, 28, 6, 58, 10, 51, 4, 22, 55, 42, 60, 45, 34, 51, 42, 5, 30, 45, 27, 40, 13, 47, 4, 49, 21, 38, 60, 29, 2, 57, 17, 27, 52, 19, 61, 14, 30, 34, 2, 44, 63, 33, 11, 35, 16, 51, 25, 6, 14, 47, 31, 61, 37, 29, 18, 8, 52, 2, 28, 54, 13, 41, 15, 62, 35, 18, 2, 60, 6, 33, 41, 61, 31, 6, 56, 17, 34, 50, 6, 52, 44, 35, 16, 51, 59, 24, 48, 18, 31, 40, 16, 49, 21, 60, 17, 39, 10, 49, 32, 57, 24, 39, 1, 25, 18, 62, 37, 12, 56, 1, 37, 11, 52, 44, 9, 30, 47, 4, 51, 40, 55, 25, 34, 27, 56, 30, 32, 54 },
-  { 63, 40, 49, 15, 43, 26, 63, 38, 16, 20, 30, 12, 57, 14, 19, 60, 36, 12, 59, 2, 57, 17, 42, 31, 1, 44, 16, 35, 47, 11, 32, 48, 13, 43, 1, 39, 51, 12, 57, 23, 6, 40, 53, 3, 55, 31, 39, 60, 35, 44, 5, 15, 45, 1, 62, 41, 26, 14, 47, 22, 36, 27, 50, 9, 26, 47, 52, 28, 54, 16, 1, 13, 51, 39, 23, 63, 1, 30, 15, 26, 2, 57, 19, 37, 1, 44, 21, 50, 13, 63, 8, 24, 56, 1, 35, 25, 58, 20, 2, 28, 14, 51, 33, 59, 13, 30, 4, 49, 31, 24, 63, 26, 33, 3, 58, 38, 62, 24, 32, 8, 17, 45, 5, 48, 18, 3, 43, 11 },
-  { 21, 4, 24, 34, 59, 1, 37, 11, 53, 5, 47, 2, 22, 40, 32, 1, 24, 50, 21, 29, 38, 25, 63, 8, 55, 24, 53, 6, 62, 23, 59, 3, 54, 20, 58, 24, 5, 46, 15, 38, 48, 14, 27, 42, 23, 7, 46, 10, 17, 58, 25, 52, 23, 32, 49, 12, 55, 30, 40, 7, 59, 1, 56, 21, 39, 4, 23, 15, 37, 46, 55, 42, 21, 4, 48, 8, 45, 54, 37, 55, 32, 8, 46, 10, 30, 54, 4, 41, 25, 29, 36, 48, 11, 43, 14, 47, 5, 43, 53, 36, 61, 10, 45, 6, 41, 54, 27, 43, 16, 55, 6, 46, 18, 42, 23, 15, 1, 45, 12, 60, 37, 22, 62, 12, 39, 59, 16, 52 },
-  { 47, 35, 56, 7, 19, 46, 31, 50, 33, 24, 61, 35, 50, 7, 53, 44, 55, 6, 46, 10, 52, 5, 21, 43, 36, 10, 18, 41, 26, 37, 8, 29, 40, 36, 9, 49, 34, 26, 61, 21, 7, 59, 18, 62, 29, 54, 20, 32, 51, 0, 40, 10, 55, 6, 20, 36, 9, 61, 5, 51, 44, 19, 33, 43, 13, 57, 40, 63, 8, 24, 29, 10, 60, 34, 27, 40, 25, 18, 10, 42, 21, 49, 26, 62, 38, 12, 33, 61, 5, 57, 2, 19, 54, 28, 62, 22, 38, 31, 16, 7, 22, 47, 29, 17, 35, 8, 20, 51, 2, 40, 22, 50, 13, 61, 28, 53, 35, 20, 56, 30, 2, 53, 14, 41, 23, 34, 8, 31 },
-  { 12, 2, 42, 29, 52, 13, 21, 8, 55, 14, 41, 17, 28, 58, 23, 11, 17, 36, 31, 62, 17, 34, 50, 14, 28, 61, 33, 52, 2, 51, 17, 45, 7, 25, 62, 30, 18, 55, 0, 42, 30, 35, 45, 1, 12, 48, 3, 63, 21, 36, 30, 48, 19, 59, 43, 27, 46, 17, 34, 25, 12, 29, 53, 6, 48, 31, 11, 34, 49, 3, 36, 50, 19, 47, 14, 61, 11, 36, 58, 4, 60, 14, 39, 22, 6, 52, 15, 35, 17, 46, 31, 42, 9, 34, 3, 52, 12, 60, 26, 56, 40, 2, 53, 23, 57, 38, 62, 14, 36, 59, 10, 31, 39, 6, 49, 9, 41, 26, 5, 48, 43, 27, 33, 58, 1, 50, 25, 57 },
-  { 61, 37, 15, 61, 3, 39, 58, 43, 26, 0, 44, 10, 47, 3, 37, 63, 28, 43, 13, 39, 3, 57, 30, 59, 0, 48, 5, 43, 13, 22, 60, 33, 55, 15, 42, 4, 52, 10, 45, 13, 54, 4, 24, 49, 37, 26, 41, 14, 42, 9, 61, 13, 38, 23, 3, 53, 0, 58, 21, 42, 63, 10, 17, 61, 25, 0, 58, 28, 17, 44, 57, 12, 27, 0, 55, 5, 52, 28, 23, 47, 29, 0, 43, 17, 58, 28, 47, 23, 55, 10, 58, 23, 51, 40, 18, 33, 45, 0, 49, 8, 32, 61, 19, 48, 0, 26, 7, 47, 29, 18, 44, 0, 56, 34, 20, 59, 15, 51, 37, 18, 10, 52, 7, 20, 46, 9, 38, 17 },
-  { 6, 27, 48, 23, 45, 29, 5, 18, 38, 62, 27, 56, 20, 32, 15, 9, 48, 0, 54, 22, 45, 20, 7, 41, 23, 39, 19, 27, 58, 31, 44, 0, 12, 50, 23, 56, 20, 39, 32, 59, 16, 52, 33, 9, 57, 22, 6, 58, 28, 50, 24, 2, 56, 35, 16, 45, 32, 38, 15, 54, 2, 38, 46, 22, 35, 45, 20, 5, 52, 25, 7, 35, 59, 32, 22, 43, 38, 3, 51, 16, 34, 53, 32, 50, 3, 40, 8, 43, 0, 39, 27, 4, 14, 61, 8, 55, 15, 41, 20, 44, 27, 13, 39, 11, 46, 42, 54, 33, 4, 52, 23, 61, 14, 25, 43, 2, 33, 11, 63, 29, 61, 17, 40, 55, 22, 62, 28, 44 },
-  { 20, 54, 8, 56, 35, 10, 63, 31, 52, 12, 48, 6, 59, 41, 52, 33, 19, 58, 25, 49, 11, 37, 47, 12, 54, 15, 56, 35, 7, 47, 16, 53, 28, 34, 5, 37, 28, 8, 48, 3, 28, 38, 18, 61, 16, 43, 53, 32, 4, 17, 47, 27, 44, 8, 63, 10, 25, 49, 6, 37, 24, 52, 32, 3, 50, 12, 41, 56, 38, 14, 62, 20, 40, 16, 53, 31, 18, 63, 41, 9, 59, 7, 13, 25, 57, 20, 63, 26, 53, 18, 48, 62, 30, 46, 21, 25, 58, 29, 36, 4, 55, 34, 6, 60, 31, 16, 21, 12, 58, 38, 9, 29, 47, 7, 52, 30, 57, 44, 22, 0, 35, 45, 3, 31, 14, 36, 0, 51 },
-  { 42, 14, 33, 24, 16, 49, 40, 2, 22, 33, 16, 36, 25, 1, 21, 61, 38, 8, 33, 4, 62, 26, 29, 60, 6, 46, 30, 11, 63, 4, 36, 40, 19, 57, 46, 11, 41, 63, 22, 25, 58, 10, 46, 2, 34, 27, 11, 38, 56, 34, 12, 53, 18, 33, 41, 51, 13, 28, 60, 20, 47, 14, 29, 59, 16, 62, 8, 22, 32, 47, 9, 49, 2, 44, 7, 12, 45, 6, 20, 27, 45, 24, 62, 42, 36, 11, 33, 15, 37, 7, 32, 10, 37, 1, 35, 50, 6, 11, 63, 24, 52, 15, 50, 24, 3, 37, 56, 27, 34, 22, 49, 16, 36, 62, 17, 39, 4, 15, 54, 24, 50, 8, 58, 26, 49, 54, 11, 30 },
-  { 4, 59, 41, 1, 53, 12, 25, 45, 59, 7, 51, 39, 54, 14, 46, 4, 27, 53, 16, 44, 18, 51, 1, 32, 25, 2, 50, 40, 20, 54, 24, 9, 62, 2, 27, 60, 1, 17, 36, 50, 6, 40, 30, 55, 41, 19, 49, 1, 21, 60, 40, 5, 62, 1, 22, 30, 57, 4, 43, 31, 1, 55, 40, 7, 27, 37, 30, 54, 1, 19, 42, 30, 56, 26, 62, 49, 24, 57, 37, 56, 2, 39, 16, 5, 30, 55, 3, 49, 60, 23, 56, 44, 17, 52, 13, 42, 28, 48, 18, 45, 9, 37, 21, 41, 58, 10, 48, 1, 63, 5, 41, 57, 2, 24, 12, 48, 27, 42, 32, 46, 13, 38, 19, 34, 5, 41, 25, 60 },
-  { 39, 28, 21, 46, 32, 57, 36, 9, 19, 42, 4, 29, 11, 43, 30, 49, 13, 42, 35, 56, 9, 39, 15, 52, 36, 61, 18, 26, 45, 14, 31, 48, 21, 43, 14, 33, 49, 54, 14, 44, 21, 62, 13, 23, 8, 62, 15, 51, 44, 7, 30, 37, 20, 42, 56, 7, 39, 18, 50, 11, 61, 9, 19, 43, 57, 2, 48, 11, 39, 60, 28, 4, 37, 17, 35, 1, 33, 11, 31, 14, 48, 19, 35, 51, 46, 21, 44, 29, 12, 41, 2, 22, 58, 26, 54, 4, 59, 38, 2, 33, 57, 1, 63, 13, 28, 51, 15, 40, 18, 45, 8, 30, 43, 37, 54, 19, 8, 59, 21, 6, 60, 29, 55, 10, 63, 15, 47, 17 },
-  { 3, 50, 10, 62, 18, 5, 27, 49, 60, 23, 55, 18, 62, 24, 56, 10, 59, 28, 2, 23, 34, 59, 43, 20, 10, 42, 8, 49, 1, 37, 57, 6, 51, 29, 53, 7, 23, 31, 5, 32, 51, 0, 35, 54, 45, 31, 5, 26, 36, 24, 55, 15, 48, 29, 14, 48, 26, 60, 21, 41, 36, 26, 50, 33, 14, 44, 17, 24, 52, 15, 46, 23, 54, 6, 47, 21, 60, 50, 4, 53, 29, 61, 8, 23, 1, 60, 19, 6, 53, 16, 47, 34, 6, 39, 16, 31, 12, 20, 53, 22, 30, 43, 25, 46, 35, 6, 44, 32, 53, 26, 55, 19, 11, 59, 5, 33, 51, 1, 35, 53, 25, 3, 42, 23, 44, 32, 7, 53 },
-  { 22, 44, 37, 6, 26, 51, 38, 0, 34, 13, 31, 46, 3, 37, 6, 19, 40, 21, 47, 63, 12, 5, 29, 55, 22, 58, 34, 28, 60, 22, 11, 41, 17, 38, 9, 44, 59, 39, 56, 19, 11, 47, 25, 15, 3, 39, 57, 17, 61, 11, 46, 3, 58, 9, 54, 35, 2, 34, 8, 45, 15, 56, 5, 23, 53, 33, 63, 35, 4, 59, 10, 51, 13, 61, 29, 41, 15, 25, 43, 19, 40, 10, 54, 33, 41, 12, 38, 51, 31, 26, 61, 9, 30, 45, 24, 62, 49, 40, 10, 61, 14, 49, 5, 17, 54, 20, 60, 23, 3, 13, 35, 50, 32, 23, 46, 27, 38, 63, 16, 12, 39, 48, 18, 51, 1, 27, 56, 35 },
-  { 63, 15, 30, 55, 43, 14, 57, 17, 53, 44, 7, 48, 26, 50, 32, 60, 0, 53, 14, 31, 50, 24, 46, 0, 38, 13, 4, 52, 16, 45, 30, 59, 0, 25, 55, 35, 16, 10, 26, 42, 58, 29, 60, 38, 50, 22, 28, 47, 0, 50, 28, 19, 33, 39, 11, 44, 16, 52, 24, 59, 3, 38, 27, 51, 0, 21, 7, 42, 26, 34, 21, 40, 33, 18, 39, 3, 54, 38, 8, 59, 0, 44, 27, 15, 58, 28, 57, 9, 43, 0, 36, 50, 20, 59, 8, 34, 0, 27, 47, 7, 36, 19, 56, 32, 0, 38, 11, 29, 62, 47, 6, 61, 0, 41, 14, 56, 10, 23, 45, 31, 57, 8, 36, 13, 58, 38, 11, 19 },
-  { 0, 34, 12, 47, 21, 2, 40, 30, 11, 25, 61, 20, 40, 15, 35, 22, 45, 36, 7, 41, 17, 57, 9, 48, 32, 62, 44, 24, 35, 3, 54, 13, 33, 63, 19, 4, 48, 22, 62, 2, 37, 8, 33, 6, 20, 52, 9, 32, 43, 13, 39, 63, 25, 4, 49, 23, 62, 32, 9, 30, 48, 18, 63, 12, 46, 29, 58, 13, 48, 8, 57, 31, 0, 51, 9, 58, 12, 22, 47, 29, 35, 22, 49, 5, 46, 4, 34, 20, 63, 24, 56, 11, 41, 3, 51, 19, 56, 35, 17, 58, 28, 42, 9, 45, 59, 26, 51, 42, 17, 36, 25, 15, 53, 21, 44, 3, 30, 55, 5, 50, 21, 28, 61, 32, 6, 49, 28, 46 },
-  { 58, 42, 60, 4, 31, 59, 22, 63, 35, 38, 9, 54, 1, 57, 8, 51, 16, 58, 27, 53, 3, 38, 30, 15, 27, 6, 19, 56, 10, 50, 21, 36, 47, 5, 43, 28, 51, 32, 13, 46, 18, 54, 16, 43, 63, 12, 36, 59, 22, 34, 5, 52, 17, 59, 27, 41, 0, 19, 55, 37, 13, 43, 6, 34, 41, 10, 36, 55, 19, 44, 3, 16, 58, 27, 49, 25, 32, 62, 17, 55, 13, 63, 18, 52, 25, 37, 17, 48, 13, 32, 5, 46, 28, 37, 14, 43, 25, 5, 51, 39, 3, 52, 33, 22, 8, 40, 12, 4, 57, 9, 46, 39, 28, 58, 13, 62, 17, 42, 19, 36, 0, 47, 16, 43, 24, 21, 54, 13 },
-  { 25, 9, 23, 50, 36, 8, 45, 14, 3, 51, 16, 28, 44, 12, 42, 29, 4, 26, 10, 47, 22, 61, 18, 54, 51, 39, 46, 13, 41, 26, 58, 7, 18, 39, 12, 57, 15, 1, 52, 27, 41, 23, 48, 1, 27, 45, 18, 2, 57, 26, 55, 8, 43, 31, 6, 58, 14, 51, 40, 5, 61, 31, 24, 54, 17, 60, 22, 1, 39, 30, 53, 45, 36, 13, 43, 5, 45, 2, 37, 6, 34, 42, 2, 39, 10, 62, 7, 54, 40, 18, 60, 15, 52, 21, 63, 8, 55, 46, 15, 30, 23, 13, 62, 16, 50, 24, 58, 31, 48, 21, 34, 2, 49, 7, 31, 37, 26, 48, 9, 61, 40, 11, 52, 2, 60, 40, 4, 37 },
-  { 52, 28, 39, 16, 54, 19, 29, 55, 42, 20, 58, 33, 24, 63, 18, 55, 39, 62, 43, 34, 12, 40, 6, 35, 2, 25, 8, 62, 34, 1, 31, 42, 61, 27, 53, 24, 40, 61, 34, 8, 59, 4, 30, 56, 40, 6, 53, 42, 10, 48, 16, 37, 12, 46, 21, 36, 47, 11, 28, 45, 22, 10, 57, 2, 49, 31, 14, 44, 61, 11, 25, 6, 23, 63, 18, 36, 28, 56, 20, 51, 11, 48, 27, 56, 32, 22, 45, 30, 2, 42, 27, 39, 1, 44, 23, 31, 38, 22, 11, 61, 43, 54, 4, 47, 35, 2, 44, 16, 28, 54, 12, 62, 18, 43, 10, 52, 1, 58, 33, 15, 29, 56, 20, 34, 9, 30, 48, 17 },
-  { 46, 2, 56, 11, 41, 1, 49, 6, 27, 47, 2, 48, 5, 32, 37, 3, 13, 19, 32, 1, 55, 28, 60, 17, 43, 59, 32, 20, 49, 16, 55, 23, 14, 46, 2, 36, 6, 30, 20, 49, 12, 47, 35, 14, 21, 60, 29, 14, 35, 24, 46, 1, 56, 29, 53, 8, 33, 23, 56, 1, 35, 46, 20, 39, 26, 4, 53, 28, 17, 38, 60, 34, 48, 9, 55, 15, 46, 7, 41, 31, 60, 24, 16, 36, 1, 59, 19, 52, 35, 6, 55, 11, 59, 33, 7, 57, 4, 29, 48, 1, 19, 26, 37, 30, 18, 63, 37, 6, 59, 1, 40, 24, 56, 33, 46, 22, 35, 7, 24, 53, 39, 5, 26, 45, 55, 18, 62, 7 },
-  { 20, 60, 29, 34, 20, 62, 33, 52, 10, 36, 13, 60, 41, 21, 50, 27, 56, 49, 8, 51, 21, 45, 11, 48, 8, 23, 53, 3, 29, 44, 5, 52, 9, 32, 50, 17, 43, 56, 3, 38, 24, 10, 62, 25, 51, 9, 33, 49, 61, 7, 30, 62, 22, 19, 2, 42, 63, 5, 49, 18, 60, 15, 52, 7, 43, 56, 23, 50, 5, 50, 2, 20, 41, 30, 1, 52, 22, 61, 14, 26, 3, 43, 53, 7, 47, 28, 11, 14, 23, 58, 33, 25, 47, 13, 50, 17, 40, 54, 34, 60, 41, 6, 59, 14, 50, 7, 25, 55, 20, 42, 51, 8, 27, 4, 16, 60, 28, 50, 44, 3, 22, 49, 63, 12, 33, 1, 43, 31 },
-  { 36, 5, 46, 8, 44, 24, 13, 39, 25, 57, 31, 18, 8, 52, 10, 45, 6, 30, 36, 24, 63, 4, 33, 26, 57, 40, 15, 56, 37, 12, 40, 25, 37, 58, 11, 63, 21, 45, 16, 60, 31, 53, 18, 33, 3, 45, 23, 0, 20, 54, 40, 15, 50, 38, 60, 16, 25, 42, 29, 38, 7, 41, 25, 62, 18, 33, 8, 35, 42, 16, 32, 56, 12, 39, 59, 19, 34, 9, 49, 38, 57, 12, 21, 50, 14, 40, 61, 44, 50, 9, 49, 19, 3, 29, 35, 62, 12, 24, 7, 18, 52, 32, 10, 46, 21, 41, 32, 11, 36, 29, 14, 34, 60, 38, 54, 11, 41, 14, 19, 57, 32, 16, 7, 41, 51, 25, 14, 57 },
-  { 53, 18, 26, 50, 15, 58, 4, 63, 17, 43, 7, 40, 61, 35, 15, 41, 23, 60, 16, 38, 14, 42, 19, 50, 0, 31, 10, 46, 27, 63, 18, 60, 0, 20, 29, 39, 8, 26, 37, 5, 42, 0, 44, 39, 57, 17, 58, 41, 28, 37, 4, 32, 9, 44, 12, 31, 54, 10, 59, 14, 27, 53, 12, 36, 0, 47, 13, 63, 21, 58, 10, 24, 50, 27, 4, 26, 44, 53, 31, 0, 18, 42, 29, 33, 57, 4, 32, 26, 0, 38, 16, 61, 41, 53, 20, 0, 42, 44, 49, 27, 10, 56, 39, 0, 57, 15, 53, 49, 3, 61, 22, 47, 17, 5, 49, 26, 2, 63, 39, 10, 47, 27, 37, 23, 4, 59, 38, 10 },
-  { 23, 39, 61, 3, 37, 28, 48, 31, 0, 34, 51, 23, 2, 26, 58, 0, 53, 11, 46, 1, 57, 29, 52, 14, 37, 61, 21, 35, 2, 49, 7, 34, 47, 55, 4, 33, 54, 13, 58, 52, 19, 50, 22, 7, 13, 29, 36, 11, 51, 17, 60, 25, 55, 4, 34, 51, 0, 35, 20, 48, 32, 3, 51, 30, 59, 28, 40, 3, 46, 29, 54, 43, 7, 62, 47, 11, 39, 4, 23, 46, 55, 8, 63, 5, 25, 37, 18, 46, 21, 56, 31, 5, 36, 8, 45, 58, 26, 15, 2, 36, 47, 21, 29, 44, 25, 34, 3, 27, 43, 10, 52, 0, 45, 30, 24, 36, 43, 18, 34, 59, 0, 52, 61, 15, 44, 19, 30, 49 },
-  { 0, 27, 12, 43, 54, 9, 22, 53, 21, 46, 15, 55, 29, 47, 20, 33, 39, 28, 59, 35, 9, 44, 5, 24, 47, 7, 52, 17, 56, 22, 30, 42, 14, 26, 45, 18, 49, 1, 24, 34, 11, 27, 55, 32, 61, 47, 2, 56, 6, 44, 13, 47, 36, 27, 58, 22, 16, 47, 40, 4, 57, 38, 21, 45, 16, 9, 56, 26, 11, 38, 0, 22, 36, 17, 33, 57, 16, 30, 62, 15, 35, 40, 20, 45, 59, 10, 54, 8, 63, 13, 52, 27, 22, 57, 28, 12, 32, 51, 55, 22, 63, 4, 16, 54, 12, 62, 45, 19, 58, 13, 32, 40, 20, 56, 7, 57, 9, 54, 6, 29, 42, 21, 8, 55, 35, 47, 6, 41 },
-  { 56, 33, 58, 32, 19, 35, 42, 6, 59, 11, 38, 5, 49, 12, 62, 7, 52, 17, 5, 25, 54, 20, 61, 31, 54, 27, 41, 11, 44, 5, 59, 12, 36, 51, 10, 61, 28, 41, 48, 9, 43, 63, 5, 40, 20, 8, 49, 26, 34, 21, 58, 1, 18, 45, 7, 39, 61, 26, 8, 50, 23, 10, 63, 5, 55, 37, 19, 49, 52, 15, 59, 47, 13, 54, 1, 25, 42, 58, 10, 48, 3, 27, 50, 1, 17, 48, 34, 41, 16, 40, 2, 45, 10, 39, 17, 61, 5, 38, 19, 9, 41, 31, 60, 38, 5, 23, 36, 8, 30, 55, 24, 63, 12, 48, 14, 51, 31, 20, 45, 25, 12, 50, 32, 2, 28, 11, 62, 14 },
-  { 44, 16, 7, 48, 1, 62, 16, 50, 27, 33, 61, 25, 17, 44, 31, 14, 22, 43, 32, 48, 18, 40, 8, 36, 3, 16, 33, 62, 23, 38, 25, 53, 2, 21, 41, 6, 22, 15, 59, 29, 16, 37, 26, 15, 52, 42, 23, 15, 54, 39, 10, 30, 53, 11, 49, 24, 2, 43, 55, 17, 34, 44, 15, 31, 24, 44, 2, 32, 7, 35, 25, 5, 40, 45, 29, 51, 6, 21, 37, 52, 24, 60, 13, 31, 53, 23, 2, 28, 49, 24, 31, 60, 20, 51, 1, 34, 48, 14, 59, 33, 50, 1, 18, 33, 48, 60, 17, 51, 39, 6, 38, 2, 35, 29, 40, 23, 1, 62, 15, 53, 37, 17, 46, 57, 40, 51, 24, 22 },
-  { 5, 37, 52, 24, 45, 13, 40, 3, 45, 9, 19, 42, 56, 4, 37, 46, 56, 2, 63, 11, 51, 1, 49, 13, 59, 45, 39, 1, 48, 15, 58, 9, 46, 31, 54, 35, 57, 38, 3, 46, 56, 4, 47, 57, 1, 30, 38, 63, 3, 46, 28, 63, 41, 14, 33, 62, 19, 32, 13, 28, 61, 1, 53, 42, 11, 60, 22, 62, 27, 42, 61, 31, 19, 8, 61, 12, 32, 55, 2, 18, 33, 12, 43, 36, 9, 62, 30, 55, 6, 58, 35, 7, 43, 29, 54, 23, 43, 30, 3, 25, 11, 45, 52, 28, 7, 14, 42, 1, 22, 50, 16, 53, 19, 59, 4, 46, 33, 41, 4, 35, 58, 5, 26, 13, 20, 2, 34, 54 },
-  { 30, 63, 21, 10, 26, 55, 29, 59, 23, 39, 53, 1, 36, 24, 59, 27, 10, 34, 23, 38, 30, 60, 22, 42, 28, 19, 9, 57, 30, 19, 43, 33, 13, 63, 3, 19, 11, 50, 31, 20, 14, 34, 10, 35, 17, 59, 7, 31, 19, 25, 50, 5, 20, 57, 29, 6, 52, 41, 4, 46, 20, 37, 26, 17, 49, 6, 39, 18, 53, 14, 3, 49, 57, 23, 34, 48, 14, 41, 28, 38, 56, 6, 58, 25, 39, 19, 43, 15, 37, 11, 47, 18, 53, 4, 37, 9, 62, 21, 53, 40, 57, 24, 13, 40, 56, 26, 47, 31, 59, 25, 45, 27, 10, 43, 21, 61, 13, 27, 48, 9, 23, 43, 31, 62, 38, 59, 9, 47 },
-  { 25, 4, 40, 60, 34, 6, 18, 36, 8, 57, 12, 30, 49, 14, 6, 54, 41, 16, 50, 6, 43, 15, 34, 4, 53, 24, 50, 35, 4, 51, 7, 55, 28, 24, 39, 44, 60, 7, 25, 62, 42, 53, 24, 61, 28, 45, 52, 12, 48, 37, 9, 35, 43, 3, 37, 48, 12, 58, 30, 52, 9, 59, 6, 57, 33, 29, 48, 4, 37, 45, 20, 34, 10, 39, 0, 60, 22, 45, 8, 63, 21, 42, 14, 49, 3, 56, 11, 46, 21, 61, 0, 42, 25, 13, 63, 17, 36, 8, 46, 16, 6, 35, 63, 0, 21, 37, 4, 57, 9, 34, 5, 61, 48, 32, 8, 37, 54, 17, 56, 30, 60, 0, 50, 16, 7, 29, 42, 17 },
-  { 32, 50, 15, 48, 2, 43, 52, 25, 47, 16, 32, 63, 21, 52, 40, 19, 0, 61, 29, 58, 20, 56, 26, 46, 12, 55, 6, 22, 62, 32, 17, 40, 0, 49, 34, 8, 27, 32, 48, 0, 21, 39, 5, 44, 12, 6, 22, 40, 0, 57, 16, 60, 23, 17, 54, 22, 36, 15, 24, 39, 19, 34, 47, 23, 0, 54, 13, 51, 24, 9, 55, 16, 52, 27, 44, 20, 4, 54, 26, 49, 0, 30, 46, 16, 29, 51, 34, 4, 52, 28, 33, 15, 57, 39, 26, 49, 0, 56, 27, 31, 48, 20, 43, 29, 53, 11, 46, 19, 41, 13, 55, 18, 0, 57, 26, 51, 2, 44, 6, 38, 14, 40, 22, 45, 36, 53, 3, 57 },
-  { 44, 12, 37, 28, 22, 57, 11, 38, 0, 51, 9, 41, 4, 29, 11, 47, 33, 45, 12, 26, 3, 36, 9, 63, 31, 16, 38, 44, 14, 47, 25, 61, 20, 58, 15, 47, 17, 57, 13, 36, 9, 51, 18, 29, 50, 36, 54, 20, 61, 27, 32, 13, 53, 44, 9, 27, 0, 63, 45, 2, 56, 10, 14, 43, 41, 28, 58, 11, 35, 60, 30, 41, 6, 63, 11, 51, 37, 32, 15, 10, 35, 53, 5, 61, 22, 7, 26, 59, 23, 9, 44, 48, 21, 3, 51, 32, 24, 41, 12, 61, 2, 55, 9, 15, 35, 58, 28, 15, 62, 30, 37, 23, 42, 29, 11, 17, 35, 24, 63, 20, 52, 28, 8, 55, 11, 23, 47, 19 },
-  { 0, 56, 8, 53, 14, 31, 61, 20, 55, 28, 62, 18, 35, 60, 25, 57, 7, 23, 39, 54, 47, 17, 43, 0, 40, 59, 29, 2, 56, 10, 37, 5, 43, 11, 29, 52, 1, 23, 54, 41, 59, 30, 55, 1, 62, 15, 33, 4, 43, 10, 47, 39, 1, 31, 40, 60, 49, 33, 7, 55, 26, 50, 31, 61, 8, 18, 21, 32, 44, 1, 25, 47, 18, 36, 30, 23, 59, 7, 40, 59, 27, 19, 38, 32, 44, 54, 40, 17, 38, 60, 27, 6, 35, 55, 10, 14, 44, 5, 50, 17, 38, 26, 42, 50, 18, 3, 44, 52, 2, 49, 7, 52, 15, 46, 62, 39, 55, 10, 31, 48, 3, 58, 33, 18, 61, 34, 13, 59 },
-  { 39, 27, 63, 20, 35, 41, 4, 45, 26, 5, 38, 13, 44, 2, 50, 17, 37, 52, 2, 13, 28, 58, 24, 51, 21, 8, 34, 48, 27, 42, 18, 51, 31, 56, 5, 36, 38, 44, 4, 17, 26, 11, 38, 23, 42, 8, 56, 39, 24, 51, 5, 56, 21, 59, 14, 6, 18, 42, 22, 35, 16, 37, 3, 25, 39, 46, 63, 5, 50, 17, 58, 8, 55, 3, 50, 12, 43, 17, 47, 2, 51, 9, 62, 12, 1, 35, 13, 50, 1, 37, 12, 51, 19, 29, 46, 59, 22, 58, 33, 45, 22, 60, 10, 32, 61, 39, 8, 33, 25, 36, 20, 60, 38, 4, 21, 5, 28, 45, 12, 18, 42, 11, 49, 1, 27, 40, 6, 30 },
-  { 24, 16, 42, 1, 50, 10, 48, 17, 33, 43, 24, 48, 21, 55, 31, 42, 10, 21, 63, 35, 49, 6, 33, 13, 41, 53, 10, 20, 60, 6, 53, 26, 12, 41, 22, 60, 14, 28, 63, 33, 49, 3, 45, 16, 48, 26, 14, 46, 18, 30, 35, 26, 8, 50, 29, 51, 25, 57, 12, 47, 53, 9, 62, 20, 54, 2, 36, 15, 40, 28, 33, 13, 38, 24, 46, 1, 29, 56, 33, 20, 44, 24, 41, 26, 57, 20, 63, 8, 30, 55, 5, 41, 62, 8, 34, 2, 37, 10, 19, 6, 37, 1, 53, 23, 5, 27, 58, 22, 43, 12, 50, 26, 9, 34, 54, 32, 49, 1, 59, 37, 22, 46, 25, 36, 51, 15, 54, 46 },
-  { 52, 7, 45, 33, 26, 58, 14, 60, 7, 54, 3, 58, 8, 34, 14, 5, 59, 30, 18, 44, 8, 22, 48, 62, 3, 26, 55, 38, 23, 16, 39, 1, 62, 24, 49, 9, 53, 19, 46, 7, 19, 60, 31, 58, 2, 34, 53, 7, 59, 2, 62, 42, 46, 19, 36, 11, 44, 4, 38, 28, 1, 43, 32, 51, 12, 29, 56, 22, 52, 2, 62, 49, 22, 60, 14, 35, 63, 5, 25, 57, 14, 53, 4, 46, 18, 31, 42, 22, 47, 20, 58, 31, 16, 43, 23, 54, 30, 42, 52, 57, 29, 49, 30, 13, 45, 48, 16, 55, 6, 63, 1, 44, 14, 58, 19, 47, 15, 24, 51, 34, 6, 55, 5, 63, 20, 41, 21, 9 },
-  { 30, 62, 18, 55, 5, 23, 39, 29, 49, 30, 15, 36, 28, 46, 60, 25, 39, 46, 4, 32, 61, 40, 15, 30, 36, 45, 14, 2, 49, 33, 57, 45, 18, 32, 3, 45, 30, 2, 35, 52, 40, 27, 13, 21, 38, 63, 20, 28, 37, 23, 16, 10, 13, 55, 2, 62, 21, 32, 60, 17, 58, 23, 5, 40, 16, 48, 7, 45, 10, 26, 43, 19, 6, 31, 52, 21, 39, 16, 48, 9, 37, 28, 36, 55, 7, 48, 3, 59, 15, 45, 25, 1, 53, 13, 47, 7, 62, 15, 4, 25, 12, 41, 18, 60, 38, 11, 34, 19, 39, 31, 29, 56, 23, 42, 3, 27, 60, 41, 8, 16, 61, 29, 43, 9, 32, 2, 60, 34 },
-  { 3, 38, 13, 37, 52, 44, 2, 19, 12, 42, 63, 19, 40, 1, 20, 50, 12, 55, 15, 56, 27, 1, 54, 11, 57, 18, 32, 63, 44, 4, 29, 13, 37, 61, 35, 16, 42, 57, 12, 22, 6, 55, 43, 10, 50, 5, 44, 11, 48, 52, 34, 58, 28, 41, 38, 30, 7, 52, 11, 49, 30, 14, 45, 27, 59, 34, 21, 38, 32, 58, 11, 36, 56, 42, 9, 41, 3, 54, 31, 42, 0, 60, 16, 11, 39, 24, 52, 33, 6, 36, 10, 40, 32, 60, 26, 20, 39, 28, 47, 34, 63, 8, 54, 3, 24, 56, 0, 51, 13, 47, 16, 40, 7, 35, 52, 11, 36, 4, 57, 30, 39, 13, 18, 50, 58, 28, 12, 48 },
-  { 57, 24, 49, 21, 10, 31, 61, 36, 56, 0, 22, 53, 11, 56, 32, 7, 36, 27, 41, 9, 46, 19, 34, 42, 25, 7, 50, 9, 28, 21, 54, 8, 50, 7, 27, 59, 10, 25, 48, 62, 37, 0, 33, 58, 25, 18, 32, 61, 0, 15, 45, 5, 50, 3, 23, 55, 47, 17, 40, 6, 60, 34, 53, 8, 41, 0, 61, 13, 54, 4, 46, 28, 0, 17, 48, 27, 58, 13, 23, 61, 33, 21, 50, 30, 62, 8, 14, 29, 56, 27, 61, 49, 17, 2, 44, 11, 51, 0, 59, 17, 40, 20, 32, 47, 36, 21, 42, 28, 60, 4, 54, 10, 59, 17, 30, 62, 21, 43, 26, 48, 0, 56, 36, 25, 8, 44, 39, 17 },
-  { 10, 42, 4, 59, 27, 47, 8, 23, 51, 32, 45, 6, 37, 26, 48, 43, 62, 0, 21, 53, 38, 12, 51, 5, 60, 47, 24, 37, 59, 15, 35, 47, 22, 55, 0, 50, 21, 40, 6, 29, 15, 52, 24, 8, 41, 55, 13, 29, 40, 56, 24, 31, 19, 33, 61, 15, 0, 35, 24, 42, 21, 2, 19, 57, 24, 15, 30, 50, 20, 25, 40, 16, 57, 34, 61, 8, 29, 45, 6, 49, 11, 47, 2, 44, 19, 57, 38, 50, 12, 42, 21, 4, 35, 52, 28, 56, 23, 36, 13, 45, 4, 52, 27, 14, 6, 62, 9, 45, 21, 37, 25, 46, 33, 49, 0, 44, 7, 53, 13, 19, 53, 31, 3, 47, 15, 56, 22, 51 },
-  { 35, 28, 53, 32, 1, 16, 54, 40, 9, 17, 25, 58, 14, 59, 3, 22, 16, 51, 31, 5, 23, 58, 28, 17, 35, 20, 0, 42, 11, 52, 3, 31, 41, 17, 43, 13, 32, 54, 18, 60, 32, 45, 17, 49, 2, 36, 51, 22, 7, 36, 9, 63, 48, 12, 46, 26, 43, 28, 63, 13, 48, 37, 51, 33, 5, 47, 55, 9, 42, 63, 7, 51, 24, 12, 37, 19, 55, 34, 18, 38, 15, 28, 54, 34, 5, 43, 22, 0, 48, 14, 54, 24, 58, 9, 38, 5, 32, 55, 21, 30, 49, 9, 59, 43, 30, 51, 35, 26, 7, 53, 2, 22, 14, 27, 57, 18, 38, 24, 33, 45, 10, 41, 20, 60, 37, 5, 32, 0 },
-  { 63, 19, 15, 40, 62, 35, 14, 28, 46, 61, 4, 49, 35, 10, 29, 54, 33, 8, 45, 62, 37, 1, 43, 55, 10, 52, 61, 30, 19, 40, 25, 62, 11, 38, 27, 58, 36, 3, 46, 8, 39, 4, 62, 28, 47, 20, 4, 54, 47, 27, 43, 1, 21, 38, 8, 58, 10, 54, 4, 56, 9, 26, 12, 39, 60, 27, 18, 37, 1, 31, 35, 5, 45, 50, 2, 43, 26, 1, 59, 23, 56, 40, 7, 26, 58, 17, 32, 63, 25, 39, 7, 31, 45, 19, 63, 15, 48, 8, 37, 61, 16, 34, 1, 56, 18, 3, 15, 58, 49, 32, 63, 41, 55, 5, 40, 22, 50, 6, 59, 2, 63, 23, 52, 11, 26, 61, 44, 23 },
-  { 11, 56, 46, 6, 22, 43, 58, 3, 34, 21, 38, 30, 18, 44, 52, 13, 41, 57, 17, 28, 14, 49, 25, 7, 33, 39, 26, 6, 56, 48, 1, 20, 56, 5, 46, 9, 19, 51, 30, 25, 56, 21, 35, 14, 57, 42, 16, 33, 10, 57, 17, 59, 41, 25, 53, 37, 20, 40, 30, 18, 31, 62, 44, 22, 3, 44, 11, 48, 23, 53, 18, 60, 29, 22, 62, 15, 53, 47, 10, 41, 3, 19, 52, 36, 13, 46, 10, 35, 3, 61, 41, 16, 1, 50, 26, 42, 18, 46, 2, 25, 54, 20, 39, 23, 47, 31, 41, 12, 38, 17, 8, 19, 31, 48, 12, 61, 9, 54, 29, 35, 15, 38, 6, 43, 34, 14, 7, 47 },
-  { 39, 2, 33, 26, 53, 8, 18, 50, 41, 12, 53, 1, 63, 24, 19, 39, 2, 24, 47, 10, 60, 38, 19, 63, 48, 4, 15, 45, 32, 14, 60, 36, 29, 53, 23, 63, 34, 12, 61, 1, 43, 11, 53, 30, 1, 26, 60, 45, 23, 39, 3, 29, 12, 50, 4, 16, 51, 3, 45, 36, 50, 1, 16, 54, 35, 14, 57, 30, 58, 9, 46, 14, 41, 10, 32, 38, 4, 30, 21, 51, 32, 63, 25, 1, 60, 27, 53, 18, 51, 22, 28, 55, 34, 12, 40, 3, 60, 29, 57, 41, 6, 44, 11, 53, 8, 61, 24, 57, 1, 28, 44, 59, 36, 3, 34, 25, 41, 31, 16, 44, 22, 47, 28, 58, 1, 49, 54, 29 },
-  { 58, 25, 50, 13, 38, 30, 60, 24, 6, 57, 27, 42, 9, 45, 6, 61, 30, 50, 4, 34, 29, 3, 46, 13, 22, 42, 58, 28, 9, 39, 23, 44, 7, 15, 44, 2, 40, 15, 47, 41, 23, 37, 7, 59, 38, 11, 34, 6, 62, 14, 52, 35, 55, 19, 32, 61, 33, 24, 57, 6, 22, 59, 29, 7, 49, 25, 40, 3, 17, 39, 27, 52, 0, 55, 16, 57, 24, 61, 36, 6, 29, 12, 48, 39, 20, 44, 6, 40, 33, 5, 48, 10, 57, 36, 22, 51, 33, 9, 24, 12, 62, 29, 50, 35, 14, 43, 5, 33, 47, 52, 13, 23, 10, 51, 56, 16, 46, 1, 49, 4, 61, 9, 52, 18, 31, 21, 36, 17 },
-  { 19, 42, 9, 48, 2, 44, 11, 37, 48, 20, 33, 16, 55, 35, 49, 15, 37, 20, 59, 16, 53, 22, 56, 31, 50, 11, 34, 54, 16, 51, 4, 49, 33, 53, 21, 28, 56, 24, 31, 9, 52, 16, 48, 24, 44, 13, 51, 20, 31, 49, 18, 6, 34, 2, 44, 14, 47, 8, 15, 43, 13, 41, 33, 52, 20, 61, 7, 51, 34, 62, 4, 20, 36, 33, 43, 8, 46, 13, 53, 17, 45, 42, 9, 31, 52, 11, 30, 56, 13, 59, 17, 44, 27, 6, 62, 11, 43, 17, 49, 38, 26, 2, 16, 27, 58, 21, 54, 18, 26, 5, 35, 61, 43, 27, 7, 39, 14, 58, 37, 55, 20, 33, 13, 40, 62, 10, 55, 5 },
-  { 51, 14, 61, 29, 59, 20, 55, 31, 0, 49, 11, 60, 3, 26, 22, 56, 0, 40, 12, 43, 41, 8, 36, 0, 17, 57, 24, 2, 46, 26, 61, 18, 0, 38, 12, 59, 6, 49, 3, 57, 19, 63, 5, 33, 18, 54, 28, 56, 0, 43, 26, 46, 63, 27, 56, 22, 27, 54, 38, 28, 63, 24, 10, 45, 0, 31, 42, 21, 12, 25, 44, 49, 59, 6, 26, 50, 3, 34, 27, 59, 0, 35, 62, 16, 4, 58, 47, 0, 43, 24, 37, 2, 54, 20, 46, 31, 0, 56, 34, 5, 55, 45, 60, 37, 0, 40, 10, 38, 63, 46, 15, 20, 0, 53, 21, 62, 30, 11, 24, 27, 40, 0, 57, 26, 3, 45, 27, 35 },
-};
-
-#else
-#define DM_WIDTH 8
-#define DM_WIDTH_SHIFT 3
-#define DM_HEIGHT 8
-static const unsigned char DM[8][8] =
-{
-  { 0,  32, 8,  40, 2,  34, 10, 42 },
-  { 48, 16, 56, 24, 50, 18, 58, 26 },
-  { 12, 44, 4,  36, 14, 46, 6,  38 },
-  { 60, 28, 52, 20, 62, 30, 54, 22 },
-  { 3,  35, 11, 43, 1,  33, 9,  41 },
-  { 51, 19, 59, 27, 49, 17, 57, 25 },
-  { 15, 47, 7,  39, 13, 45, 5,  37 },
-  { 63, 31, 55, 23, 61, 29, 53, 21 }
-};
-#endif
-
-
-static void
-xxlib_rgb_preprocess_dm_565 (XlibRgbHandle *handle)
-{
-  int i;
-  uint32 dith;
-
-  if (handle->DM_565 == NULL)
-    {
-      handle->DM_565 = malloc(sizeof(uint32) * DM_WIDTH * DM_HEIGHT);
-      for (i = 0; i < DM_WIDTH * DM_HEIGHT; i++)
-        {
-          dith = DM[i / DM_WIDTH][i % DM_WIDTH] >> 3;
-          handle->DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10);
-#ifdef VERBOSE
-          printf ("%i %x %x\n", i, dith, handle->DM_565[i]);
-#endif
-        }
-    }
-}
-
-static void
-xxlib_rgb_convert_8_d666 (XlibRgbHandle *handle, XImage *image,
-                        int ax, int ay, int width, int height,
-                        unsigned char *buf, int rowstride,
-                        int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int dith;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7;
-          r = ((r * 5) + dith) >> 8;
-          g = ((g * 5) + (262 - dith)) >> 8;
-          b = ((b * 5) + dith) >> 8;
-          obptr[0] = handle->colorcube_d[(r << 6) | (g << 3) | b];
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_8_d (XlibRgbHandle *handle, XImage *image,
-                     int ax, int ay, int width, int height,
-                     unsigned char *buf, int rowstride,
-                     int x_align, int y_align,
-                     XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int dith;
-  int rs, gs, bs;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  rs = handle->nred_shades - 1;
-  gs = handle->ngreen_shades - 1;
-  bs = handle->nblue_shades - 1;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 7;
-          r = ((r * rs) + dith) >> 8;
-          g = ((g * gs) + (262 - dith)) >> 8;
-          b = ((b * bs) + dith) >> 8;
-          obptr[0] = handle->colorcube_d[(r << 6) | (g << 3) | b];
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_8_indexed (XlibRgbHandle *handle, XImage *image,
-                           int ax, int ay, int width, int height,
-                           unsigned char *buf, int rowstride,
-                           int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  unsigned char c;
-  unsigned char *lut;
-
-  lut = cmap->lut;
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          c = *bp2++;
-          obptr[0] = lut[c];
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_gray8 (XlibRgbHandle *handle, XImage *image,
-                       int ax, int ay, int width, int height,
-                       unsigned char *buf, int rowstride,
-                       int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          obptr[0] = (g + ((b + r) >> 1)) >> 1;
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_gray8_gray (XlibRgbHandle *handle, XImage *image,
-                            int ax, int ay, int width, int height,
-                            unsigned char *buf, int rowstride,
-                            int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int y;
-  int bpl;
-  unsigned char *obuf;
-  unsigned char *bptr;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      memcpy (obuf, bptr, (unsigned int)width);
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define HAIRY_CONVERT_565
-#endif
-
-#ifdef HAIRY_CONVERT_565
-/* Render a 24-bit RGB image in buf into the XImage, without dithering.
-   This assumes native byte ordering - what should really be done is to
-   check whether handle->static_image->byte_order is consistent with 
-   the _ENDIAN config flag, and if not, use a different function.
-
-   This one is even faster than the one below - its inner loop loads 3
-   words (i.e. 4 24-bit pixels), does a lot of shifting and masking,
-   then writes 2 words. */
-static void
-xxlib_rgb_convert_565 (XlibRgbHandle *handle, XImage *image,
-                     int ax, int ay, int width, int height,
-                     unsigned char *buf, int rowstride,
-                     int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
-        {
-          for (x = 0; x < width; x++)
-            {
-              r = *bp2++;
-              g = *bp2++;
-              b = *bp2++;
-              ((uint16 *)obptr)[0] = ((r & 0xf8) << 8) |
-                ((g & 0xfc) << 3) |
-                (b >> 3);
-              obptr += 2;
-            }
-        }
-      else
-        {
-          for (x = 0; x < width - 3; x += 4)
-            {
-              uint32 r1b0g0r0;
-              uint32 g2r2b1g1;
-              uint32 b3g3r3b2;
-
-              r1b0g0r0 = ((uint32 *)bp2)[0];
-              g2r2b1g1 = ((uint32 *)bp2)[1];
-              b3g3r3b2 = ((uint32 *)bp2)[2];
-              ((uint32 *)obptr)[0] =
-                ((r1b0g0r0 & 0xf8) << 8) |
-                ((r1b0g0r0 & 0xfc00) >> 5) |
-                ((r1b0g0r0 & 0xf80000) >> 19) |
-                (r1b0g0r0 & 0xf8000000) |
-                ((g2r2b1g1 & 0xfc) << 19) |
-                ((g2r2b1g1 & 0xf800) << 5);
-              ((uint32 *)obptr)[1] =
-                ((g2r2b1g1 & 0xf80000) >> 8) |
-                ((g2r2b1g1 & 0xfc000000) >> 21) |
-                ((b3g3r3b2 & 0xf8) >> 3) |
-                ((b3g3r3b2 & 0xf800) << 16) |
-                ((b3g3r3b2 & 0xfc0000) << 3) |
-                ((b3g3r3b2 & 0xf8000000) >> 11);
-              bp2 += 12;
-              obptr += 8;
-            }
-          for (; x < width; x++)
-            {
-              r = *bp2++;
-              g = *bp2++;
-              b = *bp2++;
-              ((uint16 *)obptr)[0] = ((r & 0xf8) << 8) |
-                ((g & 0xfc) << 3) |
-                (b >> 3);
-              obptr += 2;
-            }
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#else
-/* Render a 24-bit RGB image in buf into the XImage, without dithering.
-   This assumes native byte ordering - what should really be done is to
-   check whether handle->static_image->byte_order is consistent with the
-    _ENDIAN config flag, and if not, use a different function.
-
-   This routine is faster than the one included with Gtk 1.0 for a number
-   of reasons:
-
-   1. Shifting instead of lookup tables (less memory traffic).
-
-   2. Much less register pressure, especially because shifts are
-   in the code.
-
-   3. A memcpy is avoided (i.e. the transfer function).
-
-   4. On big-endian architectures, byte swapping is avoided.
-
-   That said, it wouldn't be hard to make it even faster - just make an
-   inner loop that reads 3 words (i.e. 4 24-bit pixels), does a lot of
-   shifting and masking, then writes 2 words.
-*/
-static void
-xxlib_rgb_convert_565 (XlibRgbHandle *handle, XImage *image,
-                     int ax, int ay, int width, int height,
-                     unsigned char *buf, int rowstride,
-                     int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          ((unsigned short *)obuf)[x] = ((r & 0xf8) << 8) |
-            ((g & 0xfc) << 3) |
-            (b >> 3);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#endif
-
-#ifdef HAIRY_CONVERT_565
-static void
-xxlib_rgb_convert_565_gray (XlibRgbHandle *handle, XImage *image,
-                          int ax, int ay, int width, int height,
-                          unsigned char *buf, int rowstride,
-                          int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char g;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
-        {
-          for (x = 0; x < width; x++)
-            {
-              g = *bp2++;
-              ((uint16 *)obptr)[0] = ((g & 0xf8) << 8) |
-                ((g & 0xfc) << 3) |
-                (g >> 3);
-              obptr += 2;
-            }
-        }
-      else
-        {
-          for (x = 0; x < width - 3; x += 4)
-            {
-              uint32 g3g2g1g0;
-
-              g3g2g1g0 = ((uint32 *)bp2)[0];
-              ((uint32 *)obptr)[0] =
-                ((g3g2g1g0 & 0xf8) << 8) |
-                ((g3g2g1g0 & 0xfc) << 3) |
-                ((g3g2g1g0 & 0xf8) >> 3) |
-                (g3g2g1g0 & 0xf800) << 16 |
-                ((g3g2g1g0 & 0xfc00) << 11) |
-                ((g3g2g1g0 & 0xf800) << 5);
-              ((uint32 *)obptr)[1] =
-                ((g3g2g1g0 & 0xf80000) >> 8) |
-                ((g3g2g1g0 & 0xfc0000) >> 13) |
-                ((g3g2g1g0 & 0xf80000) >> 19) |
-                (g3g2g1g0 & 0xf8000000) |
-                ((g3g2g1g0 & 0xfc000000) >> 5) |
-                ((g3g2g1g0 & 0xf8000000) >> 11);
-              bp2 += 4;
-              obptr += 8;
-            }
-          for (; x < width; x++)
-            {
-              g = *bp2++;
-              ((uint16 *)obptr)[0] = ((g & 0xf8) << 8) |
-                ((g & 0xfc) << 3) |
-                (g >> 3);
-              obptr += 2;
-            }
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#else
-static void
-xxlib_rgb_convert_565_gray (XlibRgbHandle *handle, XImage *image,
-                          int ax, int ay, int width, int height,
-                          unsigned char *buf, int rowstride,
-                          int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char g;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          g = *bp2++;
-          ((uint16 *)obuf)[x] = ((g & 0xf8) << 8) |
-            ((g & 0xfc) << 3) |
-            (g >> 3);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#endif
-
-static void
-xxlib_rgb_convert_565_br (XlibRgbHandle *handle, XImage *image,
-                         int ax, int ay, int width, int height,
-                         unsigned char *buf, int rowstride,
-                         int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          /* final word is:
-             g4 g3 g2 b7 b6 b5 b4 b3  r7 r6 r5 r4 r3 g7 g6 g5
-           */
-          ((unsigned short *)obuf)[x] = (r & 0xf8) |
-            ((g & 0xe0) >> 5) |
-            ((g & 0x1c) << 11) |
-            ((b & 0xf8) << 5);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* Thanks to Ray Lehtiniemi for a patch that resulted in a ~25% speedup
-   in this mode. */
-#ifdef HAIRY_CONVERT_565
-static void
-xxlib_rgb_convert_565_d (XlibRgbHandle *handle, XImage *image,
-                     int ax, int ay, int width, int height,
-                     unsigned char *buf, int rowstride,
-                     int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  /* Now this is what I'd call some highly tuned code! */
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-
-  width += x_align;
-  height += y_align;
-  
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = y_align; y < height; y++)
-    {
-      uint32 *dmp = handle->DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT);
-      bp2 = bptr;
-      obptr = obuf;
-      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
-        {
-          for (x = x_align; x < width; x++)
-            {
-              int32 rgb = *bp2++ << 20;
-              rgb += *bp2++ << 10;
-              rgb += *bp2++;
-              rgb += dmp[x & (DM_WIDTH - 1)];
-              rgb += 0x10040100
-                - ((rgb & 0x1e0001e0) >> 5)
-                - ((rgb & 0x00070000) >> 6);
-
-              ((unsigned short *)obptr)[0] =
-                ((rgb & 0x0f800000) >> 12) |
-                ((rgb & 0x0003f000) >> 7) |
-                ((rgb & 0x000000f8) >> 3);
-              obptr += 2;
-            }
-        }
-      else
-        {
-          for (x = x_align; x < width - 3; x += 4)
-            {
-              uint32 r1b0g0r0;
-              uint32 g2r2b1g1;
-              uint32 b3g3r3b2;
-              uint32 rgb02, rgb13;
-
-              r1b0g0r0 = ((uint32 *)bp2)[0];
-              g2r2b1g1 = ((uint32 *)bp2)[1];
-              b3g3r3b2 = ((uint32 *)bp2)[2];
-              rgb02 =
-                ((r1b0g0r0 & 0xff) << 20) +
-                ((r1b0g0r0 & 0xff00) << 2) +
-                ((r1b0g0r0 & 0xff0000) >> 16) +
-                dmp[x & (DM_WIDTH - 1)];
-              rgb02 += 0x10040100
-                - ((rgb02 & 0x1e0001e0) >> 5)
-                - ((rgb02 & 0x00070000) >> 6);
-              rgb13 =
-                ((r1b0g0r0 & 0xff000000) >> 4) +
-                ((g2r2b1g1 & 0xff) << 10) +
-                ((g2r2b1g1 & 0xff00) >> 8) +
-                dmp[(x + 1) & (DM_WIDTH - 1)];
-              rgb13 += 0x10040100
-                - ((rgb13 & 0x1e0001e0) >> 5)
-                - ((rgb13 & 0x00070000) >> 6);
-              ((uint32 *)obptr)[0] =
-                ((rgb02 & 0x0f800000) >> 12) |
-                ((rgb02 & 0x0003f000) >> 7) |
-                ((rgb02 & 0x000000f8) >> 3) |
-                ((rgb13 & 0x0f800000) << 4) |
-                ((rgb13 & 0x0003f000) << 9) |
-                ((rgb13 & 0x000000f8) << 13);
-              rgb02 =
-                ((g2r2b1g1 & 0xff0000) << 4) +
-                ((g2r2b1g1 & 0xff000000) >> 14) +
-                (b3g3r3b2 & 0xff) +
-                dmp[(x + 2) & (DM_WIDTH - 1)];
-              rgb02 += 0x10040100
-                - ((rgb02 & 0x1e0001e0) >> 5)
-                - ((rgb02 & 0x00070000) >> 6);
-              rgb13 =
-                ((b3g3r3b2 & 0xff00) << 12) +
-                ((b3g3r3b2 & 0xff0000) >> 6) +
-                ((b3g3r3b2 & 0xff000000) >> 24) +
-                dmp[(x + 3) & (DM_WIDTH - 1)];
-              rgb13 += 0x10040100
-                - ((rgb13 & 0x1e0001e0) >> 5)
-                - ((rgb13 & 0x00070000) >> 6);
-              ((uint32 *)obptr)[1] =
-                ((rgb02 & 0x0f800000) >> 12) |
-                ((rgb02 & 0x0003f000) >> 7) |
-                ((rgb02 & 0x000000f8) >> 3) |
-                ((rgb13 & 0x0f800000) << 4) |
-                ((rgb13 & 0x0003f000) << 9) |
-                ((rgb13 & 0x000000f8) << 13);
-              bp2 += 12;
-              obptr += 8;
-            }
-          for (; x < width; x++)
-            {
-              int32 rgb = *bp2++ << 20;
-              rgb += *bp2++ << 10;
-              rgb += *bp2++;
-              rgb += dmp[x & (DM_WIDTH - 1)];
-              rgb += 0x10040100
-                - ((rgb & 0x1e0001e0) >> 5)
-                - ((rgb & 0x00070000) >> 6);
-
-              ((unsigned short *)obptr)[0] =
-                ((rgb & 0x0f800000) >> 12) |
-                ((rgb & 0x0003f000) >> 7) |
-                ((rgb & 0x000000f8) >> 3);
-              obptr += 2;
-            }
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#else
-static void
-xxlib_rgb_convert_565_d (XlibRgbHandle *handle, XImage *image,
-                       int ax, int ay, int width, int height,
-                       unsigned char *buf, int rowstride,
-                       int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr;
-
-  width += x_align;
-  height += y_align;
-  
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + (ax - x_align) * 2;
-
-  for (y = y_align; y < height; y++)
-    {
-      uint32 *dmp = handle->DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT);
-      unsigned char *bp2 = bptr;
-
-      for (x = x_align; x < width; x++)
-        {
-          int32 rgb = *bp2++ << 20;
-          rgb += *bp2++ << 10;
-          rgb += *bp2++;
-          rgb += dmp[x & (DM_WIDTH - 1)];
-          rgb += 0x10040100
-            - ((rgb & 0x1e0001e0) >> 5)
-            - ((rgb & 0x00070000) >> 6);
-
-          ((unsigned short *)obuf)[x] =
-            ((rgb & 0x0f800000) >> 12) |
-            ((rgb & 0x0003f000) >> 7) |
-            ((rgb & 0x000000f8) >> 3);
-        }
-
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#endif
-
-static void
-xxlib_rgb_convert_555 (XlibRgbHandle *handle, XImage *image,
-                     int ax, int ay, int width, int height,
-                     unsigned char *buf, int rowstride,
-                     int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          ((unsigned short *)obuf)[x] = ((r & 0xf8) << 7) |
-            ((g & 0xf8) << 2) |
-            (b >> 3);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_555_br (XlibRgbHandle *handle, XImage *image,
-                        int ax, int ay, int width, int height,
-                        unsigned char *buf, int rowstride,
-                        int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  unsigned char r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 2;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          /* final word is:
-             g5 g4 g3 b7 b6 b5 b4 b3  0 r7 r6 r5 r4 r3 g7 g6
-           */
-          ((unsigned short *)obuf)[x] = ((r & 0xf8) >> 1) |
-            ((g & 0xc0) >> 6) |
-            ((g & 0x18) << 10) |
-            ((b & 0xf8) << 5);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_888_msb (XlibRgbHandle *handle, XImage *image,
-                         int ax, int ay, int width, int height,
-                         unsigned char *buf, int rowstride,
-                         int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 3;
-  for (y = 0; y < height; y++)
-    {
-      memcpy (obuf, bptr, (unsigned int)(width + width + width));
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* todo: optimize this */
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define HAIRY_CONVERT_888
-#endif
-
-#ifdef HAIRY_CONVERT_888
-static void
-xxlib_rgb_convert_888_lsb (XlibRgbHandle *handle, XImage *image,
-                          int ax, int ay, int width, int height,
-                          unsigned char *buf, int rowstride,
-                          int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 3;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      if (((unsigned long)obuf | (unsigned long) bp2) & 3)
-        {
-          for (x = 0; x < width; x++)
-            {
-              r = bp2[0];
-              g = bp2[1];
-              b = bp2[2];
-              *obptr++ = b;
-              *obptr++ = g;
-              *obptr++ = r;
-              bp2 += 3;
-            }
-        }
-      else
-        {
-          for (x = 0; x < width - 3; x += 4)
-            {
-              uint32 r1b0g0r0;
-              uint32 g2r2b1g1;
-              uint32 b3g3r3b2;
-
-              r1b0g0r0 = ((uint32 *)bp2)[0];
-              g2r2b1g1 = ((uint32 *)bp2)[1];
-              b3g3r3b2 = ((uint32 *)bp2)[2];
-              ((uint32 *)obptr)[0] =
-                (r1b0g0r0 & 0xff00) |
-                ((r1b0g0r0 & 0xff0000) >> 16) |
-                (((g2r2b1g1 & 0xff00) | (r1b0g0r0 & 0xff)) << 16);
-              ((uint32 *)obptr)[1] =
-                (g2r2b1g1 & 0xff0000ff) |
-                ((r1b0g0r0 & 0xff000000) >> 16) |
-                ((b3g3r3b2 & 0xff) << 16);
-              ((uint32 *)obptr)[2] =
-                (((g2r2b1g1 & 0xff0000) | (b3g3r3b2 & 0xff000000)) >> 16) |
-                ((b3g3r3b2 & 0xff00) << 16) |
-                ((b3g3r3b2 & 0xff0000));
-              bp2 += 12;
-              obptr += 12;
-            }
-          for (; x < width; x++)
-            {
-              r = bp2[0];
-              g = bp2[1];
-              b = bp2[2];
-              *obptr++ = b;
-              *obptr++ = g;
-              *obptr++ = r;
-              bp2 += 3;
-            }
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#else
-static void
-xxlib_rgb_convert_888_lsb (XlibRgbHandle *handle, XImage *image,
-                         int ax, int ay, int width, int height,
-                         unsigned char *buf, int rowstride,
-                         int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 3;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          obuf[x * 3] = b;
-          obuf[x * 3 + 1] = g;
-          obuf[x * 3 + 2] = r;
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-#endif
-
-/* convert 24-bit packed to 32-bit unpacked */
-/* todo: optimize this */
-static void
-xxlib_rgb_convert_0888 (XlibRgbHandle *handle, XImage *image,
-                      int ax, int ay, int width, int height,
-                      unsigned char *buf, int rowstride,
-                      int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          ((uint32 *)obuf)[x] = (r << 16) | (g << 8) | b;
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_0888_br (XlibRgbHandle *handle, XImage *image,
-                         int ax, int ay, int width, int height,
-                         unsigned char *buf, int rowstride,
-                         int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          ((uint32 *)obuf)[x] = (b << 24) | (g << 16) | (r << 8);
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_8880_br (XlibRgbHandle *handle, XImage *image,
-                         int ax, int ay, int width, int height,
-                         unsigned char *buf, int rowstride,
-                         int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * 4;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          ((uint32 *)obuf)[x] = (b << 16) | (g << 8) | r;
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* Generic truecolor/directcolor conversion function. Slow, but these
-   are oddball modes. */
-static void
-xxlib_rgb_convert_truecolor_lsb (XlibRgbHandle *handle, XImage *image,
-                               int ax, int ay, int width, int height,
-                               unsigned char *buf, int rowstride,
-                               int x_align, int y_align,
-                               XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int r_right, r_left;
-  int g_right, g_left;
-  int b_right, b_left;
-  int bpp;
-  uint32 pixel;
-  int i;
-
-  r_right = 8 - handle->red_prec;
-  r_left = handle->red_shift;
-  g_right = 8 - handle->green_prec;
-  g_left = handle->green_shift;
-  b_right = 8 - handle->blue_prec;
-  b_left = handle->blue_shift;
-  bpp = handle->bpp;
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
-  for (y = 0; y < height; y++)
-    {
-      obptr = obuf;
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          pixel = ((r >> r_right) << r_left) |
-            ((g >> g_right) << g_left) |
-            ((b >> b_right) << b_left);
-          for (i = 0; i < bpp; i++)
-            {
-              *obptr++ = pixel & 0xff;
-              pixel >>= 8;
-            }
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_truecolor_lsb_d (XlibRgbHandle *handle, XImage *image,
-                                 int ax, int ay, int width, int height,
-                                 unsigned char *buf, int rowstride,
-                                 int x_align, int y_align,
-                                 XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int r_right, r_left, r_prec;
-  int g_right, g_left, g_prec;
-  int b_right, b_left, b_prec;
-  int bpp;
-  uint32 pixel;
-  int i;
-  int dith;
-  int r1, g1, b1;
-  const unsigned char *dmp;
-
-  r_right = 8 - handle->red_prec;
-  r_left = handle->red_shift;
-  r_prec = handle->red_prec;
-  g_right = 8 - handle->green_prec;
-  g_left = handle->green_shift;
-  g_prec = handle->green_prec;
-  b_right = 8 - handle->blue_prec;
-  b_left = handle->blue_shift;
-  b_prec = handle->blue_prec;
-  bpp = handle->bpp;
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      obptr = obuf;
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2;
-          r1 = r + (dith >> r_prec);
-          g1 = g + ((252 - dith) >> g_prec);
-          b1 = b + (dith >> b_prec);
-          pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
-            (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
-            (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
-          for (i = 0; i < bpp; i++)
-            {
-              *obptr++ = pixel & 0xff;
-              pixel >>= 8;
-            }
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_truecolor_msb (XlibRgbHandle *handle, XImage *image,
-                               int ax, int ay, int width, int height,
-                               unsigned char *buf, int rowstride,
-                               int x_align, int y_align,
-                               XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int r_right, r_left;
-  int g_right, g_left;
-  int b_right, b_left;
-  int bpp;
-  uint32 pixel;
-  int shift, shift_init;
-
-  r_right = 8 - handle->red_prec;
-  r_left = handle->red_shift;
-  g_right = 8 - handle->green_prec;
-  g_left = handle->green_shift;
-  b_right = 8 - handle->blue_prec;
-  b_left = handle->blue_shift;
-  bpp = handle->bpp;
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
-  shift_init = (bpp - 1) << 3;
-  for (y = 0; y < height; y++)
-    {
-      obptr = obuf;
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          pixel = ((r >> r_right) << r_left) |
-            ((g >> g_right) << g_left) |
-            ((b >> b_right) << b_left);
-          for (shift = shift_init; shift >= 0; shift -= 8)
-            {
-              *obptr++ = (pixel >> shift) & 0xff;
-            }
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_truecolor_msb_d (XlibRgbHandle *handle, XImage *image,
-                                 int ax, int ay, int width, int height,
-                                 unsigned char *buf, int rowstride,
-                                 int x_align, int y_align,
-                                 XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *obuf, *obptr;
-  int bpl;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int r_right, r_left, r_prec;
-  int g_right, g_left, g_prec;
-  int b_right, b_left, b_prec;
-  int bpp;
-  uint32 pixel;
-  int shift, shift_init;
-  int dith;
-  int r1, g1, b1;
-  const unsigned char *dmp;
-
-  r_right = 8 - handle->red_prec;
-  r_left = handle->red_shift;
-  r_prec = handle->red_prec;
-  g_right = 8 - handle->green_prec;
-  g_left = handle->green_shift;
-  g_prec = handle->green_prec;
-  b_right = 8 - handle->blue_prec;
-  b_left = handle->blue_shift;
-  b_prec = handle->blue_prec;
-  bpp = handle->bpp;
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax * bpp;
-  shift_init = (bpp - 1) << 3;
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      obptr = obuf;
-      bp2 = bptr;
-      for (x = 0; x < width; x++)
-        {
-          r = bp2[0];
-          g = bp2[1];
-          b = bp2[2];
-          dith = dmp[(x_align + x) & (DM_WIDTH - 1)] << 2;
-          r1 = r + (dith >> r_prec);
-          g1 = g + ((252 - dith) >> g_prec);
-          b1 = b + (dith >> b_prec);
-          pixel = (((r1 - (r1 >> r_prec)) >> r_right) << r_left) |
-            (((g1 - (g1 >> g_prec)) >> g_right) << g_left) |
-            (((b1 - (b1 >> b_prec)) >> b_right) << b_left);
-          for (shift = shift_init; shift >= 0; shift -= 8)
-            {
-              *obptr++ = (pixel >> shift) & 0xff;
-            }
-          bp2 += 3;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* This actually works for depths from 3 to 7 */
-static void
-xxlib_rgb_convert_4 (XlibRgbHandle *handle, XImage *image,
-                   int ax, int ay, int width, int height,
-                   unsigned char *buf, int rowstride,
-                   int x_align, int y_align,
-                   XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int dith;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x += 1)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) | 3;
-          obptr[0] = handle->colorcube_d[(((r + dith) & 0x100) >> 2) |
-                                (((g + 258 - dith) & 0x100) >> 5) |
-                                (((b + dith) & 0x100) >> 8)];
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* This actually works for depths from 3 to 7 */
-static void
-xxlib_rgb_convert_gray4 (XlibRgbHandle *handle, XImage *image,
-                       int ax, int ay, int width, int height,
-                       unsigned char *buf, int rowstride,
-                       int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int shift;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  shift = 9 - handle->x_visual_info->depth;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          obptr[0] = (g + ((b + r) >> 1)) >> shift;
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_gray4_pack (XlibRgbHandle *handle, XImage *image,
-                            int ax, int ay, int width, int height,
-                            unsigned char *buf, int rowstride,
-                            int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  int shift;
-  unsigned char pix0, pix1;
-  /* todo: this is hardcoded to big-endian. Make endian-agile. */
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 1);
-  shift = 9 - handle->x_visual_info->depth;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x += 2)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          pix0 = (g + ((b + r) >> 1)) >> shift;
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          pix1 = (g + ((b + r) >> 1)) >> shift;
-          obptr[0] = (pix0 << 4) | pix1;
-          obptr++;
-        }
-      if (width & 1)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          pix0 = (g + ((b + r) >> 1)) >> shift;
-          obptr[0] = (pix0 << 4);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* This actually works for depths from 3 to 7 */
-static void
-xxlib_rgb_convert_gray4_d (XlibRgbHandle *handle, XImage *image,
-                       int ax, int ay, int width, int height,
-                       unsigned char *buf, int rowstride,
-                       int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int prec, right;
-  int gray;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + ax;
-  prec = handle->x_visual_info->depth;
-  right = 8 - prec;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          gray = (g + ((b + r) >> 1)) >> 1;
-          gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec;
-          obptr[0] = (gray - (gray >> prec)) >> right;
-          obptr++;
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_gray4_d_pack (XlibRgbHandle *handle, XImage *image,
-                              int ax, int ay, int width, int height,
-                              unsigned char *buf, int rowstride,
-                              int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int prec, right;
-  int gray;
-  unsigned char pix0, pix1;
-  /* todo: this is hardcoded to big-endian. Make endian-agile. */
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 1);
-  prec = handle->x_visual_info->depth;
-  right = 8 - prec;
-  for (y = 0; y < height; y++)
-    {
-      bp2 = bptr;
-      obptr = obuf;
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      for (x = 0; x < width; x += 2)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          gray = (g + ((b + r) >> 1)) >> 1;
-          gray += (dmp[(x_align + x) & (DM_WIDTH - 1)] << 2) >> prec;
-          pix0 = (gray - (gray >> prec)) >> right;
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          gray = (g + ((b + r) >> 1)) >> 1;
-          gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec;
-          pix1 = (gray - (gray >> prec)) >> right;
-          obptr[0] = (pix0 << 4) | pix1;
-          obptr++;
-        }
-      if (width & 1)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          gray = (g + ((b + r) >> 1)) >> 1;
-          gray += (dmp[(x_align + x + 1) & (DM_WIDTH - 1)] << 2) >> prec;
-          pix0 = (gray - (gray >> prec)) >> right;
-          obptr[0] = (pix0 << 4);
-        }
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-static void
-xxlib_rgb_convert_1 (XlibRgbHandle *handle, XImage *image,
-                   int ax, int ay, int width, int height,
-                   unsigned char *buf, int rowstride,
-                   int x_align, int y_align,
-                   XlibRgbCmap *cmap)
-{
-  int x, y;
-  int bpl;
-  unsigned char *obuf, *obptr;
-  unsigned char *bptr, *bp2;
-  int r, g, b;
-  const unsigned char *dmp;
-  int dith;
-  unsigned char byte;
-
-  bptr = buf;
-  bpl = image->bytes_per_line;
-  obuf = ((unsigned char *)image->data) + ay * bpl + (ax >> 3);
-  byte = 0; /* unnecessary, but it keeps gcc from complaining */
-  for (y = 0; y < height; y++)
-    {
-      dmp = DM[(y_align + y) & (DM_HEIGHT - 1)];
-      bp2 = bptr;
-      obptr = obuf;
-      for (x = 0; x < width; x++)
-        {
-          r = *bp2++;
-          g = *bp2++;
-          b = *bp2++;
-          dith = (dmp[(x_align + x) & (DM_WIDTH - 1)] << 4) | 4;
-          byte += byte + (r + g + g + b + dith > 1020);
-          if ((x & 7) == 7)
-            {
-              obptr[0] = byte;
-              obptr++;
-            }
-        }
-      if (x & 7)
-        obptr[0] = byte << (8 - (x & 7));
-      bptr += rowstride;
-      obuf += bpl;
-    }
-}
-
-/* Returns a pointer to the stage buffer. */
-static unsigned char *
-xxlib_rgb_ensure_stage (XlibRgbHandle *handle)
-{
-  if (handle->stage_buf == NULL)
-    handle->stage_buf = malloc (IMAGE_HEIGHT * STAGE_ROWSTRIDE);
-  return handle->stage_buf;
-}
-
-/* This is slow. Speed me up, please. */
-static void
-xxlib_rgb_32_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height)
-{
-  int x, y;
-  unsigned char *pi_start, *po_start;
-  unsigned char *pi, *po;
-
-  pi_start = buf;
-  po_start = xxlib_rgb_ensure_stage (handle);
-  for (y = 0; y < height; y++)
-    {
-      pi = pi_start;
-      po = po_start;
-      for (x = 0; x < width; x++)
-        {
-          *po++ = *pi++;
-          *po++ = *pi++;
-          *po++ = *pi++;
-          pi++;
-        }
-      pi_start += rowstride;
-      po_start += STAGE_ROWSTRIDE;
-    }
-}
-
-/* Generic 32bit RGB conversion function - convert to 24bit packed, then
-   go from there. */
-static void
-xxlib_rgb_convert_32_generic (XlibRgbHandle *handle, XImage *image,
-                            int ax, int ay, int width, int height,
-                            unsigned char *buf, int rowstride,
-                            int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  xxlib_rgb_32_to_stage (handle, buf, rowstride, width, height);
-
-  (*handle->conv) (handle, image, ax, ay, width, height,
-                       handle->stage_buf, STAGE_ROWSTRIDE,
-                       x_align, y_align, cmap);
-}
-
-/* Generic 32bit RGB conversion function - convert to 24bit packed, then
-   go from there. */
-static void
-xxlib_rgb_convert_32_generic_d (XlibRgbHandle *handle, XImage *image,
-                              int ax, int ay, int width, int height,
-                              unsigned char *buf, int rowstride,
-                              int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  xxlib_rgb_32_to_stage (handle, buf, rowstride, width, height);
-
-  (*handle->conv_d) (handle, image, ax, ay, width, height,
-                         handle->stage_buf, STAGE_ROWSTRIDE,
-                         x_align, y_align, cmap);
-}
-
-/* This is slow. Speed me up, please. */
-static void
-xxlib_rgb_gray_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height)
-{
-  int x, y;
-  unsigned char *pi_start, *po_start;
-  unsigned char *pi, *po;
-  unsigned char gray;
-
-  pi_start = buf;
-  po_start = xxlib_rgb_ensure_stage (handle);
-  for (y = 0; y < height; y++)
-    {
-      pi = pi_start;
-      po = po_start;
-      for (x = 0; x < width; x++)
-        {
-          gray = *pi++;
-          *po++ = gray;
-          *po++ = gray;
-          *po++ = gray;
-        }
-      pi_start += rowstride;
-      po_start += STAGE_ROWSTRIDE;
-    }
-}
-
-/* Generic gray conversion function - convert to 24bit packed, then go
-   from there. */
-static void
-xxlib_rgb_convert_gray_generic (XlibRgbHandle *handle, XImage *image,
-                              int ax, int ay, int width, int height,
-                              unsigned char *buf, int rowstride,
-                              int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  xxlib_rgb_gray_to_stage (handle, buf, rowstride, width, height);
-
-  (*handle->conv) (handle, image, ax, ay, width, height,
-                       handle->stage_buf, STAGE_ROWSTRIDE,
-                       x_align, y_align, cmap);
-}
-
-static void
-xxlib_rgb_convert_gray_generic_d (XlibRgbHandle *handle, XImage *image,
-                                int ax, int ay, int width, int height,
-                                unsigned char *buf, int rowstride,
-                                int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  xxlib_rgb_gray_to_stage (handle, buf, rowstride, width, height);
-
-  (*handle->conv_d) (handle, image, ax, ay, width, height,
-                         handle->stage_buf, STAGE_ROWSTRIDE,
-                         x_align, y_align, cmap);
-}
-
-/* Render grayscale using indexed method. */
-static void
-xxlib_rgb_convert_gray_cmap (XlibRgbHandle *handle, XImage *image,
-                           int ax, int ay, int width, int height,
-                           unsigned char *buf, int rowstride,
-                           int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  (*handle->conv_indexed) (handle, image, ax, ay, width, height,
-                               buf, rowstride,
-                               x_align, y_align, handle->gray_cmap);
-}
-
-#if 0
-static void
-xxlib_rgb_convert_gray_cmap_d (XlibRgbHandle *handle, XImage *image,
-                                int ax, int ay, int width, int height,
-                                unsigned char *buf, int rowstride,
-                                int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  (*handle->conv_indexed_d) (handle, image, ax, ay, width, height,
-                                 buf, rowstride,
-                                 x_align, y_align, handle->gray_cmap);
-}
-#endif
-
-/* This is slow. Speed me up, please. */
-static void
-xxlib_rgb_indexed_to_stage (XlibRgbHandle *handle, unsigned char *buf, int rowstride, int width, int height,
-                          XlibRgbCmap *cmap)
-{
-  int x, y;
-  unsigned char *pi_start, *po_start;
-  unsigned char *pi, *po;
-  int rgb;
-
-  pi_start = buf;
-  po_start = xxlib_rgb_ensure_stage (handle);
-  for (y = 0; y < height; y++)
-    {
-      pi = pi_start;
-      po = po_start;
-      for (x = 0; x < width; x++)
-        {
-          rgb = cmap->colors[*pi++];
-          *po++ = rgb >> 16;
-          *po++ = (rgb >> 8) & 0xff;
-          *po++ = rgb & 0xff;
-        }
-      pi_start += rowstride;
-      po_start += STAGE_ROWSTRIDE;
-    }
-}
-
-/* Generic gray conversion function - convert to 24bit packed, then go
-   from there. */
-static void
-xxlib_rgb_convert_indexed_generic (XlibRgbHandle *handle, XImage *image,
-                                 int ax, int ay, int width, int height,
-                                 unsigned char *buf, int rowstride,
-                                 int x_align, int y_align, XlibRgbCmap *cmap)
-{
-  xxlib_rgb_indexed_to_stage (handle, buf, rowstride, width, height, cmap);
-
-  (*handle->conv) (handle, image, ax, ay, width, height,
-                       handle->stage_buf, STAGE_ROWSTRIDE,
-                       x_align, y_align, cmap);
-}
-
-static void
-xxlib_rgb_convert_indexed_generic_d (XlibRgbHandle *handle, XImage *image,
-                                   int ax, int ay, int width, int height,
-                                   unsigned char *buf, int rowstride,
-                                   int x_align, int y_align,
-                                   XlibRgbCmap *cmap)
-{
-  xxlib_rgb_indexed_to_stage (handle, buf, rowstride, width, height, cmap);
-
-  (*handle->conv_d) (handle, image, ax, ay, width, height,
-                         handle->stage_buf, STAGE_ROWSTRIDE,
-                         x_align, y_align, cmap);
-}
-
-/* Select a conversion function based on the visual and a
-   representative image. */
-static void
-xxlib_rgb_select_conv (XlibRgbHandle *handle, XImage *image, ByteOrder byte_order)
-{
-  int depth, byterev;
-  int vtype; /* visual type */
-  int bpp; /* bits per pixel - from the visual */
-  uint32 red_mask, green_mask, blue_mask;
-  XlibRgbConvFunc conv, conv_d;
-  XlibRgbConvFunc conv_32, conv_32_d;
-  XlibRgbConvFunc conv_gray, conv_gray_d;
-  XlibRgbConvFunc conv_indexed, conv_indexed_d;
-  Bool mask_rgb, mask_bgr;
-
-  depth = handle->x_visual_info->depth;
-  bpp = image->bits_per_pixel;
-  if (handle->xlib_rgb_verbose)
-    printf ("Chose visual 0x%x, image bpp=%d, %s first\n",
-            (int)handle->x_visual_info->visual->visualid,
-            bpp, byte_order == LSB_FIRST ? "lsb" : "msb");
-
-#if G_BYTE_ORDER == G_BIG_ENDIAN
-  byterev = (byte_order == LSB_FIRST);
-#else
-  byterev = (byte_order == MSB_FIRST);
-#endif
-
-  vtype = handle->x_visual_info->class;
-  if (vtype == DirectColor)
-    vtype = TrueColor;
-
-  red_mask = handle->x_visual_info->red_mask;
-  green_mask = handle->x_visual_info->green_mask;
-  blue_mask = handle->x_visual_info->blue_mask;
-
-  mask_rgb = red_mask == 0xff0000 && green_mask == 0xff00 && blue_mask == 0xff;
-  mask_bgr = red_mask == 0xff && green_mask == 0xff00 && blue_mask == 0xff0000;
-
-  conv   = NULL;
-  conv_d = NULL;
-
-  conv_32     = xxlib_rgb_convert_32_generic;
-  conv_32_d   = xxlib_rgb_convert_32_generic_d;
-
-  conv_gray   = xxlib_rgb_convert_gray_generic;
-  conv_gray_d = xxlib_rgb_convert_gray_generic_d;
-
-  conv_indexed   = xxlib_rgb_convert_indexed_generic;
-  conv_indexed_d = xxlib_rgb_convert_indexed_generic_d;
-
-  handle->dith_default = FALSE;
-
-  if (handle->bitmap)
-    conv = xxlib_rgb_convert_1;
-  else if (bpp == 16 && depth == 16 && !byterev &&
-      red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
-    {
-      conv = xxlib_rgb_convert_565;
-      conv_d = xxlib_rgb_convert_565_d;
-      conv_gray = xxlib_rgb_convert_565_gray;
-      xxlib_rgb_preprocess_dm_565 (handle);
-    }
-  else if (bpp == 16 && depth == 16 &&
-           vtype == TrueColor&& byterev &&
-      red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
-    conv = xxlib_rgb_convert_565_br;
-
-  else if (bpp == 16 && depth == 15 &&
-           vtype == TrueColor && !byterev &&
-      red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
-    conv = xxlib_rgb_convert_555;
-
-  else if (bpp == 16 && depth == 15 &&
-           vtype == TrueColor && byterev &&
-      red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
-    conv = xxlib_rgb_convert_555_br;
-
-  /* I'm not 100% sure about the 24bpp tests - but testing will show*/
-  else if (bpp == 24 && depth == 24 && vtype == TrueColor &&
-           ((mask_rgb && byte_order == LSB_FIRST) ||
-            (mask_bgr && byte_order == MSB_FIRST)))
-    conv = xxlib_rgb_convert_888_lsb;
-  else if (bpp == 24 && depth == 24 && vtype == TrueColor &&
-           ((mask_rgb && byte_order == MSB_FIRST) ||
-            (mask_bgr && byte_order == LSB_FIRST)))
-    conv = xxlib_rgb_convert_888_msb;
-#if G_BYTE_ORDER == G_BIG_ENDIAN
-  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
-           (mask_rgb && byte_order == LSB_FIRST))
-    conv = xxlib_rgb_convert_0888_br;
-  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
-           (mask_rgb && byte_order == MSB_FIRST))
-    conv = xxlib_rgb_convert_0888;
-  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
-           (mask_bgr && byte_order == MSB_FIRST))
-    conv = xxlib_rgb_convert_8880_br;
-#else
-  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
-           (mask_rgb && byte_order == MSB_FIRST))
-    conv = xxlib_rgb_convert_0888_br;
-  else if (bpp == 32 && (depth == 32 || depth == 24) && vtype == TrueColor &&
-           (mask_rgb && byte_order == LSB_FIRST))
-    conv = xxlib_rgb_convert_0888;
-  else if (bpp == 32 && depth == 24 && vtype == TrueColor &&
-           (mask_bgr && byte_order == LSB_FIRST))
-    conv = xxlib_rgb_convert_8880_br;
-#endif
-
-  else if (vtype == TrueColor && byte_order == LSB_FIRST)
-    {
-      conv = xxlib_rgb_convert_truecolor_lsb;
-      conv_d = xxlib_rgb_convert_truecolor_lsb_d;
-    }
-  else if (vtype == TrueColor && byte_order == MSB_FIRST)
-    {
-      conv = xxlib_rgb_convert_truecolor_msb;
-      conv_d = xxlib_rgb_convert_truecolor_msb_d;
-    }
-  else if (bpp == 8 && depth == 8 && (vtype == PseudoColor || vtype == StaticColor
-#ifdef ENABLE_GRAYSCALE
-                                      || vtype == GrayScale
-#endif
-                                      ))
-    {
-      handle->dith_default = TRUE;
-      conv = xxlib_rgb_convert_8;
-      if (vtype != GrayScale)
-        {
-          if (handle->nred_shades == 6 &&
-              handle->ngreen_shades == 6 &&
-              handle->nblue_shades == 6)
-            conv_d = xxlib_rgb_convert_8_d666;
-          else
-            conv_d = xxlib_rgb_convert_8_d;
-        }
-      conv_indexed = xxlib_rgb_convert_8_indexed;
-      conv_gray = xxlib_rgb_convert_gray_cmap;
-    }
-  else if (bpp == 8 && depth == 8 && (vtype == StaticGray
-#ifdef not_ENABLE_GRAYSCALE
-                                      || vtype == GrayScale
-#endif
-                                      ))
-    {
-      conv = xxlib_rgb_convert_gray8;
-      conv_gray = xxlib_rgb_convert_gray8_gray;
-    }
-  else if (bpp == 8 && depth < 8 && depth >= 2 &&
-           (vtype == StaticGray
-            || vtype == GrayScale))
-    {
-      conv = xxlib_rgb_convert_gray4;
-      conv_d = xxlib_rgb_convert_gray4_d;
-    }
-  else if (bpp == 8 && depth < 8 && depth >= 3)
-    {
-      conv = xxlib_rgb_convert_4;
-    }
-  else if (bpp == 4 && depth <= 4 && depth >= 2 &&
-           (vtype == StaticGray
-            || vtype == GrayScale))
-    {
-      conv = xxlib_rgb_convert_gray4_pack;
-      conv_d = xxlib_rgb_convert_gray4_d_pack;
-    }
-
-  if (conv_d == NULL)
-    conv_d = conv;
-
-  handle->conv = conv;
-  handle->conv_d = conv_d;
-
-  handle->conv_32 = conv_32;
-  handle->conv_32_d = conv_32_d;
-
-  handle->conv_gray = conv_gray;
-  handle->conv_gray_d = conv_gray_d;
-
-  handle->conv_indexed = conv_indexed;
-  handle->conv_indexed_d = conv_indexed_d;
-}
-
-static int
-xxlib_rgb_alloc_scratch_image (XlibRgbHandle *handle)
-{
-  if (handle->static_image_idx == N_IMAGES)
-  {
-#ifdef XLIBRGB_ENABLE_MITSHM_SUPPORT
-    if (handle->xlib_use_shm)
-      XFlush(handle->display);
-#endif /* XLIBRGB_ENABLE_MITSHM_SUPPORT */
-      
-    handle->static_image_idx = 0;
-    handle->horiz_y = IMAGE_HEIGHT;
-    handle->vert_x  = IMAGE_WIDTH;
-    handle->tile_x  = IMAGE_WIDTH;
-    handle->tile_y1 = handle->tile_y2 = IMAGE_HEIGHT;
-  }
-  
-  return handle->static_image_idx++;
-}
-
-static XImage *
-xxlib_rgb_alloc_scratch (XlibRgbHandle *handle, int width, int height, int *ax, int *ay)
-{
-  XImage *image;
-  int idx;
-
-  if (width >= (IMAGE_WIDTH >> 1))
-  {
-    if (height >= (IMAGE_HEIGHT >> 1))
-    {
-      idx = xxlib_rgb_alloc_scratch_image (handle);
-      *ax = 0;
-      *ay = 0;
-    }
-    else
-    {
-      if (height + handle->horiz_y > IMAGE_HEIGHT)
-      {
-        handle->horiz_idx = xxlib_rgb_alloc_scratch_image (handle);
-        handle->horiz_y = 0;
-      }
-      idx = handle->horiz_idx;
-      *ax = 0;
-      *ay = handle->horiz_y;
-      handle->horiz_y += height;
-    }
-  }
-  else
-  {
-    if (height >= (IMAGE_HEIGHT >> 1))
-    {
-      if (width + handle->vert_x > IMAGE_WIDTH)
-      {
-        handle->vert_idx = xxlib_rgb_alloc_scratch_image (handle);
-        handle->vert_x = 0;
-      }
-      idx = handle->vert_idx;
-      *ax = handle->vert_x;
-      *ay = 0;
-      /* using 3 and -4 would be slightly more efficient on 32-bit machines
-         with > 1bpp displays */
-      handle->vert_x += (width + 7) & -8;
-    }
-    else
-    {
-      if (width + handle->tile_x > IMAGE_WIDTH)
-      {
-        handle->tile_y1 = handle->tile_y2;
-        handle->tile_x = 0;
-      }
-      if (height + handle->tile_y1 > IMAGE_HEIGHT)
-      {
-        handle->tile_idx = xxlib_rgb_alloc_scratch_image (handle);
-        handle->tile_x = 0;
-        handle->tile_y1 = 0;
-        handle->tile_y2 = 0;
-      }
-      if (height + handle->tile_y1 > handle->tile_y2)
-        handle->tile_y2 = height + handle->tile_y1;
-      idx = handle->tile_idx;
-      *ax = handle->tile_x;
-      *ay = handle->tile_y1;
-      handle->tile_x += (width + 7) & -8;
-    }
-  }
-  image = handle->static_image[idx];
-
-  return image;
-}
-
-
-static int 
-xxlib_get_bits_per_pixel (XlibRgbHandle *handle, int depth)
-{
-  if (depth <= 4)
-      return 4;
-  if (depth <= 8)
-      return 8;
-  if (depth <= 16)
-      return 16;
-  return 32;
-}
-
-/* Use optimized code... */   
-#define XLIB_USE_FAST_BUT_UGLY_CODE 1
-
-/* size of static buffer to store images in non-tiling mode
- * (see xlib_disallow_image_tiling()). If this buffer is too small to store
- * the whole image into it a new buffer is allocated for that image 
- */
-#define XLIB_STATIC_IMAGE_BUFFER_SIZE (256 * 128 * (32/4))   
-
-static void
-xxlib_draw_rgb_image_core (XlibRgbHandle *handle, 
-                           Drawable drawable,
-                           GC gc,
-                           int x,
-                           int y,
-                           int width,
-                           int height,
-                           unsigned char *buf,
-                           int pixstride,
-                           int rowstride,
-                           XlibRgbConvFunc conv,
-                           XlibRgbCmap *cmap,
-                           int xdith,
-                           int ydith)
-{
-  Bool do_tile;
-  
-  if (handle->bitmap)
-  {
-    if (handle->own_gc == None)
-    {
-      XColor color;
-
-      handle->own_gc = XCreateGC(handle->display,
-                                 drawable,
-                                 0, NULL);
-      color.pixel = XWhitePixel(handle->display,
-                                handle->screen_num);
-      XSetForeground(handle->display, handle->own_gc, color.pixel);
-      color.pixel = XBlackPixel(handle->display,
-                                handle->screen_num);
-      XSetBackground(handle->display, handle->own_gc, color.pixel);
-    }
-    gc = handle->own_gc;
-  }
-
-  /* Avoid image tiling for small images (1/32 of the maximum request size -
-   * guranteed to be at least 16384 bytes). Tiling buffers are rare - and 
-   * in the case of MIT-SHM require a XFlush() if all tile images have been used-up.
-   */
-  do_tile = ((handle->x_visual_info->depth+7)/8 * width * height) > (handle->max_request_size/32);
-      
-  if( (!handle->disallow_image_tiling) && do_tile )
-  {
-    int ay, ax;
-    int xs0, ys0;
-    int width1, height1;
-    unsigned char *buf_ptr;
-    XImage *image;
-          
-    for (ay = 0; ay < height; ay += IMAGE_HEIGHT)
-    {
-      height1 = MIN (height - ay, IMAGE_HEIGHT);
-      for (ax = 0; ax < width; ax += IMAGE_WIDTH)
-      {
-        width1 = MIN (width - ax, IMAGE_WIDTH);
-        buf_ptr = buf + ay * rowstride + ax * pixstride;
-
-        image = xxlib_rgb_alloc_scratch (handle, width1, height1, &xs0, &ys0);
-
-        conv (handle, image, xs0, ys0, width1, height1, buf_ptr, rowstride,
-              x + ax + xdith, y + ay + ydith, cmap);
-
-#ifndef DONT_ACTUALLY_DRAW
-        xxlib_image_put(handle, drawable, gc, image,
-                       xs0, ys0, x + ax, y + ay,
-                       (unsigned int)width1, (unsigned int)height1);
-#endif /* !DONT_ACTUALLY_DRAW */
-      }
-    }
-  }
-  else
-#ifdef XLIB_USE_FAST_BUT_UGLY_CODE
-  /* This is a heavily optimized version of the implementation used when  
-   * XLIB_USE_FAST_BUT_UGLY_CODE is not set. It tries to avoid malloc()/XCreateImage() 
-   * by using a static buffer if possible - but uses malloc() when the image data are 
-   * too large to fit info that buffer...
-   */
-  {    
-    XImage ximage;
-    int    format;
-    int    depth;
-    int    xpad;
-    long   image_data_size;
-    
-    /* allocate static buffer if we do not have one yet... */      
-    if( handle->static_buffer == NULL )
-    {
-      handle->static_buffer = malloc(XLIB_STATIC_IMAGE_BUFFER_SIZE);
-      if(!handle->static_buffer)
-        return; /* error - no memory */
-    }
-    
-    /* fill the XImage structure... */
-    memset(&ximage, 0, sizeof(ximage));
-    
-    if (handle->bitmap) 
-    {
-      format = XYBitmap;
-      depth  = 1;
-      xpad   = 8;
-    }
-    else 
-    {
-      format = ZPixmap;
-      depth  = handle->x_visual_info->depth;
-      xpad   = 32;
-    }
-
-    ximage.width            = width;
-    ximage.height           = height;
-    ximage.format           = format;
-    ximage.byte_order       = XImageByteOrder(handle->display);
-    ximage.bitmap_unit      = XBitmapUnit(handle->display);
-    ximage.bitmap_bit_order = XBitmapBitOrder(handle->display);
-    ximage.red_mask         = handle->x_visual_info->visual->red_mask;
-    ximage.green_mask       = handle->x_visual_info->visual->green_mask;
-    ximage.blue_mask        = handle->x_visual_info->visual->blue_mask;
-    if (format == ZPixmap) 
-      ximage.bits_per_pixel = xxlib_get_bits_per_pixel(handle, depth);
-    ximage.xoffset          = 0;
-    ximage.bitmap_pad       = xpad;
-    ximage.depth            = depth;
-    ximage.data             = NULL;
-    ximage.bytes_per_line   = 0; /* let XInitImage() calculate that... */
-    ximage.obdata           = NULL;
-    ximage.bitmap_bit_order = MSBFirst;
-    ximage.byte_order       = MSBFirst;
-
-    if(!XInitImage(&ximage))
-    {
-#ifdef DSIABLED_FOR_NOW_DUE_LINK_ISSUES
-      NS_ERROR("xlib_draw_rgb_image_core: XInitImage() failure - should not happen...\n");
-#endif /* DSIABLED_FOR_NOW_DUE_LINK_ISSUES */    
-      return; /* error - should not happen... */
-    }
-    
-    image_data_size = height*ximage.bytes_per_line;     
-
-    if (image_data_size > XLIB_STATIC_IMAGE_BUFFER_SIZE)
-    {
-#ifdef VERBOSE
-      printf("xlib_draw_rgb_image_core: Allocating extra large buffer(%ld > %ld)...\n",
-             (long)image_data_size, (long)XLIB_STATIC_IMAGE_BUFFER_SIZE);
-#endif /* VERBOSE */
-      ximage.data = malloc(image_data_size);
-      if (!ximage.data)
-        return; /* error - no memory */
-    }
-    else
-    {
-      ximage.data = handle->static_buffer; 
-    }
-
-    conv (handle, &ximage, 0, 0, width, height, buf, rowstride,
-          0, 0, cmap);
-
-#ifndef DONT_ACTUALLY_DRAW
-    XPutImage(handle->display, drawable, gc, &ximage,
-    0, 0, x, y, (unsigned int)width, (unsigned int)height);
-#endif
-
-    /* free any extra memory we may have allocated above */
-    if (ximage.data != handle->static_buffer)
-      free(ximage.data);
-  }
-#else
-  /* this is the clean&pretty version of the code above... */
-  {
-    XImage *image;
-    
-    if (handle->bitmap) 
-    {
-      image = XCreateImage(handle->display,
-                           handle->x_visual_info->visual,
-                           1,
-                           XYBitmap,
-                           0, 0, width, height,
-                           8, 0);
-    }
-    else 
-    {
-      image = XCreateImage(handle->display,
-                           handle->x_visual_info->visual,
-                           (unsigned int)handle->x_visual_info->depth,
-                           ZPixmap,
-                           0, 0, width, height,
-                           32, 0);
-    }
-
-    /* Use malloc() instead of g_malloc since X will free() this mem */
-    image->data = malloc(height*image->bytes_per_line);
-    image->bitmap_bit_order = MSBFirst;
-    image->byte_order       = MSBFirst;      
-
-    conv( handle, image, 0, 0, width, height, buf, rowstride,
-          0, 0, cmap);
-
-#ifndef DONT_ACTUALLY_DRAW
-    XPutImage(handle->display, drawable, gc, image,
-    0, 0, x, y, (unsigned int)width, (unsigned int)height);
-#endif
-
-    XDestroyImage(image);
-  }
-#endif /* XLIB_USE_FAST_BUT_UGLY_CODE */  
-}
-
-
-void
-xxlib_draw_rgb_image (XlibRgbHandle *handle, Drawable drawable,
-                     GC gc,
-                     int x,
-                     int y,
-                     int width,
-                     int height,
-                     XlibRgbDither dith,
-                     unsigned char *rgb_buf,
-                     int rowstride)
-{
-  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
-                                      !handle->dith_default))
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                              rgb_buf, 3, rowstride, handle->conv, NULL,
-                              0, 0);
-  else
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                              rgb_buf, 3, rowstride, handle->conv_d, NULL,
-                              0, 0);
-}
-
-void
-xxlib_draw_rgb_image_dithalign (XlibRgbHandle *handle, Drawable drawable,
-                              GC gc,
-                              int x,
-                              int y,
-                              int width,
-                              int height,
-                              XlibRgbDither dith,
-                              unsigned char *rgb_buf,
-                              int rowstride,
-                              int xdith,
-                              int ydith)
-{
-  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
-                                       !handle->dith_default))
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                              rgb_buf, 3, rowstride, handle->conv, NULL,
-                              xdith, ydith);
-  else
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                               rgb_buf, 3, rowstride, handle->conv_d, NULL,
-                               xdith, ydith);
-}
-
-void
-xxlib_draw_rgb_32_image (XlibRgbHandle *handle, Drawable drawable,
-                        GC gc,
-                        int x,
-                        int y,
-                        int width,
-                        int height,
-                        XlibRgbDither dith,
-                        unsigned char *buf,
-                        int rowstride)
-{
-  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
-                                       !handle->dith_default))
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                               buf, 4, rowstride,
-                               handle->conv_32, NULL, 0, 0);
-  else
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                               buf, 4, rowstride,
-                               handle->conv_32_d, NULL, 0, 0);
-}
-
-static void
-xxlib_rgb_make_gray_cmap (XlibRgbHandle *handle)
-{
-  uint32 rgb[256];
-  int i;
-
-  for (i = 0; i < 256; i++)
-    rgb[i] = (i << 16)  | (i << 8) | i;
-  handle->gray_cmap = xxlib_rgb_cmap_new (handle, rgb, 256);
-}
-
-void
-xxlib_draw_gray_image (XlibRgbHandle *handle, Drawable drawable,
-                      GC gc,
-                      int x,
-                      int y,
-                      int width,
-                      int height,
-                      XlibRgbDither dith,
-                      unsigned char *buf,
-                      int rowstride)
-{
-  if (handle->bpp == 1 &&
-      handle->gray_cmap == NULL &&
-      (handle->x_visual_info->class == PseudoColor ||
-       handle->x_visual_info->class == GrayScale))
-    xxlib_rgb_make_gray_cmap (handle);
-  
-  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
-                                      !handle->dith_default))
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                              buf, 1, rowstride,
-                              handle->conv_gray, NULL, 0, 0);
-  else
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                              buf, 1, rowstride,
-                              handle->conv_gray_d, NULL, 0, 0);
-}
-
-XlibRgbCmap *
-xxlib_rgb_cmap_new (XlibRgbHandle *handle, uint32 *colors, int n_colors)
-{
-  XlibRgbCmap *cmap;
-  int i, j;
-  uint32 rgb;
-
-  if (n_colors < 0)
-    return NULL;
-  if (n_colors > 256)
-    return NULL;
-  cmap = malloc(sizeof(XlibRgbCmap));
-  memcpy (cmap->colors, colors, n_colors * sizeof(uint32));
-  if (handle->bpp == 1 &&
-      (handle->x_visual_info->class == PseudoColor ||
-       handle->x_visual_info->class == GrayScale))
-    for (i = 0; i < n_colors; i++)
-      {
-        rgb = colors[i];
-        j = ((rgb & 0xf00000) >> 12) |
-                   ((rgb & 0xf000) >> 8) |
-                   ((rgb & 0xf0) >> 4);
-#ifdef VERBOSE
-        printf ("%d %x %x %d\n", i, j, handle->colorcube[j]);
-#endif
-        cmap->lut[i] = handle->colorcube[j];
-      }
-  return cmap;
-}
-
-void
-xxlib_rgb_cmap_free (XlibRgbHandle *handle, XlibRgbCmap *cmap)
-{
-  free (cmap);
-}
-
-void
-xxlib_draw_indexed_image (XlibRgbHandle *handle, Drawable drawable,
-                        GC gc,
-                        int x,
-                        int y,
-                        int width,
-                        int height,
-                        XlibRgbDither dith,
-                        unsigned char *buf,
-                        int rowstride,
-                        XlibRgbCmap *cmap)
-{
-  if (dith == XLIB_RGB_DITHER_NONE || (dith == XLIB_RGB_DITHER_NORMAL &&
-                                       !handle->dith_default))
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                               buf, 1, rowstride,
-                               handle->conv_indexed, cmap, 0, 0);
-  else
-    xxlib_draw_rgb_image_core (handle, drawable, gc, x, y, width, height,
-                               buf, 1, rowstride,
-                               handle->conv_indexed_d, cmap, 0, 0);
-}
-
-void
-xxlib_draw_xprint_scaled_rgb_image( XlibRgbHandle *handle,
-                                    Drawable drawable,
-                                    long paper_resolution,
-                                    long image_resolution,
-                                    GC gc,
-                                    int x,
-                                    int y,
-                                    int width,
-                                    int height,
-                                    XlibRgbDither dith,
-                                    unsigned char *rgb_buf,
-                                    int rowstride)
-{
-  long available = ((65536 < handle->max_request_size) ? 
-                    (65536 << 1):(handle->max_request_size << 1))
-		   - 512 /* SIZEOF(xPutImageReq) */;
-                
-  if (image_resolution == 0)
-    image_resolution = paper_resolution;
-
-  if( (rowstride * height) < available )
-  {
-    xxlib_draw_rgb_image(handle,
-                         drawable,
-                         gc,
-                         x, y, width, height,
-                         dith,
-                         rgb_buf, rowstride);
-  }
-  else
-  {
-    int    subimageheight = available / rowstride;
-    double scaling_factor = (double)paper_resolution / (double)image_resolution;
-
-#ifdef DEBUG    
-    printf("xxlib_draw_xprint_scaled_rgb_image: "
-           "splitting image x=%d, y=%d, width=%d, height=%d, subimageheight=%d, scaling_factor=%g, max_request_size=%ld, available=%ld\n",
-           x, y, width, height, subimageheight, scaling_factor, (long)handle->max_request_size, (long)available);
-#endif /* DEBUG */
-
-    if (subimageheight == 0)
-        subimageheight = 1;
-
-      xxlib_draw_xprint_scaled_rgb_image(handle,
-                                         drawable,
-                                         paper_resolution, image_resolution,
-                                         gc,
-                                         x, y,
-                                         width, subimageheight,
-                                         dith,
-                                         rgb_buf,
-                                         rowstride);
-
-      xxlib_draw_xprint_scaled_rgb_image(handle,
-                                         drawable,
-                                         paper_resolution, image_resolution,
-                                         gc,
-                                         x, y+(int)((double)subimageheight*scaling_factor), 
-                                         width, (height-subimageheight),
-                                         dith,
-                                         (rgb_buf+(subimageheight*rowstride)),
-                                         rowstride);
-  }
-}
-
-Bool
-xxlib_rgb_ditherable (XlibRgbHandle *handle)
-{
-  return (handle->conv != handle->conv_d);
-}
-
-Colormap
-xxlib_rgb_get_cmap (XlibRgbHandle *handle)
-{
-  return (handle)?(handle->cmap):(None);
-}
-
-Visual *
-xxlib_rgb_get_visual (XlibRgbHandle *handle)
-{
-  /* xxlib_rgb_init (); */
-  return (handle)?(handle->x_visual_info->visual):(NULL);
-}
-
-XVisualInfo *
-xxlib_rgb_get_visual_info (XlibRgbHandle *handle)
-{
-  /* xxlib_rgb_init (); */
-  return (handle)?(handle->x_visual_info):(NULL);
-}
-
-int
-xxlib_rgb_get_depth (XlibRgbHandle *handle)
-{
-  XVisualInfo *v = xxlib_rgb_get_visual_info(handle);
-
-  return (v)?(v->depth):(0);
-}
-
-Display *
-xxlib_rgb_get_display (XlibRgbHandle *handle)
-{ 
-  return (handle)?(handle->display):(NULL);
-}
-
-Screen *
-xxlib_rgb_get_screen (XlibRgbHandle *handle)
-{
-  return (handle)?(handle->screen):(NULL);
-}
-
-typedef struct _RegisteredHandle
-{
-  const char    *name;
-  XlibRgbHandle *handle;
-} RegisteredHandle;
-
-static RegisteredHandle *registered_handles      = NULL;
-static unsigned int      registered_handles_size = 0;
-
-/* find registered handle by name */
-static
-RegisteredHandle *xxlib_find_registered_handle(const char *name)
-{
-  unsigned int i;
-  
-  for( i=0 ; i < registered_handles_size ; i++ )
-  {
-    if (name && registered_handles[i].name && 
-        !strcmp(name, registered_handles[i].name))
-      return &registered_handles[i];
-  }
-  
-  return NULL;
-}
-
-/* register handle.
- * This API is public to register a handle more then once (=alias), or if the handle 
- * has not been registered yet (e.g. |xxlib_rgb_create_handle()| called with
- * a NULL-|name| argument).
- */
-Bool xxlib_register_handle(const char *name, XlibRgbHandle *handle)
-{
-  RegisteredHandle *entry = NULL;
-  unsigned int i;
-  
-  if (xxlib_find_handle(name) || (handle == NULL))
-    return False;
-  
-  /* search for a free slot... */  
-  for( i=0 ; i < registered_handles_size ; i++ )
-  {
-    if (!registered_handles[i].handle)
-    {
-      entry = &registered_handles[i];
-      break;
-    }
-  }
-  
-  /* ... no unused entry found ? Then allocate a new one... */
-  if (!entry)
-  {
-    registered_handles_size++;
-    registered_handles = realloc(registered_handles, sizeof(RegisteredHandle)*registered_handles_size);
-  
-    if (!registered_handles)
-      abort();
-    entry = &registered_handles[registered_handles_size-1];
-  }
-
-  entry->name   = strdup(name);
-  entry->handle = handle;
-  
-  return True;
-}
-
-/* unregister the given handle by name. 
- * Return |True| if the |name| was found, |False| otherwise.
- * Note that |xxlib_rgb_destroy_handle()| unregisters the handle 
- * automagically (including all aliases).
- */
-Bool xxlib_deregister_handle(const char *name)
-{
-  RegisteredHandle *entry;
-  if ((entry = xxlib_find_registered_handle(name)) != NULL)
-  {
-    free((void *)entry->name);
-    entry->name   = NULL;
-    entry->handle = NULL;
-    return True;
-  }
-  
-  return False;  
-}
-
-/* used by |xxlib_rgb_destroy_handle()| to deregister handle and all
- * it's aliases... */
-static
-void xxlib_deregister_handle_by_handle(XlibRgbHandle *handle)
-{
-  unsigned int i;
-  
-  if (!handle)
-    return;
-  
-  for( i=0 ; i < registered_handles_size ; i++ )
-  {
-    if (registered_handles[i].handle == handle)
-    {
-      free((void *)registered_handles[i].name);
-      registered_handles[i].name   = NULL;
-      registered_handles[i].handle = NULL;    
-    }
-  }
-}
-
-/* find a registered handle by |name| */
-XlibRgbHandle *xxlib_find_handle(const char *name)
-{
-  RegisteredHandle *entry = xxlib_find_registered_handle(name);
-  return (entry)?(entry->handle):(NULL);
-}
-
-
deleted file mode 100644
--- a/gfx/src/xlibrgb/xlibrgb.h
+++ /dev/null
@@ -1,280 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org Code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * This code is derived from GdkRgb.
- * For more information on GdkRgb, see http://www.levien.com/gdkrgb/
- * Raph Levien <raph@acm.org>
- */
-
-/* Ported by Christopher Blizzard to Xlib.  With permission from the
- * original authors of this file, the contents of this file are also
- * redistributable under the terms of the Mozilla Public license.  For
- * information about the Mozilla Public License, please see the
- * license information at http://www.mozilla.org/MPL/
- */
-
-/* This code is copyright the following authors:
- * Raph Levien          <raph@acm.org>
- * Manish Singh         <manish@gtk.org>
- * Tim Janik            <timj@gtk.org>
- * Peter Mattis         <petm@xcf.berkeley.edu>
- * Spencer Kimball      <spencer@xcf.berkeley.edu>
- * Josh MacDonald       <jmacd@xcf.berkeley.edu>
- * Christopher Blizzard <blizzard@redhat.com>
- * Owen Taylor          <otaylor@redhat.com>
- * Shawn T. Amundson    <amundson@gtk.org>
- * Roland Mainz         <roland.mainz@informatik.med.uni-giessen.de> 
- */
-
-
-#ifndef __XLIB_RGB_H__
-#define __XLIB_RGB_H__
-
-/* Force ANSI C prototypes from X11 headers */
-#undef FUNCPROTO
-#define FUNCPROTO 15
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xos.h>
-#include <X11/Intrinsic.h>
-
-_XFUNCPROTOBEGIN
-
-/* Porting Note:
- * If you are going to use this code somewhere other than mozilla
- * you will need to set these defines.  It's pretty easy for Intel
- * but I'm not sure about other platforms.
- */
-#ifdef USE_MOZILLA_TYPES
-/* prtypes contains definitions for uint32/int32 and uint16/int16 */
-#include "prtypes.h"
-#include "prcpucfg.h"
-#include "nscore.h"
-
-#ifdef _IMPL_XLIBRGB_API
-#define NS_XLIBRGB_API(type) NS_EXPORT_(type)
-#else
-#define NS_XLIBRGB_API(type) NS_IMPORT_(type)
-#endif
-
-#define NS_TO_XXLIB_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
-#else
-typedef unsigned int uint32;
-typedef int int32;
-typedef unsigned short uint16;
-typedef short int16;
-
-#define NS_XLIBRGB_API(type) type
-#endif /* USE_MOZILLA_TYPES */
-
-typedef struct _XlibRgbCmap XlibRgbCmap;
-typedef struct _XlibRgbHandle XlibRgbHandle;
-
-struct _XlibRgbCmap {
-  unsigned int colors[256];
-  unsigned char lut[256]; /* for 8-bit modes */
-};
-
-
-typedef enum
-{
-  XLIB_RGB_DITHER_NONE,
-  XLIB_RGB_DITHER_NORMAL,
-  XLIB_RGB_DITHER_MAX
-} XlibRgbDither;
-
-typedef struct
-{
-  const char *handle_name;
-  int         pseudogray; /* emulate GrayScale via PseudoColor visuals */
-  int         install_colormap;
-  int         disallow_image_tiling;
-  int         disallow_mit_shmem;
-  int         verbose;
-  XVisualInfo xtemplate;
-  long        xtemplate_mask;
-} XlibRgbArgs;
-
-NS_XLIBRGB_API(XlibRgbHandle *)
-xxlib_rgb_create_handle (Display *display, Screen *screen, 
-                         XlibRgbArgs *args);
-                                  
-NS_XLIBRGB_API(void)
-xxlib_rgb_destroy_handle (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(unsigned long)
-xxlib_rgb_xpixel_from_rgb (XlibRgbHandle *handle, uint32 rgb);
-
-NS_XLIBRGB_API(void)
-xxlib_rgb_gc_set_foreground (XlibRgbHandle *handle, GC gc, uint32 rgb);
-
-NS_XLIBRGB_API(void)
-xxlib_rgb_gc_set_background (XlibRgbHandle *handle, GC gc, uint32 rgb);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_rgb_image (XlibRgbHandle *handle, Drawable drawable,
-                      GC gc,
-                      int x,
-                      int y,
-                      int width,
-                      int height,
-                      XlibRgbDither dith,
-                      unsigned char *rgb_buf,
-                      int rowstride);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_rgb_image_dithalign (XlibRgbHandle *handle, Drawable drawable,
-                                GC gc,
-                                int x,
-                                int y,
-                                int width,
-                                int height,
-                                XlibRgbDither dith,
-                                unsigned char *rgb_buf,
-                                int rowstride,
-                                int xdith,
-                                int ydith);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_rgb_32_image (XlibRgbHandle *handle, Drawable drawable,
-                         GC gc,
-                         int x,
-                         int y,
-                         int width,
-                         int height,
-                         XlibRgbDither dith,
-                         unsigned char *buf,
-                         int rowstride);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_gray_image (XlibRgbHandle *handle, Drawable drawable,
-                       GC gc,
-                       int x,
-                       int y,
-                       int width,
-                       int height,
-                       XlibRgbDither dith,
-                       unsigned char *buf,
-                       int rowstride);
-
-NS_XLIBRGB_API(XlibRgbCmap *)
-xxlib_rgb_cmap_new (XlibRgbHandle *handle, uint32 *colors, int n_colors);
-
-NS_XLIBRGB_API(void)
-xxlib_rgb_cmap_free (XlibRgbHandle *handle, XlibRgbCmap *cmap);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_indexed_image (XlibRgbHandle *handle, Drawable drawable,
-                          GC gc,
-                          int x,
-                          int y,
-                          int width,
-                          int height,
-                          XlibRgbDither dith,
-                          unsigned char *buf,
-                          int rowstride,
-                          XlibRgbCmap *cmap);
-
-NS_XLIBRGB_API(void)
-xxlib_draw_xprint_scaled_rgb_image( XlibRgbHandle *handle,
-                                    Drawable drawable,
-                                    long paper_resolution,
-                                    long image_resolution,
-                                    GC gc,
-                                    int x,
-                                    int y,
-                                    int width,
-                                    int height,
-                                    XlibRgbDither dith,
-                                    unsigned char *rgb_buf,
-                                    int rowstride);
-
-/* Below are some functions which are primarily useful for debugging
-   and experimentation. */
-NS_XLIBRGB_API(Bool)
-xxlib_rgb_ditherable (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(void)
-xxlib_rgb_set_verbose (XlibRgbHandle *handle, Bool verbose);
-
-NS_XLIBRGB_API(void)
-xxlib_rgb_set_min_colors (XlibRgbHandle *handle, int min_colors);
-
-NS_XLIBRGB_API(Colormap)
-xxlib_rgb_get_cmap (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(Visual *)
-xxlib_rgb_get_visual (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(XVisualInfo *)
-xxlib_rgb_get_visual_info (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(int)
-xxlib_rgb_get_depth (XlibRgbHandle *handle);
-
-/* hint: if you don't how to obtain a handle - use |xxlib_find_handle()| :-) */
-NS_XLIBRGB_API(Display *)
-xxlib_rgb_get_display (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(Screen *)
-xxlib_rgb_get_screen (XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(unsigned long)
-xxlib_get_prec_from_mask(unsigned long);
-
-NS_XLIBRGB_API(unsigned long)
-xxlib_get_shift_from_mask(unsigned long);
-
-/* default name - for cases where there is only one XlibRgbHandle required */
-#define XXLIBRGB_DEFAULT_HANDLE ("xxlib-default")
-
-NS_XLIBRGB_API(Bool)
-xxlib_register_handle(const char *name, XlibRgbHandle *handle);
-
-NS_XLIBRGB_API(Bool)
-xxlib_deregister_handle(const char *name);
-
-NS_XLIBRGB_API(XlibRgbHandle *)
-xxlib_find_handle(const char *name);
-
-_XFUNCPROTOEND
-
-#endif /* !__XLIB_RGB_H__ */
-
deleted file mode 100644
--- a/gfx/src/xlibrgb/xlibrgb.pkg
+++ /dev/null
@@ -1,4 +0,0 @@
-[gecko]
-#if SHARED_LIBRARY
-dist/bin/@SHARED_LIBRARY@
-#endif
deleted file mode 100644
--- a/gfx/src/xprint/Makefile.in
+++ /dev/null
@@ -1,131 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE		= gfx
-LIBRARY_NAME	= gfxxprint
-EXPORT_LIBRARY	= 1
-IS_COMPONENT	= 1
-MODULE_NAME	= nsGfxXprintModule
-GRE_MODULE	= 1
-LIBXUL_LIBRARY = 1
-
-EXTRA_DSO_LIBS	= gfxshared_s gkgfx
-
-REQUIRES	= xpcom \
-		  string \
-		  xlibrgb \
-		  xprintutil \
-		  widget \
-		  pref \
-		  locale \
-		  uconv \
-		  unicharutil \
-		  imglib2 \
-		  $(NULL)
-
-# Sun's Complex Text Layout support
-ifdef SUNCTL
-REQUIRES	+= ctl
-endif
-
-# Code shared between GTK+, Xlib and Xprint gfx modules
-# (empty for now - but this will be filled soon...)
-X11SHARED_LCPPSRCS = \
-		$(NULL)
-
-# nsDrawingSurfaceXlib only required for staticbuild 
-XLIB_LCPPSRCS	= \
-		nsDrawingSurfaceXlib.cpp \
-		nsFontMetricsXlib.cpp \
-		nsRenderingContextXlib.cpp \
-		nsRegionXlib.cpp \
-		nsGCCache.cpp \
-		$(NULL)
-
-CPPSRCS		= \
-		$(X11SHARED_LCPPSRCS) \
-		$(XLIB_LCPPSRCS) \
-		nsDeviceContextXP.cpp \
-		nsGfxFactoryXP.cpp \
-		nsXPrintContext.cpp \
-		nsRenderingContextXp.cpp \
-		$(NULL)
-
-EXPORTS		= \
-		nsIDeviceContextXPrint.h \
-		nsGfxXPrintCID.h \
-		nsIDeviceContextSpecXPrint.h \
-		$(NULL)
-
-CXXFLAGS	 += $(MOZ_XPRINT_CFLAGS)
-
-GARBAGE		+= $(X11SHARED_LCPPSRCS) $(XLIB_LCPPSRCS) $(wildcard *.$(OBJ_SUFFIX))
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES         += -DUSE_MOZILLA_TYPES -DUSE_XPRINT
-CFLAGS		+= $(TK_CFLAGS)
-CXXFLAGS	+= $(TK_CFLAGS)
-
-EXTRA_DSO_LDOPTS += \
-		$(LIBS_DIR) \
-		-lxlibrgb \
-		-lxprintutil \
-		$(EXTRA_DSO_LIBS) \
-		$(MOZ_COMPONENT_LIBS) \
-		$(MOZ_XPRINT_LDFLAGS) \
-		$(MOZ_UNICHARUTIL_LIBS) \
-		$(NULL)
-
-LOCAL_INCLUDES	= \
-		-I../.. \
-		-I$(srcdir) \
-		-I$(srcdir)/../xlib \
-		-I$(srcdir)/../x11shared \
-		-I$(srcdir)/.. \
-		$(NULL)
-
-export:: $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS)) $(addprefix $(srcdir)/../xlib/,$(XLIB_LCPPSRCS))
-	$(INSTALL) $^ .
deleted file mode 100644
--- a/gfx/src/xprint/nsDeviceContextXP.cpp
+++ /dev/null
@@ -1,401 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *   Bradley Baetz <bbaetz@cs.mcgill.ca>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifdef MOZ_LOGGING
-#define FORCE_PR_LOG 1 /* Allow logging in the release build */
-#endif /* MOZ_LOGGING */
-#include "prlog.h"
- 
-#include "nsDeviceContextXP.h"
-#include "nsRenderingContextXp.h"
-#include "nsFontMetricsXlib.h"
-#include "nsIDeviceContext.h"
-#include "nsIDeviceContextSpecXPrint.h"
-#include "nspr.h"
-#include "nsXPrintContext.h"
-
-#ifdef PR_LOGGING
-static PRLogModuleInfo *nsDeviceContextXpLM = PR_NewLogModule("nsDeviceContextXp");
-#endif /* PR_LOGGING */
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-nsDeviceContextXp :: nsDeviceContextXp()
-  : nsDeviceContextX(),
-    mPrintContext(nsnull),
-    mSpec(nsnull),
-    mParentDeviceContext(nsnull),
-    mFontMetricsContext(nsnull),
-    mRCContext(nsnull)
-{
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- *        @update 12/21/98 dwc
- */
-nsDeviceContextXp :: ~nsDeviceContextXp() 
-{ 
-  DestroyXPContext();
-}
-
-
-NS_IMETHODIMP
-nsDeviceContextXp::SetSpec(nsIDeviceContextSpec* aSpec)
-{
-  nsresult  rv = NS_ERROR_FAILURE;
-  PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::SetSpec()\n"));
-
-  nsCOMPtr<nsIDeviceContextSpecXp> xpSpec;
-
-  mSpec = aSpec;
-
-  if (mPrintContext)
-    DestroyXPContext(); // we cannot reuse that...
-    
-  mPrintContext = new nsXPrintContext();
-  if (!mPrintContext)
-    return  NS_ERROR_OUT_OF_MEMORY;
-    
-  xpSpec = do_QueryInterface(mSpec, &rv);
-  if (NS_SUCCEEDED(rv)) {
-    rv = mPrintContext->Init(this, xpSpec);
-
-    if (NS_FAILED(rv)) {
-      DestroyXPContext();
-    }
-  }
- 
-  return rv;
-}
-
-NS_IMPL_ISUPPORTS_INHERITED1(nsDeviceContextXp,
-                             DeviceContextImpl,
-                             nsIDeviceContextXp)
-
-/** ---------------------------------------------------
- *  See documentation in nsDeviceContextXp.h
- * 
- * This method is called after SetSpec
- */
-NS_IMETHODIMP
-nsDeviceContextXp::InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aParentContext)
-{
-  nsresult rv;
-
-  // Initialization moved to SetSpec to be done after creating the Print Context
-  float origscale, newscale;
-  float t2d, a2d;
-  int   print_x_resolution,
-        print_y_resolution;
-
-  mPrintContext->GetPrintResolution(print_x_resolution, print_y_resolution);
-  
-  if (print_x_resolution != print_y_resolution) {
-    PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("print_x_resolution != print_y_resolution not yet supported by Mozilla's layout engine\n"));
-    return NS_ERROR_NOT_IMPLEMENTED; /* this error code should be more detailed */
-  }
-
-  mPixelsToTwips = (float)NSIntPointsToTwips(72) / (float)print_x_resolution;
-  mTwipsToPixels = 1.0f / mPixelsToTwips;
-
-  newscale = TwipsToDevUnits();
-  origscale = aParentContext->TwipsToDevUnits();
-
-  mCPixelScale = newscale / origscale;
-
-  t2d = aParentContext->TwipsToDevUnits();
-  a2d = aParentContext->AppUnitsToDevUnits();
-
-  mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
-  mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
-
-  NS_ASSERTION(aParentContext, "aCreatingDeviceContext cannot be NULL!!!");
-  mParentDeviceContext = aParentContext;
-
-  /* be sure we've cleaned-up old rubbish - new values will re-populate nsFontMetricsXlib soon... */
-  DeleteRenderingContextXlibContext(mRCContext);
-  DeleteFontMetricsXlibContext(mFontMetricsContext);
-  mRCContext          = nsnull;
-  mFontMetricsContext = nsnull;
- 
-  rv = CreateFontMetricsXlibContext(this, PR_TRUE, &mFontMetricsContext);
-  if (NS_FAILED(rv))
-    return rv;
-
-  rv = CreateRenderingContextXlibContext(this, &mRCContext);
-  if (NS_FAILED(rv))
-    return rv;
-   
-  return NS_OK;
-}
-
-/** ---------------------------------------------------
- */
-NS_IMETHODIMP nsDeviceContextXp :: CreateRenderingContext(nsIRenderingContext *&aContext)
-{
-  nsresult rv;
-   
-  aContext = nsnull;
-
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  nsCOMPtr<nsRenderingContextXp> renderingContext = new nsRenderingContextXp();
-  if (!renderingContext)
-    return NS_ERROR_OUT_OF_MEMORY;
-     
-  rv = renderingContext->Init(this);
-
-  if (NS_SUCCEEDED(rv)) {
-    aContext = renderingContext;
-    NS_ADDREF(aContext);
-  }
-
-  return rv;
-}
-
-NS_IMETHODIMP nsDeviceContextXp::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
-{
-  nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextXp();
-  if (!renderingContext)
-    return NS_ERROR_OUT_OF_MEMORY;
-         
-  aContext = renderingContext;
-  NS_ADDREF(aContext);
-  
-  return NS_OK;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
-{
-  aSupportsWidgets = PR_FALSE;
-  return NS_OK;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- *        @update 12/21/98 dwc
- */
-NS_IMETHODIMP nsDeviceContextXp :: CheckFontExistence(const nsString& aFontName)
-{
-  return nsFontMetricsXlib::FamilyExists(mFontMetricsContext, aFontName);
-}
-
-NS_IMETHODIMP nsDeviceContextXp :: GetSystemFont(nsSystemFontID aID, 
-                                                 nsFont *aFont) const
-{
-  if (mParentDeviceContext != nsnull) {
-    return mParentDeviceContext->GetSystemFont(aID, aFont);
-  }
-  return NS_ERROR_FAILURE;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::GetDeviceSurfaceDimensions(PRInt32 &aWidth, 
-                                                        PRInt32 &aHeight)
-{
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  float width, height;
-  width  = (float) mPrintContext->GetWidth();
-  height = (float) mPrintContext->GetHeight();
-
-  aWidth  = NSToIntRound(width  * mDevUnitsToAppUnits);
-  aHeight = NSToIntRound(height * mDevUnitsToAppUnits);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsDeviceContextXp::GetRect(nsRect &aRect)
-{
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  PRInt32 width, height;
-  nsresult rv;
-  rv = GetDeviceSurfaceDimensions(width, height);
-  aRect.x = 0;
-  aRect.y = 0;
-  aRect.width = width;
-  aRect.height = height;
-  return rv;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::GetClientRect(nsRect &aRect)
-{
-  return GetRect(aRect);
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext)
-{
-  aContext = nsnull;
-  return NS_OK;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
-{  
-  PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::BeginDocument()\n"));
-
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  return mPrintContext->BeginDocument(aTitle, aPrintToFileName, aStartPage, aEndPage);
-}
-
-
-void nsDeviceContextXp::DestroyXPContext()
-{
-  PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::DestroyXPContext()\n"));
-
-  if (!mPrintContext)
-    return;
-
-  /* gisburn: mPrintContext cannot be reused between to print
-   * tasks as the destination print server may be a different one
-   * or the printer used on the same print server has other
-   * properties (build-in fonts for example ) than the printer
-   * previously used. */
-  FlushFontCache();
-  DeleteRenderingContextXlibContext(mRCContext);
-  DeleteFontMetricsXlibContext(mFontMetricsContext);
-  mRCContext          = nsnull;
-  mFontMetricsContext = nsnull;
-
-  mPrintContext = nsnull; // nsCOMPtr will call |delete mPrintContext;|
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::EndDocument(void)
-{
-  PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::EndDocument()\n"));
-
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  nsresult rv = mPrintContext->EndDocument();
-  DestroyXPContext();
-  return rv;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::AbortDocument(void)
-{
-  PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::AbortDocument()\n"));
-
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  nsresult rv = mPrintContext->AbortDocument();
-  DestroyXPContext();
-  return rv;
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- */
-NS_IMETHODIMP nsDeviceContextXp::BeginPage(void)
-{
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  return mPrintContext->BeginPage();
-}
-
-/** ---------------------------------------------------
- *  See documentation in nsIDeviceContext.h
- *        @update 12/21/98 dwc
- */
-NS_IMETHODIMP nsDeviceContextXp::EndPage(void)
-{
-  NS_ENSURE_TRUE(mPrintContext != nsnull, NS_ERROR_NULL_POINTER);
-
-  return mPrintContext->EndPage();
-}
-
-NS_IMETHODIMP
-nsDeviceContextXp::GetPrintContext(nsXPrintContext*& aContext)
-{
-  aContext = mPrintContext;
-  return NS_OK;
-}
-
-class nsFontCacheXp : public nsFontCache
-{
-public:
-  /* override DeviceContextImpl::CreateFontCache() */
-  virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** aResult);
-};
-
-
-nsresult nsFontCacheXp::CreateFontMetricsInstance(nsIFontMetrics** aResult)
-{
-  NS_PRECONDITION(aResult, "null out param");
-  nsIFontMetrics *fm = new nsFontMetricsXlib();
-  if (!fm)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(fm);
-  *aResult = fm;
-  return NS_OK;
-}
-
-/* override DeviceContextImpl::CreateFontCache() */
-NS_IMETHODIMP nsDeviceContextXp::CreateFontCache()
-{
-  mFontCache = new nsFontCacheXp();
-  if (nsnull == mFontCache) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  return mFontCache->Init(this);
-}
-
-
deleted file mode 100644
--- a/gfx/src/xprint/nsDeviceContextXP.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsDeviceContextXp_h___
-#define nsDeviceContextXp_h___
-
-#include "nsDeviceContextX.h"
-#include "nsRenderingContextXp.h"
-#include "nsIDeviceContextXPrint.h"
-#include "nsXPrintContext.h"
-
-class nsDeviceContextXp : public nsDeviceContextX,
-                          public nsIDeviceContextXp
-{
-public:
-  nsDeviceContextXp();
-
-  NS_DECL_ISUPPORTS_INHERITED
-
-  /**
-   * This method does nothing since a postscript devicecontext will never be created
-   * with a NativeWidget.
-   * @update 12/21/98 dwc
-   */
-  NS_IMETHOD  InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aPrinterContext); 
-
-  NS_IMETHOD  CreateRenderingContext(nsIRenderingContext *&aContext);
-  NS_IMETHOD  CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
-  NS_IMETHOD  CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
-#ifdef NOT_NOW
-  /* Xprint API supports offscreen surfaces but Mozilla does not make use of
-   * them, see bug 124761 ("RFE: Make use of "offpaper" drawing surfaces in
-   * some printing APIs"))
-   */
-  NS_IMETHOD  CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}
-#else
-  NS_IMETHOD  CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) {return NS_ERROR_NOT_IMPLEMENTED;}
-#endif /* NOT_NOW */
-  NS_IMETHOD  CreateRenderingContextInstance(nsIRenderingContext *&aContext);
-  NS_IMETHOD  SupportsNativeWidgets(PRBool &aSupportsWidgets);
-
-  NS_IMETHOD         CheckFontExistence(const nsString& aFontName);
-
-  NS_IMETHOD         GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
-  NS_IMETHOD         GetRect(nsRect &aRect);
-  NS_IMETHOD         GetClientRect(nsRect &aRect);
-
-  NS_IMETHOD         GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext);
-  NS_IMETHOD         GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
-  NS_IMETHOD         BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
-  NS_IMETHOD         EndDocument(void);
-  NS_IMETHOD         AbortDocument(void);
-  NS_IMETHOD         BeginPage(void);
-  NS_IMETHOD         EndPage(void);
-
-  NS_IMETHOD         SetSpec(nsIDeviceContextSpec *aSpec);
-  NS_IMETHOD         GetXlibRgbHandle(XlibRgbHandle *&aHandle)
-                     { return mPrintContext->GetXlibRgbHandle(aHandle); }
-  XlibRgbHandle *GetXlibRgbHandle() { XlibRgbHandle *h; mPrintContext->GetXlibRgbHandle(h); return h; } 
-  NS_IMETHOD         GetDepth(PRUint32 &depth) 
-                     { depth = xxlib_rgb_get_depth(GetXlibRgbHandle()); return NS_OK; }
-  NS_IMETHOD         GetPrintContext(nsXPrintContext*& aContext);
-
-  NS_IMETHOD         CreateFontCache();
-
-  virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) { aContext = mFontMetricsContext; };
-  virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) { aContext = mRCContext; };
- 
-protected:
-  virtual         ~nsDeviceContextXp();
-  void             DestroyXPContext();
-
-  nsCOMPtr<nsXPrintContext>      mPrintContext;  
-  nsCOMPtr<nsIDeviceContextSpec> mSpec;
-  nsCOMPtr<nsIDeviceContext>     mParentDeviceContext;
-  nsFontMetricsXlibContext      *mFontMetricsContext;
-  nsRenderingContextXlibContext *mRCContext;
-};
-
-#endif /* !nsDeviceContextXp_h___ */
deleted file mode 100644
--- a/gfx/src/xprint/nsGfxFactoryXP.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include <stdio.h>
-#include "nscore.h"
-#include "nsIFactory.h"
-#include "nsIGenericFactory.h"     // need this for ps code
-#include "nsISupports.h"
-#include "nsGfxCIID.h"
-#include "nsIModule.h"
-#include "nsCOMPtr.h"
-#include "nsDeviceContextXP.h"
-#include "nsGfxXPrintCID.h"
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextXp)
- 
-static const nsModuleComponentInfo components[] =
-{
-  { "GFX Xprint Device Context",
-    NS_DEVICECONTEXTXP_CID,
-    "@mozilla.org/gfx/decidecontext/xprint;1",
-    nsDeviceContextXpConstructor }  
-};
- 
-NS_IMPL_NSGETMODULE(nsGfxXprintModule, components)
-
deleted file mode 100644
--- a/gfx/src/xprint/nsGfxXPrintCID.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsGfxFactoryXp_h__
-#define nsGfxFactoryXp_h__
-
-/* {4c2bb896-13c9-11d3-9304-006008948010} */
-#define NS_DEVICECONTEXTXP_CID \
-  {0x4c2bb896, 0x13c9, 0x11d3, \
-    {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}}
-
-#endif
-
deleted file mode 100644
--- a/gfx/src/xprint/nsIDeviceContextSpecXPrint.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *   Julien Lafon <julien.lafon@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsIDeviceContextSpecXP_h___
-#define nsIDeviceContextSpecXP_h___
-
-#include "nsISupports.h"
-
-/* UUID=12ab7845-a341-41ba-bc12-6025e0b11e0e */
-#define NS_IDEVICE_CONTEXT_SPEC_XP_IID { 0x12ab7845, 0xa341, 0x41ba, { 0x60, 0x25, 0xe0, 0xb1, 0x1e, 0x0e } }
-
-class nsIDeviceContextSpecXp : public nsISupports
-{
-
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_XP_IID)
-
-  /*
-   * If PR_TRUE, print to printer  
-   * @update 
-   * @param aToPrinter --  
-   * @return 
-   **/
-   NS_IMETHOD GetToPrinter( PRBool &aToPrinter ) = 0; 
-
-  /*
-   * If PR_TRUE, first page first 
-   * @update 
-   * @param aFpf -- 
-   * @return 
-   **/
-   NS_IMETHOD GetFirstPageFirst (  PRBool &aFpf ) = 0;     
-
-  /*
-   * If PR_TRUE, print grayscale 
-   * @update 
-   * @param aGrayscale --
-   * @return 
-   **/
-   NS_IMETHOD GetGrayscale(  PRBool &aGrayscale ) = 0;   
-
-  /*
-   * Top margin 
-   * @update 
-   * @param aValue --
-   * @return 
-   **/
-   NS_IMETHOD GetTopMargin (  float &aValue ) = 0; 
-
-  /*
-   * Bottom margin 
-   * @update 
-   * @param aValue --
-   * @return 
-   **/
-   NS_IMETHOD GetBottomMargin (  float &aValue ) = 0; 
-
-  /*
-   * Left margin 
-   * @update 
-   * @param aValue --
-   * @return 
-   **/
-   NS_IMETHOD GetLeftMargin (  float &aValue ) = 0; 
-
-  /*
-   * Right margin 
-   * @update 
-   * @param aValue --
-   * @return 
-   **/
-   NS_IMETHOD GetRightMargin (  float &aValue ) = 0; 
-
-  /*
-   * Printer name e.g., myprinter or myprinter@myxprt:5 
-   * @update 
-   * @param aPrinter --
-   * @return 
-   **/
-   NS_IMETHOD GetPrinterName ( const char **aPrinter ) = 0;   
-
-  /*
-   * If PR_TRUE, user chose Landscape
-   * @update 
-   * @param aLandscape
-   * @return 
-   **/
-   NS_IMETHOD GetLandscape ( PRBool &aLandscape ) = 0;   
-
-  /*
-   * If toPrinter = PR_FALSE, dest file 
-   * @update 
-   * @param aPath --
-   * @return 
-   **/
-   NS_IMETHOD GetPath ( const char **aPath ) = 0;    
-
-  /*
-   * If PR_TRUE, user cancelled 
-   * @update 
-   * @param aCancel -- 
-   * @return 
-   **/
-   NS_IMETHOD GetUserCancelled(  PRBool &aCancel ) = 0;
-   
-  /*
-   * Paper name e.g., "din-a4" or "manual/din-a4"
-   * @update 
-   * @param aPaperName --
-   * @return 
-   **/
-   NS_IMETHOD GetPaperName ( const char **aPaperName ) = 0;   
-
-  /*
-   * Plex name e.g., "simplex", "duplex", "tumble" or any 
-   * driver/printer-specific custom value
-   * @update 
-   * @param aPlexName --
-   * @return 
-   **/
-   NS_IMETHOD GetPlexName ( const char **aPlexName ) = 0;   
-
-  /*
-   * Resolution/quality name e.g., "600", "600x300", "high-res",
-   * "med-res"
-   * driver/printer-specific custom value
-   * @update 
-   * @param aResolutionName --
-   * @return 
-   **/
-   NS_IMETHOD GetResolutionName ( const char **aResolutionName ) = 0;   
-   
-  /*
-   * Colorspace name e.g., "TrueColor", "Grayscale/10bit", "b/w",
-   * "CYMK"
-   * driver/printer-specific custom value
-   * @update 
-   * @param aColorspace --
-   * @return 
-   **/
-   NS_IMETHOD GetColorspace ( const char **aColorspace ) = 0;   
-
-  /*
-   * If PR_TRUE, enable font download to printer
-   * @update 
-   * @param aDownloadFonts --
-   * @return 
-   **/
-   NS_IMETHOD GetDownloadFonts( PRBool &aDownloadFonts ) = 0;   
-
-  /*
-   * Return number of copies to print
-   * @update 
-   * @param aCopies
-   * @return 
-   **/   
-   NS_IMETHOD GetCopies ( int &aCopies ) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContextSpecXp,
-                              NS_IDEVICE_CONTEXT_SPEC_XP_IID)
-
-#endif /* !nsIDeviceContextSpecXP_h___ */
-
deleted file mode 100644
--- a/gfx/src/xprint/nsIDeviceContextXPrint.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.h"
-
-#ifndef __nsIDeviceContextXp_h
-#define __nsIDeviceContextXp_h
-
-/* {35efd8b6-13cc-11d3-9d3a-006008948010} */
-#define NS_IDEVICECONTEXTXP_IID \
-  {0x35efd8b6, 0x13cc, 0x11d3, \
-    {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}}
-
-class nsXPrintContext;
-
-class nsIDeviceContextXp : public nsISupports
-{
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICECONTEXTXP_IID)
-  
-  NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec) = 0;
-
-  NS_IMETHOD InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext,
-                                 nsIDeviceContext *aPrinterContext) = 0;
-
-  NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContextXp, NS_IDEVICECONTEXTXP_IID)
-
-#endif /* !__nsIDeviceContextXp_h */
deleted file mode 100644
--- a/gfx/src/xprint/nsRenderingContextXp.cpp
+++ /dev/null
@@ -1,316 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *   Julien Lafon <julien.lafon@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
- 
-#include "nsRenderingContextXp.h"
-#include "nsFontMetricsXlib.h"
-#include "nsDeviceContextXP.h"
-#include "nsCompressedCharMap.h"
-#include "xlibrgb.h"
-#include "prprf.h"
-#include "prmem.h"
-#include "prlog.h"
-#include "nsGCCache.h"
-#include "imgIContainer.h"
-#include "gfxIImageFrame.h"
-#include "nsIInterfaceRequestor.h"
-#include "nsIInterfaceRequestorUtils.h"
-#include "nsLocalFile.h"
-#include <sys/mman.h>
-#include <errno.h>
-
-#ifdef PR_LOGGING 
-static PRLogModuleInfo *RenderingContextXpLM = PR_NewLogModule("RenderingContextXp");
-#endif /* PR_LOGGING */ 
-
-nsRenderingContextXp::nsRenderingContextXp()
-  : nsRenderingContextXlib(),
-  mPrintContext(nsnull)
-{
-}
-
-nsRenderingContextXp::~nsRenderingContextXp()
-{
-}
-
-NS_IMETHODIMP
-nsRenderingContextXp::Init(nsIDeviceContext* aContext)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::Init(nsIDeviceContext *)\n"));
-
-  NS_ENSURE_TRUE(nsnull != aContext, NS_ERROR_NULL_POINTER);
-  mContext = aContext;
-  if (mContext) {
-     nsIDeviceContext *dc = mContext;     
-     NS_STATIC_CAST(nsDeviceContextXp *,dc)->GetPrintContext(mPrintContext);
-  }
-  NS_ENSURE_TRUE(nsnull != mPrintContext, NS_ERROR_NULL_POINTER);
-
-  mPrintContext->GetXlibRgbHandle(mXlibRgbHandle);
-  mDisplay = xxlib_rgb_get_display(mXlibRgbHandle);
-
-  /* A printer usually does not support things like multiple drawing surfaces
-   * (nor "offscreen" drawing surfaces... would be quite difficult to 
-   * implement) - however the Xprint API supports offscreen surfaces for
-   * all DDX implementations.
-   */
-  mOffscreenSurface = mSurface = mPrintContext; 
-  UpdateGC(); /* Fill |mGC| */
-  mPrintContext->SetGC(mGC);
-
-  return CommonInit();
-}
-
-NS_IMETHODIMP nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsIWidget *aWidget) 
-{ 
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsIWidget *aWidget)\n"));
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface)\n"));
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsRenderingContextXp::LockDrawingSurface(PRInt32 aX, PRInt32 aY,
-                                         PRUint32 aWidth, PRUint32 aHeight,
-                                         void **aBits,
-                                         PRInt32 *aStride,
-                                         PRInt32 *aWidthBytes,
-                                         PRUint32 aFlags)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::LockDrawingSurface()\n"));
-  PushState();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextXp::UnlockDrawingSurface(void)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::UnlockDrawingSurface()\n"));
-  PopState();
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsRenderingContextXp::DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::DrawImage()\n"));
-
-  nsRect dr = aDestRect;
-  mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
-
-  nsCOMPtr<gfxIImageFrame> iframe;
-  aImage->GetCurrentFrame(getter_AddRefs(iframe));
-  if (!iframe) 
-    return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
-  if (!img) 
-    return NS_ERROR_FAILURE;
-
-  // doesn't it seem like we should use more of the params here?
-  // img->Draw(*this, surface, sr.x, sr.y, sr.width, sr.height, dr.x, dr.y, dr.width, dr.height);
-
-  nsRect sr = aSrcRect;
-  mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
-  sr.x = aSrcRect.x;
-  sr.y = aSrcRect.y;
-  mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
-
-  UpdateGC();
-  return mPrintContext->DrawImage(mSurface->GetDrawable(),
-                                  mGC, img,
-                                  sr.x, sr.y,
-                                  sr.width, sr.height,
-                                  dr.x, dr.y,
-                                  dr.width, dr.height);
-}
-
-#ifdef JULIEN_NOTNOW
-static
-void TilePixmap(Display *dpy, Pixmap src, Pixmap dest, PRInt32 aSXOffset,
-                PRInt32 aSYOffset, const nsRect &destRect,
-                const nsRect &clipRect, PRBool useClip)
-{
-  GC gc;
-  XGCValues values;
-  unsigned long valuesMask;
-  memset(&values, 0, sizeof(XGCValues));
-  values.fill_style = FillTiled;
-  values.tile = src;
-  values.ts_x_origin = destRect.x - aSXOffset;
-  values.ts_y_origin = destRect.y - aSYOffset;
-  valuesMask = GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle;
-  gc = XCreateGC(dpy, src, valuesMask, &values);
-
-  if (useClip) {
-    XRectangle xrectangle;
-    xrectangle.x      = clipRect.x;
-    xrectangle.y      = clipRect.y;
-    xrectangle.width  = clipRect.width;
-    xrectangle.height = clipRect.height;
-    XSetClipRectangles(dpy, gc, 0, 0, &xrectangle, 1, Unsorted);
-  }
-
-  XFillRectangle(dpy, dest, gc, destRect.x, destRect.y,
-                 destRect.width, destRect.height);
-
-  XFreeGC(dpy, gc);
-}
-#endif /* JULIEN_NOTNOW */
-
-NS_IMETHODIMP
-nsRenderingContextXp::DrawTile(imgIContainer *aImage,
-                               nscoord aSXOffset,
-                               nscoord aSYOffset,
-                               const nsRect *aTileRect)
-{
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG,
-         ("nsRenderingContextXp::DrawTile(imgIContainer *aImage, nscoord aXImageStart, nscoord aYImageStart, const nsRect *aTargetRect)\n"));
-
-/* xxx_julien: Either this code or the PDF DDX needs a fix */
-#ifdef JULIEN_NOTNOW    
-  nsCOMPtr<gfxIImageFrame> iframe;
-  aImage->GetCurrentFrame(getter_AddRefs(iframe));
-  if (!iframe) 
-    return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
-  if (!img) 
-    return NS_ERROR_FAILURE;
-
-  PushState();
-
-  nscoord imgwidth, imgheight;
-  aImage->GetWidth(&imgwidth);
-  aImage->GetHeight(&imgheight);
-
-  imgwidth  = NSToCoordRound(imgwidth*mP2T);
-  imgheight = NSToCoordRound(imgheight*mP2T);
-  
-  Drawable srcdrawable;
-  Drawable destdrawable;
-  mSurface->GetDrawable(destdrawable);
-
-  UpdateGC(); 
-  srcdrawable = XCreatePixmap(mDisplay, destdrawable,
-                              imgwidth, imgheight,
-                              xxlib_rgb_get_depth(mXlibRgbHandle));
-
-  XGCValues     values;
-  unsigned long valuesMask = 0;
-  nsRenderingContextXlibContext *rcContext;
-  nsIDeviceContext *dc = mContext;
-  NS_STATIC_CAST(nsDeviceContextX *, dc)->GetRCContext(rcContext);
-  xGC *xgc = rcContext->mGcCache.GetGC(mDisplay, srcdrawable, valuesMask, &values, NULL);
-
-  mPrintContext->DrawImage(srcdrawable,
-                           xgc, img,
-                           0, 0,
-                           img->GetWidth(), img->GetHeight(),
-                           0, 0,
-                           imgwidth, imgheight);
-
-  /* Xlib API can tile for us */
-  nsRect clipRect;
-  PRBool isValid;
-
-  GetClipRect(clipRect, isValid);
-  TilePixmap(mDisplay, srcdrawable, destdrawable, aSXOffset, aSYOffset,
-             *aTileRect, clipRect, PR_FALSE);
-
-  xgc->Release();
-  XFreePixmap(mDisplay, srcdrawable);
-  
-  PopState();
-#endif /* JULIEN_NOTNOW */
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsRenderingContextXp::RenderEPS(const nsRect& aRect, FILE *aDataFile)
-{
-  nsresult             rv;
-  int                  fd;
-  const unsigned char *data;
-  size_t               datalen;
-
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("nsRenderingContextXp::RenderPostScriptDataFragment()\n"));
-
-  /* Get file size */
-  fseek(aDataFile, 0, SEEK_END);
-  datalen = ftell(aDataFile);
-
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("file size=%ld\n", (long)datalen));  
-
-  /* Safeguard against bogus values
-   * (make sure we clamp the size to a reasonable value (say... 128 MB)) */
-  if (datalen <= 0 || datalen > (128 * 1024 * 1024)) {
-    PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("error: file size %ld too large\n", (long)datalen));
-    return NS_ERROR_FAILURE;
-  }
-  
-  fflush(aDataFile);
-  fd = fileno(aDataFile);
-  PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("fileno=%d\n", fd));  
-  data = (const unsigned char *)mmap(0, datalen, PROT_READ, MAP_SHARED, fd, 0); 
-  if (MAP_FAILED == data) {
-    int saved_errno = errno;
-    PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("mmap() failure, errno=%s/%d\n",
-           strerror(saved_errno), saved_errno));  
-    return nsresultForErrno(saved_errno);
-  }
-
-  PushState();
-
-  nsRect trect = aRect;
-  mTranMatrix->TransformCoord(&trect.x, &trect.y, &trect.width, &trect.height);
-  UpdateGC();
-  rv = mPrintContext->RenderEPS(mSurface->GetDrawable(), trect, data, datalen);
-
-  PopState();
-  
-  munmap((char *)data, datalen);
-
-  return rv;
-}
-
-
-
deleted file mode 100644
--- a/gfx/src/xprint/nsRenderingContextXp.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
- 
-#ifndef nsRenderingContextXp_h___
-#define nsRenderingContextXp_h___ 1
-
-#include "nsXPrintContext.h"
-#include "nsRenderingContextXlib.h"
-
-/* Rendering context class to match the special needs of Xprint (X11 print
- * system). Nearly identical to nsRenderingContextXlib - except two details:
- * - "offscreen" drawing surfaces are not supported by printers, therefore
- *   we "disable" those functions here by overriding them with empty versions.
- * - images are handeled by nsXPrintContext class instead of nsImageXlib
- */
-class nsRenderingContextXp : public nsRenderingContextXlib
-{
- public:
-  nsRenderingContextXp();
-  virtual ~nsRenderingContextXp();
-   
-  NS_IMETHOD Init(nsIDeviceContext* aContext);
-  NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
-  NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
-
-  NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
-                                void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
-                                PRUint32 aFlags);
-  NS_IMETHOD UnlockDrawingSurface(void);
- 
-  NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect);
-
-  NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXImageStart, nscoord aYImageStart, const nsRect *aTargetRect);
-
-  NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile);
-                               
-protected:
-  nsXPrintContext *mPrintContext; /* identical to |mRenderingSurface|
-                                   * (except the different type) 
-                                   */
-};
-#endif /* !nsRenderingContextXp_h___ */
deleted file mode 100644
--- a/gfx/src/xprint/nsXPrintContext.cpp
+++ /dev/null
@@ -1,1777 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@nrubsig.org>
- *   Leon Sha <leon.sha@sun.com>
- *   Julien Lafon <julien.lafon@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* Note: Sun Workshop 6 may have problems when mixing <string,h> 
- * and X includes. This was fixed by recent Xsun patches which 
- * are part of the "recommended patches" for Solaris. 
- * See bug 88703...
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h> /* for strerror & memset */
-
-#ifdef MOZ_LOGGING
-#define FORCE_PR_LOG 1 /* Allow logging in the release build */
-#endif /* MOZ_LOGGING */
-#include "prlog.h"
-
-#include "imgScaler.h"
-#include "nsXPrintContext.h"
-#include "nsDeviceContextXP.h"
-#include "xprintutil.h"
-#include "prenv.h" /* for PR_GetEnv */
-#include "prprf.h"
-#include "plstr.h"
-#include "nsPrintfCString.h"
-#include "nsIServiceManager.h" 
-#include "nsIEnvironment.h"
- 
-/* NS_XPRINT_RGB_DITHER: Macro to check whether we should dither or not.
- * In theory we only have to look at the visual and depth ("TrueColor" with 
- * enougth bits for the colors or GrayScale/StaticGray with enougth bits for
- * the grayscale shades).
- * In real life some Xprt DDX do not have the GrayScale/StaticGray visuals and
- * we emulate grayscale support with a PseudoColor visual+grayscale palette
- * (that's why we test for |mIsGrayscale| explicitly)...
- */
-#define NS_XPRINT_RGB_DITHER \
-    (((mDepth >  12 && mVisual->c_class==TrueColor)  || \
-      (mDepth >=  7 && mVisual->c_class==GrayScale)  || \
-      (mDepth >=  7 && mVisual->c_class==StaticGray) || \
-      (mIsGrayscale == PR_TRUE)) ?(XLIB_RGB_DITHER_NONE):(XLIB_RGB_DITHER_MAX))
-
-#ifdef PR_LOGGING 
-/* DEBUG: use 
- * % export NSPR_LOG_MODULES=nsXPrintContext:5 
- * to see these debug messages... 
- */
-static PRLogModuleInfo *nsXPrintContextLM = PR_NewLogModule("nsXPrintContext");
-#endif /* PR_LOGGING */
-
-PR_BEGIN_EXTERN_C
-static 
-int xerror_handler( Display *display, XErrorEvent *ev )
-{
-    /* this should _never_ be happen... but if this happens - debug mode or not - scream !!! */
-    char errmsg[80];
-    XGetErrorText(display, ev->error_code, errmsg, sizeof(errmsg));
-    fprintf(stderr, "nsGfxXprintModule: Warning (X Error) -  %s\n", errmsg);
-    return 0;
-}
-PR_END_EXTERN_C
-
-/** ---------------------------------------------------
- *  Default Constructor
- */
-nsXPrintContext::nsXPrintContext() :
-  mXlibRgbHandle(nsnull),
-  mPDisplay(nsnull),
-  mScreen(nsnull),
-  mVisual(nsnull),
-  mDrawable(None),
-  mGC(nsnull),
-  mDepth(0),
-  mPContext(None),
-  mJobStarted(PR_FALSE),
-  mIsGrayscale(PR_FALSE), /* default is color output */
-  mIsAPrinter(PR_TRUE),   /* default destination is printer */
-  mPrintFile(nsnull),
-  mXpuPrintToFileHandle(nsnull),
-  mPrintXResolution(0L),
-  mPrintYResolution(0L),
-  mContext(nsnull)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::nsXPrintContext()\n"));
-}
-
-/** ---------------------------------------------------
- *  Destructor
- */
-nsXPrintContext::~nsXPrintContext()
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::~nsXPrintContext()\n"));
- 
-  if (mPDisplay)
-  {
-    if (mJobStarted)
-    {
-      /* Clean-up if noone else did it yet... */
-      AbortDocument();
-    }
-
-    if (mGC)
-    {
-      mGC->Release();
-      mGC = nsnull;
-    }
-       
-    if (mXlibRgbHandle)
-    {
-      xxlib_rgb_destroy_handle(mXlibRgbHandle);
-      mXlibRgbHandle = nsnull;
-    }
-    
-    XPU_TRACE(XpuClosePrinterDisplay(mPDisplay, mPContext));           
-    mPDisplay = nsnull;
-    mPContext = None;
-  }
-  
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::~nsXPrintContext() done.\n"));
-}
-
-NS_IMPL_ISUPPORTS1(nsXPrintContext, nsIDrawingSurfaceXlib)
-
-
-static nsresult
-AlertBrokenXprt(Display *pdpy)
-{
-  /* Check for broken Xprt
-   * Xfree86 Xprt is the only known broken version of Xprt (see bug 120211
-   * for a list of tested&working Xprt servers) ...
-   * XXX: We should look at XVendorRelease(), too - but there is no feedback
-   * from XFree86.org when this issue will be fixed... ;-(
-   */
-  if (!(strstr(XServerVendor(pdpy), "XFree86") /*&& XVendorRelease(pdpy) < 45000000L*/))
-    return NS_OK;
-
-  /* Bad version found... log the issue and show the dialog and warn the user... */
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-         ("nsXPrintContext::AlertBrokenXprt: vendor: '%s', release=%ld\n",
-          XServerVendor(pdpy), (long)XVendorRelease(pdpy)));
-
-  /* Dialog disabled ? */
-  if (PR_GetEnv("MOZILLA_XPRINT_DISABLE_BROKEN_XFREE86_WARNING") != nsnull)
-    return NS_OK;
-   
-  return NS_ERROR_GFX_PRINTER_XPRINT_BROKEN_XPRT;
-}
-
-NS_IMETHODIMP 
-nsXPrintContext::Init(nsDeviceContextXp *dc, nsIDeviceContextSpecXp *aSpec)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::Init()\n"));
-  nsresult rv = NS_ERROR_FAILURE;
-
- 
-  unsigned short      width,
-                      height;
-  XRectangle          rect;
-  const char         *colorspace; 
-  XpuColorspaceList   cslist;
-  int                 cscount;
-  XpuColorspaceRec   *cs;
-  VisualID            csvid;
-  int                 cs_class;
-
-  if (NS_FAILED(XPU_TRACE(rv = SetupPrintContext(aSpec))))
-    return rv;
-
-  mScreen = XpGetScreenOfContext(mPDisplay, mPContext);
-  mScreenNumber = XScreenNumberOfScreen(mScreen);
-
-  /* Convert colorspace name into visualid */
-  aSpec->GetColorspace(&colorspace);
-  cslist = XpuGetColorspaceList(mPDisplay, mPContext, &cscount);
-  if (!cslist) {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuGetColorspaceList() failed.\n"));
-    return NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED;
-  }
-  cs = XpuFindColorspaceByName(cslist, cscount, colorspace);
-  if (!cs) {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuFindColorspaceByName() failed.\n"));
-    XpuFreeColorspaceList(cslist);
-    return NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED;
-  }
-  csvid    = cs->visualinfo.visualid;
-  cs_class = cs->visualinfo.c_class;
-  XpuFreeColorspaceList(cslist);
-
-  XlibRgbArgs xargs;
-  memset(&xargs, 0, sizeof(xargs));
-  xargs.handle_name           = nsnull;
-  xargs.disallow_image_tiling = True; /* XlibRGB's "Image tiling"-hack is 
-                                       * incompatible to Xprint API */
-  
-  if (mIsGrayscale)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("printing grayscale\n"));
-
-    /* This is compliciated: Older versions of Xprt do not always have 
-     * Grayscale/StaticGray visual for a chosen printer so we only use
-     * the selected visual when it really represents gray color values.
-     * If the selected visual does not match that requirement we jump
-     * into an "emulation" codepath which tries to find a visual which
-     * matches the requirement for grayscale or b/w output */
-    if ((cs_class | GrayScale) == GrayScale)
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using selected gray visual\n"));
-      xargs.xtemplate_mask     = VisualIDMask;
-      xargs.xtemplate.visualid = csvid;
-      mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);
-    }
-    else
-    { 
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using fallback codepath\n"));
-      /* 1st attempt using GrayScale */
-      xargs.xtemplate.c_class = StaticGray;
-      xargs.xtemplate.depth   = 8;
-      xargs.xtemplate_mask    = VisualClassMask|VisualDepthMask;
-      mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);             
-
-      if (!mXlibRgbHandle)
-      { 
-        /* 2nd attempt using GrayScale */
-        xargs.xtemplate.c_class = GrayScale;
-        xargs.xtemplate.depth   = 8;
-        xargs.xtemplate_mask    = VisualClassMask|VisualDepthMask;
-        mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);             
-        if (!mXlibRgbHandle)
-        {
-          /* Last attempt: Emulate StaticGray via Pseudocolor colormap */
-          xargs.xtemplate_mask  = 0L;
-          xargs.xtemplate.depth = 0;
-          xargs.pseudogray      = True;
-          mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);
-        }
-
-        if (!mXlibRgbHandle)
-        {
-          PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("trying black/white\n"));
-
-          /* Last attempt using StaticGray 1bit (b/w printer) */
-          xargs.xtemplate.c_class = StaticGray;
-          xargs.xtemplate.depth   = 1;
-          xargs.xtemplate_mask    = VisualClassMask|VisualDepthMask;
-          xargs.pseudogray        = False;
-          mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);
-        }
-      }
-    }  
-  }
-  else
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("printing color\n"));
-    xargs.xtemplate_mask     = VisualIDMask;
-    xargs.xtemplate.visualid = csvid;
-    mXlibRgbHandle = xxlib_rgb_create_handle(mPDisplay, mScreen, &xargs);
-  }
-  
-  /* No XlibRgb handle ? Either we do not have a matching visual or no memory... */
-  if (!mXlibRgbHandle)
-    return NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED;
-
-  XpGetPageDimensions(mPDisplay, mPContext, &width, &height, &rect);
-
-  rv = SetupWindow(rect.x, rect.y, rect.width, rect.height);
-  if (NS_FAILED(rv))
-    return rv;
-
-  XMapWindow(mPDisplay, mDrawable); 
-  
-  mContext = dc;
-    
-  /* Set error handler and sync
-   * ToDo: unset handler after all is done - what about handler "stacking" ?
-   */
-  (void)XSetErrorHandler(xerror_handler);
-
-  /* only run unbuffered X11 connection on demand (for debugging/testing) */
-  if( PR_GetEnv("MOZILLA_XPRINT_EXPERIMENTAL_SYNCHRONIZE") != nsnull )
-  {
-    XSynchronize(mPDisplay, True);
-  }  
-  
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPrintContext::GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
-{
-  *aWidth = mWidth;
-  *aHeight = mHeight;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPrintContext::IsOffscreen(PRBool *aOffScreen)
-{
-  *aOffScreen = PR_FALSE;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPrintContext::IsPixelAddressable(PRBool *aAddressable)
-{
-  *aAddressable = PR_FALSE;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPrintContext::GetPixelFormat(nsPixelFormat *aFormat)
-{
-  *aFormat = mPixFormat;
-  return NS_OK;
-}
-
-PRUint8 
-nsXPrintContext::GetShiftForMask(unsigned long val)
-{
-  PRUint8 cur_bit = 0;
-  // walk through the number, looking for the first 1
-  while (cur_bit < (sizeof(unsigned long) * 8)) {
-    if ((val >> cur_bit) & 0x1) {
-      return cur_bit;
-    }
-    cur_bit++;
-  }
-  return cur_bit;
-}
-
-PRUint8 
-nsXPrintContext::ConvertMaskToCount(unsigned long val)
-{
-  PRUint8 retval = 0;
-  PRUint8 cur_bit = 0;
-  // walk through the number, incrementing the value if
-  // the bit in question is set.
-  while (cur_bit < (sizeof(unsigned long) * 8)) {
-    if ((val >> cur_bit) & 0x1) {
-      retval++;
-    }
-    cur_bit++;
-  }
-  return retval;
-}
-
-
-nsresult
-nsXPrintContext::SetupWindow(int x, int y, int width, int height)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-         ("nsXPrintContext::SetupWindow: x=%d y=%d width=%d height=%d\n",
-         x, y, width, height));
-
-  Window                 parent_win;
-  XVisualInfo           *visual_info;
-  XSetWindowAttributes   xattributes;
-  long                   xattributes_mask;
-  unsigned long          background,
-                         foreground;
-  
-  mWidth  = width;
-  mHeight = height;
-
-  visual_info = xxlib_rgb_get_visual_info(mXlibRgbHandle);
-  mVisual     = xxlib_rgb_get_visual(mXlibRgbHandle);
-  mDepth      = xxlib_rgb_get_depth(mXlibRgbHandle);
-  
-  mPixFormat.mRedMask    = visual_info->red_mask;
-  mPixFormat.mGreenMask  = visual_info->green_mask;
-  mPixFormat.mBlueMask   = visual_info->blue_mask;
-  mPixFormat.mAlphaMask  = 0;
-  mPixFormat.mRedCount   = ConvertMaskToCount(visual_info->red_mask);
-  mPixFormat.mGreenCount = ConvertMaskToCount(visual_info->green_mask);
-  mPixFormat.mBlueCount  = ConvertMaskToCount(visual_info->blue_mask);
-  mPixFormat.mAlphaCount = 0;
-  mPixFormat.mRedShift   = GetShiftForMask(visual_info->red_mask);
-  mPixFormat.mGreenShift = GetShiftForMask(visual_info->green_mask);
-  mPixFormat.mBlueShift  = GetShiftForMask(visual_info->blue_mask);
-  mPixFormat.mAlphaShift = 0;
-
-  background = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, NS_TO_XXLIB_RGB(NS_RGB(0xFF, 0xFF, 0xFF))); /* white */
-  foreground = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, NS_TO_XXLIB_RGB(NS_RGB(0x00, 0x00, 0x00))); /* black */
-  parent_win = XRootWindow(mPDisplay, mScreenNumber);                                         
-                                             
-  xattributes.background_pixel = background;
-  xattributes.border_pixel     = foreground;
-  xattributes.colormap         = xxlib_rgb_get_cmap(mXlibRgbHandle);
-  xattributes_mask             = CWBorderPixel | CWBackPixel;
-  if( xattributes.colormap != None )
-  {
-    xattributes_mask |= CWColormap;
-
-    /* XXX: Why do we need this ? See bug 80562 ("Xprint does not support any
-     * other visuals than Xprt's default one..").*/
-    if (mDepth > 12)
-    {
-      XInstallColormap(mPDisplay, xattributes.colormap);
-    }  
-  }
-
-  mDrawable = (Drawable)XCreateWindow(mPDisplay, parent_win, x, y,
-                                      width, height, 0,
-                                      mDepth, InputOutput, mVisual, xattributes_mask,
-                                      &xattributes);
-
-  /* %p would be better instead of %lx for pointers - but does PR_LOG() support that ? */
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-         ("nsXPrintContext::SetupWindow: mVisual->visualid=%x, mVisual->c_class=%x, mDepth=%d, mScreenNumber=%d, colormap=%lx, mDrawable=%lx\n",
-         (int)mVisual->visualid, (int)mVisual->c_class, (int)mDepth, (int)mScreenNumber, (long)xattributes.colormap, (long)mDrawable));
-         
-  return NS_OK;
-}
-
-
-nsresult nsXPrintContext::SetMediumSize(const char *aPaperName)
-{
-  nsresult                rv = NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;
-  XpuMediumSourceSizeList mlist;
-  int                     mlist_count;
-  int                     i;
-  char                   *paper_name,
-                         *alloc_paper_name; /* for free() ... */
-  paper_name = alloc_paper_name = strdup(aPaperName);
-  if (!paper_name)
-    return NS_ERROR_OUT_OF_MEMORY;
-  
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: Requested page '%s'\n", paper_name));
-
-  mlist = XpuGetMediumSourceSizeList(mPDisplay, mPContext, &mlist_count);
-  if( !mlist )
-  {
-    return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;
-  }
-
-  XpuMediumSourceSizeRec *match = nsnull;
-
-#ifdef PR_LOGGING 
-  /* Print page sizes for the log... */
-  for( i = 0 ; i < mlist_count ; i++ )
-  {
-    XpuMediumSourceSizeRec *curr = &mlist[i];
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("got '%s'/'%s'\t%d %f %f %f %f\n", 
-           XPU_NULLXSTR(curr->tray_name), curr->medium_name, curr->mbool, 
-           curr->ma1, curr->ma2, curr->ma3, curr->ma4));
-  }
-#endif /* PR_LOGGING */
-
-  char *s;
-  
-  /* Did we get a tray name and paper name (e.g. "manual/din-a4") ? */
-  if ((s = strchr(paper_name, '/')) != nsnull)
-  {
-    const char *tray_name;
-    *s = '\0';
-    tray_name  = paper_name;
-    paper_name = s+1;
-    
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: searching for '%s'/'%s'\n", tray_name, paper_name));
-    match = XpuFindMediumSourceSizeByName(mlist, mlist_count, tray_name, paper_name);
-  }
-  else
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("SetMediumSize: searching for '%s'\n", paper_name));
-    match = XpuFindMediumSourceSizeByName(mlist, mlist_count, nsnull, paper_name);
-  }
-  
-  /* Found a match ? */
-  if (match)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-           ("match '%s'/'%s' !\n", XPU_NULLXSTR(match->tray_name), match->medium_name));
-           
-    /* Set document's paper size */
-    if( XpuSetDocMediumSourceSize(mPDisplay, mPContext, match) == 1 )
-      rv = NS_OK;  
-  }
-  
-  XpuFreeMediumSourceSizeList(mlist);
-  free(alloc_paper_name);
-  
-  return rv;
-}
-
-nsresult nsXPrintContext::SetOrientation(int landscape)
-{
-  const char         *orientation;
-  XpuOrientationList  list;
-  int                 list_count;
-  XpuOrientationRec  *match;
-
-  /* which orientation ? */
-  switch( landscape )
-  {
-    case 1 /* NS_LANDSCAPE */: orientation = "landscape"; break;
-    case 0 /* NS_PORTRAIT */:  orientation = "portrait";  break;
-    default:  
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-             ("Unsupported orientation %d.\n", landscape));  
-      return NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED;
-  }
-  
-  /* Print the used orientation to the log... */
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("orientation=%s\n", orientation));    
-
-  /* Get list of supported orientations */
-  list = XpuGetOrientationList(mPDisplay, mPContext, &list_count);
-  if( !list )
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuGetOrientationList() failure.\n"));  
-    return NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED;
-  }
-
-#ifdef PR_LOGGING 
-  int i;
-  /* Print orientations for the log... */
-  for( i = 0 ; i < list_count ; i++ )
-  {
-    XpuOrientationRec *curr = &list[i];
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("got orientation='%s'\n", curr->orientation));
-  }
-#endif /* PR_LOGGING */
-
-  /* Find requested orientation */
-  match = XpuFindOrientationByName(list, list_count, orientation);
-  if (!match)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuFindOrientationByName() failure.\n"));  
-    XpuFreeOrientationList(list);
-    return NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED;
-  }
-
-  /* Set orientation */
-  if (XpuSetDocOrientation(mPDisplay, mPContext, match) != 1)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuSetDocOrientation() failure.\n"));  
-    
-    /* We have a "match" in the list of supported orientations but we are not
-     * allowed to set it... Well - if this happens and we only have ONE entry
-     * in this list then we can safely assume that this is the only choice...
-     * (please correct me if I am wrong) 
-     */
-    if (list_count != 1)
-    {
-      /* ... otherwise we have a problem... */
-      XpuFreeOrientationList(list);
-      return NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED;
-    }
-  }
-  
-  XpuFreeOrientationList(list);
-
-  return NS_OK;
-}
-
-nsresult nsXPrintContext::SetPlexMode(const char *plexname)
-{
-  XpuPlexList  list;
-  int          list_count;
-  XpuPlexRec  *match;
-
-  /* Print the used plex name to the log... */
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("plexname=%s\n", plexname));    
-
-  /* Get list of supported plex modes */
-  list = XpuGetPlexList(mPDisplay, mPContext, &list_count);
-  if( !list )
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuGetPlexList() failure.\n"));  
-    return NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED;
-  }
-
-#ifdef PR_LOGGING 
-  int i;
-  /* Print plex modes for the log... */
-  for( i = 0 ; i < list_count ; i++ )
-  {
-    XpuPlexRec *curr = &list[i];
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("got plex='%s'\n", curr->plex));
-  }
-#endif /* PR_LOGGING */
-
-  /* Find requested plex mode */
-  match = XpuFindPlexByName(list, list_count, plexname);
-  if (!match)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuFindPlexByName() failure.\n"));  
-    XpuFreePlexList(list);
-    return NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED;
-  }
-
-  /* Set plex */
-  if (XpuSetDocPlex(mPDisplay, mPContext, match) != 1)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuSetDocPlex() failure.\n"));  
-    
-    /* We have a "match" in the list of supported plex modes but we are not
-     * allowed to set it... Well - if this happens and we only have ONE entry
-     * in this list then we can safely assume that this is the only choice...
-     * (please correct me if I am wrong) 
-     */
-    if (list_count != 1)
-    {
-      /* ... otherwise we have a problem... */
-      XpuFreePlexList(list);
-      return NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED;
-    }
-  }
-  
-  XpuFreePlexList(list);
-
-  return NS_OK;
-}
-
-
-nsresult
-nsXPrintContext::SetupPrintContext(nsIDeviceContextSpecXp *aSpec)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::SetupPrintContext()\n"));
-  
-  float        top, bottom, left, right;
-  int          landscape;
-  int          num_copies;
-  const char  *printername;
-  nsresult     rv;
-
-  nsCOMPtr<nsIEnvironment> uEnv = do_GetService("@mozilla.org/process/environment;1", &rv);
-  if (NS_FAILED(rv))
-    return rv;
-
-  // Get the Attributes
-  aSpec->GetToPrinter(mIsAPrinter);
-  aSpec->GetGrayscale(mIsGrayscale);
-  aSpec->GetTopMargin(top);
-  aSpec->GetBottomMargin(bottom);
-  aSpec->GetLeftMargin(left);
-  aSpec->GetRightMargin(right);
-  aSpec->GetLandscape(landscape);
-  aSpec->GetCopies(num_copies);
-  
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::SetupPrintContext: borders top=%f, bottom=%f, left=%f, right=%f\n", 
-         top, bottom, left, right));
-
-  /* get destination printer (we need this when printing to file as
-   * the printer DDX in Xprt generates the data...) 
-   */
-  aSpec->GetPrinterName(&printername);
-  
-  /* Are we "printing" to a file instead to the print queue ? */
-  if (!mIsAPrinter) 
-  {
-    /* ToDo: Guess a matching file extension of user did not set one - Xprint 
-     * currrently may use %s.ps, %s.pcl, %s.xwd, %s.pdf etc.
-     * Best idea would be to ask a "datatyping" service (like CDE's datatyping 
-     * functions) what to-do...
-     */
-    aSpec->GetPath(&mPrintFile);
-
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("print to file '%s'\n", XPU_NULLXSTR(mPrintFile)));
-    
-    if(!mPrintFile || !*mPrintFile)
-      return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
-  }
-
-  /* workaround for crash in XCloseDisplay() on Solaris 2.7 Xserver - when 
-   * shared memory transport is used XCloseDisplay() tries to free() the 
-   * shared memory segment - causing heap corruption and/or SEGV.
-   */
-  uEnv->Set(NS_LITERAL_STRING("XSUNTRANSPORT"), NS_LITERAL_STRING("xxx"));
-     
-  /* Get printer, either by "name" (foobar) or "name@display" (foobar@gaja:5) */
-  if( XpuGetPrinter(printername, &mPDisplay, &mPContext) != 1 )
-    return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
-
-  /* Remember the last used printer as new "default" printer as long this
-   * Mozilla instance is running */
-  uEnv->Set(NS_LITERAL_STRING("XPRINTER"), NS_ConvertUTF8toUTF16(printername));
-
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::SetupPrintContext: name='%s', display='%s', vendor='%s', release=%ld\n",
-          printername,
-          XDisplayString(mPDisplay), 
-          XServerVendor(mPDisplay),
-          (long)XVendorRelease(mPDisplay)));
-          
-  if (NS_FAILED(rv = AlertBrokenXprt(mPDisplay)))
-    return rv;
-    
-  if( XpQueryExtension(mPDisplay, &mXpEventBase, &mXpErrorBase) == False )
-    return NS_ERROR_UNEXPECTED;
-    
-#ifdef XPRINT_DEBUG_SOMETIMES_USEFULL
-  dumpXpAttributes(mPDisplay, mPContext);
-#endif /* XPRINT_DEBUG_SOMETIMES_USEFULL */
-  
-  const char *paper_name      = nsnull,
-             *plex_name       = nsnull,
-             *resolution_name = nsnull;
-  PRBool      downloadfonts   = PR_TRUE;
-  aSpec->GetPaperName(&paper_name);
-  aSpec->GetPlexName(&plex_name);
-  aSpec->GetResolutionName(&resolution_name);
-  aSpec->GetDownloadFonts(downloadfonts);
-  
-  if (NS_FAILED(XPU_TRACE(rv = SetMediumSize(paper_name))))
-    return rv;
-  
-  if (NS_FAILED(XPU_TRACE(rv = SetOrientation(landscape))))
-    return rv;
-
-  if (NS_FAILED(XPU_TRACE(rv = SetPlexMode(plex_name))))
-    return rv;
-    
-  if (NS_FAILED(XPU_TRACE(rv = SetResolution(resolution_name))))
-    return rv;
-   
-  if (XPU_TRACE(XpuSetDocumentCopies(mPDisplay, mPContext, num_copies)) != 1)
-    return NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES;
-
-  if (XPU_TRACE(XpuSetEnableFontDownload(mPDisplay, mPContext, downloadfonts)) != 1)
-    return NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR;
-        
-  /* set printer context
-   * WARNING: after this point it is no longer allows to change job attributes
-   * only after the XpSetContext() call the alllication is allowed to make 
-   * assumptions about available fonts - otherwise you may get the wrong 
-   * ones !!
-   */
-  XPU_TRACE(XpSetContext(mPDisplay, mPContext));
-
-#ifdef XPRINT_DEBUG_SOMETIMES_USEFULL
-  dumpXpAttributes(mPDisplay, mPContext);
-#endif /* XPRINT_DEBUG_SOMETIMES_USEFULL */
-
-  /* Get default printer resolution. May fail if Xprt is misconfigured.*/
-  if( XpuGetResolution(mPDisplay, mPContext, &mPrintXResolution, &mPrintYResolution) != 1 )
-    return NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR;
-
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-         ("print resolution %ld%x%ld\n", mPrintXResolution, mPrintYResolution));
-  
-  /* We want to get events when Xp(Start|End)(Job|Page) requests are processed... */  
-  XpSelectInput(mPDisplay, mPContext, XPPrintMask);  
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPrintContext::SetResolution(const char *resolution_name)
-{
-  XpuResolutionList list;
-  int               list_count;
-  XpuResolutionRec *match;
-  int               i;
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::SetResolution('resolution_name=%s').\n", resolution_name));  
-
-  list = XpuGetResolutionList(mPDisplay, mPContext, &list_count);
-  if( !list )
-    return NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR;
-
-#ifdef PR_LOGGING 
-  /* Print resolutions for the log... */
-  for( i = 0 ; i < list_count ; i++ )
-  {
-    XpuResolutionRec *curr = &list[i];
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-           ("got resolution='%s'/%ldx%ld\n", curr->name, curr->x_dpi, curr->y_dpi));
-  }
-#endif /* PR_LOGGING */
-
-  /* Find requested resolution mode */
-  match = XpuFindResolutionByName(list, list_count, resolution_name);
-  if (!match)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuFindResolutionByName() failure.\n"));  
-    XpuFreeResolutionList(list);
-    return NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED;
-  } 
-
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("setting resolution to '%s'/%ldx%ld DPI.\n", 
-         match->name, match->x_dpi, match->y_dpi));  
-    
-  if (XpuSetDocResolution(mPDisplay, mPContext, match) != 1)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuSetDocResolution() failure.\n"));
- 
-    /* We have a "match" in the list of supported resolutions but we are not
-     * allowed to set it... Well - if this happens and we only have ONE entry
-     * in this list then we can safely assume that this is the only choice...
-     * (please correct me if I am wrong) 
-     */
-    if (list_count != 1)
-    {
-      /* ... otherwise we have a problem... */
-      XpuFreeResolutionList(list);
-      return NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR;
-    }
-  }
-  
-  XpuFreeResolutionList(list);
-  
-  return NS_OK;
-}
-  
-NS_IMETHODIMP
-nsXPrintContext::BeginDocument( PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage )
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::BeginDocument(aTitle='%s')\n", ((aTitle)?(NS_ConvertUTF16toUTF8(aTitle).get()):("<NULL>"))));
-  
-  nsXPIDLCString job_title;
-       
-  if (aTitle)
-  {
-    /* Note that this is _only_ a _hack_ until bug 73446 
-     * ("RFE: Need NS_ConvertUCS2ToLocalEncoding() and 
-     * NS_ConvertLocalEncodingToUCS2()") is implemented...) */
-    job_title.Assign(NS_ConvertUTF16toUTF8(aTitle));
-  }
-  else
-  {
-    job_title.AssignLiteral("Document without title");
-  }
- 
-  /* Set the Job Attributes */
-  XpuSetJobTitle(mPDisplay, mPContext, job_title);
-  
-  // Check the output type
-  if(mIsAPrinter) 
-  {
-    XPU_TRACE(XpuStartJobToSpooler(mPDisplay));
-  } 
-  else 
-  {   
-    if( XPU_TRACE(mXpuPrintToFileHandle = XpuStartJobToFile(mPDisplay, mPContext, mPrintFile)) == nsnull )
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-             ("nsXPrintContext::BeginDocument(): XpuPrintToFile failure %s/(%d)\n", 
-             strerror(errno), errno));
-
-      return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;
-    }    
-  } 
-
-  XPU_TRACE(XpuWaitForPrintNotify(mPDisplay, mXpEventBase, XPStartJobNotify));
-
-  mJobStarted = PR_TRUE;
-  
-  return NS_OK;
-}  
-
-NS_IMETHODIMP
-nsXPrintContext::BeginPage()
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::BeginPage()\n"));
-   
-  XPU_TRACE(XpStartPage(mPDisplay, mDrawable));
-  XPU_TRACE(XpuWaitForPrintNotify(mPDisplay, mXpEventBase, XPStartPageNotify));
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP 
-nsXPrintContext::EndPage()
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::EndPage()\n"));
-
-  XPU_TRACE(XpEndPage(mPDisplay));
-  XPU_TRACE(XpuWaitForPrintNotify(mPDisplay, mXpEventBase, XPEndPageNotify));
-  
-  return NS_OK;
-}
-
-NS_IMETHODIMP 
-nsXPrintContext::EndDocument()
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::EndDocument()\n"));
-
-  XPU_TRACE(XpEndJob(mPDisplay));
-  XPU_TRACE(XpuWaitForPrintNotify(mPDisplay, mXpEventBase, XPEndJobNotify));
-
-  /* Are we printing to a file ? */
-  if( !mIsAPrinter )
-  {
-    NS_ASSERTION(nsnull != mXpuPrintToFileHandle, "mXpuPrintToFileHandle is null.");
-    
-    if( XPU_TRACE(XpuWaitForPrintFileChild(mXpuPrintToFileHandle)) == XPGetDocFinished )
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuWaitForPrintFileChild returned success.\n"));
-    }
-    else
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuWaitForPrintFileChild returned failure.\n"));
-    }
-    
-    mXpuPrintToFileHandle = nsnull;
-  }
-
-  /*
-   * end of spooled job - get spooler command results
-   */
-  const char *results,
-             *lresults;
-  results = XpGetOneAttribute(mPDisplay, mPContext, XPJobAttr,
-  			      "xp-spooler-command-results");
-
-  if( results &&
-      (strlen(results) != 0) )
-  {
-    lresults = XpuCompoundTextToXmb(mPDisplay, results);
-  }
-  else
-  {
-    lresults = NULL;
-  }
-  /* present spooler command results
-   * TODO: Open a dialog and present the message there.
-   */
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
-         ("Printing complete - spooler command result '%s'/'%s'\n",
-  	  results  ? results  : "<no message>",
-	  lresults ? lresults : ""));
-  if( lresults )
-    XpuFreeXmbString(lresults);
-
-  if( results )
-    XFree((void *)results);
-
-  mJobStarted = PR_FALSE;
-    
-  return NS_OK;
-}
-
-NS_IMETHODIMP 
-nsXPrintContext::AbortDocument()
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::AbortDocument()\n"));
-
-  if( mJobStarted )
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("canceling...\n"));
-    XPU_TRACE(XpCancelJob(mPDisplay, True));
-  }  
-
-  /* Are we printing to a file ? */
-  if( !mIsAPrinter && mXpuPrintToFileHandle )
-  {   
-    if( XPU_TRACE(XpuWaitForPrintFileChild(mXpuPrintToFileHandle)) == XPGetDocFinished )
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuWaitForPrintFileChild returned success.\n"));
-    }
-    else
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("XpuWaitForPrintFileChild returned failure.\n"));
-    }
-
-    mXpuPrintToFileHandle = nsnull;
-  }
-
-  mJobStarted = PR_FALSE;
-
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("print job aborted.\n"));
-
-  return NS_OK;
-}
-
-static
-PRUint8 *ComposeAlphaImage(
-               PRUint8 *alphaBits, PRInt32  alphaRowBytes, PRUint8 alphaDepth,
-               PRUint8 *image_bits, PRInt32  row_bytes,
-               PRInt32 aWidth, PRInt32 aHeight)
-{
-  PRUint8 *composed_bits; /* composed image */
-  if (!(composed_bits = (PRUint8 *)PR_Malloc(aHeight * row_bytes)))
-    return nsnull;
-
-/* unfortunately this code does not work for some strange reason ... */
-#ifdef XPRINT_NOT_NOW
-  XGCValues gcv;
-  memset(&gcv, 0, sizeof(XGCValues)); /* this may be unnecessary */
-  XGetGCValues(mPDisplay, *xgc, GCForeground, &gcv);
-  
-  /* should be replaced by xxlibrgb_query_color() */
-  XColor color;
-  color.pixel = gcv.foreground;
-  XQueryColor(mPDisplay, xxlib_rgb_get_cmap(mXlibRgbHandle), &color);
-  
-  unsigned long background = NS_RGB(color.red>>8, color.green>>8, color.blue>>8);
-#else
-  unsigned long background = NS_RGB(0xFF,0xFF,0xFF); /* white! */
-#endif /* XPRINT_NOT_NOW */
-  long x, y;
-    
-  switch(alphaDepth)
-  {
-    case 1:
-    {
-#define NS_GET_BIT(rowptr, x) (rowptr[(x)>>3] &  (1<<(7-(x)&0x7)))
-        unsigned short r = NS_GET_R(background),
-                       g = NS_GET_R(background),
-                       b = NS_GET_R(background);
-                     
-        for(y = 0 ; y < aHeight ; y++)
-        {
-          unsigned char *imageRow  = image_bits    + y * row_bytes;
-          unsigned char *destRow   = composed_bits + y * row_bytes;
-          unsigned char *alphaRow  = alphaBits     + y * alphaRowBytes;
-          for(x = 0 ; x < aWidth ; x++)
-          {
-            if(NS_GET_BIT(alphaRow, x))
-            {
-              /* copy src color */
-              destRow[3*x  ] = imageRow[3*x  ];
-              destRow[3*x+1] = imageRow[3*x+1];
-              destRow[3*x+2] = imageRow[3*x+2];
-            }
-            else
-            {
-              /* copy background color (e.g. pixel is "transparent") */
-              destRow[3*x  ] = r;
-              destRow[3*x+1] = g;
-              destRow[3*x+2] = b;
-            }
-          }
-        }        
-    }  
-        break;
-    case 8:
-    {
-        unsigned short r = NS_GET_R(background),
-                       g = NS_GET_R(background),
-                       b = NS_GET_R(background);
-        
-        for(y = 0 ; y < aHeight ; y++)
-        {
-          unsigned char *imageRow  = image_bits    + y * row_bytes;
-          unsigned char *destRow   = composed_bits + y * row_bytes;
-          unsigned char *alphaRow  = alphaBits     + y * alphaRowBytes;
-          for(x = 0 ; x < aWidth ; x++)
-          {
-            unsigned short alpha = alphaRow[x];
-            MOZ_BLEND(destRow[3*x  ], r, imageRow[3*x  ], alpha);
-            MOZ_BLEND(destRow[3*x+1], g, imageRow[3*x+1], alpha);
-            MOZ_BLEND(destRow[3*x+2], b, imageRow[3*x+2], alpha);
-          }
-        }
-    }  
-        break;
-    default:
-    {
-        NS_WARNING("alpha depth x not supported");
-        PR_Free(composed_bits);
-        return nsnull;
-    }  
-        break;
-  }
-  
-  return composed_bits;      
-}
-
-
-NS_IMETHODIMP
-nsXPrintContext::DrawImage(Drawable aDrawable, xGC *xgc, nsIImage *aImage,
-                 PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
-                 PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::DrawImage(%lx, %d/%d/%d/%d - %d/%d/%d/%d)\n",
-          (long)aDrawable,
-          (int)aSX, (int)aSY, (int)aSWidth, (int)aSHeight,
-          (int)aDX, (int)aDY, (int)aDWidth, (int)aDHeight));
-  
-  double   scalingFactor;
-  int      prev_res = 0,
-           dummy;
-  long     imageResolution;
-  PRInt32  aDWidth_scaled,
-           aDHeight_scaled;
-  nsresult rv = NS_OK;
-  
-  PRInt32 aSrcWidth  = aImage->GetWidth();
-  PRInt32 aSrcHeight = aImage->GetHeight();
-  
-  if( (aSrcWidth == 0) || (aSrcHeight == 0) ||
-      (aSWidth == 0)   || (aSHeight == 0) ||
-      (aDWidth == 0)   || (aDHeight == 0) )
-  {
-    NS_ASSERTION((aSrcWidth != 0) && (aSrcHeight != 0) &&
-      (aSWidth != 0)   && (aSHeight != 0) ||
-      (aDWidth != 0)   && (aDHeight != 0), 
-      "nsXPrintContext::DrawImage(): Image with zero source||dest width||height suppressed\n");
-    return NS_OK;
-  }
-
-  /* Get the general scaling factor for this device */
-  float pixelscale = 1.0;
-  mContext->GetCanonicalPixelScale(pixelscale);
-  scalingFactor = 1.0 / pixelscale;
-
-  /* Calculate image scaling factors */
-  double scale_x = double(aSWidth)  / (double(aDWidth)  * scalingFactor);
-  double scale_y = double(aSHeight) / (double(aDHeight) * scalingFactor);
-  
-  /* Which scaling factor is the "bigger" one ? 
-   * (XpSetImageResolution() sets one image resolution for both X- and
-   * Y-axis - therefore we want to get the "best"(=smallest job size) out
-   * of the scaling factor...).
-   */
-  scalingFactor *= PR_MIN(scale_x, scale_y);
-  
-  /* Adjust destination size to the match the scaling factor */
-  imageResolution = long(   double(mPrintXResolution) * scalingFactor);
-  aDWidth_scaled  = PRInt32(double(aDWidth)           * scalingFactor);
-  aDHeight_scaled = PRInt32(double(aDHeight)          * scalingFactor);
-
-  /* Check if we scaled the image to zero width/height - if "yes" then use the
-   * smaller scaling factor and try again ... */
-  if( (aDWidth_scaled <= 0) || (aDHeight_scaled <= 0) )
-  {
-    /* Chose smaller scaling factor (e.g. the reverse of what we're doing above...) */
-    scalingFactor = 1.0 / pixelscale; /* Revert to original value */
-    scalingFactor *= PR_MAX(scale_x, scale_y);
-
-    /* Adjust destination size to the match the (new) scaling factor */
-    imageResolution = long(   double(mPrintXResolution) * scalingFactor);
-    aDWidth_scaled  = PRInt32(double(aDWidth)           * scalingFactor);
-    aDHeight_scaled = PRInt32(double(aDHeight)          * scalingFactor);
-  }
-
-  /* Image scaled to 0 width/height ? */
-  NS_ASSERTION(!((aDWidth_scaled <= 0) || (aDHeight_scaled <= 0)),
-               "Image scaled to zero width/height");
-  if( (aDWidth_scaled <= 0) || (aDHeight_scaled <= 0) )
-    return NS_OK;
-
-  /* Image scaled to zero-width/height ? */
-  NS_ASSERTION(imageResolution != 0, "Image resolution must not be 0");
-  NS_ASSERTION(imageResolution >= 0, "Image resolution must not be negative");
-  if( imageResolution <= 0 )
-    return NS_OK;
-
-  /* Set image resolution */
-  if( XpSetImageResolution(mPDisplay, mPContext, imageResolution, &prev_res) )
-  {
-    /* draw image, Xprt will do the main scaling part... */
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-           ("Xp scaling res=%d, aSWidth=%d, aSHeight=%d, aDWidth_scaled=%d, aDHeight_scaled=%d\n", 
-            (int)imageResolution, (int)aSWidth, (int)aSHeight, (int)aDWidth_scaled, (int)aDHeight_scaled));
-    
-    if( (aSX != 0) || (aSY != 0) || (aSWidth != aDWidth_scaled) || (aSHeight != aDHeight_scaled) )
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using DrawImageBitsScaled()\n"));
-      rv = DrawImageBitsScaled(aDrawable, xgc, aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
-    }
-    else
-    {
-      PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using DrawImage() [shortcut]\n"));
-      rv = DrawImage(aDrawable, xgc, aImage, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
-    }
-    
-    /* reset image resolution to previous resolution */
-    (void)XpSetImageResolution(mPDisplay, mPContext, prev_res, &dummy);
-  }
-  else /* fallback */
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("BAD BAD local scaling... ;-((\n"));
-    /* reset image resolution to previous value to be sure... */
-    (void)XpSetImageResolution(mPDisplay, mPContext, prev_res, &dummy);
-    
-    /* scale image on our side (bad) */
-    rv = DrawImageBitsScaled(aDrawable, xgc, aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight);
-  }
-  
-  return rv;
-}  
-
-// use DeviceContextImpl :: GetCanonicalPixelScale(float &aScale) 
-// to get the pixel scale of the device context
-nsresult
-nsXPrintContext::DrawImageBitsScaled(Drawable aDrawable, xGC *xgc, nsIImage *aImage,
-                 PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
-                 PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::DrawImageBitsScaled(%lx, %d/%d/%d/%d - %d/%d/%d/%d)\n",
-          (long)aDrawable,
-          (int)aSX, (int)aSY, (int)aSWidth, (int)aSHeight,
-          (int)aDX, (int)aDY, (int)aDWidth, (int)aDHeight));
-
-  nsresult rv = NS_OK;
-  
-  if (aDWidth==0 || aDHeight==0)
-  {
-    NS_ASSERTION((aDWidth==0 || aDHeight==0), 
-                 "nsXPrintContext::DrawImageBitsScaled(): Image with zero dest width||height suppressed\n");
-    return NS_OK;
-  }
-  
-  aImage->LockImagePixels(PR_FALSE);
-  
-  PRUint8 *image_bits    = aImage->GetBits();
-  PRInt32  row_bytes     = aImage->GetLineStride();
-  PRUint8  imageDepth    = 24; /* R8G8B8 packed. Thanks to "tor" for that hint... */
-  PRUint8 *alphaBits     = aImage->GetAlphaBits();
-  PRInt32  alphaRowBytes = aImage->GetAlphaLineStride();
-  int      alphaDepth    = aImage->GetAlphaDepth();
-  PRInt32  aSrcWidth     = aImage->GetWidth();
-  PRInt32  aSrcHeight    = aImage->GetHeight();
-  PRUint8 *composed_bits = nsnull;
-
- /* image data might not be available (ex: spacer image) */
-  if (!image_bits)
-  {
-    aImage->UnlockImagePixels(PR_FALSE);
-    return NS_OK;
-  }
- 
-  // Use client-side alpha image composing - plain X11 can only do 1bit alpha 
-  // stuff - this method adds 8bit alpha support, too...
-  if( alphaBits != nsnull )
-  {
-    composed_bits = ComposeAlphaImage(alphaBits, alphaRowBytes, alphaDepth,
-                                      image_bits, row_bytes,
-                                      aSrcWidth, aSrcHeight);
-    if (!composed_bits)
-    {
-      aImage->UnlockImagePixels(PR_FALSE);
-      return NS_ERROR_FAILURE;
-    }
-
-    image_bits = composed_bits;
-    alphaBits = nsnull; /* ComposeAlphaImage() handled the alpha channel. 
-                         * Once we enable XPRINT_SERVER_SIDE_ALPHA_COMPOSING 
-                         * we have to send the alpha data to the server
-                         * instead of processing them locally (e.g. on 
-                         * the client-side).
-                         */
-  }
-
-#define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
-
-  PRInt32  srcimg_bytes_per_line = row_bytes;
-  PRInt32  dstimg_bytes_per_line = ROUNDUP((imageDepth * aDWidth), 32);
-  PRUint8 *srcimg_data           = image_bits;
-  PRUint8 *dstimg_data           = (PRUint8 *)PR_Malloc((aDHeight+1) * dstimg_bytes_per_line); 
-  if (!dstimg_data)
-  {
-    aImage->UnlockImagePixels(PR_FALSE);
-    return NS_ERROR_FAILURE;
-  }
-
-  RectStretch(aSWidth, aSHeight,
-              aDWidth, aDHeight,
-              0, 0, aDWidth-1, aDHeight-1,
-              srcimg_data, srcimg_bytes_per_line,
-              dstimg_data, dstimg_bytes_per_line,
-              imageDepth);
-
-#ifdef XPRINT_SERVER_SIDE_ALPHA_COMPOSING
-/* ToDo: scale alpha image */
-#endif /* XPRINT_SERVER_SIDE_ALPHA_COMPOSING */
-    
-  rv = DrawImageBits(aDrawable, xgc, alphaBits, alphaRowBytes, alphaDepth,
-                     dstimg_data, dstimg_bytes_per_line, 
-                     aDX, aDY, aDWidth, aDHeight);
-
-  if (dstimg_data)   
-    PR_Free(dstimg_data);
-  if (composed_bits) 
-    PR_Free(composed_bits);
-  
-  aImage->UnlockImagePixels(PR_FALSE);
-
-  return rv;
-}
-
-
-NS_IMETHODIMP
-nsXPrintContext::DrawImage(Drawable aDrawable, xGC *xgc, nsIImage *aImage,
-                           PRInt32 aX, PRInt32 aY,
-                           PRInt32 dummy1, PRInt32 dummy2)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::DrawImage(%lx, %d/%d/%d(=dummy)/%d(=dummy))\n",
-         (long)aDrawable,
-         (int)aX, (int)aY, (int)dummy1, (int)dummy2));
-
-  aImage->LockImagePixels(PR_FALSE);
-
-  nsresult rv;
-  PRInt32  width         = aImage->GetWidth();
-  PRInt32  height        = aImage->GetHeight();
-  PRUint8 *alphaBits     = aImage->GetAlphaBits();
-  PRInt32  alphaRowBytes = aImage->GetAlphaLineStride();
-  PRInt32  alphaDepth    = aImage->GetAlphaDepth();
-  PRUint8 *image_bits    = aImage->GetBits();
-  PRUint8 *composed_bits = nsnull;
-  PRInt32  row_bytes     = aImage->GetLineStride();
-
-  /* image data might not be available (ex: spacer image) */
-  if (!image_bits)
-  {
-    aImage->UnlockImagePixels(PR_FALSE);
-    return NS_OK;
-  }
-  
-  // Use client-side alpha image composing - plain X11 can only do 1bit alpha
-  // stuff - this method adds 8bit alpha support, too...
-  if( alphaBits != nsnull )
-  {
-    composed_bits = ComposeAlphaImage(alphaBits, alphaRowBytes, alphaDepth,
-                                      image_bits, row_bytes,
-                                      width, height);
-    if (!composed_bits)
-    {
-      aImage->UnlockImagePixels(PR_FALSE);
-      return NS_ERROR_FAILURE;
-    }
-
-    image_bits = composed_bits;
-    alphaBits = nsnull;
-  }
-               
-  rv = DrawImageBits(aDrawable, xgc, alphaBits, alphaRowBytes, alphaDepth,
-                     image_bits, row_bytes,
-                     aX, aY, width, height);
-
-  if (composed_bits)
-    PR_Free(composed_bits);
-
-  aImage->UnlockImagePixels(PR_FALSE);
-
-  return rv;                     
-}
-
-                         
-// Draw the bitmap, this draw just has destination coordinates
-nsresult
-nsXPrintContext::DrawImageBits(Drawable aDrawable, xGC *xgc,
-                               PRUint8 *alphaBits, PRInt32  alphaRowBytes, PRUint8 alphaDepth,
-                               PRUint8 *image_bits, PRInt32  row_bytes,
-                               PRInt32 aX, PRInt32 aY,
-                               PRInt32 aWidth, PRInt32 aHeight)
-{ 
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::DrawImageBits(%lx, %d/%d/%d/%d)\n",
-         (long)aDrawable, (int)aX, (int)aY, (int)aWidth, (int)aHeight));
-
-  Pixmap alpha_pixmap  = None;
-  GC     image_gc;
-
-  if( (aWidth == 0) || (aHeight == 0) )
-  {
-    NS_ASSERTION((aWidth != 0) && (aHeight != 0), "Image with zero width||height suppressed.");
-    return NS_OK;
-  }
-  
-/* server-side alpha image support (1bit) - this does not work yet... */
-#ifdef XPRINT_SERVER_SIDE_ALPHA_COMPOSING
-  // Create gc clip-mask on demand
-  if( alphaBits != nsnull )
-  {
-    XImage    *x_image = nsnull;
-    GC         gc;
-    XGCValues  gcv;
-    
-    alpha_pixmap = XCreatePixmap(mPDisplay, 
-                                 aDrawable,
-                                 aWidth, aHeight, 1); /* ToDo: Check for error */
-  
-    /* Make an image out of the alpha-bits created by the image library (ToDo: check for error) */
-    x_image = XCreateImage(mPDisplay, mVisual,
-                           1,                 /* visual depth...1 for bitmaps */
-                           XYPixmap,
-                           0,                 /* x offset, XXX fix this */
-                           (char *)alphaBits, /* cast away our sign. */
-                           aWidth,
-                           aHeight,
-                           32,                /* bitmap pad */
-                           alphaRowBytes);    /* bytes per line */
-
-    x_image->bits_per_pixel = 1;
-
-    /* Image library always places pixels left-to-right MSB to LSB */
-    x_image->bitmap_bit_order = MSBFirst;
-
-    /* This definition doesn't depend on client byte ordering
-     * because the image library ensures that the bytes in
-     * bitmask data are arranged left to right on the screen,
-     * low to high address in memory. */
-    x_image->byte_order = MSBFirst;
-
-    // Write into the pixmap that is underneath gdk's alpha_pixmap
-    // the image we just created.
-    memset(&gcv, 0, sizeof(XGCValues)); /* this may be unnecessary */
-    XGetGCValues(mPDisplay, *xgc, GCForeground|GCBackground, &gcv);
-    gcv.function = GXcopy;
-    gc = XCreateGC(mPDisplay, alpha_pixmap, GCForeground|GCBackground|GCFunction, &gcv);
-
-    XPutImage(mPDisplay, alpha_pixmap, gc, x_image, 0, 0, 0, 0,
-              aWidth, aHeight);
-    XFreeGC(mPDisplay, gc);
-
-    // Now we are done with the temporary image
-    x_image->data = nsnull; /* Don't free the IL_Pixmap's bits. */
-    XDestroyImage(x_image);
-  }
-#endif /* XPRINT_SERVER_SIDE_ALPHA_COMPOSING */  
-  
-  if( alpha_pixmap != None )
-  {
-    /* create copy of GC before start to playing with it... */
-    XGCValues gcv;  
-    memset(&gcv, 0, sizeof(XGCValues)); /* this may be unnecessary */
-    XGetGCValues(mPDisplay, *xgc, GCForeground|GCBackground, &gcv);
-    gcv.function      = GXcopy;
-    gcv.clip_mask     = alpha_pixmap;
-    gcv.clip_x_origin = aX;
-    gcv.clip_y_origin = aY;
-
-    image_gc = XCreateGC(mPDisplay, aDrawable, 
-                         (GCForeground|GCBackground|GCFunction|
-                          GCClipXOrigin|GCClipYOrigin|GCClipMask),
-                         &gcv);
-  }
-  else
-  {
-    /* this assumes that xlib_draw_rgb_image()/xlib_draw_gray_image()
-     * does not change the GC... */
-    image_gc = *xgc;
-  }
-
-
-  xxlib_draw_xprint_scaled_rgb_image(mXlibRgbHandle,
-                                     aDrawable,
-                                     mPrintXResolution, XpGetImageResolution(mPDisplay, mPContext),
-                                     image_gc,
-                                     aX, aY, aWidth, aHeight,
-                                     NS_XPRINT_RGB_DITHER,
-                                     image_bits, row_bytes);
-  
-  if( alpha_pixmap != None ) 
-  {   
-    XFreeGC(mPDisplay, image_gc);
-    XFreePixmap(mPDisplay, alpha_pixmap);
-  }
-    
-  return NS_OK;
-}
-
-NS_IMETHODIMP nsXPrintContext::GetPrintResolution(int &aXres, int &aYres)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::GetPrintResolution() res=%ldx%ld, mPContext=%lx\n",
-          mPrintXResolution, mPrintYResolution,(long)mPContext));
-  
-  if(mPContext!=None)
-  {
-    aXres = mPrintXResolution;
-    aYres = mPrintYResolution;
-    return NS_OK;
-  }
-  
-  aXres = aYres = 0;
-  return NS_ERROR_FAILURE;    
-}
-
-/* nsEPSObjectXp - a EPSF helper class
- * For details on the EPSF spec, see Adobe specification #5002,
- * "Encapsulated PostScript File Format Specification". The document
- * structuring conventions are described in Specificion #5001, 
- * "PostScript Language Document Structuring Conventions Specification".
- */
-class nsEPSObjectXp {
-  public:
-      /** ---------------------------------------------------
-       * Constructor
-       */
-      nsEPSObjectXp(const unsigned char *aData, unsigned long aDataLength) :
-        mStatus(NS_ERROR_INVALID_ARG),
-        mData(nsnull),
-        mDataLength(0UL),
-        mCurrPos(nsnull),
-        mBBllx(0.0),
-        mBBlly(0.0),
-        mBBurx(0.0),
-        mBBury(0.0)
-      {
-        mData       = NS_REINTERPRET_CAST(const char*, aData);
-        mDataLength = aDataLength;
-
-        NS_PRECONDITION(aData != nsnull,   "aData == nsnull");
-        NS_PRECONDITION(aDataLength > 0UL, "No data");    
-
-        Reset();
-        Parse();
-      }
-      
-      static inline
-      PRBool IsEPSF(const unsigned char *aData, unsigned long aDataLength)
-      {
-        /* First line (assuming a single line of PostScript line is not longer
-         * than 256 chars) should usually look like "%!PS-Adobe-3.0 EPSF-3.0"
-         * (version numbers may be different) */
-        return (PL_strnstr(NS_REINTERPRET_CAST(const char*, aData), " EPSF-", PR_MIN(aDataLength, 256)) != nsnull);
-      }
-      
-
-      /** ---------------------------------------------------
-       * @return the result code from parsing the EPS data.
-       * If the return value is not NS_OK, the EPS object is
-       * invalid and should not be used further.
-       */
-      nsresult GetStatus() { return mStatus; };
-
-      /** ---------------------------------------------------
-       * Return Bounding box coordinates: lower left x,
-       * lower left y, upper right x, upper right y.
-       */
-      inline void GetBoundingBox(PRFloat64 &aBBllx,
-                          PRFloat64 &aBBlly,
-                          PRFloat64 &aBBurx,
-                          PRFloat64 &aBBury)
-      {
-        aBBllx = mBBllx;
-        aBBlly = mBBlly;
-        aBBurx = mBBurx;
-        aBBury = mBBury;
-      };
-
-      /** ---------------------------------------------------
-       * Append the EPS object to the provided string object.
-       */
-      void AppendTo(nsACString& aDestBuffer)
-      {
-        nsCAutoString line;
-        PRBool        inPreview = PR_FALSE;
-
-        Reset();
-        while (EPSFFgets(line)) {
-          if (inPreview) {
-            /* filter out the print-preview section */
-            if (StringBeginsWith(line, NS_LITERAL_CSTRING("%%EndPreview")))
-                inPreview = PR_FALSE;
-            continue;
-          }
-          else if (StringBeginsWith(line, NS_LITERAL_CSTRING("%%BeginPreview:"))){
-            inPreview = PR_TRUE;
-            continue;
-          }
-
-          /* Output the EPSF with this platform's line terminator */
-          aDestBuffer.Append(line.get(), line.Length());
-          aDestBuffer.Append(NS_LITERAL_CSTRING("\n"));
-        }
-      }
-  private:
-      nsresult             mStatus;
-      const char          *mData;
-      unsigned long        mDataLength;
-      const char          *mCurrPos;
-      PRFloat64            mBBllx,
-                           mBBlly,
-                           mBBurx,
-                           mBBury;
-
-      void Parse()
-      {
-        nsCAutoString line;
-
-        Reset();   
-        while (EPSFFgets(line)) {
-          if (PR_sscanf(line.get(), "%%%%BoundingBox: %lf %lf %lf %lf",
-                        &mBBllx, &mBBlly, &mBBurx, &mBBury) == 4) {
-            mStatus = NS_OK;
-            return;
-          }
-        }
-        mStatus = NS_ERROR_INVALID_ARG;
-      }
-      
-      inline void Reset()
-      {
-        mCurrPos = mData;
-      }
-
-      PRBool EPSFFgets(nsACString& aBuffer)
-      {
-        aBuffer.Truncate();
-        
-        if (!mCurrPos)
-          return PR_FALSE;
-        
-        while (1) {
-          int ch = *mCurrPos++;
-          if ('\n' == ch) {
-            /* Eat any following carriage return */
-            ch = *mCurrPos++;
-            if ((mCurrPos < (mData + mDataLength)) && ('\r' != ch))
-              mCurrPos--;
-            return PR_TRUE;
-          }
-          else if ('\r' == ch) {
-            /* Eat any following line feed */
-            ch = *mCurrPos++;
-            if ((mCurrPos < (mData + mDataLength)) && ('\n' != ch))
-              mCurrPos--;
-            return PR_TRUE;
-          }
-          else if (mCurrPos >= (mData + mDataLength)) {
-            /* If we read any text before the EOF, return true. */
-            return !aBuffer.IsEmpty();
-          }
-
-          /* Normal case */
-          aBuffer.Append((char)ch);
-        }
-      }
-};
-
-NS_IMETHODIMP nsXPrintContext::RenderEPS(Drawable aDrawable,
-                                         const nsRect& aRect,
-                                         const unsigned char *aData, unsigned long aDatalen)
-{
-  PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-         ("nsXPrintContext::EPS(aData, aDatalen=%d)\n", aDatalen));
-  
-  char xp_formats_supported[] = "xp-embedded-formats-supported";
-  const char *embedded_formats_supported = XpGetOneAttribute(mPDisplay, mPContext, XPPrinterAttr, xp_formats_supported);
-
-  /* Check whether "PostScript Level 2" is supported as embedding format
-   * (The content of the "xp-embedded-formats-supported" attribute needs
-   * to be searched in a case-insensitive way since the model-configs
-   * may use the same word with multiple variants of case
-   * (e.g. "PostScript" vs. "Postscript" or "PCL" vs. "Pcl" etc.")
-   * To avoid problems we simply use |PL_strcasestr()| (case-insensitive
-   * strstr()) instead of |strstr()| here...)
-   */
-  if (embedded_formats_supported == NULL)
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("nsXPrintContext::RenderPostScriptDataFragment(): Embedding data not supported for this DDX/Printer\n"));
-    return NS_ERROR_FAILURE;    
-  }
-
-  if( PL_strcasestr(embedded_formats_supported, "PostScript 2") == NULL )
-  {
-    PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, 
-           ("nsXPrintContext::RenderPostScriptDataFragment(): Embedding data not supported for this DDX/Printer "
-            "(supported embedding formats are '%s')\n", embedded_formats_supported));
-    XFree((void *)embedded_formats_supported);
-    return NS_ERROR_FAILURE;    
-  }
-
-  /* Temp buffer for EPSF data - this has to live outside the if()/else()
-   * block below to gurantee that the pointers we get from it are still
-   * valid when we feed the data to |XpPutDocumentData| */
-  nsXPIDLCString  aBuffer;
-  const unsigned char *embedData;
-  unsigned long        embedDataLength;
-    
-  /* If the input is EPSF then we need to do some EPSF-specific handling */
-  if (nsEPSObjectXp::IsEPSF(aData, aDatalen))
-  {
-    PRFloat64 boxLLX, 
-              boxLLY,
-              boxURX,
-              boxURY;
-
-    nsEPSObjectXp epsfData(aData, aDatalen);
-    /* Non-EPSF data are not supported yet */
-    if (NS_FAILED(epsfData.GetStatus()))
-      return NS_ERROR_INVALID_ARG;  
-
-    epsfData.GetBoundingBox(boxLLX, boxLLY, boxURX, boxURY);
-
-    /* Size buffer that all the data in |aData| and context fits into the string */
-    aBuffer.SetCapacity(aDatalen + 1024); 
-    aBuffer.Assign("%%BeginDocument: Mozilla EPSF plugin data\n"
-                   "/b4_Inc_state save def\n"
-                   "/dict_count countdictstack def\n"
-                   "/op_count count 1 sub def\n"
-                   "userdict begin\n"
-                   "/showpage { } def\n"
-                   "0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin\n"
-                   "10 setmiterlimit [ ] 0 setdash newpath\n"
-                   "/languagelevel where\n"
-                   "{pop languagelevel\n"
-                   "  1 ne\n"
-                   "  {false setstrokeadjust false setoverprint\n"
-                   "  } if\n"
-                   "} if\n");
-
-    /* translate to the lower left corner of the rectangle */
-    aBuffer.Append(nsPrintfCString(64, "%f %f translate\n", 
-                   double(aRect.x),
-                   double(aRect.y + aRect.height)));
-
-    /* Rescale */
-    aBuffer.Append(nsPrintfCString(64, "%f %f scale\n", 
-                   double(aRect.width / (boxURX - boxLLX)),
-                   double(-(aRect.height / (boxURY - boxLLY)))));
-
-    /* Translate to the EPSF origin. Can't use translate() here because
-     * it takes integers.
-     */
-    aBuffer.Append(nsPrintfCString(64, "%f %f translate\n", double(-boxLLX), double(-boxLLY)));
-
-    epsfData.AppendTo(aBuffer);
-    aBuffer.Append("count op_count sub { pop } repeat\n"
-                   "countdictstack dict_count sub { end } repeat\n"
-                   "b4_Inc_state restore\n"
-                   "%%EndDocument\n");
-    embedData       = NS_REINTERPRET_CAST(const unsigned char*, aBuffer.get());
-    embedDataLength = aBuffer.Length();
-  }
-  else
-  {
-    /* Non-EPSF codepath - pass the data as-is... */
-    embedData       = aData;
-    embedDataLength = aDatalen;
-  }
-  
-  /* Note that the embedded PostScript code uses the same resolution and
-   * coordinate space as currently be used by the DDX (if you do not
-   * want that simply reset it yourself :) */
-  const char *type     = "PostScript 2"; /* Format of embedded data 
-                                          * (older PS DDX may be picky, fixed via
-                                          * http://xprint.mozdev.org/bugs/show_bug.cgi?id=4023)
-                                          */
-  const char *option   = "";             /* PostScript DDX does not support any options yet
-                                          * (in general |BadValue| will be returned for not
-                                          * supported options/option values) */
-
-  /* XpPutDocumentData() takes |const| input for all string arguments, only the X11 prototypes do not allow |const| yet */
-  XpPutDocumentData(mPDisplay, aDrawable, (unsigned char *)embedData, embedDataLength, (char *)type, (char *)option);
-
-  XFree((void *)embedded_formats_supported);
-  
-  return NS_OK;
-}
-
-
deleted file mode 100644
--- a/gfx/src/xprint/nsXPrintContext.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *   Leon Sha <leon.sha@sun.com>
- *   Julien Lafon <julien.lafon@gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- 
-#ifndef _XPCONTEXT_H_
-#define _XPCONTEXT_H_
-
-#include <X11/Xlib.h>
-#include <X11/extensions/Print.h>
-#include "nsColor.h"
-#include "nsCoord.h"
-#include "nsIImage.h"
-#include "nsGCCache.h"
-#include "nsIDeviceContextSpecXPrint.h"
-#include "nsDrawingSurfaceXlib.h"
-#include "xlibrgb.h"
-
-class nsDeviceContextXp;
-
-class nsXPrintContext : public nsIDrawingSurfaceXlib
-{
-public:
-  nsXPrintContext();
-  virtual ~nsXPrintContext();
-
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
-                  void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
-                  PRUint32 aFlags)  { return NS_OK; };
-  NS_IMETHOD Unlock(void)  { return NS_OK; };
-  
-  NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
-  NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
-  NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
-  NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
-
-  NS_IMETHOD Init(nsDeviceContextXp *dc, nsIDeviceContextSpecXp *aSpec);
-  NS_IMETHOD BeginPage();
-  NS_IMETHOD EndPage();
-  NS_IMETHOD RenderEPS(Drawable aDrawable, const nsRect& aRect, const unsigned char *aData, unsigned long aDatalen);
-  NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
-  NS_IMETHOD EndDocument();
-  NS_IMETHOD AbortDocument();
-
-  int                     GetHeight() { return mHeight; }
-  int                     GetWidth() { return mWidth; }
-  NS_IMETHOD GetDrawable(Drawable &aDrawable) { aDrawable = mDrawable; return NS_OK; }
-  NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) { aHandle = mXlibRgbHandle; return NS_OK; }
-  NS_IMETHOD GetGC(xGC *&aXGC) { mGC->AddRef(); aXGC = mGC; return NS_OK; }
-
-  virtual Drawable GetDrawable() { return mDrawable; }
-  
-  void                    SetGC(xGC *aGC) { mGC = aGC; mGC->AddRef(); }
-
-  NS_IMETHOD GetPrintResolution(int &aXres, int &aYres);
-
-  NS_IMETHOD DrawImage(Drawable aDrawable, xGC *gc, nsIImage *aImage,
-                PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
-                PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
-
-  NS_IMETHOD DrawImage(Drawable aDrawable, xGC *gc, nsIImage *aImage,
-                 PRInt32 aX, PRInt32 aY,
-                 PRInt32 aWidth, PRInt32 aHeight);
-
-private:
-  nsresult DrawImageBitsScaled(Drawable aDrawable,
-                xGC *gc, nsIImage *aImage,
-                PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
-                PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
-                
-  nsresult DrawImageBits(Drawable aDrawable, xGC *gc, 
-                         PRUint8 *alphaBits, PRInt32  alphaRowBytes, PRUint8 alphaDepth,
-                         PRUint8 *image_bits, PRInt32  row_bytes,
-                         PRInt32 aX, PRInt32 aY,
-                         PRInt32 aWidth, PRInt32 aHeight); 
-
-  XlibRgbHandle *mXlibRgbHandle;
-  Display      *mPDisplay;
-  Screen       *mScreen;
-  Visual       *mVisual;
-  Drawable      mDrawable; /* window/paper surface */
-  nsPixelFormat mPixFormat;
-  xGC          *mGC;
-  int           mXpEventBase, /* XpExtension X event base */
-                mXpErrorBase; /* XpExtension X error base */
-  int           mDepth;
-  int           mScreenNumber;
-  int           mWidth;
-  int           mHeight;
-  XPContext     mPContext;
-  PRBool        mJobStarted;  /* |PR_TRUE| when being between XpStartJob() and XpEndJob() */
-  PRBool        mIsGrayscale; /* color or grayscale ? */
-  PRBool        mIsAPrinter;  /* destination: printer or file ? */
-  const char   *mPrintFile;   /* file to "print" to */
-  void         *mXpuPrintToFileHandle; /* handle for XpuPrintToFile/XpuWaitForPrintFileChild when printing to file */
-  long          mPrintXResolution,
-                mPrintYResolution;
-  nsDeviceContextXp *mContext; /* DeviceContext which created this object */
-
-  static PRUint8 ConvertMaskToCount(unsigned long val);
-  static PRUint8 GetShiftForMask(unsigned long val);
-
-  nsresult SetupWindow(int x, int y, int width, int height);
-  nsresult SetupPrintContext(nsIDeviceContextSpecXp *aSpec);
-  nsresult SetMediumSize(const char *paper_name);
-  nsresult SetOrientation(int landscape);
-  nsresult SetPlexMode(const char *plexname);
-  nsresult SetResolution(const char *resolution_name);
-};
-
-
-#endif /* !_XPCONTEXT_H_ */
-
deleted file mode 100644
--- a/gfx/src/xprint/xprint.pkg
+++ /dev/null
@@ -1,6 +0,0 @@
-[gecko]
-#if SHARED_LIBRARY
-dist/bin/components/@SHARED_LIBRARY@
-#else
-!staticcomp @LIBRARY@ @MODULE_NAME@
-#endif
deleted file mode 100644
--- a/gfx/src/xprintutil/Makefile.in
+++ /dev/null
@@ -1,63 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE		= xprintutil
-LIBRARY_NAME	= xprintutil
-FORCE_STATIC_LIB= 1
-EXPORT_LIBRARY=1
-LIBXUL_LIBRARY  = 1
-
-CSRCS		= \
-		xprintutil.c \
-		xprintutil_printtofile.c
-
-EXPORTS		= xprintutil.h
-
-CFLAGS		+= $(MOZ_XPRINT_CFLAGS)
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES		+= -DUSE_MOZILLA_TYPES -DUSE_XPRINT
-
deleted file mode 100644
--- a/gfx/src/xprintutil/xprintutil.c
+++ /dev/null
@@ -1,2109 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the X11 print system utilities library.
- *
- * The Initial Developer of the Original Code is
- * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>.
- * Portions created by the Initial Developer are Copyright (C) 2001
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "xprintutil.h"
- 
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <limits.h>
-#include <errno.h>
-#include <locale.h>
-
-#ifdef XPU_USE_NSPR
-#include "plstr.h"
-#undef strtok_r
-#define strtok_r(s1, s2, x) PL_strtok_r((s1), (s2), (x))
-#endif /* XPU_USE_NSPR */
-
-/* List of tokens which can be used to separate entries in the 
- * $XPSERVERLIST env var */
-static const char XPServerListSeparators[] = " \t\v\n\r\f";
-
-/* conformace only; X11 API does (currrently) not make use of |const|. 
- * If Xlib API gets fixed these macros can be turned into empty 
- * placeholders... (|#define MAKE_STRING_WRITABLE(x)|) :-)
- */
-#define MAKE_STRING_WRITABLE(str) (((str)?((str) = strdup(str)):0))
-#define FREE_WRITABLE_STRING(str) free((void *)(str))
-#define STRING_AS_WRITABLE(str) ((char *)(str))
-
-/* Local prototypes */
-static const char *XpuGetDefaultXpPrintername(void);
-static const char *XpuGetXpServerList( void );
-static const char *XpuEnumerateXpAttributeValue( const char *value, void **vcptr );
-static const char *XpuGetCurrentAttributeGroup( void **vcptr );
-static void XpuDisposeEnumerateXpAttributeValue( void **vc );
-static Bool XpuEnumerateMediumSourceSizes( Display *pdpy, XPContext pcontext,
-                                           const char **tray_name,
-                                           const char **medium_name, int *mbool, 
-                                           float *ma1, float *ma2, float *ma3, float *ma4,
-                                           void **vcptr );
-static void XpuDisposeEnumerateMediumSourceSizes( void **vc );
-
-/*
-** XprintUtil functions start with Xpu
-**
-*/
-
-int XpuCheckExtension( Display *pdpy )
-{
-  char *display = XDisplayString(pdpy);
-  short major = 0,
-        minor = 0;
-
-  if( XpQueryVersion(pdpy, &major, &minor) != 0 )
-  {
-    XPU_DEBUG_ONLY(printf("XpuCheckExtension: XpQueryVersion '%s' %d %d\n", XPU_NULLXSTR(display), (int)major, (int)minor));
-    return(1);
-  }
-  else
-  {
-    XPU_DEBUG_ONLY(printf("XpuCheckExtension: XpQueryVersion '%s' returned 0(=Xprint not supported)\n", XPU_NULLXSTR(display)));
-  }
-  
-  return(0);
-}
-
-/* Get the default printer name from the XPRINTER env var.
- * If XPRINTER env var is not present looks for PDPRINTER, LPDEST, and
- * PRINTER (in that order)
- * See CDE's DtPrintSetupBox(3) manual page, too...
- */
-static
-const char *XpuGetDefaultXpPrintername(void)
-{
-  const char *s;
-  /* BUG/TODO: XpPrinter resource needs to be sourced, too... */
-  s = getenv("XPRINTER");
-  if( !s )
-  {
-    s = getenv("PDPRINTER");
-    if( !s )
-    {
-      s = getenv("LPDEST");
-      if( !s )
-      {
-        s = getenv("PRINTER");
-      }
-    }
-  }  
-  return s;
-}
-
-static
-const char *XpuGetXpServerList( void )
-{
-  const char *s;
-  /* BUG/TODO: XpServerList resource needs to be sourced first, then append 
-   * contents of XPSERVERLIST, then remove duplicates...
-   */
-  s = getenv("XPSERVERLIST"); 
-  if( s == NULL )
-    s = "";
-    
-  return(s);
-}
-
-
-Bool XpuXprintServersAvailable( void )
-{
-  const char *s;
-  int         c = 0;
-  /* BUGs/ToDo:
-   * - XpServerList resource needs to be sourced, too...
-   *   (see comment for |XpuGetXpServerList|, too)
-   * - There should be some validation whether the server entries
-   *   are
-   *     a) valid (easy :)
-   *   and
-   *     b) available (hard to implement when XOpenDisplay() should be avoided)
-   */
-  s = getenv("XPSERVERLIST");
-  /* Check if serverlist is non-empty */
-  if (s)
-  {
-    while( *s++ )
-    {
-      if( !isspace(*s) )
-        c++;
-    }
-  }
-  /* a valid server name must at least contain the ':'-separator
-   * and a number (e.g. ":1") */
-  return( c >= 2 );
-}
-
-
-static 
-int XpuGetPrinter2( char *printer, char *display, Display **pdpyptr, XPContext *pcontextptr )
-{
-  Display   *pdpy;
-  XPContext  pcontext;
-  
-  XPU_DEBUG_ONLY(printf("XpuGetPrinter2: probing display '%s' for '%s'\n", XPU_NULLXSTR(display), XPU_NULLXSTR(printer)));
-  
-  if( (pdpy = XOpenDisplay(display)) != NULL )
-  {
-    if( XpuCheckExtension(pdpy) )
-    {
-      XPPrinterList list;
-      int           list_count;
-      
-      /* get list of available printers... */
-      list = XpGetPrinterList(pdpy, printer, &list_count);        
-      if( list != NULL ) XpFreePrinterList(list);
-      
-      /* ...and check if printer exists... */
-      if( (list != NULL) && (list_count > 0) )
-      {
-        if( (pcontext = XpCreateContext(pdpy, printer)) != None )
-        {
-          *pdpyptr     = pdpy;
-          *pcontextptr = pcontext;
-          return(1);
-        }
-        
-        XPU_DEBUG_ONLY(printf("XpuGetPrinter2: could not create print context for '%s'\n", XPU_NULLXSTR(printer)));
-      }
-    }
-    else
-    {
-      XPU_DEBUG_ONLY(printf("display '%s' does not support the Xprint extension\n", XPU_NULLXSTR(display)));
-    }  
-
-    XCloseDisplay(pdpy);
-    return(0);
-  }
-  else
-  {
-    XPU_DEBUG_ONLY(printf("could not open display '%s'\n", XPU_NULLXSTR(display)));
-    return(0);
-  }
-}
-
-
-/* acceps "printer" or "printer@display" */
-int XpuGetPrinter( const char *arg_printername, Display **pdpyptr, XPContext *pcontextptr )
-{
-  Display       *pdpy;
-  XPContext      pcontext;
-  char          *printername;
-  char          *s;
-  char          *tok_lasts;
-  
-  *pdpyptr     = NULL;
-  *pcontextptr = None;
-  
-  XPU_DEBUG_ONLY(printf("XpuGetPrinter: looking for '%s'\n", XPU_NULLXSTR(arg_printername)));
-  
-  /* strtok_r will modify string - duplicate it first... */
-  printername = strdup(arg_printername);
-  if( printername == NULL )
-    return(0);
-  
-  if( (s = strtok_r(printername, "@", &tok_lasts)) != NULL )
-  {
-    char *name = s;
-    char *display = strtok_r(NULL, "@", &tok_lasts);
-    
-    /* if we have a display - open it and grab printer */
-    if( display != NULL )
-    {
-      if( XpuGetPrinter2(name, display, pdpyptr, pcontextptr) )
-      {
-        free(printername);
-        return(1);
-      }
-    }
-    /* if we did not get a display, travel througth all displays */
-    else
-    {
-      char *sl = strdup(XpuGetXpServerList());
-      
-      if( sl != NULL )
-      {
-        for( display = strtok_r(sl, XPServerListSeparators, &tok_lasts) ; 
-             display != NULL ; 
-             display = strtok_r(NULL, XPServerListSeparators, &tok_lasts) )
-        {       
-          if( XpuGetPrinter2(name, display, pdpyptr, pcontextptr) )
-          {
-            free(sl);
-            free(printername);
-            return(1);
-          } 
-        }
-        
-        free(sl);
-      }
-    }
-  }
-  
-  free(printername);
-  XPU_DEBUG_ONLY(printf("XpuGetPrinter: failure\n"));
-  
-  return(0);
-}
-
-
-void XpuClosePrinterDisplay(Display *pdpy, XPContext pcontext)
-{
-  if( pdpy )
-  {
-    if( pcontext != None )
-      XpDestroyContext(pdpy, pcontext);
-      
-    XCloseDisplay(pdpy);
-  }
-}
-
-void XpuSetOneAttribute( Display *pdpy, XPContext pcontext, 
-                         XPAttributes type, const char *attribute_name, const char *value, XPAttrReplacement replacement_rule )
-{
-  /* Alloc buffer for sprintf() stuff below */
-  char *buffer = (char *)malloc(strlen(attribute_name)+strlen(value)+4);
-  
-  if( buffer != NULL )
-  {
-    sprintf(buffer, "%s: %s", attribute_name, value);      
-    XpSetAttributes(pdpy, pcontext, type, buffer, replacement_rule);
-    free(buffer);
-  }  
-}
-
-void XpuSetOneLongAttribute( Display *pdpy, XPContext pcontext, 
-                             XPAttributes type, const char *attribute_name, long value, XPAttrReplacement replacement_rule )
-{
-  /* Alloc buffer for sprintf() stuff below */
-  char *buffer = (char *)malloc(strlen(attribute_name)+32+4);
-  
-  if( buffer != NULL )
-  {
-    sprintf(buffer, "%s: %ld", attribute_name, value);      
-    XpSetAttributes(pdpy, pcontext, type, buffer, replacement_rule);
-    free(buffer);
-  }  
-}
-
-/* Check if attribute value is supported or not
- * Use this function _only_ if XpuGetSupported{Job,Doc,Page}Attributes()
- * does not help you...
- */
-int XpuCheckSupported( Display *pdpy, XPContext pcontext, XPAttributes type, const char *attribute_name, const char *query )
-{
-  char *value;
-  void *tok_lasts;
-  
-  MAKE_STRING_WRITABLE(attribute_name);
-  if( attribute_name == NULL )
-    return(0);
-    
-  value = XpGetOneAttribute(pdpy, pcontext, type, STRING_AS_WRITABLE(attribute_name));   
-  
-  XPU_DEBUG_ONLY(printf("XpuCheckSupported: XpGetOneAttribute(%s) returned '%s'\n", XPU_NULLXSTR(attribute_name), XPU_NULLXSTR(value)));
-
-  FREE_WRITABLE_STRING(attribute_name);
-  
-  if( value != NULL )
-  {
-    const char *s;
-    
-    for( s = XpuEnumerateXpAttributeValue(value, &tok_lasts) ; s != NULL ; s = XpuEnumerateXpAttributeValue(NULL, &tok_lasts) )
-    {
-      XPU_DEBUG_ONLY(printf("XpuCheckSupported: probing '%s'=='%s'\n", XPU_NULLXSTR(s), XPU_NULLXSTR(query)));
-      if( !strcmp(s, query) )
-      {
-        XFree(value);
-        XpuDisposeEnumerateXpAttributeValue(&tok_lasts);
-        return(1);
-      }  
-    }
-    
-    XpuDisposeEnumerateXpAttributeValue(&tok_lasts);
-    XFree(value);
-  }  
-  
-  return(0);
-}
-
-
-int XpuSetJobTitle( Display *pdpy, XPContext pcontext, const char *title )
-{
-  if( XpuGetSupportedJobAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_JOB_NAME )
-  {
-    char *encoded_title;
-    
-    encoded_title = XpuResourceEncode(title);
-    if (!encoded_title)
-      return(0);
-    XpuSetOneAttribute(pdpy, pcontext, XPJobAttr, "*job-name", encoded_title, XPAttrMerge);
-    XpuResourceFreeString(encoded_title);
-    return(1);
-  }
-  else
-  {
-    XPU_DEBUG_ONLY(printf("XpuSetJobTitle: XPUATTRIBUTESUPPORTED_JOB_NAME not supported ('%s')\n", XPU_NULLXSTR(title)));
-    return(0); 
-  }  
-}
-    
-int XpuGetOneLongAttribute( Display *pdpy, XPContext pcontext, XPAttributes type, const char *attribute_name, long *result )
-{
-  char *s;
-  
-  MAKE_STRING_WRITABLE(attribute_name);
-  if( attribute_name == NULL )
-    return(0);
-  s = XpGetOneAttribute(pdpy, pcontext, type, STRING_AS_WRITABLE(attribute_name));
-  
-  if(s && *s) 
-  {
-    long tmp;
-    
-    XPU_DEBUG_ONLY(printf("XpuGetOneLongAttribute: '%s' got '%s'\n", XPU_NULLXSTR(attribute_name), XPU_NULLXSTR(s)));
-    
-    tmp = strtol(s, (char **)NULL, 10);
-    
-    if( !(((tmp == 0L) || (tmp == LONG_MIN) || (tmp == LONG_MAX)) && 
-          ((errno == ERANGE) || (errno == EINVAL))) )
-    {
-      *result = tmp;
-      XFree(s);
-      XPU_DEBUG_ONLY(printf("XpuGetOneLongAttribute: result %ld\n", *result));
-      FREE_WRITABLE_STRING(attribute_name);
-      return(1);
-    }            
-  }
-  
-  if( s != NULL ) 
-    XFree(s);
-  
-  FREE_WRITABLE_STRING(attribute_name);
-  
-  return(0);
-}
-
-
-#ifdef DEBUG
-/* debug only */
-void dumpXpAttributes( Display *pdpy, XPContext pcontext )
-{
-  char *s;
-  printf("------------------------------------------------\n");
-  printf("--> Job\n%s\n",         s=XpuGetJobAttributes(pdpy, pcontext));     XFree(s);
-  printf("--> Doc\n%s\n",         s=XpuGetDocAttributes(pdpy, pcontext));     XFree(s);
-  printf("--> Page\n%s\n",        s=XpuGetPageAttributes(pdpy, pcontext));    XFree(s);
-  printf("--> Printer\n%s\n",     s=XpuGetPrinterAttributes(pdpy, pcontext)); XFree(s);
-  printf("--> Server\n%s\n",      s=XpuGetServerAttributes(pdpy, pcontext));  XFree(s);
-  printf("image resolution %d\n", (int)XpGetImageResolution(pdpy, pcontext));
-  printf("------------------------------------------------\n");
-}
-#endif /* DEBUG */    
-
-
-typedef struct XpuIsNotifyEventContext_
-{
-  int event_base;
-  int detail;
-} XpuIsNotifyEventContext;
-
-static
-Bool IsXpNotifyEvent( Display *pdpy, XEvent *ev, XPointer arg )
-{
-  Bool match;
-  XpuIsNotifyEventContext *context = (XpuIsNotifyEventContext *)arg;
-  XPPrintEvent *pev = (XPPrintEvent *)ev;
-  
-  match = pev->type == (context->event_base+XPPrintNotify) && 
-          pev->detail == context->detail;
-
-  XPU_DEBUG_ONLY(printf("XpuWaitForPrintNotify: %d=IsXpNotifyEvent(%d,%d)\n",
-                 (int)match,
-                 (int)pev->type,
-                 (int)pev->detail));
-  return match;
-}
-
-void XpuWaitForPrintNotify( Display *pdpy, int xp_event_base, int detail )
-{
-  XEvent                  dummy;
-  XpuIsNotifyEventContext matchcontext;
-
-  matchcontext.event_base = xp_event_base;
-  matchcontext.detail     = detail;
-  XIfEvent(pdpy, &dummy, IsXpNotifyEvent, (XPointer)&matchcontext);
-}      
-
-static
-const char *skip_matching_brackets(const char *start)
-{
-  const char *s     = start;
-  int         level = 0;
-  
-  if( !start )
-      return(NULL);
-  
-  do
-  {
-    switch(*s++)
-    {
-      case '\0': return(NULL);
-      case '{': level++; break;
-      case '}': level--; break;
-    }
-  } while(level > 0);
-
-  return(s);
-}
-
-
-static
-const char *search_next_space(const char *start)
-{
-  const char *s     = start;
-  int         level = 0;
-  
-  if( !start )
-    return(NULL);
-  
-  for(;;)
-  {   
-    if( isspace(*s) )
-      return(s);
-
-    if( *s=='\0' )
-      return(NULL);      
-
-    s++;
-  }
-}
-
-/* PRIVATE context data for XpuEnumerateXpAttributeValue() */
-typedef struct _XpuAttributeValueEnumeration
-{
-  char   *value;
-  size_t  original_value_len; /* original length of value */
-  char   *group;
-  char   *start;
-  char   *s;
-} XpuAttributeValueEnumeration;
-
-
-/* Hacked parser for Xp values and enumerations */
-static