cmap_xfbdev.txt 1.9 KB

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