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