forked from microsoft/winrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2001-Fixing-NV12-to-I420-conversion-with-strides-and-gap.patch
76 lines (73 loc) · 3.31 KB
/
2001-Fixing-NV12-to-I420-conversion-with-strides-and-gap.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
From 144df9fb8e4dbc56130b276291ee0d8513313c81 Mon Sep 17 00:00:00 2001
From: Augusto Righetto <[email protected]>
Date: Tue, 9 Jun 2020 08:59:05 -0700
Subject: [PATCH] Fixing NV12 to I420 conversion with strides and gap
---
include/libyuv/convert.h | 3 +++
source/convert_to_i420.cc | 19 ++++++++++---------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/include/libyuv/convert.h b/include/libyuv/convert.h
index f571142f..b4534f14 100644
--- a/include/libyuv/convert.h
+++ b/include/libyuv/convert.h
@@ -481,6 +481,9 @@ int MJPGSize(const uint8_t* sample,
LIBYUV_API
int ConvertToI420(const uint8_t* sample,
size_t sample_size,
+ int src_stride_y,
+ const uint8_t* src_uv,
+ int src_stride_uv,
uint8_t* dst_y,
int dst_stride_y,
uint8_t* dst_u,
diff --git a/source/convert_to_i420.cc b/source/convert_to_i420.cc
index 584be0ac..a95aabed 100644
--- a/source/convert_to_i420.cc
+++ b/source/convert_to_i420.cc
@@ -27,6 +27,9 @@ extern "C" {
LIBYUV_API
int ConvertToI420(const uint8_t* sample,
size_t sample_size,
+ int src_stride_y,
+ const uint8_t* src_uv,
+ int src_stride_uv,
uint8_t* dst_y,
int dst_stride_y,
uint8_t* dst_u,
@@ -44,7 +47,7 @@ int ConvertToI420(const uint8_t* sample,
uint32_t format = CanonicalFourCC(fourcc);
int aligned_src_width = (src_width + 1) & ~1;
const uint8_t* src;
- const uint8_t* src_uv;
+ const uint8_t* src_uv_cropped;
const int abs_src_height = (src_height < 0) ? -src_height : src_height;
// TODO(nisse): Why allow crop_height < 0?
const int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height;
@@ -163,19 +166,17 @@ int ConvertToI420(const uint8_t* sample,
break;
// Biplanar formats
case FOURCC_NV12:
- src = sample + (src_width * crop_y + crop_x);
- src_uv = sample + (src_width * abs_src_height) +
- ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2);
- r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, dst_y,
+ src = sample + (src_stride_y * crop_y + crop_x);
+ src_uv_cropped = src_uv + ((crop_y / 2) * src_stride_uv) + ((crop_x / 2) * 2);
+ r = NV12ToI420Rotate(src, src_stride_y, src_uv_cropped, src_stride_uv, dst_y,
dst_stride_y, dst_u, dst_stride_u, dst_v,
dst_stride_v, crop_width, inv_crop_height, rotation);
break;
case FOURCC_NV21:
- src = sample + (src_width * crop_y + crop_x);
- src_uv = sample + (src_width * abs_src_height) +
- ((crop_y / 2) * aligned_src_width) + ((crop_x / 2) * 2);
+ src = sample + (src_stride_y * crop_y + crop_x);
+ src_uv_cropped = src_uv + ((crop_y / 2) * src_stride_uv) + ((crop_x / 2) * 2);
// Call NV12 but with dst_u and dst_v parameters swapped.
- r = NV12ToI420Rotate(src, src_width, src_uv, aligned_src_width, dst_y,
+ r = NV12ToI420Rotate(src, src_stride_y, src_uv_cropped, src_stride_uv, dst_y,
dst_stride_y, dst_v, dst_stride_v, dst_u,
dst_stride_u, crop_width, inv_crop_height, rotation);
break;
--
2.21.0.windows.1