michael@0: /* michael@0: * Copyright 2011 The LibYuv Project Authors. All rights reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include "libyuv/convert.h" michael@0: michael@0: #include "libyuv/basic_types.h" michael@0: #include "libyuv/cpu_id.h" michael@0: #include "libyuv/planar_functions.h" michael@0: #include "libyuv/rotate.h" michael@0: #include "libyuv/scale.h" // For ScalePlane() michael@0: #include "libyuv/row.h" michael@0: michael@0: #ifdef __cplusplus michael@0: namespace libyuv { michael@0: extern "C" { michael@0: #endif michael@0: michael@0: #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s) michael@0: static __inline int Abs(int v) { michael@0: return v >= 0 ? v : -v; michael@0: } michael@0: michael@0: // Any I4xx To I420 format with mirroring. michael@0: static int I4xxToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_u, int src_stride_u, michael@0: const uint8* src_v, int src_stride_v, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int src_y_width, int src_y_height, michael@0: int src_uv_width, int src_uv_height) { michael@0: if (src_y_width == 0 || src_y_height == 0 || michael@0: src_uv_width == 0 || src_uv_height == 0) { michael@0: return -1; michael@0: } michael@0: const int dst_y_width = Abs(src_y_width); michael@0: const int dst_y_height = Abs(src_y_height); michael@0: const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); michael@0: const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); michael@0: ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, michael@0: dst_y, dst_stride_y, dst_y_width, dst_y_height, michael@0: kFilterBilinear); michael@0: ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, michael@0: dst_u, dst_stride_u, dst_uv_width, dst_uv_height, michael@0: kFilterBilinear); michael@0: ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, michael@0: dst_v, dst_stride_v, dst_uv_width, dst_uv_height, michael@0: kFilterBilinear); michael@0: return 0; michael@0: } michael@0: michael@0: // Copy I420 with optional flipping michael@0: // TODO(fbarchard): Use Scale plane which supports mirroring, but ensure michael@0: // is does row coalescing. michael@0: LIBYUV_API michael@0: int I420Copy(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_u, int src_stride_u, michael@0: const uint8* src_v, int src_stride_v, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: const int halfheight = (height + 1) >> 1; michael@0: src_y = src_y + (height - 1) * src_stride_y; michael@0: src_u = src_u + (halfheight - 1) * src_stride_u; michael@0: src_v = src_v + (halfheight - 1) * src_stride_v; michael@0: src_stride_y = -src_stride_y; michael@0: src_stride_u = -src_stride_u; michael@0: src_stride_v = -src_stride_v; michael@0: } michael@0: michael@0: if (dst_y) { michael@0: CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); michael@0: } michael@0: // Copy UV planes. michael@0: const int halfwidth = (width + 1) >> 1; michael@0: const int halfheight = (height + 1) >> 1; michael@0: CopyPlane(src_u, src_stride_u, dst_u, dst_stride_u, halfwidth, halfheight); michael@0: CopyPlane(src_v, src_stride_v, dst_v, dst_stride_v, halfwidth, halfheight); michael@0: return 0; michael@0: } michael@0: michael@0: // 422 chroma is 1/2 width, 1x height michael@0: // 420 chroma is 1/2 width, 1/2 height michael@0: LIBYUV_API michael@0: int I422ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_u, int src_stride_u, michael@0: const uint8* src_v, int src_stride_v, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: const int src_uv_width = SUBSAMPLE(width, 1, 1); michael@0: return I4xxToI420(src_y, src_stride_y, michael@0: src_u, src_stride_u, michael@0: src_v, src_stride_v, michael@0: dst_y, dst_stride_y, michael@0: dst_u, dst_stride_u, michael@0: dst_v, dst_stride_v, michael@0: width, height, michael@0: src_uv_width, height); michael@0: } michael@0: michael@0: // 444 chroma is 1x width, 1x height michael@0: // 420 chroma is 1/2 width, 1/2 height michael@0: LIBYUV_API michael@0: int I444ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_u, int src_stride_u, michael@0: const uint8* src_v, int src_stride_v, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: return I4xxToI420(src_y, src_stride_y, michael@0: src_u, src_stride_u, michael@0: src_v, src_stride_v, michael@0: dst_y, dst_stride_y, michael@0: dst_u, dst_stride_u, michael@0: dst_v, dst_stride_v, michael@0: width, height, michael@0: width, height); michael@0: } michael@0: michael@0: // 411 chroma is 1/4 width, 1x height michael@0: // 420 chroma is 1/2 width, 1/2 height michael@0: LIBYUV_API michael@0: int I411ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_u, int src_stride_u, michael@0: const uint8* src_v, int src_stride_v, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: const int src_uv_width = SUBSAMPLE(width, 3, 2); michael@0: return I4xxToI420(src_y, src_stride_y, michael@0: src_u, src_stride_u, michael@0: src_v, src_stride_v, michael@0: dst_y, dst_stride_y, michael@0: dst_u, dst_stride_u, michael@0: dst_v, dst_stride_v, michael@0: width, height, michael@0: src_uv_width, height); michael@0: } michael@0: michael@0: // I400 is greyscale typically used in MJPG michael@0: LIBYUV_API michael@0: int I400ToI420(const uint8* src_y, int src_stride_y, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_y || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_y = src_y + (height - 1) * src_stride_y; michael@0: src_stride_y = -src_stride_y; michael@0: } michael@0: int halfwidth = (width + 1) >> 1; michael@0: int halfheight = (height + 1) >> 1; michael@0: CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); michael@0: SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); michael@0: SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); michael@0: return 0; michael@0: } michael@0: michael@0: static void CopyPlane2(const uint8* src, int src_stride_0, int src_stride_1, michael@0: uint8* dst, int dst_stride, michael@0: int width, int height) { michael@0: void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; michael@0: #if defined(HAS_COPYROW_X86) michael@0: if (TestCpuFlag(kCpuHasX86) && IS_ALIGNED(width, 4)) { michael@0: CopyRow = CopyRow_X86; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32) && michael@0: IS_ALIGNED(src, 16) && michael@0: IS_ALIGNED(src_stride_0, 16) && IS_ALIGNED(src_stride_1, 16) && michael@0: IS_ALIGNED(dst, 16) && IS_ALIGNED(dst_stride, 16)) { michael@0: CopyRow = CopyRow_SSE2; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_ERMS) michael@0: if (TestCpuFlag(kCpuHasERMS)) { michael@0: CopyRow = CopyRow_ERMS; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { michael@0: CopyRow = CopyRow_NEON; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_MIPS) michael@0: if (TestCpuFlag(kCpuHasMIPS)) { michael@0: CopyRow = CopyRow_MIPS; michael@0: } michael@0: #endif michael@0: michael@0: // Copy plane michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: CopyRow(src, dst, width); michael@0: CopyRow(src + src_stride_0, dst + dst_stride, width); michael@0: src += src_stride_0 + src_stride_1; michael@0: dst += dst_stride * 2; michael@0: } michael@0: if (height & 1) { michael@0: CopyRow(src, dst, width); michael@0: } michael@0: } michael@0: michael@0: // Support converting from FOURCC_M420 michael@0: // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for michael@0: // easy conversion to I420. michael@0: // M420 format description: michael@0: // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. michael@0: // Chroma is half width / half height. (420) michael@0: // src_stride_m420 is row planar. Normally this will be the width in pixels. michael@0: // The UV plane is half width, but 2 values, so src_stride_m420 applies to michael@0: // this as well as the two Y planes. michael@0: static int X420ToI420(const uint8* src_y, michael@0: int src_stride_y0, int src_stride_y1, michael@0: const uint8* src_uv, int src_stride_uv, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_y || !src_uv || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: int halfheight = (height + 1) >> 1; michael@0: dst_y = dst_y + (height - 1) * dst_stride_y; michael@0: dst_u = dst_u + (halfheight - 1) * dst_stride_u; michael@0: dst_v = dst_v + (halfheight - 1) * dst_stride_v; michael@0: dst_stride_y = -dst_stride_y; michael@0: dst_stride_u = -dst_stride_u; michael@0: dst_stride_v = -dst_stride_v; michael@0: } michael@0: // Coalesce rows. michael@0: int halfwidth = (width + 1) >> 1; michael@0: int halfheight = (height + 1) >> 1; michael@0: if (src_stride_y0 == width && michael@0: src_stride_y1 == width && michael@0: dst_stride_y == width) { michael@0: width *= height; michael@0: height = 1; michael@0: src_stride_y0 = src_stride_y1 = dst_stride_y = 0; michael@0: } michael@0: // Coalesce rows. michael@0: if (src_stride_uv == halfwidth * 2 && michael@0: dst_stride_u == halfwidth && michael@0: dst_stride_v == halfwidth) { michael@0: halfwidth *= halfheight; michael@0: halfheight = 1; michael@0: src_stride_uv = dst_stride_u = dst_stride_v = 0; michael@0: } michael@0: void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix) = michael@0: SplitUVRow_C; michael@0: #if defined(HAS_SPLITUVROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && halfwidth >= 16) { michael@0: SplitUVRow = SplitUVRow_Any_SSE2; michael@0: if (IS_ALIGNED(halfwidth, 16)) { michael@0: SplitUVRow = SplitUVRow_Unaligned_SSE2; michael@0: if (IS_ALIGNED(src_uv, 16) && IS_ALIGNED(src_stride_uv, 16) && michael@0: IS_ALIGNED(dst_u, 16) && IS_ALIGNED(dst_stride_u, 16) && michael@0: IS_ALIGNED(dst_v, 16) && IS_ALIGNED(dst_stride_v, 16)) { michael@0: SplitUVRow = SplitUVRow_SSE2; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_SPLITUVROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && halfwidth >= 32) { michael@0: SplitUVRow = SplitUVRow_Any_AVX2; michael@0: if (IS_ALIGNED(halfwidth, 32)) { michael@0: SplitUVRow = SplitUVRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_SPLITUVROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && halfwidth >= 16) { michael@0: SplitUVRow = SplitUVRow_Any_NEON; michael@0: if (IS_ALIGNED(halfwidth, 16)) { michael@0: SplitUVRow = SplitUVRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_SPLITUVROW_MIPS_DSPR2) michael@0: if (TestCpuFlag(kCpuHasMIPS_DSPR2) && halfwidth >= 16) { michael@0: SplitUVRow = SplitUVRow_Any_MIPS_DSPR2; michael@0: if (IS_ALIGNED(halfwidth, 16)) { michael@0: SplitUVRow = SplitUVRow_Unaligned_MIPS_DSPR2; michael@0: if (IS_ALIGNED(src_uv, 4) && IS_ALIGNED(src_stride_uv, 4) && michael@0: IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) && michael@0: IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) { michael@0: SplitUVRow = SplitUVRow_MIPS_DSPR2; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: if (dst_y) { michael@0: if (src_stride_y0 == src_stride_y1) { michael@0: CopyPlane(src_y, src_stride_y0, dst_y, dst_stride_y, width, height); michael@0: } else { michael@0: CopyPlane2(src_y, src_stride_y0, src_stride_y1, dst_y, dst_stride_y, michael@0: width, height); michael@0: } michael@0: } michael@0: michael@0: for (int y = 0; y < halfheight; ++y) { michael@0: // Copy a row of UV. michael@0: SplitUVRow(src_uv, dst_u, dst_v, halfwidth); michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: src_uv += src_stride_uv; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert NV12 to I420. michael@0: LIBYUV_API michael@0: int NV12ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_uv, int src_stride_uv, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: return X420ToI420(src_y, src_stride_y, src_stride_y, michael@0: src_uv, src_stride_uv, michael@0: dst_y, dst_stride_y, michael@0: dst_u, dst_stride_u, michael@0: dst_v, dst_stride_v, michael@0: width, height); michael@0: } michael@0: michael@0: // Convert NV21 to I420. Same as NV12 but u and v pointers swapped. michael@0: LIBYUV_API michael@0: int NV21ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_vu, int src_stride_vu, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: return X420ToI420(src_y, src_stride_y, src_stride_y, michael@0: src_vu, src_stride_vu, michael@0: dst_y, dst_stride_y, michael@0: dst_v, dst_stride_v, michael@0: dst_u, dst_stride_u, michael@0: width, height); michael@0: } michael@0: michael@0: // Convert M420 to I420. michael@0: LIBYUV_API michael@0: int M420ToI420(const uint8* src_m420, int src_stride_m420, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: return X420ToI420(src_m420, src_stride_m420, src_stride_m420 * 2, michael@0: src_m420 + src_stride_m420 * 2, src_stride_m420 * 3, michael@0: dst_y, dst_stride_y, michael@0: dst_u, dst_stride_u, michael@0: dst_v, dst_stride_v, michael@0: width, height); michael@0: } michael@0: michael@0: // Convert Q420 to I420. michael@0: // Format is rows of YY/YUYV michael@0: LIBYUV_API michael@0: int Q420ToI420(const uint8* src_y, int src_stride_y, michael@0: const uint8* src_yuy2, int src_stride_yuy2, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_y || !src_yuy2 || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: int halfheight = (height + 1) >> 1; michael@0: dst_y = dst_y + (height - 1) * dst_stride_y; michael@0: dst_u = dst_u + (halfheight - 1) * dst_stride_u; michael@0: dst_v = dst_v + (halfheight - 1) * dst_stride_v; michael@0: dst_stride_y = -dst_stride_y; michael@0: dst_stride_u = -dst_stride_u; michael@0: dst_stride_v = -dst_stride_v; michael@0: } michael@0: // CopyRow for rows of just Y in Q420 copied to Y plane of I420. michael@0: void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; michael@0: #if defined(HAS_COPYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && IS_ALIGNED(width, 32)) { michael@0: CopyRow = CopyRow_NEON; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_X86) michael@0: if (IS_ALIGNED(width, 4)) { michael@0: CopyRow = CopyRow_X86; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(width, 32) && michael@0: IS_ALIGNED(src_y, 16) && IS_ALIGNED(src_stride_y, 16) && michael@0: IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: CopyRow = CopyRow_SSE2; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_ERMS) michael@0: if (TestCpuFlag(kCpuHasERMS)) { michael@0: CopyRow = CopyRow_ERMS; michael@0: } michael@0: #endif michael@0: #if defined(HAS_COPYROW_MIPS) michael@0: if (TestCpuFlag(kCpuHasMIPS)) { michael@0: CopyRow = CopyRow_MIPS; michael@0: } michael@0: #endif michael@0: michael@0: void (*YUY2ToUV422Row)(const uint8* src_yuy2, uint8* dst_u, uint8* dst_v, michael@0: int pix) = YUY2ToUV422Row_C; michael@0: void (*YUY2ToYRow)(const uint8* src_yuy2, uint8* dst_y, int pix) = michael@0: YUY2ToYRow_C; michael@0: #if defined(HAS_YUY2TOYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_Any_SSE2; michael@0: YUY2ToYRow = YUY2ToYRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_Unaligned_SSE2; michael@0: YUY2ToYRow = YUY2ToYRow_Unaligned_SSE2; michael@0: if (IS_ALIGNED(src_yuy2, 16) && IS_ALIGNED(src_stride_yuy2, 16)) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_SSE2; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: YUY2ToYRow = YUY2ToYRow_SSE2; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_YUY2TOYROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_Any_AVX2; michael@0: YUY2ToYRow = YUY2ToYRow_Any_AVX2; michael@0: if (IS_ALIGNED(width, 32)) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_AVX2; michael@0: YUY2ToYRow = YUY2ToYRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_YUY2TOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: YUY2ToYRow = YUY2ToYRow_Any_NEON; michael@0: if (width >= 16) { michael@0: YUY2ToUV422Row = YUY2ToUV422Row_Any_NEON; michael@0: } michael@0: if (IS_ALIGNED(width, 16)) { michael@0: YUY2ToYRow = YUY2ToYRow_NEON; michael@0: YUY2ToUV422Row = YUY2ToUV422Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: CopyRow(src_y, dst_y, width); michael@0: src_y += src_stride_y; michael@0: dst_y += dst_stride_y; michael@0: michael@0: YUY2ToUV422Row(src_yuy2, dst_u, dst_v, width); michael@0: YUY2ToYRow(src_yuy2, dst_y, width); michael@0: src_yuy2 += src_stride_yuy2; michael@0: dst_y += dst_stride_y; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: CopyRow(src_y, dst_y, width); michael@0: YUY2ToUV422Row(src_yuy2, dst_u, dst_v, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert YUY2 to I420. michael@0: LIBYUV_API michael@0: int YUY2ToI420(const uint8* src_yuy2, int src_stride_yuy2, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; michael@0: src_stride_yuy2 = -src_stride_yuy2; michael@0: } michael@0: void (*YUY2ToUVRow)(const uint8* src_yuy2, int src_stride_yuy2, michael@0: uint8* dst_u, uint8* dst_v, int pix); michael@0: void (*YUY2ToYRow)(const uint8* src_yuy2, michael@0: uint8* dst_y, int pix); michael@0: YUY2ToYRow = YUY2ToYRow_C; michael@0: YUY2ToUVRow = YUY2ToUVRow_C; michael@0: #if defined(HAS_YUY2TOYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: YUY2ToUVRow = YUY2ToUVRow_Any_SSE2; michael@0: YUY2ToYRow = YUY2ToYRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: YUY2ToUVRow = YUY2ToUVRow_Unaligned_SSE2; michael@0: YUY2ToYRow = YUY2ToYRow_Unaligned_SSE2; michael@0: if (IS_ALIGNED(src_yuy2, 16) && IS_ALIGNED(src_stride_yuy2, 16)) { michael@0: YUY2ToUVRow = YUY2ToUVRow_SSE2; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: YUY2ToYRow = YUY2ToYRow_SSE2; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_YUY2TOYROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { michael@0: YUY2ToUVRow = YUY2ToUVRow_Any_AVX2; michael@0: YUY2ToYRow = YUY2ToYRow_Any_AVX2; michael@0: if (IS_ALIGNED(width, 32)) { michael@0: YUY2ToUVRow = YUY2ToUVRow_AVX2; michael@0: YUY2ToYRow = YUY2ToYRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_YUY2TOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: YUY2ToYRow = YUY2ToYRow_Any_NEON; michael@0: if (width >= 16) { michael@0: YUY2ToUVRow = YUY2ToUVRow_Any_NEON; michael@0: } michael@0: if (IS_ALIGNED(width, 16)) { michael@0: YUY2ToYRow = YUY2ToYRow_NEON; michael@0: YUY2ToUVRow = YUY2ToUVRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: YUY2ToUVRow(src_yuy2, src_stride_yuy2, dst_u, dst_v, width); michael@0: YUY2ToYRow(src_yuy2, dst_y, width); michael@0: YUY2ToYRow(src_yuy2 + src_stride_yuy2, dst_y + dst_stride_y, width); michael@0: src_yuy2 += src_stride_yuy2 * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: YUY2ToUVRow(src_yuy2, 0, dst_u, dst_v, width); michael@0: YUY2ToYRow(src_yuy2, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert UYVY to I420. michael@0: LIBYUV_API michael@0: int UYVYToI420(const uint8* src_uyvy, int src_stride_uyvy, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; michael@0: src_stride_uyvy = -src_stride_uyvy; michael@0: } michael@0: void (*UYVYToUVRow)(const uint8* src_uyvy, int src_stride_uyvy, michael@0: uint8* dst_u, uint8* dst_v, int pix); michael@0: void (*UYVYToYRow)(const uint8* src_uyvy, michael@0: uint8* dst_y, int pix); michael@0: UYVYToYRow = UYVYToYRow_C; michael@0: UYVYToUVRow = UYVYToUVRow_C; michael@0: #if defined(HAS_UYVYTOYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: UYVYToUVRow = UYVYToUVRow_Any_SSE2; michael@0: UYVYToYRow = UYVYToYRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: UYVYToUVRow = UYVYToUVRow_Unaligned_SSE2; michael@0: UYVYToYRow = UYVYToYRow_Unaligned_SSE2; michael@0: if (IS_ALIGNED(src_uyvy, 16) && IS_ALIGNED(src_stride_uyvy, 16)) { michael@0: UYVYToUVRow = UYVYToUVRow_SSE2; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: UYVYToYRow = UYVYToYRow_SSE2; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_UYVYTOYROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { michael@0: UYVYToUVRow = UYVYToUVRow_Any_AVX2; michael@0: UYVYToYRow = UYVYToYRow_Any_AVX2; michael@0: if (IS_ALIGNED(width, 32)) { michael@0: UYVYToUVRow = UYVYToUVRow_AVX2; michael@0: UYVYToYRow = UYVYToYRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_UYVYTOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: UYVYToYRow = UYVYToYRow_Any_NEON; michael@0: if (width >= 16) { michael@0: UYVYToUVRow = UYVYToUVRow_Any_NEON; michael@0: } michael@0: if (IS_ALIGNED(width, 16)) { michael@0: UYVYToYRow = UYVYToYRow_NEON; michael@0: UYVYToUVRow = UYVYToUVRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: UYVYToUVRow(src_uyvy, src_stride_uyvy, dst_u, dst_v, width); michael@0: UYVYToYRow(src_uyvy, dst_y, width); michael@0: UYVYToYRow(src_uyvy + src_stride_uyvy, dst_y + dst_stride_y, width); michael@0: src_uyvy += src_stride_uyvy * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: UYVYToUVRow(src_uyvy, 0, dst_u, dst_v, width); michael@0: UYVYToYRow(src_uyvy, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert ARGB to I420. michael@0: LIBYUV_API michael@0: int ARGBToI420(const uint8* src_argb, int src_stride_argb, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_argb || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_argb = src_argb + (height - 1) * src_stride_argb; michael@0: src_stride_argb = -src_stride_argb; michael@0: } michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOYROW_SSSE3) && defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_Unaligned_SSSE3; michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(src_argb, 16) && IS_ALIGNED(src_stride_argb, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_ARGBTOYROW_AVX2) && defined(HAS_ARGBTOUVROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && width >= 32) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_AVX2; michael@0: ARGBToYRow = ARGBToYRow_Any_AVX2; michael@0: if (IS_ALIGNED(width, 32)) { michael@0: ARGBToUVRow = ARGBToUVRow_AVX2; michael@0: ARGBToYRow = ARGBToYRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_ARGBTOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: ARGBToYRow = ARGBToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ARGBToYRow = ARGBToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: ARGBToUVRow(src_argb, src_stride_argb, dst_u, dst_v, width); michael@0: ARGBToYRow(src_argb, dst_y, width); michael@0: ARGBToYRow(src_argb + src_stride_argb, dst_y + dst_stride_y, width); michael@0: src_argb += src_stride_argb * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: ARGBToUVRow(src_argb, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(src_argb, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert BGRA to I420. michael@0: LIBYUV_API michael@0: int BGRAToI420(const uint8* src_bgra, int src_stride_bgra, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_bgra || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_bgra = src_bgra + (height - 1) * src_stride_bgra; michael@0: src_stride_bgra = -src_stride_bgra; michael@0: } michael@0: void (*BGRAToUVRow)(const uint8* src_bgra0, int src_stride_bgra, michael@0: uint8* dst_u, uint8* dst_v, int width) = BGRAToUVRow_C; michael@0: void (*BGRAToYRow)(const uint8* src_bgra, uint8* dst_y, int pix) = michael@0: BGRAToYRow_C; michael@0: #if defined(HAS_BGRATOYROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: BGRAToUVRow = BGRAToUVRow_Any_SSSE3; michael@0: BGRAToYRow = BGRAToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: BGRAToUVRow = BGRAToUVRow_Unaligned_SSSE3; michael@0: BGRAToYRow = BGRAToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(src_bgra, 16) && IS_ALIGNED(src_stride_bgra, 16)) { michael@0: BGRAToUVRow = BGRAToUVRow_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: BGRAToYRow = BGRAToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_BGRATOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: BGRAToYRow = BGRAToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: BGRAToYRow = BGRAToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: BGRAToUVRow = BGRAToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: BGRAToUVRow = BGRAToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: BGRAToUVRow(src_bgra, src_stride_bgra, dst_u, dst_v, width); michael@0: BGRAToYRow(src_bgra, dst_y, width); michael@0: BGRAToYRow(src_bgra + src_stride_bgra, dst_y + dst_stride_y, width); michael@0: src_bgra += src_stride_bgra * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: BGRAToUVRow(src_bgra, 0, dst_u, dst_v, width); michael@0: BGRAToYRow(src_bgra, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert ABGR to I420. michael@0: LIBYUV_API michael@0: int ABGRToI420(const uint8* src_abgr, int src_stride_abgr, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_abgr || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_abgr = src_abgr + (height - 1) * src_stride_abgr; michael@0: src_stride_abgr = -src_stride_abgr; michael@0: } michael@0: void (*ABGRToUVRow)(const uint8* src_abgr0, int src_stride_abgr, michael@0: uint8* dst_u, uint8* dst_v, int width) = ABGRToUVRow_C; michael@0: void (*ABGRToYRow)(const uint8* src_abgr, uint8* dst_y, int pix) = michael@0: ABGRToYRow_C; michael@0: #if defined(HAS_ABGRTOYROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ABGRToUVRow = ABGRToUVRow_Any_SSSE3; michael@0: ABGRToYRow = ABGRToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ABGRToUVRow = ABGRToUVRow_Unaligned_SSSE3; michael@0: ABGRToYRow = ABGRToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(src_abgr, 16) && IS_ALIGNED(src_stride_abgr, 16)) { michael@0: ABGRToUVRow = ABGRToUVRow_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ABGRToYRow = ABGRToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_ABGRTOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: ABGRToYRow = ABGRToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ABGRToYRow = ABGRToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: ABGRToUVRow = ABGRToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ABGRToUVRow = ABGRToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: ABGRToUVRow(src_abgr, src_stride_abgr, dst_u, dst_v, width); michael@0: ABGRToYRow(src_abgr, dst_y, width); michael@0: ABGRToYRow(src_abgr + src_stride_abgr, dst_y + dst_stride_y, width); michael@0: src_abgr += src_stride_abgr * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: ABGRToUVRow(src_abgr, 0, dst_u, dst_v, width); michael@0: ABGRToYRow(src_abgr, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert RGBA to I420. michael@0: LIBYUV_API michael@0: int RGBAToI420(const uint8* src_rgba, int src_stride_rgba, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_rgba || michael@0: !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_rgba = src_rgba + (height - 1) * src_stride_rgba; michael@0: src_stride_rgba = -src_stride_rgba; michael@0: } michael@0: void (*RGBAToUVRow)(const uint8* src_rgba0, int src_stride_rgba, michael@0: uint8* dst_u, uint8* dst_v, int width) = RGBAToUVRow_C; michael@0: void (*RGBAToYRow)(const uint8* src_rgba, uint8* dst_y, int pix) = michael@0: RGBAToYRow_C; michael@0: #if defined(HAS_RGBATOYROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: RGBAToUVRow = RGBAToUVRow_Any_SSSE3; michael@0: RGBAToYRow = RGBAToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RGBAToUVRow = RGBAToUVRow_Unaligned_SSSE3; michael@0: RGBAToYRow = RGBAToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(src_rgba, 16) && IS_ALIGNED(src_stride_rgba, 16)) { michael@0: RGBAToUVRow = RGBAToUVRow_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: RGBAToYRow = RGBAToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_RGBATOYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: RGBAToYRow = RGBAToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: RGBAToYRow = RGBAToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: RGBAToUVRow = RGBAToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RGBAToUVRow = RGBAToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: RGBAToUVRow(src_rgba, src_stride_rgba, dst_u, dst_v, width); michael@0: RGBAToYRow(src_rgba, dst_y, width); michael@0: RGBAToYRow(src_rgba + src_stride_rgba, dst_y + dst_stride_y, width); michael@0: src_rgba += src_stride_rgba * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: RGBAToUVRow(src_rgba, 0, dst_u, dst_v, width); michael@0: RGBAToYRow(src_rgba, dst_y, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert RGB24 to I420. michael@0: LIBYUV_API michael@0: int RGB24ToI420(const uint8* src_rgb24, int src_stride_rgb24, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_rgb24 || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; michael@0: src_stride_rgb24 = -src_stride_rgb24; michael@0: } michael@0: michael@0: #if defined(HAS_RGB24TOYROW_NEON) michael@0: void (*RGB24ToUVRow)(const uint8* src_rgb24, int src_stride_rgb24, michael@0: uint8* dst_u, uint8* dst_v, int width) = RGB24ToUVRow_C; michael@0: void (*RGB24ToYRow)(const uint8* src_rgb24, uint8* dst_y, int pix) = michael@0: RGB24ToYRow_C; michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: RGB24ToYRow = RGB24ToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: RGB24ToYRow = RGB24ToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: RGB24ToUVRow = RGB24ToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RGB24ToUVRow = RGB24ToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #else // HAS_RGB24TOYROW_NEON michael@0: michael@0: // Allocate 2 rows of ARGB. michael@0: const int kRowSize = (width * 4 + 15) & ~15; michael@0: align_buffer_64(row, kRowSize * 2); michael@0: michael@0: void (*RGB24ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = michael@0: RGB24ToARGBRow_C; michael@0: #if defined(HAS_RGB24TOARGBROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: RGB24ToARGBRow = RGB24ToARGBRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RGB24ToARGBRow = RGB24ToARGBRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif // HAS_ARGBTOUVROW_SSSE3 michael@0: #endif // HAS_RGB24TOYROW_NEON michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: #if defined(HAS_RGB24TOYROW_NEON) michael@0: RGB24ToUVRow(src_rgb24, src_stride_rgb24, dst_u, dst_v, width); michael@0: RGB24ToYRow(src_rgb24, dst_y, width); michael@0: RGB24ToYRow(src_rgb24 + src_stride_rgb24, dst_y + dst_stride_y, width); michael@0: #else michael@0: RGB24ToARGBRow(src_rgb24, row, width); michael@0: RGB24ToARGBRow(src_rgb24 + src_stride_rgb24, row + kRowSize, width); michael@0: ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); michael@0: #endif michael@0: src_rgb24 += src_stride_rgb24 * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: #if defined(HAS_RGB24TOYROW_NEON) michael@0: RGB24ToUVRow(src_rgb24, 0, dst_u, dst_v, width); michael@0: RGB24ToYRow(src_rgb24, dst_y, width); michael@0: #else michael@0: RGB24ToARGBRow(src_rgb24, row, width); michael@0: ARGBToUVRow(row, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: #endif michael@0: } michael@0: #if !defined(HAS_RGB24TOYROW_NEON) michael@0: free_aligned_buffer_64(row); michael@0: #endif michael@0: return 0; michael@0: } michael@0: michael@0: // Convert RAW to I420. michael@0: LIBYUV_API michael@0: int RAWToI420(const uint8* src_raw, int src_stride_raw, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_raw || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_raw = src_raw + (height - 1) * src_stride_raw; michael@0: src_stride_raw = -src_stride_raw; michael@0: } michael@0: michael@0: #if defined(HAS_RAWTOYROW_NEON) michael@0: void (*RAWToUVRow)(const uint8* src_raw, int src_stride_raw, michael@0: uint8* dst_u, uint8* dst_v, int width) = RAWToUVRow_C; michael@0: void (*RAWToYRow)(const uint8* src_raw, uint8* dst_y, int pix) = michael@0: RAWToYRow_C; michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: RAWToYRow = RAWToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: RAWToYRow = RAWToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: RAWToUVRow = RAWToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RAWToUVRow = RAWToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #else // HAS_RAWTOYROW_NEON michael@0: michael@0: // Allocate 2 rows of ARGB. michael@0: const int kRowSize = (width * 4 + 15) & ~15; michael@0: align_buffer_64(row, kRowSize * 2); michael@0: michael@0: void (*RAWToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = michael@0: RAWToARGBRow_C; michael@0: #if defined(HAS_RAWTOARGBROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: RAWToARGBRow = RAWToARGBRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RAWToARGBRow = RAWToARGBRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif // HAS_ARGBTOUVROW_SSSE3 michael@0: #endif // HAS_RAWTOYROW_NEON michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: #if defined(HAS_RAWTOYROW_NEON) michael@0: RAWToUVRow(src_raw, src_stride_raw, dst_u, dst_v, width); michael@0: RAWToYRow(src_raw, dst_y, width); michael@0: RAWToYRow(src_raw + src_stride_raw, dst_y + dst_stride_y, width); michael@0: #else michael@0: RAWToARGBRow(src_raw, row, width); michael@0: RAWToARGBRow(src_raw + src_stride_raw, row + kRowSize, width); michael@0: ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); michael@0: #endif michael@0: src_raw += src_stride_raw * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: #if defined(HAS_RAWTOYROW_NEON) michael@0: RAWToUVRow(src_raw, 0, dst_u, dst_v, width); michael@0: RAWToYRow(src_raw, dst_y, width); michael@0: #else michael@0: RAWToARGBRow(src_raw, row, width); michael@0: ARGBToUVRow(row, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: #endif michael@0: } michael@0: #if !defined(HAS_RAWTOYROW_NEON) michael@0: free_aligned_buffer_64(row); michael@0: #endif michael@0: return 0; michael@0: } michael@0: michael@0: // Convert RGB565 to I420. michael@0: LIBYUV_API michael@0: int RGB565ToI420(const uint8* src_rgb565, int src_stride_rgb565, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_rgb565 || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; michael@0: src_stride_rgb565 = -src_stride_rgb565; michael@0: } michael@0: michael@0: #if defined(HAS_RGB565TOYROW_NEON) michael@0: void (*RGB565ToUVRow)(const uint8* src_rgb565, int src_stride_rgb565, michael@0: uint8* dst_u, uint8* dst_v, int width) = RGB565ToUVRow_C; michael@0: void (*RGB565ToYRow)(const uint8* src_rgb565, uint8* dst_y, int pix) = michael@0: RGB565ToYRow_C; michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: RGB565ToYRow = RGB565ToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: RGB565ToYRow = RGB565ToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: RGB565ToUVRow = RGB565ToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: RGB565ToUVRow = RGB565ToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #else // HAS_RGB565TOYROW_NEON michael@0: michael@0: // Allocate 2 rows of ARGB. michael@0: const int kRowSize = (width * 4 + 15) & ~15; michael@0: align_buffer_64(row, kRowSize * 2); michael@0: michael@0: void (*RGB565ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = michael@0: RGB565ToARGBRow_C; michael@0: #if defined(HAS_RGB565TOARGBROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { michael@0: RGB565ToARGBRow = RGB565ToARGBRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: RGB565ToARGBRow = RGB565ToARGBRow_SSE2; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif // HAS_ARGBTOUVROW_SSSE3 michael@0: #endif // HAS_RGB565TOYROW_NEON michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: #if defined(HAS_RGB565TOYROW_NEON) michael@0: RGB565ToUVRow(src_rgb565, src_stride_rgb565, dst_u, dst_v, width); michael@0: RGB565ToYRow(src_rgb565, dst_y, width); michael@0: RGB565ToYRow(src_rgb565 + src_stride_rgb565, dst_y + dst_stride_y, width); michael@0: #else michael@0: RGB565ToARGBRow(src_rgb565, row, width); michael@0: RGB565ToARGBRow(src_rgb565 + src_stride_rgb565, row + kRowSize, width); michael@0: ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); michael@0: #endif michael@0: src_rgb565 += src_stride_rgb565 * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: #if defined(HAS_RGB565TOYROW_NEON) michael@0: RGB565ToUVRow(src_rgb565, 0, dst_u, dst_v, width); michael@0: RGB565ToYRow(src_rgb565, dst_y, width); michael@0: #else michael@0: RGB565ToARGBRow(src_rgb565, row, width); michael@0: ARGBToUVRow(row, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: #endif michael@0: } michael@0: #if !defined(HAS_RGB565TOYROW_NEON) michael@0: free_aligned_buffer_64(row); michael@0: #endif michael@0: return 0; michael@0: } michael@0: michael@0: // Convert ARGB1555 to I420. michael@0: LIBYUV_API michael@0: int ARGB1555ToI420(const uint8* src_argb1555, int src_stride_argb1555, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_argb1555 || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; michael@0: src_stride_argb1555 = -src_stride_argb1555; michael@0: } michael@0: michael@0: #if defined(HAS_ARGB1555TOYROW_NEON) michael@0: void (*ARGB1555ToUVRow)(const uint8* src_argb1555, int src_stride_argb1555, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGB1555ToUVRow_C; michael@0: void (*ARGB1555ToYRow)(const uint8* src_argb1555, uint8* dst_y, int pix) = michael@0: ARGB1555ToYRow_C; michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: ARGB1555ToYRow = ARGB1555ToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ARGB1555ToYRow = ARGB1555ToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: ARGB1555ToUVRow = ARGB1555ToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGB1555ToUVRow = ARGB1555ToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #else // HAS_ARGB1555TOYROW_NEON michael@0: michael@0: // Allocate 2 rows of ARGB. michael@0: const int kRowSize = (width * 4 + 15) & ~15; michael@0: align_buffer_64(row, kRowSize * 2); michael@0: michael@0: void (*ARGB1555ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = michael@0: ARGB1555ToARGBRow_C; michael@0: #if defined(HAS_ARGB1555TOARGBROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { michael@0: ARGB1555ToARGBRow = ARGB1555ToARGBRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ARGB1555ToARGBRow = ARGB1555ToARGBRow_SSE2; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif // HAS_ARGBTOUVROW_SSSE3 michael@0: #endif // HAS_ARGB1555TOYROW_NEON michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: #if defined(HAS_ARGB1555TOYROW_NEON) michael@0: ARGB1555ToUVRow(src_argb1555, src_stride_argb1555, dst_u, dst_v, width); michael@0: ARGB1555ToYRow(src_argb1555, dst_y, width); michael@0: ARGB1555ToYRow(src_argb1555 + src_stride_argb1555, dst_y + dst_stride_y, michael@0: width); michael@0: #else michael@0: ARGB1555ToARGBRow(src_argb1555, row, width); michael@0: ARGB1555ToARGBRow(src_argb1555 + src_stride_argb1555, row + kRowSize, michael@0: width); michael@0: ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); michael@0: #endif michael@0: src_argb1555 += src_stride_argb1555 * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: #if defined(HAS_ARGB1555TOYROW_NEON) michael@0: ARGB1555ToUVRow(src_argb1555, 0, dst_u, dst_v, width); michael@0: ARGB1555ToYRow(src_argb1555, dst_y, width); michael@0: #else michael@0: ARGB1555ToARGBRow(src_argb1555, row, width); michael@0: ARGBToUVRow(row, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: #endif michael@0: } michael@0: #if !defined(HAS_ARGB1555TOYROW_NEON) michael@0: free_aligned_buffer_64(row); michael@0: #endif michael@0: return 0; michael@0: } michael@0: michael@0: // Convert ARGB4444 to I420. michael@0: LIBYUV_API michael@0: int ARGB4444ToI420(const uint8* src_argb4444, int src_stride_argb4444, michael@0: uint8* dst_y, int dst_stride_y, michael@0: uint8* dst_u, int dst_stride_u, michael@0: uint8* dst_v, int dst_stride_v, michael@0: int width, int height) { michael@0: if (!src_argb4444 || !dst_y || !dst_u || !dst_v || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: // Negative height means invert the image. michael@0: if (height < 0) { michael@0: height = -height; michael@0: src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; michael@0: src_stride_argb4444 = -src_stride_argb4444; michael@0: } michael@0: michael@0: #if defined(HAS_ARGB4444TOYROW_NEON) michael@0: void (*ARGB4444ToUVRow)(const uint8* src_argb4444, int src_stride_argb4444, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGB4444ToUVRow_C; michael@0: void (*ARGB4444ToYRow)(const uint8* src_argb4444, uint8* dst_y, int pix) = michael@0: ARGB4444ToYRow_C; michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: ARGB4444ToYRow = ARGB4444ToYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ARGB4444ToYRow = ARGB4444ToYRow_NEON; michael@0: } michael@0: if (width >= 16) { michael@0: ARGB4444ToUVRow = ARGB4444ToUVRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGB4444ToUVRow = ARGB4444ToUVRow_NEON; michael@0: } michael@0: } michael@0: } michael@0: #else // HAS_ARGB4444TOYROW_NEON michael@0: michael@0: // Allocate 2 rows of ARGB. michael@0: const int kRowSize = (width * 4 + 15) & ~15; michael@0: align_buffer_64(row, kRowSize * 2); michael@0: michael@0: void (*ARGB4444ToARGBRow)(const uint8* src_rgb, uint8* dst_argb, int pix) = michael@0: ARGB4444ToARGBRow_C; michael@0: #if defined(HAS_ARGB4444TOARGBROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 8) { michael@0: ARGB4444ToARGBRow = ARGB4444ToARGBRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: ARGB4444ToARGBRow = ARGB4444ToARGBRow_SSE2; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToUVRow)(const uint8* src_argb0, int src_stride_argb, michael@0: uint8* dst_u, uint8* dst_v, int width) = ARGBToUVRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToUVRow = ARGBToUVRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToUVRow = ARGBToUVRow_SSSE3; michael@0: } michael@0: } michael@0: #endif michael@0: void (*ARGBToYRow)(const uint8* src_argb, uint8* dst_y, int pix) = michael@0: ARGBToYRow_C; michael@0: #if defined(HAS_ARGBTOUVROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 16) { michael@0: ARGBToYRow = ARGBToYRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: ARGBToYRow = ARGBToYRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_y, 16) && IS_ALIGNED(dst_stride_y, 16)) { michael@0: ARGBToYRow = ARGBToYRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif // HAS_ARGBTOUVROW_SSSE3 michael@0: #endif // HAS_ARGB4444TOYROW_NEON michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: #if defined(HAS_ARGB4444TOYROW_NEON) michael@0: ARGB4444ToUVRow(src_argb4444, src_stride_argb4444, dst_u, dst_v, width); michael@0: ARGB4444ToYRow(src_argb4444, dst_y, width); michael@0: ARGB4444ToYRow(src_argb4444 + src_stride_argb4444, dst_y + dst_stride_y, michael@0: width); michael@0: #else michael@0: ARGB4444ToARGBRow(src_argb4444, row, width); michael@0: ARGB4444ToARGBRow(src_argb4444 + src_stride_argb4444, row + kRowSize, michael@0: width); michael@0: ARGBToUVRow(row, kRowSize, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: ARGBToYRow(row + kRowSize, dst_y + dst_stride_y, width); michael@0: #endif michael@0: src_argb4444 += src_stride_argb4444 * 2; michael@0: dst_y += dst_stride_y * 2; michael@0: dst_u += dst_stride_u; michael@0: dst_v += dst_stride_v; michael@0: } michael@0: if (height & 1) { michael@0: #if defined(HAS_ARGB4444TOYROW_NEON) michael@0: ARGB4444ToUVRow(src_argb4444, 0, dst_u, dst_v, width); michael@0: ARGB4444ToYRow(src_argb4444, dst_y, width); michael@0: #else michael@0: ARGB4444ToARGBRow(src_argb4444, row, width); michael@0: ARGBToUVRow(row, 0, dst_u, dst_v, width); michael@0: ARGBToYRow(row, dst_y, width); michael@0: #endif michael@0: } michael@0: #if !defined(HAS_ARGB4444TOYROW_NEON) michael@0: free_aligned_buffer_64(row); michael@0: #endif michael@0: return 0; michael@0: } michael@0: michael@0: #ifdef __cplusplus michael@0: } // extern "C" michael@0: } // namespace libyuv michael@0: #endif