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 "config.h"
21 #include "art_rgb_affine.h"
22 
23 #include <math.h>
24 #include "art_misc.h"
25 #include "art_point.h"
26 #include "art_affine.h"
27 #include "art_rgb_affine_private.h"
28 
29 /* This module handles compositing of affine-transformed rgb images
30    over rgb pixel buffers. */
31 
32 /**
33  * art_rgb_affine: Affine transform source RGB image and composite.
34  * @dst: Destination image RGB buffer.
35  * @x0: Left coordinate of destination rectangle.
36  * @y0: Top coordinate of destination rectangle.
37  * @x1: Right coordinate of destination rectangle.
38  * @y1: Bottom coordinate of destination rectangle.
39  * @dst_rowstride: Rowstride of @dst buffer.
40  * @src: Source image RGB buffer.
41  * @src_width: Width of source image.
42  * @src_height: Height of source image.
43  * @src_rowstride: Rowstride of @src buffer.
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 done
55  * in a gamma-corrected color space. Since the source image is opaque RGB,
56  * this argument only affects the edges. In the current implementation,
57  * it is ignored.
58  *
59  * The @level parameter specifies the speed/quality tradeoff of the
60  * image interpolation. Currently, only ART_FILTER_NEAREST is
61  * implemented.
62  **/
63 void
art_rgb_affine(art_u8 * dst,int x0,int y0,int x1,int y1,int dst_rowstride,const art_u8 * src,int src_width,int src_height,int src_rowstride,const double affine[6],ArtFilterLevel level,ArtAlphaGamma * alphagamma)64 art_rgb_affine (art_u8 *dst, int x0, int y0, int x1, int y1, int dst_rowstride,
65 		const art_u8 *src,
66 		int src_width, int src_height, int src_rowstride,
67 		const double affine[6],
68 		ArtFilterLevel level,
69 		ArtAlphaGamma *alphagamma)
70 {
71   /* Note: this is a slow implementation, and is missing all filter
72      levels other than NEAREST. It is here for clarity of presentation
73      and to establish the interface. */
74   int x, y;
75   double inv[6];
76   art_u8 *dst_p, *dst_linestart;
77   const art_u8 *src_p;
78   ArtPoint pt, src_pt;
79   int src_x, src_y;
80   int run_x0, run_x1;
81 
82   dst_linestart = dst;
83   art_affine_invert (inv, affine);
84   for (y = y0; y < y1; y++)
85     {
86       pt.y = y + 0.5;
87       run_x0 = x0;
88       run_x1 = x1;
89       art_rgb_affine_run (&run_x0, &run_x1, y, src_width, src_height,
90 			  inv);
91       dst_p = dst_linestart + (run_x0 - x0) * 3;
92       for (x = run_x0; x < run_x1; x++)
93 	{
94 	  pt.x = x + 0.5;
95 	  art_affine_point (&src_pt, &pt, inv);
96 	  src_x = floor (src_pt.x);
97 	  src_y = floor (src_pt.y);
98 	  src_p = src + (src_y * src_rowstride) + src_x * 3;
99 	  dst_p[0] = src_p[0];
100 	  dst_p[1] = src_p[1];
101 	  dst_p[2] = src_p[2];
102 	  dst_p += 3;
103 	}
104       dst_linestart += dst_rowstride;
105     }
106 }
107