static void img_apply_gamma(img_t *img) { if (img == NULL || img->im == NULL || img->cmod == NULL) return; if (img->gamma == 0) { imlib_context_set_color_modifier(NULL); } else { double range = img->gamma <= 0 ? 1.0 : GAMMA_MAX - 1.0; imlib_context_set_color_modifier(img->cmod); imlib_reset_color_modifier(); imlib_modify_color_modifier_gamma(1.0 + img->gamma * (range / GAMMA_RANGE)); } }
void init_x_and_imlib(void) { disp = XOpenDisplay(NULL); if (!disp) eprintf("Can't open X display. It *is* running, yeah?"); vis = DefaultVisual(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp)); root = RootWindow(disp, DefaultScreen(disp)); scr = ScreenOfDisplay(disp, DefaultScreen(disp)); xid_context = XUniqueContext(); #ifdef HAVE_LIBXINERAMA init_xinerama(); #endif /* HAVE_LIBXINERAMA */ imlib_context_set_display(disp); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_color_modifier(NULL); imlib_context_set_progress_function(NULL); imlib_context_set_operation(IMLIB_OP_COPY); wmDeleteWindow = XInternAtom(disp, "WM_DELETE_WINDOW", False); /* Initialise random numbers */ srand(getpid() * time(NULL) % ((unsigned int) -1)); return; }
void img_invert(img_t *img){ /* the code here is almost verbatim taken from Julien Danjou's telak. */ int i; DATA8 r_table[256]; DATA8 g_table[256]; DATA8 b_table[256]; DATA8 a_table[256]; Imlib_Color_Modifier color_mod; imlib_context_set_image(img->im); color_mod = imlib_create_color_modifier(); imlib_context_set_color_modifier(color_mod); imlib_reset_color_modifier(); imlib_get_color_modifier_tables(r_table, g_table, b_table, a_table); for(i = 0; i <= 255; i++) { r_table[255-i] = i; g_table[255-i] = i; b_table[255-i] = i; } imlib_set_color_modifier_tables(r_table, g_table, b_table, a_table); }
void img_init(img_t *img, win_t *win) { zoom_min = zoom_levels[0] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; if (img == NULL || win == NULL) return; imlib_context_set_display(win->env.dpy); imlib_context_set_visual(win->env.vis); imlib_context_set_colormap(win->env.cmap); img->im = NULL; img->win = win; img->scalemode = options->scalemode; img->zoom = options->zoom; img->zoom = MAX(img->zoom, zoom_min); img->zoom = MIN(img->zoom, zoom_max); img->checkpan = false; img->dirty = false; img->aa = ANTI_ALIAS; img->alpha = ALPHA_LAYER; img->multi.cap = img->multi.cnt = 0; img->multi.animate = options->animate; img->multi.length = 0; img->cmod = imlib_create_color_modifier(); imlib_context_set_color_modifier(img->cmod); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); img->ss.on = options->slideshow > 0; img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY; }
void image_destroy_imlib2(struct R_image *image) { Imlib_Border *border; Imlib_Color_Modifier colormod; int i; if (image == NULL) { return; } if (image->filename) { free(image->filename); image->filename = NULL; } border = &image->im2border; memset(border, 0, sizeof(Imlib_Border)); for (i = 0 ; i < IMAGE_COLOR_MODIFIERS ; i++) { colormod = image->im2colormods[i]; if (colormod) { imlib_context_set_color_modifier(colormod); imlib_free_color_modifier(); } } image->flags &= ~IMAGE_KEEP_PIXMAP; image_destroy_data_imlib2(image); return; }
static Imlib_Color_Modifier create_modifier(MainWin *mw, dlist *config, const char *item, const char *d_bright, const char *d_tint, const char *d_opacity) { const char *tmp; XColor exact_color, screen_color; int i, alpha_v; DATA8 red[256], green[256], blue[256], alpha[256]; Imlib_Color_Modifier modifier = imlib_create_color_modifier(); imlib_context_set_color_modifier(modifier); tmp = config_get(config, item, "brightness", d_bright); imlib_modify_color_modifier_brightness(strtod(tmp, NULL)); imlib_get_color_modifier_tables(red, green, blue, alpha); tmp = config_get(config, item, "tint", d_tint); if(XLookupColor(mw->dpy, mw->colormap, tmp, &exact_color, &screen_color) != 0) { double red_f = (double)exact_color.red / 65536.0, green_f = (double)exact_color.green / 65536.0, blue_f = (double)exact_color.blue / 65536.0; for(i = 0; i < 256; i++) { red[i] = (double)red[i] * red_f; green[i] = (double)green[i] * green_f; blue[i] = (double)blue[i] * blue_f; } } else fprintf(stderr, "WARNING: Couldn't look up tint color'%s'.\n", tmp); tmp = config_get(config, item, "opacity", d_opacity); alpha_v = strtol(tmp, 0, 10); if(alpha_v != 255) { for(i = 0; i < 256; i++) alpha[i] = alpha_v; } imlib_set_color_modifier_tables(red, green, blue, alpha); imlib_context_set_color_modifier(0); return modifier; }
void mainwin_destroy(MainWin *mw) { if(mw->tooltip) tooltip_destroy(mw->tooltip); if(! mw->no_free_color) XFreeColors(mw->dpy, mw->colormap, mw->pixels, 2, 0); else { if(! (mw->no_free_color & 1)) XFreeColors(mw->dpy, mw->colormap, &BORDER_COLOR(mw), 1, 0); if(! (mw->no_free_color & 2)) XFreeColors(mw->dpy, mw->colormap, &HIGHLIGHT_COLOR(mw), 1, 0); } if(mw->cm_highlight) { imlib_context_set_color_modifier(mw->cm_highlight); imlib_free_color_modifier(); } if(mw->cm_normal) { imlib_context_set_color_modifier(mw->cm_normal); imlib_free_color_modifier(); } if(mw->background) { imlib_context_set_image(mw->background); imlib_free_image(); } if(mw->bg_pixmap != None) imlib_free_pixmap_and_mask(mw->bg_pixmap); XDestroyWindow(mw->dpy, mw->window); #ifdef XINERAMA if(mw->xin_info) XFree(mw->xin_info); #endif /* XINERAMA */ free(mw); }
void gib_imlib_apply_color_modifier_to_rectangle(Imlib_Image im, int x, int y, int w, int h, DATA8 * rtab, DATA8 * gtab, DATA8 * btab, DATA8 * atab) { Imlib_Color_Modifier cm; imlib_context_set_image(im); cm = imlib_create_color_modifier(); imlib_context_set_color_modifier(cm); imlib_set_color_modifier_tables(rtab, gtab, btab, atab); imlib_apply_color_modifier_to_rectangle(x, y, w, h); imlib_free_color_modifier(); }
void XImlib2Image::applyMouseOverEffects() { if (glowChange) { imlib_context_set_color_modifier(colorMod); imlib_get_color_modifier_tables(mapNone, mapNone, mapNone, NULL); imlib_reset_color_modifier(); if (glowing == true) // reset to standard alpha mapping imlib_set_color_modifier_tables(mapNone, mapNone, mapNone, mapNone); else // remap alpha values lower to increase transparency imlib_set_color_modifier_tables(mapNone, mapNone, mapNone, defaultTransTable); glowChange = false; } }
int image_apply_modifier_imlib2(struct R_image *image, int which, double gamma, double brightness, double contrast) { Imlib_Image img; Imlib_Color_Modifier colormod; if (image == NULL || which < 0 || which > IMAGE_COLOR_MODIFIERS - 1) { return -1; } img = image->im2img; if (img) { imlib_context_set_image(img); colormod = image->im2colormods[which]; if (colormod == NULL) { colormod = imlib_create_color_modifier(); if (colormod == NULL) { return -1; } } imlib_context_set_color_modifier(colormod); if (gamma >= 0.0) { imlib_modify_color_modifier_gamma(gamma); } else { imlib_modify_color_modifier_gamma(IMLIB2_NORMAL_MODIFIER); } if (brightness >= 0.0) { imlib_modify_color_modifier_brightness(brightness); } else { imlib_modify_color_modifier_brightness(IMLIB2_NORMAL_MODIFIER); } if (contrast >= 0.0) { imlib_modify_color_modifier_contrast(contrast); } else { imlib_modify_color_modifier_contrast(IMLIB2_NORMAL_MODIFIER); } imlib_apply_color_modifier(); } return 0; }
void XImlib2Shadow::configure() { XImlib2Image::configure(); DesktopIconConfig * dIconConfig = dynamic_cast<DesktopIconConfig *>(iconConfig); transparency = dIconConfig->getSnapShadowTrans(); if (transparency == -1 ) transparency = 200; //default value imlib_context_set_image(image); imlib_context_set_color_modifier(colorMod); imlib_set_color_modifier_tables(mapNone, mapNone, mapNone, defaultTransTable); }
static void setup_imlib_color_modifier(qiv_color_modifier q) { if (q.gamma == DEFAULT_GAMMA && q.brightness == DEFAULT_BRIGHTNESS && q.contrast == DEFAULT_CONTRAST) { if (imlib_context_get_color_modifier()) imlib_free_color_modifier(); return; } if (imlib_context_get_color_modifier()) imlib_reset_color_modifier(); else imlib_context_set_color_modifier(imlib_create_color_modifier()); imlib_modify_color_modifier_gamma(q.gamma / 256.0); imlib_modify_color_modifier_brightness((q.brightness - 256) / 256.0); imlib_modify_color_modifier_contrast(q.contrast / 256.0); }
void XImlib2Image::shapeWindow() { XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(container); //Shape the window to the icon imlib_context_set_image(image); imlib_context_set_color_modifier(colorMod); imlib_set_color_modifier_tables(mapNone, mapNone, mapNone, mapZeroAlpha); Pixmap pixmap, pixMask; imlib_render_pixmaps_for_whole_image(&pixmap, &pixMask); XSetWindowBackgroundPixmap (display, window, pixmap); #ifdef SHAPE XShapeCombineMask(display, window, ShapeBounding, 0, 0, pixMask, ShapeSet); #endif // SHAPE imlib_reset_color_modifier(); imlib_free_pixmap_and_mask(pixmap); }
int main (int argc, char **argv) { Visual *vis; Colormap cm; Display *_display; Imlib_Context context; Imlib_Image image; Pixmap pixmap; Imlib_Color_Modifier modifier = NULL; _display = XOpenDisplay (NULL); int width, height, depth, i, alpha; char str1[40]; char str2[40]; char str3[40]; char str4[40]; char str5[40]; int ck0; int w, h; w = 0; h = 0; char strA1[30] = "hwe"; char strA2[30] = "hwer"; const char jpg[15] = "jpg"; //1 const char png[15] = "png"; //2 char *A1; char *A2; strcpy(strA1, argv[argc-1]); strcpy(strA2, strA1); A1 = strstr(strA1, jpg); A2 = strstr(strA2, png); //check to be sure image format is written right or abort checkForNull(A1, A2); for (screen = 0; screen < ScreenCount (_display); screen++) { display = XOpenDisplay (NULL); context = imlib_context_new (); imlib_context_push (context); imlib_context_set_display (display); vis = DefaultVisual (display, screen); cm = DefaultColormap (display, screen); width = DisplayWidth (display, screen); height = DisplayHeight (display, screen); depth = DefaultDepth (display, screen); pixmap = XCreatePixmap (display, RootWindow (display, screen), width, height, depth); imlib_context_set_visual (vis); imlib_context_set_colormap (cm); imlib_context_set_drawable (pixmap); imlib_context_set_color_range (imlib_create_color_range ()); image = imlib_create_image (width, height); imlib_context_set_image (image); printf("1\n"); imlib_context_set_color (0, 0, 0, 255); imlib_image_fill_rectangle (0, 0, width, height); imlib_context_set_dither (1); imlib_context_set_blend (1); printf("2\n"); alpha = 255; for (i = 1; i < argc; i++) { if (modifier != NULL) { imlib_apply_color_modifier (); imlib_free_color_modifier (); } modifier = imlib_create_color_modifier (); imlib_context_set_color_modifier (modifier); if (strcmp (argv[i], "-alpha") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing alpha\n"); continue; } if (sscanf (argv[i], "%i", &alpha) == 0) { fprintf (stderr, "Bad alpha (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-solid") == 0) { Color c; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_image_fill_rectangle (0, 0, width, height); } else if (strcmp (argv[i], "-clear") == 0) { imlib_free_color_range (); imlib_context_set_color_range (imlib_create_color_range ()); } else if (strcmp (argv[i], "-add") == 0) { Color c; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_add_color_to_color_range (1); } else if (strcmp (argv[i], "-addd") == 0) { Color c; int distance; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if ((++i) >= argc) { fprintf (stderr, "Missing distance\n"); continue; } if (parse_color (argv[i - 1], &c, alpha) == 1) { fprintf (stderr, "Bad color (%s)\n", argv[i - 1]); continue; } if (sscanf (argv[i], "%i", &distance) == 1) { fprintf (stderr, "Bad distance (%s)\n", argv[i]); continue; } imlib_context_set_color (c.r, c.g, c.b, c.a); imlib_add_color_to_color_range (distance); } else if (strcmp (argv[i], "-gradient") == 0) { int angle; if ((++i) >= argc) { fprintf (stderr, "Missing angle\n"); continue; } if (sscanf (argv[i], "%i", &angle) == 1) { fprintf (stderr, "Bad angle (%s)\n", argv[i]); continue; } imlib_image_fill_color_range_rectangle (0, 0, width, height, angle); } else if (strcmp (argv[i], "-fill") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing image\n"); continue; } if ( load_Mod_image(Fill, argv[i], width, height, alpha, image, ck0) == 1) { fprintf (stderr, "Bad image (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-dia") == 0) { if((++i) >= argc) { fprintf(stderr, "missing Dia, and Image\n"); continue; } strcpy (str1, argv[i]); strcpy (str2, str1); if ( findX(str1, &w, &h) == 1 ) { fprintf(stderr, " Bad Format\n"); continue; } else if (findX(str2, &w, &h) == 0 && ((++i) >= argc)) { fprintf(stderr, "Missing Image\n"); continue; } else { //if format is correct then assign a number for //load_Mod_Image to check ck0 = -2; w = w; h = h; } if( load_Mod_image(Dia, argv[i], w, h, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimensions \n"); } } else if (strcmp (argv[i], "-tile") == 0) { if ((++i) >= argc) { fprintf(stderr, "format 0 missing \n"); continue; } strcpy (str1, argv[i]); strcpy (str2, str1); strcpy (str3, str2); strcpy (str4, str3); strcpy (str5, str4); if ( findX(str1, &w, &h) == 3 && ((++i) >= argc)) { fprintf(stderr, "missing Image\n"); continue; } //check to see if format is -tile 0 else if (findX(str2, &w, &h) == 3) { ck0 = 3; if( load_Mod_image(Tile, argv[i], width, height, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimensions \n"); continue; } } if (findX(str3, &w, &h) == 1) { fprintf(stderr, "bad format\n"); continue; } if (findX(str4, &w, &h) == 0 && ((++i) >= argc)) { fprintf(stderr, "missing something again\n"); continue; } if (findX (str5, &w, &h) == 0 ) { ck0 = 2; w = w; h = h; } if( load_Mod_image(Tile, argv[i], w, h, alpha, image, ck0) == 1 ) { fprintf(stderr, "Bad Image or Bad Image Dimension\n"); } } else if (strcmp (argv[i], "-center") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing image\n"); continue; } if (load_Mod_image (Center, argv[i], width, height, alpha, image, ck0) == 1) { fprintf (stderr, "Bad image (%s)\n", argv[i]); continue; } } else if (strcmp (argv[i], "-tint") == 0) { Color c; DATA8 r[256], g[256], b[256], a[256]; int j; if ((++i) >= argc) { fprintf (stderr, "Missing color\n"); continue; } if (parse_color (argv[i], &c, 255) == 1) { fprintf (stderr, "Bad color\n"); continue; } imlib_get_color_modifier_tables (r, g, b, a); for (j = 0; j < 256; j++) { r[j] = (DATA8) (((double) r[j] / 255.0) * (double) c.r); g[j] = (DATA8) (((double) g[j] / 255.0) * (double) c.g); b[j] = (DATA8) (((double) b[j] / 255.0) * (double) c.b); } imlib_set_color_modifier_tables (r, g, b, a); } else if (strcmp (argv[i], "-blur") == 0) { int intval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%i", &intval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_image_blur (intval); } else if (strcmp (argv[i], "-sharpen") == 0) { int intval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%i", &intval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_image_sharpen (intval); } else if (strcmp (argv[i], "-contrast") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_contrast (dblval); } else if (strcmp (argv[i], "-brightness") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_brightness (dblval); } else if (strcmp (argv[i], "-gamma") == 0) { double dblval; if ((++i) >= argc) { fprintf (stderr, "Missing value\n"); continue; } if (sscanf (argv[i], "%lf", &dblval) == 1) { fprintf (stderr, "Bad value (%s)\n", argv[i]); continue; } imlib_modify_color_modifier_gamma (dblval); } else if (strcmp (argv[i], "-flipv") == 0) { imlib_image_flip_vertical (); } else if (strcmp (argv[i], "-fliph") == 0) { imlib_image_flip_horizontal (); } else if (strcmp (argv[i], "-flipd") == 0) { imlib_image_flip_diagonal (); } else if (strcmp (argv[i], "-write") == 0) { if ((++i) >= argc) { fprintf (stderr, "Missing filename\n"); continue; } imlib_save_image (argv[i]); } else { usage (argv[0]); imlib_free_image (); imlib_free_color_range (); if (modifier != NULL) { imlib_context_set_color_modifier (modifier); imlib_free_color_modifier (); modifier = NULL; } XFreePixmap (display, pixmap); exit (1); } // end else } // end loop off of argc if (modifier != NULL) { imlib_context_set_color_modifier (modifier); imlib_apply_color_modifier (); imlib_free_color_modifier (); modifier = NULL; } imlib_render_image_on_drawable (0, 0); imlib_free_image (); imlib_free_color_range (); if (setRootAtoms (pixmap) == 0) fprintf (stderr, "Couldn't create atoms...\n"); XKillClient (display, AllTemporary); XSetCloseDownMode (display, RetainTemporary); XSetWindowBackgroundPixmap (display, RootWindow (display, screen), pixmap); XClearWindow (display, RootWindow (display, screen)); XFlush (display); XSync (display, False); imlib_context_pop (); imlib_context_free (context); } // end for loop off screen // } // frist if statment at start of main return 0; }
int load_Mod_image (ImageMode mode, const char *arg, int userW, int userH, int alpha, Imlib_Image rootimg, int ck0) { int width, height; int imgW, imgH, o; int left, top; left=top=0; int x, y; width = DisplayWidth (display, screen); height = DisplayHeight (display, screen); Imlib_Image buffer = imlib_load_image (arg); if ( !buffer ) { return 1; } imlib_context_set_image (buffer); imgW = imlib_image_get_width (), imgH = imlib_image_get_height (); if (alpha < 255) { // Create alpha-override mask imlib_image_set_has_alpha (1); Imlib_Color_Modifier modifier = imlib_create_color_modifier (); imlib_context_set_color_modifier (modifier); DATA8 red[256], green[256], blue[256], alph[256]; imlib_get_color_modifier_tables (red, green, blue, alph); for (o = 0; o < 256; o++) alph[o] = (DATA8) alpha; imlib_set_color_modifier_tables (red, green, blue, alph); imlib_apply_color_modifier (); imlib_free_color_modifier (); } imlib_context_set_image (rootimg); if (mode == Fill) { imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, 0, 0, userW, userH); } if (mode == Dia) { if (userW >= width || userH >= height ) { imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, 0, 0, width, height); } else if ( userH < height || userW < width ) { int left, top; left = (width - userW) / 2; top = (height - userH) / 2; imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, left, top, userW, userH); } } if (mode == Tile) { if ( ck0 == 3 ) { left = (width - imgW) / 2; top = (height - imgH) / 2; for (; left > 0; left -= imgW); for (; top > 0; top -= imgH); for (x = left; x < width; x += imgW) for (y = top; y < height; y += imgH) imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, x, y, imgW, imgH); } if (ck0 != 3) { left = (width - userW) / 2; top = (height - userH) /2; for (; left > 0; left -= userW); for (; top > 0; top -= userH); for (x = left; x < width; x += userW) for (y = top; y < height; y += userH) imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, x, y, userW, userH); } } if (mode == Center) { left = (width - imgW) / 2; top = (height - imgH) / 2; imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, left, top, imgW, imgH); } imlib_context_set_image (buffer); imlib_free_image (); imlib_context_set_image (rootimg); return 0; }
int main(int argc, char **argv) { int w, h, x, y; Imlib_Image im = NULL, im_bg = NULL; XEvent ev; const char *display_name = getenv("DISPLAY"); /** * Initialization according to options */ printf("Initialising\n"); /** * First tests to determine which rendering task to perform */ if (display_name == NULL) display_name = ":0"; disp = XOpenDisplay(display_name); if (disp == NULL) { fprintf(stderr, "Can't open display %s\n", display_name); return 1; } vis = DefaultVisual(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp)); win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, 0); XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask | ExposureMask); XMapWindow(disp, win); /** * Start rendering */ printf("Rendering\n"); imlib_context_set_display(disp); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_drawable(win); imlib_context_set_dither(1); imlib_context_set_blend(0); imlib_context_set_color_modifier(NULL); im_bg = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png"); im = imlib_load_image(PACKAGE_DATA_DIR"/data/images/imlib2.png"); imlib_context_set_image(im_bg); w = imlib_image_get_width(); h = imlib_image_get_height(); printf("Resizing Window to %d by %d\n", w, h); XResizeWindow(disp, win, w, h); XSync(disp, False); x = -9999; y = -9999; while (1) { Imlib_Image *temp, *temp2; do { XNextEvent(disp, &ev); switch (ev.type) { case Expose: break; case ButtonRelease: exit(0); break; case MotionNotify: x = ev.xmotion.x; y = ev.xmotion.y; default: break; } } while (XPending(disp)); imlib_context_set_blend(0); imlib_context_set_image(im_bg); temp = imlib_clone_image(); imlib_context_set_image(temp); /* imlib_blend_image_onto_image(im_bg, 0, * 0, 0, w, h, * 0, 0, w, h); * first = 0; */ imlib_apply_filter ("bump_map_point(x=[],y=[],map="PACKAGE_DATA_DIR"/data/images/imlib2.png);", &x, &y); temp2 = im_bg; im_bg = temp; imlib_context_set_image(im_bg); imlib_render_image_on_drawable(0, 0); im_bg = temp2; imlib_context_set_image(temp); imlib_free_image(); } return 0; }
int image_render_imlib2(Drawable drawable, struct R_image *image, int w, int h) { Window dummyw; Imlib_Image img; Imlib_Border *border; Imlib_Color_Modifier colormod; Pixmap pixmap; Pixmap mask; int origw, origh; int neww, newh; int dummyi; unsigned int drawablew, drawableh; unsigned int dummyui; if (image == NULL) { return -1; } if (image->im2img == NULL) { image_load_data_imlib2(image); } pixmap = None; mask = None; img = image->im2img; if (img) { imlib_context_set_drawable(drawable); imlib_context_set_image(img); imlib_context_set_mask(image->maskpixmap); imlib_context_set_blend(0); border = &image->im2border; imlib_image_set_border(border); if (w == -1 || h == -1) { XGetGeometry(Rglobals.app->display, drawable, &dummyw, &dummyi, &dummyi, &drawablew, &drawableh, &dummyui, &dummyui); } origw = imlib_image_get_width(); image->origw = origw; if (w == 0) { neww = origw; } else if (w == -1) { neww = drawablew; } else { neww = w; } origh = imlib_image_get_height(); image->origh = origh; if (h == 0) { newh = origh; } else if (h == -1) { newh = drawableh; } else { newh = h; } colormod = image->im2colormods[IMAGE_COLOR_MODIFIER]; if (colormod == NULL) { colormod = imlib_create_color_modifier(); image->im2colormods[IMAGE_COLOR_MODIFIER] = colormod; } imlib_context_set_color_modifier(colormod); imlib_render_pixmaps_for_whole_image_at_size(&pixmap, &mask, neww, newh); if (image->pixmap) { imlib_free_pixmap_and_mask(image->pixmap); image->pixmap = None; image->maskpixmap = None; } image->pixmap = pixmap; image->maskpixmap = mask; #if 0 image->flags |= IMAGE_KEEP_PIXMAP; image_destroy_data_imlib2(image); #endif } return 0; }
void window_fade_imlib2(Rwindow_t *window, struct R_image *image, int usecs, int mode) { double value, lastvalue; struct R_image *scaledimage; Imlib_Color_Modifier colormod; Pixmap pixmap; Pixmap mask; struct timeval start, stop; int usedtime; XWindowAttributes attributes; if (window == NULL || image == NULL) { return; } if (mode == WINDOW_FADE_IN) { value = 0.0; } else { value = 1.0; } lastvalue = -1.0; usedtime = 0; memset(&attributes, 0, sizeof(attributes)); XGetWindowAttributes(window->app->display, window->win, &attributes); scaledimage = image_clone_imlib2(window->win, image, attributes.width, attributes.height); if (scaledimage == NULL) { return; } colormod = imlib_create_color_modifier(); if (colormod == NULL) { image_destroy_imlib2(scaledimage); return; } imlib_context_set_drawable(window->win); imlib_context_set_image(scaledimage->im2img); imlib_context_set_color_modifier(colormod); imlib_modify_color_modifier_gamma(1.0); imlib_modify_color_modifier_contrast(1.0); gettimeofday(&start, NULL); while (usedtime < usecs) { if (value != lastvalue) { imlib_modify_color_modifier_brightness(value); imlib_context_set_mask(0); imlib_render_pixmaps_for_whole_image(&pixmap, &mask); XSetWindowBackgroundPixmap(window->app->display, window->win, pixmap); XClearWindow(window->app->display, window->win); XFlush(window->app->display); imlib_free_pixmap_and_mask(pixmap); lastvalue = value; } gettimeofday(&stop, NULL); usedtime = TIMEVAL_CMP_USEC(&start, &stop); value = IMAGE_NORMAL_MODIFIER * (usedtime / (double)usecs); if (mode == WINDOW_FADE_OUT) { value = IMAGE_NORMAL_MODIFIER - value; } } if (mode == WINDOW_FADE_IN && lastvalue != IMAGE_NORMAL_MODIFIER) { imlib_modify_color_modifier_brightness(IMAGE_NORMAL_MODIFIER); imlib_context_set_mask(0); imlib_render_pixmaps_for_whole_image(&pixmap, &mask); XSetWindowBackgroundPixmap(window->app->display, window->win, pixmap); XClearWindow(window->app->display, window->win); XFlush(window->app->display); imlib_free_pixmap_and_mask(pixmap); } else if (lastvalue != 0.0) { imlib_modify_color_modifier_brightness(0.0); imlib_context_set_mask(0); imlib_render_pixmaps_for_whole_image(&pixmap, &mask); XSetWindowBackgroundPixmap(window->app->display, window->win, pixmap); XClearWindow(window->app->display, window->win); XFlush(window->app->display); imlib_free_pixmap_and_mask(pixmap); } image_destroy_imlib2(scaledimage); return; }
int main(int argc, char **argv) { int w, h, tw, th; Imlib_Image im_bg = NULL; XEvent ev; KeySym keysym; static char kbuf[20]; Imlib_Font font; Imlib_Color_Range range; const char *display_name = getenv("DISPLAY"); /** * First tests to determine which rendering task to perform */ if (display_name == NULL) display_name = ":0"; disp = XOpenDisplay(display_name); if (disp == NULL) { fprintf(stderr, "Can't open display %s\n", display_name); return 1; } vis = DefaultVisual(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp)); win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, 0); XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask | ExposureMask | KeyPressMask); XMapWindow(disp, win); /** * Start rendering */ imlib_set_font_cache_size(512 * 1024); imlib_add_path_to_font_path(PACKAGE_DATA_DIR"/data/fonts"); imlib_context_set_display(disp); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_drawable(win); imlib_context_set_blend(0); imlib_context_set_color_modifier(NULL); imlib_context_set_blend(0); im_bg = imlib_create_image(600, 400); imlib_context_set_image(im_bg); w = imlib_image_get_width(); h = imlib_image_get_height(); imlib_context_set_color(128, 128, 255, 255); imlib_image_fill_rectangle(0, 0, w, h); XResizeWindow(disp, win, w, h); XSync(disp, False); while (1) { do { XNextEvent(disp, &ev); switch (ev.type) { case ButtonRelease: exit(0); break; case KeyPress: XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym, NULL); switch (*kbuf) { case 'q': exit(0); default: break; } break; default: break; } } while (XPending(disp)); imlib_context_set_image(im_bg); imlib_context_set_color(128, 128, 255, 255); imlib_image_fill_rectangle(0, 0, w, h); imlib_context_set_color(0, 0, 0, 255); imlib_image_draw_rectangle(20, 20, 560, 140); imlib_image_draw_rectangle(20, 220, 560, 140); font = imlib_load_font("notepad/15"); if (font) { char text[4096]; imlib_context_set_font(font); imlib_context_set_color(0, 0, 0, 255); sprintf(text, "RGBA range, 2 points, from red to magenta"); imlib_get_text_size(text, &tw, &th); imlib_text_draw(300 - tw / 2, 180 - th / 2, text); sprintf(text, "HSVA range, 2 points, from red to magenta"); imlib_get_text_size(text, &tw, &th); imlib_text_draw(300 - tw / 2, 380 - th / 2, text); imlib_free_font(); } /* Draw rectangle w/ RGBA gradient */ range = imlib_create_color_range(); imlib_context_set_color_range(range); imlib_context_set_color(255, 0, 0, 255); imlib_add_color_to_color_range(0); imlib_context_set_color(255, 0, 255, 255); imlib_add_color_to_color_range(20); imlib_image_fill_color_range_rectangle(21, 21, 558, 138, -90.0); imlib_free_color_range(); /* Draw rectangle w/ HSVA gradient */ range = imlib_create_color_range(); imlib_context_set_color_range(range); imlib_context_set_color_hsva(0, 1, 1, 255); imlib_add_color_to_color_range(0); imlib_context_set_color_hsva(300, 1, 1, 255); imlib_add_color_to_color_range(20); imlib_image_fill_hsva_color_range_rectangle(21, 221, 558, 138, -90.0); imlib_free_color_range(); imlib_render_image_on_drawable(0, 0); } return 0; }
int main(int argc, char **argv) { int w, h; Imlib_Image im_bg = NULL; XEvent ev; KeySym keysym; static char kbuf[20]; ImlibPolygon poly, poly1, poly2; const char *display_name = getenv("DISPLAY"); /** * First tests to determine which rendering task to perform */ if (display_name == NULL) display_name = ":0"; disp = XOpenDisplay(display_name); if (disp == NULL) { fprintf(stderr, "Can't open display %s\n", display_name); return 1; } vis = DefaultVisual(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp)); win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, 0); XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask | ExposureMask | KeyPressMask); XMapWindow(disp, win); /** * Start rendering */ imlib_context_set_display(disp); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_drawable(win); imlib_context_set_blend(0); imlib_context_set_color_modifier(NULL); imlib_context_set_blend(0); im_bg = imlib_create_image(400, 400); imlib_context_set_image(im_bg); w = imlib_image_get_width(); h = imlib_image_get_height(); imlib_context_set_color(0, 0, 0, 255); imlib_image_fill_rectangle(0, 0, w, h); XResizeWindow(disp, win, w, h); XSync(disp, False); poly = imlib_polygon_new(); imlib_polygon_add_point(poly, 20, 20); imlib_polygon_add_point(poly, 70, 20); imlib_polygon_add_point(poly, 70, 70); imlib_polygon_add_point(poly, 20, 70); poly1 = imlib_polygon_new(); imlib_polygon_add_point(poly1, 100, 20); imlib_polygon_add_point(poly1, 190, 100); imlib_polygon_add_point(poly1, 120, 70); poly2 = imlib_polygon_new(); imlib_polygon_add_point(poly2, 290, 20); imlib_polygon_add_point(poly2, 200, 100); imlib_polygon_add_point(poly2, 270, 70); while (1) { do { XNextEvent(disp, &ev); switch (ev.type) { case ButtonRelease: exit(0); break; case KeyPress: XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym, NULL); switch (*kbuf) { case ' ': imlib_context_set_anti_alias (!imlib_context_get_anti_alias()); printf("AA is %s\n", imlib_context_get_anti_alias()? "on" : "off"); break; case 'q': exit(0); default: break; } break; default: break; } } while (XPending(disp)); imlib_context_set_image(im_bg); imlib_context_set_color(0, 0, 0, 255); imlib_image_fill_rectangle(0, 0, w, h); imlib_context_set_color(255, 255, 255, 255); imlib_image_fill_polygon(poly); imlib_image_fill_polygon(poly1); imlib_image_fill_polygon(poly2); imlib_render_image_on_drawable(0, 0); } return 0; }