blob: 91accbee09083c097269e74f90f5268f8a980271 [file] [log] [blame]
Jason Sams87fe59a2011-04-20 15:09:01 -07001/*
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
25using namespace android;
26using namespace android::renderscript;
27
28
29void Matrix2x2::loadIdentity() {
30 m[0] = 1.f;
31 m[1] = 0.f;
32 m[2] = 0.f;
33 m[3] = 1.f;
34}
35
36void Matrix2x2::load(const float *v) {
37 memcpy(m, v, sizeof(m));
38}
39
40void Matrix2x2::load(const rs_matrix2x2 *v) {
41 memcpy(m, v->m, sizeof(m));
42}
43
44void Matrix2x2::loadMultiply(const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070045 // Use a temporary variable to support the case where one of the inputs
46 // is also the destination, e.g. left.loadMultiply(left, right);
47 Matrix2x2 temp;
Jason Sams87fe59a2011-04-20 15:09:01 -070048 for (int i=0 ; i<2 ; i++) {
49 float ri0 = 0;
50 float ri1 = 0;
51 for (int j=0 ; j<2 ; j++) {
52 const float rhs_ij = ((const Matrix2x2 *)rhs)->get(i, j);
53 ri0 += ((const Matrix2x2 *)lhs)->get(j, 0) * rhs_ij;
54 ri1 += ((const Matrix2x2 *)lhs)->get(j, 1) * rhs_ij;
55 }
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070056 temp.set(i, 0, ri0);
57 temp.set(i, 1, ri1);
Jason Sams87fe59a2011-04-20 15:09:01 -070058 }
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070059 load(&temp);
Jason Sams87fe59a2011-04-20 15:09:01 -070060}
61
62void Matrix2x2::transpose() {
63 float temp = m[1];
64 m[1] = m[2];
65 m[2] = temp;
66}
67