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