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