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