Exemple #1
0
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);
	}
}
Exemple #2
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;
}
Exemple #3
0
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());
}
Exemple #4
0
static Imlib_Image check_image(void *_object)
{
	Imlib_Image image = (Imlib_Image)IMAGE.Check(THIS, &_image_owner);
	imlib_context_set_image(image);
	imlib_image_set_has_alpha(TRUE);
	return image;
}
Exemple #5
0
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;
}
Exemple #6
0
void
Rterm_draw_screen_string_imlib2(struct R_termscreen *screen, int row, int column, int len)
{
    R_text_t *text;
    R_textflags_t *textflags;
    int bufferrow;
    int bgcolor, fgcolor;
    int textw, texth;
    struct imlib2color *color;
    Imlib_Image *textimg;

    if (screen == NULL) {

	return;
    }
    text = screen->textbuf.data[screen->viewrow + row] + column;
    textflags = screen->textbuf.renddata[screen->viewrow + row] + column;
    memcpy(screen->stringbuffer, text, len);
    screen->stringbuffer[len] = '\0';
    fprintf(stderr, "string: %s\n", screen->stringbuffer);
    fgcolor = RTERM_CHAR_FG_COLOR(*textflags);
    if (fgcolor) {
	color = &screen->im2colors[fgcolor];
    } else {
	color = &screen->im2colors[RTERM_SCREEN_FOREGROUND];
    }
#if 0
    fprintf(stderr, "red == %d, green == %d, blue == %d, alpha == %d\n",
	    color->red, color->green, color->blue, color->alpha);
#endif
    imlib_context_set_font(screen->im2font);
    imlib_context_set_color(color->red, color->green, color->blue,
			    color->alpha);
    imlib_context_set_drawable(screen->buf);
    imlib_get_text_size(screen->stringbuffer,
                        &textw, &texth);
    textimg = imlib_create_image(textw, texth);
    imlib_context_set_image(textimg);
    imlib_image_clear();
    imlib_image_set_has_alpha(1);
    imlib_context_set_blend(0);
    imlib_context_set_anti_alias(0);
    imlib_text_draw(0,
                    0,
		    screen->stringbuffer);
    imlib_render_image_on_drawable(Rterm_screen_column_x(screen, column),
                                   Rterm_screen_row_y(screen, column));
    imlib_free_image();

    return;
}
Exemple #7
0
void init_render(struct xinfo *X, struct panel *P)
{
	bbwidth = P->width;
	bbheight = P->theme->height;
	bb = imlib_create_image(bbwidth, bbheight);
	bbcolor = imlib_create_image(bbwidth, bbheight);
	imlib_context_set_image(bb);
	imlib_image_set_has_alpha(1);
	bbdpy = X->display;
	bbvis = X->visual;
	bbwin = P->win;
	bbcm = X->colmap;
	bbx = P->x;
	bby = P->y;
	rootpmap = &X->rootpmap;
	theme = P->theme;

	imlib_context_set_display(bbdpy);
	imlib_context_set_visual(bbvis);
	imlib_context_set_colormap(bbcm);

#ifdef WITH_COMPOSITE
	if (P->theme->use_composite) {
		XRenderPictFormat *fmt = XRenderFindStandardFormat(bbdpy, PictStandardARGB32);
		bbalpha = imlib_create_image(bbwidth, bbheight);

		pixcolor = XCreatePixmap(bbdpy, bbwin, bbwidth, bbheight, 32);
		pixalpha = XCreatePixmap(bbdpy, bbwin, bbwidth, bbheight, 32);

		piccolor = XRenderCreatePicture(bbdpy, pixcolor, fmt, 0, 0);
		picalpha = XRenderCreatePicture(bbdpy, pixalpha, fmt, 0, 0);
	
		XRenderPictureAttributes pwin;
		pwin.subwindow_mode = IncludeInferiors;
		rootpic = XRenderCreatePicture(bbdpy, bbwin, XRenderFindVisualFormat(bbdpy, bbvis), 
				CPSubwindowMode, &pwin);
	} else 
#endif
	if (*rootpmap) {
		update_bg();
	} else {
		set_bg();
	}

	imlib_context_set_blend(0);
	imlib_context_set_operation(IMLIB_OP_COPY);
}
Exemple #8
0
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;
}
Exemple #9
0
bool img_load_gif(img_t *img, const fileinfo_t *file)
{
	GifFileType *gif;
	GifRowType *rows = NULL;
	GifRecordType rec;
	ColorMapObject *cmap;
	DATA32 bgpixel, *data, *ptr;
	DATA32 *prev_frame = NULL;
	Imlib_Image im;
	int i, j, bg, r, g, b;
	int x, y, w, h, sw, sh;
	int px, py, pw, ph;
	int intoffset[] = { 0, 4, 2, 1 };
	int intjump[] = { 8, 8, 4, 2 };
	int transp = -1;
	unsigned int disposal = 0, prev_disposal = 0;
	unsigned int delay = 0;
	bool err = false;

	if (img->multi.cap == 0) {
		img->multi.cap = 8;
		img->multi.frames = (img_frame_t*)
		                    s_malloc(sizeof(img_frame_t) * img->multi.cap);
	}
	img->multi.cnt = img->multi.sel = 0;
	img->multi.length = 0;

#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
	gif = DGifOpenFileName(file->path, NULL);
#else
	gif = DGifOpenFileName(file->path);
#endif
	if (gif == NULL) {
		warn("could not open gif file: %s", file->name);
		return false;
	}
	bg = gif->SBackGroundColor;
	sw = gif->SWidth;
	sh = gif->SHeight;
	px = py = pw = ph = 0;

	do {
		if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
			err = true;
			break;
		}
		if (rec == EXTENSION_RECORD_TYPE) {
			int ext_code;
			GifByteType *ext = NULL;

			DGifGetExtension(gif, &ext_code, &ext);
			while (ext) {
				if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
					if (ext[1] & 1)
						transp = (int) ext[4];
					else
						transp = -1;

					delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
					disposal = (unsigned int) ext[1] >> 2 & 0x7;
				}
				ext = NULL;
				DGifGetExtensionNext(gif, &ext);
			}
		} else if (rec == IMAGE_DESC_RECORD_TYPE) {
			if (DGifGetImageDesc(gif) == GIF_ERROR) {
				err = true;
				break;
			}
			x = gif->Image.Left;
			y = gif->Image.Top;
			w = gif->Image.Width;
			h = gif->Image.Height;

			rows = (GifRowType*) s_malloc(h * sizeof(GifRowType));
			for (i = 0; i < h; i++)
				rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType));
			if (gif->Image.Interlace) {
				for (i = 0; i < 4; i++) {
					for (j = intoffset[i]; j < h; j += intjump[i])
						DGifGetLine(gif, rows[j], w);
				}
			} else {
				for (i = 0; i < h; i++)
					DGifGetLine(gif, rows[i], w);
			}

			ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh);
			cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
			r = cmap->Colors[bg].Red;
			g = cmap->Colors[bg].Green;
			b = cmap->Colors[bg].Blue;
			bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);

			for (i = 0; i < sh; i++) {
				for (j = 0; j < sw; j++) {
					if (i < y || i >= y + h || j < x || j >= x + w ||
					    rows[i-y][j-x] == transp)
					{
						if (prev_frame != NULL && (prev_disposal != 2 ||
						    i < py || i >= py + ph || j < px || j >= px + pw))
						{
							*ptr = prev_frame[i * sw + j];
						} else {
							*ptr = bgpixel;
						}
					} else {
						r = cmap->Colors[rows[i-y][j-x]].Red;
						g = cmap->Colors[rows[i-y][j-x]].Green;
						b = cmap->Colors[rows[i-y][j-x]].Blue;
						*ptr = 0xff << 24 | r << 16 | g << 8 | b;
					}
					ptr++;
				}
			}

			im = imlib_create_image_using_copied_data(sw, sh, data);

			for (i = 0; i < h; i++)
				free(rows[i]);
			free(rows);
			free(data);

			if (im == NULL) {
				err = true;
				break;
			}

			imlib_context_set_image(im);
			imlib_image_set_format("gif");
			if (transp >= 0)
				imlib_image_set_has_alpha(1);

			if (disposal != 3)
				prev_frame = imlib_image_get_data_for_reading_only();
			prev_disposal = disposal;
			px = x, py = y, pw = w, ph = h;

			if (img->multi.cnt == img->multi.cap) {
				img->multi.cap *= 2;
				img->multi.frames = (img_frame_t*)
				                    s_realloc(img->multi.frames,
				                              img->multi.cap * sizeof(img_frame_t));
			}
			img->multi.frames[img->multi.cnt].im = im;
			img->multi.frames[img->multi.cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY;
			img->multi.length += img->multi.frames[img->multi.cnt].delay;
			img->multi.cnt++;
		}
	} while (rec != TERMINATE_RECORD_TYPE);
