예제 #1
0
파일: io-ras.c 프로젝트: dimkr/gdk-pixbuf
/* Shared library entry point */
GdkPixbuf *gdk_pixbuf__ras_image_load(FILE * f)
{
	guchar *membuf;
	size_t length;
	struct ras_progressive_state *State;
	
	GdkPixbuf *pb;
	
	State = gdk_pixbuf__ras_image_begin_load(NULL, NULL, NULL, NULL, NULL);
	
	membuf = g_malloc(4096);
	
	g_assert(membuf != NULL);
	
	while (feof(f) == 0) {
		length = fread(membuf, 1, 4096, f);
		(void)gdk_pixbuf__ras_image_load_increment(State, membuf, length);
	} 
	g_free(membuf);
	if (State->pixbuf != NULL)
		gdk_pixbuf_ref(State->pixbuf);

	pb = State->pixbuf;

	gdk_pixbuf__ras_image_stop_load(State);
	return pb;
}
예제 #2
0
파일: pixmaps.c 프로젝트: EQ4/samplecat
/* Scale src down to fit in max_w, max_h and return the new pixbuf.
 * If src is small enough, then ref it and return that.
 */
GdkPixbuf *scale_pixbuf(GdkPixbuf *src, int max_w, int max_h)
{
	int	w, h;

	w = gdk_pixbuf_get_width(src);
	h = gdk_pixbuf_get_height(src);

	if (w <= max_w && h <= max_h)
	{
		gdk_pixbuf_ref(src);
		return src;
	}
	else
	{
		float scale_x = ((float) w) / max_w;
		float scale_y = ((float) h) / max_h;
		float scale = MAX(scale_x, scale_y);
		int dest_w = w / scale;
		int dest_h = h / scale;
		
		return gdk_pixbuf_scale_simple(src,
						MAX(dest_w, 1),
						MAX(dest_h, 1),
						GDK_INTERP_BILINEAR);
	}
}
예제 #3
0
static GdkPixbuf*
link_get_icon (void)
{
  static GdkPixbuf *icon = NULL;

  if (icon == NULL)
    icon = gdk_pixbuf_new_from_file ("data/link.png", NULL);

  return gdk_pixbuf_ref (icon);
}
예제 #4
0
static void
progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
{
        GtkWidget** retloc = data;
        GdkPixbuf* pixbuf;

        pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
        g_assert(pixbuf != NULL);

        gdk_pixbuf_ref(pixbuf); /* for the RGB window */

        *retloc = new_testrgb_window(pixbuf, "Progressive");

        return;
}
예제 #5
0
static PyObject *Pixels_New (GdkPixbuf *pixbuf)
{
	PixelsObject *self;

	dbg();
	self = (PixelsObject *) PyObject_NEW (PixelsObject, &PixelsType);
	if (self == NULL)
		return NULL;

	self->pixbuf = pixbuf;
	self->pixels = gdk_pixbuf_get_pixels (pixbuf);
	if (self->pixels == NULL)
	{	PyErr_SetString (PyExc_Exception, "couldn't get pixels");
		return NULL;
	}

	self->length = gdk_pixbuf_get_rowstride(pixbuf) * 
		       gdk_pixbuf_get_height(pixbuf);
	gdk_pixbuf_ref (pixbuf);

	return (PyObject *) self;
}
예제 #6
0
파일: pixmaps.c 프로젝트: EQ4/samplecat
/* Scale src up to fit in max_w, max_h and return the new pixbuf.
 * If src is that size or bigger, then ref it and return that.
 */
static GdkPixbuf *scale_pixbuf_up(GdkPixbuf *src, int max_w, int max_h)
{
	int	w, h;

	w = gdk_pixbuf_get_width(src);
	h = gdk_pixbuf_get_height(src);

	if (w == 0 || h == 0 || w >= max_w || h >= max_h)
	{
		gdk_pixbuf_ref(src);
		return src;
	}
	else
	{
		float scale_x = max_w / ((float) w);
		float scale_y = max_h / ((float) h);
		float scale = MIN(scale_x, scale_y);
		
		return gdk_pixbuf_scale_simple(src,
						w * scale,
						h * scale,
						GDK_INTERP_BILINEAR);
	}
}
예제 #7
0
static void
cb_thumb_loader_done (ImageLoader * il, gpointer data)
{
    ThumbLoader *tl = data;
    GdkPixbuf *pixbuf;
    gint    pw, ph;
    gint    save;

    pixbuf = image_loader_get_pixbuf (tl->il);
    if (!pixbuf)
    {
	cb_thumb_loader_error (tl->il, tl);
	return;
    }

    pw = gdk_pixbuf_get_width (pixbuf);
    ph = gdk_pixbuf_get_height (pixbuf);

    if (tl->from_cache && pw != tl->max_w && ph != tl->max_h)
    {
	/*
	 * requested thumbnail size may have changed, load original 
	 */
	tl->from_cache = FALSE;

	image_loader_free (tl->il);
	thumb_loader_setup (tl, tl->path);

	if (!image_loader_start (tl->il, cb_thumb_loader_done, tl))
	    cb_thumb_loader_error (tl->il, tl);

	return;
    }

    gdk_pixbuf_ref (pixbuf);

    /*
     * scale ?? 
     */

    if (pw > tl->max_w || ph > tl->max_h)
    {
	gint    w, h;

	if (((float) tl->max_w / pw) < ((float) tl->max_h / ph))
	{
	    w = tl->max_w;
	    h = (float) w / pw * ph;
	    if (h < 1)
		h = 1;
	}
	else
	{
	    h = tl->max_h;
	    w = (float) h / ph * pw;
	    if (w < 1)
		w = 1;
	}

	tl->pixbuf =
	    gdk_pixbuf_scale_simple (pixbuf, w, h,
				     (GdkInterpType) conf.thumbnail_quality);
	save = TRUE;
    }
    else
    {
	tl->pixbuf = pixbuf;
	save = FALSE;
    }
    gdk_pixbuf_ref (tl->pixbuf);

    gdk_pixbuf_unref (pixbuf);

    /*
     * save it ? 
     */
    if (conf.enable_thumb_caching && save)
    {
	thumb_loader_save_to_cache (tl);
    }

    if (tl->func_done)
	tl->func_done (tl, tl->data_done);
}