#include "../xlib/xlib.h" #include /*void ExtractColorsymbols(s48_value v, XpmColorSymbols** CS, unsigned int* n) { int i; int len = S48_VECTOR_LENGTH */ void Attribs_To_XpmAttributes(s48_value attribs, XpmAttributes* XA) { unsigned long mask = s48_extract_integer(S48_CAR(attribs)); s48_value v = S48_CDR(attribs); if (mask & XpmVisual) XA->visual = SCX_EXTRACT_VISUAL(v); if (mask & XpmColormap) XA->colormap = SCX_EXTRACT_COLORMAP(v); if (mask & XpmDepth) XA->depth = s48_extract_integer(v); if ((mask & XpmReturnPixels) && (S48_FALSE_P(v))) mask = mask & (~XpmReturnPixels); if (mask & XpmExactColors) XA->exactColors = s48_extract_integer(v); if ((mask & XpmReturnAllocPixels) && (S48_FALSE_P(v))) mask = mask & (~XpmReturnAllocPixels); if (mask & XpmAllocCloseColors) XA->alloc_close_colors = s48_extract_integer(v); if (mask & XpmBitmapFormat) XA->bitmap_format = s48_extract_integer(v); // if (mask & XpmColorSymbols) // XA->colorsyms = ExtractColorsymbols(v, XA->colorsymbols, XA->numsymbols); XA->valuemask = mask; return; } s48_value Make_XPM_Result(Pixmap* pixmap, Pixmap* shapemask, XpmAttributes* XA) { s48_value res = s48_make_vector(6, S48_FALSE); S48_DECLARE_GC_PROTECT(1); S48_GC_PROTECT_1(res); S48_VECTOR_SET(res, 0, SCX_ENTER_PIXMAP(*pixmap)); S48_VECTOR_SET(res, 1, s48_cons(s48_enter_fixnum(XA->width), s48_enter_fixnum(XA->height))); if (XA->valuemask & XpmHotspot != 0) S48_VECTOR_SET(res, 2, s48_cons(s48_enter_fixnum(XA->x_hotspot), s48_enter_fixnum(XA->y_hotspot))); S48_VECTOR_SET(res, 3, SCX_ENTER_PIXMAP(*shapemask)); S48_GC_UNPROTECT(); return res; } s48_value scx_Create_Pixmap_From_Data(s48_value Xdisplay, s48_value Xdrawable, s48_value data, s48_value attribute_vector) { Pixmap pixmap, shapemask; XpmAttributes XA; int r, i, n = S48_VECTOR_LENGTH(data); char* d[n]; for (i=0; i < n; i++) d[i] = s48_extract_string(S48_VECTOR_REF(data, i)); Attribs_To_XpmAttributes(attribute_vector, &XA); r = XpmCreatePixmapFromData( SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable), d, &pixmap, &shapemask, &XA ); if (r == XpmNoMemory) return s48_enter_fixnum(0); else if (r == XpmFileInvalid) return s48_enter_fixnum(1); else if (r == XpmSuccess) return Make_XPM_Result(&pixmap, &shapemask, &XA); } s48_value scx_Read_File_To_Pixmap(s48_value Xdisplay, s48_value Xdrawable, s48_value filename, s48_value attribute_vector) { Pixmap pixmap, shapemask; XpmAttributes XA; int r; Attribs_To_XpmAttributes(attribute_vector, &XA); r = XpmReadFileToPixmap( SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable), s48_extract_string(filename), &pixmap, &shapemask, &XA ); if (r == XpmNoMemory) return s48_enter_fixnum(0); else if (r == XpmFileInvalid) return s48_enter_fixnum(1); else if (r == XpmOpenFailed) return s48_enter_fixnum(2); else if (r == XpmSuccess) return Make_XPM_Result(&pixmap, &shapemask, &XA); } void scx_init_xpm(void) { S48_EXPORT_FUNCTION(scx_Create_Pixmap_From_Data); S48_EXPORT_FUNCTION(scx_Read_File_To_Pixmap); }