Home | History | Annotate | Download | only in analyzer
      1 /*
      2  * Copyright (C) 2011 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 com.android.cts.verifier.camera.analyzer;
     18 
     19 import android.graphics.Bitmap;
     20 import android.hardware.Camera;
     21 import android.os.Environment;
     22 import android.util.Log;
     23 import android.view.SurfaceView;
     24 
     25 import java.io.FileOutputStream;
     26 import java.io.File;
     27 import java.lang.Runnable;
     28 
     29 /**
     30  * Provides an abstraction for all camera tests and allows communication
     31  * between camera test classes with the UI thread. This base class provides
     32  * functions to contruct and access debug output images. It can access and
     33  * set the pointer address of checkerboard centers and radius. It also provides
     34  * native methods to convert an image shot by the camera into a native
     35  * character array. Another native method it provides is to create a native
     36  * test handler with desired debug height and width.
     37  */
     38 public abstract class CameraTests{
     39 
     40     public static final int CAMERA_TEST_NOT_RUN = 0;
     41     public static final int CAMERA_TEST_SUCCESS = 1;
     42     public static final int CAMERA_TEST_FAILURE = 2;
     43 
     44     private static final String TAG = "CameraTests";
     45 
     46     /** Memory address of the color checker centers. */
     47     private static long sCheckerCenterAddress = 0;
     48     /** Memory address of the color checker radius. */
     49     private static long sCheckerRadiusAddress = 0;
     50     /** The surface view linked with the camera preview. */
     51     private static SurfaceView sCameraView;
     52     /** Image debug output. */
     53     private Bitmap mDebugOutput;
     54     /** Shared camera instance. */
     55     protected static Camera mTestCamera = null;
     56 
     57     /**
     58      * Constructs the base CameraTests class.
     59      */
     60     public CameraTests() {}
     61 
     62     /**
     63      * Returns debug Bitmap image. In the test to find the color checker,
     64      * the debug image will be the captured image with a matched color checker
     65      * overlay on top. In the exposure compensation test, the debug image
     66      * will be the response curve of the camera.
     67      * @return A low-resolution Bitmap to be displayed in the UI.
     68      */
     69     public Bitmap getDebugOutput() {
     70         return mDebugOutput;
     71     }
     72 
     73     public String getDebugText() {
     74         return "";
     75     }
     76 
     77     public abstract String getTestName();
     78 
     79     /**
     80      * Gets the detailed report for CTS output.
     81      */
     82     public String getResultText(){
     83         return "Details not available \n";
     84     }
     85 
     86     /**
     87      * Provides a polymorphism to start the run() method for all child classes.
     88      */
     89     public abstract void run(int index);
     90 
     91     public SurfaceView getCameraView() {
     92         return sCameraView;
     93     }
     94 
     95     public static void setCameraView(SurfaceView cameraView) {
     96         sCameraView = cameraView;
     97     }
     98 
     99     /**
    100      * Refreshes the camera instance when the activity opens a new camera.
    101      */
    102     public static void setCamera(Camera newCamera) {
    103         mTestCamera = newCamera;
    104     }
    105 
    106     public static Camera getCamera() {
    107         return mTestCamera;
    108     }
    109 
    110     /**
    111      * Sets the memory address of the checker centers and checker radius.
    112      *
    113      * @param inputCenterAddress the new memory address of
    114      *                           the color checker centers
    115      * @param inputRadiusAddress the new memory address of
    116      *                           the color checker radius
    117      */
    118     public static void setCheckerAddress(long inputCenterAddress, long inputRadiusAddress) {
    119         sCheckerCenterAddress = inputCenterAddress;
    120         sCheckerRadiusAddress = inputRadiusAddress;
    121     }
    122 
    123     /**
    124      * Provides polymorphism to indicate whether the checker memory addresses
    125      * should be copied.
    126      *
    127      * @return <code>true</code> if the class invoking the method needs to
    128      *                           update the memory address of the color checker
    129      *                           centers and radius;
    130      *         <code>false</code> if the class invoking the method does NOT
    131      *                           update the memory address of the color checker
    132      *                           centers and radius.
    133      */
    134     public boolean copyCheckerAddress() {
    135         return false;
    136     }
    137 
    138     public void cleanUp() {
    139     }
    140 
    141     public static long getCheckerCenter() {
    142         return sCheckerCenterAddress;
    143     }
    144 
    145     public static long getCheckerRadius() {
    146         return sCheckerRadiusAddress;
    147     }
    148 
    149     public abstract String getTestName(int index);
    150 
    151     public abstract int getResult(int index);
    152 
    153     public abstract int getNumTests();
    154 
    155     /**
    156      * Provides a native method to convert the input Bitmap of the captured
    157      * image into a native character array and constructs a native image class
    158      * with this character array. This method currently supports conversion
    159      * of Bitmaps in the formats of RGB_565 and RGB_8888.
    160      *
    161      * @param input the input Bitmap, which is decoded from the camrea data.
    162      *
    163      * @return the memory address of the native image class which contains
    164      * the character array.
    165      */
    166     public native long findNative(Bitmap input);
    167 
    168     /**
    169      * Provides a native method to create a native image handler class. The
    170      * native image handler class is the base class for all test classes and
    171      * contains the debug output as a character array.
    172      *
    173      * @param outputHeight the desired height for the debug output
    174      * @param outputWidth the desired width for the debug output
    175      *
    176      * @return the memory address of the native test handler class.
    177      */
    178     public native long createImageTestHandler(int outputHeight, int outputWidth);
    179 
    180     /**
    181      * Provides a native method to clean up the memory taken by the handler.
    182      *
    183      * @param handlerAddress the memory address of the native test handler,
    184      * which contains the debug output.
    185      */
    186     public native void cleanUpHandler(long handlerAddress);
    187 
    188     /**
    189      * Provides a native method to convert the native debug output from
    190      * character array back to Bitmap and copy it to the debug output of this
    191      * class.
    192      *
    193      * @param handlerAddress the memory address of the native test handler,
    194      * which contains the debug output.
    195      */
    196     public native void displayHandlerDebugOutput(long handlerAddress);
    197 
    198     static {
    199         System.loadLibrary("cameraanalyzer");
    200     }
    201 }
    202