The BIG graph update
[rrdtool.git] / libraries / libart_lgpl-2.3.7 / art_rgb_pixbuf_affine.c
1 /* Libart_LGPL - library of basic graphic primitives
2  * Copyright (C) 1998 Raph Levien
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <math.h>
21 #include "art_misc.h"
22 #include "art_point.h"
23 #include "art_affine.h"
24 #include "art_pixbuf.h"
25 #include "art_rgb_affine.h"
26 #include "art_rgb_affine.h"
27 #include "art_rgb_rgba_affine.h"
28 #include "art_rgb_pixbuf_affine.h"
29
30 /* This module handles compositing of affine-transformed generic
31    pixbuf images over rgb pixel buffers. */
32
33 /* Composite the source image over the destination image, applying the
34    affine transform. */
35 /**
36  * art_rgb_pixbuf_affine: Affine transform source RGB pixbuf and composite.
37  * @dst: Destination image RGB buffer.
38  * @x0: Left coordinate of destination rectangle.
39  * @y0: Top coordinate of destination rectangle.
40  * @x1: Right coordinate of destination rectangle.
41  * @y1: Bottom coordinate of destination rectangle.
42  * @dst_rowstride: Rowstride of @dst buffer.
43  * @pixbuf: source image pixbuf.
44  * @affine: Affine transform.
45  * @level: Filter level.
46  * @alphagamma: #ArtAlphaGamma for gamma-correcting the compositing.
47  *
48  * Affine transform the source image stored in @src, compositing over
49  * the area of destination image @dst specified by the rectangle
50  * (@x0, @y0) - (@x1, @y1). As usual in libart, the left and top edges
51  * of this rectangle are included, and the right and bottom edges are
52  * excluded.
53  *
54  * The @alphagamma parameter specifies that the alpha compositing be
55  * done in a gamma-corrected color space. In the current
56  * implementation, it is ignored.
57  *
58  * The @level parameter specifies the speed/quality tradeoff of the
59  * image interpolation. Currently, only ART_FILTER_NEAREST is
60  * implemented.
61  **/
62 void
63 art_rgb_pixbuf_affine (art_u8 *dst,
64                        int x0, int y0, int x1, int y1, int dst_rowstride,
65                        const ArtPixBuf *pixbuf,
66                        const double affine[6],
67                        ArtFilterLevel level,
68                        ArtAlphaGamma *alphagamma)
69 {
70   if (pixbuf->format != ART_PIX_RGB)
71     {
72       art_warn ("art_rgb_pixbuf_affine: need RGB format image\n");
73       return;
74     }
75
76   if (pixbuf->bits_per_sample != 8)
77     {
78       art_warn ("art_rgb_pixbuf_affine: need 8-bit sample data\n");
79       return;
80     }
81
82   if (pixbuf->n_channels != 3 + (pixbuf->has_alpha != 0))
83     {
84       art_warn ("art_rgb_pixbuf_affine: need 8-bit sample data\n");
85       return;
86     }
87
88   if (pixbuf->has_alpha)
89     art_rgb_rgba_affine (dst, x0, y0, x1, y1, dst_rowstride,
90                          pixbuf->pixels,
91                          pixbuf->width, pixbuf->height, pixbuf->rowstride,
92                          affine,
93                          level,
94                          alphagamma);
95   else
96     art_rgb_affine (dst, x0, y0, x1, y1, dst_rowstride,
97                     pixbuf->pixels,
98                     pixbuf->width, pixbuf->height, pixbuf->rowstride,
99                     affine,
100                     level,
101                     alphagamma);
102 }