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 17 package androidx.media.filterfw.samples.simplecamera; 18 19 import android.content.res.AssetManager; 20 import android.graphics.Bitmap; 21 import android.graphics.BitmapFactory; 22 import android.net.Uri; 23 import android.provider.MediaStore; 24 import androidx.media.filterfw.Filter; 25 import androidx.media.filterfw.FrameImage2D; 26 import androidx.media.filterfw.FrameType; 27 import androidx.media.filterfw.MffContext; 28 import androidx.media.filterfw.MffFilterTestCase; 29 30 import java.io.FileNotFoundException; 31 import java.io.IOException; 32 import java.util.concurrent.ExecutionException; 33 import java.util.concurrent.TimeoutException; 34 35 36 public 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 }