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" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // be the center of the filter function since it could get clipped on the | 293 // be the center of the filter function since it could get clipped on the |
294 // edges, but it doesn't matter enough to worry about that case). | 294 // edges, but it doesn't matter enough to worry about that case). |
295 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; | 295 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; |
296 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; | 296 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; |
297 | 297 |
298 // Now it's ready to go. | 298 // Now it's ready to go. |
299 output->AddFilter(src_begin, &fixed_filter_values[0], | 299 output->AddFilter(src_begin, &fixed_filter_values[0], |
300 static_cast<int>(fixed_filter_values->size())); | 300 static_cast<int>(fixed_filter_values->size())); |
301 } | 301 } |
302 | 302 |
303 output->PaddingForSIMD(8); | 303 output->PaddingForSIMD(); |
304 } | 304 } |
305 | 305 |
306 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod( | 306 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod( |
307 ImageOperations::ResizeMethod method) { | 307 ImageOperations::ResizeMethod method) { |
308 // Convert any "Quality Method" into an "Algorithm Method" | 308 // Convert any "Quality Method" into an "Algorithm Method" |
309 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD && | 309 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD && |
310 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) { | 310 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) { |
311 return method; | 311 return method; |
312 } | 312 } |
313 // The call to ImageOperationsGtv::Resize() above took care of | 313 // The call to ImageOperationsGtv::Resize() above took care of |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 ResizeFilter filter(method, source.width(), source.height(), | 502 ResizeFilter filter(method, source.width(), source.height(), |
503 dest_width, dest_height, dest_subset); | 503 dest_width, dest_height, dest_subset); |
504 | 504 |
505 // Get a source bitmap encompassing this touched area. We construct the | 505 // Get a source bitmap encompassing this touched area. We construct the |
506 // offsets and row strides such that it looks like a new bitmap, while | 506 // offsets and row strides such that it looks like a new bitmap, while |
507 // referring to the old data. | 507 // referring to the old data. |
508 const uint8* source_subset = | 508 const uint8* source_subset = |
509 reinterpret_cast<const uint8*>(source.getPixels()); | 509 reinterpret_cast<const uint8*>(source.getPixels()); |
510 | 510 |
511 // Convolve into the result. | 511 // Convolve into the result. |
512 base::CPU cpu; | |
513 SkBitmap result; | 512 SkBitmap result; |
514 result.setConfig(SkBitmap::kARGB_8888_Config, | 513 result.setConfig(SkBitmap::kARGB_8888_Config, |
515 dest_subset.width(), dest_subset.height()); | 514 dest_subset.width(), dest_subset.height()); |
516 result.allocPixels(allocator, NULL); | 515 result.allocPixels(allocator, NULL); |
517 if (!result.readyToDraw()) | 516 if (!result.readyToDraw()) |
518 return SkBitmap(); | 517 return SkBitmap(); |
519 | 518 |
520 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), | 519 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), |
521 !source.isOpaque(), filter.x_filter(), filter.y_filter(), | 520 !source.isOpaque(), filter.x_filter(), filter.y_filter(), |
522 static_cast<int>(result.rowBytes()), | 521 static_cast<int>(result.rowBytes()), |
523 static_cast<unsigned char*>(result.getPixels()), | 522 static_cast<unsigned char*>(result.getPixels()), |
524 cpu.has_sse2()); | 523 true); |
525 | 524 |
526 // Preserve the "opaque" flag for use as an optimization later. | 525 // Preserve the "opaque" flag for use as an optimization later. |
527 result.setIsOpaque(source.isOpaque()); | 526 result.setIsOpaque(source.isOpaque()); |
528 | 527 |
529 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; | 528 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; |
530 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); | 529 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); |
531 | 530 |
532 return result; | 531 return result; |
533 } | 532 } |
534 | 533 |
535 // static | 534 // static |
536 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 535 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
537 ResizeMethod method, | 536 ResizeMethod method, |
538 int dest_width, int dest_height, | 537 int dest_width, int dest_height, |
539 SkBitmap::Allocator* allocator) { | 538 SkBitmap::Allocator* allocator) { |
540 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; | 539 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; |
541 return Resize(source, method, dest_width, dest_height, dest_subset, | 540 return Resize(source, method, dest_width, dest_height, dest_subset, |
542 allocator); | 541 allocator); |
543 } | 542 } |
544 | 543 |
545 } // namespace skia | 544 } // namespace skia |
OLD | NEW |