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 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; } }
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; }
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; }