]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - Documentation/fb/cmap_xfbdev.txt
viafb: add documentation for proc interface
[linux-2.6.git] / Documentation / fb / cmap_xfbdev.txt
1 Understanding fbdev's cmap
2 --------------------------
3
4 These notes explain how X's dix layer uses fbdev's cmap structures.
5
6 *. example of relevant structures in fbdev as used for a 3-bit grayscale cmap
7 struct fb_var_screeninfo {
8         .bits_per_pixel = 8,
9         .grayscale      = 1,
10         .red =          { 4, 3, 0 },
11         .green =        { 0, 0, 0 },
12         .blue =         { 0, 0, 0 },
13 }
14 struct fb_fix_screeninfo {
15         .visual =       FB_VISUAL_STATIC_PSEUDOCOLOR,
16 }
17 for (i = 0; i < 8; i++)
18         info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
19 memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
20 memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
21
22 *. X11 apps do something like the following when trying to use grayscale.
23 for (i=0; i < 8; i++) {
24         char colorspec[64];
25         memset(colorspec,0,64);
26         sprintf(colorspec, "rgb:%x/%x/%x", i*36,i*36,i*36);
27         if (!XParseColor(outputDisplay, testColormap, colorspec, &wantedColor))
28                 printf("Can't get color %s\n",colorspec);
29         XAllocColor(outputDisplay, testColormap, &wantedColor);
30         grays[i] = wantedColor;
31 }
32 There's also named equivalents like gray1..x provided you have an rgb.txt.
33
34 Somewhere in X's callchain, this results in a call to X code that handles the
35 colormap. For example, Xfbdev hits the following:
36
37 xc-011010/programs/Xserver/dix/colormap.c:
38
39 FindBestPixel(pentFirst, size, prgb, channel)
40
41 dr = (long) pent->co.local.red - prgb->red;
42 dg = (long) pent->co.local.green - prgb->green;
43 db = (long) pent->co.local.blue - prgb->blue;
44 sq = dr * dr;
45 UnsignedToBigNum (sq, &sum);
46 BigNumAdd (&sum, &temp, &sum);
47
48 co.local.red are entries that were brought in through FBIOGETCMAP which come
49 directly from the info->cmap.red that was listed above. The prgb is the rgb
50 that the app wants to match to. The above code is doing what looks like a least
51 squares matching function. That's why the cmap entries can't be set to the left
52 hand side boundaries of a color range.
53