[Extensions] Reduce the percentage of visible pixels required.
This CL also adds a new utility function to render the icon to be
checked. A follow-up CL will add a unit test to reproduce the analysis
that led to lowering this number.
Bug: 805600
Change-Id: I7b93e1eececa4bb70659d8a89f782d0d9cbc5f44
Reviewed-on: https://chromium-review.googlesource.com/c/1431478
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626215}
diff --git a/extensions/common/image_util.cc b/extensions/common/image_util.cc
index 7e5ab41..841950fc 100644
--- a/extensions/common/image_util.cc
+++ b/extensions/common/image_util.cc
@@ -233,7 +233,7 @@
constexpr unsigned int kThreshold = 7;
// The minimum "percent" of pixels that must be visible for the icon to be
// considered OK.
- constexpr double kMinPercentVisiblePixels = 0.05;
+ constexpr double kMinPercentVisiblePixels = 0.03;
const int total_pixels = icon.height() * icon.width();
// Pre-calculate the minimum number of visible pixels so we can exit early.
// Since we expect most icons to be visible, this will perform better for
@@ -246,11 +246,8 @@
// values against the threshold. Any pixel with a value greater than the
// threshold is considered visible.
SkBitmap bitmap;
- bitmap.allocN32Pixels(icon.width(), icon.height());
- bitmap.eraseColor(background_color);
- SkCanvas offscreen(bitmap);
- offscreen.drawImage(SkImage::MakeFromBitmap(icon), 0, 0);
- offscreen.drawColor(background_color, SkBlendMode::kDifference);
+ RenderIconForVisibilityAnalysis(icon, background_color, &bitmap);
+
int visible_pixels = 0;
for (int x = 0; x < icon.width(); ++x) {
for (int y = 0; y < icon.height(); ++y) {
@@ -266,6 +263,18 @@
return false;
}
+void RenderIconForVisibilityAnalysis(const SkBitmap& icon,
+ SkColor background_color,
+ SkBitmap* rendered_icon) {
+ DCHECK(rendered_icon);
+ DCHECK(rendered_icon->empty());
+ rendered_icon->allocN32Pixels(icon.width(), icon.height());
+ rendered_icon->eraseColor(background_color);
+ SkCanvas offscreen(*rendered_icon);
+ offscreen.drawImage(SkImage::MakeFromBitmap(icon), 0, 0);
+ offscreen.drawColor(background_color, SkBlendMode::kDifference);
+}
+
bool IsRenderedIconAtPathSufficientlyVisible(const base::FilePath& path,
SkColor background_color) {
SkBitmap icon;
diff --git a/extensions/common/image_util.h b/extensions/common/image_util.h
index 7501780..31bc54b 100644
--- a/extensions/common/image_util.h
+++ b/extensions/common/image_util.h
@@ -59,6 +59,12 @@
bool IsRenderedIconAtPathSufficientlyVisible(const base::FilePath& path,
SkColor background_color);
+// Renders the icon bitmap onto another bitmap, combining it with the specified
+// background color. The output bitmap must be empty.
+void RenderIconForVisibilityAnalysis(const SkBitmap& icon,
+ SkColor background_color,
+ SkBitmap* rendered_icon);
+
// Load a PNG image from a file into the destination bitmap.
bool LoadPngFromFile(const base::FilePath& path, SkBitmap* dst);