CmapAlloc.c File Reference

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xmu/StdCmap.h>
#include <stdio.h>

Include dependency graph for CmapAlloc.c:

Go to the source code of this file.

Defines

#define lowbit(x)   ((x) & (~(x) + 1))

Functions

static void best_allocation (XVisualInfo *, unsigned long *, unsigned long *, unsigned long *)
static int default_allocation (XVisualInfo *, unsigned long *, unsigned long *, unsigned long *)
static void gray_allocation (int, unsigned long *, unsigned long *, unsigned long *)
static int icbrt (int)
static int icbrt_with_bits (int, int)
static int icbrt_with_guess (int, int)
Status XmuGetColormapAllocation (XVisualInfo *vinfo, Atom property, unsigned long *red_max, unsigned long *green_max, unsigned long *blue_max)


Define Documentation

#define lowbit ( x   )     ((x) & (~(x) + 1))

Definition at line 40 of file CmapAlloc.c.

Referenced by default_allocation(), readwrite_map(), and XmuStandardColormap().


Function Documentation

static void best_allocation ( XVisualInfo *  ,
unsigned long ,
unsigned long ,
unsigned long  
) [static]

Definition at line 212 of file CmapAlloc.c.

References b, bits, g, icbrt_with_bits(), and n.

Referenced by XmuGetColormapAllocation().

