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 Matrix2x2::loadIdentity() {
29     m[0] = 1.f;
30     m[1] = 0.f;
31     m[2] = 0.f;
32     m[3] = 1.f;
33 }
34 
load(const float * v)35 void Matrix2x2::load(const float *v) {
36     memcpy(m, v, sizeof(m));
37 }
38 
load(const rs_matrix2x2 * v)39 void Matrix2x2::load(const rs_matrix2x2 *v) {
40     memcpy(m, v->m, sizeof(m));
41 }
42 
loadMultiply(const rs_matrix2x2 * lhs,const rs_matrix2x2 * rhs)43 void Matrix2x2::loadMultiply(const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
44     // Use a temporary variable to support the case where one of the inputs
45     // is also the destination, e.g. left.loadMultiply(left, right);
46     Matrix2x2 temp;
47     for (int i=0 ; i<2 ; i++) {
48         float ri0 = 0;
49         float ri1 = 0;
50         for (int j=0 ; j<2 ; j++) {
51             const float rhs_ij = ((const Matrix2x2 *)rhs)->get(i, j);
52             ri0 += ((const Matrix2x2 *)lhs)->get(j, 0) * rhs_ij;
53             ri1 += ((const Matrix2x2 *)lhs)->get(j, 1) * rhs_ij;
54         }
55         temp.set(i, 0, ri0);
56         temp.set(i, 1, ri1);
57     }
58     load(&temp);
59 }
60 
transpose()61 void Matrix2x2::transpose() {
62     float temp = m[1];
63     m[1] = m[2];
64     m[2] = temp;
65 }
66 
67 } // namespace renderscript
68 } // namespace android
69