コード例 #1
0
/* Returns a copy of pixbuf scaled down, preserving aspect ratio, to fit
 * within the specified width and height. If it already fits, a copy of
 * the original, without scaling, is returned.
 */
GdkPixbuf *
eel_gdk_pixbuf_scale_down_to_fit (GdkPixbuf *pixbuf, int max_width, int max_height)
{
	int scaled_width;
	int scaled_height;
	
	double scale_factor;

	scale_factor = eel_gdk_scale_to_fit_factor (gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf),
						    max_width, max_height,
						    &scaled_width, &scaled_height);

	if (scale_factor >= 1.0) {
		return gdk_pixbuf_copy (pixbuf);
	} else {				
		return eel_gdk_pixbuf_scale_down (pixbuf, scaled_width, scaled_height);	
	}
}
コード例 #2
0
int 
main (int argc, char* argv[])
{
	GdkPixbuf *pixbuf, *scaled;
	GError *error;
	struct timeval t1, t2;
	int i;
	
	test_init (&argc, &argv);

	if (argc != 2) {
		printf ("Usage: test <image filename>\n");
		exit (1);
	}

	error = NULL;
	pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);

	if (pixbuf == NULL) {
		printf ("error loading pixbuf: %s\n", error->message);
		exit (1);
	}
	
	printf ("scale factors: %f, %f\n",
		(double)gdk_pixbuf_get_width(pixbuf)/DEST_WIDTH,
		(double)gdk_pixbuf_get_height(pixbuf)/DEST_HEIGHT);
	
	gettimeofday(&t1, NULL);
	for (i = 0; i < N_SCALES; i++) {
		scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT);
		g_object_unref (scaled);
	}
	gettimeofday(&t2, NULL);
	g_print ("Time for eel_gdk_pixbuf_scale_down: %ld msecs\n",
		 (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);
	
		
	
	gettimeofday(&t1, NULL);
	for (i = 0; i < N_SCALES; i++) {
		scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_NEAREST);
		g_object_unref (scaled);
	}
	gettimeofday(&t2, NULL);
	g_print ("Time for INTERP_NEAREST: %ld msecs\n",
		 (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);

	
	gettimeofday(&t1, NULL);
	for (i = 0; i < N_SCALES; i++) {
		scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_BILINEAR);
		g_object_unref (scaled);
	}
	gettimeofday(&t2, NULL);
	g_print ("Time for INTERP_BILINEAR: %ld msecs\n",
		 (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);
	
	scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT);
	gdk_pixbuf_save (scaled, "eel_scaled.png", "png", NULL, NULL); 
	g_object_unref (scaled);

	scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_NEAREST);
	gdk_pixbuf_save (scaled, "nearest_scaled.png", "png", NULL, NULL); 
	g_object_unref (scaled);

	scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_BILINEAR);
	gdk_pixbuf_save (scaled, "bilinear_scaled.png", "png", NULL, NULL); 
	g_object_unref (scaled);

	return 0;
}