Chromium Code Reviews| 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..49af2ee63a32d6e9c56450f2145a753a4d615af6 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,52 @@ favicon_base::FaviconRawBitmapResult ResizeFaviconBitmapResult( |
| return bitmap_result; |
| } |
| +SkBitmap ResizeBitmapByDownsamplingIfPossible( |
| + const std::vector<SkBitmap>& input_bitmaps, |
| + int desired_size) { |
|
pkotwicz
2016/12/19 00:03:29
Now that this function is not in the anonymous nam
jkrcal
2016/12/19 17:07:19
Done.
|
| + 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 favicon_base |