#include "xlib.h" #include "scheme48.h" s48_value scx_Free_Colormap (s48_value Xcolormap, s48_value Xdisplay) { XFreeColormap(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap)); return S48_UNSPECIFIC; } s48_value scx_Alloc_Color(s48_value Xcolormap, s48_value Xcolor, s48_value Xdisplay) { XColor* cp = SCX_EXTRACT_COLOR(Xcolor); if (!XAllocColor(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap), cp)) return S48_FALSE; else return SCX_ENTER_PIXEL(cp->pixel); } s48_value scx_Alloc_Named_Color(s48_value Xcolormap, s48_value color_name, s48_value Xdisplay) { XColor screen, exact; int r; s48_value ret = S48_FALSE; S48_DECLARE_GC_PROTECT(1); r = XAllocNamedColor (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap), s48_extract_string(color_name), &screen, &exact); if (r) { S48_GC_PROTECT_1(ret); ret = s48_cons(scx_Int_Extract_RGB_Values(exact), S48_NULL); ret = s48_cons(scx_Int_Extract_RGB_Values(screen), ret); ret = s48_cons(SCX_ENTER_PIXEL(screen.pixel), ret); } S48_GC_UNPROTECT(); return ret; } // swaped from util.c to this file s48_value scx_Parse_Color (s48_value Xdpy, s48_value cmap, s48_value spec) { XColor ret; if (XParseColor (SCX_EXTRACT_DISPLAY(Xdpy), SCX_EXTRACT_COLORMAP(cmap), s48_extract_string(spec), &ret)) { s48_value res = s48_make_vector(3, S48_FALSE); S48_DECLARE_GC_PROTECT(1); S48_GC_PROTECT_1(res); S48_VECTOR_SET(res, 0, s48_enter_integer(ret.red)); S48_VECTOR_SET(res, 1, s48_enter_integer(ret.green)); S48_VECTOR_SET(res, 2, s48_enter_integer(ret.blue)); S48_GC_UNPROTECT(); return res; } return S48_FALSE; } s48_value scx_Create_Colormap (s48_value Xdisplay, s48_value Xwindow, s48_value Xvisual, s48_value alloc) { Colormap cm = XCreateColormap( SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_WINDOW(Xwindow), SCX_EXTRACT_VISUAL(Xvisual), S48_FALSE_P(alloc) ? AllocNone : AllocAll ); return SCX_ENTER_COLORMAP(cm); } s48_value scx_Alloc_Color_Cells (s48_value Xdisplay, s48_value Xcolormap, s48_value contig, s48_value nplanes, s48_value npixels) { int npl = s48_extract_integer(nplanes); int npx = s48_extract_integer(npixels); unsigned long plane_masks[npl]; unsigned long pixels[npx]; s48_value pls = S48_FALSE, pxs = S48_FALSE; S48_DECLARE_GC_PROTECT(2); if (XAllocColorCells(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap), !S48_FALSE_P(contig), plane_masks, npl, pixels, npx)) { int i; pls = s48_make_vector(npl, S48_FALSE); pxs = s48_make_vector(npx, S48_FALSE); S48_GC_PROTECT_2(pls, pxs); for (i = 0; i < npl; i++) S48_VECTOR_SET(pls, i, s48_enter_integer(plane_masks[i])); for (i = 0; i < npx; i++) S48_VECTOR_SET(pxs, i, s48_enter_integer(pixels[i])); S48_GC_UNPROTECT(); return s48_cons(pls, pxs); } else return S48_FALSE; } s48_value scx_Store_Color(s48_value Xdisplay, s48_value Xcolormap, s48_value Xpixel, s48_value Xcolor, s48_value flags) { XColor t; XColor* c; c = SCX_EXTRACT_COLOR(Xcolor); t.pixel = SCX_EXTRACT_PIXEL(Xpixel); t.red = c->red; t.green = c->green; t.blue = c->blue; t.flags = Symbols_To_Bits(flags, Color_Flags_Syms); XStoreColor(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap), &t); return S48_UNSPECIFIC; } s48_value scx_Store_Colors(s48_value Xdisplay, s48_value Xcolormap, s48_value cells) { int n = S48_VECTOR_LENGTH(cells); XColor colors[n]; XColor* c; int i; for (i = 0; i < n; i++) { s48_value def = S48_VECTOR_REF(cells, i); colors[i].pixel = SCX_EXTRACT_PIXEL(S48_VECTOR_REF(def, 0)); c = SCX_EXTRACT_COLOR(S48_VECTOR_REF(def, 1)); colors[i].red = c->red; colors[i].green = c->green; colors[i].blue = c->blue; colors[i].flags = Symbols_To_Bits(S48_VECTOR_REF(def, 2), Color_Flags_Syms); } XStoreColors(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap), colors, n); return S48_UNSPECIFIC; } s48_value scx_Copy_Colormap_And_Free(s48_value Xdisplay, s48_value Xcolormap) { Colormap cm = XCopyColormapAndFree(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_COLORMAP(Xcolormap)); return SCX_ENTER_COLORMAP(cm); } void scx_init_colormap(void) { S48_EXPORT_FUNCTION(scx_Free_Colormap); S48_EXPORT_FUNCTION(scx_Alloc_Color); S48_EXPORT_FUNCTION(scx_Alloc_Named_Color); S48_EXPORT_FUNCTION(scx_Parse_Color); S48_EXPORT_FUNCTION(scx_Create_Colormap); S48_EXPORT_FUNCTION(scx_Alloc_Color_Cells); S48_EXPORT_FUNCTION(scx_Store_Color); S48_EXPORT_FUNCTION(scx_Store_Colors); S48_EXPORT_FUNCTION(scx_Copy_Colormap_And_Free); }