uint QGLContext::colorIndex( const QColor& c ) const { if ( isValid() ) { if ( format().plane() && c.pixel() == overlayTransparentColor().pixel() ) return c.pixel(); // Special; don't look-up if ( ((XVisualInfo*)vi)->visualid == XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual() ) ) return c.pixel(); // We're using QColor's cmap CMapEntry *x = cmap_dict->find( (long)((XVisualInfo*)vi)->visualid ); if ( x && !x->alloc) { // It's a standard colormap int rf = (int)(((float)c.red() * (x->scmap.red_max+1))/256.0); int gf = (int)(((float)c.green() * (x->scmap.green_max+1))/256.0); int bf = (int)(((float)c.blue() * (x->scmap.blue_max+1))/256.0); uint p = x->scmap.base_pixel + ( rf * x->scmap.red_mult ) + ( gf * x->scmap.green_mult ) + ( bf * x->scmap.blue_mult ); return p; } else return c.pixel(); // ### wrong; should really ask QColor to alloc } return 0; }
uint QGLContext::colorIndex( const QColor& c ) const { int screen = ((XVisualInfo *)vi)->screen; if ( isValid() ) { if ( format().plane() && c.pixel( screen ) == overlayTransparentColor().pixel( screen ) ) return c.pixel( screen ); // Special; don't look-up if ( ((XVisualInfo*)vi)->visualid == XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual( screen ) ) ) return c.pixel( screen ); // We're using QColor's cmap XVisualInfo *info = (XVisualInfo *) vi; CMapEntry *x = cmap_dict->find( (long) info->visualid + ( info->screen * 256 ) ); if ( x && !x->alloc) { // It's a standard colormap int rf = (int)(((float)c.red() * (x->scmap.red_max+1))/256.0); int gf = (int)(((float)c.green() * (x->scmap.green_max+1))/256.0); int bf = (int)(((float)c.blue() * (x->scmap.blue_max+1))/256.0); uint p = x->scmap.base_pixel + ( rf * x->scmap.red_mult ) + ( gf * x->scmap.green_mult ) + ( bf * x->scmap.blue_mult ); return p; } else { if (!qglcmap_dict) { qglcmap_dict = new QIntDict< QMap<int, QRgb> >; } QMap<int, QRgb> *cmap; if ((cmap = qglcmap_dict->find((long) info->visualid)) == 0) { cmap = new QMap<int, QRgb>; qglcmap_dict->insert((long) info->visualid, cmap); } // already in the map? QRgb target = c.rgb(); QMap<int, QRgb>::Iterator it = cmap->begin(); for (; it != cmap->end(); ++it) { if ((*it) == target) return it.key(); } // need to alloc color unsigned long plane_mask[2]; unsigned long color_map_entry; if (!XAllocColorCells (QPaintDevice::x11AppDisplay(), x->cmap, TRUE, plane_mask, 0, &color_map_entry, 1)) return c.pixel(screen); XColor col; col.flags = DoRed | DoGreen | DoBlue; col.pixel = color_map_entry; col.red = (ushort)((qRed(c.rgb()) / 255.0) * 65535.0 + 0.5); col.green = (ushort)((qGreen(c.rgb()) / 255.0) * 65535.0 + 0.5); col.blue = (ushort)((qBlue(c.rgb()) / 255.0) * 65535.0 + 0.5); XStoreColor(QPaintDevice::x11AppDisplay(), x->cmap, &col); cmap->insert(color_map_entry, target); return color_map_entry; } } return 0; }