applied fix for 8 bit displays (already in the 2.2 branch since almost a year)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-09-28 14:41:07 +00:00
parent bed118ca9e
commit d13fd3e468
2 changed files with 108 additions and 46 deletions

View File

@@ -29,6 +29,7 @@ public:
~wxColourRefData(); ~wxColourRefData();
void FreeColour(); void FreeColour();
void AllocColour( GdkColormap* cmap );
public: public:
GdkColor m_color; GdkColor m_color;
@@ -36,6 +37,26 @@ public:
bool m_hasPixel; bool m_hasPixel;
friend class wxColour; friend class wxColour;
// reference counter for systems with <= 8-Bit display
static gushort colMapAllocCounter[ 256 ];
};
gushort wxColourRefData::colMapAllocCounter[ 256 ] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };
wxColourRefData::wxColourRefData() wxColourRefData::wxColourRefData()
@@ -66,13 +87,42 @@ void wxColourRefData::FreeColour()
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif #endif
{ {
// What happens if the colour has not been allocated int idx = m_color.pixel;
// anew but has been found? RR. colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
if (colMapAllocCounter[ idx ] == 0)
gdk_colormap_free_colors( m_colormap, &m_color, 1 ); gdk_colormap_free_colors( m_colormap, &m_color, 1 );
} }
} }
} }
void wxColourRefData::AllocColour( GdkColormap *cmap )
{
if (m_hasPixel && (m_colormap == cmap))
return;
FreeColour();
#ifdef __WXGTK20__
if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#else
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif
{
m_hasPixel = gdk_colormap_alloc_color( cmap, &m_color, FALSE, TRUE );
int idx = m_color.pixel;
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1;
}
else
{
m_hasPixel = gdk_color_alloc( cmap, &m_color );
}
m_colormap = cmap;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#define M_COLDATA ((wxColourRefData *)m_refData) #define M_COLDATA ((wxColourRefData *)m_refData)
@@ -83,6 +133,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
wxColour::wxColour() wxColour::wxColour()
{ {
m_refData = new wxColourRefData();
} }
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue ) wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
@@ -200,27 +251,7 @@ void wxColour::CalcPixel( GdkColormap *cmap )
{ {
if (!Ok()) return; if (!Ok()) return;
if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return; M_COLDATA->AllocColour( cmap );
M_COLDATA->FreeColour();
#ifdef __WXGTK20__
if ((cmap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(cmap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#else
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif
{
M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE );
}
else
{
M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
}
M_COLDATA->m_colormap = cmap;
} }
int wxColour::GetPixel() const int wxColour::GetPixel() const

View File

@@ -29,6 +29,7 @@ public:
~wxColourRefData(); ~wxColourRefData();
void FreeColour(); void FreeColour();
void AllocColour( GdkColormap* cmap );
public: public:
GdkColor m_color; GdkColor m_color;
@@ -36,6 +37,26 @@ public:
bool m_hasPixel; bool m_hasPixel;
friend class wxColour; friend class wxColour;
// reference counter for systems with <= 8-Bit display
static gushort colMapAllocCounter[ 256 ];
};
gushort wxColourRefData::colMapAllocCounter[ 256 ] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };
wxColourRefData::wxColourRefData() wxColourRefData::wxColourRefData()
@@ -66,13 +87,42 @@ void wxColourRefData::FreeColour()
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif #endif
{ {
// What happens if the colour has not been allocated int idx = m_color.pixel;
// anew but has been found? RR. colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
if (colMapAllocCounter[ idx ] == 0)
gdk_colormap_free_colors( m_colormap, &m_color, 1 ); gdk_colormap_free_colors( m_colormap, &m_color, 1 );
} }
} }
} }
void wxColourRefData::AllocColour( GdkColormap *cmap )
{
if (m_hasPixel && (m_colormap == cmap))
return;
FreeColour();
#ifdef __WXGTK20__
if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#else
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif
{
m_hasPixel = gdk_colormap_alloc_color( cmap, &m_color, FALSE, TRUE );
int idx = m_color.pixel;
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1;
}
else
{
m_hasPixel = gdk_color_alloc( cmap, &m_color );
}
m_colormap = cmap;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#define M_COLDATA ((wxColourRefData *)m_refData) #define M_COLDATA ((wxColourRefData *)m_refData)
@@ -83,6 +133,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
wxColour::wxColour() wxColour::wxColour()
{ {
m_refData = new wxColourRefData();
} }
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue ) wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
@@ -200,27 +251,7 @@ void wxColour::CalcPixel( GdkColormap *cmap )
{ {
if (!Ok()) return; if (!Ok()) return;
if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap)) return; M_COLDATA->AllocColour( cmap );
M_COLDATA->FreeColour();
#ifdef __WXGTK20__
if ((cmap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(cmap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#else
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
#endif
{
M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE );
}
else
{
M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
}
M_COLDATA->m_colormap = cmap;
} }
int wxColour::GetPixel() const int wxColour::GetPixel() const