Chromium Code Reviews| 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 6fca9adc45f6d3e00310e856495386d691917117..8606862753863e96ccf1f4d01011477f11053622 100644 |
| --- a/chrome/browser/favicon/select_favicon_frames.cc |
| +++ b/chrome/browser/favicon/select_favicon_frames.cc |
| @@ -18,6 +18,13 @@ void SizesFromBitmaps(const std::vector<SkBitmap>& bitmaps, |
| sizes->push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); |
| } |
| +void SizesFromFaviconBitmapIDSizes( |
|
sky
2012/09/04 20:52:29
Add description.
|
| + const std::vector<history::FaviconBitmapIDSize>& bitmap_id_sizes, |
| + std::vector<gfx::Size>* sizes) { |
| + for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) |
| + sizes->push_back(bitmap_id_sizes[i].pixel_size); |
| +} |
| + |
| size_t BiggestCandidate(const std::vector<gfx::Size>& candidate_sizes) { |
| size_t max_index = 0; |
| int max_area = candidate_sizes[0].GetArea(); |
| @@ -139,9 +146,14 @@ size_t GetCandidateIndexWithBestScore( |
| } |
| const gfx::Size& candidate_size = candidate_sizes[candidate_index]; |
| - bool is_integer_multiple = desired_size % candidate_size.width() == 0 && |
| - desired_size % candidate_size.height() == 0; |
| - *resize_method = is_integer_multiple ? SAMPLE_NEAREST_NEIGHBOUR : LANCZOS; |
| + if (candidate_size.IsEmpty()) { |
| + *resize_method = NONE; |
| + } else if (desired_size % candidate_size.width() == 0 && |
| + desired_size % candidate_size.height() == 0) { |
| + *resize_method = SAMPLE_NEAREST_NEIGHBOUR; |
| + } else { |
| + *resize_method = LANCZOS; |
| + } |
| return candidate_index; |
| } |
| @@ -246,3 +258,28 @@ gfx::ImageSkia SelectFaviconFrames( |
| } |
| return multi_image; |
| } |
| + |
| +void SelectFaviconBitmapIDs( |
| + const std::vector<history::FaviconBitmapIDSize>& bitmap_id_sizes, |
| + const std::vector<ui::ScaleFactor>& scale_factors, |
| + int desired_size, |
| + std::vector<history::FaviconBitmapID>* filtered_favicon_bitmap_ids, |
| + float* match_score) { |
| + std::vector<gfx::Size> candidate_sizes; |
| + SizesFromFaviconBitmapIDSizes(bitmap_id_sizes, &candidate_sizes); |
| + |
| + std::vector<SelectionResult> results; |
| + GetCandidateIndicesWithBestScores(candidate_sizes, scale_factors, |
| + desired_size, match_score, &results); |
| + |
| + std::set<history::FaviconBitmapID> already_added; |
| + for (size_t i = 0; i < results.size(); ++i) { |
| + const SelectionResult& result = results[i]; |
| + history::FaviconBitmapID bitmap_id = |
| + bitmap_id_sizes[result.index].bitmap_id; |
| + if (already_added.find(bitmap_id) == already_added.end()) { |
| + already_added.insert(bitmap_id); |
| + filtered_favicon_bitmap_ids->push_back(bitmap_id); |
| + } |
| + } |
| +} |