Back to home page

OSCL-LXR

 
 

    


0001 ==========================
0002 Understanding fbdev's cmap
0003 ==========================
0004 
0005 These notes explain how X's dix layer uses fbdev's cmap structures.
0006 
0007 -  example of relevant structures in fbdev as used for a 3-bit grayscale cmap::
0008 
0009     struct fb_var_screeninfo {
0010             .bits_per_pixel = 8,
0011             .grayscale      = 1,
0012             .red =          { 4, 3, 0 },
0013             .green =        { 0, 0, 0 },
0014             .blue =         { 0, 0, 0 },
0015     }
0016     struct fb_fix_screeninfo {
0017             .visual =       FB_VISUAL_STATIC_PSEUDOCOLOR,
0018     }
0019     for (i = 0; i < 8; i++)
0020         info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
0021     memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
0022     memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
0023 
0024 -  X11 apps do something like the following when trying to use grayscale::
0025 
0026     for (i=0; i < 8; i++) {
0027         char colorspec[64];
0028         memset(colorspec,0,64);
0029         sprintf(colorspec, "rgb:%x/%x/%x", i*36,i*36,i*36);
0030         if (!XParseColor(outputDisplay, testColormap, colorspec, &wantedColor))
0031                 printf("Can't get color %s\n",colorspec);
0032         XAllocColor(outputDisplay, testColormap, &wantedColor);
0033         grays[i] = wantedColor;
0034     }
0035 
0036 There's also named equivalents like gray1..x provided you have an rgb.txt.
0037 
0038 Somewhere in X's callchain, this results in a call to X code that handles the
0039 colormap. For example, Xfbdev hits the following:
0040 
0041 xc-011010/programs/Xserver/dix/colormap.c::
0042 
0043   FindBestPixel(pentFirst, size, prgb, channel)
0044 
0045   dr = (long) pent->co.local.red - prgb->red;
0046   dg = (long) pent->co.local.green - prgb->green;
0047   db = (long) pent->co.local.blue - prgb->blue;
0048   sq = dr * dr;
0049   UnsignedToBigNum (sq, &sum);
0050   BigNumAdd (&sum, &temp, &sum);
0051 
0052 co.local.red are entries that were brought in through FBIOGETCMAP which come
0053 directly from the info->cmap.red that was listed above. The prgb is the rgb
0054 that the app wants to match to. The above code is doing what looks like a least
0055 squares matching function. That's why the cmap entries can't be set to the left
0056 hand side boundaries of a color range.