Home | History | Annotate | Download | only in simplecamera
      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.util.Log;
     20 import androidx.media.filterfw.Filter;
     21 import androidx.media.filterfw.Frame;
     22 import androidx.media.filterfw.FrameImage2D;
     23 import androidx.media.filterfw.FrameType;
     24 import androidx.media.filterfw.FrameValue;
     25 import androidx.media.filterfw.MffContext;
     26 import androidx.media.filterfw.OutputPort;
     27 import androidx.media.filterfw.Signature;
     28 
     29 import java.nio.ByteBuffer;
     30 
     31 public class ContrastRatioFilter extends Filter {
     32 
     33     private static final String TAG = "ContrastRatioFilter";
     34     private static boolean mLogVerbose = Log.isLoggable(TAG, Log.VERBOSE);
     35 
     36     public ContrastRatioFilter(MffContext context, String name) {
     37         super(context, name);
     38     }
     39 
     40     @Override
     41     public Signature getSignature() {
     42         FrameType imageIn = FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU);
     43         FrameType floatT = FrameType.single(float.class);
     44         return new Signature().addInputPort("image", Signature.PORT_REQUIRED, imageIn)
     45                 .addOutputPort("contrastRatingToGoodness", Signature.PORT_REQUIRED, floatT)
     46                 .disallowOtherPorts();
     47 
     48     }
     49 
     50     @Override
     51     protected void onProcess() {
     52         FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
     53 
     54         float contrastRatio;
     55         ByteBuffer inputBuffer  = inputImage.lockBytes(Frame.MODE_READ);
     56 
     57         contrastRatio = contrastOperator(inputImage.getWidth(), inputImage.getHeight(),
     58                     inputBuffer);
     59 
     60         inputImage.unlock();
     61 
     62         if (mLogVerbose) Log.v(TAG, "contrastRatio: " + contrastRatio);
     63 
     64         OutputPort contrastToGoodnessPort = getConnectedOutputPort("contrastRatingToGoodness");
     65         FrameValue contrastOutFrame2 =
     66                 contrastToGoodnessPort.fetchAvailableFrame(null).asFrameValue();
     67         contrastOutFrame2.setValue(contrastRatio);
     68         contrastToGoodnessPort.pushFrame(contrastOutFrame2);
     69 
     70 
     71     }
     72 
     73     private static native float contrastOperator(int width, int height, ByteBuffer imageBuffer);
     74 
     75     static {
     76         System.loadLibrary("smartcamera_jni");
     77     }
     78 
     79 }
     80