blob: 964e7c18d30bd9bc01704b753baba7c78a4252bc [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
Jason Samse3150cf2012-07-24 18:10:20 -070024void Animation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070025}
26
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080027Animation *Animation::createFromStream(Context *rsc, IStream *stream) {
Chris Wailes44bef6f2014-08-12 13:51:10 -070028 return nullptr;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070029}
30
Jason Samsc1ed5892010-03-10 17:30:41 -080031/*
32Animation::Animation(Context *rsc) : ObjectBase(rsc)
33{
34 mAllocFile = __FILE__;
35 mAllocLine = __LINE__;
36
Chris Wailes44bef6f2014-08-12 13:51:10 -070037 mValuesInput = nullptr;
38 mValuesOutput = nullptr;
Jason Samsc1ed5892010-03-10 17:30:41 -080039 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
47Animation * 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.");
Chris Wailes44bef6f2014-08-12 13:51:10 -070054 return nullptr;
Jason Samsc1ed5892010-03-10 17:30:41 -080055 }
56 Animation *a = new Animation(rsc);
57 if (!a) {
58 rsc->setError(RS_ERROR_OUT_OF_MEMORY);
Chris Wailes44bef6f2014-08-12 13:51:10 -070059 return nullptr;
Jason Samsc1ed5892010-03-10 17:30:41 -080060 }
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;
Chris Wailes44bef6f2014-08-12 13:51:10 -070066 if (a->mValuesInput == nullptr || a->mValuesOutput == nullptr) {
Jason Samsc1ed5892010-03-10 17:30:41 -080067 delete a;
68 rsc->setError(RS_ERROR_OUT_OF_MEMORY);
Chris Wailes44bef6f2014-08-12 13:51:10 -070069 return nullptr;
Jason Samsc1ed5892010-03-10 17:30:41 -080070 }
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
119namespace android {
120namespace renderscript {
121
122RsAnimation rsi_AnimationCreate(Context *rsc,
123 const float *inValues,
124 const float *outValues,
125 uint32_t valueCount,
126 RsAnimationInterpolation interp,
127 RsAnimationEdge pre,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800128 RsAnimationEdge post) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000129 //ALOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
Chris Wailes44bef6f2014-08-12 13:51:10 -0700130 Animation *a = nullptr;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post);
131 if (a != nullptr) {
Jason Samsc1ed5892010-03-10 17:30:41 -0800132 a->incUserRef();
133 }
134 return (RsAnimation)a;
135}
136
137
138}
139}
140