| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 size_t GetCandidateIndexWithBestScore( | 53 size_t GetCandidateIndexWithBestScore( |
| 54 const std::vector<gfx::Size>& candidate_sizes_in_pixel, | 54 const std::vector<gfx::Size>& candidate_sizes_in_pixel, |
| 55 ui::ScaleFactor scale_factor, | 55 ui::ScaleFactor scale_factor, |
| 56 int desired_size_in_dip, | 56 int desired_size_in_dip, |
| 57 float* score, | 57 float* score, |
| 58 ResizeMethod* resize_method) { | 58 ResizeMethod* resize_method) { |
| 59 DCHECK_NE(desired_size_in_dip, 0); | 59 DCHECK_NE(desired_size_in_dip, 0); |
| 60 | 60 |
| 61 float scale = ui::GetImageScale(scale_factor); | 61 float scale = ui::GetScaleFactorScale(scale_factor); |
| 62 int desired_size_in_pixel = | 62 int desired_size_in_pixel = |
| 63 static_cast<int>(desired_size_in_dip * scale + 0.5f); | 63 static_cast<int>(desired_size_in_dip * scale + 0.5f); |
| 64 | 64 |
| 65 // Try to find an exact match. | 65 // Try to find an exact match. |
| 66 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) { | 66 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) { |
| 67 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel && | 67 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel && |
| 68 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) { | 68 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) { |
| 69 *score = 1; | 69 *score = 1; |
| 70 *resize_method = NONE; | 70 *resize_method = NONE; |
| 71 return i; | 71 return i; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 if (match_score) | 173 if (match_score) |
| 174 *match_score = total_score / scale_factors.size(); | 174 *match_score = total_score / scale_factors.size(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Resize |source_bitmap| using |resize_method|. | 177 // Resize |source_bitmap| using |resize_method|. |
| 178 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, | 178 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, |
| 179 int desired_size_in_dip, | 179 int desired_size_in_dip, |
| 180 ui::ScaleFactor scale_factor, | 180 ui::ScaleFactor scale_factor, |
| 181 ResizeMethod resize_method) { | 181 ResizeMethod resize_method) { |
| 182 float scale = ui::GetImageScale(scale_factor); | 182 float scale = ui::GetScaleFactorScale(scale_factor); |
| 183 int desired_size_in_pixel = static_cast<int>( | 183 int desired_size_in_pixel = static_cast<int>( |
| 184 desired_size_in_dip * scale + 0.5f); | 184 desired_size_in_dip * scale + 0.5f); |
| 185 | 185 |
| 186 switch (resize_method) { | 186 switch (resize_method) { |
| 187 case NONE: | 187 case NONE: |
| 188 return source_bitmap; | 188 return source_bitmap; |
| 189 case SAMPLE_NEAREST_NEIGHBOUR: | 189 case SAMPLE_NEAREST_NEIGHBOUR: |
| 190 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel); | 190 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel); |
| 191 case LANCZOS: | 191 case LANCZOS: |
| 192 return skia::ImageOperations::Resize( | 192 return skia::ImageOperations::Resize( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 std::vector<SelectionResult> results; | 209 std::vector<SelectionResult> results; |
| 210 GetCandidateIndicesWithBestScores(original_sizes, scale_factors, | 210 GetCandidateIndicesWithBestScores(original_sizes, scale_factors, |
| 211 desired_size, match_score, &results); | 211 desired_size, match_score, &results); |
| 212 | 212 |
| 213 gfx::ImageSkia multi_image; | 213 gfx::ImageSkia multi_image; |
| 214 for (size_t i = 0; i < results.size(); ++i) { | 214 for (size_t i = 0; i < results.size(); ++i) { |
| 215 const SelectionResult& result = results[i]; | 215 const SelectionResult& result = results[i]; |
| 216 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], | 216 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], |
| 217 desired_size, result.scale_factor, result.resize_method); | 217 desired_size, result.scale_factor, result.resize_method); |
| 218 multi_image.AddRepresentation( | 218 multi_image.AddRepresentation( |
| 219 gfx::ImageSkiaRep(resized_bitmap, | 219 gfx::ImageSkiaRep(resized_bitmap, result.scale_factor)); |
| 220 ui::GetImageScale(result.scale_factor))); | |
| 221 } | 220 } |
| 222 return multi_image; | 221 return multi_image; |
| 223 } | 222 } |
| 224 | 223 |
| 225 void SelectFaviconFrameIndices( | 224 void SelectFaviconFrameIndices( |
| 226 const std::vector<gfx::Size>& frame_pixel_sizes, | 225 const std::vector<gfx::Size>& frame_pixel_sizes, |
| 227 const std::vector<ui::ScaleFactor>& scale_factors, | 226 const std::vector<ui::ScaleFactor>& scale_factors, |
| 228 int desired_size, | 227 int desired_size, |
| 229 std::vector<size_t>* best_indices, | 228 std::vector<size_t>* best_indices, |
| 230 float* match_score) { | 229 float* match_score) { |
| 231 std::vector<SelectionResult> results; | 230 std::vector<SelectionResult> results; |
| 232 GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors, | 231 GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors, |
| 233 desired_size, match_score, &results); | 232 desired_size, match_score, &results); |
| 234 | 233 |
| 235 std::set<size_t> already_added; | 234 std::set<size_t> already_added; |
| 236 for (size_t i = 0; i < results.size(); ++i) { | 235 for (size_t i = 0; i < results.size(); ++i) { |
| 237 size_t index = results[i].index; | 236 size_t index = results[i].index; |
| 238 // GetCandidateIndicesWithBestScores() will return duplicate indices if the | 237 // GetCandidateIndicesWithBestScores() will return duplicate indices if the |
| 239 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple | 238 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple |
| 240 // scale factors. Remove duplicates here such that |best_indices| contains | 239 // scale factors. Remove duplicates here such that |best_indices| contains |
| 241 // no duplicates. | 240 // no duplicates. |
| 242 if (already_added.find(index) == already_added.end()) { | 241 if (already_added.find(index) == already_added.end()) { |
| 243 already_added.insert(index); | 242 already_added.insert(index); |
| 244 best_indices->push_back(index); | 243 best_indices->push_back(index); |
| 245 } | 244 } |
| 246 } | 245 } |
| 247 } | 246 } |
| OLD | NEW |