aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2019-07-29 16:07:37 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2019-09-29 17:10:05 +0200
commite2fa4f5c4b5ce4999d16fd4a55ff44e5b198aece (patch)
treec15a703269750807ae97de2bf6be55603be7fc04 /nx-X11
parent19267ddf42afe3f53eba0d6ae82963b9f6dfdeb9 (diff)
downloadnx-libs-e2fa4f5c4b5ce4999d16fd4a55ff44e5b198aece.tar.gz
nx-libs-e2fa4f5c4b5ce4999d16fd4a55ff44e5b198aece.tar.bz2
nx-libs-e2fa4f5c4b5ce4999d16fd4a55ff44e5b198aece.zip
Colormap.c: Formatting and scope improvements
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Colormap.c245
1 files changed, 122 insertions, 123 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Colormap.c b/nx-X11/programs/Xserver/hw/nxagent/Colormap.c
index 7fa006539..b04977887 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Colormap.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Colormap.c
@@ -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
@@ -281,36 +295,36 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
This will only work with default local visual colormaps.
*/
if (icws.numWindows)
+ {
+ WindowPtr pWin;
+ Visual *visual;
+ ColormapPtr pCmap;
+
+ pWin = nxagentWindowPtr(icws.windows[0]);
+ visual = nxagentVisualFromID(pScreen, wVisual(pWin));
+
+ if (visual == nxagentDefaultVisual(pScreen))
+ pCmap = (ColormapPtr)LookupIDByType(wColormap(pWin),
+ RT_COLORMAP);
+ else
+ pCmap = (ColormapPtr)LookupIDByType(pScreen->defColormap,
+ RT_COLORMAP);
+
+ if (pCmap != NULL)
{
- WindowPtr pWin;
- Visual *visual;
- ColormapPtr pCmap;
-
- pWin = nxagentWindowPtr(icws.windows[0]);
- visual = nxagentVisualFromID(pScreen, wVisual(pWin));
-
- if (visual == nxagentDefaultVisual(pScreen))
- pCmap = (ColormapPtr)LookupIDByType(wColormap(pWin),
- RT_COLORMAP);
- else
- pCmap = (ColormapPtr)LookupIDByType(pScreen->defColormap,
- RT_COLORMAP);
-
- if (pCmap != NULL)
- {
- XSetWindowColormap(nxagentDisplay,
- nxagentDefaultWindows[pScreen->myNum],
- nxagentColormap(pCmap));
- }
- #ifdef WARNING
- else
- {
- fprintf(stderr, "nxagentSetInstalledColormapWindows: WARNING! "
- "Window at [%p] has no colormap with class [%d].\n",
- (void *)pWin, pWin -> drawable.class);
- }
- #endif
+ XSetWindowColormap(nxagentDisplay,
+ nxagentDefaultWindows[pScreen->myNum],
+ nxagentColormap(pCmap));
}
+ #ifdef WARNING
+ else
+ {
+ fprintf(stderr, "nxagentSetInstalledColormapWindows: WARNING! "
+ "Window at [%p] has no colormap with class [%d].\n",
+ (void *)pWin, pWin -> drawable.class);
+ }
+ #endif
+ }
#endif /* DUMB_WINDOW_MANAGERS */
}
else
@@ -345,7 +359,8 @@ void nxagentDirectInstallColormaps(ScreenPtr pScreen)
{
Colormap pCmapIDs[MAXCMAPS];
- if (!nxagentDoDirectColormaps) return;
+ if (!nxagentDoDirectColormaps)
+ return;
int n = (*pScreen->ListInstalledColormaps)(pScreen, pCmapIDs);
@@ -375,45 +390,39 @@ 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)
- {
- nxagentDirectUninstallColormaps(pCmap->pScreen);
+ {
+ nxagentDirectUninstallColormaps(pCmap->pScreen);
- /* Uninstall pInstalledMap. Notify all interested parties. */
- if(pOldCmap != (ColormapPtr)None)
- WalkTree(pCmap->pScreen, TellLostMap, (void *)&pOldCmap->mid);
+ /* Uninstall pInstalledMap. Notify all interested parties. */
+ if(pOldCmap != (ColormapPtr)None)
+ WalkTree(pCmap->pScreen, TellLostMap, (void *)&pOldCmap->mid);
- InstalledMaps[index] = pCmap;
- WalkTree(pCmap->pScreen, TellGainedMap, (void *)&pCmap->mid);
+ InstalledMaps[index] = pCmap;
+ WalkTree(pCmap->pScreen, TellGainedMap, (void *)&pCmap->mid);
- nxagentSetInstalledColormapWindows(pCmap->pScreen);
- nxagentDirectInstallColormaps(pCmap->pScreen);
- }
+ nxagentSetInstalledColormapWindows(pCmap->pScreen);
+ nxagentDirectInstallColormaps(pCmap->pScreen);
+ }
}
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)
+ {
+ if ((unsigned int)pCmap->mid != pCmap->pScreen->defColormap)
{
- if ((unsigned int)pCmap->mid != pCmap->pScreen->defColormap)
- {
- pCurCmap = (ColormapPtr)LookupIDByType(pCmap->pScreen->defColormap,
- RT_COLORMAP);
- (*pCmap->pScreen->InstallColormap)(pCurCmap);
- }
+ pCurCmap = (ColormapPtr)LookupIDByType(pCmap->pScreen->defColormap,
+ RT_COLORMAP);
+ (*pCmap->pScreen->InstallColormap)(pCurCmap);
}
+ }
}
int nxagentListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIds)
@@ -456,50 +465,43 @@ 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))
- {
- /* rescale to rgb bits */
- *pRed = ((*pRed >> shift) * 65535) / lim;
- *pGreen = ((*pGreen >> shift) * 65535) / lim;
- *pBlue = ((*pBlue >> shift) * 65535) / lim;
- }
+ {
+ /* 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;
- }
+ {
+ /* 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;
- }
+ {
+ 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;
+ *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;
- }
+ {
+ 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;
+ *pGreen = ((((((*pGreen * (limg + 1)) >> 16) *
+ 65535) / limg) >> shift) * 65535) / lim;
+ *pBlue = ((((((*pBlue * (limb + 1)) >> 16) *
+ 65535) / limb) >> shift) * 65535) / lim;
+ }
}
Bool nxagentCreateDefaultColormap(ScreenPtr pScreen)
@@ -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)
{