gdiplus: Added GdipTransformMatrixPoints.
[wine] / dlls / gdiplus / matrix.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24
25 #include "gdiplus.h"
26 #include "gdiplus_private.h"
27
28 GpStatus WINGDIPAPI GdipCreateMatrix2(REAL m11, REAL m12, REAL m21, REAL m22,
29     REAL dx, REAL dy, GpMatrix **matrix)
30 {
31     if(!matrix)
32         return InvalidParameter;
33
34     *matrix = GdipAlloc(sizeof(GpMatrix));
35     if(!*matrix)    return OutOfMemory;
36
37     /* first row */
38     (*matrix)->matrix[0] = m11;
39     (*matrix)->matrix[1] = m12;
40     /* second row */
41     (*matrix)->matrix[2] = m21;
42     (*matrix)->matrix[3] = m22;
43     /* third row */
44     (*matrix)->matrix[4] = dx;
45     (*matrix)->matrix[5] = dy;
46
47     return Ok;
48 }
49
50 GpStatus WINGDIPAPI GdipDeleteMatrix(GpMatrix *matrix)
51 {
52     if(!matrix)
53         return InvalidParameter;
54
55     GdipFree(matrix);
56
57     return Ok;
58 }
59
60 GpStatus WINGDIPAPI GdipTransformMatrixPoints(GpMatrix *matrix, GpPointF *pts,
61                                               INT count)
62 {
63     REAL x, y;
64     INT i;
65
66     if(!matrix || !pts)
67         return InvalidParameter;
68
69     for(i = 0; i < count; i++)
70     {
71         x = pts[i].X;
72         y = pts[i].Y;
73
74         pts[i].X = x * matrix->matrix[0] + y * matrix->matrix[2] + matrix->matrix[4];
75         pts[i].Y = x * matrix->matrix[1] + y * matrix->matrix[3] + matrix->matrix[5];
76     }
77
78     return Ok;
79 }