blob: 3681784942a028b4b7cb6027f5e330ec0c3baf52 [file] [log] [blame]
Chris Craikc3683b52012-10-01 18:22:38 -07001#pragma version(1)
2#pragma rs java_package_name(com.android.test.hwuicompare)
3
4int REGION_SIZE;
5int WIDTH;
6int HEIGHT;
7
8const uchar4 *ideal;
9const uchar4 *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 int regionColor = (int)ideal[y * WIDTH + x];
18 for (int i = 0; i < REGION_SIZE && !interestingRegion; i++) {
19 for (int j = 0; j < REGION_SIZE && !interestingRegion; j++) {
20 interestingRegion |= (int)(ideal[(y + i) * WIDTH + (x + j)]) != regionColor;
21 }
22 }
23 if (interestingRegion) {
24 v_out[0]++;
25 }
26 }
27}
28
29void accumulateError(const int32_t *v_in, int32_t *v_out) {
30 int startY = v_in[0];
31 int error = 0;
32 for (int y = startY; y < startY + REGION_SIZE; y++) {
33 for (int x = 0; x < HEIGHT; x++) {
34 uchar4 idealPixel = ideal[y * WIDTH + x];
35 uchar4 givenPixel = given[y * WIDTH + x];
36 error += abs(idealPixel.x - givenPixel.x);
37 error += abs(idealPixel.y - givenPixel.y);
38 error += abs(idealPixel.z - givenPixel.z);
39 error += abs(idealPixel.w - givenPixel.w);
40 }
41 }
42 v_out[0] = error;
43}
44
45void displayDifference(const uchar4 *v_in, uchar4 *v_out, uint32_t x, uint32_t y) {
46 float4 idealPixel = rsUnpackColor8888(ideal[y * WIDTH + x]);
47 float4 givenPixel = rsUnpackColor8888(given[y * WIDTH + x]);
48
49 float4 diff = idealPixel - givenPixel;
50 float totalDiff = diff.x + diff.y + diff.z + diff.w;
51 if (totalDiff < 0) {
Jason Sams579c00e2013-05-29 11:53:13 -070052 v_out[0] = rsPackColorTo8888(0, 0, clamp(-totalDiff/2.f, 0.f, 1.f));
Chris Craikc3683b52012-10-01 18:22:38 -070053 } else {
Jason Sams579c00e2013-05-29 11:53:13 -070054 v_out[0] = rsPackColorTo8888(clamp(totalDiff/2.f, 0.f, 1.f), 0, 0);
Chris Craikc3683b52012-10-01 18:22:38 -070055 }
56}