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

Side by Side Diff: chrome/browser/favicon/select_favicon_frames.cc

Issue 10837278: fix win build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/favicon/select_favicon_frames.h" 5 #include "chrome/browser/favicon/select_favicon_frames.h"
6 6
7 #include "skia/ext/image_operations.h" 7 #include "skia/ext/image_operations.h"
8 #include "ui/gfx/image/image.h" 8 #include "ui/gfx/image/image.h"
9 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 // If that failed, the following special rules apply: 77 // If that failed, the following special rules apply:
78 // 1. 17px-24px images are built from 16px images by adding 78 // 1. 17px-24px images are built from 16px images by adding
79 // a transparent border. 79 // a transparent border.
80 if (desired_size > 16 * scale && desired_size <= 24 * scale) { 80 if (desired_size > 16 * scale && desired_size <= 24 * scale) {
81 int source_size = static_cast<int>(16 * scale + 0.5f); 81 int source_size = static_cast<int>(16 * scale + 0.5f);
82 for (size_t i = 0; i < bitmaps.size(); ++i) { 82 for (size_t i = 0; i < bitmaps.size(); ++i) {
83 if (bitmaps[i].width() == source_size && 83 if (bitmaps[i].width() == source_size &&
84 bitmaps[i].height() == source_size) { 84 bitmaps[i].height() == source_size) {
85 *score = 0.2; 85 *score = 0.2f;
86 return PadWithBorder(bitmaps[i], desired_size, source_size); 86 return PadWithBorder(bitmaps[i], desired_size, source_size);
87 } 87 }
88 } 88 }
89 // Try again, with upsizing the base variant. 89 // Try again, with upsizing the base variant.
90 for (size_t i = 0; i < bitmaps.size(); ++i) { 90 for (size_t i = 0; i < bitmaps.size(); ++i) {
91 if (bitmaps[i].width() * scale == source_size && 91 if (bitmaps[i].width() * scale == source_size &&
92 bitmaps[i].height() * scale == source_size) { 92 bitmaps[i].height() * scale == source_size) {
93 *score = 0.15; 93 *score = 0.15f;
94 return PadWithBorder(bitmaps[i], desired_size, source_size); 94 return PadWithBorder(bitmaps[i], desired_size, source_size);
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 // 2. Integer multiples are built using nearest neighbor sampling. 99 // 2. Integer multiples are built using nearest neighbor sampling.
100 // 3. Else, use Lancosz scaling: 100 // 3. Else, use Lancosz scaling:
101 // b) If available, from the next bigger variant. 101 // b) If available, from the next bigger variant.
102 int candidate = -1; 102 int candidate = -1;
103 int min_area = INT_MAX; 103 int min_area = INT_MAX;
104 for (size_t i = 0; i < bitmaps.size(); ++i) { 104 for (size_t i = 0; i < bitmaps.size(); ++i) {
105 int area = bitmaps[i].width() * bitmaps[i].height(); 105 int area = bitmaps[i].width() * bitmaps[i].height();
106 if (bitmaps[i].width() > desired_size && 106 if (bitmaps[i].width() > desired_size &&
107 bitmaps[i].height() > desired_size && 107 bitmaps[i].height() > desired_size &&
108 (candidate == -1 || area < min_area)) { 108 (candidate == -1 || area < min_area)) {
109 candidate = i; 109 candidate = i;
110 min_area = area; 110 min_area = area;
111 } 111 }
112 } 112 }
113 *score = 0.1; 113 *score = 0.1f;
114 // c) Else, from the biggest smaller variant. 114 // c) Else, from the biggest smaller variant.
115 if (candidate == -1) { 115 if (candidate == -1) {
116 *score = 0; 116 *score = 0;
117 candidate = BiggestCandidate(bitmaps); 117 candidate = BiggestCandidate(bitmaps);
118 } 118 }
119 119
120 const SkBitmap& bitmap = bitmaps[candidate]; 120 const SkBitmap& bitmap = bitmaps[candidate];
121 bool is_integer_multiple = desired_size % bitmap.width() == 0 && 121 bool is_integer_multiple = desired_size % bitmap.width() == 0 &&
122 desired_size % bitmap.height() == 0; 122 desired_size % bitmap.height() == 0;
123 if (is_integer_multiple) 123 if (is_integer_multiple)
(...skipping 13 matching lines...) Expand all
137 gfx::ImageSkia multi_image; 137 gfx::ImageSkia multi_image;
138 if (bitmaps.empty()) 138 if (bitmaps.empty())
139 return multi_image; 139 return multi_image;
140 140
141 if (desired_size == 0) { 141 if (desired_size == 0) {
142 // Just return the biggest image available. 142 // Just return the biggest image available.
143 size_t max_index = BiggestCandidate(bitmaps); 143 size_t max_index = BiggestCandidate(bitmaps);
144 multi_image.AddRepresentation( 144 multi_image.AddRepresentation(
145 gfx::ImageSkiaRep(bitmaps[max_index], ui::SCALE_FACTOR_100P)); 145 gfx::ImageSkiaRep(bitmaps[max_index], ui::SCALE_FACTOR_100P));
146 if (match_score) 146 if (match_score)
147 *match_score = 0.8; 147 *match_score = 0.8f;
148 return multi_image; 148 return multi_image;
149 } 149 }
150 150
151 float total_score = 0; 151 float total_score = 0;
152 for (size_t i = 0; i < scale_factors.size(); ++i) { 152 for (size_t i = 0; i < scale_factors.size(); ++i) {
153 float score; 153 float score;
154 multi_image.AddRepresentation(gfx::ImageSkiaRep( 154 multi_image.AddRepresentation(gfx::ImageSkiaRep(
155 SelectCandidate(bitmaps, desired_size, scale_factors[i], &score), 155 SelectCandidate(bitmaps, desired_size, scale_factors[i], &score),
156 scale_factors[i])); 156 scale_factors[i]));
157 total_score += score; 157 total_score += score;
158 } 158 }
159 159
160 if (match_score) 160 if (match_score)
161 *match_score = total_score / scale_factors.size(); 161 *match_score = total_score / scale_factors.size();
162 return multi_image; 162 return multi_image;
163 } 163 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698