scx/c/xlib/color.c

109 lines
2.7 KiB
C
Raw Normal View History

2001-05-08 10:21:00 -04:00
#include "xlib.h"
#include "scheme48.h"
s48_value Create_Color(s48_value r, s48_value g, s48_value b) {
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
}
s48_value Int_Extract_RGB_Values(XColor col) {
s48_value res = S48_NULL;
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(res);
res = s48_cons( s48_enter_integer(col.red), res );
res = s48_cons( s48_enter_integer(col.green), res );
res = s48_cons( s48_enter_integer(col.blue), res );
S48_GC_UNPROTECT();
return res;
2001-05-08 10:21:00 -04:00
}
s48_value Extract_RGB_Values(s48_value Xcolor) {
XColor* col = EXTRACT_COLOR(Xcolor);
return Int_Extract_RGB_Values(*col);
2001-05-08 10:21:00 -04:00
}
s48_value Query_Color (s48_value Xcolormap, s48_value Xpixel,
s48_value Xdisplay) {
XColor c;
Colormap cm = EXTRACT_COLORMAP(Xcolormap);
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
c.pixel = EXTRACT_PIXEL(Xpixel);
XQueryColor(dpy, cm, &c);
return Int_Extract_RGB_Values(c);
2001-05-08 10:21:00 -04:00
}
/*
s48_value Query_Colors(s48_value Xcolormap, s48_value Xpixels,
s48_value Xdisplay) {
Colormap* cm = (Colormap*)S48_EXTRACT_VALUE_POINTER(Xcolormap, Colormap);
Display* dpy = (Display*)s48_extract_integer(Xdisplay);
2001-05-08 10:21:00 -04:00
long l = S48_VECTOR_LENGTH(Xpixels);
2001-05-08 10:21:00 -04:00
register i, n;
s48_value ret;
2001-05-08 10:21:00 -04:00
register XColor *p;
S48_DECLARE_GC_PROTECT(1);
2001-05-08 10:21:00 -04:00
Alloca_Begin;
Check_Type (v, T_Vector);
n = S48_VECTOR_LENGTH(v);
2001-05-08 10:21:00 -04:00
Alloca (p, XColor*, n * sizeof (XColor));
for (i = 0; i < n; i++)
p[i].pixel = Get_Pixel (VECTOR(v)->data[i]);
Disable_Interrupts;
XQueryColors (COLORMAP(cmap)->dpy, cm, p, n);
Enable_Interrupts;
ret = s48_make_vector (n, S48_NULL);
S48_GC_PROTECT_1 (ret);
2001-05-08 10:21:00 -04:00
for (i = 0; i < n; i++, p++) {
s48_value x;
2001-05-08 10:21:00 -04:00
x = Make_Color (p->red, p->green, p->blue);
S48_VECTOR_SET(ret, i, x;)
2001-05-08 10:21:00 -04:00
}
S48_GC_UNPROTECT;
2001-05-08 10:21:00 -04:00
Alloca_End;
return ret;
}
*/
s48_value Lookup_Color(s48_value Xcolormap, s48_value Xdisplay,
s48_value color_name) {
XColor visual, exact;
Colormap cm = EXTRACT_COLORMAP(Xcolormap);
Display* dpy = EXTRACT_DISPLAY(Xdisplay);
s48_value res = S48_FALSE;
S48_DECLARE_GC_PROTECT(1);
S48_GC_PROTECT_1(res);
if (XLookupColor( dpy, cm, s48_extract_string(color_name),
&visual, &exact )) {
res = s48_cons( Int_Extract_RGB_Values( visual ),
Int_Extract_RGB_Values( exact ) );
}
S48_GC_UNPROTECT();
return res;
2001-05-08 10:21:00 -04:00
}
void s48_init_color(void) {
S48_EXPORT_FUNCTION(Create_Color);
S48_EXPORT_FUNCTION(Extract_RGB_Values);
S48_EXPORT_FUNCTION(Query_Color);
// S48_EXPORT_FUNCTION(Query_Colors);
S48_EXPORT_FUNCTION(Lookup_Color);
2001-05-08 10:21:00 -04:00
}