1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "rsMatrix2x2.h"
18 #include "rsMatrix3x3.h"
19 #include "rsMatrix4x4.h"
20
21 #include "stdlib.h"
22 #include "string.h"
23 #include "math.h"
24
25 namespace android {
26 namespace renderscript {
27
loadIdentity()28 void Matrix3x3::loadIdentity() {
29 m[0] = 1.f;
30 m[1] = 0.f;
31 m[2] = 0.f;
32 m[3] = 0.f;
33 m[4] = 1.f;
34 m[5] = 0.f;
35 m[6] = 0.f;
36 m[7] = 0.f;
37 m[8] = 1.f;
38 }
39
load(const float * v)40 void Matrix3x3::load(const float *v) {
41 memcpy(m, v, sizeof(m));
42 }
43
load(const rs_matrix3x3 * v)44 void Matrix3x3::load(const rs_matrix3x3 *v) {
45 memcpy(m, v->m, sizeof(m));
46 }
47
loadMultiply(const rs_matrix3x3 * lhs,const rs_matrix3x3 * rhs)48 void Matrix3x3::loadMultiply(const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
49 // Use a temporary variable to support the case where one of the inputs
50 // is also the destination, e.g. left.loadMultiply(left, right);
51 Matrix3x3 temp;
52 for (int i=0 ; i<3 ; i++) {
53 float ri0 = 0;
54 float ri1 = 0;
55 float ri2 = 0;
56 for (int j=0 ; j<3 ; j++) {
57 const float rhs_ij = ((const Matrix3x3 *)rhs)->get(i, j);
58 ri0 += ((const Matrix3x3 *)lhs)->get(j, 0) * rhs_ij;
59 ri1 += ((const Matrix3x3 *)lhs)->get(j, 1) * rhs_ij;
60 ri2 += ((const Matrix3x3 *)lhs)->get(j, 2) * rhs_ij;
61 }
62 temp.set(i, 0, ri0);
63 temp.set(i, 1, ri1);
64 temp.set(i, 2, ri2);
65 }
66 load(&temp);
67 }
68
transpose()69 void Matrix3x3::transpose() {
70 int i, j;
71 float temp;
72 for (i = 0; i < 2; ++i) {
73 for (j = i + 1; j < 3; ++j) {
74 temp = get(i, j);
75 set(i, j, get(j, i));
76 set(j, i, temp);
77 }
78 }
79 }
80
81 } // namespace renderscript
82 } // namespace android
83