📄 xm_api.c
字号:
#endif *color = subColor; *exact = 0;}/* * Do setup for PF_GRAYSCALE pixel format. * Note that buffer may be NULL. */static GLboolean setup_grayscale( int client, XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap ){ if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { return GL_FALSE; } if (buffer) { XMesaBuffer prevBuffer; if (!cmap) { return GL_FALSE; } prevBuffer = find_xmesa_buffer(v->display, cmap, buffer); if (prevBuffer && (buffer->xm_visual->mesa_visual.rgbMode == prevBuffer->xm_visual->mesa_visual.rgbMode)) { /* Copy colormap stuff from previous XMesaBuffer which uses same * X colormap. Do this to avoid time spent in noFaultXAllocColor. */ copy_colortable_info(buffer, prevBuffer); } else { /* Allocate 256 shades of gray */ int gray; int colorsfailed = 0; for (gray=0;gray<256;gray++) { GLint r = gamma_adjust( v->RedGamma, gray, 255 ); GLint g = gamma_adjust( v->GreenGamma, gray, 255 ); GLint b = gamma_adjust( v->BlueGamma, gray, 255 ); int exact, alloced; XMesaColor xcol; xcol.red = (r << 8) | r; xcol.green = (g << 8) | g; xcol.blue = (b << 8) | b; noFaultXAllocColor( client, v->display, cmap, GET_COLORMAP_SIZE(v), &xcol, &exact, &alloced ); if (!exact) { colorsfailed++; } if (alloced) { assert(buffer->num_alloced<256); buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; buffer->num_alloced++; } /*OLD assert(gray < 576); buffer->color_table[gray*3+0] = xcol.pixel; buffer->color_table[gray*3+1] = xcol.pixel; buffer->color_table[gray*3+2] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = gray * 30 / 100; buffer->pixel_to_g[xcol.pixel] = gray * 59 / 100; buffer->pixel_to_b[xcol.pixel] = gray * 11 / 100; */ buffer->color_table[gray] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = gray; buffer->pixel_to_g[xcol.pixel] = gray; buffer->pixel_to_b[xcol.pixel] = gray; } if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Note: %d out of 256 needed colors do not match exactly.\n", colorsfailed ); } } } v->dithered_pf = PF_Grayscale; v->undithered_pf = PF_Grayscale; return GL_TRUE;}/* * Setup RGB rendering for a window with a PseudoColor, StaticColor, * or 8-bit TrueColor visual visual. We try to allocate a palette of 225 * colors (5 red, 9 green, 5 blue) and dither to approximate a 24-bit RGB * color. While this function was originally designed just for 8-bit * visuals, it has also proven to work from 4-bit up to 16-bit visuals. * Dithering code contributed by Bob Mercier. */static GLboolean setup_dithered_color( int client, XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap ){ if (GET_VISUAL_DEPTH(v)<4 || GET_VISUAL_DEPTH(v)>16) { return GL_FALSE; } if (buffer) { XMesaBuffer prevBuffer; if (!cmap) { return GL_FALSE; } prevBuffer = find_xmesa_buffer(v->display, cmap, buffer); if (prevBuffer && (buffer->xm_visual->mesa_visual.rgbMode == prevBuffer->xm_visual->mesa_visual.rgbMode)) { /* Copy colormap stuff from previous, matching XMesaBuffer. * Do this to avoid time spent in noFaultXAllocColor. */ copy_colortable_info(buffer, prevBuffer); } else { /* Allocate X colors and initialize color_table[], red_table[], etc */ int r, g, b, i; int colorsfailed = 0; for (r = 0; r < DITH_R; r++) { for (g = 0; g < DITH_G; g++) { for (b = 0; b < DITH_B; b++) { XMesaColor xcol; int exact, alloced; xcol.red =gamma_adjust(v->RedGamma, r*65535/(DITH_R-1),65535); xcol.green=gamma_adjust(v->GreenGamma, g*65535/(DITH_G-1),65535); xcol.blue =gamma_adjust(v->BlueGamma, b*65535/(DITH_B-1),65535); noFaultXAllocColor( client, v->display, cmap, GET_COLORMAP_SIZE(v), &xcol, &exact, &alloced ); if (!exact) { colorsfailed++; } if (alloced) { assert(buffer->num_alloced<256); buffer->alloced_colors[buffer->num_alloced] = xcol.pixel; buffer->num_alloced++; } i = DITH_MIX( r, g, b ); assert(i < 576); buffer->color_table[i] = xcol.pixel; assert(xcol.pixel < 65536); buffer->pixel_to_r[xcol.pixel] = r * 255 / (DITH_R-1); buffer->pixel_to_g[xcol.pixel] = g * 255 / (DITH_G-1); buffer->pixel_to_b[xcol.pixel] = b * 255 / (DITH_B-1); } } } if (colorsfailed && _mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Note: %d out of %d needed colors do not match exactly.\n", colorsfailed, DITH_R * DITH_G * DITH_B ); } } } v->dithered_pf = PF_Dither; v->undithered_pf = PF_Lookup; return GL_TRUE;}/* * Setup for Hewlett Packard Color Recovery 8-bit TrueColor mode. * HPCR simulates 24-bit color fidelity with an 8-bit frame buffer. * Special dithering tables have to be initialized. */static void setup_8bit_hpcr( XMesaVisual v ){ /* HP Color Recovery contributed by: Alex De Bruyn (ad@lms.be) * To work properly, the atom _HP_RGB_SMOOTH_MAP_LIST must be defined * on the root window AND the colormap obtainable by XGetRGBColormaps * for that atom must be set on the window. (see also tkInitWindow) * If that colormap is not set, the output will look stripy. */ /* Setup color tables with gamma correction */ int i; double g; g = 1.0 / v->RedGamma; for (i=0; i<256; i++) { GLint red = IROUND_POS(255.0 * _mesa_pow( hpcr_rgbTbl[0][i]/255.0, g )); v->hpcr_rgbTbl[0][i] = CLAMP( red, 16, 239 ); } g = 1.0 / v->GreenGamma; for (i=0; i<256; i++) { GLint green = IROUND_POS(255.0 * _mesa_pow( hpcr_rgbTbl[1][i]/255.0, g )); v->hpcr_rgbTbl[1][i] = CLAMP( green, 16, 239 ); } g = 1.0 / v->BlueGamma; for (i=0; i<256; i++) { GLint blue = IROUND_POS(255.0 * _mesa_pow( hpcr_rgbTbl[2][i]/255.0, g )); v->hpcr_rgbTbl[2][i] = CLAMP( blue, 32, 223 ); } v->undithered_pf = PF_HPCR; /* can't really disable dithering for now */ v->dithered_pf = PF_HPCR; /* which method should I use to clear */ /* GL_FALSE: keep the ordinary method */ /* GL_TRUE : clear with dither pattern */ v->hpcr_clear_flag = _mesa_getenv("MESA_HPCR_CLEAR") ? GL_TRUE : GL_FALSE; if (v->hpcr_clear_flag) { v->hpcr_clear_pixmap = XMesaCreatePixmap(v->display, DefaultRootWindow(v->display), 16, 2, 8);#ifndef XFree86Server v->hpcr_clear_ximage = XGetImage(v->display, v->hpcr_clear_pixmap, 0, 0, 16, 2, AllPlanes, ZPixmap);#endif }}/* * Setup RGB rendering for a window with a True/DirectColor visual. */static void setup_truecolor( XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap ){ unsigned long rmask, gmask, bmask; (void) buffer; (void) cmap; /* Compute red multiplier (mask) and bit shift */ v->rshift = 0; rmask = GET_REDMASK(v); while ((rmask & 1)==0) { v->rshift++; rmask = rmask >> 1; } /* Compute green multiplier (mask) and bit shift */ v->gshift = 0; gmask = GET_GREENMASK(v); while ((gmask & 1)==0) { v->gshift++; gmask = gmask >> 1; } /* Compute blue multiplier (mask) and bit shift */ v->bshift = 0; bmask = GET_BLUEMASK(v); while ((bmask & 1)==0) { v->bshift++; bmask = bmask >> 1; } /* * Compute component-to-pixel lookup tables and dithering kernel */ { static GLubyte kernel[16] = { 0*16, 8*16, 2*16, 10*16, 12*16, 4*16, 14*16, 6*16, 3*16, 11*16, 1*16, 9*16, 15*16, 7*16, 13*16, 5*16, }; GLint rBits = _mesa_bitcount(rmask); GLint gBits = _mesa_bitcount(gmask); GLint bBits = _mesa_bitcount(bmask); GLint maxBits; GLuint i; /* convert pixel components in [0,_mask] to RGB values in [0,255] */ for (i=0; i<=rmask; i++) v->PixelToR[i] = (unsigned char) ((i * 255) / rmask); for (i=0; i<=gmask; i++) v->PixelToG[i] = (unsigned char) ((i * 255) / gmask); for (i=0; i<=bmask; i++) v->PixelToB[i] = (unsigned char) ((i * 255) / bmask); /* convert RGB values from [0,255] to pixel components */ for (i=0;i<256;i++) { GLint r = gamma_adjust(v->RedGamma, i, 255); GLint g = gamma_adjust(v->GreenGamma, i, 255); GLint b = gamma_adjust(v->BlueGamma, i, 255); v->RtoPixel[i] = (r >> (8-rBits)) << v->rshift; v->GtoPixel[i] = (g >> (8-gBits)) << v->gshift; v->BtoPixel[i] = (b >> (8-bBits)) << v->bshift; } /* overflow protection */ for (i=256;i<512;i++) { v->RtoPixel[i] = v->RtoPixel[255]; v->GtoPixel[i] = v->GtoPixel[255]; v->BtoPixel[i] = v->BtoPixel[255]; } /* setup dithering kernel */ maxBits = rBits; if (gBits > maxBits) maxBits = gBits; if (bBits > maxBits) maxBits = bBits; for (i=0;i<16;i++) { v->Kernel[i] = kernel[i] >> maxBits; } v->undithered_pf = PF_Truecolor; v->dithered_pf = (GET_VISUAL_DEPTH(v)<24) ? PF_Dither_True : PF_Truecolor; } /* * Now check for TrueColor visuals which we can optimize. */ if ( GET_REDMASK(v) ==0x0000ff && GET_GREENMASK(v)==0x00ff00 && GET_BLUEMASK(v) ==0xff0000 && CHECK_BYTE_ORDER(v) && v->BitsPerPixel==32 && sizeof(GLuint)==4 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* common 32 bpp config used on SGI, Sun */ v->undithered_pf = v->dithered_pf = PF_8A8B8G8R; } else if (GET_REDMASK(v) ==0xff0000 && GET_GREENMASK(v)==0x00ff00 && GET_BLUEMASK(v) ==0x0000ff && CHECK_BYTE_ORDER(v) && v->BitsPerPixel==32 && sizeof(GLuint)==4 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* common 32 bpp config used on Linux, HP, IBM */ if (GET_VISUAL_DEPTH(v)==32) v->undithered_pf = v->dithered_pf = PF_8A8R8G8B; else v->undithered_pf = v->dithered_pf = PF_8R8G8B; } else if (GET_REDMASK(v) ==0xff0000 && GET_GREENMASK(v)==0x00ff00 && GET_BLUEMASK(v) ==0x0000ff && CHECK_BYTE_ORDER(v) && v->BitsPerPixel==24 && sizeof(GLuint)==4 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* common packed 24 bpp config used on Linux */ v->undithered_pf = v->dithered_pf = PF_8R8G8B24; } else if (GET_REDMASK(v) ==0xf800 && GET_GREENMASK(v)==0x07e0 && GET_BLUEMASK(v) ==0x001f && CHECK_BYTE_ORDER(v) && v->BitsPerPixel==16 && sizeof(GLushort)==2 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* 5-6-5 color weight on common PC VGA boards */ v->undithered_pf = PF_5R6G5B; v->dithered_pf = PF_Dither_5R6G5B; } else if (GET_REDMASK(v) ==0xe0 && GET_GREENMASK(v)==0x1c && GET_BLUEMASK(v) ==0x03 && CHECK_FOR_HPCR(v)) { setup_8bit_hpcr( v ); }}/* * Setup RGB rendering for a window with a monochrome visual. */static void setup_monochrome( XMesaVisual v, XMesaBuffer b ){ (void) b; v->dithered_pf = v->undithered_pf = PF_1Bit; /* if black=1 then we must flip pixel values */ v->bitFlip = (GET_BLACK_PIXEL(v) != 0);}/* * When a context is "made current" for the first time, we can finally * finish initializing the context's visual and buffer information. * Input: v - the XMesaVisual to initialize * b - the XMesaBuffer to initialize (may be NULL) * rgb_flag - TRUE = RGBA mode, FALSE = color index mode * window - the window/pixmap we're rendering into * cmap - the colormap associated with the window/pixmap * Return: GL_TRUE=success, GL_FALSE=failure */static GLboolean initialize_visual_and_buffer( int client, XMesaVisual v, XMesaBuffer b, GLboolean rgb_flag, XMesaDrawable window, XMesaColormap cmap ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -