]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/x11/x11_display.cpp
Skins2: Move getShifts from const to static.
[vlc] / modules / gui / skins2 / x11 / x11_display.cpp
index 05887de28f0fa7cdfbb364f1d9ae24f2953e1f2f..9a6f43265b2b142320c562cac0114c6337159a70 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * x11_display.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,9 +17,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef X11_SKINS
 #include "x11_display.hpp"
 #include "../src/logger.hpp"
 
+template<class type> type X11Display::putPixel(type r, type g, type b) const
+{
+    return ( (r >> m_redRightShift)   << m_redLeftShift   ) |
+           ( (g >> m_greenRightShift) << m_greenLeftShift ) |
+           ( (b >> m_blueRightShift)  << m_blueLeftShift  );
+}
+
+template<class type>
+type X11Display::blendPixel(type v,type r, type g, type b, type a) const
+{
+    uint16_t temp;
+
+    temp = ((uint8_t)((v >> m_redLeftShift) << m_redRightShift));
+    uint8_t red = r + ( temp * (255 - a) ) / 255;
+    temp = ((uint8_t)((v >> m_greenLeftShift) << m_greenRightShift));
+    uint8_t green = g + ( temp * (255 - a) ) / 255;
+    temp = ((uint8_t)((v >> m_blueLeftShift) << m_blueRightShift));
+    uint8_t blue = b + ( temp * (255 - a) ) / 255;
+
+    return putPixel<type>(red,green,blue);
+}
 
 X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
     m_mainWindow( 0 ), m_gc( NULL ), m_colormap( 0 )
 {
+    char *psz_display = var_CreateGetNonEmptyString( pIntf, "x11-display" );
     // Open a connection to the X Server
-    m_pDisplay = XOpenDisplay( NULL );
+    m_pDisplay = XOpenDisplay( psz_display );
+    free( psz_display );
 
     if( m_pDisplay == NULL )
     {
@@ -52,6 +75,7 @@ X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
     int screen = DefaultScreen( m_pDisplay );
     int depth = DefaultDepth( m_pDisplay, screen );
     int order = ImageByteOrder( m_pDisplay );
+    Window root = DefaultRootWindow( m_pDisplay );
 
     // Template for looking up the XVisualInfo
     XVisualInfo xVInfoTemplate;
@@ -63,108 +87,108 @@ X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
 
     switch( depth )
     {
-        case 8:
-            xVInfoTemplate.c_class = DirectColor;
-            // Get the DirectColor visual
-            pVInfo = XGetVisualInfo( m_pDisplay, VisualScreenMask |
-                                     VisualClassMask, &xVInfoTemplate,
-                                     &vCount );
-            if( pVInfo == NULL )
-            {
-                msg_Err( getIntf(), "no DirectColor visual available" );
-                m_pDisplay = NULL;
-                break;
-            }
-            m_pVisual = pVInfo->visual;
-
-            // Compute the color shifts
-            getShifts( pVInfo->red_mask, m_redLeftShift, m_redRightShift );
-            getShifts( pVInfo->green_mask, m_greenLeftShift,
-                       m_greenRightShift );
-            getShifts( pVInfo->blue_mask, m_blueLeftShift, m_blueRightShift );
-
-            // Create a color map
-            m_colormap = XCreateColormap( m_pDisplay,
-                    DefaultRootWindow( m_pDisplay ),
-                    DefaultVisual( m_pDisplay, screen ), AllocAll );
-
-            // Create the palette
-            XColor pColors[255];
-            for( uint16_t i = 0; i < 255; i++ )
-            {
-                // kludge: colors are indexed reversely because color 255 seems
-                // to bereserved for black even if we try to set it to white
-                pColors[i].pixel = 254-i;
-                pColors[i].pad   = 0;
-                pColors[i].flags = DoRed | DoGreen | DoBlue;
-                pColors[i].red   = (i >> m_redLeftShift) << (m_redRightShift + 8);
-                pColors[i].green = (i >> m_greenLeftShift) << (m_greenRightShift + 8);
-                pColors[i].blue  = (i >> m_blueLeftShift) << (m_blueRightShift + 8);
-            }
-            XStoreColors( m_pDisplay, m_colormap, pColors, 255 );
-            makePixelImpl = &X11Display::makePixel8;
-            m_pixelSize = 1;
+    case 8:
+        xVInfoTemplate.c_class = DirectColor;
+        // Get the DirectColor visual
+        pVInfo = XGetVisualInfo( m_pDisplay, VisualScreenMask |
+                                 VisualClassMask, &xVInfoTemplate,
+                                 &vCount );
+        if( pVInfo == NULL )
+        {
+            msg_Err( getIntf(), "no DirectColor visual available" );
+            m_pDisplay = NULL;
+            break;
+        }
+        m_pVisual = pVInfo->visual;
+
+        // Compute the color shifts
+        getShifts( pVInfo->red_mask, m_redLeftShift, m_redRightShift );
+        getShifts( pVInfo->green_mask, m_greenLeftShift,
+                   m_greenRightShift );
+        getShifts( pVInfo->blue_mask, m_blueLeftShift, m_blueRightShift );
+
+        // Create a color map
+        m_colormap = XCreateColormap( m_pDisplay, root,
+                DefaultVisual( m_pDisplay, screen ), AllocAll );
+
+        // Create the palette
+        XColor pColors[255];
+        for( uint16_t i = 0; i < 255; i++ )
+        {
+            // kludge: colors are indexed reversely because color 255 seems
+            // to bereserved for black even if we try to set it to white
+            pColors[i].pixel = 254-i;
+            pColors[i].pad   = 0;
+            pColors[i].flags = DoRed | DoGreen | DoBlue;
+            pColors[i].red   =
+                (i >> m_redLeftShift) << (m_redRightShift + 8);
+            pColors[i].green =
+                (i >> m_greenLeftShift) << (m_greenRightShift + 8);
+            pColors[i].blue  =
+                (i >> m_blueLeftShift) << (m_blueRightShift + 8);
+        }
+        XStoreColors( m_pDisplay, m_colormap, pColors, 255 );
+        blendPixelImpl = &X11Display::blendPixel8;
+        putPixelImpl = &X11Display::putPixel8;
+        m_pixelSize = 1;
+        break;
+
+    case 15:
+    case 16:
+    case 24:
+    case 32:
+        // Get the TrueColor visual
+        xVInfoTemplate.c_class = TrueColor;
+        pVInfo = XGetVisualInfo( m_pDisplay, VisualScreenMask |
+                                 VisualDepthMask | VisualClassMask,
+                                 &xVInfoTemplate, &vCount );
+        if( pVInfo == NULL )
+        {
+            msg_Err( getIntf(), "No TrueColor visual for depth %d", depth );
+            m_pDisplay = NULL;
             break;
+        }
+        m_pVisual = pVInfo->visual;
 
-        case 16:
-        case 24:
-        case 32:
-            // Get the TrueColor visual
-            xVInfoTemplate.c_class = TrueColor;
-            pVInfo = XGetVisualInfo( m_pDisplay, VisualScreenMask |
-                                     VisualDepthMask | VisualClassMask,
-                                     &xVInfoTemplate, &vCount );
-            if( pVInfo == NULL )
+        // Compute the color shifts
+        getShifts( pVInfo->red_mask,   m_redLeftShift,   m_redRightShift   );
+        getShifts( pVInfo->green_mask, m_greenLeftShift, m_greenRightShift );
+        getShifts( pVInfo->blue_mask,  m_blueLeftShift,  m_blueRightShift  );
+
+        if( depth == 15 || depth == 16 )
+        {
+            if( order == MSBFirst )
             {
-                msg_Err( getIntf(), "No TrueColor visual for depth %d",
-                         depth );
-                m_pDisplay = NULL;
-                break;
+                blendPixelImpl = &X11Display::blendPixel16MSB;
+                putPixelImpl = &X11Display::putPixel16MSB;
             }
-            m_pVisual = pVInfo->visual;
-
-            // Compute the color shifts
-            getShifts( pVInfo->red_mask, m_redLeftShift, m_redRightShift );
-            getShifts( pVInfo->green_mask, m_greenLeftShift,
-                       m_greenRightShift );
-            getShifts( pVInfo->blue_mask, m_blueLeftShift, m_blueRightShift );
-
-            if( depth == 8 )
+            else
             {
-                makePixelImpl = &X11Display::makePixel8;
-                m_pixelSize = 1;
+                blendPixelImpl = &X11Display::blendPixel16LSB;
+                putPixelImpl = &X11Display::putPixel16LSB;
             }
-
-            if( depth == 16 )
+            m_pixelSize = 2;
+        }
+        else
+        {
+            if( order == MSBFirst )
             {
-                if( order == MSBFirst )
-                {
-                    makePixelImpl = &X11Display::makePixel16MSB;
-                }
-                else
-                {
-                    makePixelImpl = &X11Display::makePixel16LSB;
-                }
-                m_pixelSize = 2;
+                blendPixelImpl = &X11Display::blendPixel32MSB;
+                putPixelImpl = &X11Display::putPixel32MSB;
             }
             else
             {
-                if( order == MSBFirst )
-                {
-                    makePixelImpl = &X11Display::makePixel32MSB;
-                }
-                else
-                {
-                    makePixelImpl = &X11Display::makePixel32LSB;
-                }
-                m_pixelSize = 4;
+                blendPixelImpl = &X11Display::blendPixel32LSB;
+                putPixelImpl = &X11Display::putPixel32LSB;
             }
-            break;
-
-        default:
-            msg_Err( getIntf(), "Unsupported depth: %d bpp\n", depth );
-            m_pDisplay = NULL;
-            break;
+            m_pixelSize = 4;
+        }
+        break;
+
+    default:
+        msg_Err( getIntf(), "unsupported depth: %d bpp\n", depth );
+        m_pDisplay = NULL;
+        break;
     }
 
     // Free the visual info
@@ -178,66 +202,58 @@ X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
     {
         XGCValues xgcvalues;
         xgcvalues.graphics_exposures = False;
-        m_gc = XCreateGC( m_pDisplay, DefaultRootWindow( m_pDisplay ),
-                          GCGraphicsExposures, &xgcvalues );
+        m_gc = XCreateGC( m_pDisplay, root, GCGraphicsExposures, &xgcvalues );
+
+        // Create a parent window to have a single task in the task bar
+        XSetWindowAttributes attr;
+        m_mainWindow = XCreateWindow( m_pDisplay, root, 0, 0, 1, 1, 0, 0,
+                                      InputOutput, CopyFromParent, 0, &attr );
+
+        // Changing decorations
+        struct {
+            unsigned long flags;
+            unsigned long functions;
+            unsigned long decorations;
+            long input_mode;
+            unsigned long status;
+        } motifWmHints;
+        Atom hints_atom = XInternAtom( m_pDisplay, "_MOTIF_WM_HINTS", False );
+        motifWmHints.flags = 2;    // MWM_HINTS_DECORATIONS;
+        motifWmHints.decorations = 0;
+        XChangeProperty( m_pDisplay, m_mainWindow, hints_atom, hints_atom, 32,
+                         PropModeReplace, (unsigned char *)&motifWmHints,
+                         sizeof( motifWmHints ) / sizeof( long ) );
+
+        // Change the window title
+        XStoreName( m_pDisplay, m_mainWindow, "VLC Media Player" );
+
+        // Receive map notify events
+        XSelectInput( m_pDisplay, m_mainWindow, StructureNotifyMask );
+
+        // Set an empty mask for the window
+        Region mask = XCreateRegion();
+        XShapeCombineRegion( m_pDisplay, m_mainWindow, ShapeBounding, 0, 0,
+                             mask, ShapeSet );
+        XDestroyRegion( mask );
+
+        XMapWindow( m_pDisplay, m_mainWindow);
+
+        // Move it outside the screen to avoid seeing it in workspace selector
+        XMoveWindow( m_pDisplay, m_mainWindow, -10, -10 );
     }
-
-    // Create a parent window to have a single task in the task bar
-    XSetWindowAttributes attr;
-    m_mainWindow = XCreateWindow( m_pDisplay, DefaultRootWindow( m_pDisplay),
-                                  0, 0, 1, 1, 0, 0, InputOutput,
-                                  CopyFromParent, 0, &attr );
-
-    // Changing decorations
-    struct {
-        unsigned long flags;
-        unsigned long functions;
-        unsigned long decorations;
-        long input_mode;
-        unsigned long status;
-    } motifWmHints;
-    Atom hints_atom = XInternAtom( m_pDisplay, "_MOTIF_WM_HINTS", False );
-    motifWmHints.flags = 2;    // MWM_HINTS_DECORATIONS;
-    motifWmHints.decorations = 0;
-    XChangeProperty( m_pDisplay, m_mainWindow, hints_atom, hints_atom, 32,
-                     PropModeReplace, (unsigned char *)&motifWmHints,
-                     sizeof( motifWmHints ) / sizeof( long ) );
-
-    // Change the window title
-    XStoreName( m_pDisplay, m_mainWindow, "VLC Media Player" );
-
-    // Set an empty mask for the window
-    Region mask = XCreateRegion();
-    XShapeCombineRegion( m_pDisplay, m_mainWindow, ShapeBounding, 0, 0, mask,
-                         ShapeSet );
-    // Map the window
-    XMapWindow( m_pDisplay, m_mainWindow);
 }
 
 
 X11Display::~X11Display()
 {
-    if( m_mainWindow )
-    {
-        XDestroyWindow( m_pDisplay, m_mainWindow );
-    }
-    if( m_gc )
-    {
-        XFreeGC( m_pDisplay, m_gc );
-    }
-    if( m_colormap )
-    {
-        XFreeColormap( m_pDisplay, m_colormap );
-    }
-    if( m_pDisplay )
-    {
-        XCloseDisplay( m_pDisplay );
-    }
+    if( m_mainWindow ) XDestroyWindow( m_pDisplay, m_mainWindow );
+    if( m_gc )         XFreeGC( m_pDisplay, m_gc );
+    if( m_colormap )   XFreeColormap( m_pDisplay, m_colormap );
+    if( m_pDisplay )   XCloseDisplay( m_pDisplay );
 }
 
 
-void X11Display::getShifts( uint32_t mask, int &rLeftShift,
-                            int &rRightShift ) const
+void X11Display::getShifts( uint32_t mask, int &rLeftShift, int &rRightShift )
 {
     for( rLeftShift = 0; (rLeftShift < 32) && !(mask & 1); rLeftShift++ )
     {
@@ -255,163 +271,123 @@ void X11Display::getShifts( uint32_t mask, int &rLeftShift,
 }
 
 
-void X11Display::makePixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
-                             uint8_t a ) const
+void X11Display::blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g,
+                              uint8_t b, uint8_t a ) const
 {
-    // Get the current pixel value
-    uint8_t value = 255 - *pPixel;
-
-    // Compute the new color values
-    uint16_t temp;
-    temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift));
-    uint8_t red = ( temp * (255 - a) + r * a ) / 255;
-    temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift));
-    uint8_t green = ( temp * (255 - a) + g * a ) / 255;
-    temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift));
-    uint8_t blue = ( temp * (255 - a) + b * a ) / 255;
-
-    // Set the new pixel value
-    value =
-        ( ((uint8_t)red >> m_redRightShift) << m_redLeftShift ) |
-        ( ((uint8_t)green >> m_greenRightShift) << m_greenLeftShift ) |
-        ( ((uint8_t)blue >> m_blueRightShift) << m_blueLeftShift );
-
-    *pPixel = 255 - value;
+    *pPixel = 255 - blendPixel<uint8_t>(255 - *pPixel,r,g,b,a);
 }
 
 