00214 {
00215 
00216     if (vinfo->class == DirectColor ||  vinfo->class == TrueColor)
00217     {
00218         *red = vinfo->red_mask;
00219         while ((*red & 01) == 0)
00220             *red >>= 1;
00221         *green = vinfo->green_mask;
00222         while ((*green & 01) == 0)
00223             *green >>=1;
00224         *blue = vinfo->blue_mask;
00225         while ((*blue & 01) == 0)
00226             *blue >>= 1;
00227     }
00228     else
00229     {
00230         register int bits, n;
00231         
00232         /* Determine n such that n is the least integral power of 2 which is
00233          * greater than or equal to the number of entries in the colormap.
00234          */
00235         n = 1;
00236         bits = 0;
00237         while (vinfo->colormap_size > n)
00238         {
00239             n = n << 1;
00240             bits++;
00241         }
00242         
00243         /* If the number of entries in the colormap is a power of 2, determine
00244          * the allocation by "dealing" the bits, first to green, then red, then
00245          * blue.  If not, find the maximum integral red, green, and blue values
00246          * which, when multiplied together, do not exceed the number of 
00247 
00248          * colormap entries.
00249          */
00250         if (n == vinfo->colormap_size)
00251         {
00252             register int r, g, b;
00253             b = bits / 3;
00254             g = b + ((bits % 3) ? 1 : 0);
00255             r = b + (((bits % 3) == 2) ? 1 : 0);
00256             *red = 1 << r;
00257             *green = 1 << g;
00258             *blue = 1 << b;
00259         }
00260         else
00261         {
00262             *red = icbrt_with_bits(vinfo->colormap_size, bits);
00263             *blue = *red;       
00264             *green = (vinfo->colormap_size / ((*red) * (*blue)));
00265         }
00266         (*red)--;
00267         (*green)--;
00268         (*blue)--;
00269     }
00270     return;
00271 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int default_allocation ( XVisualInfo *  ,
unsigned long ,
unsigned long ,
unsigned long  
) [static]

Definition at line 138 of file CmapAlloc.c.

References gray_allocation(), icbrt(), long, and lowbit.

Referenced by XmuGetColormapAllocation().

00140 {
00141     int                 ngrays;         /* number of gray cells */
00142 
00143     switch (vinfo->class) {
00144       case PseudoColor:
00145 
00146         if (vinfo->colormap_size > 65000)
00147             /* intended for displays with 16 planes */
00148             *red = *green = *blue = (unsigned long) 27;
00149         else if (vinfo->colormap_size > 4000)
00150             /* intended for displays with 12 planes */
00151             *red = *green = *blue = (unsigned long) 12;
00152         else if (vinfo->colormap_size < 250)
00153             return 0;
00154         else
00155             /* intended for displays with 8 planes */
00156             *red = *green = *blue = (unsigned long)
00157                 (icbrt(vinfo->colormap_size - 125) - 1);
00158         break;
00159 
00160       case DirectColor:
00161 
00162         if (vinfo->colormap_size < 10)
00163             return 0;
00164         *red = *green = *blue = vinfo->colormap_size / 2 - 1;
00165         break;
00166 
00167       case TrueColor:
00168 
00169         *red = vinfo->red_mask / lowbit(vinfo->red_mask);
00170         *green = vinfo->green_mask / lowbit(vinfo->green_mask);
00171         *blue = vinfo->blue_mask / lowbit(vinfo->blue_mask);
00172         break;
00173 
00174       case GrayScale:
00175 
00176         if (vinfo->colormap_size > 65000)
00177             ngrays = 4096;
00178         else if (vinfo->colormap_size > 4000)
00179             ngrays = 512;
00180         else if (vinfo->colormap_size < 250)
00181             return 0;
00182         else
00183             ngrays = 12;
00184         gray_allocation(ngrays, red, green, blue);
00185         break;
00186         
00187       default:
00188         return 0;
00189     }
00190     return 1;
00191 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void gray_allocation ( int  ,
unsigned long ,
unsigned long ,
unsigned long  
) [static]

Definition at line 114 of file CmapAlloc.c.

Referenced by default_allocation(), and XmuGetColormapAllocation().

00116 {
00117     *red_max = (n * 30) / 100;
00118     *green_max = (n * 59) / 100; 
00119     *blue_max = (n * 11) / 100; 
00120     *green_max += ((n - 1) - (*red_max + *green_max + *blue_max));
00121 }

Here is the caller graph for this function:

static int icbrt ( int   )  [static]

Definition at line 280 of file CmapAlloc.c.

References bits, icbrt_with_bits(), and n.

Referenced by default_allocation().

00281 {
00282     register int bits = 0;
00283     register unsigned n = a;
00284 
00285     while (n)
00286     {
00287         bits++;
00288         n >>= 1;
00289     }
00290     return icbrt_with_bits(a, bits);
00291 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int icbrt_with_bits ( int  ,
int   
) [static]

Definition at line 295 of file CmapAlloc.c.

References icbrt_with_guess().

Referenced by best_allocation(), and icbrt().

00297 {
00298     return icbrt_with_guess(a, a>>2*bits/3);
00299 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int icbrt_with_guess ( int  ,
int   
) [static]

Definition at line 316 of file CmapAlloc.c.

Referenced by icbrt_with_bits().

00317 {
00318     register int delta;
00319 
00320 #ifdef _X_ROOT_STATS
00321     icbrt_loopcount = 0;
00322 #endif
00323     if (a <= 0)
00324         return 0;
00325     if (guess < 1)
00326         guess = 1;
00327 
00328     do {
00329 #ifdef _X_ROOT_STATS
00330         icbrt_loopcount++;
00331 #endif
00332         delta = (guess - a/(guess*guess))/3;
00333 #ifdef DEBUG
00334         printf("pass %d: guess=%d, delta=%d\n", icbrt_loopcount, guess, delta);
00335 #endif
00336         guess -= delta;
00337     } while (delta != 0);
00338 
00339     if (guess*guess*guess > a)
00340         guess--;
00341 
00342     return guess;
00343 }

Here is the caller graph for this function:

Status XmuGetColormapAllocation ( XVisualInfo *  vinfo,
Atom  property,
unsigned long red_max,
unsigned long green_max,
unsigned long blue_max 
)

Definition at line 68 of file CmapAlloc.c.

References best_allocation(), default_allocation(), and gray_allocation().

Referenced by XmuLookupStandardColormap().

00072 {
00073     Status      status = 1;
00074 
00075     if (vinfo->colormap_size <= 2)
00076         return 0;
00077 
00078     switch (property)
00079     {
00080       case XA_RGB_DEFAULT_MAP:
00081         status = default_allocation(vinfo, red_max, green_max, blue_max);
00082         break;
00083       case XA_RGB_BEST_MAP:
00084         best_allocation(vinfo, red_max, green_max, blue_max);
00085         break;
00086       case XA_RGB_GRAY_MAP:
00087         gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max);
00088         break;
00089       case XA_RGB_RED_MAP:
00090         *red_max = vinfo->colormap_size - 1;
00091         *green_max = *blue_max = 0;
00092         break;
00093       case XA_RGB_GREEN_MAP:
00094         *green_max = vinfo->colormap_size - 1;
00095         *red_max = *blue_max = 0;
00096         break;
00097       case XA_RGB_BLUE_MAP:
00098         *blue_max = vinfo->colormap_size - 1;
00099         *red_max = *green_max = 0;
00100         break;
00101       default:
00102         status = 0;
00103     }
00104     return status;
00105 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Mar 4 16:03:35 2007 for Scilab [trunk] by  doxygen 1.5.1