1 /* TSI 2023.xmo */ 2 /******************************************************************************* 3 * Copyright (c) 2023 Think Silicon Single Member PC 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this header file and/or associated documentation files to use, copy, 7 * modify, merge, publish, distribute, sublicense, and/or sell copies of the 8 * Materials, and to permit persons to whom the Materials are furnished to do 9 * so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Materials. 13 * 14 * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 15 * NEMAGFX API. THE UNMODIFIED, NORMATIVE VERSIONS OF THINK-SILICON NEMAGFX 16 * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT: 17 * https://think-silicon.com/products/software/nemagfx-api 18 * 19 * The software is provided 'as is', without warranty of any kind, express or 20 * implied, including but not limited to the warranties of merchantability, 21 * fitness for a particular purpose and noninfringement. In no event shall 22 * Think Silicon Single Member PC be liable for any claim, damages or other 23 * liability, whether in an action of contract, tort or otherwise, arising 24 * from, out of or in connection with the software or the use or other dealings 25 * in the software. 26 ******************************************************************************/ 27 28 29 #ifndef NEMA_MATRIX3X3_H__ 30 #define NEMA_MATRIX3X3_H__ 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 typedef float nema_matrix3x3_t[3][3]; 37 38 39 /** \brief Load Identity Matrix 40 * 41 * \param m Matrix to be loaded 42 * 43 */ 44 void nema_mat3x3_load_identity(nema_matrix3x3_t m); 45 46 47 /** \brief Copy matrix _m to matrix m 48 * 49 * \param m Destination matrix 50 * \param m Source matrix 51 * 52 */ 53 void 54 nema_mat3x3_copy(nema_matrix3x3_t m, nema_matrix3x3_t _m); 55 56 /** \brief Apply translate transformation 57 * 58 * \param m Matrix to apply transformation 59 * \param tx X translation factor 60 * \param ty Y translation factor 61 * 62 */ 63 void nema_mat3x3_translate (nema_matrix3x3_t m, float tx, float ty); 64 65 /** \brief Apply scale transformation 66 * 67 * \param m Matrix to apply transformation 68 * \param sx X scaling factor 69 * \param sy Y scaling factor 70 * 71 */ 72 void nema_mat3x3_scale (nema_matrix3x3_t m, float sx, float sy); 73 74 /** \brief Apply shear transformation 75 * 76 * \param m Matrix to apply transformation 77 * \param shx X shearing factor 78 * \param shy Y shearing factor 79 * 80 */ 81 void nema_mat3x3_shear (nema_matrix3x3_t m, float shx, float shy); 82 83 /** \brief Apply mirror transformation 84 * 85 * \param m Matrix to apply transformation 86 * \param mx if non-zero, mirror horizontally 87 * \param my if non-zero, mirror vertically 88 * 89 */ 90 void nema_mat3x3_mirror (nema_matrix3x3_t m, int mx, int my); 91 92 /** \brief Apply rotation transformation 93 * 94 * \param m Matrix to apply transformation 95 * \param angle_degrees Angle to rotate in degrees 96 * 97 */ 98 void nema_mat3x3_rotate (nema_matrix3x3_t m, float angle_degrees); 99 100 /** \brief Apply rotation transformation 101 * 102 * \param m Matrix to apply transformation 103 * \param cosa Cos of angle to rotate 104 * \param sina Sin of angle to rotate 105 * 106 */ 107 void 108 nema_mat3x3_rotate2(nema_matrix3x3_t m, float cosa, float sina); 109 110 111 /** \brief Multiply two 3x3 matrices ( m = m*_m) 112 * 113 * \param m left matrix, will be overwritten by the result 114 * \param _m right matrix 115 * 116 */ 117 void nema_mat3x3_mul(nema_matrix3x3_t m, nema_matrix3x3_t _m); 118 119 /** \brief Multiply vector with matrix 120 * 121 * \param m Matrix to multiply with 122 * \param x Vector x coefficient 123 * \param y Vector y coefficient 124 * 125 */ 126 void nema_mat3x3_mul_vec(nema_matrix3x3_t m, float *x, float *y); 127 128 /** \brief Multiply vector with affine matrix 129 * 130 * \param m Matrix to multiply with 131 * \param x Vector x coefficient 132 * \param y Vector y coefficient 133 * 134 */ 135 void nema_mat3x3_mul_vec_affine(nema_matrix3x3_t m, float *x, float *y); 136 137 /** \brief Calculate adjoint 138 * 139 * \param m Matrix 140 * 141 */ 142 void nema_mat3x3_adj(nema_matrix3x3_t m); 143 144 145 /** \brief Divide matrix with scalar value 146 * 147 * \param m Matrix to divide 148 * \param s scalar value 149 * 150 */ 151 void nema_mat3x3_div_scalar(nema_matrix3x3_t m, float s); 152 153 /** \brief Invert matrix 154 * 155 * \param m Matrix to invert 156 * 157 */ 158 int nema_mat3x3_invert(nema_matrix3x3_t m); 159 160 /** \private */ 161 int nema_mat3x3_square_to_quad(float dx0, float dy0, 162 float dx1, float dy1, 163 float dx2, float dy2, 164 float dx3, float dy3, 165 nema_matrix3x3_t m); 166 167 /** \brief Map rectangle to quadrilateral 168 * 169 * \param width Rectangle width 170 * \param height Rectangle height 171 * \param sx0 x coordinate at the first vertex of the quadrilateral 172 * \param sy0 y coordinate at the first vertex of the quadrilateral 173 * \param sx1 x coordinate at the second vertex of the quadrilateral 174 * \param sy1 y coordinate at the second vertex of the quadrilateral 175 * \param sx2 x coordinate at the third vertex of the quadrilateral 176 * \param sy2 y coordinate at the third vertex of the quadrilateral 177 * \param sx3 x coordinate at the fourth vertex of the quadrilateral 178 * \param sy3 y coordinate at the fourth vertex of the quadrilateral 179 * \param m Mapping matrix 180 * 181 */ 182 int nema_mat3x3_quad_to_rect(int width, int height, 183 float sx0, float sy0, 184 float sx1, float sy1, 185 float sx2, float sy2, 186 float sx3, float sy3, 187 nema_matrix3x3_t m); 188 189 /** \brief Apply rotation around a pivot point 190 * 191 * \param m Matrix to apply transformation 192 * \param angle_degrees Angle to rotate in degrees 193 * \param x X coordinate of the pivot point 194 * \param y Y coordinate of the pivot point 195 * 196 */ 197 void nema_mat3x3_rotate_pivot(nema_matrix3x3_t m, float angle_degrees, 198 float x, float y); 199 200 /** \brief Apply scale and then rotation around a pivot point 201 * 202 * \param m Matrix to apply transformation 203 * \param sx X scaling factor 204 * \param sy Y scaling factor 205 * \param angle_degrees Angle to rotate in degrees 206 * \param x X coordinate of the pivot point 207 * \param y Y coordinate of the pivot point 208 * 209 */ 210 void nema_mat3x3_scale_rotate_pivot(nema_matrix3x3_t m, 211 float sx, float sy, 212 float angle_degrees, float x, float y); 213 214 215 /** \brief Copy matrix _m to matrix m 216 * 217 * \param m Destination matrix 218 * \param m Source matrix 219 * 220 */ 221 222 void 223 nema_mat3x3_copy(nema_matrix3x3_t m, nema_matrix3x3_t _m); 224 225 226 #ifdef __cplusplus 227 } 228 #endif 229 230 #endif 231