OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 extern "C" { | 24 extern "C" { |
25 #endif | 25 #endif |
26 | 26 |
27 // Copy a plane of data | 27 // Copy a plane of data |
28 LIBYUV_API | 28 LIBYUV_API |
29 void CopyPlane(const uint8* src_y, int src_stride_y, | 29 void CopyPlane(const uint8* src_y, int src_stride_y, |
30 uint8* dst_y, int dst_stride_y, | 30 uint8* dst_y, int dst_stride_y, |
31 int width, int height) { | 31 int width, int height) { |
32 int y; | 32 int y; |
33 void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; | 33 void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; |
34 // Negative height means invert the image. | |
fbarchard1
2016/08/24 23:04:11
this change isnt needed? remove
fbarchard1
2016/08/24 23:11:50
Acknowledged. Currently needed in this CL and con
| |
35 if (height < 0) { | |
36 height = -height; | |
37 dst_y = dst_y + (height - 1) * dst_stride_y; | |
38 dst_stride_y = -dst_stride_y; | |
39 } | |
34 // Coalesce rows. | 40 // Coalesce rows. |
35 if (src_stride_y == width && | 41 if (src_stride_y == width && |
36 dst_stride_y == width) { | 42 dst_stride_y == width) { |
37 width *= height; | 43 width *= height; |
38 height = 1; | 44 height = 1; |
39 src_stride_y = dst_stride_y = 0; | 45 src_stride_y = dst_stride_y = 0; |
40 } | 46 } |
41 // Nothing to do. | 47 // Nothing to do. |
42 if (src_y == dst_y && src_stride_y == dst_stride_y) { | 48 if (src_y == dst_y && src_stride_y == dst_stride_y) { |
43 return; | 49 return; |
(...skipping 2431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2475 // TODO(fbarchard): Consider if width is even Y channel can be split | 2481 // TODO(fbarchard): Consider if width is even Y channel can be split |
2476 // directly. A SplitUVRow_Odd function could copy the remaining chroma. | 2482 // directly. A SplitUVRow_Odd function could copy the remaining chroma. |
2477 | 2483 |
2478 LIBYUV_API | 2484 LIBYUV_API |
2479 int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2, | 2485 int YUY2ToNV12(const uint8* src_yuy2, int src_stride_yuy2, |
2480 uint8* dst_y, int dst_stride_y, | 2486 uint8* dst_y, int dst_stride_y, |
2481 uint8* dst_uv, int dst_stride_uv, | 2487 uint8* dst_uv, int dst_stride_uv, |
2482 int width, int height) { | 2488 int width, int height) { |
2483 int y; | 2489 int y; |
2484 int halfwidth = (width + 1) >> 1; | 2490 int halfwidth = (width + 1) >> 1; |
2485 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, | |
2486 int width) = SplitUVRow_C; | |
2487 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, | 2491 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, |
2488 ptrdiff_t src_stride, int dst_width, | 2492 ptrdiff_t src_stride, int dst_width, |
2489 int source_y_fraction) = InterpolateRow_C; | 2493 int source_y_fraction) = InterpolateRow_C; |
2490 if (!src_yuy2 || | 2494 if (!src_yuy2 || |
2491 !dst_y || !dst_uv || | 2495 !dst_y || !dst_uv || |
2492 width <= 0 || height == 0) { | 2496 width <= 0 || height == 0) { |
2493 return -1; | 2497 return -1; |
2494 } | 2498 } |
2495 // Negative height means invert the image. | 2499 // Negative height means invert the image. |
2496 if (height < 0) { | 2500 if (height < 0) { |
2497 height = -height; | 2501 height = -height; |
2498 src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; | 2502 src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; |
2499 src_stride_yuy2 = -src_stride_yuy2; | 2503 src_stride_yuy2 = -src_stride_yuy2; |
2500 } | 2504 } |
2501 #if defined(HAS_SPLITUVROW_SSE2) | |
2502 if (TestCpuFlag(kCpuHasSSE2)) { | |
2503 SplitUVRow = SplitUVRow_Any_SSE2; | |
2504 if (IS_ALIGNED(width, 16)) { | |
2505 SplitUVRow = SplitUVRow_SSE2; | |
2506 } | |
2507 } | |
2508 #endif | |
2509 #if defined(HAS_SPLITUVROW_AVX2) | |
2510 if (TestCpuFlag(kCpuHasAVX2)) { | |
2511 SplitUVRow = SplitUVRow_Any_AVX2; | |
2512 if (IS_ALIGNED(width, 32)) { | |
2513 SplitUVRow = SplitUVRow_AVX2; | |
2514 } | |
2515 } | |
2516 #endif | |
2517 #if defined(HAS_SPLITUVROW_NEON) | |
2518 if (TestCpuFlag(kCpuHasNEON)) { | |
2519 SplitUVRow = SplitUVRow_Any_NEON; | |
2520 if (IS_ALIGNED(width, 16)) { | |
2521 SplitUVRow = SplitUVRow_NEON; | |
2522 } | |
2523 } | |
2524 #endif | |
2525 #if defined(HAS_INTERPOLATEROW_SSSE3) | 2505 #if defined(HAS_INTERPOLATEROW_SSSE3) |
2526 if (TestCpuFlag(kCpuHasSSSE3)) { | 2506 if (TestCpuFlag(kCpuHasSSSE3)) { |
2527 InterpolateRow = InterpolateRow_Any_SSSE3; | 2507 InterpolateRow = InterpolateRow_Any_SSSE3; |
2528 if (IS_ALIGNED(width, 16)) { | 2508 if (IS_ALIGNED(width, 16)) { |
2529 InterpolateRow = InterpolateRow_SSSE3; | 2509 InterpolateRow = InterpolateRow_SSSE3; |
2530 } | 2510 } |
2531 } | 2511 } |
2532 #endif | 2512 #endif |
2533 #if defined(HAS_INTERPOLATEROW_AVX2) | 2513 #if defined(HAS_INTERPOLATEROW_AVX2) |
2534 if (TestCpuFlag(kCpuHasAVX2)) { | 2514 if (TestCpuFlag(kCpuHasAVX2)) { |
(...skipping 10 matching lines...) Expand all Loading... | |
2545 InterpolateRow = InterpolateRow_NEON; | 2525 InterpolateRow = InterpolateRow_NEON; |
2546 } | 2526 } |
2547 } | 2527 } |
2548 #endif | 2528 #endif |
2549 | 2529 |
2550 { | 2530 { |
2551 int awidth = halfwidth * 2; | 2531 int awidth = halfwidth * 2; |
2552 // row of y and 2 rows of uv | 2532 // row of y and 2 rows of uv |
2553 align_buffer_64(rows, awidth * 3); | 2533 align_buffer_64(rows, awidth * 3); |
2554 | 2534 |
2535 SplitUVRowFunction SplitUVRow = GetOptimizedSplitUVRowFunction( | |
2536 src_yuy2, src_stride_yuy2, | |
2537 rows, awidth, | |
2538 rows, awidth, | |
2539 awidth); | |
2540 | |
2555 for (y = 0; y < height - 1; y += 2) { | 2541 for (y = 0; y < height - 1; y += 2) { |
2556 // Split Y from UV. | 2542 // Split Y from UV. |
2557 SplitUVRow(src_yuy2, rows, rows + awidth, awidth); | 2543 SplitUVRow(src_yuy2, rows, rows + awidth, awidth); |
2558 memcpy(dst_y, rows, width); | 2544 memcpy(dst_y, rows, width); |
2559 SplitUVRow(src_yuy2 + src_stride_yuy2, rows, rows + awidth * 2, awidth); | 2545 SplitUVRow(src_yuy2 + src_stride_yuy2, rows, rows + awidth * 2, awidth); |
2560 memcpy(dst_y + dst_stride_y, rows, width); | 2546 memcpy(dst_y + dst_stride_y, rows, width); |
2561 InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128); | 2547 InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128); |
2562 src_yuy2 += src_stride_yuy2 * 2; | 2548 src_yuy2 += src_stride_yuy2 * 2; |
2563 dst_y += dst_stride_y * 2; | 2549 dst_y += dst_stride_y * 2; |
2564 dst_uv += dst_stride_uv; | 2550 dst_uv += dst_stride_uv; |
2565 } | 2551 } |
2566 if (height & 1) { | 2552 if (height & 1) { |
2567 // Split Y from UV. | 2553 // Split Y from UV. |
2568 SplitUVRow(src_yuy2, rows, dst_uv, awidth); | 2554 SplitUVRow(src_yuy2, rows, rows + awidth, awidth); |
2569 memcpy(dst_y, rows, width); | 2555 memcpy(dst_y, rows, width); |
2556 memcpy(dst_uv, rows + awidth, awidth); | |
fbarchard1
2016/08/24 23:04:11
this change isnt needed? remove.
if this change i
| |
2570 } | 2557 } |
2571 free_aligned_buffer_64(rows); | 2558 free_aligned_buffer_64(rows); |
2572 } | 2559 } |
2573 return 0; | 2560 return 0; |
2574 } | 2561 } |
2575 | 2562 |
2576 LIBYUV_API | 2563 LIBYUV_API |
2577 int UYVYToNV12(const uint8* src_uyvy, int src_stride_uyvy, | 2564 int UYVYToNV12(const uint8* src_uyvy, int src_stride_uyvy, |
2578 uint8* dst_y, int dst_stride_y, | 2565 uint8* dst_y, int dst_stride_y, |
2579 uint8* dst_uv, int dst_stride_uv, | 2566 uint8* dst_uv, int dst_stride_uv, |
2580 int width, int height) { | 2567 int width, int height) { |
2581 int y; | 2568 int y; |
2582 int halfwidth = (width + 1) >> 1; | 2569 int halfwidth = (width + 1) >> 1; |
2583 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, | |
2584 int width) = SplitUVRow_C; | |
2585 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, | 2570 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, |
2586 ptrdiff_t src_stride, int dst_width, | 2571 ptrdiff_t src_stride, int dst_width, |
2587 int source_y_fraction) = InterpolateRow_C; | 2572 int source_y_fraction) = InterpolateRow_C; |
2588 if (!src_uyvy || | 2573 if (!src_uyvy || |
2589 !dst_y || !dst_uv || | 2574 !dst_y || !dst_uv || |
2590 width <= 0 || height == 0) { | 2575 width <= 0 || height == 0) { |
2591 return -1; | 2576 return -1; |
2592 } | 2577 } |
2593 // Negative height means invert the image. | 2578 // Negative height means invert the image. |
2594 if (height < 0) { | 2579 if (height < 0) { |
2595 height = -height; | 2580 height = -height; |
2596 src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; | 2581 src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; |
2597 src_stride_uyvy = -src_stride_uyvy; | 2582 src_stride_uyvy = -src_stride_uyvy; |
2598 } | 2583 } |
2599 #if defined(HAS_SPLITUVROW_SSE2) | |
2600 if (TestCpuFlag(kCpuHasSSE2)) { | |
2601 SplitUVRow = SplitUVRow_Any_SSE2; | |
2602 if (IS_ALIGNED(width, 16)) { | |
2603 SplitUVRow = SplitUVRow_SSE2; | |
2604 } | |
2605 } | |
2606 #endif | |
2607 #if defined(HAS_SPLITUVROW_AVX2) | |
2608 if (TestCpuFlag(kCpuHasAVX2)) { | |
2609 SplitUVRow = SplitUVRow_Any_AVX2; | |
2610 if (IS_ALIGNED(width, 32)) { | |
2611 SplitUVRow = SplitUVRow_AVX2; | |
2612 } | |
2613 } | |
2614 #endif | |
2615 #if defined(HAS_SPLITUVROW_NEON) | |
2616 if (TestCpuFlag(kCpuHasNEON)) { | |
2617 SplitUVRow = SplitUVRow_Any_NEON; | |
2618 if (IS_ALIGNED(width, 16)) { | |
2619 SplitUVRow = SplitUVRow_NEON; | |
2620 } | |
2621 } | |
2622 #endif | |
2623 #if defined(HAS_INTERPOLATEROW_SSSE3) | 2584 #if defined(HAS_INTERPOLATEROW_SSSE3) |
2624 if (TestCpuFlag(kCpuHasSSSE3)) { | 2585 if (TestCpuFlag(kCpuHasSSSE3)) { |
2625 InterpolateRow = InterpolateRow_Any_SSSE3; | 2586 InterpolateRow = InterpolateRow_Any_SSSE3; |
2626 if (IS_ALIGNED(width, 16)) { | 2587 if (IS_ALIGNED(width, 16)) { |
2627 InterpolateRow = InterpolateRow_SSSE3; | 2588 InterpolateRow = InterpolateRow_SSSE3; |
2628 } | 2589 } |
2629 } | 2590 } |
2630 #endif | 2591 #endif |
2631 #if defined(HAS_INTERPOLATEROW_AVX2) | 2592 #if defined(HAS_INTERPOLATEROW_AVX2) |
2632 if (TestCpuFlag(kCpuHasAVX2)) { | 2593 if (TestCpuFlag(kCpuHasAVX2)) { |
(...skipping 10 matching lines...) Expand all Loading... | |
2643 InterpolateRow = InterpolateRow_NEON; | 2604 InterpolateRow = InterpolateRow_NEON; |
2644 } | 2605 } |
2645 } | 2606 } |
2646 #endif | 2607 #endif |
2647 | 2608 |
2648 { | 2609 { |
2649 int awidth = halfwidth * 2; | 2610 int awidth = halfwidth * 2; |
2650 // row of y and 2 rows of uv | 2611 // row of y and 2 rows of uv |
2651 align_buffer_64(rows, awidth * 3); | 2612 align_buffer_64(rows, awidth * 3); |
2652 | 2613 |
2614 SplitUVRowFunction SplitUVRow = GetOptimizedSplitUVRowFunction( | |
2615 src_uyvy, src_stride_uyvy, | |
2616 rows, awidth, | |
2617 rows, awidth, | |
2618 awidth); | |
2619 | |
2653 for (y = 0; y < height - 1; y += 2) { | 2620 for (y = 0; y < height - 1; y += 2) { |
2654 // Split Y from UV. | 2621 // Split Y from UV. |
2655 SplitUVRow(src_uyvy, rows + awidth, rows, awidth); | 2622 SplitUVRow(src_uyvy, rows + awidth, rows, awidth); |
2656 memcpy(dst_y, rows, width); | 2623 memcpy(dst_y, rows, width); |
2657 SplitUVRow(src_uyvy + src_stride_uyvy, rows + awidth * 2, rows, awidth); | 2624 SplitUVRow(src_uyvy + src_stride_uyvy, rows + awidth * 2, rows, awidth); |
2658 memcpy(dst_y + dst_stride_y, rows, width); | 2625 memcpy(dst_y + dst_stride_y, rows, width); |
2659 InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128); | 2626 InterpolateRow(dst_uv, rows + awidth, awidth, awidth, 128); |
2660 src_uyvy += src_stride_uyvy * 2; | 2627 src_uyvy += src_stride_uyvy * 2; |
2661 dst_y += dst_stride_y * 2; | 2628 dst_y += dst_stride_y * 2; |
2662 dst_uv += dst_stride_uv; | 2629 dst_uv += dst_stride_uv; |
2663 } | 2630 } |
2664 if (height & 1) { | 2631 if (height & 1) { |
2665 // Split Y from UV. | 2632 // Split Y from UV. |
2666 SplitUVRow(src_uyvy, dst_uv, rows, awidth); | 2633 SplitUVRow(src_uyvy, rows + awidth, rows, awidth); |
2667 memcpy(dst_y, rows, width); | 2634 memcpy(dst_y, rows, width); |
2635 memcpy(dst_uv, rows + awidth, awidth); | |
2668 } | 2636 } |
2669 free_aligned_buffer_64(rows); | 2637 free_aligned_buffer_64(rows); |
2670 } | 2638 } |
2671 return 0; | 2639 return 0; |
2672 } | 2640 } |
2673 | 2641 |
2674 #ifdef __cplusplus | 2642 #ifdef __cplusplus |
2675 } // extern "C" | 2643 } // extern "C" |
2676 } // namespace libyuv | 2644 } // namespace libyuv |
2677 #endif | 2645 #endif |
OLD | NEW |