1/*
2 * Copyright (C) 2013 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 */
16package androidx.media.filterfw.samples.simplecamera;
17
18import androidx.media.filterfw.Filter;
19import androidx.media.filterfw.FrameType;
20import androidx.media.filterfw.FrameValue;
21import androidx.media.filterfw.MffContext;
22import androidx.media.filterfw.MffFilterTestCase;
23
24
25public class AverageFilterTest extends MffFilterTestCase {
26
27    @Override
28    protected Filter createFilter(MffContext mffContext) {
29        return new AverageFilter(mffContext, "averageFilter");
30    }
31
32    public void testAverageFilter() throws Exception {
33        FrameValue frame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue();
34        frame.setValue(5f);
35
36        injectInputFrame("sharpness", frame);
37
38        process();
39        assertEquals(1f, ((Float) getOutputFrame("avg").asFrameValue().getValue()).floatValue(),
40                0.001f);
41    }
42
43    public void testAverageFilter2() throws Exception{
44        FrameValue frame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue();
45        frame.setValue(4f);
46
47        injectInputFrame("sharpness", frame);
48
49        process();
50        assertEquals(0.8f, ((Float) getOutputFrame("avg").asFrameValue().getValue()).floatValue(),
51                0.001f);
52    }
53}
54