Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1202)

Unified Diff: chrome/browser/favicon/select_favicon_frames.cc

Issue 10828186: Use nearest neighbor resampling when upscaling a favicon an integer amount (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/favicon/select_favicon_frames.cc
diff --git a/chrome/browser/favicon/select_favicon_frames.cc b/chrome/browser/favicon/select_favicon_frames.cc
index 36c360ca9eff4a074b40bf809e1f6eb1d243599e..52cb6ab880226775b94e8be2b9da0f31be76f003 100644
--- a/chrome/browser/favicon/select_favicon_frames.cc
+++ b/chrome/browser/favicon/select_favicon_frames.cc
@@ -41,6 +41,23 @@ SkBitmap PadWithBorder(SkBitmap contents, int desired_size, int source_size) {
return bitmap;
}
+SkBitmap SampleNearestNeighbor(SkBitmap contents, int desired_size) {
+ SkBitmap bitmap;
+ bitmap.setConfig(
+ SkBitmap::kARGB_8888_Config, desired_size, desired_size);
+ bitmap.allocPixels();
+ if (!contents.isOpaque())
+ bitmap.eraseARGB(0, 0, 0, 0);
+
+ {
+ SkCanvas canvas(bitmap);
+ SkRect dest(SkRect::MakeWH(desired_size, desired_size));
+ canvas.drawBitmapRect(contents, NULL, dest);
+ }
+
+ return bitmap;
+}
+
SkBitmap SelectCandidate(const std::vector<SkBitmap>& bitmaps,
int desired_size,
ui::ScaleFactor scale_factor) {
@@ -76,27 +93,30 @@ SkBitmap SelectCandidate(const std::vector<SkBitmap>& bitmaps,
}
// 2. Integer multiples are built using nearest neighbor sampling.
- // TODO(thakis): Implement.
-
// 3. Else, use Lancosz scaling:
// b) If available, from the next bigger variant.
- int lancosz_candidate = -1;
+ int candidate = -1;
int min_area = INT_MAX;
for (size_t i = 0; i < bitmaps.size(); ++i) {
int area = bitmaps[i].width() * bitmaps[i].height();
if (bitmaps[i].width() > desired_size &&
bitmaps[i].height() > desired_size &&
- (lancosz_candidate == -1 || area < min_area)) {
- lancosz_candidate = i;
+ (candidate == -1 || area < min_area)) {
+ candidate = i;
min_area = area;
}
}
// c) Else, from the biggest smaller variant.
- if (lancosz_candidate == -1)
- lancosz_candidate = BiggestCandidate(bitmaps);
-
+ if (candidate == -1)
+ candidate = BiggestCandidate(bitmaps);
+
+ const SkBitmap& bitmap = bitmaps[candidate];
+ bool is_integer_multiple = desired_size % bitmap.width() == 0 &&
+ desired_size % bitmap.height() == 0;
+ if (is_integer_multiple)
+ return SampleNearestNeighbor(bitmap, desired_size);
return skia::ImageOperations::Resize(
- bitmaps[lancosz_candidate], skia::ImageOperations::RESIZE_LANCZOS3,
+ bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
desired_size, desired_size);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698