Skip to content

Commit dfaf753

Browse files
eshrubsFrank Barchard
authored andcommitted
NV12 Copy, include scale_uv.h
Bug: None Change-Id: I8148def3f1253913eb62fcc000e5f72704262a17 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2569748 Reviewed-by: Frank Barchard <[email protected]>
1 parent ad89006 commit dfaf753

File tree

7 files changed

+111
-2
lines changed

7 files changed

+111
-2
lines changed

README.chromium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: libyuv
22
URL: http://code.google.com/p/libyuv/
3-
Version: 1767
3+
Version: 1768
44
License: BSD
55
License File: LICENSE
66

include/libyuv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "libyuv/scale.h"
2727
#include "libyuv/scale_argb.h"
2828
#include "libyuv/scale_row.h"
29+
#include "libyuv/scale_uv.h"
2930
#include "libyuv/version.h"
3031
#include "libyuv/video_common.h"
3132

include/libyuv/planar_functions.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ int I444Copy(const uint8_t* src_y,
200200
int width,
201201
int height);
202202

203+
// Copy NV12. Supports inverting.
204+
int NV12Copy(const uint8_t* src_y, int src_stride_y, const uint8_t* src_uv,
205+
int src_stride_uv, uint8_t* dst_y, int dst_stride_y,
206+
uint8_t* dst_uv, int dst_stride_uv, int width, int height);
207+
208+
// Copy NV21. Supports inverting.
209+
int NV21Copy(const uint8_t* src_y, int src_stride_y, const uint8_t* src_vu,
210+
int src_stride_vu, uint8_t* dst_y, int dst_stride_y,
211+
uint8_t* dst_vu, int dst_stride_vu, int width, int height);
212+
203213
// Convert YUY2 to I422.
204214
LIBYUV_API
205215
int YUY2ToI422(const uint8_t* src_yuy2,

include/libyuv/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#ifndef INCLUDE_LIBYUV_VERSION_H_
1212
#define INCLUDE_LIBYUV_VERSION_H_
1313

14-
#define LIBYUV_VERSION 1767
14+
#define LIBYUV_VERSION 1768
1515

1616
#endif // INCLUDE_LIBYUV_VERSION_H_

source/planar_functions.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,39 @@ int I420ToI400(const uint8_t* src_y,
349349
return 0;
350350
}
351351

352+
// Copy NV12. Supports inverting.
353+
int NV12Copy(const uint8_t* src_y, int src_stride_y, const uint8_t* src_uv,
354+
int src_stride_uv, uint8_t* dst_y, int dst_stride_y,
355+
uint8_t* dst_uv, int dst_stride_uv, int width, int height) {
356+
if (!src_y || !dst_y || !src_uv || !dst_uv || width <= 0 || height == 0) {
357+
return -1;
358+
}
359+
360+
int halfwidth = (width + 1) >> 1;
361+
int halfheight = (height + 1) >> 1;
362+
// Negative height means invert the image.
363+
if (height < 0) {
364+
height = -height;
365+
halfheight = (height + 1) >> 1;
366+
src_y = src_y + (height - 1) * src_stride_y;
367+
src_uv = src_uv + (halfheight - 1) * src_stride_uv;
368+
src_stride_y = -src_stride_y;
369+
src_stride_uv = -src_stride_uv;
370+
}
371+
CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
372+
CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, halfwidth * 2,
373+
halfheight);
374+
return 0;
375+
}
376+
377+
// Copy NV21. Supports inverting.
378+
int NV21Copy(const uint8_t* src_y, int src_stride_y, const uint8_t* src_vu,
379+
int src_stride_vu, uint8_t* dst_y, int dst_stride_y,
380+
uint8_t* dst_vu, int dst_stride_vu, int width, int height) {
381+
return NV12Copy(src_y, src_stride_y, src_vu, src_stride_vu, dst_y,
382+
dst_stride_y, dst_vu, dst_stride_vu, width, height);
383+
}
384+
352385
// Support function for NV12 etc UV channels.
353386
// Width and height are plane sizes (typically half pixel width).
354387
LIBYUV_API

unit_test/planar_test.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,4 +3562,68 @@ TEST_F(LibYUVPlanarTest, HalfMergeUVPlane_Opt) {
35623562
free_aligned_buffer_page_end(dst_pixels_uv_c);
35633563
}
35643564

