| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 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 | using namespace android; | 
|  | 22 | using namespace android::renderscript; | 
|  | 23 |  | 
| Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 24 | void Animation::serialize(Context *rsc, OStream *stream) const { | 
| Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 25 | } | 
|  | 26 |  | 
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 27 | Animation *Animation::createFromStream(Context *rsc, IStream *stream) { | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 28 | return nullptr; | 
| Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 29 | } | 
|  | 30 |  | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 31 | /* | 
|  | 32 | Animation::Animation(Context *rsc) : ObjectBase(rsc) | 
|  | 33 | { | 
|  | 34 | mAllocFile = __FILE__; | 
|  | 35 | mAllocLine = __LINE__; | 
|  | 36 |  | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 37 | mValuesInput = nullptr; | 
|  | 38 | mValuesOutput = nullptr; | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 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."); | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 54 | return nullptr; | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 55 | } | 
|  | 56 | Animation *a = new Animation(rsc); | 
|  | 57 | if (!a) { | 
|  | 58 | rsc->setError(RS_ERROR_OUT_OF_MEMORY); | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 59 | return nullptr; | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 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; | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 66 | if (a->mValuesInput == nullptr || a->mValuesOutput == nullptr) { | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 67 | delete a; | 
|  | 68 | rsc->setError(RS_ERROR_OUT_OF_MEMORY); | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 69 | return nullptr; | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 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 |  | 
|  | 119 | namespace android { | 
|  | 120 | namespace renderscript { | 
|  | 121 |  | 
|  | 122 | RsAnimation rsi_AnimationCreate(Context *rsc, | 
|  | 123 | const float *inValues, | 
|  | 124 | const float *outValues, | 
|  | 125 | uint32_t valueCount, | 
|  | 126 | RsAnimationInterpolation interp, | 
|  | 127 | RsAnimationEdge pre, | 
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 128 | RsAnimationEdge post) { | 
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 129 | //ALOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize); | 
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 130 | Animation *a = nullptr;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post); | 
|  | 131 | if (a != nullptr) { | 
| Jason Sams | c1ed589 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 132 | a->incUserRef(); | 
|  | 133 | } | 
|  | 134 | return (RsAnimation)a; | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 |  | 
|  | 138 | } | 
|  | 139 | } | 
|  | 140 |  |