rsMatrix2x2.cpp revision 1bb2eed69caa28cf8198d58db7d9134cc2f563f5
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
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) {
45    // 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;
48    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        }
56        temp.set(i, 0, ri0);
57        temp.set(i, 1, ri1);
58    }
59    load(&temp);
60}
61
62void Matrix2x2::transpose() {
63    float temp = m[1];
64    m[1] = m[2];
65    m[2] = temp;
66}
67
68