2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
26 #include "gdiplus_private.h"
28 /* Multiplies two matrices of the form
34 * and puts the output in out.
36 static void matrix_multiply(GDIPCONST REAL * left, GDIPCONST REAL * right, REAL * out)
41 for(i = 0; i < 6; i++){
43 temp[i] = left[i - odd] * right[odd] + left[i - odd + 1] * right[odd + 2] +
44 (i >= 4 ? right[odd + 4] : 0.0);
47 memcpy(out, temp, 6 * sizeof(REAL));
50 GpStatus WINGDIPAPI GdipCreateMatrix2(REAL m11, REAL m12, REAL m21, REAL m22,
51 REAL dx, REAL dy, GpMatrix **matrix)
54 return InvalidParameter;
56 *matrix = GdipAlloc(sizeof(GpMatrix));
57 if(!*matrix) return OutOfMemory;
60 (*matrix)->matrix[0] = m11;
61 (*matrix)->matrix[1] = m12;
63 (*matrix)->matrix[2] = m21;
64 (*matrix)->matrix[3] = m22;
66 (*matrix)->matrix[4] = dx;
67 (*matrix)->matrix[5] = dy;
72 GpStatus WINGDIPAPI GdipDeleteMatrix(GpMatrix *matrix)
75 return InvalidParameter;
82 GpStatus WINGDIPAPI GdipMultiplyMatrix(GpMatrix *matrix, GpMatrix* matrix2,
85 if(!matrix || !matrix2)
86 return InvalidParameter;
88 if(order == MatrixOrderAppend)
89 matrix_multiply(matrix->matrix, matrix2->matrix, matrix->matrix);
91 matrix_multiply(matrix2->matrix, matrix->matrix, matrix->matrix);
96 GpStatus WINGDIPAPI GdipScaleMatrix(GpMatrix *matrix, REAL scaleX, REAL scaleY,
102 return InvalidParameter;
111 if(order == MatrixOrderAppend)
112 matrix_multiply(matrix->matrix, scale, matrix->matrix);
114 matrix_multiply(scale, matrix->matrix, matrix->matrix);
119 GpStatus WINGDIPAPI GdipTransformMatrixPoints(GpMatrix *matrix, GpPointF *pts,
126 return InvalidParameter;
128 for(i = 0; i < count; i++)
133 pts[i].X = x * matrix->matrix[0] + y * matrix->matrix[2] + matrix->matrix[4];
134 pts[i].Y = x * matrix->matrix[1] + y * matrix->matrix[3] + matrix->matrix[5];
140 GpStatus WINGDIPAPI GdipTranslateMatrix(GpMatrix *matrix, REAL offsetX,
141 REAL offsetY, GpMatrixOrder order)
146 return InvalidParameter;
152 translate[4] = offsetX;
153 translate[5] = offsetY;
155 if(order == MatrixOrderAppend)
156 matrix_multiply(matrix->matrix, translate, matrix->matrix);
158 matrix_multiply(translate, matrix->matrix, matrix->matrix);