diff --git a/src/E.h b/src/E.h index 71b1cae1..aac0e6a7 100644 --- a/src/E.h +++ b/src/E.h @@ -61,8 +61,6 @@ #define USE_COMPOSITE 1 #endif -#include - #define ENABLE_COLOR_MODIFIERS 0 /* Not functional */ #define ENABLE_TRANSPARENCY 1 @@ -669,7 +667,6 @@ void DialogAlertOK(const char *fmt, ...); void DockIt(EWin * ewin); /* draw.c */ -Imlib_Image *ELoadImage(const char *file); void DrawEwinShape(EWin * ewin, int md, int x, int y, int w, int h, char firstlast); diff --git a/src/Makefile.am b/src/Makefile.am index 90402994..e646d13a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,6 +45,8 @@ e16_SOURCES = \ econfig.c \ econfig.h \ edge.c \ + eimage.c \ + eimage.h \ emodule.c \ emodule.h \ eobj.c \ diff --git a/src/backgrounds.c b/src/backgrounds.c index 9d24afa9..5fd60404 100644 --- a/src/backgrounds.c +++ b/src/backgrounds.c @@ -27,6 +27,7 @@ #include "desktops.h" #include "dialog.h" #include "e16-ecore_list.h" +#include "eimage.h" #include "emodule.h" #include "iclass.h" #include "tclass.h" @@ -36,7 +37,7 @@ typedef struct { char *file; char *real_file; - Imlib_Image *im; + EImage *im; char keep_aspect; int xjust, yjust; int xperc, yperc; @@ -168,7 +169,7 @@ BackgroundPixmapFree(Background * bg) { if (bg->pmap) { - imlib_free_pixmap_and_mask(bg->pmap); + EImagePixmapFree(bg->pmap); bg->pmap = None; } } @@ -178,14 +179,12 @@ BackgroundImagesFree(Background * bg) { if (bg->bg.im) { - imlib_context_set_image(bg->bg.im); - imlib_free_image(); + EImageFree(bg->bg.im); bg->bg.im = NULL; } if (bg->top.im) { - imlib_context_set_image(bg->top.im); - imlib_free_image(); + EImageFree(bg->top.im); bg->top.im = NULL; } } @@ -451,7 +450,9 @@ static void BgFindImageSize(BgPart * bgp, unsigned int rw, unsigned int rh, unsigned int *pw, unsigned int *ph) { - int w, h; + int w, h, iw, ih; + + EImageGetSize(bgp->im, &iw, &ih); if (bgp->keep_aspect) bgp->xperc = bgp->yperc; @@ -459,12 +460,12 @@ BgFindImageSize(BgPart * bgp, unsigned int rw, unsigned int rh, if (bgp->xperc > 0) w = (rw * bgp->xperc) >> 10; else - w = (imlib_image_get_width() * rw) / VRoot.w; + w = (iw * rw) / VRoot.w; if (bgp->yperc > 0) h = (rh * bgp->yperc) >> 10; else - h = (imlib_image_get_height() * rh) / VRoot.h; + h = (ih * rh) / VRoot.h; if (w <= 0) w = 1; @@ -475,15 +476,13 @@ BgFindImageSize(BgPart * bgp, unsigned int rw, unsigned int rh, { if (bgp->yperc <= 0) { - if (((w << 10) / h) != - ((imlib_image_get_width() << 10) / imlib_image_get_height())) - h = ((w * imlib_image_get_height()) / imlib_image_get_width()); + if (((w << 10) / h) != ((iw << 10) / ih)) + h = ((w * ih) / iw); } else { - if (((h << 10) / w) != - ((imlib_image_get_height() << 10) / imlib_image_get_width())) - w = ((h * imlib_image_get_width()) / imlib_image_get_height()); + if (((h << 10) / w) != ((ih << 10) / iw)) + w = ((h * iw) / ih); } } @@ -491,83 +490,6 @@ BgFindImageSize(BgPart * bgp, unsigned int rw, unsigned int rh, *ph = (unsigned int)h; } -static void -e16_tile_image_onto_image(Imlib_Image * tile, int blend, int tw, int th, - int dx, int dy, int dw, int dh, int ox, int oy) -{ - Imlib_Image *im, *tim; - int x, y, tx, ty, ww, hh; - int sw, sh; - - im = imlib_context_get_image(); - imlib_context_set_image(tile); - sw = imlib_image_get_width(); - sh = imlib_image_get_height(); - if (sw == tw && sh == th) - { - tim = tile; - } - else - { - tim = imlib_create_image(tw, th); - imlib_context_set_image(tim); - imlib_context_set_blend(0); - imlib_blend_image_onto_image(tile, 0, 0, 0, sw, sh, 0, 0, tw, th); - } - imlib_context_set_image(im); - - if (ox) - { - ox = tw - ox; - ox %= tw; - if (ox < 0) - ox += tw; - } - if (oy) - { - oy = th - oy; - oy %= th; - if (oy < 0) - oy += th; - } - dw += dx; - dh += dy; - y = dy; - ty = oy; - hh = th - oy; - for (;;) - { - if (y + hh >= dh) - hh = dh - y; - if (hh <= 0) - break; - x = dx; - tx = ox; - ww = tw - ox; - for (;;) - { - if (x + ww >= dw) - ww = dw - x; - if (ww <= 0) - break; - imlib_blend_image_onto_image(tim, blend, tx, ty, ww, hh, - x, y, ww, hh); - tx = 0; - x += ww; - ww = tw; - } - ty = 0; - y += hh; - hh = th; - } - if (tim != tile) - { - imlib_context_set_image(tim); - imlib_free_image(); - imlib_context_set_image(im); - } -} - static Pixmap BackgroundCreatePixmap(Window win, unsigned int w, unsigned int h, unsigned int depth) @@ -596,11 +518,10 @@ BackgroundRealize(Background * bg, Drawable draw, unsigned int rw, { Pixmap pmap; GC gc; - int rt; - int x, y; - unsigned int w, h, ww, hh; + int x, y, ww, hh; + unsigned int w, h; char hasbg, hasfg; - Imlib_Image *im; + EImage *im; #if ENABLE_COLOR_MODIFIERS ColorModifierClass *cm; @@ -610,14 +531,14 @@ BackgroundRealize(Background * bg, Drawable draw, unsigned int rw, { if (!bg->bg.real_file) bg->bg.real_file = ThemeFileFind(bg->bg.file, 0); - bg->bg.im = ELoadImage(bg->bg.real_file); + bg->bg.im = EImageLoad(bg->bg.real_file); } if (bg->top.file && !bg->top.im) { if (!bg->top.real_file) bg->top.real_file = ThemeFileFind(bg->top.file, 0); - bg->top.im = ELoadImage(bg->top.real_file); + bg->top.im = EImageLoad(bg->top.real_file); } #if ENABLE_COLOR_MODIFIERS @@ -677,21 +598,10 @@ BackgroundRealize(Background * bg, Drawable draw, unsigned int rw, /* Has either bg or fg image */ - rt = imlib_context_get_dither(); - if (Conf.backgrounds.hiquality) - { - imlib_context_set_dither(1); -#if 0 /* ??? */ - imlib_context_set_anti_alias(1); -#endif - } - w = h = x = y = 0; if (hasbg) { - imlib_context_set_image(bg->bg.im); - BgFindImageSize(&(bg->bg), rw, rh, &w, &h); x = ((int)(rw - w) * bg->bg.xjust) >> 10; y = ((int)(rh - h) * bg->bg.yjust) >> 10; @@ -702,8 +612,7 @@ BackgroundRealize(Background * bg, Drawable draw, unsigned int rw, { /* Window, no fg, no offset, and scale to 100%, or tiled, no trans */ pmap = BackgroundCreatePixmap(draw, w, h, VRoot.depth); - imlib_context_set_drawable(pmap); - imlib_render_image_on_drawable_at_size(0, 0, w, h); + EImageRenderOnDrawable(bg->bg.im, pmap, 0, 0, w, h, 0); #if 0 /* FIXME - Remove? */ if (x == 0 && y == 0) /* Hmmm. Always true. */ @@ -728,72 +637,55 @@ BackgroundRealize(Background * bg, Drawable draw, unsigned int rw, pmap = BackgroundCreatePixmap(draw, rw, rh, VRoot.depth); else pmap = draw; - imlib_context_set_drawable(pmap); if (hasbg && !hasfg && x == 0 && y == 0 && w == rw && h == rh) { im = bg->bg.im; - imlib_context_set_image(im); } else { /* Create full size image */ - im = imlib_create_image(rw, rh); - imlib_context_set_image(im); - imlib_image_set_has_alpha(0); + im = EImageCreate(rw, rh); + EImageSetHasAlpha(im, 0); if (!hasbg || !bg->bg_tile) { /* Fill solid */ - imlib_context_set_blend(0); - imlib_context_set_color(bg->bg_solid.red, bg->bg_solid.green, - bg->bg_solid.blue, 0); - imlib_image_fill_rectangle(0, 0, rw, rh); + EImageFill(im, 0, 0, rw, rh, bg->bg_solid.red, bg->bg_solid.green, + bg->bg_solid.blue, 255); } if (hasbg) { if (bg->bg_tile) { - e16_tile_image_onto_image(bg->bg.im, 0, w, h, - 0, 0, rw, rh, x, y); + EImageTile(im, bg->bg.im, 0, w, h, 0, 0, rw, rh, x, y); } else { - imlib_context_set_image(bg->bg.im); - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); - imlib_context_set_image(im); - imlib_blend_image_onto_image(bg->bg.im, 1, 0, 0, ww, hh, - x, y, w, h); + EImageGetSize(bg->bg.im, &ww, &hh); + EImageBlend(im, bg->bg.im, 0, 0, 0, ww, hh, x, y, w, h, 1, 0); } } } if (hasfg) { - imlib_context_set_image(bg->top.im); + EImageGetSize(bg->top.im, &ww, &hh); BgFindImageSize(&(bg->top), rw, rh, &w, &h); x = ((rw - w) * bg->top.xjust) >> 10; y = ((rh - h) * bg->top.yjust) >> 10; - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); - imlib_context_set_image(im); - imlib_context_set_blend(1); - imlib_blend_image_onto_image(bg->top.im, 0, 0, 0, ww, hh, x, y, w, h); - imlib_context_set_blend(0); + EImageBlend(im, bg->top.im, 1, 0, 0, ww, hh, x, y, w, h, 0, 0); } - imlib_render_image_on_drawable_at_size(0, 0, rw, rh); + EImageRenderOnDrawable(im, pmap, 0, 0, rw, rh, 0); if (im != bg->bg.im) - imlib_free_image(); + EImageFree(im); done: if (!bg->keepim) BackgroundImagesFree(bg); - imlib_context_set_dither(rt); - if (ppmap) *ppmap = pmap; if (ppixel) @@ -821,7 +713,7 @@ BackgroundApplyWin(Background * bg, Window win) if (pmap != None) { ESetWindowBackgroundPixmap(win, pmap); - imlib_free_pixmap_and_mask(pmap); + EImagePixmapFree(pmap); } else { @@ -858,7 +750,7 @@ BrackgroundCreateFromImage(const char *bgid, const char *file, char *thumb, int thlen) { Background *bg; - Imlib_Image *im, *im2; + EImage *im, *im2; XColor xclr; char tile = 1, keep_asp = 0; int width, height; @@ -883,13 +775,11 @@ BrackgroundCreateFromImage(const char *bgid, const char *file, return bg; } - im = imlib_load_image(file); + im = EImageLoad(file); if (!im) return NULL; - imlib_context_set_image(im); - width = imlib_image_get_width(); - height = imlib_image_get_height(); + EImageGetSize(im, &width, &height); if (thumb) { @@ -900,14 +790,13 @@ BrackgroundCreateFromImage(const char *bgid, const char *file, w2 = maxw; h2 = (height * w2) / width; } - im2 = imlib_create_cropped_scaled_image(0, 0, width, height, w2, h2); - imlib_free_image_and_decache(); - imlib_context_set_image(im2); - imlib_image_set_format("png"); - imlib_save_image(thumb); - imlib_free_image_and_decache(); + im2 = EImageCreateScaled(im, 0, 0, width, height, w2, h2); + EImageSave(im2, thumb); + EImageDecache(im2); } + EImageDecache(im); + /* Quit if the background itself already exists */ if (bg) return bg; @@ -1038,22 +927,21 @@ BackgroundIsNone(const Background * bg) return (bg) ? bg->external : 1; } -static Imlib_Image * +static EImage * BackgroundCacheMini(Background * bg, int keep, int nuke) { char s[4096]; - Imlib_Image *im; + EImage *im; Pixmap pmap; Esnprintf(s, sizeof(s), "%s/cached/bgsel/%s.png", EDirUserCache(), BackgroundGetName(bg)); - im = ELoadImage(s); + im = EImageLoad(s); if (im) { - imlib_context_set_image(im); if (nuke) - imlib_free_image_and_decache(); + EImageDecache(im); else goto done; } @@ -1061,17 +949,14 @@ BackgroundCacheMini(Background * bg, int keep, int nuke) /* Create new cached bg mini image */ pmap = ECreatePixmap(VRoot.win, 64, 48, VRoot.depth); BackgroundApplyPmap(bg, pmap, 64, 48); - imlib_context_set_drawable(pmap); - im = imlib_create_image_from_drawable(0, 0, 0, 64, 48, 0); - imlib_context_set_image(im); - imlib_image_set_format("png"); - imlib_save_image(s); + im = EImageGrabDrawable(pmap, None, 0, 0, 64, 48, 0); + EImageSave(im, s); EFreePixmap(pmap); done: if (keep) return im; - imlib_free_image(); + EImageFree(im); return NULL; } @@ -1841,7 +1726,7 @@ BG_RedrawView(void) { if (((x + 64 + 8) >= 0) && (x < w)) { - Imlib_Image *im; + EImage *im; if (ic_button) ImageclassApplySimple(ic_button, win, pmap, @@ -1870,10 +1755,8 @@ BG_RedrawView(void) im = BackgroundCacheMini(bg, 1, 0); if (im) { - imlib_context_set_image(im); - imlib_context_set_drawable(pmap); - imlib_render_image_on_drawable_at_size(x + 4, 4, 64, 48); - imlib_free_image(); + EImageRenderOnDrawable(im, pmap, x + 4, 4, 64, 48, 0); + EImageFree(im); } } } diff --git a/src/borders.c b/src/borders.c index 2ab1092c..0083aaa2 100644 --- a/src/borders.c +++ b/src/borders.c @@ -256,7 +256,7 @@ BorderWinpartCalc(EWin * ewin, int i, int ww, int hh) int dummywidth, wmax, wmin; ImageClass *iclass; TextClass *tclass; - Imlib_Border *pad; + EImageBorder *pad; /* * calculate width before height, because we need it in order to @@ -321,7 +321,7 @@ BorderWinpartCalc(EWin * ewin, int i, int ww, int hh) int dummyheight; ImageClass *iclass; TextClass *tclass; - Imlib_Border *pad; + EImageBorder *pad; iclass = ewin->border->part[i].iclass; tclass = ewin->border->part[i].tclass; diff --git a/src/borders.h b/src/borders.h index 9296bb9f..864bb406 100644 --- a/src/borders.h +++ b/src/borders.h @@ -24,6 +24,8 @@ #ifndef _BORDERS_H_ #define _BORDERS_H_ +#include "eimage.h" + typedef struct _winpoint { int originbox; @@ -60,7 +62,7 @@ typedef struct _border { char *name; char *group_border_name; - Imlib_Border border; + EImageBorder border; int num_winparts; WinPart *part; char changes_shape; diff --git a/src/buttons.c b/src/buttons.c index 9fdb1f71..af18104a 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -26,6 +26,7 @@ #include "buttons.h" #include "desktops.h" #include "e16-ecore_list.h" +#include "eimage.h" #include "emodule.h" #include "iclass.h" #include "tclass.h" @@ -225,7 +226,7 @@ static void ButtonCalc(Button * b) { int w, h, x, y, xo, yo; - Imlib_Image *im; + EImage *im; x = 0; y = 0; @@ -236,10 +237,8 @@ ButtonCalc(Button * b) im = ImageclassGetImage(b->iclass, 0, 0, 0); if (im) { - imlib_context_set_image(im); - w = imlib_image_get_width(); - h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &w, &h); + EImageFree(im); } else { diff --git a/src/coords.c b/src/coords.c index 22ba7079..8715173b 100644 --- a/src/coords.c +++ b/src/coords.c @@ -42,7 +42,7 @@ CoordsShow(EWin * ewin) unsigned int w, h; int cx, cy, cw, ch; EObj *eo = coord_eo; - Imlib_Border *pad; + EImageBorder *pad; int bl, br, bt, bb; if (!Conf.movres.mode_info) diff --git a/src/dialog.c b/src/dialog.c index b9a0a8d5..bf7bd0b0 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -24,6 +24,7 @@ #include "E.h" #include "dialog.h" #include "e16-ecore_list.h" +#include "eimage.h" #include "ewins.h" #include "hints.h" #include "iclass.h" @@ -124,7 +125,7 @@ struct _ditem void *data; ImageClass *iclass; TextClass *tclass; - Imlib_Border padding; + EImageBorder padding; char fill_h; char fill_v; int align_h; @@ -319,7 +320,7 @@ void DialogSetText(Dialog * d, const char *text) { int w, h; - Imlib_Border *pad; + EImageBorder *pad; if (d->text) Efree(d->text); @@ -367,7 +368,7 @@ DialogAddButton(Dialog * d, const char *text, DialogCallbackFunc * func, { DButton *db; int w, h; - Imlib_Border *pad; + EImageBorder *pad; db = Emalloc(sizeof(DButton)); @@ -414,7 +415,7 @@ static void DialogDrawButton(Dialog * d __UNUSED__, DButton * db) { int state; - Imlib_Image *im; + EImage *im; state = STATE_NORMAL; if ((db->hilited) && (db->clicked)) @@ -439,16 +440,16 @@ DialogDrawButton(Dialog * d __UNUSED__, DButton * db) switch (db->image) { case DLG_BUTTON_OK: - im = ELoadImage("pix/ok.png"); + im = EImageLoad("pix/ok.png"); break; case DLG_BUTTON_CANCEL: - im = ELoadImage("pix/cancel.png"); + im = EImageLoad("pix/cancel.png"); break; case DLG_BUTTON_APPLY: - im = ELoadImage("pix/apply.png"); + im = EImageLoad("pix/apply.png"); break; case DLG_BUTTON_CLOSE: - im = ELoadImage("pix/close.png"); + im = EImageLoad("pix/close.png"); break; default: break; @@ -458,7 +459,7 @@ DialogDrawButton(Dialog * d __UNUSED__, DButton * db) if (im) { ImageClass *ic = db->iclass; - Imlib_Border *pad; + EImageBorder *pad; int h; pad = ImageclassGetPadding(ic); @@ -468,12 +469,8 @@ DialogDrawButton(Dialog * d __UNUSED__, DButton * db) db->w - (h + 2 + pad->left + pad->right), h, h, TextclassGetJustification(db->tclass)); - imlib_context_set_image(im); - imlib_context_set_drawable(db->win); - imlib_context_set_blend(1); - imlib_render_image_on_drawable_at_size(pad->left, pad->top, h, h); - imlib_context_set_blend(0); - imlib_free_image(); + EImageRenderOnDrawable(im, db->win, pad->left, pad->top, h, h, 1); + EImageFree(im); } else { @@ -576,7 +573,7 @@ ShowDialog(Dialog * d) { int i, w, h, mw, mh; EWin *ewin; - Imlib_Border *pad; + EImageBorder *pad; if (d->title) { @@ -946,8 +943,8 @@ DialogRealizeItem(Dialog * d, DItem * di) const char *def = NULL; int iw = 0, ih = 0; int register_win_callback; - Imlib_Image *im; - Imlib_Border *pad; + EImage *im; + EImageBorder *pad; if (di->type == DITEM_BUTTON) { @@ -1042,10 +1039,9 @@ DialogRealizeItem(Dialog * d, DItem * di) im = ImageclassGetImage(di->item.slider.ic_base, 0, 0, 0); if (im) { - imlib_context_set_image(im); - di->item.slider.base_orig_w = imlib_image_get_width(); - di->item.slider.base_orig_h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &di->item.slider.base_orig_w, + &di->item.slider.base_orig_h); + EImageFree(im); } if (di->item.slider.ic_base) ImageclassIncRefcount(di->item.slider.ic_base); @@ -1069,10 +1065,9 @@ DialogRealizeItem(Dialog * d, DItem * di) im = ImageclassGetImage(di->item.slider.ic_knob, 0, 0, 0); if (im) { - imlib_context_set_image(im); - di->item.slider.knob_orig_w = imlib_image_get_width(); - di->item.slider.knob_orig_h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &di->item.slider.knob_orig_w, + &di->item.slider.knob_orig_h); + EImageFree(im); } if (!di->item.slider.ic_border) { @@ -1093,10 +1088,9 @@ DialogRealizeItem(Dialog * d, DItem * di) im = ImageclassGetImage(di->item.slider.ic_border, 0, 0, 0); if (im) { - imlib_context_set_image(im); - di->item.slider.border_orig_w = imlib_image_get_width(); - di->item.slider.border_orig_h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &di->item.slider.border_orig_w, + &di->item.slider.border_orig_h); + EImageFree(im); di->item.slider.border_win = ECreateWindow(d->win, -20, -20, 2, 2, 0); EMapWindow(di->item.slider.border_win); @@ -1153,10 +1147,9 @@ DialogRealizeItem(Dialog * d, DItem * di) im = ImageclassGetImage(di->iclass, 0, 0, 0); if (im) { - imlib_context_set_image(im); - di->item.check_button.check_orig_w = imlib_image_get_width(); - di->item.check_button.check_orig_h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &di->item.check_button.check_orig_w, + &di->item.check_button.check_orig_h); + EImageFree(im); } TextSize(di->tclass, 0, 0, STATE_NORMAL, di->text, &iw, &ih, 17); if (ih < di->item.check_button.check_orig_h) @@ -1179,22 +1172,19 @@ DialogRealizeItem(Dialog * d, DItem * di) di->h = ih; break; case DITEM_IMAGE: - im = ELoadImage(di->item.image.image); + im = EImageLoad(di->item.image.image); if (im) { Pixmap pmap = 0, mask = 0; - imlib_context_set_image(im); - iw = imlib_image_get_width(); - ih = imlib_image_get_height(); + EImageGetSize(im, &iw, &ih); di->win = ECreateWindow(d->win, 0, 0, iw, ih, 0); EMapWindow(di->win); - imlib_context_set_drawable(di->win); - imlib_render_pixmaps_for_whole_image(&pmap, &mask); + EImageRenderPixmaps(im, di->win, &pmap, &mask, 0, 0); ESetWindowBackgroundPixmap(di->win, pmap); EShapeCombineMask(di->win, ShapeBounding, 0, 0, mask, ShapeSet); - imlib_free_pixmap_and_mask(pmap); - imlib_free_image(); + EImagePixmapFree(pmap); + EImageFree(im); } di->w = iw; di->h = ih; @@ -1215,10 +1205,9 @@ DialogRealizeItem(Dialog * d, DItem * di) im = ImageclassGetImage(di->iclass, 0, 0, 0); if (im) { - imlib_context_set_image(im); - di->item.radio_button.radio_orig_w = imlib_image_get_width(); - di->item.radio_button.radio_orig_h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &di->item.radio_button.radio_orig_w, + &di->item.radio_button.radio_orig_h); + EImageFree(im); } TextSize(di->tclass, 0, 0, STATE_NORMAL, di->text, &iw, &ih, 17); if (ih < di->item.radio_button.radio_orig_h) @@ -1565,7 +1554,7 @@ static void DialogDrawItem(Dialog * d, DItem * di) { int state; - Imlib_Border *pad; + EImageBorder *pad; if (!di->update && di->type != DITEM_TABLE) return; @@ -1773,7 +1762,7 @@ DialogsCheckUpdate(void) static void DialogItemsRealize(Dialog * d) { - Imlib_Border *pad; + EImageBorder *pad; if (!d->item) return; diff --git a/src/draw.c b/src/draw.c index db6145da..c8c20949 100644 --- a/src/draw.c +++ b/src/draw.c @@ -981,29 +981,3 @@ DrawEwinShape(EWin * ewin, int md, int x, int y, int w, int h, char firstlast) CoordsHide(); } } - -Imlib_Image * -ELoadImage(const char *file) -{ - Imlib_Image *im; - char *f; - - if (!file) - return NULL; - - if (file[0] == '/') - { - im = imlib_load_image(file); - return im; - } - - f = ThemeFileFind(file, 0); - if (f) - { - im = imlib_load_image(f); - Efree(f); - return im; - } - - return NULL; -} diff --git a/src/eimage.c b/src/eimage.c new file mode 100644 index 00000000..d750f63e --- /dev/null +++ b/src/eimage.c @@ -0,0 +1,470 @@ +/* + * Copyright (C) 2004-2006 Kim Woelders + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include "E.h" +#include "eimage.h" +#include "xwin.h" +#include + +void +EImageInit(Display * dpy) +{ + imlib_set_cache_size(2048 * 1024); + imlib_set_font_cache_size(512 * 1024); + + imlib_set_color_usage(128); + + imlib_context_set_display(dpy); + imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy))); + imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy))); + + imlib_context_set_dither(1); +} + +EImage * +EImageLoad(const char *file) +{ + EImage *im; + char *f; + + if (!file) + return NULL; + + if (file[0] == '/') + { + im = imlib_load_image(file); + return im; + } + + f = ThemeFileFind(file, 0); + if (f) + { + im = imlib_load_image(f); + Efree(f); + return im; + } + + return NULL; +} + +void +EImageSave(EImage * im, const char *file) +{ + imlib_context_set_image(im); + imlib_image_set_format("png"); + imlib_save_image(file); +} + +EImage * +EImageCreate(int w, int h) +{ + EImage *im; + + im = imlib_create_image(w, h); + + return im; +} + +EImage * +EImageCreateFromData(int w, int h, unsigned int *data) +{ + EImage *im; + + im = imlib_create_image_using_copied_data(w, h, data); + + return im; +} + +EImage * +EImageCreateScaled(EImage * im, int sx, int sy, int sw, int sh, int dw, int dh) +{ + imlib_context_set_image(im); + if (sw <= 0) + sw = imlib_image_get_width(); + if (sh <= 0) + sh = imlib_image_get_height(); + return imlib_create_cropped_scaled_image(sx, sy, sw, sh, dw, dh); +} + +void +EImageFree(EImage * im) +{ + imlib_context_set_image(im); + imlib_free_image(); +} + +void +EImageDecache(EImage * im) +{ + imlib_context_set_image(im); + imlib_free_image_and_decache(); +} + +static int +_EImageCheckAlpha(void) +{ + static const short oink = 3; /* For endianness checking */ + unsigned char *pb, *pe; + + if (!imlib_image_has_alpha()) + return 0; + + pb = (unsigned char *)imlib_image_get_data_for_reading_only(); + pe = pb + 4 * imlib_image_get_width() * imlib_image_get_height(); + pb += *((char *)(&oink)); + for (; pb < pe; pb += 4) + if (*pb != 0xff) + return 1; + + return 0; +} + +void +EImageCheckAlpha(EImage * im) +{ + imlib_context_set_image(im); + + if (imlib_image_has_alpha() && !_EImageCheckAlpha()) + { +#if 0 + Eprintf("Alpha set but no shape %s\n", is->real_file); +#endif + imlib_image_set_has_alpha(0); + } +} + +void +EImageSetHasAlpha(EImage * im, int has_alpha) +{ + imlib_context_set_image(im); + imlib_image_set_has_alpha(has_alpha); +} + +void +EImageSetBorder(EImage * im, EImageBorder * border) +{ + Imlib_Border ib; + + ib.left = border->left; + ib.right = border->right; + ib.top = border->top; + ib.bottom = border->bottom; + imlib_context_set_image(im); + imlib_image_set_border(&ib); +} + +int +EImageHasAlpha(EImage * im) +{ + imlib_context_set_image(im); + return imlib_image_has_alpha(); +} + +void +EImageGetSize(EImage * im, int *pw, int *ph) +{ + imlib_context_set_image(im); + *pw = imlib_image_get_width(); + *ph = imlib_image_get_height(); +} + +void +EImageFill(EImage * im, int x, int y, int w, int h, int r, int g, int b, int a) +{ + imlib_context_set_image(im); + imlib_context_set_color(r, g, b, a); + imlib_context_set_blend(0); + imlib_image_fill_rectangle(x, y, w, h); +} + +void +EImageOrientate(EImage * im, int orientation) +{ + imlib_context_set_image(im); + imlib_image_orientate(orientation); +} + +void +EImageBlend(EImage * im, EImage * src, int blend, + int sx, int sy, int sw, int sh, + int dx, int dy, int dw, int dh, int merge_alpha, int anti_alias) +{ + imlib_context_set_image(im); + if (anti_alias) + imlib_context_set_anti_alias(1); + if (blend) + imlib_context_set_blend(1); + imlib_blend_image_onto_image(src, merge_alpha, sx, sy, sw, sh, + dx, dy, dw, dh); + if (blend) + imlib_context_set_blend(0); + if (anti_alias) + imlib_context_set_anti_alias(0); +} + +void +EImageBlendCM(EImage * im, EImage * src, EImageColorModifier * icm) +{ + int w, h, iw, ih; + + imlib_context_set_image(src); + iw = imlib_image_get_width(); + ih = imlib_image_get_height(); + imlib_context_set_image(im); + w = imlib_image_get_width(); + h = imlib_image_get_height(); + + imlib_context_set_blend(1); + if (icm) + imlib_context_set_color_modifier(icm); + imlib_context_set_operation(IMLIB_OP_COPY); + imlib_blend_image_onto_image(src, 0, 0, 0, iw, ih, 0, 0, w, h); + imlib_context_set_blend(0); + if (icm) + imlib_context_set_color_modifier(NULL); +} + +void +EImageTile(EImage * im, EImage * tile, int blend, int tw, int th, + int dx, int dy, int dw, int dh, int ox, int oy) +{ + Imlib_Image *tim; + int x, y, tx, ty, ww, hh; + int sw, sh; + + imlib_context_set_image(tile); + sw = imlib_image_get_width(); + sh = imlib_image_get_height(); + if (sw == tw && sh == th) + { + tim = tile; + } + else + { + tim = imlib_create_image(tw, th); + imlib_context_set_image(tim); + imlib_context_set_blend(0); + imlib_blend_image_onto_image(tile, 0, 0, 0, sw, sh, 0, 0, tw, th); + } + imlib_context_set_image(im); + + if (ox) + { + ox = tw - ox; + ox %= tw; + if (ox < 0) + ox += tw; + } + if (oy) + { + oy = th - oy; + oy %= th; + if (oy < 0) + oy += th; + } + dw += dx; + dh += dy; + y = dy; + ty = oy; + hh = th - oy; + for (;;) + { + if (y + hh >= dh) + hh = dh - y; + if (hh <= 0) + break; + x = dx; + tx = ox; + ww = tw - ox; + for (;;) + { + if (x + ww >= dw) + ww = dw - x; + if (ww <= 0) + break; + imlib_blend_image_onto_image(tim, blend, tx, ty, ww, hh, + x, y, ww, hh); + tx = 0; + x += ww; + ww = tw; + } + ty = 0; + y += hh; + hh = th; + } + if (tim != tile) + { + imlib_context_set_image(tim); + imlib_free_image(); + imlib_context_set_image(im); /* FIXME - Remove */ + } +} + +EImage * +EImageGrabDrawable(Drawable draw, Pixmap mask, int x, int y, int w, int h, + int grab) +{ + EImage *im; + + imlib_context_set_drawable(draw); + im = imlib_create_image_from_drawable(mask, x, y, w, h, grab); + + return im; +} + +EImage * +EImageGrabDrawableScaled(Drawable draw, Pixmap mask, int x, int y, int w, int h, + int iw, int ih, int grab, int get_mask_from_shape) +{ + EImage *im; + + imlib_context_set_drawable(draw); + im = + imlib_create_scaled_image_from_drawable(mask, x, y, w, h, iw, ih, grab, + get_mask_from_shape); + + return im; +} + +void +EImageRenderOnDrawable(EImage * im, Drawable draw, int x, int y, int w, int h, + int blend) +{ + imlib_context_set_image(im); + imlib_context_set_drawable(draw); + if (blend) + imlib_context_set_blend(1); + imlib_render_image_on_drawable_at_size(x, y, w, h); + if (blend) + imlib_context_set_blend(0); +} + +void +EImageRenderPixmaps(EImage * im, Drawable draw, Pixmap * pmap, Pixmap * mask, + int w, int h) +{ + imlib_context_set_image(im); + imlib_context_set_drawable(draw); + + *pmap = *mask = None; + if (w <= 0 || h <= 0) + imlib_render_pixmaps_for_whole_image(pmap, mask); + else + imlib_render_pixmaps_for_whole_image_at_size(pmap, mask, w, h); +} + +void +EImagePixmapFree(Pixmap pmap) +{ + imlib_free_pixmap_and_mask(pmap); +} + +void +ScaleRect(Window src, Pixmap dst, Pixmap * pdst, int sx, int sy, int sw, int sh, + int dx, int dy, int dw, int dh, int scale) +{ + Imlib_Image *im; + Pixmap pmap, mask; + + scale = (scale) ? 2 : 1; + + imlib_context_set_drawable(src); + im = imlib_create_scaled_image_from_drawable(None, sx, sy, sw, sh, + scale * dw, scale * dh, 0, 0); + imlib_context_set_image(im); + imlib_context_set_anti_alias(1); + if (pdst) + { + imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, dw, dh); + *pdst = pmap; + } + else + { + imlib_context_set_drawable(dst); + imlib_render_image_on_drawable_at_size(dx, dy, dw, dh); + } + imlib_free_image(); +} + +void +EDrawableDumpImage(Drawable draw, const char *txt) +{ + static int seqn = 0; + char buf[1024]; + Imlib_Image *im; + int w, h; + + w = h = 0; + EGetGeometry(draw, NULL, NULL, NULL, &w, &h, NULL, NULL); + if (w <= 0 || h <= 0) + return; + imlib_context_set_drawable(draw); + im = imlib_create_image_from_drawable(None, 0, 0, w, h, !EServerIsGrabbed()); + imlib_context_set_image(im); + imlib_image_set_format("png"); + sprintf(buf, "%s-%#lx-%d.png", txt, draw, seqn++); + Eprintf("EDrawableDumpImage: %s\n", buf); + imlib_save_image(buf); + imlib_free_image_and_decache(); +} + +void +FreePmapMask(PmapMask * pmm) +{ + /* type !=0: Created by imlib_render_pixmaps_for_whole_image... */ + if (pmm->pmap) + { + if (pmm->type == 0) + EFreePixmap(pmm->pmap); + else + imlib_free_pixmap_and_mask(pmm->pmap); + pmm->pmap = 0; + } + + if (pmm->mask) + { + if (pmm->type == 0) + EFreePixmap(pmm->mask); + pmm->mask = 0; + } +} + +EImageColorModifier * +EImageColorModifierCreate(unsigned char *r, unsigned char *g, unsigned char *b, + unsigned char *a) +{ + EImageColorModifier *icm; + + icm = imlib_create_color_modifier(); + if (!icm) + return NULL; + imlib_context_set_color_modifier(icm); +#if 0 /* Useful in this context? */ + imlib_modify_color_modifier_gamma(0.5); + imlib_modify_color_modifier_brightness(0.5); + imlib_modify_color_modifier_contrast(0.5); +#endif + imlib_set_color_modifier_tables(r, g, b, a); + imlib_context_set_color_modifier(NULL); + + return icm; +} diff --git a/src/eimage.h b/src/eimage.h new file mode 100644 index 00000000..8a33ed4c --- /dev/null +++ b/src/eimage.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2004-2006 Kim Woelders + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef _EIMAGE_H_ +#define _EIMAGE_H_ + +typedef void EImage; +typedef void EImageColorModifier; + +typedef struct +{ + int left, right, top, bottom; +} EImageBorder; + +void EImageInit(Display * dpy); + +EImage *EImageCreate(int w, int h); +EImage *EImageCreateFromData(int w, int h, unsigned int *data); +EImage *EImageCreateScaled(EImage * im, int sx, int sy, + int sw, int sh, int dw, int dh); + +void EImageFree(EImage * im); +void EImageDecache(EImage * im); + +void EImageSave(EImage * im, const char *file); +EImage *EImageLoad(const char *file); + +void EImageCheckAlpha(EImage * im); + +void EImageSetHasAlpha(EImage * im, int has_alpha); +void EImageSetBorder(EImage * im, EImageBorder * border); + +int EImageHasAlpha(EImage * im); +void EImageGetSize(EImage * im, int *pw, int *ph); + +void EImageFill(EImage * im, int x, int y, int w, int h, int r, + int g, int b, int a); +void EImageOrientate(EImage * im, int orientation); + +void EImageBlend(EImage * im, EImage * src, int blend, + int sx, int sy, int sw, int sh, + int dx, int dy, int dw, int dh, + int merge_alpha, int anti_alias); +void EImageBlendCM(EImage * im, EImage * src, + EImageColorModifier * icm); +void EImageTile(EImage * im, EImage * tile, int blend, int tw, + int th, int dx, int dy, int dw, int dh, int ox, + int oy); + +EImage *EImageGrabDrawable(Drawable draw, Pixmap mask, + int x, int y, int w, int h, int grab); +EImage *EImageGrabDrawableScaled(Drawable draw, Pixmap mask, + int x, int y, int w, int h, + int iw, int ih, int grab, + int get_mask_from_shape); + +void EImageRenderOnDrawable(EImage * im, Drawable draw, + int x, int y, int w, int h, + int blend); + +void EImageRenderPixmaps(EImage * im, Drawable draw, + Pixmap * pmap, Pixmap * mask, + int w, int h); +void EImagePixmapFree(Pixmap pmap); + +EImageColorModifier *EImageColorModifierCreate(unsigned char *r, + unsigned char *g, + unsigned char *b, + unsigned char *a); + +void ScaleRect(Window src, Pixmap dst, Pixmap * pdst, + int sx, int sy, int sw, int sh, + int dx, int dy, int dw, int dh, int scale); + +#endif /* _EIMAGE_H_ */ diff --git a/src/extinitwin.c b/src/extinitwin.c index 1d5a2699..00836b04 100644 --- a/src/extinitwin.c +++ b/src/extinitwin.c @@ -23,6 +23,7 @@ */ #include "E.h" #include "e16-ecore_hints.h" +#include "eimage.h" #include "xwin.h" #include @@ -44,15 +45,7 @@ ExtInitWinMain(void) EGrabServer(); -#if 0 - imlib_set_cache_size(2048 * 1024); - imlib_set_font_cache_size(512 * 1024); - imlib_set_color_usage(128); -#endif - - imlib_context_set_display(disp); - imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp))); - imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp))); + EImageInit(disp); attr.backing_store = NotUseful; attr.override_redirect = True; @@ -85,9 +78,9 @@ ExtInitWinMain(void) { Window w2, ww; char s[1024]; - Imlib_Image *im; + EImage *im; struct timeval tv; - int dd, x, y; + int dd, x, y, w, h; unsigned int mm; Cursor cs = 0; XColor cl; @@ -122,25 +115,20 @@ ExtInitWinMain(void) if (EventDebug(EDBUG_TYPE_SESSION)) Eprintf("ExtInitWinCreate - child %s\n", s); - im = ELoadImage(s); + im = EImageLoad(s); if (im) { - imlib_context_set_image(im); - imlib_context_set_drawable(w2); - imlib_render_pixmaps_for_whole_image(&pmap, &mask); + EImageRenderPixmaps(im, w2, &pmap, &mask, 0, 0); + EImageGetSize(im, &w, &h); XShapeCombineMask(disp, w2, ShapeBounding, 0, 0, mask, ShapeSet); XSetWindowBackgroundPixmap(disp, w2, pmap); - imlib_free_pixmap_and_mask(pmap); + EImagePixmapFree(pmap); XClearWindow(disp, w2); XQueryPointer(disp, win, &ww, &ww, &dd, &dd, &x, &y, &mm); - XMoveResizeWindow(disp, w2, - x - imlib_image_get_width() / 2, - y - imlib_image_get_height() / 2, - imlib_image_get_width(), - imlib_image_get_height()); + XMoveResizeWindow(disp, w2, x - w / 2, y - h / 2, w, h); XMapWindow(disp, w2); - imlib_free_image(); + EImageFree(im); } tv.tv_sec = 0; tv.tv_usec = 50000; diff --git a/src/fx.c b/src/fx.c index 3e8e91ad..4f874104 100644 --- a/src/fx.c +++ b/src/fx.c @@ -23,6 +23,7 @@ #include "E.h" #include "desktops.h" #include "dialog.h" +#include "eimage.h" #include "emodule.h" #include "xwin.h" #include @@ -717,22 +718,19 @@ FX_imagespinner_timeout(int val __UNUSED__, void *data __UNUSED__) fx_imagespinner_count++; if (string) { - Imlib_Image *im; + EImage *im; - im = ELoadImage(string); + im = EImageLoad(string); if (im) { int x, y, w, h; - imlib_context_set_image(im); - w = imlib_image_get_width(); - h = imlib_image_get_height(); + EImageGetSize(im, &w, &h); sscanf(fx_imagespinner_params, "%*s %i %i ", &x, &y); x = ((VRoot.w * x) >> 10) - ((w * x) >> 10); y = ((VRoot.h * y) >> 10) - ((h * y) >> 10); - imlib_context_set_drawable(fx_imagespinner_win); - imlib_render_image_on_drawable_at_size(x, y, w, h); - imlib_free_image(); + EImageRenderOnDrawable(im, fx_imagespinner_win, x, y, w, h, 0); + EImageFree(im); } Efree(string); } diff --git a/src/hiwin.c b/src/hiwin.c index b235ec81..f9a189d3 100644 --- a/src/hiwin.c +++ b/src/hiwin.c @@ -40,6 +40,7 @@ struct _hiwin void *data; char animate; GC gc; + EImage *im; }; typedef struct @@ -55,41 +56,34 @@ static void HiwinRenderImageInit(Hiwin * phi) { EWin *ewin = phi->ewin; - Imlib_Image *im; Pixmap pmap; pmap = EoGetPixmap(ewin); if (pmap) { - imlib_context_set_drawable(pmap); - im = imlib_create_image_from_drawable(0, 0, 0, - EoGetW(ewin), EoGetH(ewin), 0); + phi->im = EImageGrabDrawable(pmap, None, 0, 0, + EoGetW(ewin), EoGetH(ewin), 0); /* Skip zoom effect if composite is active */ phi->animate = 0; } else if (phi->zoom > 2 && EwinIsOnScreen(ewin)) { - imlib_context_set_drawable(EoGetWin(ewin)); - im = imlib_create_image_from_drawable(0, 0, 0, - EoGetW(ewin), EoGetH(ewin), 0); + phi->im = EImageGrabDrawable(EoGetWin(ewin), None, 0, 0, + EoGetW(ewin), EoGetH(ewin), 0); } else { - imlib_context_set_drawable(ewin->mini_pmm.pmap); - im = imlib_create_image_from_drawable(0, 0, 0, - ewin->mini_w, ewin->mini_h, 0); + phi->im = EImageGrabDrawable(ewin->mini_pmm.pmap, None, 0, 0, + ewin->mini_w, ewin->mini_h, 0); } - imlib_context_set_image(im); - imlib_context_set_drawable(EoGetWin(phi)); ESetWindowBackgroundPixmap(EoGetWin(phi), None); } static void HiwinRenderImageDrawX(Hiwin * phi, Drawable draw) { - imlib_context_set_drawable(draw); - imlib_render_image_on_drawable_at_size(0, 0, EoGetW(phi), EoGetH(phi)); + EImageRenderOnDrawable(phi->im, draw, 0, 0, EoGetW(phi), EoGetH(phi), 0); } static void @@ -112,14 +106,14 @@ HiwinRenderImageFini(Hiwin * phi, int shown) EFreePixmap(pmap); EClearWindow(EoGetWin(phi)); } - imlib_free_image_and_decache(); + EImageDecache(phi->im); + phi->im = NULL; } #if USE_COMPOSITE static void HiwinRenderImageUpdate(Hiwin * phi) { - Imlib_Image *im; Pixmap pmap; EWin *ewin = phi->ewin; @@ -127,14 +121,12 @@ HiwinRenderImageUpdate(Hiwin * phi) if (pmap == None) return; - imlib_context_set_drawable(pmap); - im = imlib_create_image_from_drawable(0, 0, 0, - EoGetW(ewin), EoGetH(ewin), 0); - - imlib_context_set_image(im); + phi->im = EImageGrabDrawable(pmap, None, 0, 0, + EoGetW(ewin), EoGetH(ewin), 0); ESetWindowBackgroundPixmap(EoGetWin(phi), None); HiwinRenderImageDrawX(phi, EoGetWin(phi)); - imlib_free_image_and_decache(); + EImageDecache(phi->im); + phi->im = NULL; } #endif diff --git a/src/iclass.c b/src/iclass.c index 3e438e58..660645ec 100644 --- a/src/iclass.c +++ b/src/iclass.c @@ -26,6 +26,7 @@ #include "conf.h" #include "desktops.h" #include "e16-ecore_list.h" +#include "eimage.h" #include "emodule.h" #include "iclass.h" #include "tclass.h" @@ -56,8 +57,8 @@ struct _imagestate char *real_file; char unloadable; char transparent; - Imlib_Image *im; - Imlib_Border *border; + EImage *im; + EImageBorder *border; int pixmapfillstyle; XColor bg, hi, lo, hihi, lolo; int bevelstyle; @@ -79,7 +80,7 @@ struct _imageclass { char *name; ImageStateArray norm, active, sticky, sticky_active; - Imlib_Border padding; + EImageBorder padding; #if ENABLE_COLOR_MODIFIERS ColorModifierClass *colmod; #endif @@ -90,9 +91,9 @@ static Ecore_List *iclass_list = NULL; #ifdef ENABLE_THEME_TRANSPARENCY -static Imlib_Color_Modifier *icm = NULL; -static DATA8 gray[256]; -static DATA8 alpha[256]; +static EImageColorModifier *icm = NULL; +static unsigned char gray[256]; +static unsigned char alpha[256]; static int prev_alpha = -1; @@ -120,15 +121,7 @@ TransparencyMakeColorModifier(void) } if (icm == NULL) - icm = imlib_create_color_modifier(); - imlib_context_set_color_modifier(icm); -#if 0 /* Useful in this context? */ - imlib_modify_color_modifier_gamma(0.5); - imlib_modify_color_modifier_brightness(0.5); - imlib_modify_color_modifier_contrast(0.5); -#endif - imlib_set_color_modifier_tables(gray, gray, gray, alpha); - imlib_context_set_color_modifier(NULL); + icm = EImageColorModifierCreate(gray, gray, gray, alpha); } void @@ -211,8 +204,7 @@ FreeImageState(ImageState * i) if (i->im) { - imlib_context_set_image(i->im); - imlib_free_image(); + EImageFree(i->im); i->im = NULL; } @@ -251,25 +243,6 @@ ImagestatePopulate(ImageState * is) EAllocColor(&is->lolo); } -static int -e16_image_check_has_alpha(void) -{ - static const short oink = 3; /* For endianness checking */ - unsigned char *pb, *pe; - - if (!imlib_image_has_alpha()) - return 0; - - pb = (unsigned char *)imlib_image_get_data_for_reading_only(); - pe = pb + 4 * imlib_image_get_width() * imlib_image_get_height(); - pb += *((char *)(&oink)); - for (; pb < pe; pb += 4) - if (*pb != 0xff) - return 1; - - return 0; -} - static void ImagestateRealize(ImageState * is) { @@ -284,7 +257,7 @@ ImagestateRealize(ImageState * is) if (!is->real_file) is->real_file = ThemeFileFind(is->im_file, 0); - is->im = ELoadImage(is->real_file); + is->im = EImageLoad(is->real_file); if (!is->im) { Eprintf @@ -293,18 +266,10 @@ ImagestateRealize(ImageState * is) return; } - imlib_context_set_image(is->im); - - if (imlib_image_has_alpha() && !e16_image_check_has_alpha()) - { -#if 0 - Eprintf("Alpha set but no shape %s\n", is->real_file); -#endif - imlib_image_set_has_alpha(0); - } + EImageCheckAlpha(is->im); if (is->border) - imlib_image_set_border(is->border); + EImageSetBorder(is->im, is->border); #if 0 /* To be implemented? */ if (is->colmod) @@ -399,7 +364,7 @@ ImageclassGetName(ImageClass * ic) return (ic) ? ic->name : NULL; } -Imlib_Border * +EImageBorder * ImageclassGetPadding(ImageClass * ic) { return (ic) ? &(ic->padding) : NULL; @@ -563,7 +528,7 @@ ImageclassConfigLoad(FILE * fs) goto done; case ICLASS_LRTB: { - ICToRead->border = Emalloc(sizeof(Imlib_Border)); + ICToRead->border = Emalloc(sizeof(EImageBorder)); l = r = t = b = 0; sscanf(s, "%*s %i %i %i %i", &l, &r, &t, &b); @@ -804,10 +769,10 @@ ImageclassGetImageState(ImageClass * ic, int state, int active, int sticky) return is; } -Imlib_Image * +EImage * ImageclassGetImage(ImageClass * ic, int active, int sticky, int state) { - Imlib_Image *im; + EImage *im; ImageState *is; if (!ic) @@ -833,7 +798,7 @@ ImageclassApplySimple(ImageClass * ic, Window win, Drawable draw, int state, int x, int y, int w, int h) { Pixmap pmap; - Imlib_Image *im; + EImage *im; im = ImageclassGetImage(ic, 0, 0, state); if (!im) @@ -846,10 +811,9 @@ ImageclassApplySimple(ImageClass * ic, Window win, Drawable draw, int state, draw = pmap; x = y = 0; } - imlib_context_set_image(im); - imlib_context_set_drawable(draw); - imlib_render_image_on_drawable_at_size(x, y, w, h); - imlib_free_image(); + + EImageRenderOnDrawable(im, draw, x, y, w, h, 0); + EImageFree(im); return pmap; } @@ -907,10 +871,10 @@ pt_type_to_flags(int image_type) return flags; } -static Imlib_Image * +static EImage * pt_get_bg_image(Window win, int w, int h, int use_root) { - Imlib_Image *ii = NULL; + EImage *ii = NULL; Window cr, dummy; Drawable bg; int xx, yy; @@ -932,53 +896,25 @@ pt_get_bg_image(Window win, int w, int h, int use_root) if (xx < VRoot.w && yy < VRoot.h && xx + w >= 0 && yy + h >= 0) { /* Create the background base image */ - imlib_context_set_drawable(bg); - ii = imlib_create_image_from_drawable(0, xx, yy, w, h, - !EServerIsGrabbed()); + ii = EImageGrabDrawable(bg, None, xx, yy, w, h, !EServerIsGrabbed()); } return ii; } -static void -pt_blend(Imlib_Image * bg, Imlib_Image * im, int use_cm) +#endif + +EImage * +ImageclassGetImageBlended(ImageClass * ic, Window win, int w, int h, int active, + int sticky, int state, int image_type) { - int w, h, iw, ih; - - imlib_context_set_image(im); - iw = imlib_image_get_width(); - ih = imlib_image_get_height(); - imlib_context_set_image(bg); - w = imlib_image_get_width(); - h = imlib_image_get_height(); - - imlib_context_set_blend(1); -#ifdef ENABLE_THEME_TRANSPARENCY - if (use_cm) - { - imlib_context_set_color_modifier(icm); - } -#endif - imlib_context_set_operation(IMLIB_OP_COPY); - imlib_blend_image_onto_image(im, 0, 0, 0, iw, ih, 0, 0, w, h); - imlib_context_set_blend(0); -#ifdef ENABLE_THEME_TRANSPARENCY - if (use_cm) - { - imlib_context_set_color_modifier(NULL); - } -#endif -} - -#endif - -Imlib_Image * -EImageBlendPT(Imlib_Image * im, Window win, int w, int h, int image_type) -{ - Imlib_Image *bg; + EImage *im, *bg; int flags; - int ww, hh; + if (!ic) + return NULL; + + im = ImageclassGetImage(ic, active, sticky, state); if (!im) return NULL; @@ -989,8 +925,8 @@ EImageBlendPT(Imlib_Image * im, Window win, int w, int h, int image_type) bg = pt_get_bg_image(win, w, h, flags & ICLASS_ATTR_GLASS); if (bg) { - pt_blend(bg, im, flags & ICLASS_ATTR_USE_CM); - return bg; + EImageBlendCM(bg, im, (flags & ICLASS_ATTR_USE_CM) ? icm : NULL); + goto done; } } #else @@ -998,10 +934,10 @@ EImageBlendPT(Imlib_Image * im, Window win, int w, int h, int image_type) win = None; #endif - imlib_context_set_image(im); - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); - bg = imlib_create_cropped_scaled_image(0, 0, ww, hh, w, h); + bg = EImageCreateScaled(im, 0, 0, 0, 0, w, h); + + done: + EImageFree(im); return bg; } @@ -1011,7 +947,7 @@ ImagestateMakePmapMask(ImageState * is, Drawable win, PmapMask * pmm, int make_mask, int w, int h, int image_type) { #ifdef ENABLE_TRANSPARENCY - Imlib_Image *ii = NULL; + EImage *ii = NULL; int flags; Pixmap pmap, mask; @@ -1023,7 +959,7 @@ ImagestateMakePmapMask(ImageState * is, Drawable win, PmapMask * pmm, * 0x02: Use root window as base (use only for transients, if at all) * 0x04: Don't apply image mask to result */ - if (is->transparent && imlib_image_has_alpha()) + if (is->transparent && EImageHasAlpha(is->im)) flags = is->transparent; if (flags != ICLASS_ATTR_OPAQUE) @@ -1039,36 +975,29 @@ ImagestateMakePmapMask(ImageState * is, Drawable win, PmapMask * pmm, if (ii) { - imlib_context_set_drawable(win); - pt_blend(ii, is->im, flags & ICLASS_ATTR_USE_CM); + EImageBlendCM(ii, is->im, (flags & ICLASS_ATTR_USE_CM) ? icm : NULL); pmm->type = 0; pmm->pmap = pmap = ECreatePixmap(win, w, h, VRoot.depth); pmm->mask = None; pmm->w = w; pmm->h = h; - imlib_context_set_image(ii); - imlib_context_set_drawable(pmap); - imlib_render_image_on_drawable_at_size(0, 0, w, h); - imlib_context_set_drawable(win); + EImageRenderOnDrawable(ii, pmap, 0, 0, w, h, 0); if (make_mask && !(flags & ICLASS_ATTR_NO_CLIP)) { - imlib_context_set_image(is->im); - if (imlib_image_has_alpha()) + if (EImageHasAlpha(is->im)) { /* Make the scaled clip mask to be used */ - imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, w, - h); + EImageRenderPixmaps(is->im, win, &pmap, &mask, w, h); /* Replace the mask with the correct one */ pmm->mask = ECreatePixmapCopy(mask, w, h, 1); - imlib_free_pixmap_and_mask(pmap); + EImagePixmapFree(pmap); } } - imlib_context_set_image(ii); - imlib_free_image_and_decache(); + EImageDecache(ii); } else #else @@ -1081,19 +1010,13 @@ ImagestateMakePmapMask(ImageState * is, Drawable win, PmapMask * pmm, pmm->pmap = pmm->mask = None; pmm->w = w; pmm->h = h; - imlib_context_set_image(is->im); - imlib_context_set_drawable(win); - imlib_render_pixmaps_for_whole_image_at_size(&pmm->pmap, &pmm->mask, - w, h); + EImageRenderPixmaps(is->im, win, &pmm->pmap, &pmm->mask, w, h); } else { int ww, hh, cw, ch, pw, ph; - imlib_context_set_image(is->im); - - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); + EImageGetSize(is->im, &ww, &hh); pw = w; ph = h; @@ -1123,9 +1046,7 @@ ImagestateMakePmapMask(ImageState * is, Drawable win, PmapMask * pmm, pmm->pmap = pmm->mask = None; pmm->w = pw; pmm->h = ph; - imlib_context_set_drawable(win); - imlib_render_pixmaps_for_whole_image_at_size(&pmm->pmap, &pmm->mask, - pw, ph); + EImageRenderPixmaps(is->im, win, &pmm->pmap, &pmm->mask, pw, ph); } } @@ -1296,8 +1217,7 @@ ITApply(Window win, ImageClass * ic, ImageState * is, int w, int h, int state, if ((is->unloadable) || (Conf.memory_paranoia)) { - imlib_context_set_image(is->im); - imlib_free_image(); + EImageFree(is->im); is->im = NULL; } } @@ -1396,8 +1316,7 @@ ImageclassApplyCopy(ImageClass * ic, Window win, int w, int h, int active, if ((is->unloadable) || (Conf.memory_paranoia)) { - imlib_context_set_image(is->im); - imlib_free_image(); + EImageFree(is->im); is->im = NULL; } } @@ -1561,7 +1480,7 @@ ImageclassIpc(const char *params, Client * c __UNUSED__) word(params, 3, param3); p = (Pixmap) strtol(param3, (char **)NULL, 0); - imlib_free_pixmap_and_mask(p); + EImagePixmapFree(p); } else if (!strcmp(param2, "get_padding")) { @@ -1581,10 +1500,11 @@ ImageclassIpc(const char *params, Client * c __UNUSED__) ImagestateRealize(ic->norm.normal); if (ic->norm.normal->im) { - imlib_context_set_image(ic->norm.normal->im); - IpcPrintf("%i %i\n", imlib_image_get_width(), - imlib_image_get_height()); - imlib_free_image(); + int w, h; + + EImageGetSize(ic->norm.normal->im, &w, &h); + EImageFree(ic->norm.normal->im); + IpcPrintf("%i %i\n", w, h); } } else diff --git a/src/iclass.h b/src/iclass.h index 9237818d..987b6e24 100644 --- a/src/iclass.h +++ b/src/iclass.h @@ -24,6 +24,7 @@ #ifndef _ICLASS_H #define _ICLASS_H +#include "eimage.h" #include "xwin.h" struct _textclass; @@ -99,18 +100,15 @@ int ImageclassIsTransparent(ImageClass * ic); #define ImageclassIsTransparent(ic) 0 #endif -Imlib_Image *EImageBlendPT(Imlib_Image * im, Window win, int w, int h, - int image_type); - ImageClass *ImageclassFind(const char *name, int fallback); void ImageclassIncRefcount(ImageClass * ic); void ImageclassDecRefcount(ImageClass * ic); const char *ImageclassGetName(ImageClass * ic); -Imlib_Border *ImageclassGetPadding(ImageClass * ic); +EImageBorder *ImageclassGetPadding(ImageClass * ic); ImageState *ImageclassGetImageState(ImageClass * ic, int state, int active, int sticky); ImageClass *ImageclassCreateSimple(const char *name, const char *image); -Imlib_Image *ImageclassGetImage(ImageClass * ic, int active, int sticky, +EImage *ImageclassGetImage(ImageClass * ic, int active, int sticky, int state); Pixmap ImageclassApplySimple(ImageClass * ic, Window win, Drawable draw, int state, int x, @@ -122,6 +120,10 @@ void ImageclassApplyCopy(ImageClass * ic, Window win, int w, int h, int active, int sticky, int state, PmapMask * pmm, int make_mask, int image_type); +EImage *ImageclassGetImageBlended(ImageClass * ic, Window win, + int w, int h, int active, + int sticky, int state, + int image_type); void ITApply(Window win, ImageClass * ic, ImageState * is, int w, int h, int state, int active, int sticky, char expose, int image_type, struct _textclass *tc, diff --git a/src/iconify.c b/src/iconify.c index cd348aac..ab6ccdde 100644 --- a/src/iconify.c +++ b/src/iconify.c @@ -64,7 +64,7 @@ typedef struct } u; int xo, yo, wo, ho; /* Outer */ int xi, yi, wi, hi; /* Inner */ - Imlib_Image *im; + EImage *im; } IboxOject; struct _iconbox @@ -94,7 +94,7 @@ struct _iconbox int max, max_min; ImageClass *ic_box; ImageClass *ic_item_base; - Imlib_Image *im_item_base; + EImage *im_item_base; char arrow1_hilited; char arrow1_clicked; @@ -479,7 +479,7 @@ static void IconboxReconfigure(Iconbox * ib) { ImageClass *ic, *ic2; - Imlib_Border *pad; + EImageBorder *pad; EWin *ewin; int extra; unsigned int wmin, hmin, wmax, hmax; @@ -704,10 +704,8 @@ IconboxObjEwinDel(Iconbox * ib, EWin * ewin) return; if (ib->objs[i].im) - { - imlib_context_set_image(ib->objs[i].im); - imlib_free_image(); - } + EImageFree(ib->objs[i].im); + IconboxObjectDel(ib, ewin); } @@ -829,10 +827,7 @@ IconboxUpdateEwinIcon(Iconbox * ib, EWin * ewin, int icon_mode) return; if (ib->objs[i].im) - { - imlib_context_set_image(ib->objs[i].im); - imlib_free_image(); - } + EImageFree(ib->objs[i].im); ib->objs[i].im = EwinIconImageGet(ewin, ib->iconsize, icon_mode); IconboxRedraw(ib); @@ -848,13 +843,11 @@ IconboxesUpdateEwinIcon(EWin * ewin, int icon_mode) } static void -IconboxFindIconSize(Imlib_Image * im, int *pw, int *ph, int size) +IconboxFindIconSize(EImage * im, int *pw, int *ph, int size) { int w, h, minsz, maxwh; - imlib_context_set_image(im); - w = imlib_image_get_width(); - h = imlib_image_get_height(); + EImageGetSize(im, &w, &h); maxwh = (w > h) ? w : h; if (maxwh <= 1) @@ -879,7 +872,7 @@ IconboxLayoutImageWin(Iconbox * ib) int i, xo, yo, wo, ho, wi, hi; int item_pad, padl, padr, padt, padb; IboxOject *ibo; - Imlib_Border *pad; + EImageBorder *pad; if (ib->orientation) ib->ic_box = ImageclassFind("ICONBOX_VERTICAL", 0); @@ -1034,7 +1027,7 @@ static void IB_DrawScroll(Iconbox * ib) { ImageClass *ic; - Imlib_Border *pad; + EImageBorder *pad; int arrow_mode = ib->arrow_side; int bs, bw, bx; int state; @@ -1568,7 +1561,7 @@ IconboxDraw(Iconbox * ib) ImageClass *ib_ic_cover; int ib_xlt, ib_ylt, ib_ww, ib_hh; int ib_x0, ib_y0, ib_w0, ib_h0; - Imlib_Image *im, *im2; + EImage *im; int ww, hh; Pixmap pmap, mask; @@ -1636,21 +1629,15 @@ IconboxDraw(Iconbox * ib) (!ib->nobg || (ib->type == IB_TYPE_SYSTRAY && !ib->draw_icon_base))) { /* Start out with iconbox image class image */ - im2 = ImageclassGetImage(ib->ic_box, 0, 0, STATE_NORMAL); - im = EImageBlendPT(im2, ib->icon_win, ib_w0, ib_h0, ST_ICONBOX); - imlib_context_set_image(im2); - imlib_free_image(); - imlib_context_set_image(im); + im = ImageclassGetImageBlended(ib->ic_box, ib->icon_win, ib_w0, ib_h0, + 0, 0, STATE_NORMAL, ST_ICONBOX); } else { /* Start out with blank image */ - im = imlib_create_image(ib_w0, ib_h0); - imlib_context_set_image(im); - imlib_image_set_has_alpha(1); - imlib_context_set_blend(0); - imlib_context_set_color(0, 0, 0, 0); - imlib_image_fill_rectangle(0, 0, ib_w0, ib_h0); + im = EImageCreate(ib_w0, ib_h0); + EImageFill(im, 0, 0, ib_w0, ib_h0, 0, 0, 0, 255); + EImageSetHasAlpha(im, 1); } for (i = 0; i < ib->num_objs; i++) @@ -1661,32 +1648,18 @@ IconboxDraw(Iconbox * ib) if (ib->draw_icon_base && ib->im_item_base) { - imlib_context_set_image(ib->im_item_base); - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); - imlib_context_set_image(im); - imlib_context_set_blend(1); - imlib_blend_image_onto_image(ib->im_item_base, 1, 0, 0, - ww, hh, ibo->xo, ibo->yo, - ibo->wo, ibo->ho); - imlib_context_set_blend(0); + EImageGetSize(ib->im_item_base, &ww, &hh); + EImageBlend(im, ib->im_item_base, 1, 0, 0, ww, hh, + ibo->xo, ibo->yo, ibo->wo, ibo->ho, 1, 0); } if (ib->type == IB_TYPE_ICONBOX) { if (ibo->im) { - imlib_context_set_image(ibo->im); - ww = imlib_image_get_width(); - hh = imlib_image_get_height(); - imlib_context_set_image(im); - imlib_context_set_anti_alias(1); - imlib_context_set_blend(1); - imlib_blend_image_onto_image(ibo->im, 1, 0, 0, ww, hh, - ibo->xi, ibo->yi, ibo->wi, - ibo->hi); - imlib_context_set_blend(0); - imlib_context_set_anti_alias(0); + EImageGetSize(ibo->im, &ww, &hh); + EImageBlend(im, ibo->im, 1, 0, 0, ww, hh, + ibo->xi, ibo->yi, ibo->wi, ibo->hi, 1, 1); } } else @@ -1702,15 +1675,11 @@ IconboxDraw(Iconbox * ib) if (im) { EMapWindow(ib->icon_win); - imlib_context_set_drawable(ib->icon_win); - imlib_context_set_image(im); - imlib_image_set_has_alpha(1); - pmap = mask = None; - imlib_render_pixmaps_for_whole_image(&pmap, &mask); + EImageRenderPixmaps(im, ib->icon_win, &pmap, &mask, 0, 0); ESetWindowBackgroundPixmap(ib->icon_win, pmap); EShapeCombineMask(ib->icon_win, ShapeBounding, 0, 0, mask, ShapeSet); - imlib_free_pixmap_and_mask(pmap); - imlib_free_image(); + EImagePixmapFree(pmap); + EImageFree(im); EClearWindow(ib->icon_win); if (ib->type == IB_TYPE_SYSTRAY && ib->nobg && !ib->draw_icon_base) @@ -1864,7 +1833,7 @@ IboxEventScrollbarWin(XEvent * ev, void *prm) static int px, py, pos0; int bs, dp; ImageClass *ic; - Imlib_Border *pad; + EImageBorder *pad; switch (ev->type) { diff --git a/src/icons.c b/src/icons.c index e9a5901f..b35521fe 100644 --- a/src/icons.c +++ b/src/icons.c @@ -22,6 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "E.h" +#include "eimage.h" #include "ewins.h" #include "icons.h" #include "xwin.h" @@ -64,12 +65,12 @@ NetwmIconFindBestSize(unsigned int *val, unsigned int len, int size) return k; } -static Imlib_Image * +static EImage * IB_SnapEWin(EWin * ewin, int size) { /* Make snapshot of window */ int w, h, ww, hh, scale; - Imlib_Image *im; + EImage *im; Drawable draw; if (!EwinIsMapped(ewin)) @@ -111,33 +112,28 @@ IB_SnapEWin(EWin * ewin, int size) Pixmap mask; mask = EWindowGetShapePixmap(EoGetWin(ewin)); - imlib_context_set_drawable(draw); - im = imlib_create_scaled_image_from_drawable(mask, 0, 0, ww, hh, - w, h, !EServerIsGrabbed(), - 0); + im = EImageGrabDrawableScaled(draw, mask, 0, 0, ww, hh, w, h, + !EServerIsGrabbed(), 0); } else { draw = EoGetWin(ewin); - imlib_context_set_drawable(draw); - im = imlib_create_scaled_image_from_drawable(None, 0, 0, ww, hh, - w, h, !EServerIsGrabbed(), - 1); + im = EImageGrabDrawableScaled(draw, None, 0, 0, ww, hh, w, h, + !EServerIsGrabbed(), 1); } - imlib_context_set_image(im); - imlib_image_set_has_alpha(1); + EImageSetHasAlpha(im, 1); return im; } -static Imlib_Image * +static EImage * IB_GetAppIcon(EWin * ewin, int size) { /* Get the applications icon pixmap/mask */ int x, y; unsigned int w, h, depth, bw; Window rt; - Imlib_Image im; + EImage *im; if (ewin->ewmh.wm_icon) { @@ -145,13 +141,10 @@ IB_GetAppIcon(EWin * ewin, int size) size); if (x >= 0) { - im = imlib_create_image_using_copied_data(ewin->ewmh.wm_icon[x], - ewin->ewmh.wm_icon[x + - 1], - ewin->ewmh.wm_icon + x + - 2); - imlib_context_set_image(im); - imlib_image_set_has_alpha(1); + im = EImageCreateFromData(ewin->ewmh.wm_icon[x], + ewin->ewmh.wm_icon[x + 1], + ewin->ewmh.wm_icon + x + 2); + EImageSetHasAlpha(im, 1); return im; } } @@ -166,30 +159,25 @@ IB_GetAppIcon(EWin * ewin, int size) if (w < 1 || h < 1) return NULL; - imlib_context_set_colormap(None); - imlib_context_set_drawable(ewin->icccm.icon_pmap); - im = imlib_create_image_from_drawable(ewin->icccm.icon_mask, 0, 0, w, h, - !EServerIsGrabbed()); - imlib_context_set_image(im); - imlib_image_set_has_alpha(1); /* Should be set by imlib? */ - imlib_context_set_colormap(VRoot.cmap); - imlib_context_set_drawable(VRoot.win); + im = EImageGrabDrawable(ewin->icccm.icon_pmap, ewin->icccm.icon_mask, + 0, 0, w, h, !EServerIsGrabbed()); + EImageSetHasAlpha(im, 1); return im; } -static Imlib_Image * +static EImage * IB_GetEIcon(EWin * ewin) { /* get the icon defined for this window in E's iconf match file */ const char *file; - Imlib_Image *im; + EImage *im; file = WindowMatchEwinIcon(ewin); if (!file) return NULL; - im = ELoadImage(file); + im = EImageLoad(file); return im; } @@ -204,10 +192,10 @@ static const char ewin_icon_modes[N_MODES][N_TYPES] = { {EWIN_ICON_TYPE_APP, EWIN_ICON_TYPE_IMG, EWIN_ICON_TYPE_NONE}, }; -Imlib_Image * +EImage * EwinIconImageGet(EWin * ewin, int size, int mode) { - Imlib_Image *im = NULL; + EImage *im = NULL; int i, type; if (mode < 0 || mode >= N_MODES) diff --git a/src/icons.h b/src/icons.h index 684e15fd..55d736a4 100644 --- a/src/icons.h +++ b/src/icons.h @@ -21,6 +21,10 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#ifndef _ICONS_H_ +#define _ICONS_H_ + +#include "eimage.h" typedef enum { @@ -30,4 +34,6 @@ typedef enum EWIN_ICON_TYPE_NONE, } ewin_icon_e; -Imlib_Image *EwinIconImageGet(EWin * ewin, int size, int mode); +EImage *EwinIconImageGet(EWin * ewin, int size, int mode); + +#endif /* _ICONS_H_ */ diff --git a/src/menus.c b/src/menus.c index 60f533ea..f6dd62c5 100644 --- a/src/menus.c +++ b/src/menus.c @@ -25,6 +25,7 @@ #include "borders.h" #include "dialog.h" #include "e16-ecore_list.h" +#include "eimage.h" #include "emodule.h" #include "eobj.h" #include "ewins.h" @@ -650,8 +651,8 @@ MenuRealize(Menu * m) int i, maxh, maxw, nmaxy; int maxx1, maxx2, w, h, x, y, r, mmw, mmh; int iw, ih; - Imlib_Image *im; - Imlib_Border *pad, *pad_item, *pad_sub; + EImage *im; + EImageBorder *pad, *pad_item, *pad_sub; char has_i, has_s; if (!m->style) @@ -709,10 +710,8 @@ MenuRealize(Menu * m) w = h = Conf.menus.icon_size; if (w <= 0 || h <= 0) { - imlib_context_set_image(im); - w = imlib_image_get_width(); - h = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &w, &h); + EImageFree(im); } m->items[i]->icon_w = w; m->items[i]->icon_h = h; diff --git a/src/pager.c b/src/pager.c index fbb2278f..524e1fb9 100644 --- a/src/pager.c +++ b/src/pager.c @@ -144,33 +144,6 @@ PagerDestroy(Pager * p) Efree(p); } -static void -ScaleRect(Window src, Pixmap dst, Pixmap * pdst, int sx, int sy, int sw, int sh, - int dx, int dy, int dw, int dh, int scale) -{ - Imlib_Image *im; - Pixmap pmap, mask; - - scale = (scale) ? 2 : 1; - - imlib_context_set_drawable(src); - im = imlib_create_scaled_image_from_drawable(None, sx, sy, sw, sh, - scale * dw, scale * dh, 0, 0); - imlib_context_set_image(im); - imlib_context_set_anti_alias(1); - if (pdst) - { - imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask, dw, dh); - *pdst = pmap; - } - else - { - imlib_context_set_drawable(dst); - imlib_render_image_on_drawable_at_size(dx, dy, dw, dh); - } - imlib_free_image(); -} - static void PagerScanTrig(Pager * p) { @@ -270,18 +243,15 @@ PagerScanTimeout(int val __UNUSED__, void *data) static void PagerHiwinUpdate(Hiwin * phi, Pager * p __UNUSED__, EWin * ewin) { - Imlib_Image *im; + EImage *im; if (!EoIsShown(phi) || !ewin->mini_pmm.pmap) return; - imlib_context_set_drawable(ewin->mini_pmm.pmap); - im = imlib_create_image_from_drawable(0, 0, 0, - ewin->mini_w, ewin->mini_h, 0); - imlib_context_set_image(im); - imlib_context_set_drawable(EoGetWin(phi)); - imlib_render_image_on_drawable_at_size(0, 0, EoGetW(phi), EoGetH(phi)); - imlib_free_image_and_decache(); + im = EImageGrabDrawable(ewin->mini_pmm.pmap, None, 0, 0, + ewin->mini_w, ewin->mini_h, 0); + EImageRenderOnDrawable(im, EoGetWin(phi), 0, 0, EoGetW(phi), EoGetH(phi), 0); + EImageDecache(im); } #endif @@ -542,32 +512,27 @@ PagerUpdateBg(Pager * p) #if USE_PAGER_BACKGROUND_CACHE char s[4096]; char *uniq; - Imlib_Image *im; + EImage *im; uniq = BackgroundGetUniqueString(bg); Esnprintf(s, sizeof(s), "%s/cached/pager/%s.%i.%i.%s.png", EDirUserCache(), BackgroundGetName(bg), p->dw, p->dh, uniq); Efree(uniq); - im = imlib_load_image(s); + im = EImageLoad(s); if (im) { - imlib_context_set_image(im); - imlib_context_set_drawable(pmap); - imlib_render_image_on_drawable_at_size(0, 0, p->dw, p->dh); - imlib_free_image_and_decache(); + EImageRenderOnDrawable(im, pmap, 0, 0, p->dw, p->dh, 0); + EImageDecache(im); } else { #endif BackgroundApplyPmap(bg, pmap, p->dw, p->dh); #if USE_PAGER_BACKGROUND_CACHE - imlib_context_set_drawable(pmap); - im = imlib_create_image_from_drawable(0, 0, 0, p->dw, p->dh, 1); - imlib_context_set_image(im); - imlib_image_set_format("png"); - imlib_save_image(s); - imlib_free_image_and_decache(); + im = EImageGrabDrawable(pmap, None, 0, 0, p->dw, p->dh, 0); + EImageSave(im, s); + EImageDecache(im); } #endif return; diff --git a/src/setup.c b/src/setup.c index 9268ceab..0390292b 100644 --- a/src/setup.c +++ b/src/setup.c @@ -22,6 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "E.h" +#include "eimage.h" #include "ewins.h" #include "xwin.h" #include @@ -242,17 +243,8 @@ SetupX(const char *dstr) VRoot.h = RRoot.h; } - /* initialise imlib */ - imlib_set_cache_size(2048 * 1024); - imlib_set_font_cache_size(512 * 1024); - imlib_set_color_usage(128); - - imlib_context_set_dither(1); - - imlib_context_set_display(disp); - imlib_context_set_visual(VRoot.vis); - imlib_context_set_colormap(VRoot.cmap); - imlib_context_set_dither_mask(0); + /* Initialise image handling */ + EImageInit(disp); /* Initialise event handling */ EventsInit(); diff --git a/src/tclass.c b/src/tclass.c index 3df09dd2..9774ede9 100644 --- a/src/tclass.c +++ b/src/tclass.c @@ -475,7 +475,7 @@ TextclassApply(ImageClass * iclass, Window win, int w, int h, int active, int sticky, int state, char expose __UNUSED__, TextClass * tclass, const char *text) { - Imlib_Border *pad; + EImageBorder *pad; if ((!iclass) || (!tclass) || (!text) || (!win) || (w < 1) || (h < 1)) return; diff --git a/src/text.c b/src/text.c index c0a698fa..eb255deb 100644 --- a/src/text.c +++ b/src/text.c @@ -22,6 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "E.h" +#include "eimage.h" #include "tclass.h" #include "xwin.h" @@ -790,10 +791,10 @@ TextDraw(TextClass * tclass, Window win, int active, int sticky, int state, } void -TextDrawRotTo(Window win, Drawable * drawable, int x, int y, int w, int h, +TextDrawRotTo(Window win, Drawable * draw, int x, int y, int w, int h, TextState * ts) { - Imlib_Image *ii = NULL; + EImage *im; int win_x, win_y; unsigned int win_w, win_h, win_b, win_d; Window rr; @@ -801,43 +802,35 @@ TextDrawRotTo(Window win, Drawable * drawable, int x, int y, int w, int h, switch (ts->style.orientation) { case FONT_TO_UP: - imlib_context_set_drawable(win); - ii = imlib_create_image_from_drawable(0, y, x, h, w, 0); - imlib_context_set_image(ii); - imlib_image_orientate(1); - imlib_context_set_drawable(*drawable); - imlib_render_image_on_drawable_at_size(0, 0, w, h); + im = EImageGrabDrawable(win, 0, y, x, h, w, 0); + EImageOrientate(im, 1); + EImageRenderOnDrawable(im, *draw, 0, 0, w, h, 0); + EImageFree(im); break; case FONT_TO_DOWN: XGetGeometry(disp, win, &rr, &win_x, &win_y, &win_w, &win_h, &win_b, &win_d); - imlib_context_set_drawable(win); - ii = imlib_create_image_from_drawable(0, win_w - y - h, x, h, w, 0); - imlib_context_set_image(ii); - imlib_image_orientate(3); - imlib_context_set_drawable(*drawable); - imlib_render_image_on_drawable_at_size(0, 0, w, h); + im = EImageGrabDrawable(win, None, win_w - y - h, x, h, w, 0); + EImageOrientate(im, 3); + EImageRenderOnDrawable(im, *draw, 0, 0, w, h, 0); + EImageFree(im); break; case FONT_TO_LEFT: /* Holy carumba! That's for yoga addicts, maybe .... */ - imlib_context_set_drawable(win); - ii = imlib_create_image_from_drawable(0, x, y, w, h, 0); - imlib_context_set_image(ii); - imlib_image_orientate(2); - imlib_context_set_drawable(*drawable); - imlib_render_image_on_drawable_at_size(0, 0, w, h); + im = EImageGrabDrawable(win, None, x, y, w, h, 0); + EImageOrientate(im, 2); + EImageRenderOnDrawable(im, *draw, 0, 0, w, h, 0); + EImageFree(im); break; default: break; } - if (ii) - imlib_free_image(); } void -TextDrawRotBack(Window win, Pixmap drawable, int x, int y, int w, int h, +TextDrawRotBack(Window win, Pixmap draw, int x, int y, int w, int h, TextState * ts) { - Imlib_Image *ii = NULL; + EImage *im; int win_x, win_y; unsigned int win_w, win_h, win_b, win_d; Window rr; @@ -845,34 +838,26 @@ TextDrawRotBack(Window win, Pixmap drawable, int x, int y, int w, int h, switch (ts->style.orientation) { case FONT_TO_UP: - imlib_context_set_drawable(drawable); - ii = imlib_create_image_from_drawable(0, 0, 0, w, h, 0); - imlib_context_set_image(ii); - imlib_image_orientate(3); - imlib_context_set_drawable(win); - imlib_render_image_on_drawable_at_size(y, x, h, w); + im = EImageGrabDrawable(draw, None, 0, 0, w, h, 0); + EImageOrientate(im, 3); + EImageRenderOnDrawable(im, win, y, x, h, w, 0); + EImageFree(im); break; case FONT_TO_DOWN: - imlib_context_set_drawable(drawable); XGetGeometry(disp, win, &rr, &win_x, &win_y, &win_w, &win_h, &win_b, &win_d); - ii = imlib_create_image_from_drawable(0, 0, 0, w, h, 0); - imlib_context_set_image(ii); - imlib_image_orientate(1); - imlib_context_set_drawable(win); - imlib_render_image_on_drawable_at_size(win_w - y - h, x, h, w); + im = EImageGrabDrawable(draw, None, 0, 0, w, h, 0); + EImageOrientate(im, 1); + EImageRenderOnDrawable(im, win, win_w - y - h, x, h, w, 0); + EImageFree(im); break; case FONT_TO_LEFT: /* Holy carumba! That's for yoga addicts, maybe .... */ - imlib_context_set_drawable(drawable); - ii = imlib_create_image_from_drawable(0, 0, 0, w, h, 0); - imlib_context_set_image(ii); - imlib_image_orientate(2); - imlib_context_set_drawable(win); - imlib_render_image_on_drawable_at_size(x, y, w, h); + im = EImageGrabDrawable(draw, None, 0, 0, w, h, 0); + EImageOrientate(im, 2); + EImageRenderOnDrawable(im, win, x, y, w, h, 0); + EImageFree(im); break; default: break; } - if (ii) - imlib_free_image(); } diff --git a/src/tooltips.c b/src/tooltips.c index a83d6f42..d9861a0d 100644 --- a/src/tooltips.c +++ b/src/tooltips.c @@ -232,7 +232,8 @@ static ImageClass * TooltipCreateIclass(const char *name, const char *file, int *pw, int *ph) { ImageClass *ic; - Imlib_Image *im; + EImage *im; + int w, h; ic = ImageclassFind(name, 0); if (!ic) @@ -241,11 +242,11 @@ TooltipCreateIclass(const char *name, const char *file, int *pw, int *ph) if (im) { - imlib_context_set_image(im); - if (*pw < imlib_image_get_width()) - *pw = imlib_image_get_width(); - if (*ph < imlib_image_get_height()) - *ph = imlib_image_get_height(); + EImageGetSize(im, &w, &h); + if (*pw < w) + *pw = w; + if (*ph < h) + *ph = h; } return ic; @@ -255,20 +256,18 @@ static void TooltipIclassPaste(ToolTip * tt, const char *ic_name, int x, int y, int *px) { ImageClass *ic; - Imlib_Image *im; + EImage *im; + int w, h; ic = ImageclassFind(ic_name, 0); im = ImageclassGetImage(ic, 0, 0, 0); if (!ic || !im) return; - imlib_context_set_image(im); - imlib_context_set_drawable(tt->TTWIN->win); - imlib_context_set_blend(1); - imlib_render_image_on_drawable(x, y); - imlib_context_set_blend(0); + EImageGetSize(im, &w, &h); + EImageRenderOnDrawable(im, tt->TTWIN->win, x, y, w, h, 1); - *px = x + imlib_image_get_width(); + *px = x + w; } void @@ -278,10 +277,10 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y) int ww, hh, adx, ady, dist; int headline_h = 0, headline_w = 0, icons_width = 0, labels_width = 0, double_w = 0; - Imlib_Image *im; + EImage *im; int *heights = NULL; ImageClass *ic; - Imlib_Border *pad; + EImageBorder *pad; int cols[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int num, modifiers; Action *aa; @@ -431,10 +430,8 @@ TooltipShow(ToolTip * tt, const char *text, ActionClass * ac, int x, int y) iy = 0; if (im) { - imlib_context_set_image(im); - iw = imlib_image_get_width(); - ih = imlib_image_get_height(); - imlib_free_image(); + EImageGetSize(im, &iw, &ih); + EImageFree(im); } w += iw; if (h < ih) diff --git a/src/ttfont.c b/src/ttfont.c index f22d07b2..8babcbc6 100644 --- a/src/ttfont.c +++ b/src/ttfont.c @@ -22,8 +22,10 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "E.h" +#include "eimage.h" #include "tclass.h" #include "xwin.h" +#include struct _efont { @@ -65,21 +67,19 @@ void EFont_draw_string(Drawable win, GC gc, int x, int y, const char *text, Efont * f, Visual * vis __UNUSED__, Colormap cm) { - Imlib_Image im; + EImage *im; int w, h, ascent, descent; Efont_extents(f, text, &ascent, &descent, &w, NULL, NULL, NULL, NULL); h = ascent + descent; - imlib_context_set_drawable(win); - im = imlib_create_image_from_drawable(0, x, y - ascent, w, h, 0); + im = EImageGrabDrawable(win, None, x, y - ascent, w, h, 0); imlib_context_set_image(im); - imlib_context_set_font(f->face); ImlibSetFgColorFromGC(gc, cm); imlib_text_draw(0, 0, text); - imlib_render_image_on_drawable(x, y - ascent); - imlib_free_image(); + EImageRenderOnDrawable(im, win, x, y - ascent, w, h, 0); + EImageFree(im); } void diff --git a/src/warp.c b/src/warp.c index 1626148a..b805bffa 100644 --- a/src/warp.c +++ b/src/warp.c @@ -108,7 +108,7 @@ static void WarpFocusWinShow(WarpFocusWin * fw) { WarplistItem *wi; - Imlib_Border *pad; + EImageBorder *pad; int i, x, y, w, h, ww, hh; char s[1024]; const char *fmt; @@ -212,8 +212,8 @@ WarpFocusWinPaint(WarpFocusWin * fw) if (Conf.warplist.icon_mode != 0) { int icon_size = fw->mh - 2 * ICON_PAD; - Imlib_Image *im; - Imlib_Border *pad; + EImage *im; + EImageBorder *pad; pad = ImageclassGetPadding(fw->ic); @@ -225,14 +225,10 @@ WarpFocusWinPaint(WarpFocusWin * fw) if (!im) continue; - imlib_context_set_image(im); - imlib_context_set_drawable(wi->win); - imlib_context_set_blend(1); - imlib_render_image_on_drawable_at_size(pad->left + - ICON_PAD, ICON_PAD, - icon_size, icon_size); - imlib_free_image(); - imlib_context_set_blend(0); + EImageRenderOnDrawable(im, wi->win, pad->left + + ICON_PAD, ICON_PAD, + icon_size, icon_size, 1); + EImageFree(im); } else { diff --git a/src/x.c b/src/x.c index c1d6e216..81d5440a 100644 --- a/src/x.c +++ b/src/x.c @@ -1548,46 +1548,3 @@ EGetTimestamp(void) return ev.xproperty.time; } - -void -EDrawableDumpImage(Drawable draw, const char *txt) -{ - static int seqn = 0; - char buf[1024]; - Imlib_Image *im; - int w, h; - - w = h = 0; - EGetGeometry(draw, NULL, NULL, NULL, &w, &h, NULL, NULL); - if (w <= 0 || h <= 0) - return; - imlib_context_set_drawable(draw); - im = imlib_create_image_from_drawable(None, 0, 0, w, h, !EServerIsGrabbed()); - imlib_context_set_image(im); - imlib_image_set_format("png"); - sprintf(buf, "%s-%#lx-%d.png", txt, draw, seqn++); - Eprintf("EDrawableDumpImage: %s\n", buf); - imlib_save_image(buf); - imlib_free_image_and_decache(); -} - -void -FreePmapMask(PmapMask * pmm) -{ - /* type !=0: Created by imlib_render_pixmaps_for_whole_image... */ - if (pmm->pmap) - { - if (pmm->type == 0) - EFreePixmap(pmm->pmap); - else - imlib_free_pixmap_and_mask(pmm->pmap); - pmm->pmap = 0; - } - - if (pmm->mask) - { - if (pmm->type == 0) - EFreePixmap(pmm->mask); - pmm->mask = 0; - } -}