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 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 dest_width * dest_height); | 338 dest_width * dest_height); |
339 // Ensure that the ResizeMethod enumeration is sound. | 339 // Ensure that the ResizeMethod enumeration is sound. |
340 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && | 340 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && |
341 (method <= RESIZE_LAST_QUALITY_METHOD)) || | 341 (method <= RESIZE_LAST_QUALITY_METHOD)) || |
342 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 342 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
343 (method <= RESIZE_LAST_ALGORITHM_METHOD))); | 343 (method <= RESIZE_LAST_ALGORITHM_METHOD))); |
344 | 344 |
345 // Time how long this takes to see if it's a problem for users. | 345 // Time how long this takes to see if it's a problem for users. |
346 base::TimeTicks resize_start = base::TimeTicks::Now(); | 346 base::TimeTicks resize_start = base::TimeTicks::Now(); |
347 | 347 |
348 SkIRect dest = { 0, 0, dest_width, dest_height }; | |
349 DCHECK(dest.contains(dest_subset)) << | |
350 "The supplied subset does not fall within the destination image."; | |
351 | |
352 // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just | 348 // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just |
353 // return empty. | 349 // return empty. |
354 if (source.width() < 1 || source.height() < 1 || | 350 if (source.width() < 1 || source.height() < 1 || |
355 dest_width < 1 || dest_height < 1) | 351 dest_width < 1 || dest_height < 1) |
356 return SkBitmap(); | 352 return SkBitmap(); |
357 | 353 |
| 354 SkIRect dest = {0, 0, dest_width, dest_height}; |
| 355 DCHECK(dest.contains(dest_subset)) |
| 356 << "The supplied subset does not fall within the destination image."; |
| 357 |
358 method = ResizeMethodToAlgorithmMethod(method); | 358 method = ResizeMethodToAlgorithmMethod(method); |
359 // Check that we deal with an "algorithm methods" from this point onward. | 359 // Check that we deal with an "algorithm methods" from this point onward. |
360 SkASSERT((ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 360 SkASSERT((ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
361 (method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD)); | 361 (method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD)); |
362 | 362 |
363 if (!source.readyToDraw() || source.colorType() != kN32_SkColorType) | 363 if (!source.readyToDraw() || source.colorType() != kN32_SkColorType) |
364 return SkBitmap(); | 364 return SkBitmap(); |
365 | 365 |
366 ResizeFilter filter(method, source.width(), source.height(), | 366 ResizeFilter filter(method, source.width(), source.height(), |
367 dest_width, dest_height, dest_subset); | 367 dest_width, dest_height, dest_subset); |
(...skipping 27 matching lines...) Expand all Loading... |
395 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 395 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
396 ResizeMethod method, | 396 ResizeMethod method, |
397 int dest_width, int dest_height, | 397 int dest_width, int dest_height, |
398 SkBitmap::Allocator* allocator) { | 398 SkBitmap::Allocator* allocator) { |
399 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; | 399 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; |
400 return Resize(source, method, dest_width, dest_height, dest_subset, | 400 return Resize(source, method, dest_width, dest_height, dest_subset, |
401 allocator); | 401 allocator); |
402 } | 402 } |
403 | 403 |
404 } // namespace skia | 404 } // namespace skia |
OLD | NEW |