-void X11Display::makePixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
-                                 uint8_t b, uint8_t a ) const
+void X11Display::blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                  uint8_t b, uint8_t a ) const
 {
-    // Get the current pixel value
     uint16_t value = pPixel[1] | pPixel[0] << 8;
 
-    // Compute the new color values
-    uint16_t temp;
-    temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift));
-    uint8_t red = ( temp * (255 - a) + r * a ) / 255;
-    temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift));
-    uint8_t green = ( temp * (255 - a) + g * a ) / 255;
-    temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift));
-    uint8_t blue = ( temp * (255 - a) + b * a ) / 255;
-
-    // Set the new pixel value
-    value =
-        ( ((uint16_t)red >> m_redRightShift) << m_redLeftShift ) |
-        ( ((uint16_t)green >> m_greenRightShift) << m_greenLeftShift ) |
-        ( ((uint16_t)blue >> m_blueRightShift) << m_blueLeftShift );
+    value = blendPixel<uint16_t>(value,r,g,b,a);
 
-    pPixel[1] = value;
-    value >>= 8;
+    pPixel[1] = value; value >>= 8;
     pPixel[0] = value;
 }
 
 
-void X11Display::makePixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
-                                 uint8_t b, uint8_t a ) const
+void X11Display::blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                  uint8_t b, uint8_t a ) const
 {
-    // Get the current pixel value
     uint16_t value = pPixel[0] | pPixel[1] << 8;
 
-    // Compute the new color values
-    uint16_t temp;
-    temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift));
-    uint8_t red = ( temp * (255 - a) + r * a ) / 255;
-    temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift));
-    uint8_t green = ( temp * (255 - a) + g * a ) / 255;
-    temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift));
-    uint8_t blue = ( temp * (255 - a) + b * a ) / 255;
-
-    // Set the new pixel value
-    value =
-        ( ((uint16_t)red >> m_redRightShift) << m_redLeftShift ) |
-        ( ((uint16_t)green >> m_greenRightShift) << m_greenLeftShift ) |
-        ( ((uint16_t)blue >> m_blueRightShift) << m_blueLeftShift );
+    value = blendPixel<uint16_t>(value,r,g,b,a);
 
-    pPixel[0] = value;
-    value >>= 8;
+    pPixel[0] = value; value >>= 8;
     pPixel[1] = value;
 }
 
 
-void X11Display::makePixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
-                                 uint8_t b, uint8_t a ) const
+void X11Display::blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                  uint8_t b, uint8_t a ) const
 {
-    // Get the current pixel value
-    uint32_t value = pPixel[3] | pPixel[2] << 8 | pPixel[1] << 16 |
-                          pPixel[0] << 24;
+    uint32_t value = pPixel[3] | pPixel[2] << 8 |
+                     pPixel[1] << 16 | pPixel[0] << 24;
 
-    // Compute the new color values
-    uint16_t temp;
-    temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift));
-    uint8_t red = ( temp * (255 - a) + r * a ) / 255;
-    temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift));
-    uint8_t green = ( temp * (255 - a) + g * a ) / 255;
-    temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift));
-    uint8_t blue = ( temp * (255 - a) + b * a ) / 255;
-
-    // Set the new pixel value
-    value =
-        ( ((uint32_t)red >> m_redRightShift) << m_redLeftShift ) |
-        ( ((uint32_t)green >> m_greenRightShift) << m_greenLeftShift ) |
-        ( ((uint32_t)blue >> m_blueRightShift) << m_blueLeftShift );
+    value = blendPixel<uint32_t>(value,r,g,b,a);
 
