Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: source/convert_from.cc

Issue 2277603004: Add SplitUVPlanes and MergeUVPlanes (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return 0; 361 return 0;
362 } 362 }
363 363
364 LIBYUV_API 364 LIBYUV_API
365 int I420ToNV12(const uint8* src_y, int src_stride_y, 365 int I420ToNV12(const uint8* src_y, int src_stride_y,
366 const uint8* src_u, int src_stride_u, 366 const uint8* src_u, int src_stride_u,
367 const uint8* src_v, int src_stride_v, 367 const uint8* src_v, int src_stride_v,
368 uint8* dst_y, int dst_stride_y, 368 uint8* dst_y, int dst_stride_y,
369 uint8* dst_uv, int dst_stride_uv, 369 uint8* dst_uv, int dst_stride_uv,
370 int width, int height) { 370 int width, int height) {
371 int y; 371 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) { 372 width <= 0 || height == 0) {
379 return -1; 373 return -1;
380 } 374 }
375 int halfwidth = (width + 1) / 2;
376 int halfheight = height > 0 ? (height + 1) / 2 : (height - 1) / 2;
377 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
378 return MergeUVPlanes(src_u, src_stride_u,
379 src_v, src_stride_v,
380 dst_uv, dst_stride_uv,
381 halfwidth, halfheight);
382 }
383
384 LIBYUV_API
385 int MergeUVPlanes(const uint8* src_u, int src_stride_u,
386 const uint8* src_v, int src_stride_v,
387 uint8* dst_uv, int dst_stride_uv,
388 int width, int height) {
389 if (!src_u || !src_v || !dst_uv || width <= 0 || height == 0) {
390 return -1;
391 }
381 // Negative height means invert the image. 392 // Negative height means invert the image.
382 if (height < 0) { 393 if (height < 0) {
383 height = -height; 394 height = -height;
384 halfheight = (height + 1) >> 1; 395 dst_uv = dst_uv + (height - 1) * dst_stride_uv;
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; 396 dst_stride_uv = -dst_stride_uv;
391 } 397 }
392 if (src_stride_y == width && 398 // Coalesce rows.
393 dst_stride_y == width) { 399 if (src_stride_u == width &&
400 src_stride_v == width &&
401 dst_stride_uv == width * 2) {
394 width *= height; 402 width *= height;
395 height = 1; 403 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; 404 src_stride_u = src_stride_v = dst_stride_uv = 0;
405 } 405 }
406 #if defined(HAS_MERGEUVROW_SSE2) 406 MergeUVRowFunction MergeUVRow_ = GetOptimizedMergeUVRowFunction(width);
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 407
431 if (dst_y) { 408 for (int y = 0; y < height; ++y) {
432 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
433 }
434 for (y = 0; y < halfheight; ++y) {
435 // Merge a row of U and V into a row of UV. 409 // Merge a row of U and V into a row of UV.
436 MergeUVRow_(src_u, src_v, dst_uv, halfwidth); 410 MergeUVRow_(src_u, src_v, dst_uv, width);
437 src_u += src_stride_u; 411 src_u += src_stride_u;
438 src_v += src_stride_v; 412 src_v += src_stride_v;
439 dst_uv += dst_stride_uv; 413 dst_uv += dst_stride_uv;
440 } 414 }
441 return 0; 415 return 0;
442 } 416 }
443 417
444 LIBYUV_API 418 LIBYUV_API
445 int I420ToNV21(const uint8* src_y, int src_stride_y, 419 int I420ToNV21(const uint8* src_y, int src_stride_y,
446 const uint8* src_u, int src_stride_u, 420 const uint8* src_u, int src_stride_u,
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 default: 1137 default:
1164 return -1; // unknown fourcc - return failure code. 1138 return -1; // unknown fourcc - return failure code.
1165 } 1139 }
1166 return r; 1140 return r;
1167 } 1141 }
1168 1142
1169 #ifdef __cplusplus 1143 #ifdef __cplusplus
1170 } // extern "C" 1144 } // extern "C"
1171 } // namespace libyuv 1145 } // namespace libyuv
1172 #endif 1146 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698