IntrinsicBlurFilter.cpp revision e7f4e676bb88b17241d71731f9ea50c18cfcb039
1/* 2 * Copyright (C) 2014 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//#define LOG_NDEBUG 0 18#define LOG_TAG "IntrinsicBlurFilter" 19 20#include <utils/Log.h> 21 22#include <media/stagefright/foundation/ABuffer.h> 23#include <media/stagefright/foundation/ADebug.h> 24#include <media/stagefright/foundation/AMessage.h> 25 26#include "IntrinsicBlurFilter.h" 27 28namespace android { 29 30status_t IntrinsicBlurFilter::start() { 31 // TODO: use a single RS context object for entire application 32 mRS = new RSC::RS(); 33 34 if (!mRS->init(mCacheDir.c_str())) { 35 ALOGE("Failed to initialize RenderScript context."); 36 return NO_INIT; 37 } 38 39 // 32-bit elements for ARGB8888 40 RSC::sp<const RSC::Element> e = RSC::Element::U8_4(mRS); 41 42 RSC::Type::Builder tb(mRS, e); 43 tb.setX(mWidth); 44 tb.setY(mHeight); 45 RSC::sp<const RSC::Type> t = tb.create(); 46 47 mAllocIn = RSC::Allocation::createTyped(mRS, t); 48 mAllocOut = RSC::Allocation::createTyped(mRS, t); 49 50 mBlur = RSC::ScriptIntrinsicBlur::create(mRS, e); 51 mBlur->setRadius(mBlurRadius); 52 mBlur->setInput(mAllocIn); 53 54 return OK; 55} 56 57void IntrinsicBlurFilter::reset() { 58 mBlur.clear(); 59 mAllocOut.clear(); 60 mAllocIn.clear(); 61 mRS.clear(); 62} 63 64status_t IntrinsicBlurFilter::setParameters(const sp<AMessage> &msg) { 65 sp<AMessage> params; 66 CHECK(msg->findMessage("params", ¶ms)); 67 68 float blurRadius; 69 if (params->findFloat("blur-radius", &blurRadius)) { 70 mBlurRadius = blurRadius; 71 } 72 73 return OK; 74} 75 76status_t IntrinsicBlurFilter::processBuffers( 77 const sp<ABuffer> &srcBuffer, const sp<ABuffer> &outBuffer) { 78 mAllocIn->copy1DRangeFrom(0, mWidth * mHeight, srcBuffer->data()); 79 mBlur->forEach(mAllocOut); 80 mAllocOut->copy1DRangeTo(0, mWidth * mHeight, outBuffer->data()); 81 82 return OK; 83} 84 85} // namespace android 86