blob: 5d79faa9e79f102d9ad546bb020801b048f089e7 [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
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080025namespace android {
26namespace renderscript {
Jason Sams87fe59a2011-04-20 15:09:01 -070027
28void Matrix2x2::loadIdentity() {
29 m[0] = 1.f;
30 m[1] = 0.f;
31 m[2] = 0.f;
32 m[3] = 1.f;
33}
34
35void Matrix2x2::load(const float *v) {
36 memcpy(m, v, sizeof(m));
37}
38
39void Matrix2x2::load(const rs_matrix2x2 *v) {
40 memcpy(m, v->m, sizeof(m));
41}
42
43void Matrix2x2::loadMultiply(const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070044 // 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;
Jason Sams87fe59a2011-04-20 15:09:01 -070047 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 }
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070055 temp.set(i, 0, ri0);
56 temp.set(i, 1, ri1);
Jason Sams87fe59a2011-04-20 15:09:01 -070057 }
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070058 load(&temp);
Jason Sams87fe59a2011-04-20 15:09:01 -070059}
60
61void Matrix2x2::transpose() {
62 float temp = m[1];
63 m[1] = m[2];
64 m[2] = temp;
65}
66
Chih-Hung Hsieh11496ac2016-11-15 15:14:05 -080067} // namespace renderscript
68} // namespace android