| Index: components/favicon_base/favicon_util.cc
|
| diff --git a/components/favicon_base/favicon_util.cc b/components/favicon_base/favicon_util.cc
|
| index d45196e2a707ae48f5fb4dfa88516966025b2505..1861935e48d1e073e52f3305f6a77aa6f3d3f8b5 100644
|
| --- a/components/favicon_base/favicon_util.cc
|
| +++ b/components/favicon_base/favicon_util.cc
|
| @@ -86,59 +86,6 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
|
| return png_reps;
|
| }
|
|
|
| -// Returns a resampled bitmap of |desired_size| x |desired_size| by resampling
|
| -// the best bitmap out of |input_bitmaps|.
|
| -// ResizeBitmapByDownsamplingIfPossible() is similar to SelectFaviconFrames()
|
| -// but it operates on bitmaps which have already been resampled via
|
| -// SelectFaviconFrames().
|
| -SkBitmap ResizeBitmapByDownsamplingIfPossible(
|
| - const std::vector<SkBitmap>& input_bitmaps,
|
| - int desired_size) {
|
| - DCHECK(!input_bitmaps.empty());
|
| - DCHECK_NE(0, desired_size);
|
| -
|
| - SkBitmap best_bitmap;
|
| - for (size_t i = 0; i < input_bitmaps.size(); ++i) {
|
| - const SkBitmap& input_bitmap = input_bitmaps[i];
|
| - if (input_bitmap.width() == desired_size &&
|
| - input_bitmap.height() == desired_size) {
|
| - return input_bitmap;
|
| - } else if (best_bitmap.isNull()) {
|
| - best_bitmap = input_bitmap;
|
| - } else if (input_bitmap.width() >= best_bitmap.width() &&
|
| - input_bitmap.height() >= best_bitmap.height()) {
|
| - if (best_bitmap.width() < desired_size ||
|
| - best_bitmap.height() < desired_size) {
|
| - best_bitmap = input_bitmap;
|
| - }
|
| - } else {
|
| - if (input_bitmap.width() >= desired_size &&
|
| - input_bitmap.height() >= desired_size) {
|
| - best_bitmap = input_bitmap;
|
| - }
|
| - }
|
| - }
|
| -
|
| - if (desired_size % best_bitmap.width() == 0 &&
|
| - desired_size % best_bitmap.height() == 0) {
|
| - // Use nearest neighbour resampling if upsampling by an integer. This
|
| - // makes the result look similar to the result of SelectFaviconFrames().
|
| - SkBitmap bitmap;
|
| - bitmap.allocN32Pixels(desired_size, desired_size);
|
| - if (!best_bitmap.isOpaque())
|
| - bitmap.eraseARGB(0, 0, 0, 0);
|
| -
|
| - SkCanvas canvas(bitmap);
|
| - canvas.drawBitmapRect(
|
| - best_bitmap, SkRect::MakeIWH(desired_size, desired_size), NULL);
|
| - return bitmap;
|
| - }
|
| - return skia::ImageOperations::Resize(best_bitmap,
|
| - skia::ImageOperations::RESIZE_LANCZOS3,
|
| - desired_size,
|
| - desired_size);
|
| -}
|
| -
|
| } // namespace
|
|
|
| std::vector<float> GetFaviconScales() {
|
| @@ -295,4 +242,54 @@ favicon_base::FaviconRawBitmapResult ResizeFaviconBitmapResult(
|
| return bitmap_result;
|
| }
|
|
|
| +SkBitmap ResizeBitmapByDownsamplingIfPossible(
|
| + const std::vector<SkBitmap>& input_bitmaps,
|
| + int desired_size) {
|
| + DCHECK_NE(0, desired_size);
|
| +
|
| + if (input_bitmaps.empty())
|
| + return SkBitmap();
|
| +
|
| + SkBitmap best_bitmap;
|
| + for (size_t i = 0; i < input_bitmaps.size(); ++i) {
|
| + const SkBitmap& input_bitmap = input_bitmaps[i];
|
| + if (input_bitmap.width() == desired_size &&
|
| + input_bitmap.height() == desired_size) {
|
| + return input_bitmap;
|
| + } else if (best_bitmap.isNull()) {
|
| + best_bitmap = input_bitmap;
|
| + } else if (input_bitmap.width() >= best_bitmap.width() &&
|
| + input_bitmap.height() >= best_bitmap.height()) {
|
| + if (best_bitmap.width() < desired_size ||
|
| + best_bitmap.height() < desired_size) {
|
| + best_bitmap = input_bitmap;
|
| + }
|
| + } else {
|
| + if (input_bitmap.width() >= desired_size &&
|
| + input_bitmap.height() >= desired_size) {
|
| + best_bitmap = input_bitmap;
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (desired_size % best_bitmap.width() == 0 &&
|
| + desired_size % best_bitmap.height() == 0) {
|
| + // Use nearest neighbour resampling if upsampling by an integer. This
|
| + // makes the result look similar to the result of SelectFaviconFrames().
|
| + SkBitmap bitmap;
|
| + bitmap.allocN32Pixels(desired_size, desired_size);
|
| + if (!best_bitmap.isOpaque())
|
| + bitmap.eraseARGB(0, 0, 0, 0);
|
| +
|
| + SkCanvas canvas(bitmap);
|
| + canvas.drawBitmapRect(
|
| + best_bitmap, SkRect::MakeIWH(desired_size, desired_size), NULL);
|
| + return bitmap;
|
| + }
|
| + return skia::ImageOperations::Resize(best_bitmap,
|
| + skia::ImageOperations::RESIZE_LANCZOS3,
|
| + desired_size,
|
| + desired_size);
|
| +}
|
| +
|
| } // namespace favicon_base
|
|
|