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 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 #endif | 2367 #endif |
2368 | 2368 |
2369 for (y = 0; y < height; ++y) { | 2369 for (y = 0; y < height; ++y) { |
2370 ARGBCopyAlphaRow(src_argb, dst_argb, width); | 2370 ARGBCopyAlphaRow(src_argb, dst_argb, width); |
2371 src_argb += src_stride_argb; | 2371 src_argb += src_stride_argb; |
2372 dst_argb += dst_stride_argb; | 2372 dst_argb += dst_stride_argb; |
2373 } | 2373 } |
2374 return 0; | 2374 return 0; |
2375 } | 2375 } |
2376 | 2376 |
| 2377 // Extract just the alpha channel from ARGB. |
| 2378 LIBYUV_API |
| 2379 int ARGBExtractAlpha(const uint8* src_argb, int src_stride, |
| 2380 uint8* dst_a, int dst_stride, |
| 2381 int width, int height) { |
| 2382 if (!src_argb || !dst_a || width <= 0 || height == 0) { |
| 2383 return -1; |
| 2384 } |
| 2385 // Negative height means invert the image. |
| 2386 if (height < 0) { |
| 2387 height = -height; |
| 2388 src_argb += (height - 1) * src_stride; |
| 2389 src_stride = -src_stride; |
| 2390 } |
| 2391 // Coalesce rows. |
| 2392 if (src_stride == width * 4 && dst_stride == width) { |
| 2393 width *= height; |
| 2394 height = 1; |
| 2395 src_stride = dst_stride = 0; |
| 2396 } |
| 2397 void (*ARGBExtractAlphaRow)(const uint8 *src_argb, uint8 *dst_a, int width) = |
| 2398 ARGBExtractAlphaRow_C; |
| 2399 #if defined(HAS_ARGBEXTRACTALPHAROW_SSE2) |
| 2400 if (TestCpuFlag(kCpuHasSSE2)) { |
| 2401 ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_SSE2 |
| 2402 : ARGBExtractAlphaRow_Any_SSE2; |
| 2403 } |
| 2404 #endif |
| 2405 #if defined(HAS_ARGBEXTRACTALPHAROW_NEON) |
| 2406 if (TestCpuFlag(kCpuHasNEON)) { |
| 2407 ARGBExtractAlphaRow = IS_ALIGNED(width, 8) ? ARGBExtractAlphaRow_NEON |
| 2408 : ARGBExtractAlphaRow_Any_NEON; |
| 2409 } |
| 2410 #endif |
| 2411 |
| 2412 for (int y = 0; y < height; ++y) { |
| 2413 ARGBExtractAlphaRow(src_argb, dst_a, width); |
| 2414 src_argb += src_stride; |
| 2415 dst_a += dst_stride; |
| 2416 } |
| 2417 return 0; |
| 2418 } |
| 2419 |
2377 // Copy a planar Y channel to the alpha channel of a destination ARGB image. | 2420 // Copy a planar Y channel to the alpha channel of a destination ARGB image. |
2378 LIBYUV_API | 2421 LIBYUV_API |
2379 int ARGBCopyYToAlpha(const uint8* src_y, int src_stride_y, | 2422 int ARGBCopyYToAlpha(const uint8* src_y, int src_stride_y, |
2380 uint8* dst_argb, int dst_stride_argb, | 2423 uint8* dst_argb, int dst_stride_argb, |
2381 int width, int height) { | 2424 int width, int height) { |
2382 int y; | 2425 int y; |
2383 void (*ARGBCopyYToAlphaRow)(const uint8* src_y, uint8* dst_argb, int width) = | 2426 void (*ARGBCopyYToAlphaRow)(const uint8* src_y, uint8* dst_argb, int width) = |
2384 ARGBCopyYToAlphaRow_C; | 2427 ARGBCopyYToAlphaRow_C; |
2385 if (!src_y || !dst_argb || width <= 0 || height == 0) { | 2428 if (!src_y || !dst_argb || width <= 0 || height == 0) { |
2386 return -1; | 2429 return -1; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2619 } | 2662 } |
2620 free_aligned_buffer_64(rows); | 2663 free_aligned_buffer_64(rows); |
2621 } | 2664 } |
2622 return 0; | 2665 return 0; |
2623 } | 2666 } |
2624 | 2667 |
2625 #ifdef __cplusplus | 2668 #ifdef __cplusplus |
2626 } // extern "C" | 2669 } // extern "C" |
2627 } // namespace libyuv | 2670 } // namespace libyuv |
2628 #endif | 2671 #endif |
OLD | NEW |