• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 using namespace android;
26 using namespace android::renderscript;
27 
28 
loadIdentity()29 void Matrix2x2::loadIdentity() {
30     m[0] = 1.f;
31     m[1] = 0.f;
32     m[2] = 0.f;
33     m[3] = 1.f;
34 }
35 
load(const float * v)36 void Matrix2x2::load(const float *v) {
37     memcpy(m, v, sizeof(m));
38 }
39 
load(const rs_matrix2x2 * v)40 void Matrix2x2::load(const rs_matrix2x2 *v) {
41     memcpy(m, v->m, sizeof(m));
42 }
43 
loadMultiply(const rs_matrix2x2 * lhs,const rs_matrix2x2 * rhs)44 void Matrix2x2::loadMultiply(const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
45     for (int i=0 ; i<2 ; i++) {
46         float ri0 = 0;
47         float ri1 = 0;
48         for (int j=0 ; j<2 ; j++) {
49             const float rhs_ij = ((const Matrix2x2 *)rhs)->get(i, j);
50             ri0 += ((const Matrix2x2 *)lhs)->get(j, 0) * rhs_ij;
51             ri1 += ((const Matrix2x2 *)lhs)->get(j, 1) * rhs_ij;
52         }
53         set(i, 0, ri0);
54         set(i, 1, ri1);
55     }
56 }
57 
transpose()58 void Matrix2x2::transpose() {
59     float temp = m[1];
60     m[1] = m[2];
61     m[2] = temp;
62 }
63 
64