ExcCode screen_cursor_blend(int x, int y, Imlib_Image image) { xcb_xfixes_get_cursor_image_cookie_t cookie = xcb_xfixes_get_cursor_image(display); xcb_xfixes_get_cursor_image_reply_t *reply = xcb_xfixes_get_cursor_image_reply(display, cookie, NULL); if (reply == NULL) return 0; unsigned *cursor_data = xcb_xfixes_get_cursor_image_cursor_image(reply); if (cursor_data == NULL) return 0; Imlib_Image cursor = imlib_create_image_using_data( reply->width, reply->height, cursor_data); if (cursor == NULL) PANIC(ERR_IMAGE); imlib_context_set_image(cursor); imlib_image_set_has_alpha(1); imlib_context_set_image(image); imlib_blend_image_onto_image(cursor, 0, 0, 0, reply->width, reply->height, reply->x - reply->xhot - x, reply->y - reply->yhot - y, reply->width, reply->height); imlib_context_set_image(cursor); imlib_free_image_and_decache(); free(reply); return 0; }
Imlib_Image create_transparent_image(Imlib_Image w_image, Imlib_Image b_image) { int w, h; DATA32 *dst_data, *src_data; imlib_context_set_image(w_image); dst_data = imlib_image_get_data(); imlib_context_set_image(b_image); src_data = imlib_image_get_data(); h = gib_imlib_image_get_height(w_image); w = gib_imlib_image_get_width(w_image); unsigned long i; for(i=0; i<w*h; i++) if(dst_data[i] != src_data[i]) { DATA32 alpha; alpha = (src_data[i] & 0xff) - (dst_data[i] & 0xff); alpha = (alpha << 24) & 0xff000000; dst_data[i] = (src_data[i] & 0xffffff) | alpha; } Imlib_Image ret_img; ret_img = imlib_create_image_using_data(w, h, dst_data); imlib_context_set_image(ret_img); imlib_image_set_has_alpha(1); return ret_img; }
void gib_imlib_render_image_part_on_drawable_at_size_with_rotation(Drawable d, Imlib_Image im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, double angle, char dither, char blend, char alias) { Imlib_Image new_im; imlib_context_set_image(im); imlib_context_set_drawable(d); imlib_context_set_anti_alias(alias); imlib_context_set_dither(dither); imlib_context_set_angle(angle); imlib_context_set_blend(blend); new_im = imlib_create_rotated_image(angle); imlib_context_set_image(new_im); imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); imlib_free_image_and_decache(); }
static void update_bg() { if (currootpmap != *rootpmap && *rootpmap != 0) { currootpmap = *rootpmap; imlib_context_set_drawable(currootpmap); if (bg) { imlib_context_set_image(bg); imlib_free_image(); } bg = imlib_create_image_from_drawable(0, bbx, bby, bbwidth, bbheight, 1); Pixmap tile, mask; imlib_context_set_display(bbdpy); imlib_context_set_visual(bbvis); imlib_context_set_drawable(bbwin); imlib_context_set_image(bg); Imlib_Image tmpbg = imlib_clone_image(); tile_image_blend(tmpbg, theme->tile_img, 0, bbwidth); imlib_render_pixmaps_for_whole_image(&tile, &mask); XSetWindowBackgroundPixmap(bbdpy, bbwin, tile); imlib_free_pixmap_and_mask(tile); imlib_free_image(); } }
/* crop image */ Imlib_Image crop(Imlib_Image *source_image, int x, int y, int w, int h) { Imlib_Image new_image; /* construct filtered image here */ Imlib_Image current_image; /* save image pointer */ int width, height; /* source image dimensions */ /* save pointer to current image */ current_image = imlib_context_get_image(); /* get width and height of source image */ imlib_context_set_image(*source_image); width = imlib_image_get_width(); height = imlib_image_get_height(); /* get sane values */ if(x < 0) x = 0; if(y < 0) y = 0; if(x >= width) x = width - 1; if(y >= height) y = height - 1; if(x + w > width) w = width - x; if(y + h > height) h = height - x; /* create the new image */ imlib_context_set_image(*source_image); new_image = imlib_create_cropped_image(x, y, w, h); /* restore image from before function call */ imlib_context_set_image(current_image); /* return filtered image */ return new_image; }
/* draw a white (background) border around image, overwriting image contents * beneath border*/ Imlib_Image white_border(Imlib_Image *source_image, int bdwidth) { Imlib_Image new_image; /* construct filtered image here */ Imlib_Image current_image; /* save image pointer */ int height, width; /* image dimensions */ int x,y; /* coordinates of upper left corner of rectangles */ /* save pointer to current image */ current_image = imlib_context_get_image(); /* create a new image */ imlib_context_set_image(*source_image); height = imlib_image_get_height(); width = imlib_image_get_width(); new_image = imlib_clone_image(); /* assure border width has a legal value */ if(bdwidth > width/2) bdwidth = width/2; if(bdwidth > height/2) bdwidth = height/2; /* draw white (background) rectangle around new image */ for(x=0, y=0; x<bdwidth; x++, y++) { imlib_context_set_image(new_image); ssocr_set_color(BG); imlib_image_draw_rectangle(x, y, width-2*x, height-2*y); } /* restore image from before function call */ imlib_context_set_image(current_image); /* return filtered image */ return new_image; }
static int save_lua( lua_State *L ) { img_t *img = (img_t*)luaL_checkudata( L, 1, MODULE_MT ); const char *path = luaL_checkstring( L, 2 ); ImlibLoadError err = IMLIB_LOAD_ERROR_NONE; Imlib_Image work = imlib_create_image_using_data( img->size.w, img->size.h, img->blob ); // set current image imlib_context_set_image( work ); work = imlib_create_cropped_scaled_image( 0, 0, img->size.w, img->size.h, img->resize.w, img->resize.h ); imlib_free_image_and_decache(); imlib_context_set_image( work ); save2path( img, path, &err ); // failed if( err ){ liberr2errno( err ); lua_pushstring( L, strerror(errno) ); return 2; } // success else { lua_pushnil( L ); } return 1; }
void execp_dump_geometry(void *obj, int indent) { Execp *execp = obj; if (execp->backend->has_icon && execp->backend->icon) { Imlib_Image tmp = imlib_context_get_image(); imlib_context_set_image(execp->backend->icon); fprintf(stderr, "%*sIcon: x = %d, y = %d, w = %d, h = %d\n", indent, "", execp->frontend->iconx, execp->frontend->icony, imlib_image_get_width(), imlib_image_get_height()); if (tmp) imlib_context_set_image(tmp); } fprintf(stderr, "%*sText: x = %d, y = %d, w = %d, align = %s, text = %s\n", indent, "", execp->frontend->textx, execp->frontend->texty, execp->frontend->textw, execp->backend->centered ? "center" : "left", execp->backend->text); }
void image_to_pixmap(image *img, GdkPixmap *pm, int w, int h) { int realw, realh; int need_free; imlib_context_set_image(img->image); realw = imlib_image_get_width(); realh = imlib_image_get_height(); if (w != realw || h != realh) { Imlib_Image newimg; newimg = imlib_create_cropped_scaled_image(0, 0, realw, realh, w, h); imlib_context_set_image(newimg); need_free = TRUE; } else need_free = FALSE; imlib_context_set_display(GDK_WINDOW_XDISPLAY(pm)); imlib_context_set_visual(GDK_VISUAL_XVISUAL(gdk_visual_get_system())); imlib_context_set_colormap (GDK_COLORMAP_XCOLORMAP(gdk_colormap_get_system())); imlib_context_set_drawable(GDK_WINDOW_XWINDOW(pm)); imlib_context_set_blend(1); imlib_render_image_on_drawable(0, 0); if (need_free) imlib_free_image(); }
void render_taskbar(struct task *tasks, struct desktop *desktops) { tile_image(theme->tile_img, taskbar_pos, taskbar_width); int activedesktop = 0; struct desktop *iter = desktops; while (iter) { if (iter->focused) break; activedesktop++; iter = iter->next; } struct task *t = tasks; uint state; int gap = theme->taskbar.space_gap; while (t) { if (t->desktop == activedesktop || t->desktop == -1) { state = t->focused ? BSTATE_PRESSED : BSTATE_IDLE; /* draw bg */ draw_taskbar_button(state, t->posx, t->width); int lgap = get_image_width(theme->taskbar.left_img[state]); int rgap = get_image_width(theme->taskbar.right_img[state]); int x = t->posx + gap + lgap; int w = t->width - ((gap * 2) + lgap + rgap); /* draw icon */ if (theme->taskbar.icon_h && theme->taskbar.icon_w) { int srcw, srch; int y = (theme->height - theme->taskbar.icon_h) / 2; imlib_context_set_image(t->icon); srcw = imlib_image_get_width(); srch = imlib_image_get_height(); y += theme->taskbar.icon_offset_y; x += theme->taskbar.icon_offset_x; w -= theme->taskbar.icon_offset_x; imlib_context_set_image(bb); imlib_context_set_blend(1); imlib_blend_image_onto_image(t->icon, 1, 0, 0, srcw, srch, x, y, theme->taskbar.icon_w, theme->taskbar.icon_h); imlib_context_set_blend(0); x += theme->taskbar.icon_w; w -= theme->taskbar.icon_w; } /* draw text */ imlib_context_set_cliprect(x, 0, w, bbheight); draw_text(theme->taskbar.font, theme->taskbar.text_align, x, w, theme->taskbar.text_offset_x, theme->taskbar.text_offset_y, t->name, &theme->taskbar.text_color[state]); imlib_context_set_cliprect(0, 0, bbwidth, bbheight); /* draw separator if exists */ if (t->next && t->next->desktop == activedesktop) draw_image(theme->taskbar.separator_img, x+w+gap+rgap); } t = t->next; } }
/* draw a fore- or background pixel */ void draw_pixel(Imlib_Image *image, int x, int y, fg_bg_t color) { Imlib_Image *current_image; /* save current image */ current_image = imlib_context_get_image(); imlib_context_set_image(image); ssocr_set_color(color); imlib_image_draw_pixel(x,y,0); imlib_context_set_image(current_image); }
void render_present() { update_bg(); #ifdef WITH_COMPOSITE if (theme->use_composite) { /* * Because XRender can't do directly SRCc * SRCa + DSTc * (1 - SRCa) blending, * I must apply SRCa to my SRCc manually. To do this I'm using PictOpSrc with * alpha channel in mask. So, I need to copy RGB data to one buffer (color) and * Alpha to another buffer (mask), then use them in XRenderComposite. * * But I think in can be done on theme loading stage. Just apply SRCa to SRCc * immediately. Optimization? */ /* copy color part to bbcolor */ imlib_context_set_image(bbcolor); imlib_image_set_has_alpha(1); imlib_context_set_color(0,0,0,255); imlib_image_fill_rectangle(0,0,bbwidth,bbheight); imlib_blend_image_onto_image(bb,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight); imlib_context_set_drawable(pixcolor); imlib_render_image_on_drawable(0,0); /* copy alpha part to bbalpha */ imlib_context_set_image(bbalpha); imlib_image_copy_alpha_to_image(bb,0,0); imlib_image_set_has_alpha(1); imlib_context_set_drawable(pixalpha); imlib_render_image_on_drawable(0,0); XRenderComposite(bbdpy, PictOpSrc, piccolor, picalpha, rootpic, 0, 0, 0, 0, 0, 0, bbwidth, bbheight); } else #endif if (*rootpmap) { imlib_context_set_image(bbcolor); imlib_blend_image_onto_image(bg,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight); imlib_context_set_blend(1); imlib_blend_image_onto_image(bb,0,0,0,bbwidth,bbheight,0,0,bbwidth,bbheight); imlib_context_set_blend(0); imlib_context_set_drawable(bbwin); imlib_render_image_on_drawable(0,0); } else { imlib_context_set_drawable(bbwin); imlib_context_set_image(bb); imlib_render_image_on_drawable(0,0); } }
void feh_edit_inplace(winwidget w, int op) { int tmp; Imlib_Image old = NULL; Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE; if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename) return; if (!strcmp(gib_imlib_image_format(w->im), "jpeg") && !path_is_url(FEH_FILE(w->file->data)->filename)) { feh_edit_inplace_lossless(w, op); feh_reload_image(w, 1, 1); return; } old = imlib_load_image_with_error_return(FEH_FILE(w->file->data)->filename, &err); if ((old != NULL) && (err == IMLIB_LOAD_ERROR_NONE)) { imlib_context_set_image(old); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else imlib_image_orientate(op); gib_imlib_save_image_with_error_return(old, FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); if (err) feh_imlib_print_load_error(FEH_FILE(w->file->data)->filename, w, err); feh_reload_image(w, 1, 1); } else { /* * Image was opened using curl/magick or has been deleted after * opening it */ imlib_context_set_image(w->im); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else { imlib_image_orientate(op); tmp = w->im_w; FEH_FILE(w->file->data)->info->width = w->im_w = w->im_h; FEH_FILE(w->file->data)->info->height = w->im_h = tmp; } im_weprintf(w, "unable to edit in place. Changes have not been saved."); winwidget_render_image(w, 1, 0); } return; }
static int save_trim_lua( lua_State *L ) { img_t *img = (img_t*)luaL_checkudata( L, 1, MODULE_MT ); const char *path = luaL_checkstring( L, 2 ); img_bounds_t bounds = (img_bounds_t){ 0, 0, 0, 0 }; double aspect_org = 0; double aspect = 0; ImlibLoadError err = IMLIB_LOAD_ERROR_NONE; Imlib_Image work = NULL; // calculate bounds of image with maintaining aspect ratio. aspect_org = (double)img->size.w/(double)img->size.h; aspect = (double)img->resize.w/(double)img->resize.h; // based on width if( aspect_org > aspect ){ bounds.w = img->resize.w; bounds.h = (int)((double)bounds.w / aspect_org); } // based on height else if( aspect_org < aspect ){ bounds.h = img->resize.h; bounds.w = (int)((double)bounds.h * aspect_org); } // square else { bounds.w = img->resize.w; bounds.h = img->resize.h; } // create image work = imlib_create_image_using_data( img->size.w, img->size.h, img->blob ); // set current image imlib_context_set_image( work ); work = imlib_create_cropped_scaled_image( 0, 0, img->size.w, img->size.h, bounds.w, bounds.h ); imlib_free_image_and_decache(); imlib_context_set_image( work ); save2path( img, path, &err ); // failed if( err ){ liberr2errno( err ); lua_pushstring( L, strerror(errno) ); } // success else { lua_pushnil( L ); } return 1; }
static inline PyObject * ImageObject_blend_image(PyObject* self, PyObject *args, PyObject *kwargs) { int merge_alpha = 1; PyObject *src = NULL; int src_x = 0, src_y = 0, src_h = -1, src_w = -1; int dest_x = 0, dest_y = 0, dest_h = -1, dest_w = -1; Imlib_Image *src_img; static char *keywords[] = {"img", "src", "dest", "alpha", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|(iiii)(iiii)i:blend_image", keywords, &src, &src_x, &src_y, &src_w, &src_h, &dest_x, &dest_y, &dest_w, &dest_h, &merge_alpha)){ return NULL; } DEBUG("src = %d %d %d %d ", src_x, src_y, src_w, src_h); DEBUG("dest = %d %d %d %d ", dest_x, dest_y, dest_w, dest_h); DEBUG("alpha = %d ", merge_alpha); //check if(!CheckImageObject(src)){ //TODO raise TypeError return NULL; } src_img = (((ImageObject *)src)->image); imlib_context_set_image(src_img); if(src_w == -1){ src_w = imlib_image_get_width(); } if(src_h == -1){ src_h = imlib_image_get_height(); } if(dest_w == -1){ dest_w = src_w; } if(dest_h == -1){ dest_h = src_h; } imlib_context_set_image(((ImageObject *)self)->image); imlib_context_set_blend(1); imlib_blend_image_onto_image(src_img, merge_alpha, src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h); Py_RETURN_NONE; }
/* set pixels that have at least mask pixels around it set (including the * examined pixel itself) to black (foreground), all other pixels to white * (background) */ Imlib_Image set_pixels_filter(Imlib_Image *source_image, double thresh, luminance_t lt, int mask) { Imlib_Image new_image; /* construct filtered image here */ Imlib_Image current_image; /* save image pointer */ int height, width; /* image dimensions */ int x,y,i,j; /* iteration variables */ int set_pixel; /* should pixel be set or not? */ Imlib_Color color; int lum; /* luminance value of pixel */ /* save pointer to current image */ current_image = imlib_context_get_image(); /* create a new image */ imlib_context_set_image(*source_image); height = imlib_image_get_height(); width = imlib_image_get_width(); new_image = imlib_clone_image(); /* check for every pixel if it should be set in filtered image */ for(x=0; x<width; x++) { for(y=0; y<height; y++) { set_pixel=0; for(i=x-1; i<=x+1; i++) { for(j=y-1; j<=y+1; j++) { if(i>=0 && i<width && j>=0 && j<height) { /* i,j inside image? */ imlib_image_query_pixel(i, j, &color); lum = get_lum(&color, lt); if(is_pixel_set(lum, thresh)) { set_pixel++; } } } } /* set pixel if at least mask pixels around it are set */ if(set_pixel >= mask) { draw_fg_pixel(new_image, x, y); } else { draw_bg_pixel(new_image, x, y); } } } /* restore image from before function call */ imlib_context_set_image(current_image); /* return filtered image */ return new_image; }
/** Draw an image in a drawable * \param dr Drawable * \param x X position * \param y Y position * \param name Path of the image */ static void draw_image(Drawable dr, int x, int y, int w, int h, char *name) { Imlib_Image image; if(!name) return; imlib_set_cache_size(2048 * 1024); imlib_context_set_display(dpy); imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy))); imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy))); imlib_context_set_drawable(dr); image = imlib_load_image(patht(name)); imlib_context_set_image(image); if(w <= 0) w = imlib_image_get_width(); if(h <= 0) h = imlib_image_get_height(); if(image) { imlib_render_image_on_drawable_at_size(x, y, w, h); imlib_free_image(); } else warnx("Can't draw image: '%s'", name); return; }
struct R_image * R_load_image_imlib2(struct R_app *app, const char *filename, struct R_image *image) { Imlib_Image *img; if (!image) { image = R_alloc_image(); } if (image) { img = imlib_load_image(filename); if (img) { imlib_context_set_image(img); image->app = app; image->filename = (char *)filename; image->origw = imlib_image_get_width(); image->origh = imlib_image_get_height(); image->orig = img; image->pixmap = image->mask = None; image->tpixmap = image->tmask = None; image->xpixmap = None; #if (USE_XSHM) image->hasshm = 0; #endif } else { fprintf(stderr, "failed to load: %s\n", filename); } } return image; }
static int get_image_width(Imlib_Image img) { if (!img) return 0; imlib_context_set_image(img); return imlib_image_get_width(); }
static void draw_text(Imlib_Font font, uint align, int ox, int width, int offx, int offy, const char *text, struct color *c) { if (!font) return; imlib_context_set_image(bb); imlib_context_set_font(font); imlib_context_set_color(c->r, c->g, c->b, 255); int texth, textw, oy; imlib_get_text_size(text, &textw, &texth); oy = (theme->height - texth) / 2; switch (align) { case ALIGN_LEFT: break; case ALIGN_CENTER: ox += (width - textw) / 2; break; case ALIGN_RIGHT: ox = width - textw; break; } ox += offx; oy += offy; imlib_text_draw(ox, oy, text); }
void feh_menu_draw_submenu_at(int x, int y, Imlib_Image dst, int ox, int oy) { ImlibPolygon poly; x -= ox; y -= oy; imlib_context_set_image(dst); poly = imlib_polygon_new(); imlib_polygon_add_point(poly, x + 2, y + 5); imlib_polygon_add_point(poly, x + 5, y + 7); imlib_polygon_add_point(poly, x + 2, y + 11); imlib_context_set_color(0, 0, 0, 60); imlib_image_fill_polygon(poly); imlib_polygon_free(poly); poly = imlib_polygon_new(); imlib_polygon_add_point(poly, x, y + 3); imlib_polygon_add_point(poly, x + 3, y + 6); imlib_polygon_add_point(poly, x, y + 9); imlib_context_set_color(0, 0, 0, 255); imlib_image_fill_polygon(poly); imlib_polygon_free(poly); return; }
static void _eiw_render_loop(Window win, EImage * im, EiwData * d) { int w, h; XRenderPictFormat *pictfmt; Pixmap pmap; Picture pict; EImageGetSize(im, &w, &h); pictfmt = XRenderFindStandardFormat(disp, PictStandardARGB32); pmap = XCreatePixmap(disp, WinGetXwin(VROOT), w, h, 32); imlib_context_set_image(im); imlib_context_set_drawable(pmap); imlib_render_image_on_drawable(0, 0); pict = XRenderCreatePicture(disp, pmap, pictfmt, 0, 0); XFreePixmap(disp, pmap); if (d->curs != None) XFreeCursor(disp, d->curs); d->curs = XRenderCreateCursor(disp, pict, w / 2, h / 2); XRenderFreePicture(disp, pict); XDefineCursor(disp, win, d->curs); }
void tinto_take_snapshot(const char *path) { Panel* panel = &panel1[0]; if (panel->area.bounds.width > server.monitor[0].width) panel->area.bounds.width = server.monitor[0].width; panel->temp_pmap = XCreatePixmap (server.dsp, server.root_win, panel->area.bounds.width, panel->area.bounds.height, server.depth); rendering (panel); imlib_context_set_drawable (panel->temp_pmap); Imlib_Image img = imlib_create_image_from_drawable (None, 0, 0, panel->area.bounds.width, panel->area.bounds.height, 0); imlib_context_set_image (img); if (!panel_horizontal) { imlib_image_flip_horizontal (); imlib_image_flip_diagonal (); } imlib_save_image (path); imlib_free_image (); }
void tinto_deinit (void) { cleanup_systray (); cleanup_tooltip (); cleanup_clock (); launcher_deinit (); #ifdef ENABLE_BATTERY cleanup_battery (); #endif panel_cleanup (); cleanup_config (); if (default_icon) { imlib_context_set_image (default_icon); imlib_free_image (); default_icon = NULL; } imlib_context_disconnect_display (); cleanup_server (); cleanup_timeout (); if (server.dsp) XCloseDisplay (server.dsp); server.dsp = NULL; }
void feh_menu_item_draw_at(int x, int y, int w, int h, Imlib_Image dst, int ox, int oy, int selected) { imlib_context_set_image(dst); if (selected) gib_imlib_image_fill_rectangle(dst, x - ox, y - oy, w, h, 255, 255, 255, 178); return; }
void slideshow_save_image(winwidget win) { char *tmpname; Imlib_Load_Error err; if (win->file) { tmpname = feh_unique_filename("", FEH_FILE(win->file->data)->name); } else if (mode) { char *tmp; tmp = estrjoin(".", mode, "png", NULL); tmpname = feh_unique_filename("", tmp); free(tmp); } else { tmpname = feh_unique_filename("", "noname.png"); } if (opt.verbose) printf("saving image to filename '%s'\n", tmpname); /* XXX gib_imlib_save_image_with_error_return breaks with *.XXX and * similar because it tries to set the image format, which only works * with .xxx . * So we leave that part out. */ imlib_context_set_image(win->im); imlib_save_image_with_error_return(tmpname, &err); if (err) im_weprintf(win, "Can't save image %s:", tmpname); free(tmpname); return; }
void draw_execp(void *obj, cairo_t *c) { Execp *execp = obj; PangoLayout *layout = pango_cairo_create_layout(c); if (execp->backend->has_icon && execp->backend->icon) { imlib_context_set_image(execp->backend->icon); // Render icon render_image(execp->area.pix, execp->frontend->iconx, execp->frontend->icony); } // draw layout pango_layout_set_font_description(layout, execp->backend->font_desc); pango_layout_set_width(layout, execp->frontend->textw * PANGO_SCALE); pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); if (!execp->backend->has_markup) pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text)); else pango_layout_set_markup(layout, execp->backend->text, strlen(execp->backend->text)); pango_cairo_update_layout(c, layout); draw_text(layout, c, execp->frontend->textx, execp->frontend->texty, &execp->backend->font_color, panel_config.font_shadow); g_object_unref(layout); }
void XImlib2Image::repaint() { XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(container); Imlib_Image cropImage = xContainer->bg->createCropImage(x, y, width, height, width, height); imlib_context_set_dither(1); imlib_context_set_blend(1); //automatically blend image and background imlib_context_set_dither_mask(0); imlib_context_set_image(cropImage); imlib_blend_image_onto_image(image, 1, 0, 0, width, height, 0, 0, width, height); imlib_image_set_has_alpha(1); imlib_context_set_anti_alias(1); //smoother scaling imlib_context_set_blend(0); imlib_context_set_drawable(window); imlib_render_image_on_drawable_at_size(0, 0, width, height); imlib_free_image(); imlib_context_set_drawable(xContainer->getRootWindow()); }
int main(int argc, char **argv) { char *dot, *colon, *n, *oldn; Imlib_Image im; /* I'm just plain being lazy here.. get our basename. */ for (oldn = n = argv[0]; n; oldn = n) n = strchr(++oldn, '/'); if (argc < 3 || !strcmp(argv[1], "-h")) usage(-1); if (!(im = imlib_load_image(argv[1]))) { fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]); exit(-1); } /* we only care what format the export format is. */ imlib_context_set_image(im); /* hopefully the last one will be the one we want.. */ dot = strrchr(argv[2], '.'); /* if there's a format, snarf it and set the format. */ if (dot && *(dot + 1)) { colon = strrchr(++dot, ':'); /* if a db file with a key, export it to a db. */ if (colon && *(colon + 1)) { *colon = 0; /* beats having to look for strcasecmp() */ if (!strncmp(dot, "db", 2) || !strncmp(dot, "dB", 2) || !strncmp(dot, "DB", 2) || !strncmp(dot, "Db", 2)) { imlib_image_set_format("db"); } *colon = ':'; } else { char *p, *q; /* max length of 8 for format name. seems reasonable. */ q = p = malloc(9); memset(p, 0, 8); strncpy(p, dot, (strlen(dot) < 9) ? strlen(dot) : 8); /* Imlib2 only recognizes lowercase formats. convert it. */ for (q[8] = 0; *q; q++) *q = tolower(*q); imlib_image_set_format(p); free(p); } dot--; } else imlib_image_set_format("jpg"); imlib_save_image(argv[2]); return 0; }
PyObject *image_to_surface(PyObject *self, PyObject *args) { PyObject *pyimg; Imlib_Image *img; PySurfaceObject *pysurf; unsigned char *pixels; static int init = 0; CHECK_IMAGE_PYOBJECT if (init == 0) { import_pygame_surface(); init = 1; } if (!PyArg_ParseTuple(args, "O!O!", Image_PyObject_Type, &pyimg, &PySurface_Type, &pysurf)) return NULL; img = imlib_image_from_pyobject(pyimg); imlib_context_set_image(img); pixels = (unsigned char *)imlib_image_get_data_for_reading_only(); memcpy(pysurf->surf->pixels, pixels, imlib_image_get_width() * imlib_image_get_height() * 4); Py_INCREF(Py_None); return Py_None; }