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.bitmapcomparers;
17 
18 import android.content.res.Resources;
19 import android.renderscript.Allocation;
20 import android.renderscript.RenderScript;
21 
22 /**
23  * This abstract class can be used by the tester to implement their own comparison methods
24  */
25 public abstract class BitmapComparer {
26     /**
27      * Compares the two bitmaps given using Java.
28      * @param offset where in the bitmaps to start
29      * @param stride how much to skip between two different rows
30      * @param width the width of the subsection being tested
31      * @param height the height of the subsection being tested
32      * @return
33      */
verifySame(int[] ideal, int[] given, int offset, int stride, int width, int height)34     public abstract boolean verifySame(int[] ideal, int[] given, int offset, int stride, int width,
35             int height);
36 
37     /**
38      * Compare the two bitmaps using RenderScript, if the comparer
39      * {@link supportsRenderScript() supports it}. If it does not, this method will throw an
40      * UnsupportedOperationException
41      */
verifySameRS(Resources resources, Allocation ideal, Allocation given, int offset, int stride, int width, int height, RenderScript renderScript)42     public boolean verifySameRS(Resources resources, Allocation ideal,
43             Allocation given, int offset, int stride, int width, int height,
44             RenderScript renderScript) {
45         throw new UnsupportedOperationException("Renderscript not supported for this calculator");
46     }
47 
48     /**
49      * This calculates the position in an array that would represent a bitmap given the parameters.
50      */
indexFromXAndY(int x, int y, int stride, int offset)51     protected static int indexFromXAndY(int x, int y, int stride, int offset) {
52         return x + (y * stride) + offset;
53     }
54 
55     /**
56      * Returns whether the verifySameRS() is implemented, and may be used on a RenderScript enabled
57      * system
58      */
supportsRenderScript()59     public boolean supportsRenderScript() {
60         return false;
61     }
62 }
63