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.util.Log; 19 20 /** 21 * This class does an exact comparison of the pixels in a bitmap. 22 */ 23 public class ExactComparer extends BitmapComparer { 24 private static final String TAG = "ExactComparer"; 25 26 /** 27 * This method does an exact 1 to 1 comparison of the two bitmaps 28 */ verifySame(int[] ideal, int[] given, int offset, int stride, int width, int height)29 public boolean verifySame(int[] ideal, int[] given, int offset, int stride, int width, 30 int height) { 31 int count = 0; 32 33 for (int y = 0 ; y < height ; y++) { 34 for (int x = 0 ; x < width ; x++) { 35 int index = indexFromXAndY(x, y, stride, offset); 36 if (ideal[index] != given[index]) { 37 if (count < 50) { 38 Log.d(TAG, "Failure on position x = " + x + " y = " + y); 39 Log.d(TAG, "Expected color : " + Integer.toHexString(ideal[index]) + 40 " given color : " + Integer.toHexString(given[index])); 41 } 42 count++; 43 } 44 } 45 } 46 Log.d(TAG, "Number of different pixels : " + count); 47 48 return (count == 0); 49 } 50 } 51