]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-xform.c
Fix typo (s/expansive/expensive) (#389183)
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-xform.c
1 /* FIXME FIXME FIXME
2  *
3  * This file is not being used.  The gdk_pixbuf_scale() here is not useful
4  * anymore, since we have the new functions in gdk-pixbuf-scale.c.
5  *
6  * The rotation function needs to be implemented without libart if it is
7  * to go inside the GdkPixbuf library.
8  */
9
10 GdkPixbuf *
11 gdk_pixbuf_scale (const GdkPixbuf *pixbuf, gint w, gint h)
12 {
13         guchar *pixels;
14         gint rowstride;
15         double affine[6];
16         ArtAlphaGamma *alphagamma;
17         ArtPixBuf *art_pixbuf = NULL;
18         GdkPixbuf *copy = NULL;
19
20         alphagamma = NULL;
21
22         affine[1] = affine[2] = affine[4] = affine[5] = 0;
23
24         affine[0] = w / (double)(pixbuf->width);
25         affine[3] = h / (double)(pixbuf->height);
26
27         /* rowstride = w * pixbuf->n_channels; */
28         rowstride = w * 3;
29
30         pixels = art_alloc (h * rowstride);
31         art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
32                                pixbuf->art_pixbuf,
33                                affine, ART_FILTER_NEAREST, alphagamma);
34
35         if (pixbuf->art_pixbuf->has_alpha)
36                 /* should be rgba */
37                 art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
38         else
39                 art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
40
41         copy = gdk_pixbuf_new (art_pixbuf, NULL);
42
43         if (!copy)
44                 art_free (pixels);
45
46         return copy;
47 }
48
49 GdkPixbuf *
50 gdk_pixbuf_rotate (GdkPixbuf *pixbuf, gdouble angle)
51 {
52         art_u8 *pixels;
53         gint rowstride, w, h;
54         gdouble rad;
55         double rot[6], trans[6], affine[6];
56         ArtAlphaGamma *alphagamma = NULL;
57         ArtPixBuf *art_pixbuf = NULL;
58
59         w = pixbuf->art_pixbuf->width;
60         h = pixbuf->art_pixbuf->height;
61
62         rad = (M_PI * angle / 180.0);
63
64         rot[0] = cos(rad);
65         rot[1] = sin(rad);
66         rot[2] = -sin(rad);
67         rot[3] = cos(rad);
68         rot[4] = rot[5] = 0;
69
70         trans[0] = trans[3] = 1;
71         trans[1] = trans[2] = 0;
72         trans[4] = -(double)w / 2.0;
73         trans[5] = -(double)h / 2.0;
74
75         art_affine_multiply(rot, trans, rot);
76
77         trans[0] = trans[3] = 1;
78         trans[1] = trans[2] = 0;
79         trans[4] = (double)w / 2.0;
80         trans[5] = (double)h / 2.0;
81
82         art_affine_multiply(affine, rot, trans);
83 /*
84         g_print("Affine: %e %e %e %e %e %e\n", affine[0], affine[1], affine[2],
85                 affine[3], affine[4], affine[5]);
86 */
87         /* rowstride = w * pixbuf->art_pixbuf->n_channels; */
88         rowstride = w * 3;
89
90         pixels = art_alloc (h * rowstride);
91         art_rgb_pixbuf_affine (pixels, 0, 0, w, h, rowstride,
92                                pixbuf->art_pixbuf,
93                                affine, ART_FILTER_NEAREST, alphagamma);
94         if (pixbuf->art_pixbuf->has_alpha)
95                 /* should be rgba */
96                 art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
97         else
98                 art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, rowstride);
99
100         art_pixbuf_free (pixbuf->art_pixbuf);
101         pixbuf->art_pixbuf = art_pixbuf;
102
103         return pixbuf;
104 }