2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
2001-06-11 11:25:39 -04:00
|
|
|
#include "scheme48.h"
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Free_Colormap (s48_value Xcolormap, s48_value Xdisplay) {
|
|
|
|
XFreeColormap(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap));
|
2001-06-11 11:25:39 -04:00
|
|
|
return S48_UNSPECIFIC;
|
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Alloc_Color(s48_value Xcolormap, s48_value Xcolor,
|
|
|
|
s48_value Xdisplay) {
|
|
|
|
XColor* cp = SCX_EXTRACT_COLOR(Xcolor);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
if (!XAllocColor(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap), cp))
|
2001-06-27 09:44:48 -04:00
|
|
|
return S48_FALSE;
|
|
|
|
else
|
2001-07-31 10:51:21 -04:00
|
|
|
return SCX_ENTER_PIXEL(cp->pixel);
|
2001-06-11 11:25:39 -04:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Alloc_Named_Color(s48_value Xcolormap, s48_value color_name,
|
|
|
|
s48_value Xdisplay) {
|
2001-06-11 11:25:39 -04:00
|
|
|
XColor screen, exact;
|
|
|
|
int r;
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value ret = S48_FALSE;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-11 11:25:39 -04:00
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
r = XAllocNamedColor (SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap),
|
2001-06-27 09:44:48 -04:00
|
|
|
s48_extract_string(color_name),
|
2001-06-11 11:25:39 -04:00
|
|
|
&screen, &exact);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
if (r) {
|
2001-06-27 09:44:48 -04:00
|
|
|
S48_GC_PROTECT_1(ret);
|
2001-07-31 10:51:21 -04:00
|
|
|
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);
|
2001-06-27 09:44:48 -04:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-11 11:25:39 -04:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return ret;
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-08-22 10:51:06 -04:00
|
|
|
// swaped from util.c to this file
|
|
|
|
|
|
|
|
s48_value scx_Parse_Color (s48_value Xdpy, s48_value cmap, s48_value spec) {
|
2001-08-29 10:54:26 -04:00
|
|
|
XColor ret;
|
|
|
|
|
|
|
|
if (XParseColor (SCX_EXTRACT_DISPLAY(Xdpy),
|
|
|
|
SCX_EXTRACT_COLORMAP(cmap),
|
|
|
|
s48_extract_string(spec),
|
2001-10-09 11:31:33 -04:00
|
|
|
&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;
|
|
|
|
}
|
2001-08-29 10:54:26 -04:00
|
|
|
return S48_FALSE;
|
2001-08-22 10:51:06 -04:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-09-20 10:41:01 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-09 11:31:33 -04:00
|
|
|
s48_value scx_Store_Color(s48_value Xdisplay, s48_value Xcolormap,
|
|
|
|
s48_value Xpixel, s48_value Xcolor,
|
|
|
|
s48_value flags) {
|
2001-09-20 10:41:01 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-09 11:31:33 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
void scx_init_colormap(void) {
|
|
|
|
S48_EXPORT_FUNCTION(scx_Free_Colormap);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Alloc_Color);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Alloc_Named_Color);
|
2001-08-29 10:54:26 -04:00
|
|
|
S48_EXPORT_FUNCTION(scx_Parse_Color);
|
2001-09-20 10:41:01 -04:00
|
|
|
S48_EXPORT_FUNCTION(scx_Create_Colormap);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Alloc_Color_Cells);
|
2001-10-09 11:31:33 -04:00
|
|
|
S48_EXPORT_FUNCTION(scx_Store_Color);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Store_Colors);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Copy_Colormap_And_Free);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|