2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
2001-06-11 11:25:39 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Create_Color(s48_value r, s48_value g, s48_value b) {
|
2001-06-11 11:25:39 -04:00
|
|
|
s48_value col = S48_MAKE_VALUE(XColor);
|
|
|
|
XColor* c = S48_EXTRACT_VALUE_POINTER(col, XColor);
|
|
|
|
c->red = s48_extract_integer(r);
|
|
|
|
c->green = s48_extract_integer(g);
|
|
|
|
c->blue = s48_extract_integer(b);
|
|
|
|
|
|
|
|
return col;
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Int_Extract_RGB_Values(XColor col) {
|
2001-06-11 11:25:39 -04:00
|
|
|
s48_value res = S48_NULL;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
S48_GC_PROTECT_1(res);
|
|
|
|
|
|
|
|
res = s48_cons( s48_enter_integer(col.blue), res );
|
2001-06-25 07:46:06 -04:00
|
|
|
res = s48_cons( s48_enter_integer(col.green), res );
|
|
|
|
res = s48_cons( s48_enter_integer(col.red), res );
|
2001-06-11 11:25:39 -04:00
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return res;
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Extract_RGB_Values(s48_value Xcolor) {
|
|
|
|
return scx_Int_Extract_RGB_Values(*SCX_EXTRACT_COLOR(Xcolor));
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Query_Color (s48_value Xcolormap, s48_value Xpixel,
|
|
|
|
s48_value Xdisplay) {
|
2001-06-11 11:25:39 -04:00
|
|
|
XColor c;
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
c.pixel = SCX_EXTRACT_PIXEL(Xpixel);
|
|
|
|
XQueryColor(SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap),
|
|
|
|
&c);
|
2001-06-11 11:25:39 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
return scx_Int_Extract_RGB_Values(c);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-06-27 09:44:48 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Query_Colors(s48_value Xcolormap, s48_value Xpixels,
|
|
|
|
s48_value Xdisplay) {
|
|
|
|
s48_value result = S48_FALSE;
|
2001-06-27 09:44:48 -04:00
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-27 09:44:48 -04:00
|
|
|
long n = S48_VECTOR_LENGTH(Xpixels);
|
|
|
|
XColor p[n];
|
|
|
|
int i;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-27 09:44:48 -04:00
|
|
|
for (i=0; i < n; i++)
|
2001-07-31 10:51:21 -04:00
|
|
|
p[i].pixel = SCX_EXTRACT_PIXEL(S48_VECTOR_REF(Xpixels, i));
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
XQueryColors( SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap), p, n );
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-27 09:44:48 -04:00
|
|
|
S48_GC_PROTECT_1(result);
|
|
|
|
result = s48_make_vector(n, S48_FALSE);
|
|
|
|
for (i=0; i < n; i++)
|
2001-07-31 10:51:21 -04:00
|
|
|
S48_VECTOR_SET(result, i, scx_Int_Extract_RGB_Values(p[i]));
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-06-27 09:44:48 -04:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-11 11:25:39 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Lookup_Color(s48_value Xcolormap, s48_value Xdisplay,
|
|
|
|
s48_value color_name) {
|
2001-06-11 11:25:39 -04:00
|
|
|
XColor visual, exact;
|
|
|
|
|
|
|
|
s48_value res = S48_FALSE;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
if (XLookupColor( SCX_EXTRACT_DISPLAY(Xdisplay),
|
|
|
|
SCX_EXTRACT_COLORMAP(Xcolormap),
|
2001-06-27 09:44:48 -04:00
|
|
|
s48_extract_string(color_name), &visual, &exact )) {
|
|
|
|
S48_GC_PROTECT_1(res);
|
2002-02-08 12:09:43 -05:00
|
|
|
res = scx_Int_Extract_RGB_Values( visual );
|
|
|
|
res = s48_cons(res, scx_Int_Extract_RGB_Values( exact ) );
|
2001-06-11 11:25:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return res;
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
void scx_init_color(void) {
|
|
|
|
S48_EXPORT_FUNCTION(scx_Create_Color);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Extract_RGB_Values);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Query_Color);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Query_Colors);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Lookup_Color);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|