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 com.android.cts.uirendering.R; 19 import com.android.cts.uirendering.ScriptC_ExactComparer; 20 21 import android.content.res.Resources; 22 import android.renderscript.Allocation; 23 import android.renderscript.RenderScript; 24 import android.util.Log; 25 26 /** 27 * This class does an exact comparison of the pixels in a bitmap. 28 */ 29 public class ExactComparer extends BaseRenderScriptComparer { 30 private static final String TAG = "ExactComparer"; 31 private ScriptC_ExactComparer mScript; 32 33 /** 34 * This method does an exact 1 to 1 comparison of the two bitmaps 35 */ verifySame(int[] ideal, int[] given, int offset, int stride, int width, int height)36 public boolean verifySame(int[] ideal, int[] given, int offset, int stride, int width, 37 int height) { 38 int count = 0; 39 40 for (int y = 0 ; y < height ; y++) { 41 for (int x = 0 ; x < width ; x++) { 42 int index = indexFromXAndY(x, y, stride, offset); 43 if (ideal[index] != given[index]) { 44 if (count < 50) { 45 Log.d(TAG, "Failure on position x = " + x + " y = " + y); 46 Log.d(TAG, "Expected color : " + Integer.toHexString(ideal[index]) + 47 " given color : " + Integer.toHexString(given[index])); 48 } 49 count++; 50 } 51 } 52 } 53 Log.d(TAG, "Number of different pixels : " + count); 54 55 return (count == 0); 56 } 57 58 @Override verifySameRowsRS(Resources resources, Allocation ideal, Allocation given, int offset, int stride, int width, int height, RenderScript renderScript, Allocation inputAllocation, Allocation outputAllocation)59 public boolean verifySameRowsRS(Resources resources, Allocation ideal, 60 Allocation given, int offset, int stride, int width, int height, 61 RenderScript renderScript, Allocation inputAllocation, Allocation outputAllocation) { 62 if (mScript == null) { 63 mScript = new ScriptC_ExactComparer(renderScript); 64 } 65 mScript.set_WIDTH(width); 66 mScript.set_OFFSET(offset); 67 68 //Set the bitmap allocations 69 mScript.set_ideal(ideal); 70 mScript.set_given(given); 71 72 //Call the renderscript function on each row 73 mScript.forEach_exactCompare(inputAllocation, outputAllocation); 74 75 float val = sum1DFloatAllocation(outputAllocation); 76 Log.d(TAG, "Number of different pixels RS : " + val); 77 78 return val == 0; 79 } 80 } 81