eel r2155 - in trunk: . eel



Author: cneumair
Date: Mon Sep  1 10:01:09 2008
New Revision: 2155
URL: http://svn.gnome.org/viewvc/eel?rev=2155&view=rev

Log:
2008-09-01  Christian Neumair  <cneumair gnome org>

	* eel/eel-gdk-pixbuf-extensions.c
	(eel_gdk_pixbuf_load_from_stream), (pixbuf_loader_size_prepared),
	(eel_gdk_pixbuf_load_from_stream_at_size):
	* eel/eel-gdk-pixbuf-extensions.h:
	Add eel_gdk_pixbuf_load_from_stream_at_size(), which sets the size of
	the pixbuf loader when loading. Part of #529371.


Modified:
   trunk/ChangeLog
   trunk/eel/eel-gdk-pixbuf-extensions.c
   trunk/eel/eel-gdk-pixbuf-extensions.h

Modified: trunk/eel/eel-gdk-pixbuf-extensions.c
==============================================================================
--- trunk/eel/eel-gdk-pixbuf-extensions.c	(original)
+++ trunk/eel/eel-gdk-pixbuf-extensions.c	Mon Sep  1 10:01:09 2008
@@ -107,6 +107,33 @@
 GdkPixbuf *
 eel_gdk_pixbuf_load_from_stream (GInputStream  *stream)
 {
+	return eel_gdk_pixbuf_load_from_stream_at_size (stream, -1);
+}
+
+static void
+pixbuf_loader_size_prepared (GdkPixbufLoader *loader,
+			     int              width,
+			     int              height,
+			     gpointer         desired_size_ptr)
+{
+	int size, desired_size;
+	float scale;
+
+	size = MAX (width, height);
+	desired_size = GPOINTER_TO_INT (desired_size_ptr);
+
+	if (size != desired_size) {
+		scale = desired_size / size;
+		gdk_pixbuf_loader_set_size (loader,
+					    floor (scale * width + 0.5),
+					    floor (scale * height + 0.5));
+	}
+}
+
+GdkPixbuf *
+eel_gdk_pixbuf_load_from_stream_at_size (GInputStream  *stream,
+					 int            size)
+{
 	char buffer[LOAD_BUFFER_SIZE];
 	gssize bytes_read;
 	GdkPixbufLoader *loader;
@@ -118,6 +145,13 @@
 
 	got_eos = FALSE;
 	loader = gdk_pixbuf_loader_new ();
+
+	if (size > 0) {
+		g_signal_connect (loader, "size-prepared",
+				  G_CALLBACK (pixbuf_loader_size_prepared),
+				  GINT_TO_POINTER (size));
+	}
+
 	while (1) {
 		bytes_read = g_input_stream_read (stream, buffer, sizeof (buffer),
 						  NULL, NULL);

Modified: trunk/eel/eel-gdk-pixbuf-extensions.h
==============================================================================
--- trunk/eel/eel-gdk-pixbuf-extensions.h	(original)
+++ trunk/eel/eel-gdk-pixbuf-extensions.h	Mon Sep  1 10:01:09 2008
@@ -52,6 +52,8 @@
 /* Loading a GdkPixbuf with a URI. */
 GdkPixbuf *          eel_gdk_pixbuf_load                      (const char            *uri);
 GdkPixbuf *          eel_gdk_pixbuf_load_from_stream          (GInputStream          *stream);
+GdkPixbuf *          eel_gdk_pixbuf_load_from_stream_at_size  (GInputStream          *stream,
+							       int                    size);
 
 
 /* Same thing async. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]