aboutsummaryrefslogtreecommitdiff
path: root/source/planar_functions.cc
diff options
context:
space:
mode:
authorFrank Barchard <fbarchard@google.com>2022-06-09 00:14:11 -0700
committerFrank Barchard <fbarchard@chromium.org>2022-06-09 08:07:50 +0000
commit30f9b280487be412da346aecce7834275020976e (patch)
treec2a25c57cc14465127cdae5b41f07fff517c3d7d /source/planar_functions.cc
parentbaef41447887e1a17897a4cb6ccc854ef3a9d652 (diff)
downloadlibyuv-30f9b280487be412da346aecce7834275020976e.tar.gz
Add I210ToI420
Bug: libyuv:931, b/228605787, b/233233302, b/233634772, b/234558395, b/234340482 Change-Id: Ib135d0b4ff17665f6a4ab60edb782a7b314219a4 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/3696042 Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Diffstat (limited to 'source/planar_functions.cc')
-rw-r--r--source/planar_functions.cc159
1 files changed, 126 insertions, 33 deletions
diff --git a/source/planar_functions.cc b/source/planar_functions.cc
index 141db6ef..b5344862 100644
--- a/source/planar_functions.cc
+++ b/source/planar_functions.cc
@@ -35,7 +35,7 @@ void CopyPlane(const uint8_t* src_y,
int height) {
int y;
void (*CopyRow)(const uint8_t* src, uint8_t* dst, int width) = CopyRow_C;
- if (width == 0 || height == 0) {
+ if (width <= 0 || height == 0) {
return;
}
// Negative height means invert the image.
@@ -84,8 +84,6 @@ void CopyPlane(const uint8_t* src_y,
}
}
-// TODO(fbarchard): Consider support for negative height.
-// TODO(fbarchard): Consider stride measured in bytes.
LIBYUV_API
void CopyPlane_16(const uint16_t* src_y,
int src_stride_y,
@@ -93,36 +91,8 @@ void CopyPlane_16(const uint16_t* src_y,
int dst_stride_y,
int width,
int height) {
- int y;
- void (*CopyRow)(const uint16_t* src, uint16_t* dst, int width) = CopyRow_16_C;
- // Coalesce rows.
- if (src_stride_y == width && dst_stride_y == width) {
- width *= height;
- height = 1;
- src_stride_y = dst_stride_y = 0;
- }
-#if defined(HAS_COPYROW_16_SSE2)
- if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32)) {
- CopyRow = CopyRow_16_SSE2;
- }
-#endif
-#if defined(HAS_COPYROW_16_ERMS)
- if (TestCpuFlag(kCpuHasERMS)) {
- CopyRow = CopyRow_16_ERMS;
- }
-#endif
-#if defined(HAS_COPYROW_16_NEON)
- if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) {
- CopyRow = CopyRow_16_NEON;
- }
-#endif
-
- // Copy plane
- for (y = 0; y < height; ++y) {
- CopyRow(src_y, dst_y, width);
- src_y += src_stride_y;
- dst_y += dst_stride_y;
- }
+ CopyPlane((const uint8_t*)src_y, src_stride_y * 2, (uint8_t*)dst_y,
+ dst_stride_y * 2, width * 2, height);
}
// Convert a plane of 16 bit data to 8 bit
@@ -138,6 +108,9 @@ void Convert16To8Plane(const uint16_t* src_y,
void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale,
int width) = Convert16To8Row_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -196,6 +169,9 @@ void Convert8To16Plane(const uint8_t* src_y,
void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int scale,
int width) = Convert8To16Row_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -470,6 +446,9 @@ void SplitUVPlane(const uint8_t* src_uv,
int y;
void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v,
int width) = SplitUVRow_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -547,6 +526,9 @@ void MergeUVPlane(const uint8_t* src_u,
int y;
void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v,
uint8_t* dst_uv, int width) = MergeUVRow_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -626,6 +608,9 @@ void SplitUVPlane_16(const uint16_t* src_uv,
void (*SplitUVRow_16)(const uint16_t* src_uv, uint16_t* dst_u,
uint16_t* dst_v, int depth, int width) =
SplitUVRow_16_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -683,6 +668,9 @@ void MergeUVPlane_16(const uint16_t* src_u,
MergeUVRow_16_C;
assert(depth >= 8);
assert(depth <= 16);
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -735,6 +723,9 @@ void ConvertToMSBPlane_16(const uint16_t* src_y,
int scale = 1 << (16 - depth);
void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale,
int width) = MultiplyRow_16_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -785,6 +776,9 @@ void ConvertToLSBPlane_16(const uint16_t* src_y,
int scale = 1 << depth;
void (*DivideRow)(const uint16_t* src_y, uint16_t* dst_y, int scale,
int width) = DivideRow_16_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -833,6 +827,9 @@ void SwapUVPlane(const uint8_t* src_uv,
int y;
void (*SwapUVRow)(const uint8_t* src_uv, uint8_t* dst_vu, int width) =
SwapUVRow_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -936,6 +933,9 @@ void DetilePlane(const uint8_t* src_y,
assert(tile_height > 0);
assert(src_stride_y > 0);
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -991,6 +991,9 @@ void DetileSplitUVPlane(const uint8_t* src_uv,
assert(tile_height > 0);
assert(src_stride_uv > 0);
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -1046,6 +1049,9 @@ void SplitRGBPlane(const uint8_t* src_rgb,
int y;
void (*SplitRGBRow)(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g,
uint8_t* dst_b, int width) = SplitRGBRow_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Negative height means invert the image.
if (height < 0) {
height = -height;
@@ -1105,6 +1111,9 @@ void MergeRGBPlane(const uint8_t* src_r,
void (*MergeRGBRow)(const uint8_t* src_r, const uint8_t* src_g,
const uint8_t* src_b, uint8_t* dst_rgb, int width) =
MergeRGBRow_C;
+ if (width <= 0 || height == 0) {
+ return;
+ }
// Coalesce rows.
// Negative height means invert the image.
if (height < 0) {
@@ -3059,6 +3068,10 @@ void SetPlane(uint8_t* dst_y,
uint32_t value) {
int y;
void (*SetRow)(uint8_t * dst, uint8_t value, int width) = SetRow_C;
+
+ if (width <= 0 || height == 0) {
+ return;
+ }
if (height < 0) {
height = -height;
dst_y = dst_y + (height - 1) * dst_stride_y;
@@ -4005,6 +4018,86 @@ int InterpolatePlane(const uint8_t* src0,
return 0;
}
+// Interpolate 2 planes by specified amount (0 to 255).
+LIBYUV_API
+int InterpolatePlane_16(const uint16_t* src0,
+ int src_stride0,
+ const uint16_t* src1,
+ int src_stride1,
+ uint16_t* dst,
+ int dst_stride,
+ int width,
+ int height,
+ int interpolation) {
+ int y;
+ void (*InterpolateRow_16)(uint16_t * dst_ptr, const uint16_t* src_ptr,
+ ptrdiff_t src_stride, int dst_width,
+ int source_y_fraction) = InterpolateRow_16_C;
+ if (!src0 || !src1 || !dst || width <= 0 || height == 0) {
+ return -1;
+ }
+ // Negative height means invert the image.
+ if (height < 0) {
+ height = -height;
+ dst = dst + (height - 1) * dst_stride;
+ dst_stride = -dst_stride;
+ }
+ // Coalesce rows.
+ if (src_stride0 == width && src_stride1 == width && dst_stride == width) {
+ width *= height;
+ height = 1;
+ src_stride0 = src_stride1 = dst_stride = 0;
+ }
+#if defined(HAS_INTERPOLATEROW_16_SSSE3)
+ if (TestCpuFlag(kCpuHasSSSE3)) {
+ InterpolateRow_16 = InterpolateRow_16_Any_SSSE3;
+ if (IS_ALIGNED(width, 16)) {
+ InterpolateRow_16 = InterpolateRow_16_SSSE3;
+ }
+ }
+#endif
+#if defined(HAS_INTERPOLATEROW_16_AVX2)
+ if (TestCpuFlag(kCpuHasAVX2)) {
+ InterpolateRow_16 = InterpolateRow_16_Any_AVX2;
+ if (IS_ALIGNED(width, 32)) {
+ InterpolateRow_16 = InterpolateRow_16_AVX2;
+ }
+ }
+#endif
+#if defined(HAS_INTERPOLATEROW_16_NEON)
+ if (TestCpuFlag(kCpuHasNEON)) {
+ InterpolateRow_16 = InterpolateRow_16_Any_NEON;
+ if (IS_ALIGNED(width, 8)) {
+ InterpolateRow_16 = InterpolateRow_16_NEON;
+ }
+ }
+#endif
+#if defined(HAS_INTERPOLATEROW_16_MSA)
+ if (TestCpuFlag(kCpuHasMSA)) {
+ InterpolateRow_16 = InterpolateRow_16_Any_MSA;
+ if (IS_ALIGNED(width, 32)) {
+ InterpolateRow_16 = InterpolateRow_16_MSA;
+ }
+ }
+#endif
+#if defined(HAS_INTERPOLATEROW_16_LSX)
+ if (TestCpuFlag(kCpuHasLSX)) {
+ InterpolateRow_16 = InterpolateRow_16_Any_LSX;
+ if (IS_ALIGNED(width, 32)) {
+ InterpolateRow_16 = InterpolateRow_16_LSX;
+ }
+ }
+#endif
+
+ for (y = 0; y < height; ++y) {
+ InterpolateRow_16(dst, src0, src1 - src0, width, interpolation);
+ src0 += src_stride0;
+ src1 += src_stride1;
+ dst += dst_stride;
+ }
+ return 0;
+}
+
// Interpolate 2 ARGB images by specified amount (0 to 255).
LIBYUV_API
int ARGBInterpolate(const uint8_t* src_argb0,