/* x blender by shudder gcc -Wall -O2 -L/usr/X11R6/lib -I/usr/X11R6/include -o xblend xblend.c -lX11 -lXpm */ #include #include #include #include #include #include #define MAXCOLORS sizeof(colors)/sizeof(char *) #define OUTPUT_FILE "xblender.xpm" char *colors[]={"#000000", "#ffffff", "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff", "#ffaa00"}; int w = 200; int h = 100; int screen; Display *display; Colormap colormap; Window win; struct { Window w; XColor c; } cw[MAXCOLORS]; Pixmap blend(XColor c1, XColor c2) { int i; int red, green, blue; XColor color; Pixmap pixmap; GC gc; pixmap = XCreatePixmap(display, win, w, h, DefaultDepth(display, screen)); gc = XCreateGC(display, pixmap, 0, 0); color.red = red = c1.red; color.green = green = c1.green; color.blue = blue = c1.blue; for(i=0; ired = r; color->green = g; color->blue = b; XAllocColor(display, colormap, color); return color->pixel; } long setnamedcolor(char *name, XColor *color) { XAllocNamedColor(display, colormap, name, color, color); return color->pixel; } int main(int argc, char *argv[]) { int i, p; int black, white; int quit; char *title = "x blender"; XColor color1, color2; XEvent event; XFontStruct *font; Window root; Window c1, c2; Window blend_b, save_b; GC gc; Atom watom; XTextProperty t; XpmAttributes xa; if (argc < 3) { fprintf(stderr, "usage: %s color1 color2\n", argv[0]); exit(1); } if (!(display = XOpenDisplay(getenv("DISPLAY")))) { fprintf(stderr, "%s: unable to open display: %s\n", argv[0], getenv("DISPLAY")); exit(1); } screen = DefaultScreen(display); root = RootWindow(display, screen); font = XLoadQueryFont(display, "*helvetica*medium*-r*12*"); black = BlackPixel(display, screen); white = WhitePixel(display, screen); colormap = DefaultColormap(display, screen); quit = 0; memset(&xa, 0, sizeof(XpmAttributes)); win = XCreateSimpleWindow(display, root, 200, 200, w, h+100, 0, 0, white); XSelectInput(display, win, StructureNotifyMask); watom = XInternAtom(display, "WM_DELETE_WINDOW", False); XSetWMProtocols(display, win, &watom, 1); XStringListToTextProperty(&title, 1, &t); XSetWMName(display, win, &t); /* create 20x20 color boxes */ for (i=0, p=2; i