hal_gfx_matrix3x3.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file hal_gfx_matrix3x3.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of Graphics library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup GRAPHICS_SDK Graphics
39 * @{
40 */
41
42 /** @addtogroup HAL_GFX HAL GFX
43 * @{
44 */
45
46 /** @defgroup HAL_GFX_MATRIX3X3 GFX MATRIX3X3
47 * @brief Base matrix3x3 Operation.
48 * @{
49 */
50
51 #ifndef HAL_GFX_MATRIX3X3_H__
52 #define HAL_GFX_MATRIX3X3_H__
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 /**
59 * @defgroup HAL_GFX_MATRIX3X3_TYPEDEF Typedefs
60 * @{
61 */
62 typedef float hal_gfx_matrix3x3_t[3][3]; /**< Global define matrix3x3 variable. */
63 /** @} */
64
65 /**
66 * @defgroup HAL_GFX_MATRIX3X3_FUNCTION Functions
67 * @{
68 */
69 /**
70 *****************************************************************************************
71 * @brief Load Identity Matrix
72 *
73 * @param[in] m: Matrix to be loaded
74 *****************************************************************************************
75 */
76 void hal_gfx_mat3x3_load_identity(hal_gfx_matrix3x3_t m);
77
78 /**
79 *****************************************************************************************
80 * @brief Apply translate transformation
81 *
82 * @param[in] m: Matrix to apply transformation
83 * @param[in] tx: X translation factor
84 * @param[in] ty: Y translation factor
85 *****************************************************************************************
86 */
87 void hal_gfx_mat3x3_translate (hal_gfx_matrix3x3_t m, float tx, float ty);
88
89 /**
90 *****************************************************************************************
91 * @brief Apply scale transformation
92 *
93 * @param[in] m: Matrix to apply transformation
94 * @param[in] sx: X scaling factor
95 * @param[in] sy: Y scaling factor
96 *****************************************************************************************
97 */
98 void hal_gfx_mat3x3_scale (hal_gfx_matrix3x3_t m, float sx, float sy);
99
100 /**
101 *****************************************************************************************
102 * @brief Apply shear transformation
103 *
104 * @param[in] m: Matrix to apply transformation
105 * @param[in] shx: X shearing factor
106 * @param[in] shy: Y shearing factor
107 *****************************************************************************************
108 */
109 void hal_gfx_mat3x3_shear (hal_gfx_matrix3x3_t m, float shx, float shy);
110
111 /**
112 *****************************************************************************************
113 * @brief Apply mirror transformation
114 *
115 * @param[in] m: Matrix to apply transformation
116 * @param[in] mx: if non-zero, mirror horizontally
117 * @param[in] my: if non-zero, mirror vertically
118 *****************************************************************************************
119 */
120 void hal_gfx_mat3x3_mirror (hal_gfx_matrix3x3_t m, int mx, int my);
121
122 /**
123 *****************************************************************************************
124 * @brief Apply rotation transformation
125 *
126 * @param[in] m: Matrix to apply transformation
127 * @param[in] angle_degrees: Angle to rotate in degrees
128 *****************************************************************************************
129 */
130 void hal_gfx_mat3x3_rotate (hal_gfx_matrix3x3_t m, float angle_degrees);
131
132 /**
133 *****************************************************************************************
134 * @brief Multiply two 3x3 matrices ( m = m*_m)
135 *
136 * @param[in] m: left matrix, will be overwritten by the result
137 * @param[in] _m: right matrix
138 *****************************************************************************************
139 */
140 void hal_gfx_mat3x3_mul(hal_gfx_matrix3x3_t m, hal_gfx_matrix3x3_t _m);
141
142 /**
143 *****************************************************************************************
144 * @brief Multiply vector with matrix
145 *
146 * @param[in] m: Matrix to multiply with
147 * @param[in] x: Vector x coefficient
148 * @param[in] y: Vector y coefficient
149 *****************************************************************************************
150 */
151 void hal_gfx_mat3x3_mul_vec(hal_gfx_matrix3x3_t m, float *x, float *y);
152
153 /**
154 *****************************************************************************************
155 * @brief Multiply vector with affine matrix
156 *
157 * @param[in] m: Matrix to multiply with
158 * @param[in] x: Vector x coefficient
159 * @param[in] y: Vector y coefficient
160 *****************************************************************************************
161 */
162 void hal_gfx_mat3x3_mul_vec_affine(hal_gfx_matrix3x3_t m, float *x, float *y);
163
164 /**
165 *****************************************************************************************
166 * @brief Calculate adjoint
167 *
168 * @param[in] m: Matrix
169 *****************************************************************************************
170 */
171 void hal_gfx_mat3x3_adj(hal_gfx_matrix3x3_t m);
172
173 /**
174 *****************************************************************************************
175 * @brief Divide matrix with scalar value
176 *
177 * @param[in] m: Matrix to divide
178 * @param[in] s: scalar value
179 *****************************************************************************************
180 */
181 void hal_gfx_mat3x3_div_scalar(hal_gfx_matrix3x3_t m, float s);
182
183 /**
184 *****************************************************************************************
185 * @brief Invert matrix
186 *
187 * @param[in] m: Matrix to invert
188 *****************************************************************************************
189 */
190 int hal_gfx_mat3x3_invert(hal_gfx_matrix3x3_t m);
191
192 /**
193 *****************************************************************************************
194 * @brief Square to quad transformation
195 *
196 * @param[in] dx0: x coordinate at the first vertex of the quadrilateral
197 * @param[in] dy0: y coordinate at the first vertex of the quadrilateral
198 * @param[in] dx1: x coordinate at the second vertex of the quadrilateral
199 * @param[in] dy1: y coordinate at the second vertex of the quadrilateral
200 * @param[in] dx2: x coordinate at the third vertex of the quadrilateral
201 * @param[in] dy2: y coordinate at the third vertex of the quadrilateral
202 * @param[in] dx3: x coordinate at the fourth vertex of the quadrilateral
203 * @param[in] dy3: y coordinate at the fourth vertex of the quadrilateral
204 * @param[in] m: Store converted matrix
205 *****************************************************************************************
206 */
207 int hal_gfx_mat3x3_square_to_quad(float dx0, float dy0,
208 float dx1, float dy1,
209 float dx2, float dy2,
210 float dx3, float dy3,
211 hal_gfx_matrix3x3_t m);
212
213 /**
214 *****************************************************************************************
215 * @brief Map rectangle to quadrilateral
216 *
217 * @param[in] width: Rectangle width
218 * @param[in] height: Rectangle height
219 * @param[in] sx0: x coordinate at the first vertex of the quadrilateral
220 * @param[in] sy0: y coordinate at the first vertex of the quadrilateral
221 * @param[in] sx1: x coordinate at the second vertex of the quadrilateral
222 * @param[in] sy1: y coordinate at the second vertex of the quadrilateral
223 * @param[in] sx2: x coordinate at the third vertex of the quadrilateral
224 * @param[in] sy2: y coordinate at the third vertex of the quadrilateral
225 * @param[in] sx3: x coordinate at the fourth vertex of the quadrilateral
226 * @param[in] sy3: y coordinate at the fourth vertex of the quadrilateral
227 * @param[in] m: Mapping matrix
228 *****************************************************************************************
229 */
230 int hal_gfx_mat3x3_quad_to_rect(int width, int height,
231 float sx0, float sy0,
232 float sx1, float sy1,
233 float sx2, float sy2,
234 float sx3, float sy3,
235 hal_gfx_matrix3x3_t m);
236 /** @} */
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif
242 /** @} */
243 /** @} */
244 /** @} */
245
hal_gfx_mat3x3_div_scalar
void hal_gfx_mat3x3_div_scalar(hal_gfx_matrix3x3_t m, float s)
Divide matrix with scalar value.
hal_gfx_mat3x3_mul_vec_affine
void hal_gfx_mat3x3_mul_vec_affine(hal_gfx_matrix3x3_t m, float *x, float *y)
Multiply vector with affine matrix.
hal_gfx_mat3x3_rotate
void hal_gfx_mat3x3_rotate(hal_gfx_matrix3x3_t m, float angle_degrees)
Apply rotation transformation.
hal_gfx_mat3x3_load_identity
void hal_gfx_mat3x3_load_identity(hal_gfx_matrix3x3_t m)
Load Identity Matrix.
hal_gfx_mat3x3_square_to_quad
int hal_gfx_mat3x3_square_to_quad(float dx0, float dy0, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3, hal_gfx_matrix3x3_t m)
Square to quad transformation.
hal_gfx_mat3x3_adj
void hal_gfx_mat3x3_adj(hal_gfx_matrix3x3_t m)
Calculate adjoint.
hal_gfx_mat3x3_mirror
void hal_gfx_mat3x3_mirror(hal_gfx_matrix3x3_t m, int mx, int my)
Apply mirror transformation.
hal_gfx_mat3x3_mul
void hal_gfx_mat3x3_mul(hal_gfx_matrix3x3_t m, hal_gfx_matrix3x3_t _m)
Multiply two 3x3 matrices ( m = m*_m)
hal_gfx_mat3x3_invert
int hal_gfx_mat3x3_invert(hal_gfx_matrix3x3_t m)
Invert matrix.
hal_gfx_mat3x3_quad_to_rect
int hal_gfx_mat3x3_quad_to_rect(int width, int height, float sx0, float sy0, float sx1, float sy1, float sx2, float sy2, float sx3, float sy3, hal_gfx_matrix3x3_t m)
Map rectangle to quadrilateral.
hal_gfx_mat3x3_translate
void hal_gfx_mat3x3_translate(hal_gfx_matrix3x3_t m, float tx, float ty)
Apply translate transformation.
hal_gfx_mat3x3_scale
void hal_gfx_mat3x3_scale(hal_gfx_matrix3x3_t m, float sx, float sy)
Apply scale transformation.
hal_gfx_matrix3x3_t
float hal_gfx_matrix3x3_t[3][3]
Global define matrix3x3 variable.
Definition: hal_gfx_matrix3x3.h:62
hal_gfx_mat3x3_mul_vec
void hal_gfx_mat3x3_mul_vec(hal_gfx_matrix3x3_t m, float *x, float *y)
Multiply vector with matrix.
hal_gfx_mat3x3_shear
void hal_gfx_mat3x3_shear(hal_gfx_matrix3x3_t m, float shx, float shy)
Apply shear transformation.