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 
18 import android.graphics.Bitmap;
19 import android.graphics.Color;
20 
21 /**
22  * Checks to see if a Bitmap follows the algorithm provided by the verifier
23  */
24 public abstract class BitmapVerifier {
25     protected static final int PASS_COLOR = Color.WHITE;
26     protected static final int FAIL_COLOR = Color.RED;
27 
28     protected Bitmap mDifferenceBitmap;
29 
verify(Bitmap bitmap)30     public boolean verify(Bitmap bitmap) {
31         int width = bitmap.getWidth();
32         int height = bitmap.getHeight();
33         int[] pixels = new int[width * height];
34         bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
35         return verify(pixels, 0, width, width, height);
36     }
37 
38     /**
39      * This will test if the bitmap is good or not.
40      */
verify(int[] bitmap, int offset, int stride, int width, int height)41     public abstract boolean verify(int[] bitmap, int offset, int stride, int width, int height);
42 
43     /**
44      * This calculates the position in an array that would represent a bitmap given the parameters.
45      */
indexFromXAndY(int x, int y, int stride, int offset)46     protected static int indexFromXAndY(int x, int y, int stride, int offset) {
47         return x + (y * stride) + offset;
48     }
49 
getDifferenceBitmap()50     public Bitmap getDifferenceBitmap() {
51         return mDifferenceBitmap;
52     }
53 }
54