WindowDevice::~WindowDevice() { numWindowDevice--; #ifdef _UNIX if (winOpen == 0) { // we must close the old window XFreeGC(theDisplay, theGC); XDestroyWindow(theDisplay, theWindow); } if (numWindowDevice == 0) { if (colorFlag == 0 ) XFreeColors(theDisplay, cmap, pixels, 256, 0); else if (colorFlag == 1) XFreeColors(theDisplay, cmap, pixels, 192, 0); else if (colorFlag == 2) XFreeColors(theDisplay, cmap, pixels, 64, 0); XFreeColormap(theDisplay, cmap); XCloseDisplay(theDisplay); } #else if (winOpen == 0) { // we must close the window oglDestroyWindow(title,theWND, theHRC, theHDC); } #endif }
static vmResult X_video_restop(void) { XWindowAttributes attrs; // Save position, since mapping and unmapping // will let window manager re-position window // (we could just iconify it instead of unmapping it!) XGetWindowAttributes(x11_dpy, vwin, &attrs); vwin_size_hints->flags |= USPosition; vwin_size_hints->x = attrs.x; vwin_size_hints->y = attrs.y; XUnmapWindow(x11_dpy, vwin); // Free allocated colors if (using_palette && x11_cmap) { XFreeColors(x11_dpy, x11_cmap, cmap, 1, x11_planes[0]); XFreeColors(x11_dpy, x11_cmap, cmap + 16, 1, x11_planes[0]); } // Free custom colormap, if any if (x11_cmap && x11_cmap != DefaultColormap(x11_dpy, x11_screen)) XFreeColormap(x11_dpy, x11_cmap); x11_cmap = 0L; return vmOk; }
static void checkerboard (Screen *screen, Drawable drawable) { Display *dpy = DisplayOfScreen (screen); unsigned int x, y; int size = 24; XColor fg, bg; XGCValues gcv; GC gc = XCreateGC (dpy, drawable, 0, &gcv); Colormap cmap; unsigned int win_width, win_height; fg.flags = bg.flags = DoRed|DoGreen|DoBlue; fg.red = fg.green = fg.blue = 0x0000; bg.red = bg.green = bg.blue = 0x4444; fg.pixel = 0; bg.pixel = 1; if (drawable_window_p (dpy, drawable)) { XWindowAttributes xgwa; XGetWindowAttributes (dpy, drawable, &xgwa); win_width = xgwa.width; win_height = xgwa.height; cmap = xgwa.colormap; screen = xgwa.screen; } else /* it's a pixmap */ { XWindowAttributes xgwa; Window root; int x, y; unsigned int bw, d; XGetWindowAttributes (dpy, RootWindowOfScreen (screen), &xgwa); cmap = xgwa.colormap; XGetGeometry (dpy, drawable, &root, &x, &y, &win_width, &win_height, &bw, &d); } /* Allocate black and gray, but don't hold them locked. */ if (XAllocColor (dpy, cmap, &fg)) XFreeColors (dpy, cmap, &fg.pixel, 1, 0); if (XAllocColor (dpy, cmap, &bg)) XFreeColors (dpy, cmap, &bg.pixel, 1, 0); XSetForeground (dpy, gc, bg.pixel); XFillRectangle (dpy, drawable, gc, 0, 0, win_width, win_height); XSetForeground (dpy, gc, fg.pixel); for (y = 0; y < win_height; y += size+size) for (x = 0; x < win_width; x += size+size) { XFillRectangle (dpy, drawable, gc, x, y, size, size); XFillRectangle (dpy, drawable, gc, x+size, y+size, size, size); } XFreeGC (dpy, gc); }
void free_color() { unsigned long pixels[2]; pixels[0] = pixel(); XFreeColors ( disp, map, pixels, 1, 0 ); }
/****************************************************************************** * Routine to allocate the requested colors from the X server. * * Colors are allocated until success by stripping off the least bits of the * * colors. * ******************************************************************************/ static void AllocateColors1(void) { int Strip, Msk, i, j; char Msg[80]; for (i = 0; i < 256; i++) XPixelTable[i] = 0; /* Put reasonable color for out of range. */ for (Strip = 0, Msk = 0xff; Strip < 8; Strip++, Msk <<= 1) { for (i = 0; i < ColorMapSize; i++) { /* Prepere color entry in X format. */ XColorTable[i].red = (ColorMap[i].Red & Msk) << 8; XColorTable[i].green = (ColorMap[i].Green & Msk) << 8; XColorTable[i].blue = (ColorMap[i].Blue & Msk) << 8; XColorTable[i].flags = DoRed | DoGreen | DoBlue; if (XAllocColor(XDisplay, XColorMap, &XColorTable[i])) XPixelTable[i] = XColorTable[i].pixel; else break; } if (i < ColorMapSize) XFreeColors(XDisplay, XColorMap, XPixelTable, i, 0L); else break; } if (Strip == 8) GIF_EXIT("Can not display the image - not enough colors available."); if (Strip != 0) { sprintf(Msg, "%d bits were stripped off the color map.", Strip); GIF_MESSAGE(Msg); } }
void gl_mousepointer (int action) { if (action==2) hide_mouse ^= 1; else hide_mouse = action ? 1 : 0; if (hide_mouse) { /* hide */ Cursor no_ptr; Pixmap bm_no; XColor black, dummy; Colormap colormap; static char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; colormap = DefaultColormap (_gl_display, _gl_screen); if (!XAllocNamedColor (_gl_display, colormap, "black", &black, &dummy) ) return; bm_no = XCreateBitmapFromData (_gl_display, _gl_win, bm_no_data, 8, 8); no_ptr = XCreatePixmapCursor (_gl_display, bm_no, bm_no, &black, &black, 0, 0); XDefineCursor (_gl_display, _gl_win, no_ptr); XFreeCursor (_gl_display, no_ptr); if (bm_no != None) XFreePixmap (_gl_display, bm_no); XFreeColors (_gl_display,colormap, &black.pixel, 1, 0); } else { /* show */ XDefineCursor(_gl_display, _gl_win, 0); } }
CONDITION LoadGrayMap(int n) { int i; XColor colors; unsigned long grayvalue; unsigned long graypixels[256]; colors.flags = DoRed | DoGreen | DoBlue; for (i = 0; i < n; i++) { grayvalue = i * WHITE / (n - 1); colors.pixel = i; colors.red = colors.green = colors.blue = grayvalue << SHIFT_FACTOR; if (!XAllocColor(G_display, G_cmap, &colors)) { if (n <= MIN_USEFUL_AMT) { COND_PushCondition(DICOMXDISP_NOCOLORS, "%s", "DICOMXDISP: Cannot get enough colors"); return (DICOMXDISP_NOCOLORS); } XFreeColors(G_display, G_cmap, graypixels, i, 0); return (LoadGrayMap(i)); } else { graypixels[i] = colors.pixel; } } graylut[0] = graypixels[0]; for (i = 1; i < LOOKUP_ENTRIES; i++) graylut[i] = graypixels[i / (LOOKUP_ENTRIES / n)]; G_ncolors = n; return (DICOMXDISP_NORMAL); }
static inline void free_x11_colors(struct qp_plot *p, struct qp_graph *gr) { ASSERT(gr->x11); if(gr->x11) { if(!gr->x11->dsp) gr->x11->dsp = gdk_x11_get_default_xdisplay(); XFreeColors(gr->x11->dsp, DefaultColormap(gr->x11->dsp, DefaultScreen(gr->x11->dsp)), &p->l.x, 1, 0); XFreeColors(gr->x11->dsp, DefaultColormap(gr->x11->dsp, DefaultScreen(gr->x11->dsp)), &p->p.x, 1, 0); } }
static int try_get_grays(Colormap cmap, int ny) { XColor xcolor; int n_pixels; int y; xpixels = (unsigned long *)G_realloc(xpixels, ny * sizeof(unsigned long)); n_pixels = 0; xcolor.flags = DoRed | DoGreen | DoBlue; for (y = 0; y < ny; y++) { unsigned short v = (unsigned short)(y * 0xFFFF / (ny - 1)); xcolor.red = v; xcolor.green = v; xcolor.blue = v; if (!XAllocColor(dpy, cmap, &xcolor)) { XFreeColors(dpy, cmap, xpixels, n_pixels, (unsigned long)0); return y; } xpixels[n_pixels++] = xcolor.pixel; } return ny; }
void showCursor(Display *dpy, Window win, int show) { if(!show) { Pixmap bm_no; Colormap cmap; Cursor no_ptr; XColor black, dummy; char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; cmap = DefaultColormap(dpy, DefaultScreen(dpy)); XAllocNamedColor(dpy, cmap, "black", &black, &dummy); bm_no = XCreateBitmapFromData(dpy, win, bm_no_data, 8, 8); no_ptr = XCreatePixmapCursor(dpy, bm_no, bm_no, &black, &black, 0, 0); XDefineCursor(dpy, win, no_ptr); XFreeCursor(dpy, no_ptr); XFreePixmap(dpy, bm_no); XFreeColors(dpy, cmap, &black.pixel, 1, 0); } else { XDefineCursor(dpy, win, 0); } }
wxPaletteRefData::~wxPaletteRefData() { Display *display = (Display*) NULL; wxList::compatibility_iterator node, next; for (node = m_palettes.GetFirst(); node; node = next) { wxXPalette *c = (wxXPalette *)node->GetData(); unsigned long *pix_array = c->m_pix_array; Colormap cmap = (Colormap) c->m_cmap; bool destroyable = c->m_destroyable; int pix_array_n = c->m_pix_array_n; display = (Display*) c->m_display; if (pix_array_n > 0) { // XFreeColors(display, cmap, pix_array, pix_array_n, 0); // Be careful not to free '0' pixels... int i, j; for(i=j=0; i<pix_array_n; i=j) { while(j<pix_array_n && pix_array[j]!=0) j++; if(j > i) XFreeColors(display, cmap, &pix_array[i], j-i, 0); while(j<pix_array_n && pix_array[j]==0) j++; } delete [] pix_array; } if (destroyable) XFreeColormap(display, cmap); next = node->GetNext(); m_palettes.Erase(node); delete c; } }
void FreeColors(Display * display, Screen * screen, int numColors, unsigned long *pr) { Colormap cmap = XDefaultColormapOfScreen(screen); XFreeColors(display, cmap, pr, numColors, 0); }
static void destroyColorChanger( color_changer * ch ) { int q; for ( q = 0; q < ch->max; q++ ) XFreeColors( st->dpy, *cmap, &( ch->shade[q].pixel ), 1, 0 ); free( ch->shade ); }
static void _qsXColor_destroy(struct QsXColor *c) { XFreeColors(c->win->dsp, DefaultColormap(c->win->dsp, DefaultScreen(c->win->dsp)), &c->pixel, 1, 0); g_free(c); }
void free_GCs(void) { #ifdef USE_XPM /* free any colors from the xfig xpm icon (if used) */ if (xfig_icon_attr.npixels > 0) { XFreeColors(tool_d, tool_cm, xfig_icon_attr.pixels, xfig_icon_attr.npixels, (unsigned long) 0); } #endif /* USE_XPM */ XFreeGC(tool_d, border_gc); XFreeGC(tool_d, pic_gc); XFreeGC(tool_d, button_gc); XFreeGC(tool_d, fill_color_gc); XFreeGC(tool_d, pen_color_gc); XFreeGC(tool_d, ind_button_gc); XFreeGC(tool_d, ind_blank_gc); XFreeGC(tool_d, blank_gc); XFreeGC(tool_d, mouse_blank_gc); XFreeGC(tool_d, mouse_button_gc); XFreeGC(tool_d, tr_gc); XFreeGC(tool_d, tr_erase_gc); XFreeGC(tool_d, tr_xor_gc); XFreeGC(tool_d, sr_gc); XFreeGC(tool_d, sr_erase_gc); }
PixmapGraphic::~PixmapGraphic() { if (f_pixmap && (f_flag == NORMAL)) { XFreePixmap (window_system().display(), f_pixmap); if (f_colors) { XFreeColors (window_system().display(), f_colormap, f_colors, f_num_colors, 0 ); XFree (f_colors); #ifdef DEBUG printf( "pixmap %lx and its colors freed in PixmapGraphic %p\n", f_pixmap, this ); #endif } if (f_tiff_context) { #ifdef DEBUG printf( "pixmap %lx and TIFF context %p freed in PixmapGraphic %p\n", f_pixmap, f_tiff_context, this ); #endif _DtGrDestroyContext(f_tiff_context); delete f_tiff_context ; // free the struct memory we own } } assert(!f_agent); }
int GetNumAvailableColors(Display * display, Screen * screen, unsigned map_entries) { unsigned long pmr[1]; unsigned long pr[SPLASH_COLOR_MAP_SIZE]; unsigned nFailed, nAllocated, done = 0, nPlanes = 0; Colormap cmap; unsigned numColors = SPLASH_COLOR_MAP_SIZE; // never try allocating more than that if (numColors > map_entries) { numColors = map_entries; } cmap = XDefaultColormapOfScreen(screen); nAllocated = 0; /* lower bound */ nFailed = numColors + 1; /* upper bound */ /* Binary search to determine the number of available cells */ for (done = 0; !done;) { if (XAllocColorCells(display, cmap, 0, pmr, nPlanes, pr, numColors)) { nAllocated = numColors; XFreeColors(display, cmap, pr, numColors, 0); if (nAllocated < (nFailed - 1)) { numColors = (nAllocated + nFailed) / 2; } else done = 1; } else { nFailed = numColors; if (nFailed > (nAllocated + 1)) numColors = (nAllocated + nFailed) / 2; else done = 1; } } return nAllocated; }
void wTextureDestroy(WScreen * scr, WTexture * texture) { int i; int count = 0; unsigned long colors[8]; /* * some stupid servers don't like white or black being freed... */ #define CANFREE(c) (c!=scr->black_pixel && c!=scr->white_pixel && c!=0) switch (texture->any.type) { case WTEX_SOLID: XFreeGC(dpy, texture->solid.light_gc); XFreeGC(dpy, texture->solid.dark_gc); XFreeGC(dpy, texture->solid.dim_gc); if (CANFREE(texture->solid.light.pixel)) colors[count++] = texture->solid.light.pixel; if (CANFREE(texture->solid.dim.pixel)) colors[count++] = texture->solid.dim.pixel; if (CANFREE(texture->solid.dark.pixel)) colors[count++] = texture->solid.dark.pixel; break; case WTEX_PIXMAP: RReleaseImage(texture->pixmap.pixmap); break; case WTEX_MHGRADIENT: case WTEX_MVGRADIENT: case WTEX_MDGRADIENT: for (i = 0; texture->mgradient.colors[i] != NULL; i++) { wfree(texture->mgradient.colors[i]); } wfree(texture->mgradient.colors); break; case WTEX_THGRADIENT: case WTEX_TVGRADIENT: case WTEX_TDGRADIENT: RReleaseImage(texture->tgradient.pixmap); break; } if (CANFREE(texture->any.color.pixel)) colors[count++] = texture->any.color.pixel; if (count > 0) { XErrorHandler oldhandler; /* ignore error from buggy servers that don't know how * to do reference counting for colors. */ XSync(dpy, 0); oldhandler = XSetErrorHandler(dummyErrorHandler); XFreeColors(dpy, scr->w_colormap, colors, count, 0); XSync(dpy, 0); XSetErrorHandler(oldhandler); } XFreeGC(dpy, texture->any.gc); wfree(texture); #undef CANFREE }
/////////////////////////////////////////////////////////////////////// /// Function: Free /// /// Author: $author$ /// Date: 4/25/2012 /////////////////////////////////////////////////////////////////////// virtual XosError Free (bool onlyAllocatred=false) { XosError error = XOS_ERROR_FAILED; Pixel detached; int err; if ((detached = Detach())) { if ((m_xDisplay) && (None != (m_xColormap))) { XFreeColors(m_xDisplay, m_xColormap, &detached, 1, 0); error = XOS_ERROR_NONE; } } else if ((onlyAllocatred)) error = XOS_ERROR_FAILED; else error = XOS_ERROR_NONE; m_xColormap = None; m_xDisplay = 0; return error; }
static int try_get_colors(Colormap cmap, int nr, int ng, int nb) { XColor xcolor; int n_pixels; int r, g, b; xpixels = (unsigned long *)G_realloc(xpixels, nr * ng * nb * sizeof(unsigned long)); n_pixels = 0; xcolor.flags = DoRed | DoGreen | DoBlue; for (r = 0; r < nr; r++) { for (g = 0; g < ng; g++) { for (b = 0; b < nb; b++) { xcolor.red = (unsigned short)(r * 0xFFFF / (nr - 1)); xcolor.green = (unsigned short)(g * 0xFFFF / (ng - 1)); xcolor.blue = (unsigned short)(b * 0xFFFF / (nb - 1)); if (!XAllocColor(dpy, cmap, &xcolor)) { XFreeColors(dpy, cmap, xpixels, n_pixels, (unsigned long)0); return 0; } xpixels[n_pixels++] = xcolor.pixel; } } } return 1; }
void str_color(char *str, XColor *c) { XColor newcolor, dummy; if(XAllocNamedColor(dpy, colormap, str, &newcolor, &dummy)) { if(!first) XFreeColors(dpy, colormap, &c->pixel, 1, 0); *c = newcolor; } }
void de_free_colour(WRootWin *rootwin, DEColour col) { DEColour pixels[1]; pixels[0]=col; XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 1, 0); }
void mainwin_destroy(MainWin *mw) { if(mw->tooltip) tooltip_destroy(mw->tooltip); if(! mw->no_free_color) XFreeColors(mw->dpy, mw->colormap, mw->pixels, 2, 0); else { if(! (mw->no_free_color & 1)) XFreeColors(mw->dpy, mw->colormap, &BORDER_COLOR(mw), 1, 0); if(! (mw->no_free_color & 2)) XFreeColors(mw->dpy, mw->colormap, &HIGHLIGHT_COLOR(mw), 1, 0); } if(mw->cm_highlight) { imlib_context_set_color_modifier(mw->cm_highlight); imlib_free_color_modifier(); } if(mw->cm_normal) { imlib_context_set_color_modifier(mw->cm_normal); imlib_free_color_modifier(); } if(mw->background) { imlib_context_set_image(mw->background); imlib_free_image(); } if(mw->bg_pixmap != None) imlib_free_pixmap_and_mask(mw->bg_pixmap); XDestroyWindow(mw->dpy, mw->window); #ifdef XINERAMA if(mw->xin_info) XFree(mw->xin_info); #endif /* XINERAMA */ free(mw); }
/* Re-pick the colors of the text and border */ static void recolor (state *s, sentence *se) { if (se->fg.flags) XFreeColors (s->dpy, s->xgwa.colormap, &se->fg.pixel, 1, 0); if (se->bg.flags) XFreeColors (s->dpy, s->xgwa.colormap, &se->bg.pixel, 1, 0); se->fg.flags = DoRed|DoGreen|DoBlue; se->bg.flags = DoRed|DoGreen|DoBlue; switch (random() % 2) { case 0: /* bright fg, dim bg */ se->fg.red = (random() % 0x8888) + 0x8888; se->fg.green = (random() % 0x8888) + 0x8888; se->fg.blue = (random() % 0x8888) + 0x8888; se->bg.red = (random() % 0x5555); se->bg.green = (random() % 0x5555); se->bg.blue = (random() % 0x5555); break; case 1: /* bright bg, dim fg */ se->fg.red = (random() % 0x4444); se->fg.green = (random() % 0x4444); se->fg.blue = (random() % 0x4444); se->bg.red = (random() % 0x4444) + 0xCCCC; se->bg.green = (random() % 0x4444) + 0xCCCC; se->bg.blue = (random() % 0x4444) + 0xCCCC; break; default: abort(); break; } if (s->debug_p) se->dark_p = (se->fg.red*2 + se->fg.green*3 + se->fg.blue < se->bg.red*2 + se->bg.green*3 + se->bg.blue); if (XAllocColor (s->dpy, s->xgwa.colormap, &se->fg)) XSetForeground (s->dpy, se->fg_gc, se->fg.pixel); if (XAllocColor (s->dpy, s->xgwa.colormap, &se->bg)) XSetBackground (s->dpy, se->fg_gc, se->bg.pixel); }
static void free_sentence (state *s, sentence *se) { int i; for (i = 0; i < se->nwords; i++) free_word (s, se->words[i]); if (se->words) free (se->words); if (se->fg.flags) XFreeColors (s->dpy, s->xgwa.colormap, &se->fg.pixel, 1, 0); if (se->bg.flags) XFreeColors (s->dpy, s->xgwa.colormap, &se->bg.pixel, 1, 0); if (se->font_name) free (se->font_name); if (se->font) XFreeFont (s->dpy, se->font); if (se->fg_gc) XFreeGC (s->dpy, se->fg_gc); free (se); }
void close_x_dialog (Display *dpy) { if (!_dlg_mwin) { assert(!_dlg_swin); return; } XUngrabPointer (dpy, CurrentTime); XUngrabKeyboard (dpy, CurrentTime); XSync (dpy, False); close_x_dialog_win(dpy, &_dlg_mwin); close_x_dialog_win(dpy, &_dlg_swin); Colormap colormap = DefaultColormap (dpy, DefaultScreen (dpy)); XFreeColors (dpy, colormap, &_c_gray1.pixel, 1, 0); XFreeColors (dpy, colormap, &_c_gray2.pixel, 1, 0); if (_dlgfont != None) XUnloadFont(dpy, _dlgfont); _dlgfont = None; force_redraw = 1; }
static void unlockscreen(Display *dpy, Lock *lock) { if(dpy == NULL || lock == NULL) return; XUngrabPointer(dpy, CurrentTime); XFreeColors(dpy, DefaultColormap(dpy, lock->screen), lock->colors, 2, 0); XFreePixmap(dpy, lock->pmap); XDestroyWindow(dpy, lock->win); free(lock); }
/**************************************************************************** * * Free an array of colours (n colours), never free black * ****************************************************************************/ void FreeColors(Pixel *pixels, int n) { int i; /* We don't ever free black - dirty hack to allow freeing colours at all */ for (i = 0; i < n; i++) { if (pixels[i] != 0) XFreeColors(dpy, Pcmap, pixels + i, 1, 0); } }
static void FreeX11ColorCells( int beg, /* First color cell to free. */ int end /* Last color cell to free. */ ) { int i; Colormap colormap = DefaultColormap(gDisplay, DefaultScreen(gDisplay)); for (i=beg; i<end; i++) { XFreeColors(gDisplay, colormap, &(gFiTable[i].xColor.pixel), 1, 0); } }
void de_free_colour(WRootWin *rootwin, DEColour col) { #ifdef HAVE_X11_XFT XftColorFree(ioncore_g.dpy, XftDEDefaultVisual(), rootwin->default_cmap, &col); #else /* HAVE_X11_XFT */ DEColour pixels[1]; pixels[0]=col; XFreeColors(ioncore_g.dpy, rootwin->default_cmap, pixels, 1, 0); #endif /* HAVE_X11_XFT */ }