-    pPixel[3] = value;
-    value >>= 8;
-    pPixel[2] = value;
-    value >>= 8;
-    pPixel[1] = value;
-    value >>= 8;
+    pPixel[3] = value; value >>= 8;
+    pPixel[2] = value; value >>= 8;
+    pPixel[1] = value; value >>= 8;
     pPixel[0] = value;
 }
 
 
-void X11Display::makePixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
-                                 uint8_t b, uint8_t a ) const
+void X11Display::blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                  uint8_t b, uint8_t a ) const
 {
-    // Get the current pixel value
-    uint32_t value = pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16 |
-                          pPixel[3] << 24;
+    uint32_t value = pPixel[0] | pPixel[1] << 8 |
+                     pPixel[2] << 16 | pPixel[3] << 24;
 
-    // Compute the new color values
-    uint16_t temp;
-    temp = ((uint8_t)((value >> m_redLeftShift) << m_redRightShift));
-    uint8_t red = ( temp * (255 - a) + r * a ) / 255;
-    temp = ((uint8_t)((value >> m_greenLeftShift) << m_greenRightShift));
-    uint8_t green = ( temp * (255 - a) + g * a ) / 255;
-    temp = ((uint8_t)((value >> m_blueLeftShift) << m_blueRightShift));
-    uint8_t blue = ( temp * (255 - a) + b * a ) / 255;
-
-    // Set the new pixel value
-    value =
-        ( ((uint32_t)red >> m_redRightShift) << m_redLeftShift ) |
-        ( ((uint32_t)green >> m_greenRightShift) << m_greenLeftShift ) |
-        ( ((uint32_t)blue >> m_blueRightShift) << m_blueLeftShift );
+    value = blendPixel<uint32_t>(value,r,g,b,a);
+
+    pPixel[0] = value; value >>= 8;
+    pPixel[1] = value; value >>= 8;
+    pPixel[2] = value; value >>= 8;
+    pPixel[3] = value;
+}
 
