Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: components/favicon_base/select_favicon_frames.cc

Issue 294863002: Cleanup changes related to replacing usage of GetImageScale with GetScaleForScaleFactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing changes to enable high dpi by default from this patch Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "skia/ext/image_operations.h" 10 #include "skia/ext/image_operations.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 enum ResizeMethod { NONE, SAMPLE_NEAREST_NEIGHBOUR, LANCZOS }; 47 enum ResizeMethod { NONE, SAMPLE_NEAREST_NEIGHBOUR, LANCZOS };
48 48
49 size_t GetCandidateIndexWithBestScore( 49 size_t GetCandidateIndexWithBestScore(
50 const std::vector<gfx::Size>& candidate_sizes_in_pixel, 50 const std::vector<gfx::Size>& candidate_sizes_in_pixel,
51 ui::ScaleFactor scale_factor, 51 ui::ScaleFactor scale_factor,
52 int desired_size_in_dip, 52 int desired_size_in_dip,
53 float* score, 53 float* score,
54 ResizeMethod* resize_method) { 54 ResizeMethod* resize_method) {
55 DCHECK_NE(desired_size_in_dip, 0); 55 DCHECK_NE(desired_size_in_dip, 0);
56 56
57 float scale = ui::GetImageScale(scale_factor); 57 float scale = ui::GetScaleForScaleFactor(scale_factor);
58 int desired_size_in_pixel = 58 int desired_size_in_pixel =
59 static_cast<int>(desired_size_in_dip * scale + 0.5f); 59 static_cast<int>(desired_size_in_dip * scale + 0.5f);
60 60
61 // Try to find an exact match. 61 // Try to find an exact match.
62 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) { 62 for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) {
63 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel && 63 if (candidate_sizes_in_pixel[i].width() == desired_size_in_pixel &&
64 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) { 64 candidate_sizes_in_pixel[i].height() == desired_size_in_pixel) {
65 *score = 1; 65 *score = 1;
66 *resize_method = NONE; 66 *resize_method = NONE;
67 return i; 67 return i;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 if (match_score) 176 if (match_score)
177 *match_score = total_score / scale_factors.size(); 177 *match_score = total_score / scale_factors.size();
178 } 178 }
179 179
180 // Resize |source_bitmap| using |resize_method|. 180 // Resize |source_bitmap| using |resize_method|.
181 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap, 181 SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap,
182 int desired_size_in_dip, 182 int desired_size_in_dip,
183 ui::ScaleFactor scale_factor, 183 ui::ScaleFactor scale_factor,
184 ResizeMethod resize_method) { 184 ResizeMethod resize_method) {
185 float scale = ui::GetImageScale(scale_factor); 185 float scale = ui::GetScaleForScaleFactor(scale_factor);
186 int desired_size_in_pixel = 186 int desired_size_in_pixel =
187 static_cast<int>(desired_size_in_dip * scale + 0.5f); 187 static_cast<int>(desired_size_in_dip * scale + 0.5f);
188 188
189 switch (resize_method) { 189 switch (resize_method) {
190 case NONE: 190 case NONE:
191 return source_bitmap; 191 return source_bitmap;
192 case SAMPLE_NEAREST_NEIGHBOUR: 192 case SAMPLE_NEAREST_NEIGHBOUR:
193 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel); 193 return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel);
194 case LANCZOS: 194 case LANCZOS:
195 return skia::ImageOperations::Resize( 195 return skia::ImageOperations::Resize(
(...skipping 20 matching lines...) Expand all
216 original_sizes, scale_factors, desired_size, match_score, &results); 216 original_sizes, scale_factors, desired_size, match_score, &results);
217 217
218 gfx::ImageSkia multi_image; 218 gfx::ImageSkia multi_image;
219 for (size_t i = 0; i < results.size(); ++i) { 219 for (size_t i = 0; i < results.size(); ++i) {
220 const SelectionResult& result = results[i]; 220 const SelectionResult& result = results[i];
221 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index], 221 SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index],
222 desired_size, 222 desired_size,
223 result.scale_factor, 223 result.scale_factor,
224 result.resize_method); 224 result.resize_method);
225 multi_image.AddRepresentation(gfx::ImageSkiaRep( 225 multi_image.AddRepresentation(gfx::ImageSkiaRep(
226 resized_bitmap, ui::GetImageScale(result.scale_factor))); 226 resized_bitmap, ui::GetScaleForScaleFactor(result.scale_factor)));
227 } 227 }
228 return multi_image; 228 return multi_image;
229 } 229 }
230 230
231 void SelectFaviconFrameIndices( 231 void SelectFaviconFrameIndices(
232 const std::vector<gfx::Size>& frame_pixel_sizes, 232 const std::vector<gfx::Size>& frame_pixel_sizes,
233 const std::vector<ui::ScaleFactor>& scale_factors, 233 const std::vector<ui::ScaleFactor>& scale_factors,
234 int desired_size, 234 int desired_size,
235 std::vector<size_t>* best_indices, 235 std::vector<size_t>* best_indices,
236 float* match_score) { 236 float* match_score) {
237 std::vector<SelectionResult> results; 237 std::vector<SelectionResult> results;
238 GetCandidateIndicesWithBestScores( 238 GetCandidateIndicesWithBestScores(
239 frame_pixel_sizes, scale_factors, desired_size, match_score, &results); 239 frame_pixel_sizes, scale_factors, desired_size, match_score, &results);
240 240
241 std::set<size_t> already_added; 241 std::set<size_t> already_added;
242 for (size_t i = 0; i < results.size(); ++i) { 242 for (size_t i = 0; i < results.size(); ++i) {
243 size_t index = results[i].index; 243 size_t index = results[i].index;
244 // GetCandidateIndicesWithBestScores() will return duplicate indices if the 244 // GetCandidateIndicesWithBestScores() will return duplicate indices if the
245 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple 245 // bitmap data with |frame_pixel_sizes[index]| should be used for multiple
246 // scale factors. Remove duplicates here such that |best_indices| contains 246 // scale factors. Remove duplicates here such that |best_indices| contains
247 // no duplicates. 247 // no duplicates.
248 if (already_added.find(index) == already_added.end()) { 248 if (already_added.find(index) == already_added.end()) {
249 already_added.insert(index); 249 already_added.insert(index);
250 best_indices->push_back(index); 250 best_indices->push_back(index);
251 } 251 }
252 } 252 }
253 } 253 }
OLDNEW
« no previous file with comments | « chrome/browser/history/select_favicon_frames_unittest.cc ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698