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

Side by Side Diff: source/convert.cc

Issue 2267303002: NV12ToI420 use SplitPlane function (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: rename SplitPlane to SplitUVPlane 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
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 src += src_stride_0 + src_stride_1; 221 src += src_stride_0 + src_stride_1;
222 dst += dst_stride * 2; 222 dst += dst_stride * 2;
223 } 223 }
224 if (height & 1) { 224 if (height & 1) {
225 CopyRow(src, dst, width); 225 CopyRow(src, dst, width);
226 } 226 }
227 } 227 }
228 228
229 // Support function for NV12 etc UV channels. 229 // Support function for NV12 etc UV channels.
230 // Width and height are plane sizes (typically half pixel width). 230 // Width and height are plane sizes (typically half pixel width).
231 static void SplitPlane(const uint8* src_uv, int src_stride_uv, 231 static void SplitUVPlane(const uint8* src_uv, int src_stride_uv,
232 uint8* dst_u, int dst_stride_u, 232 uint8* dst_u, int dst_stride_u,
233 uint8* dst_v, int dst_stride_v, 233 uint8* dst_v, int dst_stride_v,
234 int width, int height) { 234 int width, int height) {
235 int y; 235 int y;
236 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, 236 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v,
237 int width) = SplitUVRow_C; 237 int width) = SplitUVRow_C;
238 // Negative height means invert the image. 238 // Negative height means invert the image.
239 if (height < 0) { 239 if (height < 0) {
240 height = -height; 240 height = -height;
241 dst_u = dst_u + (height - 1) * dst_stride_u; 241 dst_u = dst_u + (height - 1) * dst_stride_u;
242 dst_v = dst_v + (height - 1) * dst_stride_v; 242 dst_v = dst_v + (height - 1) * dst_stride_v;
243 dst_stride_u = -dst_stride_u; 243 dst_stride_u = -dst_stride_u;
244 dst_stride_v = -dst_stride_v; 244 dst_stride_v = -dst_stride_v;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // src_stride_m420 is row planar. Normally this will be the width in pixels. 304 // src_stride_m420 is row planar. Normally this will be the width in pixels.
305 // The UV plane is half width, but 2 values, so src_stride_m420 applies to 305 // The UV plane is half width, but 2 values, so src_stride_m420 applies to
306 // this as well as the two Y planes. 306 // this as well as the two Y planes.
307 static int X420ToI420(const uint8* src_y, 307 static int X420ToI420(const uint8* src_y,
308 int src_stride_y0, int src_stride_y1, 308 int src_stride_y0, int src_stride_y1,
309 const uint8* src_uv, int src_stride_uv, 309 const uint8* src_uv, int src_stride_uv,
310 uint8* dst_y, int dst_stride_y, 310 uint8* dst_y, int dst_stride_y,
311 uint8* dst_u, int dst_stride_u, 311 uint8* dst_u, int dst_stride_u,
312 uint8* dst_v, int dst_stride_v, 312 uint8* dst_v, int dst_stride_v,
313 int width, int height) { 313 int width, int height) {
314 int y;
315 int halfwidth = (width + 1) >> 1; 314 int halfwidth = (width + 1) >> 1;
316 int halfheight = (height + 1) >> 1; 315 int halfheight = (height + 1) >> 1;
317 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v,
318 int width) = SplitUVRow_C;
319 if (!src_y || !src_uv || 316 if (!src_y || !src_uv ||
320 !dst_y || !dst_u || !dst_v || 317 !dst_y || !dst_u || !dst_v ||
321 width <= 0 || height == 0) { 318 width <= 0 || height == 0) {
322 return -1; 319 return -1;
323 } 320 }
324 // Negative height means invert the image. 321 // Negative height means invert the image.
325 if (height < 0) { 322 if (height < 0) {
326 height = -height; 323 height = -height;
327 halfheight = (height + 1) >> 1; 324 halfheight = (height + 1) >> 1;
328 dst_y = dst_y + (height - 1) * dst_stride_y; 325 dst_y = dst_y + (height - 1) * dst_stride_y;
(...skipping 12 matching lines...) Expand all
341 src_stride_y0 = src_stride_y1 = dst_stride_y = 0; 338 src_stride_y0 = src_stride_y1 = dst_stride_y = 0;
342 } 339 }
343 // Coalesce rows. 340 // Coalesce rows.
344 if (src_stride_uv == halfwidth * 2 && 341 if (src_stride_uv == halfwidth * 2 &&
345 dst_stride_u == halfwidth && 342 dst_stride_u == halfwidth &&
346 dst_stride_v == halfwidth) { 343 dst_stride_v == halfwidth) {
347 halfwidth *= halfheight; 344 halfwidth *= halfheight;
348 halfheight = 1; 345 halfheight = 1;
349 src_stride_uv = dst_stride_u = dst_stride_v = 0; 346 src_stride_uv = dst_stride_u = dst_stride_v = 0;
350 } 347 }
351 #if defined(HAS_SPLITUVROW_SSE2)
352 if (TestCpuFlag(kCpuHasSSE2)) {
353 SplitUVRow = SplitUVRow_Any_SSE2;
354 if (IS_ALIGNED(halfwidth, 16)) {
355 SplitUVRow = SplitUVRow_SSE2;
356 }
357 }
358 #endif
359 #if defined(HAS_SPLITUVROW_AVX2)
360 if (TestCpuFlag(kCpuHasAVX2)) {
361 SplitUVRow = SplitUVRow_Any_AVX2;
362 if (IS_ALIGNED(halfwidth, 32)) {
363 SplitUVRow = SplitUVRow_AVX2;
364 }
365 }
366 #endif
367 #if defined(HAS_SPLITUVROW_NEON)
368 if (TestCpuFlag(kCpuHasNEON)) {
369 SplitUVRow = SplitUVRow_Any_NEON;
370 if (IS_ALIGNED(halfwidth, 16)) {
371 SplitUVRow = SplitUVRow_NEON;
372 }
373 }
374 #endif
375 #if defined(HAS_SPLITUVROW_DSPR2)
376 if (TestCpuFlag(kCpuHasDSPR2) &&
377 IS_ALIGNED(src_uv, 4) && IS_ALIGNED(src_stride_uv, 4) &&
378 IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) &&
379 IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) {
380 SplitUVRow = SplitUVRow_Any_DSPR2;
381 if (IS_ALIGNED(halfwidth, 16)) {
382 SplitUVRow = SplitUVRow_DSPR2;
383 }
384 }
385 #endif
386 348
387 if (dst_y) { 349 if (dst_y) {
388 if (src_stride_y0 == src_stride_y1) { 350 if (src_stride_y0 == src_stride_y1) {
389 CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); 351 CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height);
390 } else { 352 } else {
391 CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, 353 CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y,
392 width, height); 354 width, height);
393 } 355 }
394 } 356 }
395 357
396 for (y = 0; y < halfheight; ++y) { 358 // Split UV plane - NV12 / NV21
397 // Copy a row of UV. 359 SplitUVPlane(src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v,
398 SplitUVRow(src_uv, dst_u, dst_v, halfwidth); 360 halfwidth, halfheight);
399 dst_u += dst_stride_u; 361
400 dst_v += dst_stride_v;
401 src_uv += src_stride_uv;
402 }
403 return 0; 362 return 0;
404 } 363 }
405 364
406 // Convert NV12 to I420. 365 // Convert NV12 to I420.
407 LIBYUV_API 366 LIBYUV_API
408 int NV12ToI420(const uint8* src_y, int src_stride_y, 367 int NV12ToI420(const uint8* src_y, int src_stride_y,
409 const uint8* src_uv, int src_stride_uv, 368 const uint8* src_uv, int src_stride_uv,
410 uint8* dst_y, int dst_stride_y, 369 uint8* dst_y, int dst_stride_y,
411 uint8* dst_u, int dst_stride_u, 370 uint8* dst_u, int dst_stride_u,
412 uint8* dst_v, int dst_stride_v, 371 uint8* dst_v, int dst_stride_v,
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 } 1457 }
1499 1458
1500 // Copy UV planes as is - I420 1459 // Copy UV planes as is - I420
1501 if (src_pixel_stride_uv == 1) { 1460 if (src_pixel_stride_uv == 1) {
1502 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); 1461 CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight);
1503 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); 1462 CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight);
1504 return 0; 1463 return 0;
1505 // Split UV planes - NV21 1464 // Split UV planes - NV21
1506 } else if (src_pixel_stride_uv == 2 && vu_off == -1 && 1465 } else if (src_pixel_stride_uv == 2 && vu_off == -1 &&
1507 src_stride_u == src_stride_v) { 1466 src_stride_u == src_stride_v) {
1508 SplitPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u, 1467 SplitUVPlane(src_v, src_stride_v, dst_v, dst_stride_v, dst_u, dst_stride_u,
1509 halfwidth, halfheight); 1468 halfwidth, halfheight);
1510 return 0; 1469 return 0;
1511 // Split UV planes - NV12 1470 // Split UV planes - NV12
1512 } else if (src_pixel_stride_uv == 2 && vu_off == 1 && 1471 } else if (src_pixel_stride_uv == 2 && vu_off == 1 &&
1513 src_stride_u == src_stride_v) { 1472 src_stride_u == src_stride_v) {
1514 SplitPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v, 1473 SplitUVPlane(src_u, src_stride_u, dst_u, dst_stride_u, dst_v, dst_stride_v,
1515 halfwidth, halfheight); 1474 halfwidth, halfheight);
1516 return 0; 1475 return 0;
1517 } 1476 }
1518 1477
1519 for (y = 0; y < halfheight; ++y) { 1478 for (y = 0; y < halfheight; ++y) {
1520 SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth); 1479 SplitPixels(src_u, src_pixel_stride_uv, dst_u, halfwidth);
1521 SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth); 1480 SplitPixels(src_v, src_pixel_stride_uv, dst_v, halfwidth);
1522 src_u += src_stride_u; 1481 src_u += src_stride_u;
1523 src_v += src_stride_v; 1482 src_v += src_stride_v;
1524 dst_u += dst_stride_u; 1483 dst_u += dst_stride_u;
1525 dst_v += dst_stride_v; 1484 dst_v += dst_stride_v;
1526 } 1485 }
1527 return 0; 1486 return 0;
1528 } 1487 }
1529 1488
1530 #ifdef __cplusplus 1489 #ifdef __cplusplus
1531 } // extern "C" 1490 } // extern "C"
1532 } // namespace libyuv 1491 } // namespace libyuv
1533 #endif 1492 #endif
OLDNEW
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698