1#pragma version(1)
2#pragma rs java_package_name(com.android.test.hwuicompare)
3
4int REGION_SIZE;
5int WIDTH;
6int HEIGHT;
7
8rs_allocation ideal;
9rs_allocation given;
10
11void countInterestingRegions(const int32_t *v_in, int32_t *v_out) {
12    int y = v_in[0];
13    v_out[0] = 0;
14
15    for (int x = 0; x < HEIGHT; x += REGION_SIZE) {
16        bool interestingRegion = false;
17        uchar4 regionColor = rsGetElementAt_uchar4(ideal, x, y);
18        for (int i = 0; i < REGION_SIZE && !interestingRegion; i++) {
19            for (int j = 0; j < REGION_SIZE && !interestingRegion; j++) {
20                uchar4 testVal = rsGetElementAt_uchar4(ideal, x + j, y + i);
21                interestingRegion |= (testVal.r != regionColor.r);
22                interestingRegion |= (testVal.g != regionColor.g);
23                interestingRegion |= (testVal.b != regionColor.b);
24                interestingRegion |= (testVal.a != regionColor.a);
25            }
26        }
27        if (interestingRegion) {
28            v_out[0]++;
29        }
30    }
31}
32
33void accumulateError(const int32_t *v_in, int32_t *v_out) {
34    int startY = v_in[0];
35    int error = 0;
36    for (int y = startY; y < startY + REGION_SIZE; y++) {
37        for (int x = 0; x < HEIGHT; x++) {
38            uchar4 idealPixel = rsGetElementAt_uchar4(ideal, x, y);
39            uchar4 givenPixel = rsGetElementAt_uchar4(given, x, y);
40
41            error += abs(idealPixel.x - givenPixel.x);
42            error += abs(idealPixel.y - givenPixel.y);
43            error += abs(idealPixel.z - givenPixel.z);
44            error += abs(idealPixel.w - givenPixel.w);
45        }
46    }
47    v_out[0] = error;
48}
49
50void displayDifference(const uchar4 *v_in, uchar4 *v_out, uint32_t x, uint32_t y) {
51    float4 idealPixel = rsGetElementAt_float4(ideal, x, y);
52    float4 givenPixel = rsGetElementAt_float4(given, x, y);
53
54    float4 diff = idealPixel - givenPixel;
55    float totalDiff = diff.x + diff.y + diff.z + diff.w;
56    if (totalDiff < 0) {
57        v_out[0] = rsPackColorTo8888(0, 0, clamp(-totalDiff/2.f, 0.f, 1.f));
58    } else {
59        v_out[0] = rsPackColorTo8888(clamp(totalDiff/2.f, 0.f, 1.f), 0, 0);
60    }
61}
62