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.content.Context; 19 import android.graphics.Bitmap; 20 import android.graphics.BitmapFactory; 21 import android.uirendering.cts.bitmapcomparers.BitmapComparer; 22 import android.uirendering.cts.differencevisualizers.PassFailVisualizer; 23 import android.uirendering.cts.testinfrastructure.ActivityTestBase; 24 25 public class GoldenImageVerifier extends BitmapVerifier { 26 private BitmapComparer mBitmapComparer; 27 private int[] mGoldenBitmapArray; 28 29 public GoldenImageVerifier(Bitmap goldenBitmap, BitmapComparer bitmapComparer) { 30 mGoldenBitmapArray = new int[ActivityTestBase.TEST_WIDTH * ActivityTestBase.TEST_HEIGHT]; 31 goldenBitmap.getPixels(mGoldenBitmapArray, 0, ActivityTestBase.TEST_WIDTH, 0, 0, 32 ActivityTestBase.TEST_WIDTH, ActivityTestBase.TEST_HEIGHT); 33 mBitmapComparer = bitmapComparer; 34 } 35 36 public GoldenImageVerifier(Context context, int goldenResId, BitmapComparer bitmapComparer) { 37 this(BitmapFactory.decodeResource(context.getResources(), goldenResId), bitmapComparer); 38 } 39 40 @Override 41 public boolean verify(int[] bitmap, int offset, int stride, int width, int height) { 42 boolean success = mBitmapComparer.verifySame(mGoldenBitmapArray, bitmap, offset, stride, 43 width, height); 44 if (!success) { 45 mDifferenceBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 46 int[] differences = new PassFailVisualizer().getDifferences(mGoldenBitmapArray, bitmap); 47 mDifferenceBitmap.setPixels(differences, 0, width, 0, 0, width, height); 48 } 49 return success; 50 } 51 } 52