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;
22import android.net.Uri;
23import android.provider.MediaStore;
24import androidx.media.filterfw.Filter;
25import androidx.media.filterfw.FrameImage2D;
26import androidx.media.filterfw.FrameType;
27import androidx.media.filterfw.MffContext;
28import androidx.media.filterfw.MffFilterTestCase;
29
30import java.io.FileNotFoundException;
31import java.io.IOException;
32import java.util.concurrent.ExecutionException;
33import java.util.concurrent.TimeoutException;
34
35
36public class ExposureFilterTest extends MffFilterTestCase {
37
38    private AssetManager assetMgr = null;
39    @Override
40    protected Filter createFilter(MffContext mffContext) {
41        assetMgr = mffContext.getApplicationContext().getAssets();
42        return new ExposureFilter(mffContext, "exposureFilter");
43    }
44
45    public void testExposureFilter() throws Exception{
46        final int INPUT_WIDTH = 480;
47        final int INPUT_HEIGHT = 640;
48        FrameImage2D image =
49                createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU),
50                        new int[] {INPUT_WIDTH,INPUT_HEIGHT}).asFrameImage2D();
51
52        Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
53        image.setBitmap(bitmap);
54
55        injectInputFrame("image", image);
56        process();
57        final float EXPECTED_OVEREXPOSURE = 0.00757f;
58        assertEquals(EXPECTED_OVEREXPOSURE, ((Float) getOutputFrame("overExposureRating").
59                asFrameValue().getValue()).floatValue(), 0.001f);
60        final float EXPECTED_UNDEREXPOSURE = 0.2077f;
61        assertEquals(EXPECTED_UNDEREXPOSURE, ((Float) getOutputFrame("underExposureRating").
62                asFrameValue().getValue()).floatValue(), 0.001f);
63    }
64}