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.FrameType; 21import androidx.media.filterfw.FrameValue; 22import androidx.media.filterfw.MffContext; 23import androidx.media.filterfw.MffFilterTestCase; 24 25import java.util.concurrent.ExecutionException; 26import java.util.concurrent.TimeoutException; 27 28public class ImageGoodnessFilterTest extends MffFilterTestCase { 29 30 String AWFUL_STRING = "Awful Picture"; 31 String BAD_STRING = "Bad Picture"; 32 String OK_STRING = "Ok Picture"; 33 String GOOD_STRING = "Good Picture!"; 34 String GREAT_STRING = "Great Picture!"; 35 @Override 36 protected Filter createFilter(MffContext mffContext) { 37 return new ImageGoodnessFilter(mffContext, "goodnessFilter"); 38 } 39 40 public void testAwfulPicture() throws Exception { 41 FrameValue sharpnessFrame = createFrame(FrameType.single(), new int[] { 1 }). 42 asFrameValue(); 43 sharpnessFrame.setValue(10f); 44 FrameValue oEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 45 oEFrame.setValue(0.39f); 46 FrameValue uEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 47 uEFrame.setValue(0.25f); 48 FrameValue colorFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 49 colorFrame.setValue(2.1f); 50 FrameValue contrastFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 51 contrastFrame.setValue(0.18f); 52 FrameValue motionFrame = createFrame(FrameType.array(), new int[] { 1 }).asFrameValue(); 53 float[] motionFloatArray = { 9.0f, 3.0f, 2.0f }; 54 motionFrame.setValue(motionFloatArray); 55 56 injectInputFrame("sharpness", sharpnessFrame); 57 injectInputFrame("overExposure", oEFrame); 58 injectInputFrame("underExposure", uEFrame); 59 injectInputFrame("colorfulness", colorFrame); 60 injectInputFrame("contrastRating", contrastFrame); 61 injectInputFrame("motionValues", motionFrame); 62 63 process(); 64 assertEquals("Awful Picture", (String) getOutputFrame("goodOrBadPic").asFrameValue(). 65 getValue()); 66 } 67 68 public void testBadPicture() throws Exception { 69 FrameValue sharpnessFrame = createFrame(FrameType.single(), new int[] { 1 }). 70 asFrameValue(); 71 sharpnessFrame.setValue(10f); 72 FrameValue oEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 73 oEFrame.setValue(0.39f); 74 FrameValue uEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 75 uEFrame.setValue(0.25f); 76 FrameValue colorFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 77 colorFrame.setValue(2.1f); 78 FrameValue contrastFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 79 contrastFrame.setValue(0.18f); 80 FrameValue motionFrame = createFrame(FrameType.array(), new int[] { 1 }).asFrameValue(); 81 float[] motionFloatArray = { 0.0f, 0.0f, 0.0f }; 82 motionFrame.setValue(motionFloatArray); 83 84 injectInputFrame("sharpness", sharpnessFrame); 85 injectInputFrame("overExposure", oEFrame); 86 injectInputFrame("underExposure", uEFrame); 87 injectInputFrame("colorfulness", colorFrame); 88 injectInputFrame("contrastRating", contrastFrame); 89 injectInputFrame("motionValues", motionFrame); 90 91 process(); 92 assertEquals("Bad Picture", (String) getOutputFrame("goodOrBadPic").asFrameValue(). 93 getValue()); 94 } 95 96 public void testOkPicture() throws Exception { 97 FrameValue sharpnessFrame = createFrame(FrameType.single(), new int[] { 1 }). 98 asFrameValue(); 99 sharpnessFrame.setValue(30f); 100 FrameValue oEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 101 oEFrame.setValue(0.39f); 102 FrameValue uEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 103 uEFrame.setValue(0.25f); 104 FrameValue colorFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 105 colorFrame.setValue(2.1f); 106 FrameValue contrastFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 107 contrastFrame.setValue(0.18f); 108 FrameValue motionFrame = createFrame(FrameType.array(), new int[] { 1 }).asFrameValue(); 109 float[] motionFloatArray = { 0.0f, 0.0f, 0.0f }; 110 motionFrame.setValue(motionFloatArray); 111 112 injectInputFrame("sharpness", sharpnessFrame); 113 injectInputFrame("overExposure", oEFrame); 114 injectInputFrame("underExposure", uEFrame); 115 injectInputFrame("colorfulness", colorFrame); 116 injectInputFrame("contrastRating", contrastFrame); 117 injectInputFrame("motionValues", motionFrame); 118 119 process(); 120 assertEquals("Ok Picture", (String) getOutputFrame("goodOrBadPic").asFrameValue(). 121 getValue()); 122 } 123 124 public void testGoodPicture() throws Exception { 125 FrameValue sharpnessFrame = createFrame(FrameType.single(), new int[] { 1 }). 126 asFrameValue(); 127 sharpnessFrame.setValue(50f); 128 FrameValue oEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 129 oEFrame.setValue(0.01f); 130 FrameValue uEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 131 uEFrame.setValue(0.01f); 132 FrameValue colorFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 133 colorFrame.setValue(2.1f); 134 FrameValue contrastFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 135 contrastFrame.setValue(0.18f); 136 FrameValue motionFrame = createFrame(FrameType.array(), new int[] { 1 }).asFrameValue(); 137 float[] motionFloatArray = { 0.0f, 0.0f, 0.0f }; 138 motionFrame.setValue(motionFloatArray); 139 140 injectInputFrame("sharpness", sharpnessFrame); 141 injectInputFrame("overExposure", oEFrame); 142 injectInputFrame("underExposure", uEFrame); 143 injectInputFrame("colorfulness", colorFrame); 144 injectInputFrame("contrastRating", contrastFrame); 145 injectInputFrame("motionValues", motionFrame); 146 147 process(); 148 assertEquals("Good Picture!", (String) getOutputFrame("goodOrBadPic").asFrameValue(). 149 getValue()); 150 } 151 152 public void testGreatPicture() throws Exception { 153 FrameValue sharpnessFrame = createFrame(FrameType.single(), new int[] { 1 }). 154 asFrameValue(); 155 sharpnessFrame.setValue(50f); 156 FrameValue oEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 157 oEFrame.setValue(0.01f); 158 FrameValue uEFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 159 uEFrame.setValue(0.02f); 160 FrameValue colorFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 161 colorFrame.setValue(2.1f); 162 FrameValue contrastFrame = createFrame(FrameType.single(), new int[] { 1 }).asFrameValue(); 163 contrastFrame.setValue(0.25f); 164 FrameValue motionFrame = createFrame(FrameType.array(), new int[] { 1 }).asFrameValue(); 165 float[] motionFloatArray = { 0.0f, 0.0f, 0.0f }; 166 motionFrame.setValue(motionFloatArray); 167 168 injectInputFrame("sharpness", sharpnessFrame); 169 injectInputFrame("overExposure", oEFrame); 170 injectInputFrame("underExposure", uEFrame); 171 injectInputFrame("colorfulness", colorFrame); 172 injectInputFrame("contrastRating", contrastFrame); 173 injectInputFrame("motionValues", motionFrame); 174 175 process(); 176 assertEquals("Great Picture!", (String) getOutputFrame("goodOrBadPic").asFrameValue(). 177 getValue()); 178 } 179} 180