Commit e2fa4f5c authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Colormap.c: Formatting and scope improvements

parent 19267ddf
......@@ -69,11 +69,7 @@ Bool nxagentReconnectAllColormap(void *p0);
Bool nxagentCreateColormap(ColormapPtr pCmap)
{
VisualPtr pVisual;
XColor *colors;
int i, ncolors;
Pixel red, green, blue;
Pixel redInc, greenInc, blueInc;
Visual *visual;
int class;
......@@ -83,8 +79,8 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
" visual [%lu].\n", pCmap->pVisual);
#endif
pVisual = pCmap->pVisual;
ncolors = pVisual->ColormapEntries;
VisualPtr pVisual = pCmap->pVisual;
int ncolors = pVisual->ColormapEntries;
pCmap->devPriv = (void *)malloc(sizeof(nxagentPrivColormap));
......@@ -102,7 +98,6 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
class = pVisual->class;
}
nxagentColormapPriv(pCmap)->colormap =
XCreateColormap(nxagentDisplay,
nxagentDefaultWindows[pCmap->pScreen->myNum],
......@@ -110,13 +105,15 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
(class & DynamicClass) ?
AllocAll : AllocNone);
switch (class) {
switch (class)
{
case StaticGray: /* read only */
colors = (XColor *)malloc(ncolors * sizeof(XColor));
for (i = 0; i < ncolors; i++)
for (int i = 0; i < ncolors; i++)
colors[i].pixel = i;
XQueryColors(nxagentDisplay, nxagentColormap(pCmap), colors, ncolors);
for (i = 0; i < ncolors; i++) {
for (int 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;
......@@ -126,10 +123,11 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
case StaticColor: /* read only */
colors = (XColor *)malloc(ncolors * sizeof(XColor));
for (i = 0; i < ncolors; i++)
for (int i = 0; i < ncolors; i++)
colors[i].pixel = i;
XQueryColors(nxagentDisplay, nxagentColormap(pCmap), colors, ncolors);
for (i = 0; i < ncolors; i++) {
for (int 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;
......@@ -139,21 +137,29 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
case TrueColor: /* read only */
colors = (XColor *)malloc(ncolors * sizeof(XColor));
red = green = blue = 0L;
Pixel red = 0L, green = 0L, blue = 0L;
Pixel redInc, greenInc, blueInc;
redInc = lowbit(pVisual->redMask);
greenInc = lowbit(pVisual->greenMask);
blueInc = lowbit(pVisual->blueMask);
for (i = 0; i < ncolors; i++) {
for (int i = 0; i < ncolors; i++)
{
colors[i].pixel = red | green | blue;
red += redInc;
if (red > pVisual->redMask) red = 0L;
if (red > pVisual->redMask)
red = 0L;
green += greenInc;
if (green > pVisual->greenMask) green = 0L;
if (green > pVisual->greenMask)
green = 0L;
blue += blueInc;
if (blue > pVisual->blueMask) blue = 0L;
if (blue > pVisual->blueMask)
blue = 0L;
}
XQueryColors(nxagentDisplay, nxagentColormap(pCmap), colors, ncolors);
for (i = 0; i < ncolors; i++) {
for (int 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;
......@@ -188,10 +194,13 @@ static int nxagentCountInstalledColormapWindows(WindowPtr pWin, void * ptr)
nxagentInstalledColormapWindows *icws = (nxagentInstalledColormapWindows *) ptr;
for (int i = 0; i < icws->numCmapIDs; i++)
if (SEARCH_PREDICATE) {
{
if (SEARCH_PREDICATE)
{
icws->numWindows++;
return WT_DONTWALKCHILDREN;
}
}
return WT_WALKCHILDREN;
}
......@@ -201,10 +210,13 @@ static int nxagentGetInstalledColormapWindows(WindowPtr pWin, void * ptr)
nxagentInstalledColormapWindows *icws = (nxagentInstalledColormapWindows *)ptr;
for (int i = 0; i < icws->numCmapIDs; i++)
if (SEARCH_PREDICATE) {
{
if (SEARCH_PREDICATE)
{
icws->windows[icws->index++] = nxagentWindow(pWin);
return WT_DONTWALKCHILDREN;
}
}
return WT_WALKCHILDREN;
}
......@@ -240,7 +252,8 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
icws.numCmapIDs = nxagentListInstalledColormaps(pScreen, icws.cmapIDs);
icws.numWindows = 0;
WalkTree(pScreen, nxagentCountInstalledColormapWindows, (void *)&icws);
if (icws.numWindows) {
if (icws.numWindows)
{
icws.windows = (Window *)malloc((icws.numWindows + 1) * sizeof(Window));
icws.index = 0;
WalkTree(pScreen, nxagentGetInstalledColormapWindows, (void *)&icws);
......@@ -254,7 +267,8 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
SAFE_free(icws.cmapIDs);
if (!nxagentSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
if (!nxagentSameInstalledColormapWindows(icws.windows, icws.numWindows))
{
SAFE_free(nxagentOldInstalledColormapWindows);
#ifdef _XSERVER64
......@@ -345,7 +359,8 @@ void nxagentDirectInstallColormaps(ScreenPtr pScreen)
{
Colormap pCmapIDs[MAXCMAPS];
if (!nxagentDoDirectColormaps) return;
if (!nxagentDoDirectColormaps)
return;
int n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs);
......@@ -375,11 +390,8 @@ void nxagentDirectUninstallColormaps(ScreenPtr pScreen)
void nxagentInstallColormap(ColormapPtr pCmap)
{
int index;
ColormapPtr pOldCmap;
index = pCmap->pScreen->myNum;
pOldCmap = InstalledMaps[index];
int index = pCmap->pScreen->myNum;
ColormapPtr pOldCmap = InstalledMaps[index];
if(pCmap != pOldCmap)
{
......@@ -399,11 +411,8 @@ void nxagentInstallColormap(ColormapPtr pCmap)
void nxagentUninstallColormap(ColormapPtr pCmap)
{
int index;
ColormapPtr pCurCmap;
index = pCmap->pScreen->myNum;
pCurCmap = InstalledMaps[index];
int index = pCmap->pScreen->myNum;
ColormapPtr pCurCmap = InstalledMaps[index];
if(pCmap == pCurCmap)
{
......@@ -456,11 +465,8 @@ void nxagentStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors)
void nxagentResolveColor(unsigned short *pRed, unsigned short *pGreen,
unsigned short *pBlue, VisualPtr pVisual)
{
int shift;
unsigned int lim;
shift = 16 - pVisual->bitsPerRGBValue;
lim = (1 << pVisual->bitsPerRGBValue) - 1;
int shift = 16 - pVisual->bitsPerRGBValue;
unsigned int lim = (1 << pVisual->bitsPerRGBValue) - 1;
if ((pVisual->class == PseudoColor) || (pVisual->class == DirectColor))
{
......@@ -477,9 +483,7 @@ void nxagentResolveColor(unsigned short *pRed, unsigned short *pGreen,
}
else if (pVisual->class == StaticGray)
{
unsigned int limg;
limg = pVisual->ColormapEntries - 1;
unsigned int 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;
......@@ -487,11 +491,9 @@ void nxagentResolveColor(unsigned short *pRed, unsigned short *pGreen,
}
else
{
unsigned limr, limg, limb;
limr = pVisual->redMask >> pVisual->offsetRed;
limg = pVisual->greenMask >> pVisual->offsetGreen;
limb = pVisual->blueMask >> pVisual->offsetBlue;
unsigned limr = pVisual->redMask >> pVisual->offsetRed;
unsigned limg = pVisual->greenMask >> pVisual->offsetGreen;
unsigned 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;
......@@ -507,7 +509,6 @@ Bool nxagentCreateDefaultColormap(ScreenPtr pScreen)
VisualPtr pVisual;
ColormapPtr pCmap;
unsigned short zero = 0, ones = 0xFFFF;
Pixel wp, bp;
#if defined(DEBUG) || defined(DEBUG_COLORMAP)
fprintf(stderr, "Debug: Searching for the root visual [%lu].\n",
......@@ -523,8 +524,8 @@ Bool nxagentCreateDefaultColormap(ScreenPtr pScreen)
!= Success)
return False;
wp = pScreen->whitePixel;
bp = pScreen->blackPixel;
Pixel wp = pScreen->whitePixel;
Pixel bp = pScreen->blackPixel;
if ((AllocColor(pCmap, &ones, &ones, &ones, &wp, 0) !=
Success) ||
(AllocColor(pCmap, &zero, &zero, &zero, &bp, 0) !=
......@@ -543,7 +544,6 @@ static void nxagentReconnectColormap(void * p0, XID x1, void * p2)
{
ColormapPtr pCmap = (ColormapPtr)p0;
Bool* pBool = (Bool*)p2;
VisualPtr pVisual;
#ifdef NXAGENT_RECONNECT_COLORMAP_DEBUG
fprintf(stderr, "nxagentReconnectColormap: %p\n", pCmap);
......@@ -552,7 +552,7 @@ static void nxagentReconnectColormap(void * p0, XID x1, void * p2)
if (!*pBool || !pCmap)
return;
pVisual = pCmap -> pVisual;
VisualPtr pVisual = pCmap -> pVisual;
nxagentColormapPriv(pCmap)->colormap =
XCreateColormap(nxagentDisplay,
......@@ -569,14 +569,13 @@ static void nxagentReconnectColormap(void * p0, XID x1, void * p2)
Bool nxagentReconnectAllColormap(void *p0)
{
int cid;
Bool success = True;
#if defined(NXAGENT_RECONNECT_DEBUG) || defined(NXAGENT_RECONNECT_COLORMAP_DEBUG)
fprintf(stderr, "nxagentReconnectAllColormap\n");
#endif
for (cid = 0; (cid < MAXCLIENTS) && success; cid++)
for (int cid = 0; (cid < MAXCLIENTS) && success; cid++)
{
if (clients[cid] && success)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment