| 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 #define _USE_MATH_DEFINES | 5 #define _USE_MATH_DEFINES |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "skia/ext/image_operations.h" | 10 #include "skia/ext/image_operations.h" |
| 11 | 11 |
| 12 // TODO(pkasting): skia/ext should not depend on base/! | 12 // TODO(pkasting): skia/ext should not depend on base/! |
| 13 #include "base/containers/stack_container.h" |
| 13 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/stack_container.h" | |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "skia/ext/convolver.h" | 19 #include "skia/ext/convolver.h" |
| 20 #include "third_party/skia/include/core/SkColorPriv.h" | 20 #include "third_party/skia/include/core/SkColorPriv.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "third_party/skia/include/core/SkRect.h" | 22 #include "third_party/skia/include/core/SkRect.h" |
| 23 #include "third_party/skia/include/core/SkFontHost.h" | 23 #include "third_party/skia/include/core/SkFontHost.h" |
| 24 | 24 |
| 25 namespace skia { | 25 namespace skia { |
| 26 | 26 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // When we're doing a magnification, the scale will be larger than one. This | 225 // When we're doing a magnification, the scale will be larger than one. This |
| 226 // means the destination pixels are much smaller than the source pixels, and | 226 // means the destination pixels are much smaller than the source pixels, and |
| 227 // that the range covered by the filter won't necessarily cover any source | 227 // that the range covered by the filter won't necessarily cover any source |
| 228 // pixel boundaries. Therefore, we use these clamped values (max of 1) for | 228 // pixel boundaries. Therefore, we use these clamped values (max of 1) for |
| 229 // some computations. | 229 // some computations. |
| 230 float clamped_scale = std::min(1.0f, scale); | 230 float clamped_scale = std::min(1.0f, scale); |
| 231 | 231 |
| 232 // Speed up the divisions below by turning them into multiplies. | 232 // Speed up the divisions below by turning them into multiplies. |
| 233 float inv_scale = 1.0f / scale; | 233 float inv_scale = 1.0f / scale; |
| 234 | 234 |
| 235 StackVector<float, 64> filter_values; | 235 base::StackVector<float, 64> filter_values; |
| 236 StackVector<int16, 64> fixed_filter_values; | 236 base::StackVector<int16, 64> fixed_filter_values; |
| 237 | 237 |
| 238 // Loop over all pixels in the output range. We will generate one set of | 238 // Loop over all pixels in the output range. We will generate one set of |
| 239 // filter values for each one. Those values will tell us how to blend the | 239 // filter values for each one. Those values will tell us how to blend the |
| 240 // source pixels to compute the destination pixel. | 240 // source pixels to compute the destination pixel. |
| 241 for (int dest_subset_i = dest_subset_lo; dest_subset_i < dest_subset_hi; | 241 for (int dest_subset_i = dest_subset_lo; dest_subset_i < dest_subset_hi; |
| 242 dest_subset_i++) { | 242 dest_subset_i++) { |
| 243 // Reset the arrays. We don't declare them inside so they can re-use the | 243 // Reset the arrays. We don't declare them inside so they can re-use the |
| 244 // same malloc-ed buffer. | 244 // same malloc-ed buffer. |
| 245 filter_values->clear(); | 245 filter_values->clear(); |
| 246 fixed_filter_values->clear(); | 246 fixed_filter_values->clear(); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 532 |
| 533 // static | 533 // static |
| 534 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 534 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
| 535 ResizeMethod method, | 535 ResizeMethod method, |
| 536 int dest_width, int dest_height) { | 536 int dest_width, int dest_height) { |
| 537 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; | 537 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; |
| 538 return Resize(source, method, dest_width, dest_height, dest_subset); | 538 return Resize(source, method, dest_width, dest_height, dest_subset); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace skia | 541 } // namespace skia |
| OLD | NEW |