1 /* 2 * Copyright (C) 2016 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.view.cts.surfacevalidator; 17 18 public class PixelColor { 19 public static final int BLACK = 0xFF000000; 20 public static final int RED = 0xFF0000FF; 21 public static final int GREEN = 0xFF00FF00; 22 public static final int BLUE = 0xFFFF0000; 23 public static final int YELLOW = 0xFF00FFFF; 24 public static final int MAGENTA = 0xFFFF00FF; 25 public static final int WHITE = 0xFFFFFFFF; 26 27 public static final int TRANSPARENT_RED = 0x7F0000FF; 28 public static final int TRANSPARENT_BLUE = 0x7FFF0000; 29 public static final int TRANSPARENT = 0x00000000; 30 31 // Default to black 32 public short mMinAlpha; 33 public short mMaxAlpha; 34 public short mMinRed; 35 public short mMaxRed; 36 public short mMinBlue; 37 public short mMaxBlue; 38 public short mMinGreen; 39 public short mMaxGreen; 40 PixelColor(int color)41 public PixelColor(int color) { 42 short alpha = (short) ((color >> 24) & 0xFF); 43 short blue = (short) ((color >> 16) & 0xFF); 44 short green = (short) ((color >> 8) & 0xFF); 45 short red = (short) (color & 0xFF); 46 47 mMinAlpha = (short) getMinValue(alpha); 48 mMaxAlpha = (short) getMaxValue(alpha); 49 mMinRed = (short) getMinValue(red); 50 mMaxRed = (short) getMaxValue(red); 51 mMinBlue = (short) getMinValue(blue); 52 mMaxBlue = (short) getMaxValue(blue); 53 mMinGreen = (short) getMinValue(green); 54 mMaxGreen = (short) getMaxValue(green); 55 } 56 PixelColor()57 public PixelColor() { 58 this(BLACK); 59 } 60 getMinValue(short color)61 private int getMinValue(short color) { 62 if (color - 4 > 0) { 63 return color - 4; 64 } 65 return 0; 66 } 67 getMaxValue(short color)68 private int getMaxValue(short color) { 69 if (color + 4 < 0xFF) { 70 return color + 4; 71 } 72 return 0xFF; 73 } 74 addToPixelCounter(ScriptC_PixelCounter script)75 public void addToPixelCounter(ScriptC_PixelCounter script) { 76 script.set_MIN_ALPHA(mMinAlpha); 77 script.set_MAX_ALPHA(mMaxAlpha); 78 script.set_MIN_RED(mMinRed); 79 script.set_MAX_RED(mMaxRed); 80 script.set_MIN_BLUE(mMinBlue); 81 script.set_MAX_BLUE(mMaxBlue); 82 script.set_MIN_GREEN(mMinGreen); 83 script.set_MAX_GREEN(mMaxGreen); 84 } 85 } 86