Commit a42c3ab3 authored by Cyril Deguet's avatar Cyril Deguet

* all: support of 8 bpp mode for X11 skins. Like in the vout it uses

 its own colormap, but I don't like that at all...
parent 060778bd
......@@ -2,7 +2,7 @@
* x11_display.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_display.cpp,v 1.2 2004/01/25 13:59:33 asmax Exp $
* $Id: x11_display.cpp,v 1.3 2004/01/25 18:41:08 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -32,7 +32,7 @@
X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
m_gc( NULL )
m_gc( NULL ), m_colormap( 0 )
{
// Open a connection to the X Server
m_pDisplay = XOpenDisplay( NULL );
......@@ -61,6 +61,49 @@ 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;
break;
case 16:
case 24:
case 32:
......@@ -84,6 +127,12 @@ X11Display::X11Display( intf_thread_t *pIntf ): SkinObject( pIntf ),
m_greenRightShift );
getShifts( pVInfo->blue_mask, m_blueLeftShift, m_blueRightShift );
if( depth == 8 )
{
makePixelImpl = &X11Display::makePixel8;
m_pixelSize = 1;
}
if( depth == 16 )
{
if( order == MSBFirst )
......@@ -139,6 +188,10 @@ X11Display::~X11Display()
{
XFreeGC( m_pDisplay, m_gc );
}
if( m_colormap )
{
XFreeColormap( m_pDisplay, m_colormap );
}
if( m_pDisplay )
{
XCloseDisplay( m_pDisplay );
......@@ -165,6 +218,31 @@ 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
{
// 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;
}
void X11Display::makePixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g,
uint8_t b, uint8_t a ) const
{
......@@ -283,4 +361,14 @@ void X11Display::makePixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g,
}
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 );
return 255 - value;
}
#endif
......@@ -2,7 +2,7 @@
* x11_display.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_display.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
* $Id: x11_display.hpp,v 1.2 2004/01/25 18:41:08 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -55,6 +55,9 @@ class X11Display: public SkinObject
/// Get the graphics context
GC getGC() const { return m_gc; }
/// Get the colormap
Colormap getColormap() const { return m_colormap; }
/// Type of function to convert RGB values into a pixel
typedef void (X11Display::*MakePixelFunc_t)( uint8_t *pPixel,
uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const;
......@@ -62,12 +65,16 @@ class X11Display: public SkinObject
/// Get a pointer on the right makePixel implementation
MakePixelFunc_t getMakePixel() const { return makePixelImpl; }
/// Get the pixel value corresponding to the given colors
unsigned long getPixelValue( uint8_t r, uint8_t g, uint8_t b ) const;
private:
/// Display parameters
Display *m_pDisplay;
Visual *m_pVisual;
int m_pixelSize;
GC m_gc;
Colormap m_colormap;
int m_redLeftShift, m_redRightShift;
int m_greenLeftShift, m_greenRightShift;
int m_blueLeftShift, m_blueRightShift;
......@@ -80,6 +87,10 @@ class X11Display: public SkinObject
void getShifts( uint32_t mask, int &rLeftShift,
int &rRightShift ) const;
/// 8 bpp version of makePixel
void makePixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp MSB first version of makePixel
void makePixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
......
......@@ -2,7 +2,7 @@
* x11_graphics.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_graphics.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
* $Id: x11_graphics.cpp,v 1.2 2004/01/25 18:41:08 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -267,16 +267,9 @@ void X11Graphics::fillRect( int left, int top, int width, int height,
XDestroyRegion( m_mask );
m_mask = newMask;
XColor xcolor;
xcolor.red = (color & 0xff0000) >> 8;
xcolor.green = color & 0xff00;
xcolor.blue = (color & 0xff) << 8;
// Draw the rectangle
Colormap cm = DefaultColormap( XDISPLAY, DefaultScreen( XDISPLAY ) );
XAllocColor( XDISPLAY, cm, &xcolor );
XGCValues gcVal;
gcVal.foreground = xcolor.pixel;
gcVal.foreground = m_rDisplay.getPixelValue( color >> 16, color >> 8, color );
XChangeGC( XDISPLAY, m_gc, GCForeground, &gcVal );
XSetRegion( XDISPLAY, m_gc, m_mask );
XFillRectangle( XDISPLAY, m_pixmap, m_gc, left, top, width, height );
......@@ -292,16 +285,9 @@ void X11Graphics::drawRect( int left, int top, int width, int height,
addVSegmentInRegion( m_mask, top, top + height, left );
addVSegmentInRegion( m_mask, top, top + height, left + width );
XColor xcolor;
xcolor.red = (color & 0xff0000) >> 8;
xcolor.green = color & 0xff00;
xcolor.blue = (color & 0xff) << 8;
// Draw the rectangle
Colormap cm = DefaultColormap( XDISPLAY, DefaultScreen( XDISPLAY ) );
XAllocColor( XDISPLAY, cm, &xcolor );
XGCValues gcVal;
gcVal.foreground = xcolor.pixel;
gcVal.foreground = m_rDisplay.getPixelValue( color >> 16, color >> 8, color );
XChangeGC( XDISPLAY, m_gc, GCForeground, &gcVal );
XSetRegion( XDISPLAY, m_gc, m_mask );
XDrawRectangle( XDISPLAY, m_pixmap, m_gc, left, top, width - 1, height - 1 );
......
......@@ -2,7 +2,7 @@
* x11_tooltip.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_tooltip.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
* $Id: x11_tooltip.cpp,v 1.2 2004/01/25 18:41:08 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -42,6 +42,12 @@ X11Tooltip::X11Tooltip( intf_thread_t *pIntf,
m_wnd = XCreateWindow( XDISPLAY, root, 0, 0, 1, 1, 0, 0,
InputOutput, CopyFromParent, CWOverrideRedirect,
&attr );
// Set the colormap for 8bpp mode
if( XPIXELSIZE == 1 )
{
XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
}
}
......
......@@ -2,7 +2,7 @@
* x11_window.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.2 2004/01/18 00:25:02 asmax Exp $
* $Id: x11_window.cpp,v 1.3 2004/01/25 18:41:08 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -45,6 +45,12 @@ X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
m_wnd = XCreateWindow( XDISPLAY, root, 0, 0, 1, 1, 0, 0,
InputOutput, CopyFromParent, 0, &attr );
// Set the colormap for 8bpp mode
if( XPIXELSIZE == 1 )
{
XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
}
// Select events received by the window
XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|PointerMotionMask|
ButtonPressMask|ButtonReleaseMask|LeaveWindowMask|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment