OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2012 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 src_u += src_stride_u; | 354 src_u += src_stride_u; |
355 src_v += src_stride_v; | 355 src_v += src_stride_v; |
356 dst_uyvy += dst_stride_uyvy * 2; | 356 dst_uyvy += dst_stride_uyvy * 2; |
357 } | 357 } |
358 if (height & 1) { | 358 if (height & 1) { |
359 I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width); | 359 I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width); |
360 } | 360 } |
361 return 0; | 361 return 0; |
362 } | 362 } |
363 | 363 |
| 364 // TODO(fbarchard): test negative height for invert. |
364 LIBYUV_API | 365 LIBYUV_API |
365 int I420ToNV12(const uint8* src_y, int src_stride_y, | 366 int I420ToNV12(const uint8* src_y, int src_stride_y, |
366 const uint8* src_u, int src_stride_u, | 367 const uint8* src_u, int src_stride_u, |
367 const uint8* src_v, int src_stride_v, | 368 const uint8* src_v, int src_stride_v, |
368 uint8* dst_y, int dst_stride_y, | 369 uint8* dst_y, int dst_stride_y, |
369 uint8* dst_uv, int dst_stride_uv, | 370 uint8* dst_uv, int dst_stride_uv, |
370 int width, int height) { | 371 int width, int height) { |
371 int y; | 372 if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || |
372 void (*MergeUVRow_)(const uint8* src_u, const uint8* src_v, uint8* dst_uv, | |
373 int width) = MergeUVRow_C; | |
374 // Coalesce rows. | |
375 int halfwidth = (width + 1) >> 1; | |
376 int halfheight = (height + 1) >> 1; | |
377 if (!src_u || !src_v || !dst_uv || | |
378 width <= 0 || height == 0) { | 373 width <= 0 || height == 0) { |
379 return -1; | 374 return -1; |
380 } | 375 } |
381 // Negative height means invert the image. | 376 int halfwidth = (width + 1) / 2; |
382 if (height < 0) { | 377 int halfheight = height > 0 ? (height + 1) / 2 : (height - 1) / 2; |
383 height = -height; | |
384 halfheight = (height + 1) >> 1; | |
385 if (dst_y) { | |
386 dst_y = dst_y + (height - 1) * dst_stride_y; | |
387 } | |
388 dst_uv = dst_uv + (halfheight - 1) * dst_stride_uv; | |
389 dst_stride_y = -dst_stride_y; | |
390 dst_stride_uv = -dst_stride_uv; | |
391 } | |
392 if (src_stride_y == width && | |
393 dst_stride_y == width) { | |
394 width *= height; | |
395 height = 1; | |
396 src_stride_y = dst_stride_y = 0; | |
397 } | |
398 // Coalesce rows. | |
399 if (src_stride_u == halfwidth && | |
400 src_stride_v == halfwidth && | |
401 dst_stride_uv == halfwidth * 2) { | |
402 halfwidth *= halfheight; | |
403 halfheight = 1; | |
404 src_stride_u = src_stride_v = dst_stride_uv = 0; | |
405 } | |
406 #if defined(HAS_MERGEUVROW_SSE2) | |
407 if (TestCpuFlag(kCpuHasSSE2)) { | |
408 MergeUVRow_ = MergeUVRow_Any_SSE2; | |
409 if (IS_ALIGNED(halfwidth, 16)) { | |
410 MergeUVRow_ = MergeUVRow_SSE2; | |
411 } | |
412 } | |
413 #endif | |
414 #if defined(HAS_MERGEUVROW_AVX2) | |
415 if (TestCpuFlag(kCpuHasAVX2)) { | |
416 MergeUVRow_ = MergeUVRow_Any_AVX2; | |
417 if (IS_ALIGNED(halfwidth, 32)) { | |
418 MergeUVRow_ = MergeUVRow_AVX2; | |
419 } | |
420 } | |
421 #endif | |
422 #if defined(HAS_MERGEUVROW_NEON) | |
423 if (TestCpuFlag(kCpuHasNEON)) { | |
424 MergeUVRow_ = MergeUVRow_Any_NEON; | |
425 if (IS_ALIGNED(halfwidth, 16)) { | |
426 MergeUVRow_ = MergeUVRow_NEON; | |
427 } | |
428 } | |
429 #endif | |
430 | |
431 if (dst_y) { | 378 if (dst_y) { |
432 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); | 379 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); |
433 } | 380 } |
434 for (y = 0; y < halfheight; ++y) { | 381 MergeUVPlane(src_u, src_stride_u, |
435 // Merge a row of U and V into a row of UV. | 382 src_v, src_stride_v, |
436 MergeUVRow_(src_u, src_v, dst_uv, halfwidth); | 383 dst_uv, dst_stride_uv, |
437 src_u += src_stride_u; | 384 halfwidth, halfheight); |
438 src_v += src_stride_v; | |
439 dst_uv += dst_stride_uv; | |
440 } | |
441 return 0; | 385 return 0; |
442 } | 386 } |
443 | 387 |
444 LIBYUV_API | 388 LIBYUV_API |
445 int I420ToNV21(const uint8* src_y, int src_stride_y, | 389 int I420ToNV21(const uint8* src_y, int src_stride_y, |
446 const uint8* src_u, int src_stride_u, | 390 const uint8* src_u, int src_stride_u, |
447 const uint8* src_v, int src_stride_v, | 391 const uint8* src_v, int src_stride_v, |
448 uint8* dst_y, int dst_stride_y, | 392 uint8* dst_y, int dst_stride_y, |
449 uint8* dst_vu, int dst_stride_vu, | 393 uint8* dst_vu, int dst_stride_vu, |
450 int width, int height) { | 394 int width, int height) { |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 default: | 1107 default: |
1164 return -1; // unknown fourcc - return failure code. | 1108 return -1; // unknown fourcc - return failure code. |
1165 } | 1109 } |
1166 return r; | 1110 return r; |
1167 } | 1111 } |
1168 | 1112 |
1169 #ifdef __cplusplus | 1113 #ifdef __cplusplus |
1170 } // extern "C" | 1114 } // extern "C" |
1171 } // namespace libyuv | 1115 } // namespace libyuv |
1172 #endif | 1116 #endif |
OLD | NEW |