1/*
2 * Copyright (C) 2011 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
17package android.media.effect;
18
19import android.filterfw.core.Filter;
20import android.filterfw.core.FilterFactory;
21import android.filterfw.core.FilterFunction;
22import android.filterfw.core.Frame;
23import android.media.effect.Effect;
24import android.media.effect.EffectContext;
25
26import android.util.Log;
27
28/**
29 * Effect subclass for effects based on a single Filter with output size differnet
30 * from input.  Subclasses need only invoke the constructor with the correct arguments
31 * to obtain an Effect implementation.
32 *
33 * @hide
34 */
35public class SizeChangeEffect extends SingleFilterEffect {
36
37    public SizeChangeEffect(EffectContext context,
38                            String name,
39                            Class filterClass,
40                            String inputName,
41                            String outputName,
42                            Object... finalParameters) {
43        super(context, name, filterClass, inputName, outputName, finalParameters);
44    }
45
46    @Override
47    public void apply(int inputTexId, int width, int height, int outputTexId) {
48        beginGLEffect();
49
50        Frame inputFrame = frameFromTexture(inputTexId, width, height);
51        Frame resultFrame = mFunction.executeWithArgList(mInputName, inputFrame);
52
53        int outputWidth = resultFrame.getFormat().getWidth();
54        int outputHeight = resultFrame.getFormat().getHeight();
55
56        Frame outputFrame = frameFromTexture(outputTexId, outputWidth, outputHeight);
57        outputFrame.setDataFromFrame(resultFrame);
58
59        inputFrame.release();
60        outputFrame.release();
61        resultFrame.release();
62
63        endGLEffect();
64    }
65}
66