mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-06 16:56:55 +08:00
Bug: libyuv:928 xed -i scale_gcc.o: SYM ScaleUVRowUp2_Linear_16_SSE2: XDIS 0: LOGICAL SSE2 660FEFED pxor xmm5, xmm5 XDIS 4: SSE SSE2 660F76E4 pcmpeqd xmm4, xmm4 XDIS 8: SSE SSE2 660F72D41F psrld xmm4, 0x1f XDIS d: SSE SSE2 660F72F401 pslld xmm4, 0x1 XDIS 12: DATAXFER SSE2 F30F7E07 movq xmm0, qword ptr [rdi] XDIS 16: DATAXFER SSE2 F30F7E4F04 movq xmm1, qword ptr [rdi+0x4] XDIS 1b: SSE SSE2 660F61C5 punpcklwd xmm0, xmm5 XDIS 1f: SSE SSE2 660F61CD punpcklwd xmm1, xmm5 XDIS 23: DATAXFER SSE2 660F6FD0 movdqa xmm2, xmm0 XDIS 27: DATAXFER SSE2 660F6FD9 movdqa xmm3, xmm1 XDIS 2b: SSE SSE2 660F70D24E pshufd xmm2, xmm2, 0x4e XDIS 30: SSE SSE2 660F70DB4E pshufd xmm3, xmm3, 0x4e XDIS 35: SSE SSE2 660FFED4 paddd xmm2, xmm4 XDIS 39: SSE SSE2 660FFEDC paddd xmm3, xmm4 XDIS 3d: SSE SSE2 660FFED0 paddd xmm2, xmm0 XDIS 41: SSE SSE2 660FFED9 paddd xmm3, xmm1 XDIS 45: SSE SSE2 660FFEC0 paddd xmm0, xmm0 XDIS 49: SSE SSE2 660FFEC9 paddd xmm1, xmm1 XDIS 4d: SSE SSE2 660FFEC2 paddd xmm0, xmm2 XDIS 51: SSE SSE2 660FFECB paddd xmm1, xmm3 XDIS 55: SSE SSE2 660F72D002 psrld xmm0, 0x2 XDIS 5a: SSE SSE2 660F72D102 psrld xmm1, 0x2 XDIS 5f: SSE SSE4 660F382BC1 packusdw xmm0, xmm1 XDIS 64: DATAXFER SSE2 F30F7F06 movdqu xmmword ptr [rsi], xmm0 XDIS 68: MISC BASE 488D7F08 lea rdi, ptr [rdi+0x8] XDIS 6c: MISC BASE 488D7610 lea rsi, ptr [rsi+0x10] XDIS 70: BINARY BASE 83EA04 sub edx, 0x4 XDIS 73: COND_BR BASE 7F9D jnle 0x12 <ScaleUVRowUp2_Linear_16_SSE2+0x12> XDIS 75: RET BASE C3 ret SYM ScaleUVRowUp2_Bilinear_16_SSE2: XDIS 0: LOGICAL SSE2 660FEFFF pxor xmm7, xmm7 XDIS 4: SSE SSE2 660F76F6 pcmpeqd xmm6, xmm6 XDIS 8: SSE SSE2 660F72D61F psrld xmm6, 0x1f XDIS d: SSE SSE2 660F72F603 pslld xmm6, 0x3 XDIS 12: DATAXFER SSE2 F30F7E07 movq xmm0, qword ptr [rdi] XDIS 16: DATAXFER SSE2 F30F7E4F04 movq xmm1, qword ptr [rdi+0x4] XDIS 1b: SSE SSE2 660F61C7 punpcklwd xmm0, xmm7 XDIS 1f: SSE SSE2 660F61CF punpcklwd xmm1, xmm7 XDIS 23: DATAXFER SSE2 660F6FD0 movdqa xmm2, xmm0 XDIS 27: DATAXFER SSE2 660F6FD9 movdqa xmm3, xmm1 XDIS 2b: SSE SSE2 660F70D24E pshufd xmm2, xmm2, 0x4e XDIS 30: SSE SSE2 660F70DB4E pshufd xmm3, xmm3, 0x4e XDIS 35: SSE SSE2 660FFED0 paddd xmm2, xmm0 XDIS 39: SSE SSE2 660FFED9 paddd xmm3, xmm1 XDIS 3d: SSE SSE2 660FFEC0 paddd xmm0, xmm0 XDIS 41: SSE SSE2 660FFEC9 paddd xmm1, xmm1 XDIS 45: SSE SSE2 660FFEC2 paddd xmm0, xmm2 XDIS 49: SSE SSE2 660FFECB paddd xmm1, xmm3 XDIS 4d: DATAXFER SSE2 F30F7E1477 movq xmm2, qword ptr [rdi+rsi*2] XDIS 52: DATAXFER SSE2 F30F7E5C7704 movq xmm3, qword ptr [rdi+rsi*2+0x4] XDIS 58: SSE SSE2 660F61D7 punpcklwd xmm2, xmm7 XDIS 5c: SSE SSE2 660F61DF punpcklwd xmm3, xmm7 XDIS 60: DATAXFER SSE2 660F6FE2 movdqa xmm4, xmm2 XDIS 64: DATAXFER SSE2 660F6FEB movdqa xmm5, xmm3 XDIS 68: SSE SSE2 660F70E44E pshufd xmm4, xmm4, 0x4e XDIS 6d: SSE SSE2 660F70ED4E pshufd xmm5, xmm5, 0x4e XDIS 72: SSE SSE2 660FFEE2 paddd xmm4, xmm2 XDIS 76: SSE SSE2 660FFEEB paddd xmm5, xmm3 XDIS 7a: SSE SSE2 660FFED2 paddd xmm2, xmm2 XDIS 7e: SSE SSE2 660FFEDB paddd xmm3, xmm3 XDIS 82: SSE SSE2 660FFED4 paddd xmm2, xmm4 XDIS 86: SSE SSE2 660FFEDD paddd xmm3, xmm5 XDIS 8a: DATAXFER SSE2 660F6FE0 movdqa xmm4, xmm0 XDIS 8e: DATAXFER SSE2 660F6FEA movdqa xmm5, xmm2 XDIS 92: SSE SSE2 660FFEE0 paddd xmm4, xmm0 XDIS 96: SSE SSE2 660FFEEE paddd xmm5, xmm6 XDIS 9a: SSE SSE2 660FFEE0 paddd xmm4, xmm0 XDIS 9e: SSE SSE2 660FFEE5 paddd xmm4, xmm5 XDIS a2: SSE SSE2 660F72D404 psrld xmm4, 0x4 XDIS a7: DATAXFER SSE2 660F6FEA movdqa xmm5, xmm2 XDIS ab: SSE SSE2 660FFEEA paddd xmm5, xmm2 XDIS af: SSE SSE2 660FFEC6 paddd xmm0, xmm6 XDIS b3: SSE SSE2 660FFEEA paddd xmm5, xmm2 XDIS b7: SSE SSE2 660FFEE8 paddd xmm5, xmm0 XDIS bb: SSE SSE2 660F72D504 psrld xmm5, 0x4 XDIS c0: DATAXFER SSE2 660F6FC1 movdqa xmm0, xmm1 XDIS c4: DATAXFER SSE2 660F6FD3 movdqa xmm2, xmm3 XDIS c8: SSE SSE2 660FFEC1 paddd xmm0, xmm1 XDIS cc: SSE SSE2 660FFED6 paddd xmm2, xmm6 XDIS d0: SSE SSE2 660FFEC1 paddd xmm0, xmm1 XDIS d4: SSE SSE2 660FFEC2 paddd xmm0, xmm2 XDIS d8: SSE SSE2 660F72D004 psrld xmm0, 0x4 XDIS dd: DATAXFER SSE2 660F6FD3 movdqa xmm2, xmm3 XDIS e1: SSE SSE2 660FFED3 paddd xmm2, xmm3 XDIS e5: SSE SSE2 660FFECE paddd xmm1, xmm6 XDIS e9: SSE SSE2 660FFED3 paddd xmm2, xmm3 XDIS ed: SSE SSE2 660FFED1 paddd xmm2, xmm1 XDIS f1: SSE SSE2 660F72D204 psrld xmm2, 0x4 XDIS f6: SSE SSE4 660F382BE0 packusdw xmm4, xmm0 XDIS fb: DATAXFER SSE2 F30F7F22 movdqu xmmword ptr [rdx], xmm4 XDIS ff: SSE SSE4 660F382BEA packusdw xmm5, xmm2 XDIS 104: DATAXFER SSE2 F30F7F2C4A movdqu xmmword ptr [rdx+rcx*2], xmm5 XDIS 109: MISC BASE 488D7F08 lea rdi, ptr [rdi+0x8] XDIS 10d: MISC BASE 488D5210 lea rdx, ptr [rdx+0x10] XDIS 111: BINARY BASE 4183E804 sub r8d, 0x4 XDIS 115: COND_BR BASE 0F8FF7FEFFFF jnle 0x12 <ScaleUVRowUp2_Bilinear_16_SSE2+0x12> XDIS 11b: RET BASE C3 ret Change-Id: Ia20860e9c3c45368822cfd8877167ff0bf973dcc Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/3587602 Reviewed-by: richard winterton <rrwinterton@gmail.com> Commit-Queue: Frank Barchard <fbarchard@chromium.org>
859 lines
27 KiB
C++
859 lines
27 KiB
C++
/*
|
|
* Copyright 2012 The LibYuv Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "libyuv/convert_from.h"
|
|
|
|
#include "libyuv/basic_types.h"
|
|
#include "libyuv/convert.h" // For I420Copy
|
|
#include "libyuv/cpu_id.h"
|
|
#include "libyuv/planar_functions.h"
|
|
#include "libyuv/rotate.h"
|
|
#include "libyuv/row.h"
|
|
#include "libyuv/scale.h" // For ScalePlane()
|
|
#include "libyuv/video_common.h"
|
|
|
|
#ifdef __cplusplus
|
|
namespace libyuv {
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
|
|
static __inline int Abs(int v) {
|
|
return v >= 0 ? v : -v;
|
|
}
|
|
|
|
// I420 To any I4xx YUV format with mirroring.
|
|
// TODO(fbarchard): Consider kFilterNone for Y, or CopyPlane
|
|
|
|
static int I420ToI4xx(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_u,
|
|
int dst_stride_u,
|
|
uint8_t* dst_v,
|
|
int dst_stride_v,
|
|
int src_y_width,
|
|
int src_y_height,
|
|
int dst_uv_width,
|
|
int dst_uv_height) {
|
|
const int dst_y_width = Abs(src_y_width);
|
|
const int dst_y_height = Abs(src_y_height);
|
|
const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1);
|
|
const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1);
|
|
if (src_y_width == 0 || src_y_height == 0 || dst_uv_width <= 0 ||
|
|
dst_uv_height <= 0) {
|
|
return -1;
|
|
}
|
|
if (dst_y) {
|
|
ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y,
|
|
dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear);
|
|
}
|
|
ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u,
|
|
dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear);
|
|
ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v,
|
|
dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear);
|
|
return 0;
|
|
}
|
|
|
|
// Convert 8 bit YUV to 10 bit.
|
|
LIBYUV_API
|
|
int I420ToI010(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint16_t* dst_y,
|
|
int dst_stride_y,
|
|
uint16_t* dst_u,
|
|
int dst_stride_u,
|
|
uint16_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
int halfwidth = (width + 1) >> 1;
|
|
int halfheight = (height + 1) >> 1;
|
|
if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
|
|
height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
halfheight = (height + 1) >> 1;
|
|
src_y = src_y + (height - 1) * src_stride_y;
|
|
src_u = src_u + (halfheight - 1) * src_stride_u;
|
|
src_v = src_v + (halfheight - 1) * src_stride_v;
|
|
src_stride_y = -src_stride_y;
|
|
src_stride_u = -src_stride_u;
|
|
src_stride_v = -src_stride_v;
|
|
}
|
|
|
|
// Convert Y plane.
|
|
Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width,
|
|
height);
|
|
// Convert UV planes.
|
|
Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth,
|
|
halfheight);
|
|
Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth,
|
|
halfheight);
|
|
return 0;
|
|
}
|
|
|
|
// Convert 8 bit YUV to 12 bit.
|
|
LIBYUV_API
|
|
int I420ToI012(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint16_t* dst_y,
|
|
int dst_stride_y,
|
|
uint16_t* dst_u,
|
|
int dst_stride_u,
|
|
uint16_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
int halfwidth = (width + 1) >> 1;
|
|
int halfheight = (height + 1) >> 1;
|
|
if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
|
|
height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
halfheight = (height + 1) >> 1;
|
|
src_y = src_y + (height - 1) * src_stride_y;
|
|
src_u = src_u + (halfheight - 1) * src_stride_u;
|
|
src_v = src_v + (halfheight - 1) * src_stride_v;
|
|
src_stride_y = -src_stride_y;
|
|
src_stride_u = -src_stride_u;
|
|
src_stride_v = -src_stride_v;
|
|
}
|
|
|
|
// Convert Y plane.
|
|
Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 4096, width,
|
|
height);
|
|
// Convert UV planes.
|
|
Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 4096, halfwidth,
|
|
halfheight);
|
|
Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 4096, halfwidth,
|
|
halfheight);
|
|
return 0;
|
|
}
|
|
|
|
// 420 chroma is 1/2 width, 1/2 height
|
|
// 422 chroma is 1/2 width, 1x height
|
|
LIBYUV_API
|
|
int I420ToI422(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_u,
|
|
int dst_stride_u,
|
|
uint8_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
const int dst_uv_width = (Abs(width) + 1) >> 1;
|
|
const int dst_uv_height = Abs(height);
|
|
return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
|
|
src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
|
|
dst_v, dst_stride_v, width, height, dst_uv_width,
|
|
dst_uv_height);
|
|
}
|
|
|
|
// 420 chroma is 1/2 width, 1/2 height
|
|
// 444 chroma is 1x width, 1x height
|
|
LIBYUV_API
|
|
int I420ToI444(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_u,
|
|
int dst_stride_u,
|
|
uint8_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
const int dst_uv_width = Abs(width);
|
|
const int dst_uv_height = Abs(height);
|
|
return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
|
|
src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
|
|
dst_v, dst_stride_v, width, height, dst_uv_width,
|
|
dst_uv_height);
|
|
}
|
|
|
|
// 420 chroma to 444 chroma, 10/12 bit version
|
|
LIBYUV_API
|
|
int I010ToI410(const uint16_t* src_y,
|
|
int src_stride_y,
|
|
const uint16_t* src_u,
|
|
int src_stride_u,
|
|
const uint16_t* src_v,
|
|
int src_stride_v,
|
|
uint16_t* dst_y,
|
|
int dst_stride_y,
|
|
uint16_t* dst_u,
|
|
int dst_stride_u,
|
|
uint16_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
if (width == 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
|
|
if (dst_y) {
|
|
ScalePlane_12(src_y, src_stride_y, width, height, dst_y, dst_stride_y,
|
|
Abs(width), Abs(height), kFilterBilinear);
|
|
}
|
|
ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1),
|
|
SUBSAMPLE(height, 1, 1), dst_u, dst_stride_u, Abs(width),
|
|
Abs(height), kFilterBilinear);
|
|
ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1),
|
|
SUBSAMPLE(height, 1, 1), dst_v, dst_stride_v, Abs(width),
|
|
Abs(height), kFilterBilinear);
|
|
return 0;
|
|
}
|
|
|
|
// 422 chroma to 444 chroma, 10/12 bit version
|
|
LIBYUV_API
|
|
int I210ToI410(const uint16_t* src_y,
|
|
int src_stride_y,
|
|
const uint16_t* src_u,
|
|
int src_stride_u,
|
|
const uint16_t* src_v,
|
|
int src_stride_v,
|
|
uint16_t* dst_y,
|
|
int dst_stride_y,
|
|
uint16_t* dst_u,
|
|
int dst_stride_u,
|
|
uint16_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
if (width == 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
|
|
if (dst_y) {
|
|
ScalePlane_12(src_y, src_stride_y, width, height, dst_y, dst_stride_y,
|
|
Abs(width), Abs(height), kFilterBilinear);
|
|
}
|
|
ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
|
|
dst_stride_u, Abs(width), Abs(height), kFilterBilinear);
|
|
ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
|
|
dst_stride_v, Abs(width), Abs(height), kFilterBilinear);
|
|
return 0;
|
|
}
|
|
|
|
// 422 chroma is 1/2 width, 1x height
|
|
// 444 chroma is 1x width, 1x height
|
|
LIBYUV_API
|
|
int I422ToI444(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_u,
|
|
int dst_stride_u,
|
|
uint8_t* dst_v,
|
|
int dst_stride_v,
|
|
int width,
|
|
int height) {
|
|
if (width == 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
|
|
if (dst_y) {
|
|
ScalePlane(src_y, src_stride_y, width, height, dst_y, dst_stride_y,
|
|
Abs(width), Abs(height), kFilterBilinear);
|
|
}
|
|
ScalePlane(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
|
|
dst_stride_u, Abs(width), Abs(height), kFilterBilinear);
|
|
ScalePlane(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
|
|
dst_stride_v, Abs(width), Abs(height), kFilterBilinear);
|
|
return 0;
|
|
}
|
|
|
|
// Copy to I400. Source can be I420,422,444,400,NV12,NV21
|
|
LIBYUV_API
|
|
int I400Copy(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
int width,
|
|
int height) {
|
|
if (!src_y || !dst_y || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
src_y = src_y + (height - 1) * src_stride_y;
|
|
src_stride_y = -src_stride_y;
|
|
}
|
|
CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I422ToYUY2(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_yuy2,
|
|
int dst_stride_yuy2,
|
|
int width,
|
|
int height) {
|
|
int y;
|
|
void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
|
|
const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
|
|
I422ToYUY2Row_C;
|
|
if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
|
|
dst_stride_yuy2 = -dst_stride_yuy2;
|
|
}
|
|
// Coalesce rows.
|
|
if (src_stride_y == width && src_stride_u * 2 == width &&
|
|
src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) {
|
|
width *= height;
|
|
height = 1;
|
|
src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0;
|
|
}
|
|
#if defined(HAS_I422TOYUY2ROW_SSE2)
|
|
if (TestCpuFlag(kCpuHasSSE2)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_SSE2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_AVX2)
|
|
if (TestCpuFlag(kCpuHasAVX2)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_AVX2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_NEON)
|
|
if (TestCpuFlag(kCpuHasNEON)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_NEON;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for (y = 0; y < height; ++y) {
|
|
I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
|
|
src_y += src_stride_y;
|
|
src_u += src_stride_u;
|
|
src_v += src_stride_v;
|
|
dst_yuy2 += dst_stride_yuy2;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I420ToYUY2(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_yuy2,
|
|
int dst_stride_yuy2,
|
|
int width,
|
|
int height) {
|
|
int y;
|
|
void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
|
|
const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
|
|
I422ToYUY2Row_C;
|
|
if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
|
|
dst_stride_yuy2 = -dst_stride_yuy2;
|
|
}
|
|
#if defined(HAS_I422TOYUY2ROW_SSE2)
|
|
if (TestCpuFlag(kCpuHasSSE2)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_SSE2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_AVX2)
|
|
if (TestCpuFlag(kCpuHasAVX2)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_AVX2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_NEON)
|
|
if (TestCpuFlag(kCpuHasNEON)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_NEON;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_MSA)
|
|
if (TestCpuFlag(kCpuHasMSA)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_MSA;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_MSA;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOYUY2ROW_LASX)
|
|
if (TestCpuFlag(kCpuHasLASX)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_Any_LASX;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToYUY2Row = I422ToYUY2Row_LASX;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for (y = 0; y < height - 1; y += 2) {
|
|
I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
|
|
I422ToYUY2Row(src_y + src_stride_y, src_u, src_v,
|
|
dst_yuy2 + dst_stride_yuy2, width);
|
|
src_y += src_stride_y * 2;
|
|
src_u += src_stride_u;
|
|
src_v += src_stride_v;
|
|
dst_yuy2 += dst_stride_yuy2 * 2;
|
|
}
|
|
if (height & 1) {
|
|
I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I422ToUYVY(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_uyvy,
|
|
int dst_stride_uyvy,
|
|
int width,
|
|
int height) {
|
|
int y;
|
|
void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
|
|
const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
|
|
I422ToUYVYRow_C;
|
|
if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
|
|
dst_stride_uyvy = -dst_stride_uyvy;
|
|
}
|
|
// Coalesce rows.
|
|
if (src_stride_y == width && src_stride_u * 2 == width &&
|
|
src_stride_v * 2 == width && dst_stride_uyvy == width * 2) {
|
|
width *= height;
|
|
height = 1;
|
|
src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0;
|
|
}
|
|
#if defined(HAS_I422TOUYVYROW_SSE2)
|
|
if (TestCpuFlag(kCpuHasSSE2)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_SSE2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_AVX2)
|
|
if (TestCpuFlag(kCpuHasAVX2)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_AVX2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_NEON)
|
|
if (TestCpuFlag(kCpuHasNEON)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_NEON;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_MSA)
|
|
if (TestCpuFlag(kCpuHasMSA)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_MSA;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_MSA;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_LASX)
|
|
if (TestCpuFlag(kCpuHasLASX)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_LASX;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for (y = 0; y < height; ++y) {
|
|
I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
|
|
src_y += src_stride_y;
|
|
src_u += src_stride_u;
|
|
src_v += src_stride_v;
|
|
dst_uyvy += dst_stride_uyvy;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I420ToUYVY(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_uyvy,
|
|
int dst_stride_uyvy,
|
|
int width,
|
|
int height) {
|
|
int y;
|
|
void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
|
|
const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
|
|
I422ToUYVYRow_C;
|
|
if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
|
|
dst_stride_uyvy = -dst_stride_uyvy;
|
|
}
|
|
#if defined(HAS_I422TOUYVYROW_SSE2)
|
|
if (TestCpuFlag(kCpuHasSSE2)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_SSE2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_AVX2)
|
|
if (TestCpuFlag(kCpuHasAVX2)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_AVX2;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_NEON)
|
|
if (TestCpuFlag(kCpuHasNEON)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
|
|
if (IS_ALIGNED(width, 16)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_NEON;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_MSA)
|
|
if (TestCpuFlag(kCpuHasMSA)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_MSA;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_MSA;
|
|
}
|
|
}
|
|
#endif
|
|
#if defined(HAS_I422TOUYVYROW_LASX)
|
|
if (TestCpuFlag(kCpuHasLASX)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
|
|
if (IS_ALIGNED(width, 32)) {
|
|
I422ToUYVYRow = I422ToUYVYRow_LASX;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for (y = 0; y < height - 1; y += 2) {
|
|
I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
|
|
I422ToUYVYRow(src_y + src_stride_y, src_u, src_v,
|
|
dst_uyvy + dst_stride_uyvy, width);
|
|
src_y += src_stride_y * 2;
|
|
src_u += src_stride_u;
|
|
src_v += src_stride_v;
|
|
dst_uyvy += dst_stride_uyvy * 2;
|
|
}
|
|
if (height & 1) {
|
|
I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I420ToNV12(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_uv,
|
|
int dst_stride_uv,
|
|
int width,
|
|
int height) {
|
|
int halfwidth = (width + 1) / 2;
|
|
int halfheight = (height + 1) / 2;
|
|
if (!src_y || !src_u || !src_v || !dst_uv || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
// Negative height means invert the image.
|
|
if (height < 0) {
|
|
height = -height;
|
|
halfheight = (height + 1) >> 1;
|
|
src_y = src_y + (height - 1) * src_stride_y;
|
|
src_u = src_u + (halfheight - 1) * src_stride_u;
|
|
src_v = src_v + (halfheight - 1) * src_stride_v;
|
|
src_stride_y = -src_stride_y;
|
|
src_stride_u = -src_stride_u;
|
|
src_stride_v = -src_stride_v;
|
|
}
|
|
if (dst_y) {
|
|
CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
|
|
}
|
|
MergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, dst_stride_uv,
|
|
halfwidth, halfheight);
|
|
return 0;
|
|
}
|
|
|
|
LIBYUV_API
|
|
int I420ToNV21(const uint8_t* src_y,
|
|
int src_stride_y,
|
|
const uint8_t* src_u,
|
|
int src_stride_u,
|
|
const uint8_t* src_v,
|
|
int src_stride_v,
|
|
uint8_t* dst_y,
|
|
int dst_stride_y,
|
|
uint8_t* dst_vu,
|
|
int dst_stride_vu,
|
|
int width,
|
|
int height) {
|
|
return I420ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u,
|
|
src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu,
|
|
width, height);
|
|
}
|
|
|
|
// Convert I420 to specified format
|
|
LIBYUV_API
|
|
int ConvertFromI420(const uint8_t* y,
|
|
int y_stride,
|
|
const uint8_t* u,
|
|
int u_stride,
|
|
const uint8_t* v,
|
|
int v_stride,
|
|
uint8_t* dst_sample,
|
|
int dst_sample_stride,
|
|
int width,
|
|
int height,
|
|
uint32_t fourcc) {
|
|
uint32_t format = CanonicalFourCC(fourcc);
|
|
int r = 0;
|
|
if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) {
|
|
return -1;
|
|
}
|
|
switch (format) {
|
|
// Single plane formats
|
|
case FOURCC_YUY2:
|
|
r = I420ToYUY2(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 2, width,
|
|
height);
|
|
break;
|
|
case FOURCC_UYVY:
|
|
r = I420ToUYVY(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 2, width,
|
|
height);
|
|
break;
|
|
case FOURCC_RGBP:
|
|
r = I420ToRGB565(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 2, width,
|
|
height);
|
|
break;
|
|
case FOURCC_RGBO:
|
|
r = I420ToARGB1555(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 2,
|
|
width, height);
|
|
break;
|
|
case FOURCC_R444:
|
|
r = I420ToARGB4444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 2,
|
|
width, height);
|
|
break;
|
|
case FOURCC_24BG:
|
|
r = I420ToRGB24(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 3, width,
|
|
height);
|
|
break;
|
|
case FOURCC_RAW:
|
|
r = I420ToRAW(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 3, width,
|
|
height);
|
|
break;
|
|
case FOURCC_ARGB:
|
|
r = I420ToARGB(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 4, width,
|
|
height);
|
|
break;
|
|
case FOURCC_BGRA:
|
|
r = I420ToBGRA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 4, width,
|
|
height);
|
|
break;
|
|
case FOURCC_ABGR:
|
|
r = I420ToABGR(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 4, width,
|
|
height);
|
|
break;
|
|
case FOURCC_RGBA:
|
|
r = I420ToRGBA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 4, width,
|
|
height);
|
|
break;
|
|
case FOURCC_AR30:
|
|
r = I420ToAR30(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width * 4, width,
|
|
height);
|
|
break;
|
|
case FOURCC_I400:
|
|
r = I400Copy(y, y_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width, width,
|
|
height);
|
|
break;
|
|
case FOURCC_NV12: {
|
|
int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
|
|
uint8_t* dst_uv = dst_sample + dst_y_stride * height;
|
|
r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width, dst_uv,
|
|
dst_sample_stride ? dst_sample_stride : width, width,
|
|
height);
|
|
break;
|
|
}
|
|
case FOURCC_NV21: {
|
|
int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
|
|
uint8_t* dst_vu = dst_sample + dst_y_stride * height;
|
|
r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride ? dst_sample_stride : width, dst_vu,
|
|
dst_sample_stride ? dst_sample_stride : width, width,
|
|
height);
|
|
break;
|
|
}
|
|
// Triplanar formats
|
|
case FOURCC_I420:
|
|
case FOURCC_YV12: {
|
|
dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
|
|
int halfstride = (dst_sample_stride + 1) / 2;
|
|
int halfheight = (height + 1) / 2;
|
|
uint8_t* dst_u;
|
|
uint8_t* dst_v;
|
|
if (format == FOURCC_YV12) {
|
|
dst_v = dst_sample + dst_sample_stride * height;
|
|
dst_u = dst_v + halfstride * halfheight;
|
|
} else {
|
|
dst_u = dst_sample + dst_sample_stride * height;
|
|
dst_v = dst_u + halfstride * halfheight;
|
|
}
|
|
r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
|
|
width, height);
|
|
break;
|
|
}
|
|
case FOURCC_I422:
|
|
case FOURCC_YV16: {
|
|
dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
|
|
int halfstride = (dst_sample_stride + 1) / 2;
|
|
uint8_t* dst_u;
|
|
uint8_t* dst_v;
|
|
if (format == FOURCC_YV16) {
|
|
dst_v = dst_sample + dst_sample_stride * height;
|
|
dst_u = dst_v + halfstride * height;
|
|
} else {
|
|
dst_u = dst_sample + dst_sample_stride * height;
|
|
dst_v = dst_u + halfstride * height;
|
|
}
|
|
r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
|
|
width, height);
|
|
break;
|
|
}
|
|
case FOURCC_I444:
|
|
case FOURCC_YV24: {
|
|
dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
|
|
uint8_t* dst_u;
|
|
uint8_t* dst_v;
|
|
if (format == FOURCC_YV24) {
|
|
dst_v = dst_sample + dst_sample_stride * height;
|
|
dst_u = dst_v + dst_sample_stride * height;
|
|
} else {
|
|
dst_u = dst_sample + dst_sample_stride * height;
|
|
dst_v = dst_u + dst_sample_stride * height;
|
|
}
|
|
r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
|
|
dst_sample_stride, dst_u, dst_sample_stride, dst_v,
|
|
dst_sample_stride, width, height);
|
|
break;
|
|
}
|
|
// Formats not supported - MJPG, biplanar, some rgb formats.
|
|
default:
|
|
return -1; // unknown fourcc - return failure code.
|
|
}
|
|
return r;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
} // namespace libyuv
|
|
#endif
|