wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
5.81k stars 1.71k forks source link

Colours on 8-Bit displays ar eoften wrong #19461

Closed wxtrac closed 2 years ago

wxtrac commented 23 years ago

Issue migrated from trac ticket # 96

component: wxGTK | priority: normal

2000-12-14 10:11:23: benndorf created the issue


we are using the GTK port of wxWindows on Solaris and Linux. We observed that our application uses different colours on differents machines, especially on 8-Bit-Grafik machines.

After digging a bit in the wxWindows code i found (in src/gtk/colour.cpp) that wxGTK on 8-Bit-Grafic displays searches only the already existing colortable, but do not allocate a new color if the color is not already existing. For a lot of cases there are still colors available and thus a new color could be allocated.

I've changed the file src/gtk/colour.cpp, more exactly the wxColour::CalcPixel method and the wxColourRefData::FreeColour method to allocate a new color and free it again later. I've tested it a bit on Solaris 8 and 24 Bit grafic machines and on Linux and it seems to work.

Best regards

Kai

My changes:

NEW: void wxColourRefData::FreeColour() { if( m_colormap ) { GdkColormapPrivate private_colormap = (GdkColormapPrivate) m_colormap; if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) || (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) { gdk_colormap_free_colors( m_colormap, &m_color, 1 ); } } } OLD: void wxColourRefData::FreeColour() { // if (m_hasPixel) gdk_colors_free( m_colormap, &m_color, 1, 0 ); }

NEW: void wxColour::CalcPixel( GdkColormap *cmap ) { if (!Ok()) return;

if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap))

return;

M_COLDATA->FreeColour();

GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
    (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
  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;

} OLD: void wxColour::CalcPixel( GdkColormap *cmap ) { if (!Ok()) return;

if ((M_COLDATA->m_hasPixel) && (M_COLDATA->m_colormap == cmap))

return;

M_COLDATA->FreeColour();

GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
    (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
    GdkColor *colors = cmap->colors;
    int max = 3 * (65536);
    int index = -1;

    for (int i = 0; i < cmap->size; i++)
    {
        int rdiff = (M_COLDATA->m_color.red - colors[i].red);
        int gdiff = (M_COLDATA->m_color.green - colors[i].green);
        int bdiff = (M_COLDATA->m_color.blue - colors[i].blue);
        int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
        if (sum < max) { index # i; maxsum; }
    }

    M_COLDATA->m_hasPixel = TRUE;
    M_COLDATA->m_color.pixel = index;
}
else
{ 
    M_COLDATA->m_hasPixel = gdk_color_alloc( cmap,

&M_COLDATA->m_color ); }

M_COLDATA->m_colormap = cmap;

}

--

Dipl.-Inf. Kai Benndorf mailto:benndorf@pb.izm.fhg.de Fraunhofer Gesellschaft URL:http://www.pb.izm.fhg.de Institut Zuverlässigkeit und Mikrointegration PHONE: (++49) 5251 60-6165 Fürstenallee 11 HOME: (++49) 5261 14465 33102 Paderborn FAX: (++49) 5251 60-6155 Germany

wxtrac commented 23 years ago

2000-12-16 12:01:31: roebling (Robert Roebling) commented


Applied, not sure if this is safe when no colours are found.