diff --git a/x11/inc/TGX11.h b/x11/inc/TGX11.h index fc3c92d4a3d6ac3e187bb373de2f4cb372600b90..cc61664465ad879fcfc69fd07e7cd0a994db13f6 100644 --- a/x11/inc/TGX11.h +++ b/x11/inc/TGX11.h @@ -1,4 +1,4 @@ -// @(#)root/x11:$Name: $:$Id: TGX11.h,v 1.8 2001/04/11 15:19:11 rdm Exp $ +// @(#)root/x11:$Name: $:$Id: TGX11.h,v 1.9 2001/05/11 17:20:14 rdm Exp $ // Author: Rene Brun, Olivier Couet, Fons Rademakers 28/11/94 /************************************************************************* @@ -133,6 +133,7 @@ protected: Int_t fBlueDiv; //Blue value divider Int_t fRedShift; //Bits to left shift red, -1 if no TrueColor visual Int_t fGreenShift; //Bits to left shift green + Int_t fBlueShift; //Bits to left shift blue // needed by TGX11TTF Bool_t AllocColor(Colormap cmap, XColor *color); diff --git a/x11/src/TGX11.cxx b/x11/src/TGX11.cxx index 8f2cff5ba728150a578a4478e6e5b74871fc1070..0411b8ae02c829b7ee82e5e5196cced34ba9bf77 100644 --- a/x11/src/TGX11.cxx +++ b/x11/src/TGX11.cxx @@ -1,4 +1,4 @@ -// @(#)root/x11:$Name: $:$Id: TGX11.cxx,v 1.5 2001/05/07 00:13:50 rdm Exp $ +// @(#)root/x11:$Name: $:$Id: TGX11.cxx,v 1.6 2001/05/11 17:20:14 rdm Exp $ // Author: Rene Brun, Olivier Couet, Fons Rademakers 28/11/94 /************************************************************************* @@ -312,6 +312,7 @@ TGX11::TGX11(const TGX11 &org) fBlueDiv = org.fBlueDiv; fRedShift = org.fRedShift; fGreenShift = org.fGreenShift; + fBlueShift = org.fBlueShift; fDrawMode = org.fDrawMode; fXEvent = new XEvent; @@ -382,7 +383,7 @@ Bool_t TGX11::AllocColor(Colormap cmap, XColor *color) } else { color->pixel = (color->red >> fRedDiv) << fRedShift | (color->green >> fGreenDiv) << fGreenShift | - (color->blue >> fBlueDiv); + (color->blue >> fBlueDiv) << fBlueShift; return kTRUE; } return kFALSE; @@ -405,8 +406,8 @@ void TGX11::QueryColors(Colormap cmap, XColor *color, Int_t ncolors) g = (color[i].pixel & vis->green_mask) >> fGreenShift; color[i].green = UShort_t(g*kBIGGEST_RGB_VALUE/(vis->green_mask >> fGreenShift)); - b = (color[i].pixel & vis->blue_mask); - color[i].blue = UShort_t(b*kBIGGEST_RGB_VALUE/vis->blue_mask); + b = (color[i].pixel & vis->blue_mask) >> fBlueShift; + color[i].blue = UShort_t(b*kBIGGEST_RGB_VALUE/(vis->blue_mask >> fBlueShift)); color[i].flags = DoRed | DoGreen | DoBlue; } @@ -1024,32 +1025,38 @@ Int_t TGX11::OpenDisplay(Display *disp) fCursors[kWatch] = XCreateFontCursor(fDisplay, XC_watch); // Setup color information - fRedDiv = fGreenDiv = fBlueDiv = fRedShift = fGreenShift = -1; + fRedDiv = fGreenDiv = fBlueDiv = fRedShift = fGreenShift = fBlueShift = -1; fDepth = DefaultDepth(fDisplay, fScreenNumber); Visual *vis = DefaultVisual(fDisplay, fScreenNumber); if (vis->c_class == TrueColor) { int i; - for (i = 0; i < int(sizeof(vis->blue_mask)*8); i++) + for (i = 0; i < int(sizeof(vis->blue_mask)*kBitsPerByte); i++) { + if (fBlueShift == -1 && ((vis->blue_mask >> i) & 1)) + fBlueShift = i; if ((vis->blue_mask >> i) == 1) { - fGreenShift = i + 1; - fBlueDiv = sizeof(UShort_t)*8 - fGreenShift; + fBlueDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fBlueShift; break; } - for (i = 0; i < int(sizeof(vis->green_mask)*8); i++) - if ((vis->green_mask >> (i+fGreenShift)) == 1) { - fRedShift = i + 1; - fGreenDiv = sizeof(UShort_t)*8 - fRedShift; - fRedShift += fGreenShift; + } + for (i = 0; i < int(sizeof(vis->green_mask)*kBitsPerByte); i++) { + if (fGreenShift == -1 && ((vis->green_mask >> i) & 1)) + fGreenShift = i; + if ((vis->green_mask >> i) == 1) { + fGreenDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fGreenShift; break; } - for (i = 0; i < int(sizeof(vis->red_mask)*8); i++) - if ((vis->red_mask >> (i+fRedShift)) == 1) { - fRedDiv = sizeof(UShort_t)*8 - (i+1); + } + for (i = 0; i < int(sizeof(vis->red_mask)*kBitsPerByte); i++) { + if (fRedShift == -1 && ((vis->red_mask >> i) & 1)) + fRedShift = i; + if ((vis->red_mask >> i) == 1) { + fRedDiv = sizeof(UShort_t)*kBitsPerByte - i - 1 + fRedShift; break; } - //printf("fRedDiv = %d, fGreenDiv = %d, fBlueDiv = %d, fRedShift = %d, fGreenShift = %d\n", - // fRedDiv, fGreenDiv, fBlueDiv, fRedShift, fGreenShift); + } + //printf("fRedDiv = %d, fGreenDiv = %d, fBlueDiv = %d, fRedShift = %d, fGreenShift = %d, fBlueShift = %d\n", + // fRedDiv, fGreenDiv, fBlueDiv, fRedShift, fGreenShift, fBlueShift); } return 0; diff --git a/x3d/inc/x3d.h b/x3d/inc/x3d.h index fa158b85aef75f6e971414071b3a356e348a6134..9b41d660043257391d7ec8c239b3012e495ff60e 100644 --- a/x3d/inc/x3d.h +++ b/x3d/inc/x3d.h @@ -1,4 +1,4 @@ -/* @(#)root/x3d:$Name: $:$Id: x3d.h,v 1.1.1.1 2000/05/16 17:00:45 rdm Exp $ */ +/* @(#)root/x3d:$Name: $:$Id: x3d.h,v 1.2 2001/05/08 18:11:04 rdm Exp $ */ /* Author: Mark Spychalla*/ /************************************************************************* @@ -116,9 +116,6 @@ #define ONE 1 #define EIGHT 8 -#define FIFTEEN 15 -#define SIXTEEN 16 -#define TWENTYFOUR 24 /* Double buffering constants */ diff --git a/x3d/src/x3d.c b/x3d/src/x3d.c index 0a3f15ecba9ff3bb45d7e02bd95d91f657e3c67e..3d049eed5c0b8116b7c0b79e546add843884a242 100644 --- a/x3d/src/x3d.c +++ b/x3d/src/x3d.c @@ -1,4 +1,4 @@ -/* @(#)root/x3d:$Name: $:$Id: x3d.c,v 1.4 2001/05/08 18:11:04 rdm Exp $ */ +/* @(#)root/x3d:$Name: $:$Id: x3d.c,v 1.5 2001/05/11 17:20:14 rdm Exp $ */ /* Author: Mark Spychalla*/ /* Copyright 1992 Mark Spychalla @@ -124,6 +124,8 @@ static Display *gDisplay = NULL; static Ginfo *gGInfo = NULL; static Oinfo *gOInfo = NULL; +static int gRedDiv, gGreenDiv, gBlueDiv, gRedShift, gGreenShift, gBlueShift; + static void sort(list, numPolys) @@ -862,52 +864,21 @@ XColor c; } -static void SixTeenBitSetColors(g) +static void TrueColorSetColors(g) Ginfo *g; /****************************************************************************** - Set up color information/stipples for a fifteen and sixteen bit displays. + Set up color information/stipples for TrueColor displays. ******************************************************************************/ { int index, colorValue; Color *colors; int numColors; - /* 15 and 16 bit true colors have 6 bits precision per color however - only the 5 most significant bits are used in the color index. - Except for 16 bits when green uses all 6 bits. I.e.: - 15 bits = rrrrrgggggbbbbb - 16 bits = rrrrrggggggbbbbb - - we calculate r, g and b with a max of 63 and then right shift by 1. - However in this case all colors are set with a max of 255 (8 bits) - so we just right shift them by 3, 2 and 3 bits respectively (and - 3, 3, 3 for 15 bits). - */ - - /* if this does not work for some reason, replace by more generic code as - in TGX11::OpenDisplay(). - */ - /* settings for 16 bit true color displays */ - int greenshift = 5; - int redshift = 6 + greenshift; - int reddiv = 3; - int greendiv = 2; - int bluediv = 3; - - /* correction for 15 bit true color displays */ - if (g->depth == 15) { - redshift = 5 + greenshift; - greendiv = 3; - } - - /* - { - XVisualInfo vInfo; - XMatchVisualInfo(g->dpy, DefaultScreen(g->dpy), g->depth, TrueColor, &vInfo); - printf("red_mask = %lu, green_mask = %lu, blue_mask = %lu," - " bit_per_rgb = %d\n", - vInfo.red_mask, vInfo.green_mask, vInfo.blue_mask, vInfo.bits_per_rgb); - } + /* On TrueColor displays the color pixel value composed directly of + r, g and b components. The order of the r, g and b and the number + of bits used for each color is specified by the X server and decoded + in the gRedShift, gRedDiv etc. values. Since X3D uses 255 as max + color the div is the number of bits to left shift (divide) from 255. */ colors = g->colors; @@ -915,66 +886,12 @@ int numColors; for(index = 0; index < numColors; index++){ -/* In 15/16 bit every color is what it is */ - - colors[index].value = - (colors[index].red >> reddiv) << redshift | - (colors[index].green >> greendiv) << greenshift | - (colors[index].blue >> bluediv); - -/* Set stipple */ - - colors[index].stipple =(int)((double)NUMSTIPPLES * - ((double)sqrt((double)( - (double)colors[index].red * (double)colors[index].red + - (double)colors[index].green * (double)colors[index].green + - (double)colors[index].blue * (double)colors[index].blue)) - / MAXCOLORDIST)); - -/* Set stereo color */ - - colorValue= (int)((double)31 * - ((double)sqrt((double)((double)colors[index].red * - (double)colors[index].red + (double)colors[index].green * - (double)colors[index].green + (double)colors[index].blue * - (double)colors[index].blue)) / MAXCOLORDIST)); - - colors[index].stereoColor = colorValue << redshift | colorValue; - } - -/* Set various important color values */ - - g->stereoBlack = 0; - g->redMask = 31 << redshift; - g->blueMask = 31; - g->Black = 0; - g->Red = 31 << redshift; - g->Blue = 31; - g->Purple = (31 << redshift) | 31; -} - - -static void TwentyFourBitSetColors(g) -Ginfo *g; -/****************************************************************************** - Set up color information/stipples for a twenty-four bit display. -******************************************************************************/ -{ -int index, colorValue; -Color *colors; -int numColors; - - colors = g->colors; - numColors = g->numColors; - - for(index = 0; index < numColors; index++){ - -/* In 24 bit every color is what it is */ +/* In TrueColor every color is what it is */ colors[index].value = - colors[index].red << 16 | - colors[index].green << 8 | - colors[index].blue; + (colors[index].red >> gRedDiv) << gRedShift | + (colors[index].green >> gGreenDiv) << gGreenShift | + (colors[index].blue >> gBlueDiv) << gBlueShift; /* Set stipple */ @@ -987,24 +904,25 @@ int numColors; /* Set stereo color */ - colorValue= (int)((double)255 * + colorValue= (int)((double)(255 >> gRedDiv) * ((double)sqrt((double)((double)colors[index].red * (double)colors[index].red + (double)colors[index].green * (double)colors[index].green + (double)colors[index].blue * (double)colors[index].blue)) / MAXCOLORDIST)); - colors[index].stereoColor = colorValue << 16 | colorValue; + colors[index].stereoColor = (colorValue << gRedShift) | + (colorValue << gBlueShift); } /* Set various important color values */ g->stereoBlack = 0; - g->redMask = 255 << 16; - g->blueMask = 255; + g->redMask = (255 >> gRedDiv) << gRedShift; + g->blueMask = (255 >> gBlueDiv) << gBlueShift; g->Black = 0; - g->Red = 255 << 16; - g->Blue = 255; - g->Purple = (255 << 16) | 255; + g->Red = (255 >> gRedDiv) << gRedShift; + g->Blue = (255 >> gBlueDiv) << gBlueShift; + g->Purple = g->Red | g->Blue; } @@ -1052,7 +970,7 @@ XWindowAttributes attributes; XSetWindowAttributes attribs; XWMHints wmhint; int index, index2, screen; -XVisualInfo vInfo; +Visual *vis; XSizeHints sizehint; int x, y, NUMCOLORS; unsigned int width, height, numSegments; @@ -1133,24 +1051,42 @@ int useroot = 0; /* Which visual do we get? */ - g->depth = ONE; - - if(XMatchVisualInfo(g->dpy, screen, 8, GrayScale, &vInfo)){ -/* An 8 bit GrayScale ? */ - g->depth = EIGHT; - }else if(XMatchVisualInfo(g->dpy, screen, 8, PseudoColor, &vInfo)){ -/* An 8 bit PseudoColor ? */ + gRedDiv = gGreenDiv = gBlueDiv = gRedShift = gGreenShift = gBlueShift = -1; + g->depth = DefaultDepth(g->dpy, screen); + + vis = DefaultVisual(g->dpy, screen); + if (g->depth > EIGHT && vis->class == TrueColor) { + int i; + for (i = 0; i < (int)sizeof(vis->blue_mask)*8; i++) { + if (gBlueShift == -1 && ((vis->blue_mask >> i) & 1)) + gBlueShift = i; + if ((vis->blue_mask >> i) == 1) { + gBlueDiv = 8 - i - 1 + gBlueShift; /* max value is 255, i.e. 8 bits */ + break; + } + } + for (i = 0; i < (int)sizeof(vis->green_mask)*8; i++) { + if (gGreenShift == -1 && ((vis->green_mask >> i) & 1)) + gGreenShift = i; + if ((vis->green_mask >> i) == 1) { + gGreenDiv = 8 - i - 1 + gGreenShift; + break; + } + } + for (i = 0; i < (int)sizeof(vis->red_mask)*8; i++) { + if (gRedShift == -1 && ((vis->red_mask >> i) & 1)) + gRedShift = i; + if ((vis->red_mask >> i) == 1) { + gRedDiv = 8 - i - 1 + gRedShift; + break; + } + } + /* + printf("gRedDiv = %d, gGreenDiv = %d, gBlueDiv = %d, gRedShift = %d, gGreenShift = %d, gBlueShift = %d\n", + gRedDiv, gGreenDiv, gBlueDiv, gRedShift, gGreenShift, gBlueShift); + */ + } else if (g->depth > EIGHT) g->depth = EIGHT; - }else if(XMatchVisualInfo(g->dpy, screen, 15, TrueColor, &vInfo)){ -/* An 15 bit TrueColor ? */ - g->depth = FIFTEEN; - }else if(XMatchVisualInfo(g->dpy, screen, 16, TrueColor, &vInfo)){ -/* An 16 bit TrueColor ? */ - g->depth = SIXTEEN; - }else if(XMatchVisualInfo(g->dpy, screen, 24, TrueColor, &vInfo)){ -/* A 24 bit TrueColor ? */ - g->depth = TWENTYFOUR; - } g->pix = XCreatePixmap(g->dpy, RootWindow(g->dpy,screen), g->winX, g->winY, g->depth); @@ -1273,12 +1209,8 @@ int useroot = 0; OneBitSetColors(g); } - if(g->depth == FIFTEEN || g->depth == SIXTEEN){ - SixTeenBitSetColors(g); - } - - if(g->depth == TWENTYFOUR){ - TwentyFourBitSetColors(g); + if(g->depth > EIGHT){ + TrueColorSetColors(g); } if(g->depth == EIGHT){