Blame view

Documentation/fb/cmap_xfbdev.rst 1.95 KB
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
1
  ==========================
de7c6d15e   Jaya Kumar   fbdev: defio and ...
2
  Understanding fbdev's cmap
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
3
  ==========================
de7c6d15e   Jaya Kumar   fbdev: defio and ...
4
5
  
  These notes explain how X's dix layer uses fbdev's cmap structures.
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
6
7
8
9
10
11
12
13
14
15
16
17
18
  -  example of relevant structures in fbdev as used for a 3-bit grayscale cmap::
  
      struct fb_var_screeninfo {
  	    .bits_per_pixel = 8,
  	    .grayscale      = 1,
  	    .red =          { 4, 3, 0 },
  	    .green =        { 0, 0, 0 },
  	    .blue =         { 0, 0, 0 },
      }
      struct fb_fix_screeninfo {
  	    .visual =       FB_VISUAL_STATIC_PSEUDOCOLOR,
      }
      for (i = 0; i < 8; i++)
de7c6d15e   Jaya Kumar   fbdev: defio and ...
19
  	info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16;
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
20
21
      memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8);
      memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);
de7c6d15e   Jaya Kumar   fbdev: defio and ...
22

ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
23
24
25
  -  X11 apps do something like the following when trying to use grayscale::
  
      for (i=0; i < 8; i++) {
de7c6d15e   Jaya Kumar   fbdev: defio and ...
26
27
28
29
30
31
32
33
  	char colorspec[64];
  	memset(colorspec,0,64);
  	sprintf(colorspec, "rgb:%x/%x/%x", i*36,i*36,i*36);
  	if (!XParseColor(outputDisplay, testColormap, colorspec, &wantedColor))
  		printf("Can't get color %s
  ",colorspec);
  	XAllocColor(outputDisplay, testColormap, &wantedColor);
  	grays[i] = wantedColor;
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
34
      }
de7c6d15e   Jaya Kumar   fbdev: defio and ...
35
36
37
38
  There's also named equivalents like gray1..x provided you have an rgb.txt.
  
  Somewhere in X's callchain, this results in a call to X code that handles the
  colormap. For example, Xfbdev hits the following:
ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
39
  xc-011010/programs/Xserver/dix/colormap.c::
de7c6d15e   Jaya Kumar   fbdev: defio and ...
40

ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
41
    FindBestPixel(pentFirst, size, prgb, channel)
de7c6d15e   Jaya Kumar   fbdev: defio and ...
42

ab42b8189   Mauro Carvalho Chehab   docs: fb: convert...
43
44
45
46
47
48
    dr = (long) pent->co.local.red - prgb->red;
    dg = (long) pent->co.local.green - prgb->green;
    db = (long) pent->co.local.blue - prgb->blue;
    sq = dr * dr;
    UnsignedToBigNum (sq, &sum);
    BigNumAdd (&sum, &temp, &sum);
de7c6d15e   Jaya Kumar   fbdev: defio and ...
49
50
51
52
53
54
  
  co.local.red are entries that were brought in through FBIOGETCMAP which come
  directly from the info->cmap.red that was listed above. The prgb is the rgb
  that the app wants to match to. The above code is doing what looks like a least
  squares matching function. That's why the cmap entries can't be set to the left
  hand side boundaries of a color range.