Commit 91ad3c28 authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[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/1431478Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626215}
parent 64f19803
......@@ -233,7 +233,7 @@ bool IsRenderedIconSufficientlyVisible(const SkBitmap& icon,
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 @@ bool IsRenderedIconSufficientlyVisible(const SkBitmap& icon,
// 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 @@ bool IsRenderedIconSufficientlyVisible(const SkBitmap& icon,
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;
......
......@@ -59,6 +59,12 @@ bool IsRenderedIconSufficientlyVisible(const SkBitmap& bitmap,
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment