Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6cf3c02 authored by Xia Wang's avatar Xia Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix image processing test to include all benchmark tests -- each test...

Merge "Fix image processing test to include all benchmark tests -- each test case can be excuted separately -- add a test case to run all benchmarks."
parents f849124b b2d98ceb
Loading
Loading
Loading
Loading
+106 −103
Original line number Diff line number Diff line
@@ -23,14 +23,7 @@ import android.os.Message;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.renderscript.ScriptC;
import android.renderscript.RenderScript;
import android.renderscript.Type;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.Script;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
@@ -39,13 +32,8 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.view.View;
import android.util.Log;
import java.lang.Math;

import android.os.Environment;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -54,12 +42,68 @@ import java.io.IOException;
public class ImageProcessingActivity extends Activity
                                       implements SeekBar.OnSeekBarChangeListener {
    private final String TAG = "Img";
    private final String RESULT_FILE = "image_processing_result.csv";
    public final String RESULT_FILE = "image_processing_result.csv";

    /**
     * Define enum type for test names
     */
    public enum TestName {
        // totally there are 38 test cases
        LEVELS_VEC3_RELAXED ("Levels Vec3 Relaxed"),
        LEVELS_VEC4_RELAXED ("Levels Vec4 Relaxed"),
        LEVELS_VEC3_FULL ("Levels Vec3 Full"),
        LEVELS_VEC4_FULL ("Levels Vec4 Full"),
        BLUR_RADIUS_25 ("Blur radius 25"),
        INTRINSIC_BLUE_RADIUS_25 ("Intrinsic Blur radius 25"),
        GREYSCALE ("Greyscale"),
        GRAIN ("Grain"),
        FISHEYE_FULL ("Fisheye Full"),
        FISHEYE_RELAXED ("Fisheye Relaxed"),
        FISHEYE_APPROXIMATE_FULL ("Fisheye Approximate Full"),
        FISHEYE_APPROXIMATE_RELAXED ("Fisheye Approximate Relaxed"),
        VIGNETTE_FULL ("Vignette Full"),
        VIGNETTE_RELAXED ("Vignette Relaxed"),
        VIGNETTE_APPROXIMATE_FULL ("Vignette Approximate Full"),
        VIGNETTE_APPROXIMATE_RELAXED ("Vignette Approximate Relaxed"),
        GROUP_TEST_EMULATED ("Group Test (emulated)"),
        GROUP_TEST_NATIVE ("Group Test (native)"),
        CONVOLVE_3X3 ("Convolve 3x3"),
        INTRINSICS_CONVOLVE_3X3 ("Intrinsics Convolve 3x3"),
        COLOR_MATRIX ("ColorMatrix"),
        INTRINSICS_COLOR_MATRIX ("Intrinsics ColorMatrix"),
        INTRINSICS_COLOR_MATRIX_GREY ("Intrinsics ColorMatrix Grey"),
        COPY ("Copy"),
        CROSS_PROCESS_USING_LUT ("CrossProcess (using LUT)"),
        CONVOLVE_5X5 ("Convolve 5x5"),
        INTRINSICS_CONVOLVE_5X5 ("Intrinsics Convolve 5x5"),
        MANDELBROT ("Mandelbrot"),
        INTRINSICS_BLEND ("Intrinsics Blend"),
        INTRINSICS_BLUR_25G ("Intrinsics Blur 25 uchar"),
        VIBRANCE ("Vibrance"),
        BW_FILTER ("BW Filter"),
        SHADOWS ("Shadows"),
        CONTRAST ("Contrast"),
        EXPOSURE ("Exposure"),
        WHITE_BALANCE ("White Balance"),
        COLOR_CUBE ("Color Cube"),
        COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)");


        private final String name;

        private TestName(String s) {
            name = s;
        }

        // return quoted string as displayed test name
        public String toString() {
            return name;
        }
    }

    Bitmap mBitmapIn;
    Bitmap mBitmapIn2;
    Bitmap mBitmapOut;
    String mTestNames[];

    private Spinner mSpinner;
    private SeekBar mBar1;
