1c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams/* 2c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * Copyright (C) 2009 The Android Open Source Project 3c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * 4c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * you may not use this file except in compliance with the License. 6c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * You may obtain a copy of the License at 7c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * 8c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * http://www.apache.org/licenses/LICENSE-2.0 9c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * 10c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * Unless required by applicable law or agreed to in writing, software 11c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * See the License for the specific language governing permissions and 14c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams * limitations under the License. 15c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams */ 16c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 17c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams#include "rsContext.h" 18c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams#include "rsAnimation.h" 19c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 20c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 21c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Samsusing namespace android; 22c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Samsusing namespace android::renderscript; 23c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 24e3150cfb3edb028407669e4a65e087eae77e718cJason Samsvoid Animation::serialize(Context *rsc, OStream *stream) const { 25fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk} 26fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk 27afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex SakhartchoukAnimation *Animation::createFromStream(Context *rsc, IStream *stream) { 2844bef6fba6244292b751387f3d6c31cca96c28adChris Wailes return nullptr; 29fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk} 30fb6b614bcea88a587a7ea4530be45ff0ffa0210eAlex Sakhartchouk 31c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams/* 32c1ed589021e280cda59a0521cb96b3e9eb629e1bJason SamsAnimation::Animation(Context *rsc) : ObjectBase(rsc) 33c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams{ 34c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mAllocFile = __FILE__; 35c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mAllocLine = __LINE__; 36c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 3744bef6fba6244292b751387f3d6c31cca96c28adChris Wailes mValuesInput = nullptr; 3844bef6fba6244292b751387f3d6c31cca96c28adChris Wailes mValuesOutput = nullptr; 39c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mValueCount = 0; 40c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mInterpolation = RS_ANIMATION_INTERPOLATION_STEP; 41c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mEdgePre = RS_ANIMATION_EDGE_UNDEFINED; 42c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mEdgePost = RS_ANIMATION_EDGE_UNDEFINED; 43c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mInputMin = 0; 44c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams mInputMax = 0; 45c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams} 46c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 47c1ed589021e280cda59a0521cb96b3e9eb629e1bJason SamsAnimation * Animation::create(Context *rsc, 48c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams const float *inValues, const float *outValues, 49c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams uint32_t valueCount, RsAnimationInterpolation interp, 50c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams RsAnimationEdge pre, RsAnimationEdge post) 51c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams{ 52c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (valueCount < 2) { 53c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams rsc->setError(RS_ERROR_BAD_VALUE, "Animations require more than 2 values."); 5444bef6fba6244292b751387f3d6c31cca96c28adChris Wailes return nullptr; 55c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 56c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams Animation *a = new Animation(rsc); 57c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (!a) { 58c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams rsc->setError(RS_ERROR_OUT_OF_MEMORY); 5944bef6fba6244292b751387f3d6c31cca96c28adChris Wailes return nullptr; 60c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 61c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 62c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams float *vin = (float *)malloc(valueCount * sizeof(float)); 63c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams float *vout = (float *)malloc(valueCount * sizeof(float)); 64c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mValuesInput = vin; 65c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mValuesOutput = vout; 6644bef6fba6244292b751387f3d6c31cca96c28adChris Wailes if (a->mValuesInput == nullptr || a->mValuesOutput == nullptr) { 67c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams delete a; 68c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams rsc->setError(RS_ERROR_OUT_OF_MEMORY); 6944bef6fba6244292b751387f3d6c31cca96c28adChris Wailes return nullptr; 70c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 71c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 72c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mEdgePre = pre; 73c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mEdgePost = post; 74c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mInterpolation = interp; 75c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mValueCount = valueCount; 76c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 77c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams memcpy(vin, inValues, valueCount * sizeof(float)); 78c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams memcpy(vout, outValues, valueCount * sizeof(float)); 79c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mInputMin = inValues[0]; 80c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mInputMax = inValues[0]; 81c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 82c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams bool needSort = false; 83c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams for (uint32_t ct=1; ct < valueCount; ct++) { 84c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (a->mInputMin > vin[ct]) { 85c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams needSort = true; 86c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mInputMin = vin[ct]; 87c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 88c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (a->mInputMax < vin[ct]) { 89c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->mInputMax = vin[ct]; 90c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } else { 91c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams needSort = true; 92c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 93c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 94c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 95c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams while (1) { 96c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams bool changed = false; 97c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams for (uint32_t ct=1; ct < valueCount; ct++) { 98c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (vin[ct-1] > vin[ct]) { 99c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams float t = vin[ct-1]; 100c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams vin[ct-1] = vin[ct]; 101c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams vin[ct] = t; 102c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams t = vout[ct-1]; 103c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams vout[ct-1] = vout[ct]; 104c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams vout[ct] = t; 105c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams changed = true; 106c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 107c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 108c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams if (!changed) break; 109c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 110c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 111c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams return a; 112c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams} 113c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams*/ 114c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 115c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 116c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams///////////////////////////////////////// 117c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams// 118c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 119c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Samsnamespace android { 120c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Samsnamespace renderscript { 121c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 122c1ed589021e280cda59a0521cb96b3e9eb629e1bJason SamsRsAnimation rsi_AnimationCreate(Context *rsc, 123c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams const float *inValues, 124c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams const float *outValues, 125c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams uint32_t valueCount, 126c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams RsAnimationInterpolation interp, 127c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams RsAnimationEdge pre, 128afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchouk RsAnimationEdge post) { 129af12ac6a08651464f8d823add667c706f993b587Steve Block //ALOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize); 13044bef6fba6244292b751387f3d6c31cca96c28adChris Wailes Animation *a = nullptr;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post); 13144bef6fba6244292b751387f3d6c31cca96c28adChris Wailes if (a != nullptr) { 132c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams a->incUserRef(); 133c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams } 134c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams return (RsAnimation)a; 135c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams} 136c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 137c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 138c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams} 139c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams} 140c1ed589021e280cda59a0521cb96b3e9eb629e1bJason Sams 141