1/*
2 * Copyright 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 */
16
17package androidx.media.filterfw.samples.simplecamera;
18
19import android.content.res.AssetManager;
20import android.graphics.Bitmap;
21import android.graphics.BitmapFactory;
22
23import android.net.Uri;
24import android.provider.MediaStore;
25import androidx.media.filterfw.Filter;
26import androidx.media.filterfw.FrameImage2D;
27import androidx.media.filterfw.FrameType;
28import androidx.media.filterfw.MffContext;
29import androidx.media.filterfw.MffFilterTestCase;
30
31
32public class AvgBrightnessFilterTest extends MffFilterTestCase {
33    private AssetManager assetMgr = null;
34    @Override
35    protected Filter createFilter(MffContext mffContext) {
36        assetMgr = mffContext.getApplicationContext().getAssets();
37        return new AvgBrightnessFilter(mffContext, "brightnessFilter");
38    }
39
40    public void testBrightnessFilter() throws Exception{
41        final int INPUT_WIDTH = 480;
42        final int INPUT_HEIGHT = 640;
43        FrameImage2D image =
44                createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU),
45                        new int[] {INPUT_WIDTH,INPUT_HEIGHT}).asFrameImage2D();
46
47        Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
48        image.setBitmap(bitmap);
49
50        injectInputFrame("image", image);
51
52        process();
53        final float EXPECTED_RESULT = 0.35f;
54        assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("brightnessRating").
55                asFrameValue().getValue()).floatValue(), 0.01f);
56    }
57}