OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/favicon_base/select_favicon_frames.h" | 5 #include "components/favicon_base/select_favicon_frames.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) { | 36 SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) { |
37 SkBitmap bitmap; | 37 SkBitmap bitmap; |
38 bitmap.allocN32Pixels(desired_size, desired_size); | 38 bitmap.allocN32Pixels(desired_size, desired_size); |
39 if (!contents.isOpaque()) | 39 if (!contents.isOpaque()) |
40 bitmap.eraseARGB(0, 0, 0, 0); | 40 bitmap.eraseARGB(0, 0, 0, 0); |
41 | 41 |
42 { | 42 { |
43 SkCanvas canvas(bitmap); | 43 SkCanvas canvas(bitmap); |
44 SkRect dest(SkRect::MakeWH(desired_size, desired_size)); | 44 canvas.drawBitmapRect( |
45 canvas.drawBitmapRect(contents, NULL, dest); | 45 contents, NULL, |
| 46 SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size))); |
46 } | 47 } |
47 | 48 |
48 return bitmap; | 49 return bitmap; |
49 } | 50 } |
50 | 51 |
51 size_t GetCandidateIndexWithBestScore( | 52 size_t GetCandidateIndexWithBestScore( |
52 const std::vector<gfx::Size>& candidate_sizes, | 53 const std::vector<gfx::Size>& candidate_sizes, |
53 int desired_size, | 54 int desired_size, |
54 float* score) { | 55 float* score) { |
55 DCHECK_NE(desired_size, 0); | 56 DCHECK_NE(desired_size, 0); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 float* score) { | 218 float* score) { |
218 | 219 |
219 const std::vector<float>& favicon_scales = favicon_base::GetFaviconScales(); | 220 const std::vector<float>& favicon_scales = favicon_base::GetFaviconScales(); |
220 std::vector<int> desired_sizes; | 221 std::vector<int> desired_sizes; |
221 | 222 |
222 if (desired_size_in_dip == 0) { | 223 if (desired_size_in_dip == 0) { |
223 desired_sizes.push_back(0); | 224 desired_sizes.push_back(0); |
224 } else { | 225 } else { |
225 for (std::vector<float>::const_iterator iter = favicon_scales.begin(); | 226 for (std::vector<float>::const_iterator iter = favicon_scales.begin(); |
226 iter != favicon_scales.end(); ++iter) { | 227 iter != favicon_scales.end(); ++iter) { |
227 desired_sizes.push_back(ceil(desired_size_in_dip * (*iter))); | 228 desired_sizes.push_back( |
| 229 static_cast<int>(ceil(desired_size_in_dip * (*iter)))); |
228 } | 230 } |
229 } | 231 } |
230 | 232 |
231 std::vector<SelectionResult> results; | 233 std::vector<SelectionResult> results; |
232 GetCandidateIndicesWithBestScores(original_sizes, | 234 GetCandidateIndicesWithBestScores(original_sizes, |
233 desired_sizes, | 235 desired_sizes, |
234 score, | 236 score, |
235 &results); | 237 &results); |
236 if (results.size() == 0) | 238 if (results.size() == 0) |
237 return gfx::ImageSkia(); | 239 return gfx::ImageSkia(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 // GetCandidateIndicesWithBestScores() will return duplicate indices if the | 271 // GetCandidateIndicesWithBestScores() will return duplicate indices if the |
270 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple | 272 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple |
271 // scale factors. Remove duplicates here such that |best_indices| contains | 273 // scale factors. Remove duplicates here such that |best_indices| contains |
272 // no duplicates. | 274 // no duplicates. |
273 if (already_added.find(index) == already_added.end()) { | 275 if (already_added.find(index) == already_added.end()) { |
274 already_added.insert(index); | 276 already_added.insert(index); |
275 best_indices->push_back(index); | 277 best_indices->push_back(index); |
276 } | 278 } |
277 } | 279 } |
278 } | 280 } |
OLD | NEW |