resolved conflicts for ed0ccb8a to mnc-dev Change-Id: I0938cf7bf1cfacc29083692907e8be20811d36cb
diff --git a/hostsidetests/theme/src/android/theme/cts/ComparisonTask.java b/hostsidetests/theme/src/android/theme/cts/ComparisonTask.java old mode 100644 new mode 100755 index 63c7472..0e11111 --- a/hostsidetests/theme/src/android/theme/cts/ComparisonTask.java +++ b/hostsidetests/theme/src/android/theme/cts/ComparisonTask.java
@@ -77,27 +77,42 @@ * @param threshold maximum difference per channel * @return {@code true} if the images are similar, false otherwise */ - private static boolean compare(BufferedImage expected, BufferedImage actual, - int threshold) { - final int w = actual.getWidth(); - final int h = actual.getHeight(); - if (w != expected.getWidth() || h != expected.getHeight()) { + private static int getAlphaScaledBlue(final int color) { + return (color & 0x000000FF) * getAlpha(color) / 255; + } + + private static int getAlphaScaledGreen(final int color) { + return ((color & 0x0000FF00) >> 8) * getAlpha(color) / 255; + } + + private static int getAlphaScaledRed(final int color) { + return ((color & 0x00FF0000) >> 16) * getAlpha(color) / 255; + } + + private static int getAlpha(final int color) { + // use logical shift for keeping an unsigned value + return (color & 0xFF000000) >>> 24; + } + + private static boolean compare(BufferedImage reference, BufferedImage generated, int threshold) { + final int w = generated.getWidth(); + final int h = generated.getHeight(); + if (w != reference.getWidth() || h != reference.getHeight()) { return false; } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { - final int p1 = expected.getRGB(i, j); - final int p2 = actual.getRGB(i, j); - final int dr = (p1 & 0x000000FF) - (p2 & 0x000000FF); - final int dg = ((p1 & 0x0000FF00) - (p2 & 0x0000FF00)) >> 8; - final int db = ((p1 & 0x00FF0000) - (p2 & 0x00FF0000)) >> 16; - final int da = ((p1 & 0xFF000000) - (p2 & 0xFF000000)) >> 24; + final int p1 = reference.getRGB(i, j); + final int p2 = generated.getRGB(i, j); + + final int dr = getAlphaScaledRed(p1) - getAlphaScaledRed(p2); + final int dg = getAlphaScaledGreen(p1) - getAlphaScaledGreen(p2); + final int db = getAlphaScaledBlue(p1) - getAlphaScaledBlue(p2); if (Math.abs(db) > threshold || Math.abs(dg) > threshold || - Math.abs(dr) > threshold || - Math.abs(da) > threshold) { + Math.abs(dr) > threshold) { return false; } }