Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package android.uirendering.cts.bitmapverifiers; |
| 17 | |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 18 | import android.graphics.Bitmap; |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 19 | import android.graphics.Point; |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 20 | import android.uirendering.cts.testinfrastructure.ActivityTestBase; |
George Mount | 4292ebc | 2014-09-10 15:52:58 -0700 | [diff] [blame] | 21 | import android.uirendering.cts.util.CompareUtils; |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 22 | import android.util.Log; |
| 23 | |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 24 | import java.util.Arrays; |
| 25 | |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 26 | /** |
| 27 | * This class will test specific points, and ensure that they match up perfectly with the input colors |
| 28 | */ |
| 29 | public class SamplePointVerifier extends BitmapVerifier { |
| 30 | private static final String TAG = "SamplePoint"; |
Teng-Hui Zhu | bf91bc3 | 2015-09-02 11:10:43 -0700 | [diff] [blame] | 31 | private static final int DEFAULT_TOLERANCE = 20; |
| 32 | private final Point[] mTestPoints; |
| 33 | private final int[] mExpectedColors; |
| 34 | private final int mTolerance; |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 35 | |
| 36 | public SamplePointVerifier(Point[] testPoints, int[] expectedColors) { |
Teng-Hui Zhu | bf91bc3 | 2015-09-02 11:10:43 -0700 | [diff] [blame] | 37 | this(testPoints, expectedColors, DEFAULT_TOLERANCE); |
| 38 | } |
| 39 | |
| 40 | public SamplePointVerifier(Point[] testPoints, int[] expectedColors, int tolerance) { |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 41 | mTestPoints = testPoints; |
| 42 | mExpectedColors = expectedColors; |
Teng-Hui Zhu | bf91bc3 | 2015-09-02 11:10:43 -0700 | [diff] [blame] | 43 | mTolerance = tolerance; |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean verify(int[] bitmap, int offset, int stride, int width, int height) { |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 48 | boolean success = true; |
| 49 | int[] differenceMap = new int[bitmap.length]; |
| 50 | Arrays.fill(differenceMap, PASS_COLOR); |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 51 | 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 Mount | 4292ebc | 2014-09-10 15:52:58 -0700 | [diff] [blame] | 55 | if (!verifyPixel(bitmap[index], mExpectedColors[i])) { |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 56 | Log.d(TAG, "Expected : " + Integer.toHexString(mExpectedColors[i]) + |
| 57 | " at position x = " + x + " y = " + y + " , tested color : " + |
| 58 | Integer.toHexString(bitmap[index])); |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 59 | differenceMap[index] = FAIL_COLOR; |
| 60 | success = false; |
| 61 | } else { |
| 62 | differenceMap[index] = PASS_COLOR; |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
Antonio Calabrese | 9921d47 | 2014-07-25 14:14:56 -0700 | [diff] [blame] | 65 | 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 Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 72 | } |
George Mount | 4292ebc | 2014-09-10 15:52:58 -0700 | [diff] [blame] | 73 | |
| 74 | protected boolean verifyPixel(int color, int expectedColor) { |
| 75 | return CompareUtils.verifyPixelWithThreshold(color, expectedColor, mTolerance); |
| 76 | } |
Antonio Calabrese | c36bc62 | 2014-07-24 15:07:50 -0700 | [diff] [blame] | 77 | } |