📄 xm_api.c
字号:
{ /* 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 voidsetup_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 && 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; /* ABGR */ } else if (GET_REDMASK(v) == 0xff0000 && GET_GREENMASK(v)== 0x00ff00 && GET_BLUEMASK(v) == 0x0000ff && CHECK_BYTE_ORDER(v) && v->RedGamma == 1.0 && v->GreenGamma == 1.0 && v->BlueGamma == 1.0){ if (v->BitsPerPixel==32) { /* if 32 bpp, and visual indicates 8 bpp alpha channel */ if (GET_VISUAL_DEPTH(v) == 32 && v->mesa_visual.alphaBits == 8) v->undithered_pf = v->dithered_pf = PF_8A8R8G8B; /* ARGB */ else v->undithered_pf = v->dithered_pf = PF_8R8G8B; /* xRGB */ } else if (v->BitsPerPixel == 24) { v->undithered_pf = v->dithered_pf = PF_8R8G8B24; /* RGB */ } } else if (GET_REDMASK(v) ==0xf800 && GET_GREENMASK(v)==0x07e0 && GET_BLUEMASK(v) ==0x001f && CHECK_BYTE_ORDER(v) && v->BitsPerPixel==16 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* 5-6-5 RGB */ 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)) { /* 8-bit HP color recovery */ setup_8bit_hpcr( v ); }}/** * Setup RGB rendering for a window with a monochrome visual. */static voidsetup_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 bound for the first time, we can finally finish * initializing the context's visual and buffer information. * \param v the XMesaVisual to initialize * \param b the XMesaBuffer to initialize (may be NULL) * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode * \param window the window/pixmap we're rendering into * \param cmap the colormap associated with the window/pixmap * \return GL_TRUE=success, GL_FALSE=failure */static GLbooleaninitialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, GLboolean rgb_flag, XMesaDrawable window, XMesaColormap cmap){ int client = 0;#ifdef XFree86Server client = (window) ? CLIENT_ID(window->id) : 0;#endif ASSERT(!b || b->xm_visual == v); /* Save true bits/pixel */ v->BitsPerPixel = bits_per_pixel(v); assert(v->BitsPerPixel > 0); if (rgb_flag == GL_FALSE) { /* COLOR-INDEXED WINDOW: * Even if the visual is TrueColor or DirectColor we treat it as * being color indexed. This is weird but might be useful to someone. */ v->dithered_pf = v->undithered_pf = PF_Index; v->mesa_visual.indexBits = GET_VISUAL_DEPTH(v); } else { /* RGB WINDOW: * We support RGB rendering into almost any kind of visual. */ const int xclass = v->mesa_visual.visualType; if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { setup_truecolor( v, b, cmap ); } else if (xclass == GLX_STATIC_GRAY && GET_VISUAL_DEPTH(v) == 1) { setup_monochrome( v, b ); } else if (xclass == GLX_GRAY_SCALE || xclass == GLX_STATIC_GRAY) { if (!setup_grayscale( client, v, b, cmap )) { return GL_FALSE; } } else if ((xclass == GLX_PSEUDO_COLOR || xclass == GLX_STATIC_COLOR) && GET_VISUAL_DEPTH(v)>=4 && GET_VISUAL_DEPTH(v)<=16) { if (!setup_dithered_color( client, v, b, cmap )) { return GL_FALSE; } } else { _mesa_warning(NULL, "XMesa: RGB mode rendering not supported in given visual.\n"); return GL_FALSE; } v->mesa_visual.indexBits = 0; if (_mesa_getenv("MESA_NO_DITHER")) { v->dithered_pf = v->undithered_pf; } } /* * If MESA_INFO env var is set print out some debugging info * which can help Brian figure out what's going on when a user * reports bugs. */ if (_mesa_getenv("MESA_INFO")) { _mesa_printf("X/Mesa visual = %p\n", (void *) v); _mesa_printf("X/Mesa dithered pf = %u\n", v->dithered_pf); _mesa_printf("X/Mesa undithered pf = %u\n", v->undithered_pf); _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level); _mesa_printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v)); _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); } if (b && window) { char *data; /* Do window-specific initializations */ /* these should have been set in create_xmesa_buffer */ ASSERT(b->frontxrb->drawable == window); ASSERT(b->frontxrb->pixmap == (XMesaPixmap) window); /* Setup for single/double buffering */ if (v->mesa_visual.doubleBufferMode) { /* Double buffered */ b->shm = check_for_xshm( v->display ); } /* X11 graphics contexts */#ifdef XFree86Server b->gc = CreateScratchGC(v->display, window->depth);#else b->gc = XCreateGC( v->display, window, 0, NULL );#endif XMesaSetFunction( v->display, b->gc, GXcopy ); /* cleargc - for glClear() */#ifdef XFree86Server b->cleargc = CreateScratchGC(v->display, window->depth);#else b->cleargc = XCreateGC( v->display, window, 0, NULL );#endif XMesaSetFunction( v->display, b->cleargc, GXcopy ); /* * Don't generate Graphics Expose/NoExpose events in swapbuffers(). * Patch contributed by Michael Pichler May 15, 1995. */#ifdef XFree86Server b->swapgc = CreateScratchGC(v->display, window->depth); { CARD32 v[1]; v[0] = FALSE; dixChangeGC(NullClient, b->swapgc, GCGraphicsExposures, v, NULL); }#else { XGCValues gcvalues; gcvalues.graphics_exposures = False; b->swapgc = XCreateGC(v->display, window, GCGraphicsExposures, &gcvalues); }#endif XMesaSetFunction( v->display, b->swapgc, GXcopy ); /* * Set fill style and tile pixmap once for all for HPCR stuff * (instead of doing it each time in clear_color_HPCR_pixmap()) * Initialize whole stuff * Patch contributed by Jacques Leroy March 8, 1998. */ if (v->hpcr_clear_flag && b->backxrb && b->backxrb->pixmap) { int i; for (i = 0; i < 16; i++) { XMesaPutPixel(v->hpcr_clear_ximage, i, 0, 0); XMesaPutPixel(v->hpcr_clear_ximage, i, 1, 0); } XMesaPutImage(b->display, (XMesaDrawable) v->hpcr_clear_pixmap, b->cleargc, v->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2); XMesaSetFillStyle( v->display, b->cleargc, FillTiled); XMesaSetTile( v->display, b->cleargc, v->hpcr_clear_pixmap ); } /* Initialize the row buffer XImage for use in write_color_span() */ data = (char*) MALLOC(MAX_WIDTH*4);#ifdef XFree86Server b->rowimage = XMesaCreateImage(GET_VISUAL_DEPTH(v), MAX_WIDTH, 1, data);#else b->rowimage = XCreateImage( v->display, v->visinfo->visual, v->visinfo->depth, ZPixmap, 0, /*format, offset*/ data, /*data*/ MAX_WIDTH, 1, /*width, height*/ 32, /*bitmap_pad*/ 0 /*bytes_per_line*/ );#endif if (!b->rowimage) return GL_FALSE; } return GL_TRUE;}/* * Convert an RGBA color to a pixel value. */unsigned longxmesa_color_to_pixel(GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLuint pixelFormat){ XMesaContext xmesa = XMESA_CONTEXT(ctx); switch (pixelFormat) { case PF_Index: return 0; case PF_Truecolor: { unsigned long p; PACK_TRUECOLOR( p, r, g, b ); return p; } case PF_8A8B8G8R: return PACK_8A8B8G8R( r, g, b, a ); case PF_8A8R8G8B: return PACK_8A8R8G8B( r, g, b, a ); case PF_8R8G8B: /* fall through */ case PF_8R8G8B24: return PACK_8R8G8B( r, g, b ); case PF_5R6G5B: return PACK_5R6G5B( r, g, b ); case PF_Dither: { DITHER_SETUP; return DITHER( 1, 0, r, g, b ); } case PF_1Bit: /* 382 = (3*255)/2 */ return ((r+g+b) > 382) ^ xmesa->xm_visual->bitFlip; case PF_HPCR: return DITHER_HPCR(1, 1, r, g, b); case PF_Lookup: { LOOKUP_SETUP; return LOOKUP( r, g, b ); } case PF_Grayscale: return GRAY_RGB( r, g, b );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -