Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static inline PyObject * 
ImageObject_get_width(PyObject* self, PyObject *args)
{
    imlib_context_set_image(((ImageObject *)self)->image);
    int w = imlib_image_get_width();
    return Py_BuildValue("i", w);
}
Ejemplo n.º 4
0
void
scale_init(void)
{
	GtkWidget *nfr1, *nlbl, *vbox1;
	GtkWidget *b1;
	GtkWidget *cur_lbl;
	int scw, sch;
	char lbl[255];

	nlbl = gtk_label_new("Image Scaling");
  nfr1 = gtk_frame_new("Image Scaling");
	gtk_container_set_border_width(GTK_CONTAINER(nfr1), 3);
	gtk_notebook_insert_page(GTK_NOTEBOOK(ModMdi), nfr1, nlbl, 6);
  gtk_widget_show(nlbl);
  gtk_widget_show(nfr1);

	vbox1 = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(nfr1), vbox1);
	b1 = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox1), b1, FALSE, TRUE, 0);
	
	imlib_context_set_image(im);
	scw = imlib_image_get_width();
	sch = imlib_image_get_height();
		
	sprintf(lbl, "Current Width: %d\nCurrent Height: %d\n", scw, sch);
	cur_lbl = gtk_label_new(lbl);
	gtk_box_pack_start(GTK_BOX(vbox1), cur_lbl, FALSE, TRUE, 0);
	gtk_widget_show(cur_lbl);

	gtk_widget_show(vbox1);
	gtk_widget_show(b1);
}
Ejemplo n.º 5
0
void execp_dump_geometry(void *obj, int indent)
{
	Execp *execp = obj;

	if (execp->backend->has_icon && execp->backend->icon) {
		Imlib_Image tmp = imlib_context_get_image();
		imlib_context_set_image(execp->backend->icon);
		fprintf(stderr,
		        "%*sIcon: x = %d, y = %d, w = %d, h = %d\n",
		        indent,
		        "",
		        execp->frontend->iconx,
		        execp->frontend->icony,
		        imlib_image_get_width(),
		        imlib_image_get_height());
		if (tmp)
			imlib_context_set_image(tmp);
	}
	fprintf(stderr,
	        "%*sText: x = %d, y = %d, w = %d, align = %s, text = %s\n",
	        indent,
	        "",
	        execp->frontend->textx,
	        execp->frontend->texty,
	        execp->frontend->textw,
	        execp->backend->centered ? "center" : "left",
	        execp->backend->text);
}
Ejemplo n.º 6
0
static int get_image_width(Imlib_Image img)
{
	if (!img)
		return 0;
	imlib_context_set_image(img);
	return imlib_image_get_width();
}
Ejemplo n.º 7
0
Archivo: sdl.c Proyecto: clones/kaa
PyObject *image_to_surface(PyObject *self, PyObject *args)
{
    PyObject *pyimg;
    Imlib_Image *img;
    PySurfaceObject *pysurf;
    unsigned char *pixels;

    static int init = 0;

    CHECK_IMAGE_PYOBJECT

    if (init == 0) {
        import_pygame_surface();
        init = 1;
    }

    if (!PyArg_ParseTuple(args, "O!O!", Image_PyObject_Type, &pyimg,
                          &PySurface_Type, &pysurf))
        return NULL;

    img  = imlib_image_from_pyobject(pyimg);
    imlib_context_set_image(img);
    pixels = (unsigned char *)imlib_image_get_data_for_reading_only();
    memcpy(pysurf->surf->pixels, pixels, imlib_image_get_width() *
           imlib_image_get_height() * 4);

    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 8
0
struct R_image *
R_load_image_imlib2(struct R_app *app,
                    const char *filename,
                    struct R_image *image)
{
    Imlib_Image *img;

    if (!image) {
        image = R_alloc_image();
    }
    if (image) {
        img = imlib_load_image(filename);
        if (img) {
            imlib_context_set_image(img);
            image->app = app;
            image->filename = (char *)filename;
            image->origw = imlib_image_get_width();
            image->origh = imlib_image_get_height();
            image->orig = img;
            image->pixmap = image->mask = None;
            image->tpixmap = image->tmask = None;
            image->xpixmap = None;
#if (USE_XSHM)
            image->hasshm = 0;
#endif
        } else {
            fprintf(stderr, "failed to load: %s\n", filename);
        }
    }

    return image;
}
Ejemplo n.º 9
0
/** Draw an image in a drawable
  * \param dr Drawable
  * \param x X position
  * \param y Y position
  * \param name Path of the image
*/
static void draw_image(Drawable dr, int x, int y, int w, int h, char *name)
{
     Imlib_Image image;

     if(!name)
          return;

     imlib_set_cache_size(2048 * 1024);
     imlib_context_set_display(dpy);
     imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy)));
     imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy)));
     imlib_context_set_drawable(dr);

     image = imlib_load_image(patht(name));
     imlib_context_set_image(image);

     if(w <= 0)
          w = imlib_image_get_width();

     if(h <= 0)
          h = imlib_image_get_height();

     if(image)
     {
          imlib_render_image_on_drawable_at_size(x, y, w, h);
          imlib_free_image();
     }
     else
          warnx("Can't draw image: '%s'", name);

     return;
}
Ejemplo n.º 10
0
Archivo: imlib2.c Proyecto: rdebath/sgt
void image_to_pixmap(image *img, GdkPixmap *pm, int w, int h)
{
    int realw, realh;
    int need_free;

    imlib_context_set_image(img->image);
    realw = imlib_image_get_width();
    realh = imlib_image_get_height();
    if (w != realw || h != realh) {
	Imlib_Image newimg;

	newimg = imlib_create_cropped_scaled_image(0, 0, realw, realh, w, h);
	imlib_context_set_image(newimg);
	need_free = TRUE;
    } else
	need_free = FALSE;

    imlib_context_set_display(GDK_WINDOW_XDISPLAY(pm));
    imlib_context_set_visual(GDK_VISUAL_XVISUAL(gdk_visual_get_system()));
    imlib_context_set_colormap
	(GDK_COLORMAP_XCOLORMAP(gdk_colormap_get_system()));
    imlib_context_set_drawable(GDK_WINDOW_XWINDOW(pm));
    imlib_context_set_blend(1);
    imlib_render_image_on_drawable(0, 0);

    if (need_free)
	imlib_free_image();
}
Ejemplo n.º 11
0
/* crop image */
Imlib_Image crop(Imlib_Image *source_image, int x, int y, int w, int h)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int width, height; /* source image dimensions */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* get width and height of source image */
  imlib_context_set_image(*source_image);
  width = imlib_image_get_width();
  height = imlib_image_get_height();

  /* get sane values */
  if(x < 0) x = 0;
  if(y < 0) y = 0;
  if(x >= width) x = width - 1;
  if(y >= height) y = height - 1;
  if(x + w > width) w = width - x;
  if(y + h > height) h = height - x;

  /* create the new image */
  imlib_context_set_image(*source_image);
  new_image = imlib_create_cropped_image(x, y, w, h);

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Ejemplo n.º 12
0
/* draw a white (background) border around image, overwriting image contents
 * beneath border*/
Imlib_Image white_border(Imlib_Image *source_image, int bdwidth)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int height, width; /* image dimensions */
  int x,y; /* coordinates of upper left corner of rectangles */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* create a new image */
  imlib_context_set_image(*source_image);
  height = imlib_image_get_height();
  width = imlib_image_get_width();
  new_image = imlib_clone_image();

  /* assure border width has a legal value */
  if(bdwidth > width/2) bdwidth = width/2;
  if(bdwidth > height/2) bdwidth = height/2;

  /* draw white (background) rectangle around new image */
  for(x=0, y=0; x<bdwidth; x++, y++) {
    imlib_context_set_image(new_image);
    ssocr_set_color(BG);
    imlib_image_draw_rectangle(x, y, width-2*x, height-2*y);
  }

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Ejemplo n.º 13
0
void render_taskbar(struct task *tasks, struct desktop *desktops)
{
	tile_image(theme->tile_img, taskbar_pos, taskbar_width);
	int activedesktop = 0;
	struct desktop *iter = desktops;
	while (iter) {
		if (iter->focused)
			break;
		activedesktop++;
		iter = iter->next;
	}
	
	struct task *t = tasks;
	uint state;
	int gap = theme->taskbar.space_gap;

	while (t) {
		if (t->desktop == activedesktop || t->desktop == -1) {
			state = t->focused ? BSTATE_PRESSED : BSTATE_IDLE;
			/* draw bg */
			draw_taskbar_button(state, t->posx, t->width);
			int lgap = get_image_width(theme->taskbar.left_img[state]);
			int rgap = get_image_width(theme->taskbar.right_img[state]);
			int x = t->posx + gap + lgap;
			int w = t->width - ((gap * 2) + lgap + rgap);

			/* draw icon */
			if (theme->taskbar.icon_h && theme->taskbar.icon_w) {
				int srcw, srch;
				int y = (theme->height - theme->taskbar.icon_h) / 2;
				imlib_context_set_image(t->icon);
				srcw = imlib_image_get_width();
				srch = imlib_image_get_height();
				y += theme->taskbar.icon_offset_y;
				x += theme->taskbar.icon_offset_x;
				w -= theme->taskbar.icon_offset_x;
				imlib_context_set_image(bb);
				imlib_context_set_blend(1);
				imlib_blend_image_onto_image(t->icon, 1, 0, 0, srcw, srch,
						x, y, theme->taskbar.icon_w, theme->taskbar.icon_h);
				imlib_context_set_blend(0);
				x += theme->taskbar.icon_w;
				w -= theme->taskbar.icon_w;
			}

			/* draw text */
			imlib_context_set_cliprect(x, 0, w, bbheight);
			draw_text(theme->taskbar.font, theme->taskbar.text_align, x, w,
				theme->taskbar.text_offset_x, theme->taskbar.text_offset_y,
				t->name, &theme->taskbar.text_color[state]);
			imlib_context_set_cliprect(0, 0, bbwidth, bbheight);

			/* draw separator if exists */
			if (t->next && t->next->desktop == activedesktop)
				draw_image(theme->taskbar.separator_img, x+w+gap+rgap);
		}
		t = t->next;
	}
}
Ejemplo n.º 14
0
// Called from backend functions.
gboolean reload_icon(Execp *execp)
{
	char *icon_path = execp->backend->icon_path;

	if (execp->backend->has_icon && icon_path) {
		if (execp->backend->icon) {
			imlib_context_set_image(execp->backend->icon);
			imlib_free_image();
		}
		execp->backend->icon = load_image(icon_path, execp->backend->cache_icon);
		if (execp->backend->icon) {
			imlib_context_set_image(execp->backend->icon);
			int w = imlib_image_get_width();
			int h = imlib_image_get_height();
			if (w && h) {
				if (execp->backend->icon_w) {
					if (!execp->backend->icon_h) {
						h = (int)(0.5 + h * execp->backend->icon_w / (float)(w));
						w = execp->backend->icon_w;
					} else {
						w = execp->backend->icon_w;
						h = execp->backend->icon_h;
					}
				} else {
					if (execp->backend->icon_h) {
						w = (int)(0.5 + w * execp->backend->icon_h / (float)(h));
						h = execp->backend->icon_h;
					}
				}
				if (w < 1)
					w = 1;
				if (h < 1)
					h = 1;
			}
			if (w != imlib_image_get_width() || h != imlib_image_get_height()) {
				Imlib_Image icon_scaled =
				    imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), w, h);
				imlib_context_set_image(execp->backend->icon);
				imlib_free_image();
				execp->backend->icon = icon_scaled;
			}
			return TRUE;
		}
	}
	return FALSE;
}
Ejemplo n.º 15
0
static void img_from_im2(sequ_image *ret,Imlib_Image img)
{
  ret->lib=&im2_lib;
  ret->privdata=img;

  /* get the diameters */
  imlib_context_set_image(img);
  ret->width=imlib_image_get_width();
  ret->height=imlib_image_get_height();
}
Ejemplo n.º 16
0
int
image_load_imlib2(struct R_image *image, const char *filename)
{
    size_t len;
    Imlib_Image *img;
    Imlib_Color_Modifier colormod;
    int i;
    struct R_image loadimage;

    if (image == NULL
	|| filename == NULL) {

	return -1;
    }
    fprintf(stderr, "loading %s\n", filename);

    image_destroy_imlib2(image);
    len = strlen(filename);
    image->filename = calloc(1, len + 1);
    if (image->filename == NULL) {

	return -1;
    }
    strncpy(image->filename, filename, len);
    memset(&loadimage, 0, sizeof(loadimage));
    img = imlib_load_image(filename);
    if (img == NULL) {
	image_destroy_imlib2(image);

	return -1;
    }
    imlib_context_set_image(img);
    image->origw = imlib_image_get_width();
    image->origh = imlib_image_get_height();
    for (i = 0 ; i < IMAGE_COLOR_MODIFIERS ; i++) {
	colormod = imlib_create_color_modifier();
	if (colormod == NULL) {
	    image_destroy_imlib2(image);

	    return -1;
	}
	image->im2colormods[i] = colormod;
    }
    colormod = imlib_create_color_modifier();
    if (colormod == NULL) {
	image_destroy_imlib2(image);

	return -1;
    }
    image->im2colormods[IMAGE_COLOR_MODIFIER] = colormod;
    image->im2img = img;

    return 0;
}
Ejemplo n.º 17
0
image *loadImage(const char *filename)
{
    Imlib_Image img;
    image *result;
    int i, j;
    int width, height;


    if ((result = (image *) calloc(1, sizeof(image))) == NULL) {
	fprintf(stderr, "Herpaderp, out of memory");
	exit(1);
    }



    if ((img = imlib_load_image(filename)) == NULL) {
	return NULL;
    }



    imlib_context_set_image(img);


    width = imlib_image_get_width();
    height = imlib_image_get_height();


    result->width = width;
    result->height = height;


    result->red = newMatrix(width, height);
    result->green = newMatrix(width, height);
    result->blue = newMatrix(width, height);


    for (i = 0; i < width; i++) {
	for (j = 0; j < height; j++) {
	    Imlib_Color col;
	    imlib_image_query_pixel(i, j, &col);


	    result->red->vals[i][j] = col.red;
	    result->green->vals[i][j] = col.green;
	    result->blue->vals[i][j] = col.blue;
	}
    }

    imlib_free_image();
    return result;
}
Ejemplo n.º 18
0
int command_line(int argc, const char **argv) {
	if ( !(dpy=XOpenDisplay(0x0)) ) exit(1);
	scr = DefaultScreen(dpy); root = DefaultRootWindow(dpy);
	sw = DisplayWidth(dpy,scr); sh = DisplayHeight(dpy,scr);
	int i; const char *c;
	for (i = 1; i < argc; i++) {
		if (argv[i][0] != '-') break;
		if ( *(c=argv[i]+1) == '-' ) c++;
		if (*c == '\0') continue;
		if (*c == 'b') win = root;
	}
	if ( !(img=imlib_load_image(argv[i])) ) exit(2);;
	imlib_context_set_image(img);
	imlib_context_set_display(dpy);
	imlib_context_set_visual(DefaultVisual(dpy,scr));
	imlib_context_set_colormap(DefaultColormap(dpy,scr));
	iw = imlib_image_get_width();
	ih = imlib_image_get_height();
	imlib_context_set_anti_alias(0);
	imlib_context_set_dither(0);
	imlib_context_set_blend(0);
	XSetWindowAttributes wa;
	if (win == root) {
		Pixmap buf = XCreatePixmap(dpy,root,sw,sh,DefaultDepth(dpy,scr));
		imlib_context_set_drawable(buf);
		imlib_render_image_on_drawable_at_size(0, 0, sw, sh);
		wa.background_pixmap = buf;
		XSetWindowBackgroundPixmap(dpy,root,buf);
		XFlush(dpy);
		XFreePixmap(dpy,buf);
		XCloseDisplay(dpy);
		exit(0);
	}
	if (iw > mw) scale = mw / (float) iw;
	if (ih * scale > mh) scale = mh / (float) ih;
	ww = iw * scale + 0.5; wh = ih * scale + 0.5;
	wa.background_pixel = BlackPixel(dpy,scr);
	wa.event_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
	win = XCreateWindow(dpy,root,0,0,ww,wh,0,DefaultDepth(dpy,scr),
			InputOutput, DefaultVisual(dpy,scr),CWEventMask|CWBackPixel,&wa);
	const char *name;
	if ( (name=strrchr(argv[i],'/')) ) name++;
	else name = argv[i];
	XStoreName(dpy,win,name);
	class.res_name = (char *) argv[0];
	class.res_class = "float";
	XSetClassHint(dpy,win,&class);
	XMapWindow(dpy,win); XFlush(dpy);
	imlib_context_set_drawable(win);
	return 0;
}
Ejemplo n.º 19
0
static inline PyObject * 
ImageObject_blend_image(PyObject* self, PyObject *args, PyObject *kwargs)
{
    int merge_alpha = 1;
    PyObject *src = NULL;
    int src_x = 0, src_y = 0, src_h = -1, src_w = -1;
    int dest_x = 0, dest_y = 0, dest_h = -1, dest_w = -1;
    Imlib_Image *src_img;

	static char *keywords[] = {"img", "src", "dest", "alpha", NULL};
	
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|(iiii)(iiii)i:blend_image", keywords, &src,
                &src_x, &src_y, &src_w, &src_h,
                &dest_x, &dest_y, &dest_w, &dest_h, &merge_alpha)){
		return NULL;
    }
    DEBUG("src = %d %d %d %d ", src_x, src_y, src_w, src_h);
    DEBUG("dest = %d %d %d %d ", dest_x, dest_y, dest_w, dest_h);
    DEBUG("alpha = %d ", merge_alpha);
    
    //check
    if(!CheckImageObject(src)){
        //TODO raise TypeError
        return NULL;
    }
    

    src_img = (((ImageObject *)src)->image);
    imlib_context_set_image(src_img);
    if(src_w == -1){
        src_w = imlib_image_get_width();
    }
    if(src_h == -1){
        src_h = imlib_image_get_height();
    }
    if(dest_w == -1){
        dest_w = src_w;
    }
    if(dest_h == -1){
        dest_h = src_h;
    }
    
    
    imlib_context_set_image(((ImageObject *)self)->image);

    imlib_context_set_blend(1);
    imlib_blend_image_onto_image(src_img, merge_alpha,
                     src_x, src_y, src_w, src_h,
                     dest_x, dest_y, dest_w, dest_h);
    Py_RETURN_NONE;
}
Ejemplo n.º 20
0
/* set pixels that have at least mask pixels around it set (including the
 * examined pixel itself) to black (foreground), all other pixels to white
 * (background) */
Imlib_Image set_pixels_filter(Imlib_Image *source_image, double thresh,
                              luminance_t lt, int mask)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int height, width; /* image dimensions */
  int x,y,i,j; /* iteration variables */
  int set_pixel; /* should  pixel be set or not? */
  Imlib_Color color;
  int lum; /* luminance value of pixel */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* create a new image */
  imlib_context_set_image(*source_image);
  height = imlib_image_get_height();
  width = imlib_image_get_width();
  new_image = imlib_clone_image();

  /* check for every pixel if it should be set in filtered image */
  for(x=0; x<width; x++) {
    for(y=0; y<height; y++) {
      set_pixel=0;
      for(i=x-1; i<=x+1; i++) {
        for(j=y-1; j<=y+1; j++) {
          if(i>=0 && i<width && j>=0 && j<height) { /* i,j inside image? */
            imlib_image_query_pixel(i, j, &color);
            lum = get_lum(&color, lt);
            if(is_pixel_set(lum, thresh)) {
              set_pixel++;
            }
          }
        }
      }
      /* set pixel if at least mask pixels around it are set */
      if(set_pixel >= mask) {
        draw_fg_pixel(new_image, x, y);
      } else {
        draw_bg_pixel(new_image, x, y);
      }
    }
  }

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Ejemplo n.º 21
0
void XImlib2Image::createPicture()
{
	DesktopIconConfig * dIconConfig =
			dynamic_cast<DesktopIconConfig *>(iconConfig);
	
	image = imlib_load_image(dIconConfig->getPictureFilename().c_str());

	if (image)
	{
		imlib_context_set_image(image);

		orgWidth = imlib_image_get_width();
		orgHeight = imlib_image_get_height();

		if (width == 0)
			width = imlib_image_get_width();
		if (height == 0)
			height= imlib_image_get_height();
		
		Imlib_Image tempImg = imlib_create_cropped_scaled_image(0, 0,
				orgWidth, orgHeight, width, height);

		imlib_free_image();

		image = tempImg;
        
		hasAlpha = true; //TODO add checks here
	}    
	else
	{
		cout << "Can't load: " << dIconConfig->getPictureFilename()
				<< " bailing -- "
				<< dIconConfig->getCaption() << endl
				<< "Check to see if the image and path to image is valid\n";
	}
	
}
Ejemplo n.º 22
0
struct R_image *
image_clone_imlib2(Drawable drawable, struct R_image *image, int w, int h)
{
    struct R_image *newimage;
    Imlib_Image img, newimg;
    int imagew, imageh;
    int neww, newh;

    if (image == NULL) {

	return NULL;
    }

    newimage = NULL;
    img = image->im2img;
    if (img) {
	imlib_context_set_drawable(drawable);
	imlib_context_set_image(img);
	imagew = imlib_image_get_width();
	imageh = imlib_image_get_height();
	if (w == 0) {
	    neww = imagew;
	} else {
	    neww = w;
	}
	if (h == 0) {
	    newh = imageh;
	} else {
	    newh = h;
	}
	newimg = imlib_create_cropped_scaled_image(0, 0,
						   imagew, imageh,
						   neww, newh);
	if (newimg == NULL) {

	    return NULL;
	}
	newimage = image_alloc();
	if (newimage == NULL) {

	    return NULL;
	}
	newimage->w = neww;
	newimage->h = newh;
	newimage->im2img = newimg;
    }

    return newimage;
}
Ejemplo n.º 23
0
static inline PyObject * 
ImageObject_scaled_image(PyObject* self, PyObject *args)
{
    int x = 0, y = 0, w = 0, h = 0, dw = 0, dh = 0;
    if (!PyArg_ParseTuple(args, "ii:cropped_scaled_image", &dw, &dh)){
        return NULL;
    }
    imlib_context_set_image(((ImageObject *)self)->image);
    w = imlib_image_get_width();
    h = imlib_image_get_height();
    Imlib_Image image = imlib_create_cropped_scaled_image(x, y, w, h, dw, dh);
    if(!image){
        return NULL;
    }
    return (PyObject *)ImageObject_New(image);
}
Ejemplo n.º 24
0
/* rotate the image */
Imlib_Image rotate(Imlib_Image *source_image, double theta)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int height, width; /* image dimensions */
  int x,y; /* iteration variables / target coordinates */
  int sx,sy; /* source coordinates */
  Imlib_Color color_return; /* for imlib_query_pixel() */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* create a new image */
  imlib_context_set_image(*source_image);
  height = imlib_image_get_height();
  width = imlib_image_get_width();
  new_image = imlib_clone_image();

  /* convert theta from degrees to radians */
  theta = theta / 360 * 2.0 * M_PI;

  /* create rotated image
   * (some parts of the original image will be lost) */
  for(x = 0; x < width; x++) {
    for(y = 0; y < height; y++) {
      sx = (x-width/2) * cos(theta) + (y-height/2) * sin(theta) + width/2;
      sy = (y-height/2) * cos(theta) - (x-width/2) * sin(theta) + height/2;
      if((sx >= 0) && (sx <= width) && (sy >= 0) && (sy <= height)) {
        imlib_image_query_pixel(sx, sy, &color_return);
        imlib_context_set_image(new_image);
        imlib_context_set_color(color_return.red, color_return.green, color_return.blue, color_return.alpha);
      } else {
        imlib_context_set_image(new_image);
        ssocr_set_color(BG);
      }
      imlib_image_draw_pixel(x,y,0);
      imlib_context_set_image(*source_image);
    }
  }

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Ejemplo n.º 25
0
static int
x11_get_image_size(w3mimg_op * self, W3MImage * img, char *fname, int *w,
		   int *h)
{
    struct x11_info *xi;
#if defined(USE_IMLIB)
    ImlibImage *im;
#elif defined(USE_IMLIB2)
    Imlib_Image im;
#elif defined(USE_GDKPIXBUF)
    GdkPixbufAnimation *animation;
#endif

    if (self == NULL)
	return 0;
    xi = (struct x11_info *)self->priv;
    if (xi == NULL)
	return 0;

#if defined(USE_IMLIB)
    im = Imlib_load_image(xi->id, fname);
    if (!im)
	return 0;

    *w = im->rgb_width;
    *h = im->rgb_height;
    Imlib_kill_image(xi->id, im);
#elif defined(USE_IMLIB2)
    im = imlib_load_image(fname);
    if (im == NULL)
	return 0;

    imlib_context_set_image(im);
    *w = imlib_image_get_width();
    *h = imlib_image_get_height();
    imlib_free_image();
#elif defined(USE_GDKPIXBUF)
    animation = gdk_pixbuf_animation_new_from_file(fname);
    if (!animation)
	return 0;

    get_animation_size(animation, w, h, NULL);
    gdk_pixbuf_animation_unref(animation);
#endif
    return 1;
}
Ejemplo n.º 26
0
/* mirror image horizontally or vertically */
Imlib_Image mirror(Imlib_Image *source_image, mirror_t direction)
{
  Imlib_Image new_image; /* construct filtered image here */
  Imlib_Image current_image; /* save image pointer */
  int height, width; /* image dimensions */
  int x,y; /* iteration variables / target coordinates */
  Imlib_Color color_return; /* for imlib_query_pixel() */

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* create a new image */
  imlib_context_set_image(*source_image);
  height = imlib_image_get_height();
  width = imlib_image_get_width();
  new_image = imlib_clone_image();

  /* create mirrored image */
  if(direction == HORIZONTAL) {
    for(x = width-1; x>=0; x--) {
      for(y = 0; y < height; y++) {
	imlib_image_query_pixel(width - 1 - x, y, &color_return);
	imlib_context_set_image(new_image);
	imlib_context_set_color(color_return.red, color_return.green, color_return.blue, color_return.alpha);
	imlib_image_draw_pixel(x,y,0);
	imlib_context_set_image(*source_image);
      }
    }
  } else if(direction == VERTICAL) {
    for(x = 0; x < width; x++) {
      for(y = height-1; y >= 0; y--) {
	imlib_image_query_pixel(x, height - 1 - y, &color_return);
	imlib_context_set_image(new_image);
	imlib_context_set_color(color_return.red, color_return.green, color_return.blue, color_return.alpha);
	imlib_image_draw_pixel(x,y,0);
	imlib_context_set_image(*source_image);
      }
    }
  }

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  /* return filtered image */
  return new_image;
}
Ejemplo n.º 27
0
bool img_frame_goto(img_t *img, int n) {
	if (img == NULL || img->im == NULL)
		return false;
	if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
		return false;

	img->multi.sel = n;
	img->im = img->multi.frames[n].im;

	imlib_context_set_image(img->im);
	img->w = imlib_image_get_width();
	img->h = imlib_image_get_height();
	img->checkpan = true;
	img->dirty = true;

	return true;
}
Ejemplo n.º 28
0
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();
}
Ejemplo n.º 29
0
/* compute dynamic threshold value from the rectangle (x,y),(x+w,y+h) of
 * source_image */
double get_threshold(Imlib_Image *source_image, double fraction, luminance_t lt,
                    int x, int y, int w, int h)
{
  Imlib_Image current_image; /* save image pointer */
  int height, width; /* image dimensions */
  int xi,yi; /* iteration variables */
  Imlib_Color color;
  int lum; /* luminance of pixel */
  double minval=(double)MAXRGB, maxval=0.0;

  /* save pointer to current image */
  current_image = imlib_context_get_image();

  /* get image dimensions */
  imlib_context_set_image(*source_image);
  height = imlib_image_get_height();
  width = imlib_image_get_width();

  /* special value -1 for width or height means image width/height */
  if(w == -1) w = width;
  if(h == -1) h = width;

  /* assure valid coordinates */
  if(x+w > width) x = width-w;
  if(y+h > height) y = height-h;
  if(x<0) x=0;
  if(y<0) y=0;

  /* find the threshold value to differentiate between dark and light */
  for(xi=0; (xi<w) && (xi<width); xi++) {
    for(yi=0; (yi<h) && (yi<height); yi++) {
      imlib_image_query_pixel(x+xi, y+yi, &color);
      lum = get_lum(&color, lt);
      if(lum < minval) minval = lum;
      if(lum > maxval) maxval = lum;
    }
  }

  /* restore image from before function call */
  imlib_context_set_image(current_image);

  return (minval + fraction * (maxval - minval)) * 100 / MAXRGB;
}
Ejemplo n.º 30
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;
}