OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 // arbitrarily add this to the center of the filter array (this won't always | 309 // arbitrarily add this to the center of the filter array (this won't always |
310 // be the center of the filter function since it could get clipped on the | 310 // be the center of the filter function since it could get clipped on the |
311 // edges, but it doesn't matter enough to worry about that case). | 311 // edges, but it doesn't matter enough to worry about that case). |
312 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; | 312 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; |
313 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; | 313 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; |
314 | 314 |
315 // Now it's ready to go. | 315 // Now it's ready to go. |
316 output->AddFilter(src_begin, &fixed_filter_values[0], | 316 output->AddFilter(src_begin, &fixed_filter_values[0], |
317 static_cast<int>(fixed_filter_values->size())); | 317 static_cast<int>(fixed_filter_values->size())); |
318 } | 318 } |
319 | |
320 output->PaddingForSIMD(8); | |
evannier
2011/02/14 23:45:13
At the API layer, this seems wrong to be visible f
fbarchard
2011/02/15 23:16:45
should be 16?
jiesun
2011/02/17 20:17:58
I agree this is ugly, but there is no "finalizefil
jiesun
2011/02/17 20:17:58
16 byte = 8 coefficient because Fixed is short(2by
| |
319 } | 321 } |
320 | 322 |
321 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod( | 323 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod( |
322 ImageOperations::ResizeMethod method) { | 324 ImageOperations::ResizeMethod method) { |
323 // Convert any "Quality Method" into an "Algorithm Method" | 325 // Convert any "Quality Method" into an "Algorithm Method" |
324 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD && | 326 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD && |
325 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) { | 327 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) { |
326 return method; | 328 return method; |
327 } | 329 } |
328 // The call to ImageOperationsGtv::Resize() above took care of | 330 // The call to ImageOperationsGtv::Resize() above took care of |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 src_row += h * row_words; | 456 src_row += h * row_words; |
455 dst_row += result.rowBytes() / 4; | 457 dst_row += result.rowBytes() / 4; |
456 } | 458 } |
457 result.setIsOpaque(img.isOpaque()); | 459 result.setIsOpaque(img.isOpaque()); |
458 return result; | 460 return result; |
459 #else | 461 #else |
460 return SkBitmap(); | 462 return SkBitmap(); |
461 #endif // OS_POSIX && !OS_MACOSX | 463 #endif // OS_POSIX && !OS_MACOSX |
462 } | 464 } |
463 | 465 |
466 #ifdef ARCH_CPU_X86_FAMILY | |
467 #ifdef _MSC_VER | |
468 #include <intrin.h> | |
469 #endif | |
470 #endif | |
471 | |
472 bool ImageOperations::hasSSE2() { | |
473 #ifdef ARCH_CPU_X86_FAMILY | |
474 #ifdef _MSC_VER | |
475 int cpu_info[4] = {-1}; | |
476 __cpuid(cpu_info, 0); | |
477 int num_ids = cpu_info[0]; | |
fbarchard
2011/02/15 23:16:45
is this necessary? i thought everyone that suppor
jiesun
2011/02/17 20:17:58
Done.
| |
478 if (num_ids > 0) { | |
479 __cpuid(cpu_info, 1); | |
480 return (cpu_info[3] & (1<<26)) != 0; | |
481 } | |
482 return false; | |
483 #else | |
484 // TODO(jiesun): This has to be resolved. We could not use skia implementation . | |
485 return true; | |
486 #endif | |
487 #else | |
488 return false; | |
489 #endif | |
490 } | |
491 | |
464 // static | 492 // static |
465 SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source, | 493 SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source, |
466 ResizeMethod method, | 494 ResizeMethod method, |
467 int dest_width, int dest_height, | 495 int dest_width, int dest_height, |
468 const SkIRect& dest_subset) { | 496 const SkIRect& dest_subset) { |
469 // Ensure that the ResizeMethod enumeration is sound. | 497 // Ensure that the ResizeMethod enumeration is sound. |
470 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && | 498 SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) && |
471 (method <= RESIZE_LAST_QUALITY_METHOD)) || | 499 (method <= RESIZE_LAST_QUALITY_METHOD)) || |
472 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && | 500 ((RESIZE_FIRST_ALGORITHM_METHOD <= method) && |
473 (method <= RESIZE_LAST_ALGORITHM_METHOD))); | 501 (method <= RESIZE_LAST_ALGORITHM_METHOD))); |
(...skipping 28 matching lines...) Expand all Loading... | |
502 reinterpret_cast<const uint8*>(source.getPixels()); | 530 reinterpret_cast<const uint8*>(source.getPixels()); |
503 | 531 |
504 // Convolve into the result. | 532 // Convolve into the result. |
505 SkBitmap result; | 533 SkBitmap result; |
506 result.setConfig(SkBitmap::kARGB_8888_Config, | 534 result.setConfig(SkBitmap::kARGB_8888_Config, |
507 dest_subset.width(), dest_subset.height()); | 535 dest_subset.width(), dest_subset.height()); |
508 result.allocPixels(); | 536 result.allocPixels(); |
509 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), | 537 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), |
510 !source.isOpaque(), filter.x_filter(), filter.y_filter(), | 538 !source.isOpaque(), filter.x_filter(), filter.y_filter(), |
511 static_cast<int>(result.rowBytes()), | 539 static_cast<int>(result.rowBytes()), |
512 static_cast<unsigned char*>(result.getPixels())); | 540 static_cast<unsigned char*>(result.getPixels()), hasSSE2()); |
513 | 541 |
514 // Preserve the "opaque" flag for use as an optimization later. | 542 // Preserve the "opaque" flag for use as an optimization later. |
515 result.setIsOpaque(source.isOpaque()); | 543 result.setIsOpaque(source.isOpaque()); |
516 | 544 |
517 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; | 545 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; |
518 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); | 546 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); |
519 | 547 |
520 return result; | 548 return result; |
521 } | 549 } |
522 | 550 |
523 // static | 551 // static |
524 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 552 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
525 ResizeMethod method, | 553 ResizeMethod method, |
526 int dest_width, int dest_height) { | 554 int dest_width, int dest_height) { |
527 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; | 555 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; |
528 return Resize(source, method, dest_width, dest_height, dest_subset); | 556 return Resize(source, method, dest_width, dest_height, dest_subset); |
529 } | 557 } |
530 | 558 |
531 } // namespace skia | 559 } // namespace skia |
OLD | NEW |