cmap_xfbdev.rst 1.9 KB

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