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