+
+void X11Display::putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g,
+                            uint8_t b, uint8_t a ) const
+{
+    *pPixel = 255 - putPixel<uint8_t>(r,g,b);
+}
+
+
+void X11Display::putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                uint8_t b, uint8_t a ) const
+{
+    uint16_t value = putPixel<uint16_t>(r, g, b);
+
+    pPixel[1] = value; value >>= 8;
     pPixel[0] = value;
-    value >>= 8;
+}
+
+
+void X11Display::putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                uint8_t b, uint8_t a ) const
+{
+    uint16_t value = putPixel<uint16_t>(r,g,b);
+    pPixel[0] = value; value >>= 8;
     pPixel[1] = value;
-    value >>= 8;
-    pPixel[2] = value;
-    value >>= 8;
+}
+
+
+void X11Display::putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                uint8_t b, uint8_t a ) const
+{
+    uint32_t value = putPixel<uint32_t>(r,g,b);
+
+    pPixel[3] = value; value >>= 8;
+    pPixel[2] = value; value >>= 8;
+    pPixel[1] = value; value >>= 8;
+    pPixel[0] = value;
+}
+
+
+void X11Display::putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
+                                uint8_t b, uint8_t a ) const
+{
+    uint32_t value = putPixel<uint32_t>(r,g,b);
+
+    pPixel[0] = value; value >>= 8;
+    pPixel[1] = value; value >>= 8;
+    pPixel[2] = value; value >>= 8;
     pPixel[3] = value;
 }
 
 
-unsigned long X11Display::getPixelValue( uint8_t r, uint8_t g, uint8_t b ) const
+unsigned long X11Display::getPixelValue( uint8_t r, uint8_t g, uint8_t b )
+    const
 {
-    unsigned long value;
-    value = ( ((uint32_t)r >> m_redRightShift) << m_redLeftShift ) |
-            ( ((uint32_t)g >> m_greenRightShift) << m_greenLeftShift ) |
-            ( ((uint32_t)b >> m_blueRightShift) << m_blueLeftShift );
-    if( m_pixelSize == 1 )
-    {
-        return 255 - value;
-    }
-    else
-    {
-        return value;
-    }
+    unsigned long value = putPixel<unsigned long>(r,g,b);
+
+    return m_pixelSize==1 ? 255 - value : value;
 }