rsMatrix2x2.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "rsMatrix2x2.h"
  17. #include "rsMatrix3x3.h"
  18. #include "rsMatrix4x4.h"
  19. #include "stdlib.h"
  20. #include "string.h"
  21. #include "math.h"
  22. namespace android {
  23. namespace renderscript {
  24. void Matrix2x2::loadIdentity() {
  25. m[0] = 1.f;
  26. m[1] = 0.f;
  27. m[2] = 0.f;
  28. m[3] = 1.f;
  29. }
  30. void Matrix2x2::load(const float *v) {
  31. memcpy(m, v, sizeof(m));
  32. }
  33. void Matrix2x2::load(const rs_matrix2x2 *v) {
  34. memcpy(m, v->m, sizeof(m));
  35. }
  36. void Matrix2x2::loadMultiply(const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
  37. // Use a temporary variable to support the case where one of the inputs
  38. // is also the destination, e.g. left.loadMultiply(left, right);
  39. Matrix2x2 temp;
  40. for (int i=0 ; i<2 ; i++) {
  41. float ri0 = 0;
  42. float ri1 = 0;
  43. for (int j=0 ; j<2 ; j++) {
  44. const float rhs_ij = ((const Matrix2x2 *)rhs)->get(i, j);
  45. ri0 += ((const Matrix2x2 *)lhs)->get(j, 0) * rhs_ij;
  46. ri1 += ((const Matrix2x2 *)lhs)->get(j, 1) * rhs_ij;
  47. }
  48. temp.set(i, 0, ri0);
  49. temp.set(i, 1, ri1);
  50. }
  51. load(&temp);
  52. }
  53. void Matrix2x2::transpose() {
  54. float temp = m[1];
  55. m[1] = m[2];
  56. m[2] = temp;
  57. }
  58. } // namespace renderscript
  59. } // namespace android