Some work for wxX11 on 8-bit visuals.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14867 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-03-29 22:58:15 +00:00
parent b33c8d22cc
commit dc4025af9a
4 changed files with 192 additions and 151 deletions

View File

@@ -30,6 +30,8 @@
#include "wx/univ/theme.h"
#include "wx/univ/renderer.h"
#define ABS(a) (((a) < 0) ? -(a) : (a))
#if wxUSE_THREADS
#include "wx/thread.h"
#endif
@@ -396,6 +398,18 @@ wxApp::wxApp()
m_mainLoop = NULL;
m_showIconic = FALSE;
m_initialSize = wxDefaultSize;
m_visualColormap = NULL;
m_colorCube = NULL;
}
wxApp::~wxApp()
{
if (m_colorCube)
free( m_colorCube );
if (m_visualColormap)
delete [] (XColor*)m_visualColormap;
}
bool wxApp::Initialized()
@@ -940,6 +954,24 @@ 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
bool wxApp::OnInitGui()
{
@@ -949,12 +981,106 @@ bool wxApp::OnInitGui()
delete wxLog::SetActiveTarget(new wxLogStderr);
if (!wxAppBase::OnInitGui())
return FALSE;
return FALSE;
GetMainColormap( wxApp::GetDisplay() );
m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
// Get info about the current visual. It is enough
// to do this once here unless we support different
// 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;
}
}
}
return TRUE;
}