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