aboutsummaryrefslogtreecommitdiffstats
path: root/packages/gtk+/pixops-test/pixops-test.c
blob: f8906dfc420f376317c3233a6c0fd2953f0f205d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdlib.h>

static gdouble total_seconds = 0.0;

/* randomly colour each pixel */
static void
fill_pixbuf (GdkPixbuf *buf)
{
	int width, height, rowstride, n_channels;
	int x,y,n;
	guchar *pixels, *p;

	g_assert (gdk_pixbuf_get_bits_per_sample (buf) == 8);

	n_channels = gdk_pixbuf_get_n_channels (buf);
	width = gdk_pixbuf_get_width (buf);
	height = gdk_pixbuf_get_height (buf);
	rowstride = gdk_pixbuf_get_rowstride (buf);
	pixels = gdk_pixbuf_get_pixels (buf);

	for (x=0; x<width; x++) {
		for (y=0; y<height; y++) {
			p = pixels + (y*rowstride) + (x*n_channels);
			for (n=0; n<n_channels; n++) {
				p[n] = (random()*255)/RAND_MAX;
			}
		}
	}
}

int
main (int argc, char **argv)
{
        GTimer *timer;
	int i,j;

        gtk_init (&argc, &argv);


	GdkPixbuf *pixbuf[4], *ret;
	pixbuf[0] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 400, 600);
	pixbuf[1] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 40, 60);
	pixbuf[2] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 400, 600);
	pixbuf[3] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 40, 60);

	for (j=0; j<4; j++)
		fill_pixbuf (pixbuf[j]);

	timer = g_timer_new ();
	g_timer_start (timer);

	for (i = 0; i < 10 ; i++) {
		for (j=0; j<4; j++) {
			ret = gdk_pixbuf_scale_simple (pixbuf[j], 700, 900, GDK_INTERP_BILINEAR);
			gdk_pixbuf_unref (ret);
			ret = gdk_pixbuf_scale_simple (pixbuf[j], 20, 50, GDK_INTERP_BILINEAR);
			gdk_pixbuf_unref (ret);
		}
	}
	g_timer_stop (timer);

	total_seconds += g_timer_elapsed (timer, NULL);
        
        g_print ("time spent scaling (in seconds): %lf\n",  total_seconds );

        return 0;
}