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

Commit db22de8c authored by Antonio Calabrese's avatar Antonio Calabrese
Browse files

Cleaned up CanvasCompare tests.

Change-Id: I93b2f73283e3ab2b8679bf36f29c7bd6cb74c6bf
parent 2e465171
Loading
Loading
Loading
Loading
+4 −11
Original line number Original line Diff line number Diff line
@@ -16,9 +16,6 @@


package com.android.test.hwuicompare;
package com.android.test.hwuicompare;


import com.android.test.hwuicompare.R;
import com.android.test.hwuicompare.ScriptC_errorCalculator;

import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
@@ -52,7 +49,6 @@ public class ErrorCalculator {
        int height = resources.getDimensionPixelSize(R.dimen.layer_height);
        int height = resources.getDimensionPixelSize(R.dimen.layer_height);
        mOutputRowRegions = new int[height / REGION_SIZE];
        mOutputRowRegions = new int[height / REGION_SIZE];


/*
        mRS = RenderScript.create(c);
        mRS = RenderScript.create(c);
        int[] rowIndices = new int[height / REGION_SIZE];
        int[] rowIndices = new int[height / REGION_SIZE];
        for (int i = 0; i < rowIndices.length; i++)
        for (int i = 0; i < rowIndices.length; i++)
@@ -68,15 +64,12 @@ public class ErrorCalculator {
        mInputRowsAllocation.copyFrom(rowIndices);
        mInputRowsAllocation.copyFrom(rowIndices);
        mOutputRegionsAllocation = Allocation.createSized(mRS, Element.I32(mRS),
        mOutputRegionsAllocation = Allocation.createSized(mRS, Element.I32(mRS),
                mOutputRowRegions.length, Allocation.USAGE_SCRIPT);
                mOutputRowRegions.length, Allocation.USAGE_SCRIPT);
*/
    }
    }




    private static long startMillis, middleMillis;
    private static long startMillis, middleMillis;


    public float calcErrorRS(Bitmap ideal, Bitmap given) {
    public float calcErrorRS(Bitmap ideal, Bitmap given) {
        if (true)
            return calcError(ideal, given);
        if (LOG_TIMING) {
        if (LOG_TIMING) {
            startMillis = System.currentTimeMillis();
            startMillis = System.currentTimeMillis();
        }
        }
@@ -86,8 +79,8 @@ public class ErrorCalculator {
        mGivenPixelsAllocation = Allocation.createFromBitmap(mRS, given,
        mGivenPixelsAllocation = Allocation.createFromBitmap(mRS, given,
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);


        mScript.bind_ideal(mIdealPixelsAllocation);
        mScript.set_ideal(mIdealPixelsAllocation);
        mScript.bind_given(mGivenPixelsAllocation);
        mScript.set_given(mGivenPixelsAllocation);


        mScript.forEach_countInterestingRegions(mInputRowsAllocation, mOutputRegionsAllocation);
        mScript.forEach_countInterestingRegions(mInputRowsAllocation, mOutputRegionsAllocation);
        mOutputRegionsAllocation.copyTo(mOutputRowRegions);
        mOutputRegionsAllocation.copyTo(mOutputRowRegions);
@@ -127,8 +120,8 @@ public class ErrorCalculator {
        mGivenPixelsAllocation = Allocation.createFromBitmap(mRS, given,
        mGivenPixelsAllocation = Allocation.createFromBitmap(mRS, given,
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);


        mScript.bind_ideal(mIdealPixelsAllocation);
        mScript.set_ideal(mIdealPixelsAllocation);
        mScript.bind_given(mGivenPixelsAllocation);
        mScript.set_given(mGivenPixelsAllocation);


        mOutputPixelsAllocation = Allocation.createFromBitmap(mRS, output,
        mOutputPixelsAllocation = Allocation.createFromBitmap(mRS, output,
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
                Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
+9 −8
Original line number Original line Diff line number Diff line
@@ -5,8 +5,8 @@ int REGION_SIZE;
int WIDTH;
int WIDTH;
int HEIGHT;
int HEIGHT;


const uchar4 *ideal;
rs_allocation ideal;
const uchar4 *given;
rs_allocation given;


void countInterestingRegions(const int32_t *v_in, int32_t *v_out) {
void countInterestingRegions(const int32_t *v_in, int32_t *v_out) {
    int y = v_in[0];
    int y = v_in[0];
@@ -14,10 +14,10 @@ void countInterestingRegions(const int32_t *v_in, int32_t *v_out) {


    for (int x = 0; x < HEIGHT; x += REGION_SIZE) {
    for (int x = 0; x < HEIGHT; x += REGION_SIZE) {
        bool interestingRegion = false;
        bool interestingRegion = false;
        int regionColor = (int)ideal[y * WIDTH + x];
        int regionColor = (int) rsGetElementAt_uchar4(ideal, x, y);
        for (int i = 0; i < REGION_SIZE && !interestingRegion; i++) {
        for (int i = 0; i < REGION_SIZE && !interestingRegion; i++) {
            for (int j = 0; j < REGION_SIZE && !interestingRegion; j++) {
            for (int j = 0; j < REGION_SIZE && !interestingRegion; j++) {
                interestingRegion |= (int)(ideal[(y + i) * WIDTH + (x + j)]) != regionColor;
                interestingRegion |= ((int) rsGetElementAt_uchar4(ideal, x + j, y + i)) != regionColor;
            }
            }
        }
        }
        if (interestingRegion) {
        if (interestingRegion) {
@@ -31,8 +31,9 @@ void accumulateError(const int32_t *v_in, int32_t *v_out) {
    int error = 0;
    int error = 0;
    for (int y = startY; y < startY + REGION_SIZE; y++) {
    for (int y = startY; y < startY + REGION_SIZE; y++) {
        for (int x = 0; x < HEIGHT; x++) {
        for (int x = 0; x < HEIGHT; x++) {
            uchar4 idealPixel = ideal[y * WIDTH + x];
            uchar4 idealPixel = rsGetElementAt_uchar4(ideal, x, y);
            uchar4 givenPixel = given[y * WIDTH + x];
            uchar4 givenPixel = rsGetElementAt_uchar4(given, x, y);

            error += abs(idealPixel.x - givenPixel.x);
            error += abs(idealPixel.x - givenPixel.x);
            error += abs(idealPixel.y - givenPixel.y);
            error += abs(idealPixel.y - givenPixel.y);
            error += abs(idealPixel.z - givenPixel.z);
            error += abs(idealPixel.z - givenPixel.z);
@@ -43,8 +44,8 @@ void accumulateError(const int32_t *v_in, int32_t *v_out) {
}
}


void displayDifference(const uchar4 *v_in, uchar4 *v_out, uint32_t x, uint32_t y) {
void displayDifference(const uchar4 *v_in, uchar4 *v_out, uint32_t x, uint32_t y) {
    float4 idealPixel = rsUnpackColor8888(ideal[y * WIDTH + x]);
    float4 idealPixel = rsGetElementAt_float4(ideal, x, y);
    float4 givenPixel = rsUnpackColor8888(given[y * WIDTH + x]);
    float4 givenPixel = rsGetElementAt_float4(given, x, y);


    float4 diff = idealPixel - givenPixel;
    float4 diff = idealPixel - givenPixel;
    float totalDiff = diff.x + diff.y + diff.z + diff.w;
    float totalDiff = diff.x + diff.y + diff.z + diff.w;