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