diff options
author | David Smith <davidas@google.com> | 2014-08-15 16:29:04 -0700 |
---|---|---|
committer | David Smith <davidas@google.com> | 2014-08-22 16:55:48 -0700 |
commit | 744f5739019d1fd917f981e740b353c3d73fd1a8 (patch) | |
tree | beb8494e67a3b7c2b8f0e0dc67347d3bed10153b /media/libstagefright/filters/IntrinsicBlurFilter.cpp | |
parent | 61cdd163e99eda4c8313bf754c1c557f8291aa8d (diff) | |
download | frameworks_av-744f5739019d1fd917f981e740b353c3d73fd1a8.zip frameworks_av-744f5739019d1fd917f981e740b353c3d73fd1a8.tar.gz frameworks_av-744f5739019d1fd917f981e740b353c3d73fd1a8.tar.bz2 |
stagefright: MediaFilter and SimpleFilter(s)
MediaFilter implements CodecBase and provides video filtering support
via filter modules which extend SimpleFilter.
Bug: 17203044
Change-Id: Ifb30c501e2901c44999d95d7d150e863b2bd06c6
Diffstat (limited to 'media/libstagefright/filters/IntrinsicBlurFilter.cpp')
-rw-r--r-- | media/libstagefright/filters/IntrinsicBlurFilter.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/media/libstagefright/filters/IntrinsicBlurFilter.cpp b/media/libstagefright/filters/IntrinsicBlurFilter.cpp new file mode 100644 index 0000000..cca97ef --- /dev/null +++ b/media/libstagefright/filters/IntrinsicBlurFilter.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#define LOG_NDEBUG 0 +#define LOG_TAG "IntrinsicBlurFilter" + +#include <utils/Log.h> + +#include <media/stagefright/foundation/ABuffer.h> +#include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/AMessage.h> + +#include "IntrinsicBlurFilter.h" + +namespace android { + +status_t IntrinsicBlurFilter::start() { + // TODO: use a single RS context object for entire application + mRS = new RSC::RS(); + + // only legitimate because this is a standalone executable + // TODO: do we need to dynamically determine the cache directory? + if (!mRS->init("/system/bin")) { + ALOGE("Failed to initialize RenderScript context."); + return NO_INIT; + } + + // 32-bit elements for ARGB8888 + RSC::sp<const RSC::Element> e = RSC::Element::U8_4(mRS); + + RSC::Type::Builder tb(mRS, e); + tb.setX(mWidth); + tb.setY(mHeight); + RSC::sp<const RSC::Type> t = tb.create(); + + mAllocIn = RSC::Allocation::createTyped(mRS, t); + mAllocOut = RSC::Allocation::createTyped(mRS, t); + + mBlur = RSC::ScriptIntrinsicBlur::create(mRS, e); + mBlur->setRadius(mBlurRadius); + mBlur->setInput(mAllocIn); + + return OK; +} + +void IntrinsicBlurFilter::reset() { + mBlur.clear(); + mAllocOut.clear(); + mAllocIn.clear(); + mRS.clear(); +} + +status_t IntrinsicBlurFilter::setParameters(const sp<AMessage> &msg) { + sp<AMessage> params; + CHECK(msg->findMessage("params", ¶ms)); + + float blurRadius; + if (params->findFloat("blur-radius", &blurRadius)) { + mBlurRadius = blurRadius; + } + + return OK; +} + +status_t IntrinsicBlurFilter::processBuffers( + const sp<ABuffer> &srcBuffer, const sp<ABuffer> &outBuffer) { + mAllocIn->copy1DRangeFrom(0, mWidth * mHeight, srcBuffer->data()); + mBlur->forEach(mAllocOut); + mAllocOut->copy1DRangeTo(0, mWidth * mHeight, outBuffer->data()); + + return OK; +} + +} // namespace android |