Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1588c4a authored by Brian Attwell's avatar Brian Attwell Committed by Android (Google) Code Review
Browse files

Merge "Small WhitenessUtils changes" into lmp-dev

parents 01408739 c55a6846
Loading
Loading
Loading
Loading
+38 −35
Original line number Diff line number Diff line
@@ -39,9 +39,9 @@ public class WhitenessUtils {
    /**
     * An image with more than this amount white, is considered to be a whitish image.
     */
    private static final float PROPORTION_WHITE_CUTOFF = 0.2f;
    private static final float PROPORTION_WHITE_CUTOFF = 0.1f;

    private static final float HALF = 0.5f;
    private static final float THIRD = 0.33f;

    /**
     * Colors with luma greater than this are considered close to white. This value is lower than
@@ -55,7 +55,7 @@ public class WhitenessUtils {
     */
    public static boolean isBitmapWhiteAtTopOrBottom(Bitmap largeBitmap) {
        Trace.beginSection("isBitmapWhiteAtTopOrBottom");

        try {
            final Bitmap smallBitmap = scaleBitmapDown(largeBitmap);

            final int[] rgbPixels = new int[smallBitmap.getWidth() * smallBitmap.getHeight()];
@@ -65,7 +65,8 @@ public class WhitenessUtils {
            // look at top right corner of the bitmap
            int whiteCount = 0;
            for (int y = 0; y < smallBitmap.getHeight() * HEIGHT_PERCENT_ANALYZED; y++) {
            for (int x = (int) (smallBitmap.getWidth() * HALF); x < smallBitmap.getWidth(); x++) {
                for (int x = (int) (smallBitmap.getWidth() * (1 - THIRD));
                        x < smallBitmap.getWidth(); x++) {
                    final int rgb = rgbPixels[y * smallBitmap.getWidth() + x];
                    if (isWhite(rgb)) {
                        whiteCount ++;
@@ -73,7 +74,7 @@ public class WhitenessUtils {
                }
            }
            int totalPixels = (int) (smallBitmap.getHeight() * smallBitmap.getWidth()
                * HALF * HEIGHT_PERCENT_ANALYZED);
                    * THIRD * HEIGHT_PERCENT_ANALYZED);
            if (whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF) {
                return true;
            }
@@ -93,8 +94,10 @@ public class WhitenessUtils {
            totalPixels = (int) (smallBitmap.getHeight()
                    * smallBitmap.getWidth() * HEIGHT_PERCENT_ANALYZED);

        Trace.endSection();
            return whiteCount / (float) totalPixels > PROPORTION_WHITE_CUTOFF;
        } finally {
            Trace.endSection();
        }
    }

    private static boolean isWhite(int rgb) {