Bug 1300543 - Use palette library instead of BitmapUtils.getDominantColor(). r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Tue, 06 Sep 2016 10:05:32 +0200
changeset 312866 4e9bf0dca65adc5da9c97f0f5e04ec79fca89331
parent 312865 714566fb31ec58b36489c6cbd9a4904fac3da778
child 312867 d5356db094fd44c7084c3a5cf9fe5fe76ea9508b
push id30663
push usercbook@mozilla.com
push dateWed, 07 Sep 2016 15:12:31 +0000
treeherdermozilla-central@3d0b41fdd93b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1300543
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1300543 - Use palette library instead of BitmapUtils.getDominantColor(). r=ahunt MozReview-Commit-ID: LTwarAG5NNm
mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java
--- a/mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/processing/ColorProcessor.java
@@ -1,25 +1,30 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.icons.processing;
 
-import org.mozilla.gecko.gfx.BitmapUtils;
+import android.support.v7.graphics.Palette;
+
 import org.mozilla.gecko.icons.IconRequest;
 import org.mozilla.gecko.icons.IconResponse;
 
 /**
  * Processor implementation to extract the dominant color from the icon and attach it to the icon
  * response object.
  */
 public class ColorProcessor implements Processor {
+    private static final int DEFAULT_COLOR = 0; // 0 == No color
+
     @Override
     public void process(IconRequest request, IconResponse response) {
         if (response.hasColor()) {
             return;
         }
 
-        response.updateColor(BitmapUtils.getDominantColor(response.getBitmap()));
+        final Palette palette = Palette.from(response.getBitmap()).generate();
+
+        response.updateColor(palette.getVibrantColor(DEFAULT_COLOR));
     }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java
@@ -28,17 +28,17 @@ public class TestColorProcessor {
 
         Assert.assertFalse(response.hasColor());
         Assert.assertEquals(0, response.getColor());
 
         final Processor processor = new ColorProcessor();
         processor.process(null, response);
 
         Assert.assertTrue(response.hasColor());
-        Assert.assertEquals(Color.RED, response.getColor());
+        Assert.assertEquals(0xFFF80000, response.getColor());
     }
 
     private Bitmap createRedBitmapMock() {
         final Bitmap bitmap = mock(Bitmap.class);
 
         doReturn(1).when(bitmap).getWidth();
         doReturn(1).when(bitmap).getHeight();