blob: c97e020b347b4cdecd6be54cec2e71ffd375a34f [file] [log] [blame]
Antonio Calabresec36bc622014-07-24 15:07:50 -07001/*
2 * Copyright (C) 2014 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 */
16package android.uirendering.cts.bitmapverifiers;
17
Antonio Calabrese9921d472014-07-25 14:14:56 -070018import android.graphics.Bitmap;
Antonio Calabresec36bc622014-07-24 15:07:50 -070019import android.graphics.Point;
Antonio Calabrese9921d472014-07-25 14:14:56 -070020import android.uirendering.cts.testinfrastructure.ActivityTestBase;
George Mount4292ebc2014-09-10 15:52:58 -070021import android.uirendering.cts.util.CompareUtils;
Antonio Calabresec36bc622014-07-24 15:07:50 -070022import android.util.Log;
23
Antonio Calabrese9921d472014-07-25 14:14:56 -070024import java.util.Arrays;
25
Antonio Calabresec36bc622014-07-24 15:07:50 -070026/**
27 * This class will test specific points, and ensure that they match up perfectly with the input colors
28 */
29public class SamplePointVerifier extends BitmapVerifier {
30 private static final String TAG = "SamplePoint";
Teng-Hui Zhubf91bc32015-09-02 11:10:43 -070031 private static final int DEFAULT_TOLERANCE = 20;
32 private final Point[] mTestPoints;
33 private final int[] mExpectedColors;
34 private final int mTolerance;
Antonio Calabresec36bc622014-07-24 15:07:50 -070035
36 public SamplePointVerifier(Point[] testPoints, int[] expectedColors) {
Teng-Hui Zhubf91bc32015-09-02 11:10:43 -070037 this(testPoints, expectedColors, DEFAULT_TOLERANCE);
38 }
39
40 public SamplePointVerifier(Point[] testPoints, int[] expectedColors, int tolerance) {
Antonio Calabresec36bc622014-07-24 15:07:50 -070041 mTestPoints = testPoints;
42 mExpectedColors = expectedColors;
Teng-Hui Zhubf91bc32015-09-02 11:10:43 -070043 mTolerance = tolerance;
Antonio Calabresec36bc622014-07-24 15:07:50 -070044 }
45
46 @Override
47 public boolean verify(int[] bitmap, int offset, int stride, int width, int height) {
Antonio Calabrese9921d472014-07-25 14:14:56 -070048 boolean success = true;
49 int[] differenceMap = new int[bitmap.length];
50 Arrays.fill(differenceMap, PASS_COLOR);
Antonio Calabresec36bc622014-07-24 15:07:50 -070051 for (int i = 0 ; i < mTestPoints.length ; i++) {
52 int x = mTestPoints[i].x;
53 int y = mTestPoints[i].y;
54 int index = indexFromXAndY(x, y, stride, offset);
George Mount4292ebc2014-09-10 15:52:58 -070055 if (!verifyPixel(bitmap[index], mExpectedColors[i])) {
Antonio Calabresec36bc622014-07-24 15:07:50 -070056 Log.d(TAG, "Expected : " + Integer.toHexString(mExpectedColors[i]) +
57 " at position x = " + x + " y = " + y + " , tested color : " +
58 Integer.toHexString(bitmap[index]));
Antonio Calabrese9921d472014-07-25 14:14:56 -070059 differenceMap[index] = FAIL_COLOR;
60 success = false;
61 } else {
62 differenceMap[index] = PASS_COLOR;
Antonio Calabresec36bc622014-07-24 15:07:50 -070063 }
64 }
Antonio Calabrese9921d472014-07-25 14:14:56 -070065 if (!success) {
66 mDifferenceBitmap = Bitmap.createBitmap(ActivityTestBase.TEST_WIDTH,
67 ActivityTestBase.TEST_HEIGHT, Bitmap.Config.ARGB_8888);
68 mDifferenceBitmap.setPixels(differenceMap, offset, stride, 0, 0,
69 ActivityTestBase.TEST_WIDTH, ActivityTestBase.TEST_HEIGHT);
70 }
71 return success;
Antonio Calabresec36bc622014-07-24 15:07:50 -070072 }
George Mount4292ebc2014-09-10 15:52:58 -070073
74 protected boolean verifyPixel(int color, int expectedColor) {
75 return CompareUtils.verifyPixelWithThreshold(color, expectedColor, mTolerance);
76 }
Antonio Calabresec36bc622014-07-24 15:07:50 -070077}