Exemple #10
0
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:
    ;
}
Exemple #11
0
/* Originally based on, but in its current form merely inspired by Imlib2's
 * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
 */
bool img_load_gif(img_t *img, const fileinfo_t *file) {
	GifFileType *gif;
	GifRowType *rows = NULL;
	GifRecordType rec;
	ColorMapObject *cmap;
	DATA32 bgpixel, *data, *ptr;
	DATA32 *prev_frame = NULL;
	Imlib_Image *im;
	int i, j, bg, r, g, b;
	int x, y, w, h, sw, sh;
	int intoffset[] = { 0, 4, 2, 1 };
	int intjump[] = { 8, 8, 4, 2 };
	int transp = -1;
	unsigned int delay = 0;
	bool err = false;

	if (img->multi.cap == 0) {
		img->multi.cap = 8;
		img->multi.frames = (img_frame_t*)
		                    s_malloc(sizeof(img_frame_t) * img->multi.cap);
	}
	img->multi.cnt = 0;
	img->multi.sel = 0;

	gif = DGifOpenFileName(file->path);
	if (gif == NULL) {
		warn("could not open gif file: %s", file->name);
		return false;
	}
	bg = gif->SBackGroundColor;
	sw = gif->SWidth;
	sh = gif->SHeight;

	do {
		if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
			err = true;
			break;
		}
		if (rec == EXTENSION_RECORD_TYPE) {
			int ext_code;
			GifByteType *ext = NULL;

			DGifGetExtension(gif, &ext_code, &ext);
			while (ext) {
				if (ext_code == 0xf9) {
					if (ext[1] & 1)
						transp = (int) ext[4];
					else
						transp = -1;

					delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
					if (delay)
						delay = MAX(delay, MIN_GIF_DELAY);

					/* TODO: handle disposal method, section 23.c.iv of
					         http://www.w3.org/Graphics/GIF/spec-gif89a.txt */
				}
				ext = NULL;
				DGifGetExtensionNext(gif, &ext);
			}
		} else if (rec == IMAGE_DESC_RECORD_TYPE) {
			if (DGifGetImageDesc(gif) == GIF_ERROR) {
				err = true;
				break;
			}
			x = gif->Image.Left;
			y = gif->Image.Top;
			w = gif->Image.Width;
			h = gif->Image.Height;

			rows = (GifRowType*) s_malloc(h * sizeof(GifRowType));
			for (i = 0; i < h; i++)
				rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType));
			if (gif->Image.Interlace) {
				for (i = 0; i < 4; i++) {
					for (j = intoffset[i]; j < h; j += intjump[i])
						DGifGetLine(gif, rows[j], w);
				}
			} else {
				for (i = 0; i < h; i++)
					DGifGetLine(gif, rows[i], w);
			}

			ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh);
			cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
			r = cmap->Colors[bg].Red;
			g = cmap->Colors[bg].Green;
			b = cmap->Colors[bg].Blue;
			bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);

			for (i = 0; i < sh; i++) {
				for (j = 0; j < sw; j++) {
					if (i < y || i >= y + h || j < x || j >= x + w ||
					    rows[i-y][j-x] == transp)
					{
						if (prev_frame != NULL)
							*ptr = prev_frame[i * sw + j];
						else
							*ptr = bgpixel;
					} else {
						r = cmap->Colors[rows[i-y][j-x]].Red;
						g = cmap->Colors[rows[i-y][j-x]].Green;
						b = cmap->Colors[rows[i-y][j-x]].Blue;
						*ptr = 0xff << 24 | r << 16 | g << 8 | b;
					}
					ptr++;
				}
			}

			im = imlib_create_image_using_copied_data(sw, sh, data);

			for (i = 0; i < h; i++)
				free(rows[i]);
			free(rows);
			free(data);

			if (im == NULL) {
				err = true;
				break;
			}

			imlib_context_set_image(im);
			prev_frame = imlib_image_get_data_for_reading_only();

			imlib_image_set_format("gif");
			if (transp >= 0)
				imlib_image_set_has_alpha(1);

			if (img->multi.cnt == img->multi.cap) {
				img->multi.cap *= 2;
				img->multi.frames = (img_frame_t*)
				                    s_realloc(img->multi.frames,
				                              img->multi.cap * sizeof(img_frame_t));
			}
			img->multi.frames[img->multi.cnt].im = im;
			img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY;
			img->multi.cnt++;
		}
	} while (rec != TERMINATE_RECORD_TYPE);

	DGifCloseFile(gif);

	if (err && !file->loaded)
		warn("corrupted gif file: %s", file->name);

	if (img->multi.cnt > 1) {
		imlib_context_set_image(img->im);
		imlib_free_image();
		img->im = img->multi.frames[0].im;
		img->multi.animate = GIF_AUTOPLAY;
	} else if (img->multi.cnt == 1) {
		imlib_context_set_image(img->multi.frames[0].im);
		imlib_free_image();
		img->multi.cnt = 0;
		img->multi.animate = false;
	}

	imlib_context_set_image(img->im);

	return !err;
}
Exemple #12
0
/*
 *    Load & display image
 */
void qiv_load_image(qiv_image *q) {
  /* Don't initialize most variables here, initialize them after load_next_image: */
  struct stat st;
  const char *image_name;
  Imlib_Image *im;
  struct timeval load_before, load_after;

  char is_stat_ok;
  /* Used to omit slow disk operations if image_file doesn't exist or isn't
   * a file.
   */
  char is_maybe_image_file;
  char is_first_error = 1;

 load_next_image:
  is_stat_ok = 0;
  is_maybe_image_file = 1;
  image_name = image_names[image_idx];
  gettimeofday(&load_before, 0);

  if (imlib_context_get_image())
    imlib_free_image();

  q->real_w = q->real_h = -2;
  q->has_thumbnail = FALSE;
  if (!do_omit_load_stat) {
    is_stat_ok = 0 == stat(image_name, &st);
    is_maybe_image_file = is_stat_ok && S_ISREG(st.st_mode);
  }
  current_mtime = is_stat_ok ? st.st_mtime : 0;
  im = NULL;
  if (thumbnail && fullscreen && (is_stat_ok || maxpect)) {
    char *th_image_name =
        is_maybe_image_file ?
        get_thumbnail_filename(image_name, &is_maybe_image_file) : NULL;
    if (th_image_name) {
      im = imlib_load_image(th_image_name);
      if (im && maxpect) {
        get_image_dimensions(image_name, th_image_name,
                             &q->real_w, &q->real_h);
      }
      free(th_image_name);
      th_image_name = NULL;
    }
  }
  if (im) {  /* We have a dumb thumbnail in im. */
    if (maxpect) {
      current_mtime = 0;
      q->has_thumbnail = TRUE;
      /* Now im still has the thumbnail image. Keep it. */
    } else {  /* Use the real, non-thumbnail image instead. */
      imlib_context_set_image(im);
      imlib_free_image();
      im = is_maybe_image_file ? imlib_load_image((char*)image_name) : NULL;
    }
  } else {
    im = is_maybe_image_file ? imlib_load_image((char*)image_name) : NULL;
  }

  if (!im) { /* error */
    q->error = 1;
    q->orig_w = 400;
    q->orig_h = 300;

    if (to_root || to_root_t || to_root_s) {
      fprintf(stderr, "qiv: cannot load background_image\n");
      qiv_exit(1);
    }

    /* Shortcut to speed up lots of subsequent load failures. */
    if (is_first_error) {
      check_size(q, TRUE);
      if (first) {
        setup_win(q);
        first = 0;
      }
      gdk_window_set_background(q->win, &error_bg);
      gdk_beep();
      is_first_error = 0;
    }

    /* TODO(pts): Avoid the slow loop of copying pointers around in update_image_on_error. */
    update_image_on_error(q);
    /* This is a shortcut to avoid stack overflow in the recursion of
     * qiv_load_image -> update_image -> qiv_load_image -> update_image -> ...
     * if there are errors loading many subsequent images.
     */
    goto load_next_image;
  }

  if (thumbnail && !q->has_thumbnail && q->real_w < 0 && is_maybe_image_file) {
    FILE *f = fopen(image_name, "rb");
    if (f) {
      get_real_dimensions_fast(f, &q->real_w, &q->real_h);
      fclose(f);
    }
  }

  /* Retrieve image properties */
  imlib_context_set_image(im);
  q->error = 0;
  q->orig_w = imlib_image_get_width();
  q->orig_h = imlib_image_get_height();
  if (q->orig_w >= (1 << 23) / q->orig_h) {
    /* Workaround for Imlib2 1.4.6 on Ubuntu Trusty: PNG images with an
     * alpha channel and pixel count >= (1 << 23) are displayed as black.
     * imlib_image_query_pixel returns the correct value, but
     * imlib_render_pixmaps_for_whole_image_at_size renders only black
     * pixels if unzoomed.
     */
    Imlib_Color c;
    /* Without this call, imlib_image_set_has_alpha(0) is too early, and
     * it has no effect.
     */
    imlib_image_query_pixel(0, 0, &c);
    imlib_image_set_has_alpha(0);
  }
#ifdef HAVE_EXIF
  if (autorotate) {
    transform( q, orient( image_name));
  }
#endif

  check_size(q, TRUE);

  if (first) {
    setup_win(q);
    first = 0;
  }

  /* desktop-background -> exit */
  if (to_root || to_root_t || to_root_s) {
    set_desktop_image(q);
    if(slide)
      return;
    else
      qiv_exit(0);
  }

  gdk_window_set_background(q->win, &image_bg);

  if (do_grab || (fullscreen && !disable_grab) ) {
    gdk_keyboard_grab(q->win, FALSE, CurrentTime);
    gdk_pointer_grab(q->win, FALSE,
      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK |
      GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, CurrentTime);
  }

  gettimeofday(&load_after, 0);
  /* load_elapsed used by update_image. */
  load_elapsed = ((load_after.tv_sec +  load_after.tv_usec / 1.0e6) -
                 (load_before.tv_sec + load_before.tv_usec / 1.0e6));

  update_image(q, FULL_REDRAW);
//    if (magnify && !fullscreen) {  // [lc]
//     setup_magnify(q, &magnify_img);
//     update_magnify(q, &magnify_img, FULL_REDRAW, 0, 0);
//    }
}
Exemple #13
0
void
menu_draw_string_imlib2(Rwindow_t *window)
{
    int textw, texth;
    unsigned int winw, winh;
    unsigned int dummyui;
    int dummyi;
    size_t len;
    char *str;
    Window dummywin;
    Imlib_Image textimg;
    char blend;

    if (window->im2title) {
        XGetGeometry(window->app->display, window->id, &dummywin,
                     &dummyi, &dummyi, &winw, &winh, &dummyui, &dummyui);
        imlib_context_set_image(window->im2title);
        imlib_context_set_drawable(window->id);
        blend = imlib_context_get_blend();
        imlib_context_set_blend(1);
        imlib_render_image_on_drawable(window->menu->lefttextoffset,
                                       (winh - window->im2titleh) / 2);
        if (window->menuitem) {
            textimg = NULL;
            if (window->menuitem->type == MENUITEM_TOGGLE) {
                if (!window->menuitem->im2true) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->truetext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->truetext);
                        window->menuitem->im2true = textimg;
                        window->menuitem->im2truew = textw;
                        window->menuitem->im2trueh = texth;
                    }
                }
                if (!window->menuitem->im2false) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->falsetext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->falsetext);
                        window->menuitem->im2false = textimg;
                        window->menuitem->im2falsew = textw;
                        window->menuitem->im2falseh = texth;
                    }
                }
                if (*((unsigned long *)window->menuitem->option.valueptr)
                    & window->menuitem->option.flag) {
                    str = window->menuitem->truetext;
                    textimg = window->menuitem->im2true;
                    textw = window->menuitem->im2truew;
                    texth = window->menuitem->im2trueh;
                } else {
                    str = window->menuitem->falsetext;
                    textimg = window->menuitem->im2false;
                    textw = window->menuitem->im2falsew;
                    texth = window->menuitem->im2falseh;
                }
            } else if (window->menuitem->righttext) {
                if (!window->menuitem->im2right) {
                    imlib_context_set_font(window->im2font);
                    imlib_get_text_size(window->menuitem->righttext,
                                        &textw, &texth);
                    textimg = imlib_create_image(textw, texth);
                    if (textimg) {
                        imlib_context_set_image(textimg);
                        imlib_image_set_has_alpha(1);
                        imlib_image_clear();
                        imlib_context_set_color(204, 181, 59, 255);
                        imlib_text_draw(0, 0, window->menuitem->righttext);
                        window->menuitem->im2right = textimg;
                        window->menuitem->im2rightw = textw;
                        window->menuitem->im2righth = texth;
                    }
                }
                str = window->menuitem->righttext;
                textimg = window->menuitem->im2right;
                textw = window->menuitem->im2rightw;
                texth = window->menuitem->im2righth;
            }
            if (textimg) {
                imlib_context_set_image(textimg);
                imlib_context_set_drawable(window->id);
                imlib_render_image_on_drawable(winw - window->menu->righttextoffset - textw,
                                               (winh - texth) / 2);
            } else {
#if 0
                len = strlen(str);
                if (len) {
                    XDrawString(window->app->display, window->id, window->gc,
                                winw - window->menu->righttextoffset
                                - len * FONT_WIDTH(window->fontinfo),
                                (winh + FONT_HEIGHT(window->fontinfo)) / 2,
                                str, len);
                }
#endif
            }
        }
        imlib_context_set_blend(blend);
    } else {
        menu_draw_string(window);
    }

    return;
}
Exemple #14
0
void
gib_imlib_image_set_has_alpha(Imlib_Image im, int alpha)
{
   imlib_context_set_image(im);
   imlib_image_set_has_alpha(alpha);
}
Exemple #15
0
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);
		}
	}
}
Exemple #16
0
int load_Mod_image (ImageMode mode, const char *arg, int userW, int userH,
				int alpha, Imlib_Image rootimg, int ck0)
{
	int width, height;
	int imgW, imgH, o;
	int left, top;
	left=top=0;
    	int x, y;
	width = DisplayWidth (display, screen);
	height = DisplayHeight (display, screen);
	
	Imlib_Image buffer = imlib_load_image (arg);

	if ( !buffer ) 
	{
		return 1;
	}

	imlib_context_set_image (buffer);
	imgW = imlib_image_get_width (), imgH = imlib_image_get_height ();

	if (alpha < 255)
	{
		// Create alpha-override mask
		imlib_image_set_has_alpha (1);
		Imlib_Color_Modifier modifier = imlib_create_color_modifier ();
		imlib_context_set_color_modifier (modifier);

		DATA8 red[256], green[256], blue[256], alph[256];
		imlib_get_color_modifier_tables (red, green, blue, alph);

		for (o = 0; o < 256; o++)
			alph[o] = (DATA8) alpha;

		imlib_set_color_modifier_tables (red, green, blue, alph);

		imlib_apply_color_modifier ();
		imlib_free_color_modifier ();
	}

		imlib_context_set_image (rootimg);

	if (mode == Fill)
	{
		imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH,
									0, 0, userW, userH);
	}
			
	if (mode == Dia)
	{
		
		
		if (userW >= width || userH >= height ) 
		{ 
			imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, 0, 0, width, height);
		}
		else if ( userH < height || userW < width )
		{
			int left, top;
			
			left = (width - userW) / 2; 
			top =  (height - userH) / 2; 
			
			imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, left, top, userW, userH);
		}
	}

	if (mode == Tile)
	{
		if ( ck0 == 3 )
		{ 
			
			left = (width - imgW) / 2;
			top = (height - imgH) / 2;
			
			for (; left > 0; left -= imgW);
				for (; top > 0; top -= imgH);
				
			for (x = left; x < width; x += imgW)
				for (y = top; y < height; y += imgH)
			
			imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, x, y, imgW, imgH);
		
		}
		if (ck0 != 3)
		{ 
			left = (width - userW) / 2;
			top = (height - userH) /2;
			
			for (; left > 0; left -= userW);
				for (; top > 0; top -= userH);

			for (x = left; x < width; x += userW)
				for (y = top; y < height; y += userH)
			
			imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, x, y, userW, userH);
		}
	}

	if (mode == Center)
	{
		left = (width - imgW) / 2;
		top =  (height - imgH) / 2;
		imlib_blend_image_onto_image (buffer, 0, 0, 0, imgW, imgH, left, top, imgW, imgH);
	} 

	imlib_context_set_image (buffer);
	imlib_free_image ();

	imlib_context_set_image (rootimg);

	return 0;
}
Exemple #17
0
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;
}