@@ -178,123 +222,123 @@ public class ImageProcessingActivity extends Activity
    }


    void changeTest(int testID) {
    void changeTest(TestName testName) {
        if (mTest != null) {
            mTest.destroy();
        }
        switch(testID) {
        case 0:
        switch(testName) {
        case LEVELS_VEC3_RELAXED:
            mTest = new LevelsV4(false, false);
            break;
        case 1:
        case LEVELS_VEC4_RELAXED:
            mTest = new LevelsV4(false, true);
            break;
        case 2:
        case LEVELS_VEC3_FULL:
            mTest = new LevelsV4(true, false);
            break;
        case 3:
        case LEVELS_VEC4_FULL:
            mTest = new LevelsV4(true, true);
            break;
        case 4:
        case BLUR_RADIUS_25:
            mTest = new Blur25(false);
            break;
        case 5:
        case INTRINSIC_BLUE_RADIUS_25:
            mTest = new Blur25(true);
            break;
        case 6:
        case GREYSCALE:
            mTest = new Greyscale();
            break;
        case 7:
        case GRAIN:
            mTest = new Grain();
            break;
        case 8:
        case FISHEYE_FULL:
            mTest = new Fisheye(false, false);
            break;
        case 9:
        case FISHEYE_RELAXED:
            mTest = new Fisheye(false, true);
            break;
        case 10:
        case FISHEYE_APPROXIMATE_FULL:
            mTest = new Fisheye(true, false);
            break;
        case 11:
        case FISHEYE_APPROXIMATE_RELAXED:
            mTest = new Fisheye(true, true);
            break;
        case 12:
        case VIGNETTE_FULL:
            mTest = new Vignette(false, false);
            break;
        case 13:
        case VIGNETTE_RELAXED:
            mTest = new Vignette(false, true);
            break;
        case 14:
        case VIGNETTE_APPROXIMATE_FULL:
            mTest = new Vignette(true, false);
            break;
        case 15:
        case VIGNETTE_APPROXIMATE_RELAXED:
            mTest = new Vignette(true, true);
            break;
        case 16:
        case GROUP_TEST_EMULATED:
            mTest = new GroupTest(false);
            break;
        case 17:
        case GROUP_TEST_NATIVE:
            mTest = new GroupTest(true);
            break;
        case 18:
        case CONVOLVE_3X3:
            mTest = new Convolve3x3(false);
            break;
        case 19:
        case INTRINSICS_CONVOLVE_3X3:
            mTest = new Convolve3x3(true);
            break;
        case 20:
        case COLOR_MATRIX:
            mTest = new ColorMatrix(false, false);
            break;
        case 21:
        case INTRINSICS_COLOR_MATRIX:
            mTest = new ColorMatrix(true, false);
            break;
        case 22:
        case INTRINSICS_COLOR_MATRIX_GREY:
            mTest = new ColorMatrix(true, true);
            break;
        case 23:
        case COPY:
            mTest = new Copy();
            break;
        case 24:
        case CROSS_PROCESS_USING_LUT:
            mTest = new CrossProcess();
            break;
        case 25:
        case CONVOLVE_5X5:
            mTest = new Convolve5x5(false);
            break;
        case 26:
        case INTRINSICS_CONVOLVE_5X5:
            mTest = new Convolve5x5(true);
            break;
        case 27:
        case MANDELBROT:
            mTest = new Mandelbrot();
            break;
        case 28:
        case INTRINSICS_BLEND:
            mTest = new Blend();
            break;
        case 29:
        case INTRINSICS_BLUR_25G:
            mTest = new Blur25G();
            break;
        case 30:
        case VIBRANCE:
            mTest = new Vibrance();
            break;
        case 31:
        case BW_FILTER:
            mTest = new BWFilter();
            break;
        case 32:
        case SHADOWS:
            mTest = new Shadows();
            break;
        case 33:
        case CONTRAST:
            mTest = new Contrast();
            break;
        case 34:
        case EXPOSURE:
            mTest = new Exposure();
            break;
        case 35:
        case WHITE_BALANCE:
            mTest = new WhiteBalance();
            break;
        case 36:
        case COLOR_CUBE:
            mTest = new ColorCube(false);
            break;
        case 37:
        case COLOR_CUBE_3D_INTRINSIC:
            mTest = new ColorCube(true);
            break;
        }
@@ -308,54 +352,14 @@ public class ImageProcessingActivity extends Activity
    }

    void setupTests() {
        mTestNames = new String[38];
        mTestNames[0] = "Levels Vec3 Relaxed";
        mTestNames[1] = "Levels Vec4 Relaxed";
        mTestNames[2] = "Levels Vec3 Full";
        mTestNames[3] = "Levels Vec4 Full";
        mTestNames[4] = "Blur radius 25";
        mTestNames[5] = "Intrinsic Blur radius 25";
        mTestNames[6] = "Greyscale";
        mTestNames[7] = "Grain";
        mTestNames[8] = "Fisheye Full";
        mTestNames[9] = "Fisheye Relaxed";
        mTestNames[10] = "Fisheye Approximate Full";
        mTestNames[11] = "Fisheye Approximate Relaxed";
        mTestNames[12] = "Vignette Full";
        mTestNames[13] = "Vignette Relaxed";
        mTestNames[14] = "Vignette Approximate Full";
        mTestNames[15] = "Vignette Approximate Relaxed";
        mTestNames[16] = "Group Test (emulated)";
        mTestNames[17] = "Group Test (native)";
        mTestNames[18] = "Convolve 3x3";
        mTestNames[19] = "Intrinsics Convolve 3x3";
        mTestNames[20] = "ColorMatrix";
        mTestNames[21] = "Intrinsics ColorMatrix";
        mTestNames[22] = "Intrinsics ColorMatrix Grey";
        mTestNames[23] = "Copy";
        mTestNames[24] = "CrossProcess (using LUT)";
        mTestNames[25] = "Convolve 5x5";
        mTestNames[26] = "Intrinsics Convolve 5x5";
        mTestNames[27] = "Mandelbrot";
        mTestNames[28] = "Intrinsics Blend";
        mTestNames[29] = "Intrinsics Blur 25 uchar";
        mTestNames[30] = "Vibrance";
        mTestNames[31] = "BW Filter";
        mTestNames[32] = "Shadows";
        mTestNames[33] = "Contrast";
        mTestNames[34] = "Exposure";
        mTestNames[35] = "White Balance";
        mTestNames[36] = "Color Cube";
        mTestNames[37] = "Color Cube (3D LUT intrinsic)";

        mTestSpinner.setAdapter(new ArrayAdapter<String>(
            this, R.layout.spinner_layout, mTestNames));
        mTestSpinner.setAdapter(new ArrayAdapter<TestName>(
            this, R.layout.spinner_layout, TestName.values()));
    }

    private AdapterView.OnItemSelectedListener mTestSpinnerListener =
            new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                    changeTest(pos);
                    changeTest(TestName.values()[pos]);
                }

                public void onNothingSelected(AdapterView parent) {
@@ -405,7 +409,7 @@ public class ImageProcessingActivity extends Activity
        mBenchmarkResult.setText("Result: not run");

        setupTests();
        changeTest(0);
        changeTest(TestName.LEVELS_VEC3_RELAXED);
    }


@@ -436,10 +440,10 @@ public class ImageProcessingActivity extends Activity
        try {
            BufferedWriter rsWriter = new BufferedWriter(new FileWriter(resultFile));
            Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
            for (int i = 0; i < mTestNames.length; i++ ) {
                changeTest(i);
            for (TestName tn: TestName.values()) {
                changeTest(tn);
                float t = getBenchmark();
                String s = new String("" + mTestNames[i] + ", " + t);
                String s = new String("" + tn.toString() + ", " + t);
                rsWriter.write(s + "\n");
                Log.v(TAG, "Test " + s + "ms\n");
            }
@@ -447,7 +451,7 @@ public class ImageProcessingActivity extends Activity
        } catch (IOException e) {
            Log.v(TAG, "Unable to write result file " + e.getMessage());
        }
        changeTest(0);
        changeTest(TestName.LEVELS_VEC3_RELAXED);
    }

    // For benchmark test
@@ -464,7 +468,6 @@ public class ImageProcessingActivity extends Activity
            mTest.finish();
        } while (t > java.lang.System.currentTimeMillis());


        //Log.v(TAG, "Benchmarking");
        int ct = 0;
        t = java.lang.System.currentTimeMillis();
+328 −43

File changed.

Preview size limit exceeded, changes collapsed.

+12 −1
Original line number Diff line number Diff line
@@ -24,14 +24,25 @@ import junit.framework.TestSuite;

/**
 * Run the ImageProcessing benchmark test
 * adb shell am instrument -w com.android.rs.image/.ImageProcessingTestRunner
 * adb shell am instrument -e iteration <n> -w com.android.rs.image/.ImageProcessingTestRunner
 *
 */
public class ImageProcessingTestRunner extends InstrumentationTestRunner {
    public int mIteration = 5;

    @Override
    public TestSuite getAllTests() {
        TestSuite suite = new InstrumentationTestSuite(this);
        suite.addTestSuite(ImageProcessingTest.class);
        return suite;
    }

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        String strIteration = (String) icicle.get("iteration");
        if (strIteration != null) {
            mIteration = Integer.parseInt(strIteration);
        }
    }
}