Moved m_visual* wxApp[X11] members used by wxBitmap and
wxColour into a new wxXVisualInfo structure, and moved code to initialize it to a new src/x11/utilsx.cpp file (utility functions shared by wxMotif and wxX11). Added (currently unused) code in wxMotif to retrieve wxXVisualInfo; it will be used when wxMotif is switched to bitmap.cpp from wxX11. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -700,6 +700,7 @@ reparent.cpp X11
|
|||||||
settings.cpp X11
|
settings.cpp X11
|
||||||
toplevel.cpp X11
|
toplevel.cpp X11
|
||||||
utils.cpp X11
|
utils.cpp X11
|
||||||
|
utilsx.cpp X11 Motif
|
||||||
window.cpp X11
|
window.cpp X11
|
||||||
|
|
||||||
accel.cpp OS2
|
accel.cpp OS2
|
||||||
|
@@ -32,6 +32,8 @@ class WXDLLEXPORT wxApp;
|
|||||||
class WXDLLEXPORT wxKeyEvent;
|
class WXDLLEXPORT wxKeyEvent;
|
||||||
class WXDLLEXPORT wxLog;
|
class WXDLLEXPORT wxLog;
|
||||||
class WXDLLEXPORT wxEventLoop;
|
class WXDLLEXPORT wxEventLoop;
|
||||||
|
class WXDLLEXPORT wxXVisualInfo;
|
||||||
|
class wxXVisualInfoMap;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// the wxApp class for Motif - see wxAppBase for more details
|
// the wxApp class for Motif - see wxAppBase for more details
|
||||||
@@ -91,6 +93,8 @@ public:
|
|||||||
// This handler is called when a property change event occurs
|
// This handler is called when a property change event occurs
|
||||||
virtual void HandlePropertyChange(WXEvent *event);
|
virtual void HandlePropertyChange(WXEvent *event);
|
||||||
|
|
||||||
|
wxXVisualInfo* GetVisualInfo(WXDisplay* display);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static long sm_lastMessageTime;
|
static long sm_lastMessageTime;
|
||||||
int m_nCmdShow;
|
int m_nCmdShow;
|
||||||
@@ -103,6 +107,7 @@ private:
|
|||||||
WXColormap m_mainColormap;
|
WXColormap m_mainColormap;
|
||||||
WXDisplay* m_initialDisplay;
|
WXDisplay* m_initialDisplay;
|
||||||
long m_maxRequestSize;
|
long m_maxRequestSize;
|
||||||
|
wxXVisualInfoMap* m_visualInfoMap;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
@@ -33,6 +33,7 @@ class WXDLLEXPORT wxApp;
|
|||||||
class WXDLLEXPORT wxKeyEvent;
|
class WXDLLEXPORT wxKeyEvent;
|
||||||
class WXDLLEXPORT wxLog;
|
class WXDLLEXPORT wxLog;
|
||||||
class WXDLLEXPORT wxEventLoop;
|
class WXDLLEXPORT wxEventLoop;
|
||||||
|
class WXDLLEXPORT wxXVisualInfo;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// the wxApp class for wxX11 - see wxAppBase for more details
|
// the wxApp class for wxX11 - see wxAppBase for more details
|
||||||
@@ -108,6 +109,13 @@ public:
|
|||||||
PangoContext* GetPangoContext();
|
PangoContext* GetPangoContext();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
wxXVisualInfo* GetVisualInfo(WXDisplay* display)
|
||||||
|
{
|
||||||
|
// this should be implemented correctly for wxBitmap to work
|
||||||
|
// with multiple display
|
||||||
|
return m_visualInfo;
|
||||||
|
}
|
||||||
|
|
||||||
// We need this before creating the app
|
// We need this before creating the app
|
||||||
static WXDisplay* GetDisplay() { return ms_display; }
|
static WXDisplay* GetDisplay() { return ms_display; }
|
||||||
static WXDisplay* ms_display;
|
static WXDisplay* ms_display;
|
||||||
@@ -118,23 +126,7 @@ public:
|
|||||||
wxSize m_initialSize;
|
wxSize m_initialSize;
|
||||||
|
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
// Someone find a better place for these
|
wxXVisualInfo* m_visualInfo;
|
||||||
int m_visualType; // TrueColor, DirectColor etc.
|
|
||||||
int m_visualDepth;
|
|
||||||
int m_visualColormapSize;
|
|
||||||
void *m_visualColormap;
|
|
||||||
int m_visualScreen;
|
|
||||||
unsigned long m_visualRedMask;
|
|
||||||
unsigned long m_visualGreenMask;
|
|
||||||
unsigned long m_visualBlueMask;
|
|
||||||
int m_visualRedShift;
|
|
||||||
int m_visualGreenShift;
|
|
||||||
int m_visualBlueShift;
|
|
||||||
int m_visualRedPrec;
|
|
||||||
int m_visualGreenPrec;
|
|
||||||
int m_visualBluePrec;
|
|
||||||
|
|
||||||
unsigned char *m_colorCube;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -135,5 +135,31 @@ bool wxWindowIsVisible(Window win);
|
|||||||
#define XFontStructGetAscent(f) f->ascent
|
#define XFontStructGetAscent(f) f->ascent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
class WXDLLEXPORT wxXVisualInfo
|
||||||
// _WX_PRIVX_H_
|
{
|
||||||
|
public:
|
||||||
|
wxXVisualInfo();
|
||||||
|
~wxXVisualInfo();
|
||||||
|
void Init( Display* dpy, XVisualInfo* visualInfo );
|
||||||
|
|
||||||
|
int m_visualType; // TrueColor, DirectColor etc.
|
||||||
|
int m_visualDepth;
|
||||||
|
int m_visualColormapSize;
|
||||||
|
void *m_visualColormap;
|
||||||
|
int m_visualScreen;
|
||||||
|
unsigned long m_visualRedMask;
|
||||||
|
unsigned long m_visualGreenMask;
|
||||||
|
unsigned long m_visualBlueMask;
|
||||||
|
int m_visualRedShift;
|
||||||
|
int m_visualGreenShift;
|
||||||
|
int m_visualBlueShift;
|
||||||
|
int m_visualRedPrec;
|
||||||
|
int m_visualGreenPrec;
|
||||||
|
int m_visualBluePrec;
|
||||||
|
|
||||||
|
unsigned char *m_colorCube;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool wxFillXVisualInfo( wxXVisualInfo* vi, Display* dpy );
|
||||||
|
|
||||||
|
#endif // _WX_PRIVX_H_
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/evtloop.h"
|
#include "wx/evtloop.h"
|
||||||
#include "wx/hash.h"
|
#include "wx/hash.h"
|
||||||
|
#include "wx/hashmap.h"
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
@@ -58,6 +59,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
WX_DECLARE_VOIDPTR_HASH_MAP( wxXVisualInfo*, wxXVisualInfoMap );
|
||||||
|
|
||||||
extern wxList wxPendingDelete;
|
extern wxList wxPendingDelete;
|
||||||
extern bool wxAddIdleCallback();
|
extern bool wxAddIdleCallback();
|
||||||
|
|
||||||
@@ -243,11 +246,21 @@ wxApp::wxApp()
|
|||||||
m_topLevelWidget = (WXWidget) NULL;
|
m_topLevelWidget = (WXWidget) NULL;
|
||||||
m_maxRequestSize = 0;
|
m_maxRequestSize = 0;
|
||||||
m_initialDisplay = (WXDisplay*) 0;
|
m_initialDisplay = (WXDisplay*) 0;
|
||||||
|
m_visualInfoMap = new wxXVisualInfoMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxApp::~wxApp()
|
wxApp::~wxApp()
|
||||||
{
|
{
|
||||||
delete m_eventLoop;
|
delete m_eventLoop;
|
||||||
|
|
||||||
|
for( wxXVisualInfoMap::iterator it = m_visualInfoMap->begin(),
|
||||||
|
end = m_visualInfoMap->end();
|
||||||
|
it != end; ++it )
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete m_visualInfoMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxApp::Initialized()
|
bool wxApp::Initialized()
|
||||||
@@ -493,6 +506,20 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
|
|||||||
return (WXColormap) c;
|
return (WXColormap) c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display )
|
||||||
|
{
|
||||||
|
wxXVisualInfoMap::iterator it = m_visualInfoMap->find( display );
|
||||||
|
|
||||||
|
if( it != m_visualInfoMap->end() ) return it->second;
|
||||||
|
|
||||||
|
wxXVisualInfo* vi = new wxXVisualInfo;
|
||||||
|
wxFillXVisualInfo( vi, (Display*)display );
|
||||||
|
|
||||||
|
(*m_visualInfoMap)[display] = vi;
|
||||||
|
|
||||||
|
return vi;
|
||||||
|
}
|
||||||
|
|
||||||
void wxExit()
|
void wxExit()
|
||||||
{
|
{
|
||||||
int retValue = 0;
|
int retValue = 0;
|
||||||
|
@@ -233,6 +233,7 @@ ALL_SOURCES = \
|
|||||||
motif/window.cpp \
|
motif/window.cpp \
|
||||||
x11/brush.cpp \
|
x11/brush.cpp \
|
||||||
x11/pen.cpp \
|
x11/pen.cpp \
|
||||||
|
x11/utilsx.cpp \
|
||||||
unix/dialup.cpp \
|
unix/dialup.cpp \
|
||||||
unix/dir.cpp \
|
unix/dir.cpp \
|
||||||
unix/fontenum.cpp \
|
unix/fontenum.cpp \
|
||||||
@@ -862,7 +863,8 @@ GUIOBJS = \
|
|||||||
utils.o \
|
utils.o \
|
||||||
window.o \
|
window.o \
|
||||||
brush.o \
|
brush.o \
|
||||||
pen.o
|
pen.o \
|
||||||
|
utilsx.o
|
||||||
|
|
||||||
UNIXOBJS = \
|
UNIXOBJS = \
|
||||||
dialup.o \
|
dialup.o \
|
||||||
|
124
src/x11/app.cpp
124
src/x11/app.cpp
@@ -32,8 +32,6 @@
|
|||||||
#include "wx/univ/theme.h"
|
#include "wx/univ/theme.h"
|
||||||
#include "wx/univ/renderer.h"
|
#include "wx/univ/renderer.h"
|
||||||
|
|
||||||
#define ABS(a) (((a) < 0) ? -(a) : (a))
|
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -380,19 +378,14 @@ wxApp::wxApp()
|
|||||||
m_initialSize = wxDefaultSize;
|
m_initialSize = wxDefaultSize;
|
||||||
|
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
m_visualColormap = NULL;
|
m_visualInfo = NULL;
|
||||||
m_colorCube = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxApp::~wxApp()
|
wxApp::~wxApp()
|
||||||
{
|
{
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
if (m_colorCube)
|
delete m_visualInfo;
|
||||||
free( m_colorCube );
|
|
||||||
|
|
||||||
if (m_visualColormap)
|
|
||||||
delete [] (XColor*)m_visualColormap;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -964,24 +957,6 @@ void wxApp::DeletePendingObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wxCalcPrecAndShift( unsigned long mask, int *shift, int *prec )
|
|
||||||
{
|
|
||||||
*shift = 0;
|
|
||||||
*prec = 0;
|
|
||||||
|
|
||||||
while (!(mask & 0x1))
|
|
||||||
{
|
|
||||||
(*shift)++;
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (mask & 0x1)
|
|
||||||
{
|
|
||||||
(*prec)++;
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create display, and other initialization
|
// Create display, and other initialization
|
||||||
bool wxApp::OnInitGui()
|
bool wxApp::OnInitGui()
|
||||||
{
|
{
|
||||||
@@ -998,99 +973,8 @@ bool wxApp::OnInitGui()
|
|||||||
m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
|
m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
|
||||||
|
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
// Get info about the current visual. It is enough
|
m_visualInfo = new wxXVisualInfo;
|
||||||
// to do this once here unless we support different
|
wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
|
||||||
// visuals, displays and screens. Given that wxX11
|
|
||||||
// mostly for embedded things, that is no real
|
|
||||||
// limitation.
|
|
||||||
Display *xdisplay = (Display*) wxApp::GetDisplay();
|
|
||||||
int xscreen = DefaultScreen(xdisplay);
|
|
||||||
Visual* xvisual = DefaultVisual(xdisplay,xscreen);
|
|
||||||
int xdepth = DefaultDepth(xdisplay, xscreen);
|
|
||||||
|
|
||||||
XVisualInfo vinfo_template;
|
|
||||||
vinfo_template.visual = xvisual;
|
|
||||||
vinfo_template.visualid = XVisualIDFromVisual( xvisual );
|
|
||||||
vinfo_template.depth = xdepth;
|
|
||||||
|
|
||||||
int nitem = 0;
|
|
||||||
XVisualInfo *vi = XGetVisualInfo( xdisplay, VisualIDMask|VisualDepthMask, &vinfo_template, &nitem );
|
|
||||||
wxASSERT_MSG( vi, wxT("No visual info") );
|
|
||||||
|
|
||||||
m_visualType = vi->visual->c_class;
|
|
||||||
m_visualScreen = vi->screen;
|
|
||||||
|
|
||||||
m_visualRedMask = vi->red_mask;
|
|
||||||
m_visualGreenMask = vi->green_mask;
|
|
||||||
m_visualBlueMask = vi->blue_mask;
|
|
||||||
|
|
||||||
if (m_visualType != GrayScale && m_visualType != PseudoColor)
|
|
||||||
{
|
|
||||||
wxCalcPrecAndShift( m_visualRedMask, &m_visualRedShift, &m_visualRedPrec );
|
|
||||||
wxCalcPrecAndShift( m_visualGreenMask, &m_visualGreenShift, &m_visualGreenPrec );
|
|
||||||
wxCalcPrecAndShift( m_visualBlueMask, &m_visualBlueShift, &m_visualBluePrec );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_visualDepth = xdepth;
|
|
||||||
if (xdepth == 16)
|
|
||||||
xdepth = m_visualRedPrec + m_visualGreenPrec + m_visualBluePrec;
|
|
||||||
|
|
||||||
m_visualColormapSize = vi->colormap_size;
|
|
||||||
|
|
||||||
XFree( vi );
|
|
||||||
|
|
||||||
if (m_visualDepth > 8)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
m_visualColormap = new XColor[m_visualColormapSize];
|
|
||||||
XColor* colors = (XColor*) m_visualColormap;
|
|
||||||
|
|
||||||
for (int i = 0; i < m_visualColormapSize; i++)
|
|
||||||
colors[i].pixel = i;
|
|
||||||
|
|
||||||
XQueryColors( xdisplay, DefaultColormap(xdisplay,xscreen), colors, m_visualColormapSize );
|
|
||||||
|
|
||||||
m_colorCube = (unsigned char*)malloc(32 * 32 * 32);
|
|
||||||
|
|
||||||
for (int r = 0; r < 32; r++)
|
|
||||||
{
|
|
||||||
for (int g = 0; g < 32; g++)
|
|
||||||
{
|
|
||||||
for (int b = 0; b < 32; b++)
|
|
||||||
{
|
|
||||||
int rr = (r << 3) | (r >> 2);
|
|
||||||
int gg = (g << 3) | (g >> 2);
|
|
||||||
int bb = (b << 3) | (b >> 2);
|
|
||||||
|
|
||||||
int index = -1;
|
|
||||||
|
|
||||||
if (colors)
|
|
||||||
{
|
|
||||||
int max = 3 * 65536;
|
|
||||||
|
|
||||||
for (int i = 0; i < m_visualColormapSize; i++)
|
|
||||||
{
|
|
||||||
int rdiff = ((rr << 8) - colors[i].red);
|
|
||||||
int gdiff = ((gg << 8) - colors[i].green);
|
|
||||||
int bdiff = ((bb << 8) - colors[i].blue);
|
|
||||||
int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
|
|
||||||
if (sum < max)
|
|
||||||
{
|
|
||||||
index = i; max = sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// assume 8-bit true or static colors. this really exists
|
|
||||||
index = (r >> (5 - m_visualRedPrec)) << m_visualRedShift;
|
|
||||||
index |= (g >> (5 - m_visualGreenPrec)) << m_visualGreenShift;
|
|
||||||
index |= (b >> (5 - m_visualBluePrec)) << m_visualBlueShift;
|
|
||||||
}
|
|
||||||
m_colorCube[ (r*1024) + (g*32) + b ] = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@@ -114,7 +114,7 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
unsigned char green = colour.Green();
|
unsigned char green = colour.Green();
|
||||||
unsigned char blue = colour.Blue();
|
unsigned char blue = colour.Blue();
|
||||||
|
|
||||||
int bpp = wxTheApp->m_visualDepth;
|
int bpp = wxTheApp->GetVisualInfo(m_display)->m_visualDepth;
|
||||||
|
|
||||||
if (bpp == 15)
|
if (bpp == 15)
|
||||||
{
|
{
|
||||||
@@ -506,7 +506,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
Window xroot = RootWindow( xdisplay, xscreen );
|
Window xroot = RootWindow( xdisplay, xscreen );
|
||||||
Visual* xvisual = DefaultVisual( xdisplay, xscreen );
|
Visual* xvisual = DefaultVisual( xdisplay, xscreen );
|
||||||
|
|
||||||
int bpp = wxTheApp->m_visualDepth;
|
int bpp = wxTheApp->GetVisualInfo(M_BMPDATA->m_display)->m_visualDepth;
|
||||||
|
|
||||||
int width = image.GetWidth();
|
int width = image.GetWidth();
|
||||||
int height = image.GetHeight();
|
int height = image.GetHeight();
|
||||||
@@ -563,14 +563,19 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
|
enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
|
||||||
byte_order b_o = RGB;
|
byte_order b_o = RGB;
|
||||||
|
|
||||||
|
wxXVisualInfo* vi = wxTheApp->GetVisualInfo(M_BMPDATA->m_display);
|
||||||
|
unsigned long greenMask = vi->m_visualGreenMask,
|
||||||
|
redMask = vi->m_visualRedMask,
|
||||||
|
blueMask = vi->m_visualBlueMask;
|
||||||
|
|
||||||
if (bpp > 8)
|
if (bpp > 8)
|
||||||
{
|
{
|
||||||
if ((wxTheApp->m_visualRedMask > wxTheApp->m_visualGreenMask) && (wxTheApp->m_visualGreenMask > wxTheApp->m_visualBlueMask)) b_o = RGB;
|
if ((redMask > greenMask) && (greenMask > blueMask)) b_o = RGB;
|
||||||
else if ((wxTheApp->m_visualRedMask > wxTheApp->m_visualBlueMask) && (wxTheApp->m_visualBlueMask > wxTheApp->m_visualGreenMask)) b_o = RBG;
|
else if ((redMask > blueMask) && (blueMask > greenMask)) b_o = RBG;
|
||||||
else if ((wxTheApp->m_visualBlueMask > wxTheApp->m_visualRedMask) && (wxTheApp->m_visualRedMask > wxTheApp->m_visualGreenMask)) b_o = BRG;
|
else if ((blueMask > redMask) && (redMask > greenMask)) b_o = BRG;
|
||||||
else if ((wxTheApp->m_visualBlueMask > wxTheApp->m_visualGreenMask) && (wxTheApp->m_visualGreenMask > wxTheApp->m_visualRedMask)) b_o = BGR;
|
else if ((blueMask > greenMask) && (greenMask > redMask))b_o = BGR;
|
||||||
else if ((wxTheApp->m_visualGreenMask > wxTheApp->m_visualRedMask) && (wxTheApp->m_visualRedMask > wxTheApp->m_visualBlueMask)) b_o = GRB;
|
else if ((greenMask > redMask) && (redMask > blueMask)) b_o = GRB;
|
||||||
else if ((wxTheApp->m_visualGreenMask > wxTheApp->m_visualBlueMask) && (wxTheApp->m_visualBlueMask > wxTheApp->m_visualRedMask)) b_o = GBR;
|
else if ((greenMask > blueMask) && (blueMask > redMask)) b_o = GBR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r_mask = image.GetMaskRed();
|
int r_mask = image.GetMaskRed();
|
||||||
@@ -580,7 +585,8 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
unsigned char* data = image.GetData();
|
unsigned char* data = image.GetData();
|
||||||
wxASSERT_MSG( data, "No image data" );
|
wxASSERT_MSG( data, "No image data" );
|
||||||
|
|
||||||
unsigned char *colorCube = wxTheApp->m_colorCube;
|
unsigned char *colorCube =
|
||||||
|
wxTheApp->GetVisualInfo(M_BMPDATA->m_display)->m_colorCube;
|
||||||
|
|
||||||
bool hasMask = image.HasMask();
|
bool hasMask = image.HasMask();
|
||||||
|
|
||||||
@@ -719,7 +725,7 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
return image;
|
return image;
|
||||||
#else
|
#else
|
||||||
// !wxUSE_NANOX
|
// !wxUSE_NANOX
|
||||||
int bpp = wxTheApp->m_visualDepth;
|
int bpp = wxTheApp->GetVisualInfo(M_BMPDATA->m_display)->m_visualDepth;
|
||||||
XImage *x_image = NULL;
|
XImage *x_image = NULL;
|
||||||
if (GetPixmap())
|
if (GetPixmap())
|
||||||
{
|
{
|
||||||
@@ -772,14 +778,17 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
|
|
||||||
if (GetPixmap())
|
if (GetPixmap())
|
||||||
{
|
{
|
||||||
red_shift_right = wxTheApp->m_visualRedShift;
|
wxXVisualInfo* vi = wxTheApp->GetVisualInfo(M_BMPDATA->m_display);
|
||||||
red_shift_left = 8-wxTheApp->m_visualRedPrec;
|
|
||||||
green_shift_right = wxTheApp->m_visualGreenShift;
|
|
||||||
green_shift_left = 8-wxTheApp->m_visualGreenPrec;
|
|
||||||
blue_shift_right = wxTheApp->m_visualBlueShift;
|
|
||||||
blue_shift_left = 8-wxTheApp->m_visualBluePrec;
|
|
||||||
|
|
||||||
use_shift = (wxTheApp->m_visualType == GrayScale) || (wxTheApp->m_visualType != PseudoColor);
|
red_shift_right = vi->m_visualRedShift;
|
||||||
|
red_shift_left = 8 - vi->m_visualRedPrec;
|
||||||
|
green_shift_right = vi->m_visualGreenShift;
|
||||||
|
green_shift_left = 8 - vi->m_visualGreenPrec;
|
||||||
|
blue_shift_right = vi->m_visualBlueShift;
|
||||||
|
blue_shift_left = 8 - vi->m_visualBluePrec;
|
||||||
|
|
||||||
|
use_shift = (vi->m_visualType == GrayScale) ||
|
||||||
|
(vi->m_visualType != PseudoColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetBitmap())
|
if (GetBitmap())
|
||||||
@@ -787,7 +796,8 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
bpp = 1;
|
bpp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
XColor *colors = (XColor*) wxTheApp->m_visualColormap;
|
XColor *colors = (XColor*)wxTheApp->
|
||||||
|
GetVisualInfo(M_BMPDATA->m_display)->m_visualColormap;
|
||||||
|
|
||||||
int width = GetWidth();
|
int width = GetWidth();
|
||||||
int height = GetHeight();
|
int height = GetHeight();
|
||||||
|
@@ -93,8 +93,8 @@ void wxColourRefData::FreeColour()
|
|||||||
if (!m_colormap)
|
if (!m_colormap)
|
||||||
return;
|
return;
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
if ((wxTheApp->m_visualType == GrayScale) ||
|
if ((wxTheApp->m_visualInfo->m_visualType == GrayScale) ||
|
||||||
(wxTheApp->m_visualType == PseudoColor))
|
(wxTheApp->m_visualInfo->m_visualType == PseudoColor))
|
||||||
{
|
{
|
||||||
int idx = m_color.pixel;
|
int idx = m_color.pixel;
|
||||||
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
|
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
|
||||||
@@ -116,8 +116,8 @@ void wxColourRefData::AllocColour( WXColormap cmap )
|
|||||||
FreeColour();
|
FreeColour();
|
||||||
|
|
||||||
#if !wxUSE_NANOX
|
#if !wxUSE_NANOX
|
||||||
if ((wxTheApp->m_visualType == GrayScale) ||
|
if ((wxTheApp->m_visualInfo->m_visualType == GrayScale) ||
|
||||||
(wxTheApp->m_visualType == PseudoColor))
|
(wxTheApp->m_visualInfo->m_visualType == PseudoColor))
|
||||||
{
|
{
|
||||||
m_hasPixel = XAllocColor( wxGlobalDisplay(), (Colormap) cmap, &m_color );
|
m_hasPixel = XAllocColor( wxGlobalDisplay(), (Colormap) cmap, &m_color );
|
||||||
int idx = m_color.pixel;
|
int idx = m_color.pixel;
|
||||||
|
@@ -31,6 +31,7 @@ ALL_SOURCES = \
|
|||||||
x11/settings.cpp \
|
x11/settings.cpp \
|
||||||
x11/toplevel.cpp \
|
x11/toplevel.cpp \
|
||||||
x11/utils.cpp \
|
x11/utils.cpp \
|
||||||
|
x11/utilsx.cpp \
|
||||||
x11/window.cpp \
|
x11/window.cpp \
|
||||||
generic/accel.cpp \
|
generic/accel.cpp \
|
||||||
generic/busyinfo.cpp \
|
generic/busyinfo.cpp \
|
||||||
@@ -640,6 +641,7 @@ GUI_LOWLEVEL_OBJS = \
|
|||||||
settings.o \
|
settings.o \
|
||||||
toplevel.o \
|
toplevel.o \
|
||||||
utils.o \
|
utils.o \
|
||||||
|
utilsx.o \
|
||||||
window.o
|
window.o
|
||||||
|
|
||||||
COMMONOBJS = \
|
COMMONOBJS = \
|
||||||
|
161
src/x11/utilsx.cpp
Normal file
161
src/x11/utilsx.cpp
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/x11/utilsx.cpp
|
||||||
|
// Purpose: Private functions common to X11 and Motif ports
|
||||||
|
// Author: Mattia Barbon
|
||||||
|
// Modified by:
|
||||||
|
// Created: 05/04/03
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Mattia Barbon
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/x11/privx.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxXVisualInfo
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if !wxUSE_NANOX
|
||||||
|
|
||||||
|
bool wxFillXVisualInfo( wxXVisualInfo* vi, Display* dpy )
|
||||||
|
{
|
||||||
|
int xscreen = DefaultScreen( dpy );
|
||||||
|
Visual* vis = DefaultVisual( dpy, xscreen );
|
||||||
|
int bpp = DefaultDepth( dpy, xscreen );
|
||||||
|
|
||||||
|
XVisualInfo vinfo_template;
|
||||||
|
XVisualInfo *vinfo;
|
||||||
|
|
||||||
|
vinfo_template.visual = vis;
|
||||||
|
vinfo_template.visualid = XVisualIDFromVisual( vis );
|
||||||
|
vinfo_template.depth = bpp;
|
||||||
|
int nitem = 0;
|
||||||
|
|
||||||
|
vinfo = XGetVisualInfo( dpy, VisualIDMask|VisualDepthMask,
|
||||||
|
&vinfo_template, &nitem );
|
||||||
|
|
||||||
|
wxCHECK_MSG( vinfo, false, wxT("no visual") );
|
||||||
|
|
||||||
|
vi->Init( dpy, vinfo );
|
||||||
|
|
||||||
|
XFree(vinfo);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int ABS(int x) { return x < 0 ? -x : x; }
|
||||||
|
|
||||||
|
static void wxCalcPrecAndShift( unsigned long mask, int *shift, int *prec )
|
||||||
|
{
|
||||||
|
*shift = 0;
|
||||||
|
*prec = 0;
|
||||||
|
|
||||||
|
while (!(mask & 0x1))
|
||||||
|
{
|
||||||
|
(*shift)++;
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mask & 0x1)
|
||||||
|
{
|
||||||
|
(*prec)++;
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxXVisualInfo::wxXVisualInfo()
|
||||||
|
{
|
||||||
|
m_visualColormap = NULL;
|
||||||
|
m_colorCube = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxXVisualInfo::~wxXVisualInfo()
|
||||||
|
{
|
||||||
|
if (m_colorCube)
|
||||||
|
free( m_colorCube );
|
||||||
|
|
||||||
|
if (m_visualColormap)
|
||||||
|
delete [] (XColor*)m_visualColormap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxXVisualInfo::Init( Display* dpy, XVisualInfo* vi )
|
||||||
|
{
|
||||||
|
m_visualType = vi->visual->c_class;
|
||||||
|
m_visualScreen = vi->screen;
|
||||||
|
|
||||||
|
m_visualRedMask = vi->red_mask;
|
||||||
|
m_visualGreenMask = vi->green_mask;
|
||||||
|
m_visualBlueMask = vi->blue_mask;
|
||||||
|
|
||||||
|
if (m_visualType != GrayScale && m_visualType != PseudoColor)
|
||||||
|
{
|
||||||
|
wxCalcPrecAndShift( m_visualRedMask, &m_visualRedShift,
|
||||||
|
&m_visualRedPrec );
|
||||||
|
wxCalcPrecAndShift( m_visualGreenMask, &m_visualGreenShift,
|
||||||
|
&m_visualGreenPrec );
|
||||||
|
wxCalcPrecAndShift( m_visualBlueMask, &m_visualBlueShift,
|
||||||
|
&m_visualBluePrec );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_visualDepth = vi->depth;
|
||||||
|
if (vi->depth == 16)
|
||||||
|
vi->depth = m_visualRedPrec + m_visualGreenPrec + m_visualBluePrec;
|
||||||
|
|
||||||
|
m_visualColormapSize = vi->colormap_size;
|
||||||
|
|
||||||
|
if (m_visualDepth > 8)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_visualColormap = new XColor[m_visualColormapSize];
|
||||||
|
XColor* colors = (XColor*) m_visualColormap;
|
||||||
|
|
||||||
|
for (int i = 0; i < m_visualColormapSize; i++)
|
||||||
|
colors[i].pixel = i;
|
||||||
|
|
||||||
|
XQueryColors( dpy, DefaultColormap(dpy, vi->screen),
|
||||||
|
colors, m_visualColormapSize );
|
||||||
|
|
||||||
|
m_colorCube = (unsigned char*)malloc(32 * 32 * 32);
|
||||||
|
|
||||||
|
for (int r = 0; r < 32; r++)
|
||||||
|
{
|
||||||
|
for (int g = 0; g < 32; g++)
|
||||||
|
{
|
||||||
|
for (int b = 0; b < 32; b++)
|
||||||
|
{
|
||||||
|
int rr = (r << 3) | (r >> 2);
|
||||||
|
int gg = (g << 3) | (g >> 2);
|
||||||
|
int bb = (b << 3) | (b >> 2);
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
if (colors)
|
||||||
|
{
|
||||||
|
int max = 3 * 65536;
|
||||||
|
|
||||||
|
for (int i = 0; i < m_visualColormapSize; i++)
|
||||||
|
{
|
||||||
|
int rdiff = ((rr << 8) - colors[i].red);
|
||||||
|
int gdiff = ((gg << 8) - colors[i].green);
|
||||||
|
int bdiff = ((bb << 8) - colors[i].blue);
|
||||||
|
int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
|
||||||
|
if (sum < max)
|
||||||
|
{
|
||||||
|
index = i; max = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// assume 8-bit true or static colors. this really exists
|
||||||
|
index = (r >> (5 - m_visualRedPrec)) << m_visualRedShift;
|
||||||
|
index |= (g >> (5 - m_visualGreenPrec)) << m_visualGreenShift;
|
||||||
|
index |= (b >> (5 - m_visualBluePrec)) << m_visualBlueShift;
|
||||||
|
}
|
||||||
|
m_colorCube[ (r*1024) + (g*32) + b ] = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !wxUSE_NANOX
|
Reference in New Issue
Block a user