3565+
TEST_F(LibYUVPlanarTest, NV12Copy) {
3566+
const int halfwidth = (benchmark_width_ + 1) >> 1;
3567+
const int halfheight = (benchmark_height_ + 1) >> 1;
3568+
align_buffer_page_end(src_y, benchmark_width_ * benchmark_height_);
3569+
align_buffer_page_end(src_uv, halfwidth * 2 * halfheight);
3570+
align_buffer_page_end(dst_y, benchmark_width_ * benchmark_height_);
3571+
align_buffer_page_end(dst_uv, halfwidth * 2 * halfheight);
3572+
3573+
MemRandomize(src_y, benchmark_width_ * benchmark_height_);
3574+
MemRandomize(src_uv, halfwidth * 2 * halfheight);
3575+
MemRandomize(dst_y, benchmark_width_ * benchmark_height_);
3576+
MemRandomize(dst_uv, halfwidth * 2 * halfheight);
3577+
3578+
for (int i = 0; i < benchmark_iterations_; ++i) {
3579+
NV12Copy(src_y, benchmark_width_, src_uv, halfwidth * 2, dst_y,
3580+
benchmark_width_, dst_uv, halfwidth * 2, benchmark_width_,
3581+
benchmark_height_);
3582+
}
3583+
3584+
for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
3585+
EXPECT_EQ(src_y[i], dst_y[i]);
3586+
}
3587+
for (int i = 0; i < halfwidth * 2 * halfheight; ++i) {
3588+
EXPECT_EQ(src_uv[i], dst_uv[i]);
3589+
}
3590+
3591+
free_aligned_buffer_page_end(src_y);
3592+
free_aligned_buffer_page_end(src_uv);
3593+
free_aligned_buffer_page_end(dst_y);
3594+
free_aligned_buffer_page_end(dst_uv);
3595+
}
3596+
3597+
TEST_F(LibYUVPlanarTest, NV21Copy) {
3598+
const int halfwidth = (benchmark_width_ + 1) >> 1;
3599+
const int halfheight = (benchmark_height_ + 1) >> 1;
3600+
align_buffer_page_end(src_y, benchmark_width_ * benchmark_height_);
3601+
align_buffer_page_end(src_vu, halfwidth * 2 * halfheight);
3602+
align_buffer_page_end(dst_y, benchmark_width_ * benchmark_height_);
3603+
align_buffer_page_end(dst_vu, halfwidth * 2 * halfheight);
3604+
3605+
MemRandomize(src_y, benchmark_width_ * benchmark_height_);
3606+
MemRandomize(src_vu, halfwidth * 2 * halfheight);
3607+
MemRandomize(dst_y, benchmark_width_ * benchmark_height_);
3608+
MemRandomize(dst_vu, halfwidth * 2 * halfheight);
3609+
3610+
for (int i = 0; i < benchmark_iterations_; ++i) {
3611+
NV21Copy(src_y, benchmark_width_, src_vu, halfwidth * 2, dst_y,
3612+
benchmark_width_, dst_vu, halfwidth * 2, benchmark_width_,
3613+
benchmark_height_);
3614+
}
3615+
3616+
for (int i = 0; i < benchmark_width_ * benchmark_height_; ++i) {
3617+
EXPECT_EQ(src_y[i], dst_y[i]);
3618+
}
3619+
for (int i = 0; i < halfwidth * 2 * halfheight; ++i) {
3620+
EXPECT_EQ(src_vu[i], dst_vu[i]);
3621+
}
3622+
3623+
free_aligned_buffer_page_end(src_y);
3624+
free_aligned_buffer_page_end(src_vu);
3625+
free_aligned_buffer_page_end(dst_y);
3626+
free_aligned_buffer_page_end(dst_vu);
3627+
}
3628+
35653629
} // namespace libyuv

winarm.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ LOCAL_OBJ_FILES = \
3131
source/scale_any.o\
3232
source/scale_argb.o\
3333
source/scale_common.o\
34+
source/scale_uv.o\
3435
source/video_common.o
3536

3637
.cc.o:

0 commit comments

Comments
 (0)