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> | 7 #include <set> |
8 | 8 |
9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 }; | 58 }; |
59 | 59 |
60 size_t GetCandidateIndexWithBestScore( | 60 size_t GetCandidateIndexWithBestScore( |
61 const std::vector<gfx::Size>& candidate_sizes_in_pixel, | 61 const std::vector<gfx::Size>& candidate_sizes_in_pixel, |
62 ui::ScaleFactor scale_factor, | 62 ui::ScaleFactor scale_factor, |
63 int desired_size_in_dip, | 63 int desired_size_in_dip, |
64 float* score, | 64 float* score, |
65 ResizeMethod* resize_method) { | 65 ResizeMethod* resize_method) { |
66 DCHECK_NE(desired_size_in_dip, 0); | 66 DCHECK_NE(desired_size_in_dip, 0); |
67 | 67 |
68 float scale = ui::GetScaleFactorScale(scale_factor); | 68 float scale = ui::GetImageScale(scale_factor); |
69 int desired_size_in_pixel = | 69 int desired_size_in_pixel = |
70 static_cast<int>(desired_size_in_dip * scale + 0.5f); | 70 static_cast<int>(desired_size_in_dip * scale + 0.5f); |
71 | 71 |
72 // Try to find an exact match. | 72 // Try to find an exact match. |
73 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) { | 73 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) { |
74 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel && | 74 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel && |
75 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) { | 75 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) { |
76 *score = 1; | 76 *score = 1; |
77 *resize_method = NONE; | 77 *resize_method = NONE; |
78 return i; | 78 return i; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 if (match_score) | 180 if (match_score) |
181 *match_score = total_score / scale_factors.size(); | 181 *match_score = total_score / scale_factors.size(); |
182 } | 182 } |
183 | 183 |
184 // Resize |source_bitmap| using |resize_method|. | 184 // Resize |source_bitmap| using |resize_method|. |
185 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, | 185 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, |
186 int desired_size_in_dip, | 186 int desired_size_in_dip, |
187 ui::ScaleFactor scale_factor, | 187 ui::ScaleFactor scale_factor, |
188 ResizeMethod resize_method) { | 188 ResizeMethod resize_method) { |
189 float scale = ui::GetScaleFactorScale(scale_factor); | 189 float scale = ui::GetImageScale(scale_factor); |
190 int desired_size_in_pixel = static_cast<int>( | 190 int desired_size_in_pixel = static_cast<int>( |
191 desired_size_in_dip * scale + 0.5f); | 191 desired_size_in_dip * scale + 0.5f); |
192 | 192 |
193 switch (resize_method) { | 193 switch (resize_method) { |
194 case NONE: | 194 case NONE: |
195 return source_bitmap; | 195 return source_bitmap; |
196 case SAMPLE_NEAREST_NEIGHBOUR: | 196 case SAMPLE_NEAREST_NEIGHBOUR: |
197 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel); | 197 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel); |
198 case LANCZOS: | 198 case LANCZOS: |
199 return skia::ImageOperations::Resize( | 199 return skia::ImageOperations::Resize( |
(...skipping 18 matching lines...) Expand all Loading... |
218 std::vector<SelectionResult> results; | 218 std::vector<SelectionResult> results; |
219 GetCandidateIndicesWithBestScores(candidate_sizes, scale_factors, | 219 GetCandidateIndicesWithBestScores(candidate_sizes, scale_factors, |
220 desired_size, match_score, &results); | 220 desired_size, match_score, &results); |
221 | 221 |
222 gfx::ImageSkia multi_image; | 222 gfx::ImageSkia multi_image; |
223 for (size_t i = 0; i < results.size(); ++i) { | 223 for (size_t i = 0; i < results.size(); ++i) { |
224 const SelectionResult& result = results[i]; | 224 const SelectionResult& result = results[i]; |
225 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], | 225 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], |
226 desired_size, result.scale_factor, result.resize_method); | 226 desired_size, result.scale_factor, result.resize_method); |
227 multi_image.AddRepresentation( | 227 multi_image.AddRepresentation( |
228 gfx::ImageSkiaRep(resized_bitmap, result.scale_factor)); | 228 gfx::ImageSkiaRep(resized_bitmap, |
| 229 ui::GetImageScale(result.scale_factor))); |
229 } | 230 } |
230 return multi_image; | 231 return multi_image; |
231 } | 232 } |
232 | 233 |
233 void SelectFaviconFrameIndices( | 234 void SelectFaviconFrameIndices( |
234 const std::vector<gfx::Size>& frame_pixel_sizes, | 235 const std::vector<gfx::Size>& frame_pixel_sizes, |
235 const std::vector<ui::ScaleFactor>& scale_factors, | 236 const std::vector<ui::ScaleFactor>& scale_factors, |
236 int desired_size, | 237 int desired_size, |
237 std::vector<size_t>* best_indices, | 238 std::vector<size_t>* best_indices, |
238 float* match_score) { | 239 float* match_score) { |
239 std::vector<SelectionResult> results; | 240 std::vector<SelectionResult> results; |
240 GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors, | 241 GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors, |
241 desired_size, match_score, &results); | 242 desired_size, match_score, &results); |
242 | 243 |
243 std::set<size_t> already_added; | 244 std::set<size_t> already_added; |
244 for (size_t i = 0; i < results.size(); ++i) { | 245 for (size_t i = 0; i < results.size(); ++i) { |
245 size_t index = results[i].index; | 246 size_t index = results[i].index; |
246 // GetCandidateIndicesWithBestScores() will return duplicate indices if the | 247 // GetCandidateIndicesWithBestScores() will return duplicate indices if the |
247 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple | 248 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple |
248 // scale factors. Remove duplicates here such that |best_indices| contains | 249 // scale factors. Remove duplicates here such that |best_indices| contains |
249 // no duplicates. | 250 // no duplicates. |
250 if (already_added.find(index) == already_added.end()) { | 251 if (already_added.find(index) == already_added.end()) { |
251 already_added.insert(index); | 252 already_added.insert(index); |
252 best_indices->push_back(index); | 253 best_indices->push_back(index); |
253 } | 254 } |
254 } | 255 } |
255 } | 256 } |
OLD | NEW |