理解 fbdev 的 cmap¶
這些筆記解釋了 X 的 dix 層如何使用 fbdev 的 cmap 結構。
fbdev 中相關結構的示例,用於 3 位灰度 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++) info->cmap.red[i] = (((2*i)+1)*(0xFFFF))/16; memcpy(info->cmap.green, info->cmap.red, sizeof(u16)*8); memcpy(info->cmap.blue, info->cmap.red, sizeof(u16)*8);當嘗試使用灰度時,X11 應用程式會執行以下操作:
for (i=0; i < 8; i++) { 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\n",colorspec); XAllocColor(outputDisplay, testColormap, &wantedColor); grays[i] = wantedColor; }
如果你有 rgb.txt,也有命名的等效項,例如 gray1..x。
在 X 的呼叫鏈中的某個地方,這會導致呼叫處理顏色對映的 X 程式碼。 例如,Xfbdev 命中以下內容
xc-011010/programs/Xserver/dix/colormap.c
FindBestPixel(pentFirst, size, prgb, channel)
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);
co.local.red 是透過 FBIOGETCMAP 引入的條目,直接來自上面列出的 info->cmap.red。 prgb 是應用程式想要匹配的 rgb。 上面的程式碼正在做看起來像最小二乘匹配的函式。 這就是為什麼 cmap 條目不能設定為顏色範圍的左側邊界。