165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn/*
265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Copyright (C) 2011 The Android Open Source Project
365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Licensed under the Apache License, Version 2.0 (the "License");
565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * you may not use this file except in compliance with the License.
665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * You may obtain a copy of the License at
765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *      http://www.apache.org/licenses/LICENSE-2.0
965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
1065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Unless required by applicable law or agreed to in writing, software
1165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * distributed under the License is distributed on an "AS IS" BASIS,
1265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * See the License for the specific language governing permissions and
1465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * limitations under the License.
1565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn */
1665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
1765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennpackage android.media.effect;
1865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
1965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.filterfw.core.Filter;
2065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.filterfw.core.FilterFactory;
2165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.filterfw.core.FilterFunction;
2265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.filterfw.core.Frame;
2365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.media.effect.Effect;
2465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.media.effect.EffectContext;
2565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
2665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennimport android.util.Log;
2765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
2865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn/**
2965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * Effect subclass for effects based on a single Filter with output size differnet
3065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * from input.  Subclasses need only invoke the constructor with the correct arguments
3165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * to obtain an Effect implementation.
3265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn *
3365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn * @hide
3465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn */
3565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Rennpublic class SizeChangeEffect extends SingleFilterEffect {
3665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
3765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    public SizeChangeEffect(EffectContext context,
3865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                            String name,
3965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                            Class filterClass,
4065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                            String inputName,
4165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                            String outputName,
4265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn                            Object... finalParameters) {
4365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        super(context, name, filterClass, inputName, outputName, finalParameters);
4465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    }
4565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
4665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    @Override
4765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    public void apply(int inputTexId, int width, int height, int outputTexId) {
4865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        beginGLEffect();
4965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
5065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        Frame inputFrame = frameFromTexture(inputTexId, width, height);
5165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        Frame resultFrame = mFunction.executeWithArgList(mInputName, inputFrame);
5265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
5365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        int outputWidth = resultFrame.getFormat().getWidth();
5465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        int outputHeight = resultFrame.getFormat().getHeight();
5565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
5665953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        Frame outputFrame = frameFromTexture(outputTexId, outputWidth, outputHeight);
5765953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        outputFrame.setDataFromFrame(resultFrame);
5865953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
5965953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        inputFrame.release();
6065953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        outputFrame.release();
6165953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        resultFrame.release();
6265953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn
6365953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn        endGLEffect();
6465953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn    }
6565953da4636fbf5f0a24b8f5f2b5fa7d76ff13d9Marius Renn}
66