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; }
struct image *image_new(int width, int height) { struct image *img; #if defined(HAVE_SDL_IMAGE_H) SDL_Surface *priv; Uint32 rmask, gmask, bmask, amask; # if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x00000000; # else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0x00000000; # endif priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); #elif defined(HAVE_IMLIB2_H) Imlib_Image priv = imlib_create_image(width, height); #elif defined(HAVE_CV_H) IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); #endif if(!priv) return NULL; img = (struct image *)malloc(sizeof(struct image)); #if defined(HAVE_SDL_IMAGE_H) img->width = priv->w; img->height = priv->h; img->pitch = priv->pitch; img->channels = priv->format->BytesPerPixel; img->pixels = priv->pixels; #elif defined(HAVE_IMLIB2_H) imlib_context_set_image(priv); img->width = imlib_image_get_width(); img->height = imlib_image_get_height(); img->pitch = 4 * imlib_image_get_width(); img->channels = 4; img->pixels = (char *)imlib_image_get_data(); #elif defined(HAVE_CV_H) img->width = priv->width; img->height = priv->height; img->pitch = priv->widthStep; img->channels = priv->nChannels; img->pixels = priv->imageData; #endif img->priv = (void *)priv; return img; }
void setup_texture( image_tile_t * image_tile ) { glBindTexture( GL_TEXTURE_2D, image_tile->texture ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture // convert imlib image to imlib_context_set_image(image_tile->image); unsigned int *image_data = imlib_image_get_data(); glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, image_data); }
struct image *image_load(const char *name) { struct image *img; #if defined(HAVE_SDL_IMAGE_H) SDL_Surface *priv = IMG_Load(name); #elif defined(HAVE_IMLIB2_H) Imlib_Image priv = imlib_load_image(name); #elif defined(HAVE_CV_H) IplImage *priv = cvLoadImage(name, -1); #endif if(!priv) return NULL; #if defined(HAVE_SDL_IMAGE_H) if(priv->format->BytesPerPixel == 1) { img = image_new(priv->w, priv->h); SDL_BlitSurface(priv, NULL, img->priv, NULL); SDL_FreeSurface(priv); return img; } #endif img = (struct image *)malloc(sizeof(struct image)); #if defined(HAVE_SDL_IMAGE_H) img->width = priv->w; img->height = priv->h; img->pitch = priv->pitch; img->channels = priv->format->BytesPerPixel; img->pixels = priv->pixels; #elif defined(HAVE_IMLIB2_H) imlib_context_set_image(priv); img->width = imlib_image_get_width(); img->height = imlib_image_get_height(); img->pitch = 4 * imlib_image_get_width(); img->channels = 4; img->pixels = (char *)imlib_image_get_data(); #elif defined(HAVE_CV_H) img->width = priv->width; img->height = priv->height; img->pitch = priv->widthStep; img->channels = priv->nChannels; img->pixels = priv->imageData; #endif img->priv = (void *)priv; return img; }
Picture::Picture(std::string file_name, const Palette &palette, bool calc_dominant) { Imlib_Image image = imlib_load_image(file_name.c_str()); assert(image); imlib_context_set_image(image); x_ = imlib_image_get_width(); y_ = imlib_image_get_height(); i = new int[x_ * y_]; uint32_t *img_data = (uint32_t *)imlib_image_get_data(); for (int y = 0; y < y_; y++) for (int x = 0; x < x_; x++) i[x + y * x_] = palette.color(img_data[x + y * x_]); if (calc_dominant) dominant = palette.color(rgbaDominant(img_data, x_*y_)); imlib_free_image(); }
Imlib_Image scale_icon(Imlib_Image original, int icon_size) { Imlib_Image icon_scaled; if (original) { imlib_context_set_image (original); icon_scaled = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), icon_size, icon_size); imlib_context_set_image (icon_scaled); imlib_image_set_has_alpha(1); DATA32* data = imlib_image_get_data(); adjust_asb(data, icon_size, icon_size, launcher_alpha, (float)launcher_saturation/100, (float)launcher_brightness/100); imlib_image_put_back_data(data); } else { icon_scaled = imlib_create_image(icon_size, icon_size); imlib_context_set_image (icon_scaled); imlib_context_set_color(255, 255, 255, 255); imlib_image_fill_rectangle(0, 0, icon_size, icon_size); } return icon_scaled; }
void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, int64_t pts) { ContextInfo *ci = (ContextInfo *) ctx; AVPicture picture1; Imlib_Image image; DATA32 *data; image = get_cached_image(ci, width, height); if (!image) { image = imlib_create_image(width, height); put_cached_image(ci, image, width, height); } imlib_context_set_image(image); data = imlib_image_get_data(); if (pix_fmt != PIX_FMT_RGBA32) { avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGBA32, width, height); if (img_convert(&picture1, PIX_FMT_RGBA32, picture, pix_fmt, width, height) < 0) { goto done; } } else { av_abort(); } imlib_image_set_has_alpha(0); { int wid, hig, h_a, v_a; char buff[1000]; char tbuff[1000]; char *tbp = ci->text; time_t now = time(0); char *p, *q; int x, y; if (ci->file) { int fd = open(ci->file, O_RDONLY); if (fd < 0) { tbp = "[File not found]"; } else { int l = read(fd, tbuff, sizeof(tbuff) - 1); if (l >= 0) { tbuff[l] = 0; tbp = tbuff; } else { tbp = "[I/O Error]"; } close(fd); } } strftime(buff, sizeof(buff), tbp ? tbp : "[No data]", localtime(&now)); x = ci->x; y = ci->y; for (p = buff; p; p = q) { q = strchr(p, '\n'); if (q) *q++ = 0; imlib_text_draw_with_return_metrics(x, y, p, &wid, &hig, &h_a, &v_a); y += v_a; } } if (pix_fmt != PIX_FMT_RGBA32) { if (img_convert(picture, pix_fmt, &picture1, PIX_FMT_RGBA32, width, height) < 0) { } } done: ; }
static Imlib_Image bump_map(Imlib_Image im, pIFunctionParam par) { Imlib_Image map = im; pIFunctionParam ptr; double an = 0, el = 30, d = 0x200; double red = 0x200, green = 0x200, blue = 0x200; double ambient = 0; int free_map = 0; DATA32 *src; DATA32 *mp, *mpy, *mpp; double z, x2, y2; int w, h, i, j, w2, h2, wh2, mx, my; for (ptr = par; ptr; ptr = ptr->next) { ASSIGN_IMAGE("map", map); ASSIGN_INT("angle", an); ASSIGN_INT("elevation", el); ASSIGN_INT("depth", d); ASSIGN_INT("red", red); ASSIGN_INT("green", green); ASSIGN_INT("blue", blue); ASSIGN_INT("ambient", ambient); } if (!map) return im; red /= 0x100; green /= 0x100; blue /= 0x100; ambient /= 0x100; d /= 0x100; imlib_context_set_image(im); src = imlib_image_get_data(); w = imlib_image_get_width(); h = imlib_image_get_height(); imlib_context_set_image(map); mpp = imlib_image_get_data_for_reading_only(); w2 = imlib_image_get_width(); h2 = imlib_image_get_height(); wh2 = w2 * h2; an *= (PI / 180); el *= (PI / 180); x2 = sin(an) * cos(el); y2 = cos(an) * cos(el); z = sin(el); d /= (255 * (255 + 255 + 255)); my = h2; for (j = h; --j >= 0;) { mp = mpp; mpp += w2; if (--my <= 0) { mpp -= wh2; my = h2; } mpy = mpp; mx = w2; for (i = w; --i >= 0;) { double x1, y1, v; int r, g, b, gr; gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)); y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) + G_VAL(mpy) + B_VAL(mpy)) - gr); mp++; mpy++; if (--mx <= 0) { mp -= w2; mpy -= w2; mx = w2; } x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)) - gr); v = x1 * x2 + y1 * y2 + z; v /= sqrt((x1 * x1) + (y1 * y1) + 1.0); v += ambient; r = v * R_VAL(src) * red; g = v * G_VAL(src) * green; b = v * B_VAL(src) * blue; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; R_VAL(src) = r; G_VAL(src) = g; B_VAL(src) = b; src++; } } if (free_map) { imlib_context_set_image(map); imlib_free_image(); } return im; }
static void take_image(CIMAGE *_object, Imlib_Image image) { imlib_context_set_image((Imlib_Image)image); IMAGE.Take(THIS, &_image_owner, image, imlib_image_get_width(), imlib_image_get_height(), (void *)imlib_image_get_data()); }
void get_icon (Task *tsk) { Panel *panel = tsk->area.panel; if (!panel->g_task.icon) return; size_t i; Imlib_Image img = NULL; XWMHints *hints = 0; gulong *data = 0; int k; for (k=0; k<TASK_STATE_COUNT; ++k) { if (tsk->icon[k]) { imlib_context_set_image(tsk->icon[k]); imlib_free_image(); tsk->icon[k] = 0; } } data = server_get_property (tsk->win, server.atom._NET_WM_ICON, XA_CARDINAL, (int*)&i); if (data) { // get ARGB icon int w, h; gulong *tmp_data; tmp_data = get_best_icon (data, get_icon_count (data, i), i, &w, &h, panel->g_task.icon_size1); #ifdef __x86_64__ DATA32 icon_data[w * h]; size_t length = w * h; for (i = 0; i < length; ++i) icon_data[i] = tmp_data[i]; img = imlib_create_image_using_copied_data (w, h, icon_data); #else img = imlib_create_image_using_data (w, h, (DATA32*)tmp_data); #endif } else { // get Pixmap icon hints = XGetWMHints(server.dsp, tsk->win); if (hints) { if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) { // get width, height and depth for the pixmap Window root; int icon_x, icon_y; uint32_t border_width, bpp; uint32_t w, h; //printf(" get pixmap\n"); XGetGeometry(server.dsp, hints->icon_pixmap, &root, &icon_x, &icon_y, &w, &h, &border_width, &bpp); imlib_context_set_drawable(hints->icon_pixmap); img = imlib_create_image_from_drawable(hints->icon_mask, 0, 0, w, h, 0); } } } if (img == NULL) { imlib_context_set_image(default_icon); img = imlib_clone_image(); } // transform icons imlib_context_set_image(img); imlib_image_set_has_alpha(1); int w, h; w = imlib_image_get_width(); h = imlib_image_get_height(); Imlib_Image orig_image = imlib_create_cropped_scaled_image(0, 0, w, h, panel->g_task.icon_size1, panel->g_task.icon_size1); imlib_free_image(); imlib_context_set_image(orig_image); tsk->icon_width = imlib_image_get_width(); tsk->icon_height = imlib_image_get_height(); for (k=0; k<TASK_STATE_COUNT; ++k) { imlib_context_set_image(orig_image); tsk->icon[k] = imlib_clone_image(); imlib_context_set_image(tsk->icon[k]); DATA32 *data32; if (panel->g_task.alpha[k] != 100 || panel->g_task.saturation[k] != 0 || panel->g_task.brightness[k] != 0) { data32 = imlib_image_get_data(); adjust_asb(data32, tsk->icon_width, tsk->icon_height, panel->g_task.alpha[k], (float)panel->g_task.saturation[k]/100, (float)panel->g_task.brightness[k]/100); imlib_image_put_back_data(data32); } } imlib_context_set_image(orig_image); imlib_free_image(); if (hints) XFree(hints); if (data) XFree (data); GPtrArray* task_group = task_get_tasks(tsk->win); if (task_group) { for (i=0; i<task_group->len; ++i) { Task* tsk2 = g_ptr_array_index(task_group, i); tsk2->icon_width = tsk->icon_width; tsk2->icon_height = tsk->icon_height; int k; for (k=0; k<TASK_STATE_COUNT; ++k) tsk2->icon[k] = tsk->icon[k]; set_task_redraw(tsk2); } } }
void systray_render_icon_composited(void *t) { // we end up in this function only in real transparency mode or if systray_task_asb != 100 0 0 // we made also sure, that we always have a 32 bit visual, i.e. we can safely create 32 bit pixmaps here TrayWindow *traywin = t; if (systray_profile) fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); // wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); struct timespec earliest_render = add_msec_to_timespec(traywin->time_last_render, min_refresh_period); if (compare_timespecs(&earliest_render, &now) > 0) { traywin->num_fast_renders++; if (traywin->num_fast_renders > max_fast_refreshes) { traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon_composited, traywin, &traywin->render_timeout); if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); return; } } else { traywin->time_last_render.tv_sec = now.tv_sec; traywin->time_last_render.tv_nsec = now.tv_nsec; traywin->num_fast_renders = 0; } if (traywin->width == 0 || traywin->height == 0) { // reschedule rendering since the geometry information has not yet been processed (can happen on slow cpu) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon_composited, traywin, &traywin->render_timeout); if (systray_profile) fprintf(stderr, YELLOW "[%f] %s:%d win = %lu (%s) delaying rendering" RESET "\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); return; } if (traywin->render_timeout) { stop_timeout(traywin->render_timeout); traywin->render_timeout = NULL; } // good systray icons support 32 bit depth, but some icons are still 24 bit. // We create a heuristic mask for these icons, i.e. we get the rgb value in the top left corner, and // mask out all pixel with the same rgb value // Very ugly hack, but somehow imlib2 is not able to get the image from the traywindow itself, // so we first render the tray window onto a pixmap, and then we tell imlib2 to use this pixmap as // drawable. If someone knows why it does not work with the traywindow itself, please tell me ;) Pixmap tmp_pmap = XCreatePixmap(server.display, traywin->win, traywin->width, traywin->height, 32); if (!tmp_pmap) { goto on_systray_error; } XRenderPictFormat *f; if (traywin->depth == 24) { f = XRenderFindStandardFormat(server.display, PictStandardRGB24); } else if (traywin->depth == 32) { f = XRenderFindStandardFormat(server.display, PictStandardARGB32); } else { fprintf(stderr, RED "Strange tray icon found with depth: %d" RESET "\n", traywin->depth); XFreePixmap(server.display, tmp_pmap); return; } XRenderPictFormat *f32 = XRenderFindVisualFormat(server.display, server.visual32); if (!f || !f32) { XFreePixmap(server.display, tmp_pmap); goto on_systray_error; } XSync(server.display, False); error = FALSE; XErrorHandler old = XSetErrorHandler(window_error_handler); // if (server.real_transparency) // Picture pict_image = XRenderCreatePicture(server.display, traywin->parent, f, 0, 0); // reverted Rev 407 because here it's breaking alls icon with systray + xcompmgr Picture pict_image = XRenderCreatePicture(server.display, traywin->win, f, 0, 0); if (!pict_image) { XFreePixmap(server.display, tmp_pmap); XSetErrorHandler(old); goto on_error; } Picture pict_drawable = XRenderCreatePicture(server.display, tmp_pmap, XRenderFindVisualFormat(server.display, server.visual32), 0, 0); if (!pict_drawable) { XRenderFreePicture(server.display, pict_image); XFreePixmap(server.display, tmp_pmap); XSetErrorHandler(old); goto on_error; } XRenderComposite(server.display, PictOpSrc, pict_image, None, pict_drawable, 0, 0, 0, 0, 0, 0, traywin->width, traywin->height); XRenderFreePicture(server.display, pict_image); XRenderFreePicture(server.display, pict_drawable); // end of the ugly hack and we can continue as before imlib_context_set_visual(server.visual32); imlib_context_set_colormap(server.colormap32); imlib_context_set_drawable(tmp_pmap); Imlib_Image image = imlib_create_image_from_drawable(0, 0, 0, traywin->width, traywin->height, 1); imlib_context_set_visual(server.visual); imlib_context_set_colormap(server.colormap); XFreePixmap(server.display, tmp_pmap); if (!image) { imlib_context_set_visual(server.visual); imlib_context_set_colormap(server.colormap); XSetErrorHandler(old); goto on_error; } else { if (traywin->image) { imlib_context_set_image(traywin->image); imlib_free_image_and_decache(); } traywin->image = image; } imlib_context_set_image(traywin->image); // if (traywin->depth == 24) // imlib_save_image("/home/thil77/test.jpg"); imlib_image_set_has_alpha(1); DATA32 *data = imlib_image_get_data(); if (traywin->depth == 24) { create_heuristic_mask(data, traywin->width, traywin->height); } if (systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) adjust_asb(data, traywin->width, traywin->height, systray.alpha, (float)systray.saturation / 100, (float)systray.brightness / 100); imlib_image_put_back_data(data); systray_render_icon_from_image(traywin); if (traywin->damage) XDamageSubtract(server.display, traywin->damage, None, None); XSync(server.display, False); XSetErrorHandler(old); if (error) goto on_error; panel_refresh = TRUE; if (systray_profile) fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); return; on_error: fprintf(stderr, RED "systray %d: rendering error for icon %lu (%s) pid %d" RESET "\n", __LINE__, traywin->win, traywin->name, traywin->pid); return; on_systray_error: fprintf(stderr, RED "systray %d: rendering error for icon %lu (%s) pid %d. " "Disabling compositing and restarting systray..." RESET "\n", __LINE__, traywin->win, traywin->name, traywin->pid); systray_composited = 0; stop_net(); start_net(); return; }