~ubuntu-branches/ubuntu/saucy/pixman/saucy-security

« back to all changes in this revision

Viewing changes to test/gradient-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2009-09-28 18:12:47 UTC
  • mfrom: (1.1.8 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090928181247-3iehog63i50htejf
Tags: 0.16.2-1
* New upstream release (closes: #546849).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
2
#include <stdlib.h>
3
 
#include <gtk/gtk.h>
4
3
#include "pixman.h"
5
 
 
6
 
GdkPixbuf *
7
 
pixbuf_from_argb32 (uint32_t *bits,
8
 
                    int width,
9
 
                    int height,
10
 
                    int stride)
11
 
{
12
 
    GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
13
 
                                        8, width, height);
14
 
    int p_stride = gdk_pixbuf_get_rowstride (pixbuf);
15
 
    guint32 *p_bits = (guint32 *)gdk_pixbuf_get_pixels (pixbuf);
16
 
    int w, h;
17
 
    
18
 
    for (h = 0; h < height; ++h)
19
 
    {
20
 
        for (w = 0; w < width; ++w)
21
 
        {
22
 
            uint32_t argb = bits[h * stride + w];
23
 
            guint32 abgr;
24
 
            
25
 
            abgr = (argb & 0xff000000) |
26
 
                (argb & 0xff) << 16 |
27
 
                (argb & 0x00ff00) |
28
 
                (argb & 0xff0000) >> 16;
29
 
            
30
 
            p_bits[h * (p_stride / 4) + w] = abgr;
31
 
        }
32
 
    }
33
 
    
34
 
    return pixbuf;
35
 
}
36
 
 
37
 
static gboolean
38
 
on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
39
 
{
40
 
    GdkPixbuf *pixbuf = data;
41
 
    
42
 
    gdk_draw_pixbuf (widget->window, NULL,
43
 
                     pixbuf, 0, 0, 0, 0,
44
 
                     gdk_pixbuf_get_width (pixbuf),
45
 
                     gdk_pixbuf_get_height (pixbuf),
46
 
                     GDK_RGB_DITHER_NONE,
47
 
                     0, 0);
48
 
    
49
 
    return TRUE;
50
 
}
51
 
 
52
 
static void
53
 
show_window (uint32_t *bits, int w, int h, int stride)
54
 
{
55
 
    GdkPixbuf *pixbuf;
56
 
    
57
 
    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
58
 
    
59
 
    pixbuf = pixbuf_from_argb32 (bits, w, h, stride);
60
 
    
61
 
    g_signal_connect (window, "expose_event", G_CALLBACK (on_expose), pixbuf);
62
 
    g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
63
 
    
64
 
    gtk_widget_show (window);
65
 
    
66
 
    gtk_main ();
67
 
}
 
4
#include "utils.h"
68
5
 
69
6
int
70
7
main (int argc, char **argv)
71
8
{
72
 
#define WIDTH 200
 
9
#define WIDTH 400
73
10
#define HEIGHT 200
74
11
    
75
12
    uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
78
15
    int i;
79
16
    pixman_gradient_stop_t stops[2] =
80
17
        {
81
 
            { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } },
82
 
            { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } }
 
18
            { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } },
 
19
            { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } }
83
20
        };
84
 
    pixman_point_fixed_t p1 = { 0, 0 };
85
 
    pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH),
86
 
                                pixman_int_to_fixed (HEIGHT) };
 
21
    pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 };
 
22
    pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH / 8.),
 
23
                                pixman_int_to_fixed (0) };
87
24
    pixman_transform_t trans = {
88
25
        { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), },
89
 
          { pixman_double_to_fixed (0), pixman_double_to_fixed (2), pixman_double_to_fixed (0), },
90
 
          { pixman_double_to_fixed (0), pixman_double_to_fixed (0.004990), pixman_double_to_fixed (1.0) } 
 
26
          { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), },
 
27
          { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } 
91
28
        }
92
29
    };
93
30
 
102
39
    pixman_fixed_t r_inner;
103
40
    pixman_fixed_t r_outer;
104
41
    
105
 
    gtk_init (&argc, &argv);
106
 
    
107
42
    for (i = 0; i < WIDTH * HEIGHT; ++i)
108
 
        dest[i] = 0x3f0000ff; /* pale blue */
 
43
        dest[i] = 0x4f00004f; /* pale blue */
109
44
    
110
45
    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
111
46
                                         WIDTH, HEIGHT, 
119
54
    r_inner = 0;
120
55
    r_outer = pixman_double_to_fixed (50.0);
121
56
    
122
 
    src_img = pixman_image_create_radial_gradient (&c_inner, &c_outer,
 
57
    src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
 
58
                                                    stops, 2);
 
59
#if 0
 
60
    src_img = pixman_image_create_conical_gradient (&c_inner, r_inner,
 
61
                                                    stops, 2);
 
62
    src_img = pixman_image_create_linear_gradient (&c_inner, &c_outer,
123
63
                                                   r_inner, r_outer,
124
64
                                                   stops, 2);
 
65
#endif
125
66
    
126
 
#if 0
127
67
    src_img = pixman_image_create_linear_gradient  (&p1, &p2,
128
68
                                                    stops, 2);
129
69
    
130
 
#endif
131
 
    pixman_image_set_transform (src_img, &trans);
 
70
    pixman_image_set_transform (src_img, &id);
 
71
    pixman_image_set_repeat (src_img, PIXMAN_REPEAT_PAD);
132
72
    
133
73
    pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img,
134
 
                            0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
 
74
                            0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT);
135
75
    
136
76
    printf ("0, 0: %x\n", dest[0]);
137
77
    printf ("10, 10: %x\n", dest[10 * 10 + 10]);
138
78
    printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]);
139
79
    
140
 
    show_window (dest, WIDTH, HEIGHT, WIDTH);
 
80
    show_image (dest_img);
141
81
    
142
82
    pixman_image_unref (src_img);
143
83
    pixman_image_unref (dest_img);