scx/c/xlib/colormap.c

64 lines
1.6 KiB
C

#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))
return scx_Create_Color (ret.red, ret.green, ret.blue);
return S48_FALSE;
}
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);
}