| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/history/select_favicon_frames.h" | 5 #include "chrome/browser/history/select_favicon_frames.h" |
| 6 | 6 |
| 7 #include <set> |
| 8 |
| 7 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
| 10 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 11 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // Return gfx::Size vector with the pixel sizes of |bitmaps|. | 17 // Return gfx::Size vector with the pixel sizes of |bitmaps|. |
| 16 void SizesFromBitmaps(const std::vector<SkBitmap>& bitmaps, | 18 void SizesFromBitmaps(const std::vector<SkBitmap>& bitmaps, |
| 17 std::vector<gfx::Size>* sizes) { | 19 std::vector<gfx::Size>* sizes) { |
| 18 for (size_t i = 0; i < bitmaps.size(); ++i) | 20 for (size_t i = 0; i < bitmaps.size(); ++i) |
| 19 sizes->push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); | 21 sizes->push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); |
| 20 } | 22 } |
| 21 | 23 |
| 22 // Return gfx::Size vector with the pixel sizes of |bitmap_id_sizes|. | |
| 23 void SizesFromFaviconBitmapIDSizes( | |
| 24 const std::vector<history::FaviconBitmapIDSize>& bitmap_id_sizes, | |
| 25 std::vector<gfx::Size>* sizes) { | |
| 26 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) | |
| 27 sizes->push_back(bitmap_id_sizes[i].pixel_size); | |
| 28 } | |
| 29 | |
| 30 size_t BiggestCandidate(const std::vector<gfx::Size>& candidate_sizes) { | 24 size_t BiggestCandidate(const std::vector<gfx::Size>& candidate_sizes) { |
| 31 size_t max_index = 0; | 25 size_t max_index = 0; |
| 32 int max_area = candidate_sizes[0].GetArea(); | 26 int max_area = candidate_sizes[0].GetArea(); |
| 33 for (size_t i = 1; i < candidate_sizes.size(); ++i) { | 27 for (size_t i = 1; i < candidate_sizes.size(); ++i) { |
| 34 int area = candidate_sizes[i].GetArea(); | 28 int area = candidate_sizes[i].GetArea(); |
| 35 if (area > max_area) { | 29 if (area > max_area) { |
| 36 max_area = area; | 30 max_area = area; |
| 37 max_index = i; | 31 max_index = i; |
| 38 } | 32 } |
| 39 } | 33 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 for (size_t i = 0; i < results.size(); ++i) { | 252 for (size_t i = 0; i < results.size(); ++i) { |
| 259 const SelectionResult& result = results[i]; | 253 const SelectionResult& result = results[i]; |
| 260 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], | 254 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], |
| 261 desired_size, result.scale_factor, result.resize_method); | 255 desired_size, result.scale_factor, result.resize_method); |
| 262 multi_image.AddRepresentation( | 256 multi_image.AddRepresentation( |
| 263 gfx::ImageSkiaRep(resized_bitmap, result.scale_factor)); | 257 gfx::ImageSkiaRep(resized_bitmap, result.scale_factor)); |
| 264 } | 258 } |
| 265 return multi_image; | 259 return multi_image; |
| 266 } | 260 } |
| 267 | 261 |
| 268 void SelectFaviconBitmapIDs( | 262 void SelectFaviconFrameIndices( |
| 269 const std::vector<history::FaviconBitmapIDSize>& bitmap_id_sizes, | 263 const std::vector<gfx::Size>& frame_pixel_sizes, |
| 270 const std::vector<ui::ScaleFactor>& scale_factors, | 264 const std::vector<ui::ScaleFactor>& scale_factors, |
| 271 int desired_size, | 265 int desired_size, |
| 272 std::vector<history::FaviconBitmapID>* filtered_favicon_bitmap_ids, | 266 std::vector<size_t>* best_indices, |
| 273 float* match_score) { | 267 float* match_score) { |
| 274 std::vector<gfx::Size> candidate_sizes; | |
| 275 SizesFromFaviconBitmapIDSizes(bitmap_id_sizes, &candidate_sizes); | |
| 276 | |
| 277 std::vector<SelectionResult> results; | 268 std::vector<SelectionResult> results; |
| 278 GetCandidateIndicesWithBestScores(candidate_sizes, scale_factors, | 269 GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors, |
| 279 desired_size, match_score, &results); | 270 desired_size, match_score, &results); |
| 280 | 271 |
| 281 std::set<history::FaviconBitmapID> already_added; | 272 std::set<size_t> already_added; |
| 282 for (size_t i = 0; i < results.size(); ++i) { | 273 for (size_t i = 0; i < results.size(); ++i) { |
| 283 const SelectionResult& result = results[i]; | 274 size_t index = results[i].index; |
| 284 history::FaviconBitmapID bitmap_id = | |
| 285 bitmap_id_sizes[result.index].bitmap_id; | |
| 286 | |
| 287 // GetCandidateIndicesWithBestScores() will return duplicate indices if the | 275 // GetCandidateIndicesWithBestScores() will return duplicate indices if the |
| 288 // bitmap data for a |bitmap_id| should be used for multiple scale factors. | 276 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple |
| 289 // Remove duplicates here such that |filtered_favicon_bitmap_ids| contains | 277 // scale factors. Remove duplicates here such that |best_indices| contains |
| 290 // no duplicates. | 278 // no duplicates. |
| 291 if (already_added.find(bitmap_id) == already_added.end()) { | 279 if (already_added.find(index) == already_added.end()) { |
| 292 already_added.insert(bitmap_id); | 280 already_added.insert(index); |
| 293 filtered_favicon_bitmap_ids->push_back(bitmap_id); | 281 best_indices->push_back(index); |
| 294 } | 282 } |
| 295 } | 283 } |
| 296 } | 284 } |
| OLD | NEW |