| 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 "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 float smallest_diff = std::numeric_limits<float>::max(); | 140 float smallest_diff = std::numeric_limits<float>::max(); |
| 141 for (size_t i = 0; i < bitmaps.size(); ++i) { | 141 for (size_t i = 0; i < bitmaps.size(); ++i) { |
| 142 float diff = std::abs(bitmaps[i].width() - desired_width) + | 142 float diff = std::abs(bitmaps[i].width() - desired_width) + |
| 143 std::abs(bitmaps[i].height() - desired_height); | 143 std::abs(bitmaps[i].height() - desired_height); |
| 144 if (diff < smallest_diff) { | 144 if (diff < smallest_diff) { |
| 145 closest_index = i; | 145 closest_index = i; |
| 146 smallest_diff = diff; | 146 smallest_diff = diff; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 if (smallest_diff < std::numeric_limits<float>::max()) { | 149 if (smallest_diff < std::numeric_limits<float>::max()) { |
| 150 *bitmap_scale_factor = bitmaps[closest_index].width() / width(); | 150 *bitmap_scale_factor = static_cast<float>(bitmaps[closest_index].width()) / |
| 151 width(); |
| 151 return bitmaps[closest_index]; | 152 return bitmaps[closest_index]; |
| 152 } | 153 } |
| 153 | 154 |
| 154 return *null_bitmap; | 155 return *null_bitmap; |
| 155 } | 156 } |
| 156 | 157 |
| 157 bool ImageSkia::empty() const { | 158 bool ImageSkia::empty() const { |
| 158 return isNull() || storage_->size().IsEmpty(); | 159 return isNull() || storage_->size().IsEmpty(); |
| 159 } | 160 } |
| 160 | 161 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 storage_ = NULL; | 199 storage_ = NULL; |
| 199 return; | 200 return; |
| 200 } | 201 } |
| 201 storage_ = new internal::ImageSkiaStorage(); | 202 storage_ = new internal::ImageSkiaStorage(); |
| 202 storage_->set_size(gfx::Size(static_cast<int>(bitmap.width() / scale_factor), | 203 storage_->set_size(gfx::Size(static_cast<int>(bitmap.width() / scale_factor), |
| 203 static_cast<int>(bitmap.height() / scale_factor))); | 204 static_cast<int>(bitmap.height() / scale_factor))); |
| 204 storage_->AddBitmap(bitmap); | 205 storage_->AddBitmap(bitmap); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace gfx | 208 } // namespace gfx |
| OLD | NEW |