summaryrefslogtreecommitdiff
path: root/hw/xnest/Color.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-03-21 12:55:09 -0700
committerKeith Packard <keithp@keithp.com>2012-03-21 13:54:42 -0700
commit9838b7032ea9792bec21af424c53c07078636d21 (patch)
treeb72d0827dac50f0f3b8eab29b3b7639546d735d7 /hw/xnest/Color.c
parent75199129c603fc8567185ac31866c9518193cb78 (diff)
Introduce a consistent coding style
This is strictly the application of the script 'x-indent-all.sh' from util/modular. Compared to the patch that Daniel posted in January, I've added a few indent flags: -bap -psl -T PrivatePtr -T pmWait -T _XFUNCPROTOBEGIN -T _XFUNCPROTOEND -T _X_EXPORT The typedefs were needed to make the output of sdksyms.sh match the previous output, otherwise, the code is formatted badly enough that sdksyms.sh generates incorrect output. The generated code was compared with the previous version and found to be essentially identical -- "assert" line numbers and BUILD_TIME were the only differences found. The comparison was done with this script: dir1=$1 dir2=$2 for dir in $dir1 $dir2; do (cd $dir && find . -name '*.o' | while read file; do dir=`dirname $file` base=`basename $file .o` dump=$dir/$base.dump objdump -d $file > $dump done) done find $dir1 -name '*.dump' | while read dump; do otherdump=`echo $dump | sed "s;$dir1;$dir2;"` diff -u $dump $otherdump done Signed-off-by: Keith Packard <keithp@keithp.com> Acked-by: Daniel Stone <daniel@fooishbar.org> Acked-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'hw/xnest/Color.c')
-rw-r--r--hw/xnest/Color.c676
1 files changed, 337 insertions, 339 deletions
diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c
index 0aae8e9c9..7ef137d59 100644
--- a/hw/xnest/Color.c
+++ b/hw/xnest/Color.c
@@ -26,7 +26,6 @@ is" without express or implied warranty.
#include "Xnest.h"
-
#include "Display.h"
#include "Screen.h"
#include "Color.h"
@@ -37,6 +36,7 @@ is" without express or implied warranty.
DevPrivateKeyRec xnestColormapPrivateKeyRec;
static DevPrivateKeyRec cmapScrPrivateKeyRec;
+
#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
@@ -45,91 +45,92 @@ static DevPrivateKeyRec cmapScrPrivateKeyRec;
Bool
xnestCreateColormap(ColormapPtr pCmap)
{
- VisualPtr pVisual;
- XColor *colors;
- int i, ncolors;
- Pixel red, green, blue;
- Pixel redInc, greenInc, blueInc;
-
- pVisual = pCmap->pVisual;
- ncolors = pVisual->ColormapEntries;
-
- xnestColormapPriv(pCmap)->colormap =
- XCreateColormap(xnestDisplay,
- xnestDefaultWindows[pCmap->pScreen->myNum],
- xnestVisual(pVisual),
- (pVisual->class & DynamicClass) ?
- AllocAll : AllocNone);
-
-
- switch (pVisual->class) {
- case StaticGray: /* read only */
- colors = (XColor *)malloc(ncolors * sizeof(XColor));
- for (i = 0; i < ncolors; i++)
- colors[i].pixel = i;
- XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
- for (i = 0; i < ncolors; i++) {
- pCmap->red[i].co.local.red = colors[i].red;
- pCmap->red[i].co.local.green = colors[i].red;
- pCmap->red[i].co.local.blue = colors[i].red;
- }
- free(colors);
- break;
-
- case StaticColor: /* read only */
- colors = (XColor *)malloc(ncolors * sizeof(XColor));
- for (i = 0; i < ncolors; i++)
- colors[i].pixel = i;
- XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
- for (i = 0; i < ncolors; i++) {
- pCmap->red[i].co.local.red = colors[i].red;
- pCmap->red[i].co.local.green = colors[i].green;
- pCmap->red[i].co.local.blue = colors[i].blue;
- }
- free(colors);
- break;
-
- case TrueColor: /* read only */
- colors = (XColor *)malloc(ncolors * sizeof(XColor));
- red = green = blue = 0L;
- redInc = lowbit(pVisual->redMask);
- greenInc = lowbit(pVisual->greenMask);
- blueInc = lowbit(pVisual->blueMask);
- for (i = 0; i < ncolors; i++) {
- colors[i].pixel = red | green | blue;
- red += redInc;
- if (red > pVisual->redMask) red = 0L;
- green += greenInc;
- if (green > pVisual->greenMask) green = 0L;
- blue += blueInc;
- if (blue > pVisual->blueMask) blue = 0L;
- }
- XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
- for (i = 0; i < ncolors; i++) {
- pCmap->red[i].co.local.red = colors[i].red;
- pCmap->green[i].co.local.green = colors[i].green;
- pCmap->blue[i].co.local.blue = colors[i].blue;
+ VisualPtr pVisual;
+ XColor *colors;
+ int i, ncolors;
+ Pixel red, green, blue;
+ Pixel redInc, greenInc, blueInc;
+
+ pVisual = pCmap->pVisual;
+ ncolors = pVisual->ColormapEntries;
+
+ xnestColormapPriv(pCmap)->colormap =
+ XCreateColormap(xnestDisplay,
+ xnestDefaultWindows[pCmap->pScreen->myNum],
+ xnestVisual(pVisual),
+ (pVisual->class & DynamicClass) ? AllocAll : AllocNone);
+
+ switch (pVisual->class) {
+ case StaticGray: /* read only */
+ colors = (XColor *) malloc(ncolors * sizeof(XColor));
+ for (i = 0; i < ncolors; i++)
+ colors[i].pixel = i;
+ XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
+ for (i = 0; i < ncolors; i++) {
+ pCmap->red[i].co.local.red = colors[i].red;
+ pCmap->red[i].co.local.green = colors[i].red;
+ pCmap->red[i].co.local.blue = colors[i].red;
+ }
+ free(colors);
+ break;
+
+ case StaticColor: /* read only */
+ colors = (XColor *) malloc(ncolors * sizeof(XColor));
+ for (i = 0; i < ncolors; i++)
+ colors[i].pixel = i;
+ XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
+ for (i = 0; i < ncolors; i++) {
+ pCmap->red[i].co.local.red = colors[i].red;
+ pCmap->red[i].co.local.green = colors[i].green;
+ pCmap->red[i].co.local.blue = colors[i].blue;
+ }
+ free(colors);
+ break;
+
+ case TrueColor: /* read only */
+ colors = (XColor *) malloc(ncolors * sizeof(XColor));
+ red = green = blue = 0L;
+ redInc = lowbit(pVisual->redMask);
+ greenInc = lowbit(pVisual->greenMask);
+ blueInc = lowbit(pVisual->blueMask);
+ for (i = 0; i < ncolors; i++) {
+ colors[i].pixel = red | green | blue;
+ red += redInc;
+ if (red > pVisual->redMask)
+ red = 0L;
+ green += greenInc;
+ if (green > pVisual->greenMask)
+ green = 0L;
+ blue += blueInc;
+ if (blue > pVisual->blueMask)
+ blue = 0L;
+ }
+ XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
+ for (i = 0; i < ncolors; i++) {
+ pCmap->red[i].co.local.red = colors[i].red;
+ pCmap->green[i].co.local.green = colors[i].green;
+ pCmap->blue[i].co.local.blue = colors[i].blue;
+ }
+ free(colors);
+ break;
+
+ case GrayScale: /* read and write */
+ break;
+
+ case PseudoColor: /* read and write */
+ break;
+
+ case DirectColor: /* read and write */
+ break;
}
- free(colors);
- break;
-
- case GrayScale: /* read and write */
- break;
-
- case PseudoColor: /* read and write */
- break;
-
- case DirectColor: /* read and write */
- break;
- }
-
- return True;
+
+ return True;
}
void
xnestDestroyColormap(ColormapPtr pCmap)
{
- XFreeColormap(xnestDisplay, xnestColormap(pCmap));
+ XFreeColormap(xnestDisplay, xnestColormap(pCmap));
}
#define SEARCH_PREDICATE \
@@ -138,31 +139,31 @@ xnestDestroyColormap(ColormapPtr pCmap)
static int
xnestCountInstalledColormapWindows(WindowPtr pWin, pointer ptr)
{
- xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr;
- int i;
-
- for (i = 0; i < icws->numCmapIDs; i++)
- if (SEARCH_PREDICATE) {
- icws->numWindows++;
- return WT_DONTWALKCHILDREN;
- }
-
- return WT_WALKCHILDREN;
+ xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *) ptr;
+ int i;
+
+ for (i = 0; i < icws->numCmapIDs; i++)
+ if (SEARCH_PREDICATE) {
+ icws->numWindows++;
+ return WT_DONTWALKCHILDREN;
+ }
+
+ return WT_WALKCHILDREN;
}
static int
xnestGetInstalledColormapWindows(WindowPtr pWin, pointer ptr)
{
- xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *)ptr;
- int i;
-
- for (i = 0; i < icws->numCmapIDs; i++)
- if (SEARCH_PREDICATE) {
- icws->windows[icws->index++] = xnestWindow(pWin);
- return WT_DONTWALKCHILDREN;
- }
-
- return WT_WALKCHILDREN;
+ xnestInstalledColormapWindows *icws = (xnestInstalledColormapWindows *) ptr;
+ int i;
+
+ for (i = 0; i < icws->numCmapIDs; i++)
+ if (SEARCH_PREDICATE) {
+ icws->windows[icws->index++] = xnestWindow(pWin);
+ return WT_DONTWALKCHILDREN;
+ }
+
+ return WT_WALKCHILDREN;
}
static Window *xnestOldInstalledColormapWindows = NULL;
@@ -171,200 +172,203 @@ static int xnestNumOldInstalledColormapWindows = 0;
static Bool
xnestSameInstalledColormapWindows(Window *windows, int numWindows)
{
- if (xnestNumOldInstalledColormapWindows != numWindows)
- return False;
+ if (xnestNumOldInstalledColormapWindows != numWindows)
+ return False;
- if (xnestOldInstalledColormapWindows == windows)
- return True;
+ if (xnestOldInstalledColormapWindows == windows)
+ return True;
- if (xnestOldInstalledColormapWindows == NULL || windows == NULL)
- return False;
+ if (xnestOldInstalledColormapWindows == NULL || windows == NULL)
+ return False;
- if (memcmp(xnestOldInstalledColormapWindows, windows,
- numWindows * sizeof(Window)))
- return False;
+ if (memcmp(xnestOldInstalledColormapWindows, windows,
+ numWindows * sizeof(Window)))
+ return False;
- return True;
+ return True;
}
void
xnestSetInstalledColormapWindows(ScreenPtr pScreen)
{
- xnestInstalledColormapWindows icws;
- int numWindows;
-
- icws.cmapIDs = (Colormap *)malloc(pScreen->maxInstalledCmaps *
- sizeof(Colormap));
- icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
- icws.numWindows = 0;
- WalkTree(pScreen, xnestCountInstalledColormapWindows, (pointer)&icws);
- if (icws.numWindows) {
- icws.windows = (Window *)malloc((icws.numWindows + 1) * sizeof(Window));
- icws.index = 0;
- WalkTree(pScreen, xnestGetInstalledColormapWindows, (pointer)&icws);
- icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum];
- numWindows = icws.numWindows + 1;
- }
- else {
- icws.windows = NULL;
- numWindows = 0;
- }
-
- free(icws.cmapIDs);
-
- if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
- free(xnestOldInstalledColormapWindows);
+ xnestInstalledColormapWindows icws;
+ int numWindows;
+
+ icws.cmapIDs = (Colormap *) malloc(pScreen->maxInstalledCmaps *
+ sizeof(Colormap));
+ icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
+ icws.numWindows = 0;
+ WalkTree(pScreen, xnestCountInstalledColormapWindows, (pointer) &icws);
+ if (icws.numWindows) {
+ icws.windows =
+ (Window *) malloc((icws.numWindows + 1) * sizeof(Window));
+ icws.index = 0;
+ WalkTree(pScreen, xnestGetInstalledColormapWindows, (pointer) &icws);
+ icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum];
+ numWindows = icws.numWindows + 1;
+ }
+ else {
+ icws.windows = NULL;
+ numWindows = 0;
+ }
+
+ free(icws.cmapIDs);
+
+ if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
+ free(xnestOldInstalledColormapWindows);
#ifdef _XSERVER64
- {
- int i;
- Window64 *windows = (Window64 *)malloc(numWindows * sizeof(Window64));
-
- for(i = 0; i < numWindows; ++i)
- windows[i] = icws.windows[i];
- XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
- windows, numWindows);
- free(windows);
- }
+ {
+ int i;
+ Window64 *windows =
+ (Window64 *) malloc(numWindows * sizeof(Window64));
+
+ for (i = 0; i < numWindows; ++i)
+ windows[i] = icws.windows[i];
+ XSetWMColormapWindows(xnestDisplay,
+ xnestDefaultWindows[pScreen->myNum], windows,
+ numWindows);
+ free(windows);
+ }
#else
- XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
- icws.windows, numWindows);
+ XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
+ icws.windows, numWindows);
#endif
- xnestOldInstalledColormapWindows = icws.windows;
- xnestNumOldInstalledColormapWindows = icws.numWindows;
+ xnestOldInstalledColormapWindows = icws.windows;
+ xnestNumOldInstalledColormapWindows = icws.numWindows;
#ifdef DUMB_WINDOW_MANAGERS
- /*
- This code is for dumb window managers.
- This will only work with default local visual colormaps.
- */
- if (icws.numWindows)
- {
- WindowPtr pWin;
- Visual *visual;
- ColormapPtr pCmap;
-
- pWin = xnestWindowPtr(icws.windows[0]);
- visual = xnestVisualFromID(pScreen, wVisual(pWin));
-
- if (visual == xnestDefaultVisual(pScreen))
- dixLookupResourceByType((pointer *)&pCmap, wColormap(pWin),
- RT_COLORMAP, serverClient, DixUseAccess);
- else
- dixLookupResourceByType((pointer *)&pCmap, pScreen->defColormap,
- RT_COLORMAP, serverClient, DixUseAccess);
-
- XSetWindowColormap(xnestDisplay,
- xnestDefaultWindows[pScreen->myNum],
- xnestColormap(pCmap));
- }
-#endif /* DUMB_WINDOW_MANAGERS */
- }
- else
- free(icws.windows);
+ /*
+ This code is for dumb window managers.
+ This will only work with default local visual colormaps.
+ */
+ if (icws.numWindows) {
+ WindowPtr pWin;
+ Visual *visual;
+ ColormapPtr pCmap;
+
+ pWin = xnestWindowPtr(icws.windows[0]);
+ visual = xnestVisualFromID(pScreen, wVisual(pWin));
+
+ if (visual == xnestDefaultVisual(pScreen))
+ dixLookupResourceByType((pointer *) &pCmap, wColormap(pWin),
+ RT_COLORMAP, serverClient,
+ DixUseAccess);
+ else
+ dixLookupResourceByType((pointer *) &pCmap,
+ pScreen->defColormap, RT_COLORMAP,
+ serverClient, DixUseAccess);
+
+ XSetWindowColormap(xnestDisplay,
+ xnestDefaultWindows[pScreen->myNum],
+ xnestColormap(pCmap));
+ }
+#endif /* DUMB_WINDOW_MANAGERS */
+ }
+ else
+ free(icws.windows);
}
void
xnestSetScreenSaverColormapWindow(ScreenPtr pScreen)
{
- free(xnestOldInstalledColormapWindows);
-
+ free(xnestOldInstalledColormapWindows);
+
#ifdef _XSERVER64
- {
- Window64 window;
+ {
+ Window64 window;
- window = xnestScreenSaverWindows[pScreen->myNum];
- XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
- &window, 1);
- xnestScreenSaverWindows[pScreen->myNum] = window;
- }
+ window = xnestScreenSaverWindows[pScreen->myNum];
+ XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
+ &window, 1);
+ xnestScreenSaverWindows[pScreen->myNum] = window;
+ }
#else
- XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
- &xnestScreenSaverWindows[pScreen->myNum], 1);
-#endif /* _XSERVER64 */
-
- xnestOldInstalledColormapWindows = NULL;
- xnestNumOldInstalledColormapWindows = 0;
-
- xnestDirectUninstallColormaps(pScreen);
+ XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum],
+ &xnestScreenSaverWindows[pScreen->myNum], 1);
+#endif /* _XSERVER64 */
+
+ xnestOldInstalledColormapWindows = NULL;
+ xnestNumOldInstalledColormapWindows = 0;
+
+ xnestDirectUninstallColormaps(pScreen);
}
void
xnestDirectInstallColormaps(ScreenPtr pScreen)
{
- int i, n;
- Colormap pCmapIDs[MAXCMAPS];
-
- if (!xnestDoDirectColormaps) return;
+ int i, n;
+ Colormap pCmapIDs[MAXCMAPS];
- n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs);
+ if (!xnestDoDirectColormaps)
+ return;
- for (i = 0; i < n; i++) {
- ColormapPtr pCmap;
-
- dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP,
- serverClient, DixInstallAccess);
- if (pCmap)
- XInstallColormap(xnestDisplay, xnestColormap(pCmap));
- }
+ n = (*pScreen->ListInstalledColormaps) (pScreen, pCmapIDs);
+
+ for (i = 0; i < n; i++) {
+ ColormapPtr pCmap;
+
+ dixLookupResourceByType((pointer *) &pCmap, pCmapIDs[i], RT_COLORMAP,
+ serverClient, DixInstallAccess);
+ if (pCmap)
+ XInstallColormap(xnestDisplay, xnestColormap(pCmap));
+ }
}
void
xnestDirectUninstallColormaps(ScreenPtr pScreen)
{
- int i, n;
- Colormap pCmapIDs[MAXCMAPS];
+ int i, n;
+ Colormap pCmapIDs[MAXCMAPS];
- if (!xnestDoDirectColormaps) return;
+ if (!xnestDoDirectColormaps)
+ return;
- n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs);
+ n = (*pScreen->ListInstalledColormaps) (pScreen, pCmapIDs);
- for (i = 0; i < n; i++) {
- ColormapPtr pCmap;
-
- dixLookupResourceByType((pointer *)&pCmap, pCmapIDs[i], RT_COLORMAP,
- serverClient, DixUninstallAccess);
- if (pCmap)
- XUninstallColormap(xnestDisplay, xnestColormap(pCmap));
- }
+ for (i = 0; i < n; i++) {
+ ColormapPtr pCmap;
+
+ dixLookupResourceByType((pointer *) &pCmap, pCmapIDs[i], RT_COLORMAP,
+ serverClient, DixUninstallAccess);
+ if (pCmap)
+ XUninstallColormap(xnestDisplay, xnestColormap(pCmap));
+ }
}
void
xnestInstallColormap(ColormapPtr pCmap)
{
- ColormapPtr pOldCmap = GetInstalledColormap(pCmap->pScreen);
-
- if(pCmap != pOldCmap)
- {
- xnestDirectUninstallColormaps(pCmap->pScreen);
-
- /* Uninstall pInstalledMap. Notify all interested parties. */
- if(pOldCmap != (ColormapPtr)None)
- WalkTree(pCmap->pScreen, TellLostMap, (pointer)&pOldCmap->mid);
-
- SetInstalledColormap(pCmap->pScreen, pCmap);
- WalkTree(pCmap->pScreen, TellGainedMap, (pointer)&pCmap->mid);
-
- xnestSetInstalledColormapWindows(pCmap->pScreen);
- xnestDirectInstallColormaps(pCmap->pScreen);
+ ColormapPtr pOldCmap = GetInstalledColormap(pCmap->pScreen);
+
+ if (pCmap != pOldCmap) {
+ xnestDirectUninstallColormaps(pCmap->pScreen);
+
+ /* Uninstall pInstalledMap. Notify all interested parties. */
+ if (pOldCmap != (ColormapPtr) None)
+ WalkTree(pCmap->pScreen, TellLostMap, (pointer) &pOldCmap->mid);
+
+ SetInstalledColormap(pCmap->pScreen, pCmap);
+ WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &pCmap->mid);
+
+ xnestSetInstalledColormapWindows(pCmap->pScreen);
+ xnestDirectInstallColormaps(pCmap->pScreen);
}
}
void
xnestUninstallColormap(ColormapPtr pCmap)
{
- ColormapPtr pCurCmap = GetInstalledColormap(pCmap->pScreen);
-
- if(pCmap == pCurCmap)
- {
- if (pCmap->mid != pCmap->pScreen->defColormap)
- {
- dixLookupResourceByType((pointer *)&pCurCmap,
- pCmap->pScreen->defColormap,
- RT_COLORMAP,
- serverClient, DixInstallAccess);
- (*pCmap->pScreen->InstallColormap)(pCurCmap);
+ ColormapPtr pCurCmap = GetInstalledColormap(pCmap->pScreen);
+
+ if (pCmap == pCurCmap) {
+ if (pCmap->mid != pCmap->pScreen->defColormap) {
+ dixLookupResourceByType((pointer *) &pCurCmap,
+ pCmap->pScreen->defColormap,
+ RT_COLORMAP,
+ serverClient, DixInstallAccess);
+ (*pCmap->pScreen->InstallColormap) (pCurCmap);
}
}
}
@@ -372,124 +376,118 @@ xnestUninstallColormap(ColormapPtr pCmap)
static Bool xnestInstalledDefaultColormap = False;
int
-xnestListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIDs)
+xnestListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmapIDs)
{
- if (xnestInstalledDefaultColormap) {
- *pCmapIDs = GetInstalledColormap(pScreen)->mid;
- return 1;
- }
- else
- return 0;
+ if (xnestInstalledDefaultColormap) {
+ *pCmapIDs = GetInstalledColormap(pScreen)->mid;
+ return 1;
+ }
+ else
+ return 0;
}
void
-xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors)
+xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem * pColors)
{
- if (pCmap->pVisual->class & DynamicClass)
+ if (pCmap->pVisual->class & DynamicClass)
#ifdef _XSERVER64
- {
- int i;
- XColor *pColors64 = (XColor *)malloc(nColors * sizeof(XColor) );
-
- for(i = 0; i < nColors; ++i)
{
- pColors64[i].pixel = pColors[i].pixel;
- pColors64[i].red = pColors[i].red;
- pColors64[i].green = pColors[i].green;
- pColors64[i].blue = pColors[i].blue;
- pColors64[i].flags = pColors[i].flags;
+ int i;
+ XColor *pColors64 = (XColor *) malloc(nColors * sizeof(XColor));
+
+ for (i = 0; i < nColors; ++i) {
+ pColors64[i].pixel = pColors[i].pixel;
+ pColors64[i].red = pColors[i].red;
+ pColors64[i].green = pColors[i].green;
+ pColors64[i].blue = pColors[i].blue;
+ pColors64[i].flags = pColors[i].flags;
+ }
+ XStoreColors(xnestDisplay, xnestColormap(pCmap), pColors64, nColors);
+ free(pColors64);
}
- XStoreColors(xnestDisplay, xnestColormap(pCmap), pColors64, nColors);
- free(pColors64);
- }
#else
- XStoreColors(xnestDisplay, xnestColormap(pCmap),
- (XColor *)pColors, nColors);
+ XStoreColors(xnestDisplay, xnestColormap(pCmap),
+ (XColor *) pColors, nColors);
#endif
}
void
xnestResolveColor(unsigned short *pRed, unsigned short *pGreen,
- unsigned short *pBlue, VisualPtr pVisual)
+ unsigned short *pBlue, VisualPtr pVisual)
{
- int shift;
- unsigned int lim;
-
- shift = 16 - pVisual->bitsPerRGBValue;
- lim = (1 << pVisual->bitsPerRGBValue) - 1;
+ int shift;
+ unsigned int lim;
- if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor))
- {
- /* rescale to rgb bits */
- *pRed = ((*pRed >> shift) * 65535) / lim;
- *pGreen = ((*pGreen >> shift) * 65535) / lim;
- *pBlue = ((*pBlue >> shift) * 65535) / lim;
+ shift = 16 - pVisual->bitsPerRGBValue;
+ lim = (1 << pVisual->bitsPerRGBValue) - 1;
+
+ if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor)) {
+ /* rescale to rgb bits */
+ *pRed = ((*pRed >> shift) * 65535) / lim;
+ *pGreen = ((*pGreen >> shift) * 65535) / lim;
+ *pBlue = ((*pBlue >> shift) * 65535) / lim;
}
- else if (pVisual->class == GrayScale)
- {
- /* rescale to gray then rgb bits */
- *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100;
- *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim;
+ else if (pVisual->class == GrayScale) {
+ /* rescale to gray then rgb bits */
+ *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100;
+ *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim;
}
- else if (pVisual->class == StaticGray)
- {
- unsigned int limg;
-
- limg = pVisual->ColormapEntries - 1;
- /* rescale to gray then [0..limg] then [0..65535] then rgb bits */
- *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100;
- *pRed = ((((*pRed * (limg + 1))) >> 16) * 65535) / limg;
- *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim;
+ else if (pVisual->class == StaticGray) {
+ unsigned int limg;
+
+ limg = pVisual->ColormapEntries - 1;
+ /* rescale to gray then [0..limg] then [0..65535] then rgb bits */
+ *pRed = (30L * *pRed + 59L * *pGreen + 11L * *pBlue) / 100;
+ *pRed = ((((*pRed * (limg + 1))) >> 16) * 65535) / limg;
+ *pBlue = *pGreen = *pRed = ((*pRed >> shift) * 65535) / lim;
}
- else
- {
- unsigned limr, limg, limb;
-
- limr = pVisual->redMask >> pVisual->offsetRed;
- limg = pVisual->greenMask >> pVisual->offsetGreen;
- limb = pVisual->blueMask >> pVisual->offsetBlue;
- /* rescale to [0..limN] then [0..65535] then rgb bits */
- *pRed = ((((((*pRed * (limr + 1)) >> 16) *
- 65535) / limr) >> shift) * 65535) / lim;
- *pGreen = ((((((*pGreen * (limg + 1)) >> 16) *
- 65535) / limg) >> shift) * 65535) / lim;
- *pBlue = ((((((*pBlue * (limb + 1)) >> 16) *
- 65535) / limb) >> shift) * 65535) / lim;
+ else {
+ unsigned limr, limg, limb;
+
+ limr = pVisual->redMask >> pVisual->offsetRed;
+ limg = pVisual->greenMask >> pVisual->offsetGreen;
+ limb = pVisual->blueMask >> pVisual->offsetBlue;
+ /* rescale to [0..limN] then [0..65535] then rgb bits */
+ *pRed = ((((((*pRed * (limr + 1)) >> 16) *
+ 65535) / limr) >> shift) * 65535) / lim;
+ *pGreen = ((((((*pGreen * (limg + 1)) >> 16) *
+ 65535) / limg) >> shift) * 65535) / lim;
+ *pBlue = ((((((*pBlue * (limb + 1)) >> 16) *
+ 65535) / limb) >> shift) * 65535) / lim;
}
}
Bool
xnestCreateDefaultColormap(ScreenPtr pScreen)
{
- VisualPtr pVisual;
- ColormapPtr pCmap;
- unsigned short zero = 0, ones = 0xFFFF;
- Pixel wp, bp;
-
- if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- for (pVisual = pScreen->visuals;
- pVisual->vid != pScreen->rootVisual;
- pVisual++);
-
- if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap,
- (pVisual->class & DynamicClass) ? AllocNone : AllocAll, 0)
- != Success)
- return False;
-
- wp = pScreen->whitePixel;
- bp = pScreen->blackPixel;
- if ((AllocColor(pCmap, &ones, &ones, &ones, &wp, 0) !=
- Success) ||
- (AllocColor(pCmap, &zero, &zero, &zero, &bp, 0) !=
- Success))
- return FALSE;
- pScreen->whitePixel = wp;
- pScreen->blackPixel = bp;
- (*pScreen->InstallColormap)(pCmap);
-
- xnestInstalledDefaultColormap = True;
-
- return True;
+ VisualPtr pVisual;
+ ColormapPtr pCmap;
+ unsigned short zero = 0, ones = 0xFFFF;
+ Pixel wp, bp;
+
+ if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+ return FALSE;
+
+ for (pVisual = pScreen->visuals;
+ pVisual->vid != pScreen->rootVisual; pVisual++);
+
+ if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap,
+ (pVisual->class & DynamicClass) ? AllocNone : AllocAll,
+ 0)
+ != Success)
+ return False;
+
+ wp = pScreen->whitePixel;
+ bp = pScreen->blackPixel;
+ if ((AllocColor(pCmap, &ones, &ones, &ones, &wp, 0) !=
+ Success) ||
+ (AllocColor(pCmap, &zero, &zero, &zero, &bp, 0) != Success))
+ return FALSE;
+ pScreen->whitePixel = wp;
+ pScreen->blackPixel = bp;
+ (*pScreen->InstallColormap) (pCmap);
+
+ xnestInstalledDefaultColormap = True;
+
+ return True;
}