rsAnimation.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2009 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 "rsContext.h"
  17. #include "rsAnimation.h"
  18. namespace android {
  19. namespace renderscript {
  20. void Animation::serialize(Context *rsc, OStream *stream) const {
  21. }
  22. Animation *Animation::createFromStream(Context *rsc, IStream *stream) {
  23. return nullptr;
  24. }
  25. /*
  26. Animation::Animation(Context *rsc) : ObjectBase(rsc)
  27. {
  28. mAllocFile = __FILE__;
  29. mAllocLine = __LINE__;
  30. mValuesInput = nullptr;
  31. mValuesOutput = nullptr;
  32. mValueCount = 0;
  33. mInterpolation = RS_ANIMATION_INTERPOLATION_STEP;
  34. mEdgePre = RS_ANIMATION_EDGE_UNDEFINED;
  35. mEdgePost = RS_ANIMATION_EDGE_UNDEFINED;
  36. mInputMin = 0;
  37. mInputMax = 0;
  38. }
  39. Animation * Animation::create(Context *rsc,
  40. const float *inValues, const float *outValues,
  41. uint32_t valueCount, RsAnimationInterpolation interp,
  42. RsAnimationEdge pre, RsAnimationEdge post)
  43. {
  44. if (valueCount < 2) {
  45. rsc->setError(RS_ERROR_BAD_VALUE, "Animations require more than 2 values.");
  46. return nullptr;
  47. }
  48. Animation *a = new Animation(rsc);
  49. if (!a) {
  50. rsc->setError(RS_ERROR_OUT_OF_MEMORY);
  51. return nullptr;
  52. }
  53. float *vin = (float *)malloc(valueCount * sizeof(float));
  54. float *vout = (float *)malloc(valueCount * sizeof(float));
  55. a->mValuesInput = vin;
  56. a->mValuesOutput = vout;
  57. if (a->mValuesInput == nullptr || a->mValuesOutput == nullptr) {
  58. delete a;
  59. rsc->setError(RS_ERROR_OUT_OF_MEMORY);
  60. return nullptr;
  61. }
  62. a->mEdgePre = pre;
  63. a->mEdgePost = post;
  64. a->mInterpolation = interp;
  65. a->mValueCount = valueCount;
  66. memcpy(vin, inValues, valueCount * sizeof(float));
  67. memcpy(vout, outValues, valueCount * sizeof(float));
  68. a->mInputMin = inValues[0];
  69. a->mInputMax = inValues[0];
  70. bool needSort = false;
  71. for (uint32_t ct=1; ct < valueCount; ct++) {
  72. if (a->mInputMin > vin[ct]) {
  73. needSort = true;
  74. a->mInputMin = vin[ct];
  75. }
  76. if (a->mInputMax < vin[ct]) {
  77. a->mInputMax = vin[ct];
  78. } else {
  79. needSort = true;
  80. }
  81. }
  82. while (1) {
  83. bool changed = false;
  84. for (uint32_t ct=1; ct < valueCount; ct++) {
  85. if (vin[ct-1] > vin[ct]) {
  86. float t = vin[ct-1];
  87. vin[ct-1] = vin[ct];
  88. vin[ct] = t;
  89. t = vout[ct-1];
  90. vout[ct-1] = vout[ct];
  91. vout[ct] = t;
  92. changed = true;
  93. }
  94. }
  95. if (!changed) break;
  96. }
  97. return a;
  98. }
  99. */
  100. /////////////////////////////////////////
  101. //
  102. RsAnimation rsi_AnimationCreate(Context *rsc,
  103. const float *inValues,
  104. const float *outValues,
  105. uint32_t valueCount,
  106. RsAnimationInterpolation interp,
  107. RsAnimationEdge pre,
  108. RsAnimationEdge post) {
  109. //ALOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
  110. Animation *a = nullptr;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post);
  111. if (a != nullptr) {
  112. a->incUserRef();
  113. }
  114. return (RsAnimation)a;
  115. }
  116. } // namespace renderscript
  117. } // namespace android