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