michael@0: /* michael@0: * Copyright 2012 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_from.h" michael@0: michael@0: #include "libyuv/basic_types.h" michael@0: #include "libyuv/convert.h" // For I420Copy michael@0: #include "libyuv/cpu_id.h" michael@0: #include "libyuv/format_conversion.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/video_common.h" 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: // I420 To any I4xx YUV format with mirroring. michael@0: static int I420ToI4xx(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 dst_uv_width, int dst_uv_height) { michael@0: if (src_y_width == 0 || src_y_height == 0 || michael@0: dst_uv_width <= 0 || dst_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 src_uv_width = SUBSAMPLE(src_y_width, 1, 1); michael@0: const int src_uv_height = SUBSAMPLE(src_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: // 420 chroma is 1/2 width, 1/2 height michael@0: // 422 chroma is 1/2 width, 1x height michael@0: LIBYUV_API michael@0: int I420ToI422(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 dst_uv_width = (Abs(width) + 1) >> 1; michael@0: const int dst_uv_height = Abs(height); michael@0: return I420ToI4xx(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: dst_uv_width, dst_uv_height); michael@0: } michael@0: michael@0: // 420 chroma is 1/2 width, 1/2 height michael@0: // 444 chroma is 1x width, 1x height michael@0: LIBYUV_API michael@0: int I420ToI444(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 dst_uv_width = Abs(width); michael@0: const int dst_uv_height = Abs(height); michael@0: return I420ToI4xx(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: dst_uv_width, dst_uv_height); michael@0: } michael@0: michael@0: // 420 chroma is 1/2 width, 1/2 height michael@0: // 411 chroma is 1/4 width, 1x height michael@0: LIBYUV_API michael@0: int I420ToI411(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 dst_uv_width = (Abs(width) + 3) >> 2; michael@0: const int dst_uv_height = Abs(height); michael@0: return I420ToI4xx(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: dst_uv_width, dst_uv_height); michael@0: } michael@0: michael@0: // Copy to I400. Source can be I420,422,444,400,NV12,NV21 michael@0: LIBYUV_API michael@0: int I400Copy(const uint8* src_y, int src_stride_y, michael@0: uint8* dst_y, int dst_stride_y, michael@0: int width, int height) { michael@0: if (!src_y || !dst_y || 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: CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I422ToYUY2(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_yuy2, int dst_stride_yuy2, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_yuy2 || 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: dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; michael@0: dst_stride_yuy2 = -dst_stride_yuy2; michael@0: } michael@0: // Coalesce rows. michael@0: if (src_stride_y == width && michael@0: src_stride_u * 2 == width && michael@0: src_stride_v * 2 == width && michael@0: dst_stride_yuy2 == width * 2) { michael@0: width *= height; michael@0: height = 1; michael@0: src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0; michael@0: } michael@0: void (*I422ToYUY2Row)(const uint8* src_y, const uint8* src_u, michael@0: const uint8* src_v, uint8* dst_yuy2, int width) = michael@0: I422ToYUY2Row_C; michael@0: #if defined(HAS_I422TOYUY2ROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: I422ToYUY2Row = I422ToYUY2Row_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToYUY2Row = I422ToYUY2Row_SSE2; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOYUY2ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 16) { michael@0: I422ToYUY2Row = I422ToYUY2Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToYUY2Row = I422ToYUY2Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width); michael@0: src_y += src_stride_y; michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: dst_yuy2 += dst_stride_yuy2; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I420ToYUY2(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_yuy2, int dst_stride_yuy2, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_yuy2 || 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: dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; michael@0: dst_stride_yuy2 = -dst_stride_yuy2; michael@0: } michael@0: void (*I422ToYUY2Row)(const uint8* src_y, const uint8* src_u, michael@0: const uint8* src_v, uint8* dst_yuy2, int width) = michael@0: I422ToYUY2Row_C; michael@0: #if defined(HAS_I422TOYUY2ROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: I422ToYUY2Row = I422ToYUY2Row_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToYUY2Row = I422ToYUY2Row_SSE2; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOYUY2ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 16) { michael@0: I422ToYUY2Row = I422ToYUY2Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToYUY2Row = I422ToYUY2Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width); michael@0: I422ToYUY2Row(src_y + src_stride_y, src_u, src_v, michael@0: dst_yuy2 + dst_stride_yuy2, width); michael@0: src_y += src_stride_y * 2; michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: dst_yuy2 += dst_stride_yuy2 * 2; michael@0: } michael@0: if (height & 1) { michael@0: I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I422ToUYVY(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_uyvy, int dst_stride_uyvy, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_uyvy || 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: dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; michael@0: dst_stride_uyvy = -dst_stride_uyvy; michael@0: } michael@0: // Coalesce rows. michael@0: if (src_stride_y == width && michael@0: src_stride_u * 2 == width && michael@0: src_stride_v * 2 == width && michael@0: dst_stride_uyvy == width * 2) { michael@0: width *= height; michael@0: height = 1; michael@0: src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0; michael@0: } michael@0: void (*I422ToUYVYRow)(const uint8* src_y, const uint8* src_u, michael@0: const uint8* src_v, uint8* dst_uyvy, int width) = michael@0: I422ToUYVYRow_C; michael@0: #if defined(HAS_I422TOUYVYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: I422ToUYVYRow = I422ToUYVYRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToUYVYRow = I422ToUYVYRow_SSE2; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOUYVYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 16) { michael@0: I422ToUYVYRow = I422ToUYVYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToUYVYRow = I422ToUYVYRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width); michael@0: src_y += src_stride_y; michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: dst_uyvy += dst_stride_uyvy; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I420ToUYVY(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_uyvy, int dst_stride_uyvy, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_uyvy || 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: dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; michael@0: dst_stride_uyvy = -dst_stride_uyvy; michael@0: } michael@0: void (*I422ToUYVYRow)(const uint8* src_y, const uint8* src_u, michael@0: const uint8* src_v, uint8* dst_uyvy, int width) = michael@0: I422ToUYVYRow_C; michael@0: #if defined(HAS_I422TOUYVYROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && width >= 16) { michael@0: I422ToUYVYRow = I422ToUYVYRow_Any_SSE2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToUYVYRow = I422ToUYVYRow_SSE2; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOUYVYROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 16) { michael@0: I422ToUYVYRow = I422ToUYVYRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToUYVYRow = I422ToUYVYRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height - 1; y += 2) { michael@0: I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width); michael@0: I422ToUYVYRow(src_y + src_stride_y, src_u, src_v, michael@0: dst_uyvy + dst_stride_uyvy, width); michael@0: src_y += src_stride_y * 2; michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: dst_uyvy += dst_stride_uyvy * 2; michael@0: } michael@0: if (height & 1) { michael@0: I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width); michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I420ToNV12(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_uv, int dst_stride_uv, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || 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_uv = dst_uv + (halfheight - 1) * dst_stride_uv; michael@0: dst_stride_y = -dst_stride_y; michael@0: dst_stride_uv = -dst_stride_uv; 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_y == width && michael@0: dst_stride_y == width) { michael@0: width *= height; michael@0: height = 1; michael@0: src_stride_y = dst_stride_y = 0; michael@0: } michael@0: // Coalesce rows. michael@0: if (src_stride_u == halfwidth && michael@0: src_stride_v == halfwidth && michael@0: dst_stride_uv == halfwidth * 2) { michael@0: halfwidth *= halfheight; michael@0: halfheight = 1; michael@0: src_stride_u = src_stride_v = dst_stride_uv = 0; michael@0: } michael@0: void (*MergeUVRow_)(const uint8* src_u, const uint8* src_v, uint8* dst_uv, michael@0: int width) = MergeUVRow_C; michael@0: #if defined(HAS_MERGEUVROW_SSE2) michael@0: if (TestCpuFlag(kCpuHasSSE2) && halfwidth >= 16) { michael@0: MergeUVRow_ = MergeUVRow_Any_SSE2; michael@0: if (IS_ALIGNED(halfwidth, 16)) { michael@0: MergeUVRow_ = MergeUVRow_Unaligned_SSE2; michael@0: if (IS_ALIGNED(src_u, 16) && IS_ALIGNED(src_stride_u, 16) && michael@0: IS_ALIGNED(src_v, 16) && IS_ALIGNED(src_stride_v, 16) && michael@0: IS_ALIGNED(dst_uv, 16) && IS_ALIGNED(dst_stride_uv, 16)) { michael@0: MergeUVRow_ = MergeUVRow_SSE2; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_MERGEUVROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && halfwidth >= 32) { michael@0: MergeUVRow_ = MergeUVRow_Any_AVX2; michael@0: if (IS_ALIGNED(halfwidth, 32)) { michael@0: MergeUVRow_ = MergeUVRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_MERGEUVROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && halfwidth >= 16) { michael@0: MergeUVRow_ = MergeUVRow_Any_NEON; michael@0: if (IS_ALIGNED(halfwidth, 16)) { michael@0: MergeUVRow_ = MergeUVRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); michael@0: for (int y = 0; y < halfheight; ++y) { michael@0: // Merge a row of U and V into a row of UV. michael@0: MergeUVRow_(src_u, src_v, dst_uv, halfwidth); michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: dst_uv += dst_stride_uv; michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: LIBYUV_API michael@0: int I420ToNV21(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_vu, int dst_stride_vu, michael@0: int width, int height) { michael@0: return I420ToNV12(src_y, src_stride_y, michael@0: src_v, src_stride_v, michael@0: src_u, src_stride_u, michael@0: dst_y, src_stride_y, michael@0: dst_vu, dst_stride_vu, michael@0: width, height); michael@0: } michael@0: michael@0: // Convert I420 to ARGB. michael@0: LIBYUV_API michael@0: int I420ToARGB(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_argb, int dst_stride_argb, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_argb || 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: dst_argb = dst_argb + (height - 1) * dst_stride_argb; michael@0: dst_stride_argb = -dst_stride_argb; michael@0: } michael@0: void (*I422ToARGBRow)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToARGBRow_C; michael@0: #if defined(HAS_I422TOARGBROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToARGBRow = I422ToARGBRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGBRow = I422ToARGBRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_argb, 16) && IS_ALIGNED(dst_stride_argb, 16)) { michael@0: I422ToARGBRow = I422ToARGBRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_I422TOARGBROW_AVX2) michael@0: if (TestCpuFlag(kCpuHasAVX2) && width >= 16) { michael@0: I422ToARGBRow = I422ToARGBRow_Any_AVX2; michael@0: if (IS_ALIGNED(width, 16)) { michael@0: I422ToARGBRow = I422ToARGBRow_AVX2; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_I422TOARGBROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToARGBRow = I422ToARGBRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGBRow = I422ToARGBRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(HAS_I422TOARGBROW_MIPS_DSPR2) michael@0: if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && michael@0: IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && michael@0: IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && michael@0: IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && michael@0: IS_ALIGNED(dst_argb, 4) && IS_ALIGNED(dst_stride_argb, 4)) { michael@0: I422ToARGBRow = I422ToARGBRow_MIPS_DSPR2; michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToARGBRow(src_y, src_u, src_v, dst_argb, width); michael@0: dst_argb += dst_stride_argb; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to BGRA. michael@0: LIBYUV_API michael@0: int I420ToBGRA(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_bgra, int dst_stride_bgra, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_bgra || 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: dst_bgra = dst_bgra + (height - 1) * dst_stride_bgra; michael@0: dst_stride_bgra = -dst_stride_bgra; michael@0: } michael@0: void (*I422ToBGRARow)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToBGRARow_C; michael@0: #if defined(HAS_I422TOBGRAROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToBGRARow = I422ToBGRARow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToBGRARow = I422ToBGRARow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_bgra, 16) && IS_ALIGNED(dst_stride_bgra, 16)) { michael@0: I422ToBGRARow = I422ToBGRARow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOBGRAROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToBGRARow = I422ToBGRARow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToBGRARow = I422ToBGRARow_NEON; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOBGRAROW_MIPS_DSPR2) michael@0: if (TestCpuFlag(kCpuHasMIPS_DSPR2) && IS_ALIGNED(width, 4) && michael@0: IS_ALIGNED(src_y, 4) && IS_ALIGNED(src_stride_y, 4) && michael@0: IS_ALIGNED(src_u, 2) && IS_ALIGNED(src_stride_u, 2) && michael@0: IS_ALIGNED(src_v, 2) && IS_ALIGNED(src_stride_v, 2) && michael@0: IS_ALIGNED(dst_bgra, 4) && IS_ALIGNED(dst_stride_bgra, 4)) { michael@0: I422ToBGRARow = I422ToBGRARow_MIPS_DSPR2; michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToBGRARow(src_y, src_u, src_v, dst_bgra, width); michael@0: dst_bgra += dst_stride_bgra; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to ABGR. michael@0: LIBYUV_API michael@0: int I420ToABGR(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_abgr, int dst_stride_abgr, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_abgr || 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: dst_abgr = dst_abgr + (height - 1) * dst_stride_abgr; michael@0: dst_stride_abgr = -dst_stride_abgr; michael@0: } michael@0: void (*I422ToABGRRow)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToABGRRow_C; michael@0: #if defined(HAS_I422TOABGRROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToABGRRow = I422ToABGRRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToABGRRow = I422ToABGRRow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_abgr, 16) && IS_ALIGNED(dst_stride_abgr, 16)) { michael@0: I422ToABGRRow = I422ToABGRRow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOABGRROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToABGRRow = I422ToABGRRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToABGRRow = I422ToABGRRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToABGRRow(src_y, src_u, src_v, dst_abgr, width); michael@0: dst_abgr += dst_stride_abgr; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to RGBA. michael@0: LIBYUV_API michael@0: int I420ToRGBA(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_rgba, int dst_stride_rgba, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_rgba || 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: dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; michael@0: dst_stride_rgba = -dst_stride_rgba; michael@0: } michael@0: void (*I422ToRGBARow)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToRGBARow_C; michael@0: #if defined(HAS_I422TORGBAROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToRGBARow = I422ToRGBARow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGBARow = I422ToRGBARow_Unaligned_SSSE3; michael@0: if (IS_ALIGNED(dst_rgba, 16) && IS_ALIGNED(dst_stride_rgba, 16)) { michael@0: I422ToRGBARow = I422ToRGBARow_SSSE3; michael@0: } michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TORGBAROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToRGBARow = I422ToRGBARow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGBARow = I422ToRGBARow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToRGBARow(src_y, src_u, src_v, dst_rgba, width); michael@0: dst_rgba += dst_stride_rgba; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to RGB24. michael@0: LIBYUV_API michael@0: int I420ToRGB24(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_rgb24, int dst_stride_rgb24, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_rgb24 || 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: dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; michael@0: dst_stride_rgb24 = -dst_stride_rgb24; michael@0: } michael@0: void (*I422ToRGB24Row)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToRGB24Row_C; michael@0: #if defined(HAS_I422TORGB24ROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToRGB24Row = I422ToRGB24Row_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGB24Row = I422ToRGB24Row_SSSE3; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TORGB24ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToRGB24Row = I422ToRGB24Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGB24Row = I422ToRGB24Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToRGB24Row(src_y, src_u, src_v, dst_rgb24, width); michael@0: dst_rgb24 += dst_stride_rgb24; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to RAW. michael@0: LIBYUV_API michael@0: int I420ToRAW(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_raw, int dst_stride_raw, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_raw || 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: dst_raw = dst_raw + (height - 1) * dst_stride_raw; michael@0: dst_stride_raw = -dst_stride_raw; michael@0: } michael@0: void (*I422ToRAWRow)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToRAWRow_C; michael@0: #if defined(HAS_I422TORAWROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToRAWRow = I422ToRAWRow_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRAWRow = I422ToRAWRow_SSSE3; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TORAWROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToRAWRow = I422ToRAWRow_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRAWRow = I422ToRAWRow_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToRAWRow(src_y, src_u, src_v, dst_raw, width); michael@0: dst_raw += dst_stride_raw; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to ARGB1555. michael@0: LIBYUV_API michael@0: int I420ToARGB1555(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_argb1555, int dst_stride_argb1555, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_argb1555 || 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: dst_argb1555 = dst_argb1555 + (height - 1) * dst_stride_argb1555; michael@0: dst_stride_argb1555 = -dst_stride_argb1555; michael@0: } michael@0: void (*I422ToARGB1555Row)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToARGB1555Row_C; michael@0: #if defined(HAS_I422TOARGB1555ROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToARGB1555Row = I422ToARGB1555Row_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGB1555Row = I422ToARGB1555Row_SSSE3; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOARGB1555ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToARGB1555Row = I422ToARGB1555Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGB1555Row = I422ToARGB1555Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToARGB1555Row(src_y, src_u, src_v, dst_argb1555, width); michael@0: dst_argb1555 += dst_stride_argb1555; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: michael@0: // Convert I420 to ARGB4444. michael@0: LIBYUV_API michael@0: int I420ToARGB4444(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_argb4444, int dst_stride_argb4444, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_argb4444 || 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: dst_argb4444 = dst_argb4444 + (height - 1) * dst_stride_argb4444; michael@0: dst_stride_argb4444 = -dst_stride_argb4444; michael@0: } michael@0: void (*I422ToARGB4444Row)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToARGB4444Row_C; michael@0: #if defined(HAS_I422TOARGB4444ROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToARGB4444Row = I422ToARGB4444Row_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGB4444Row = I422ToARGB4444Row_SSSE3; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TOARGB4444ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToARGB4444Row = I422ToARGB4444Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToARGB4444Row = I422ToARGB4444Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToARGB4444Row(src_y, src_u, src_v, dst_argb4444, width); michael@0: dst_argb4444 += dst_stride_argb4444; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to RGB565. michael@0: LIBYUV_API michael@0: int I420ToRGB565(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_rgb565, int dst_stride_rgb565, michael@0: int width, int height) { michael@0: if (!src_y || !src_u || !src_v || !dst_rgb565 || 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: dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; michael@0: dst_stride_rgb565 = -dst_stride_rgb565; michael@0: } michael@0: void (*I422ToRGB565Row)(const uint8* y_buf, michael@0: const uint8* u_buf, michael@0: const uint8* v_buf, michael@0: uint8* rgb_buf, michael@0: int width) = I422ToRGB565Row_C; michael@0: #if defined(HAS_I422TORGB565ROW_SSSE3) michael@0: if (TestCpuFlag(kCpuHasSSSE3) && width >= 8) { michael@0: I422ToRGB565Row = I422ToRGB565Row_Any_SSSE3; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGB565Row = I422ToRGB565Row_SSSE3; michael@0: } michael@0: } michael@0: #elif defined(HAS_I422TORGB565ROW_NEON) michael@0: if (TestCpuFlag(kCpuHasNEON) && width >= 8) { michael@0: I422ToRGB565Row = I422ToRGB565Row_Any_NEON; michael@0: if (IS_ALIGNED(width, 8)) { michael@0: I422ToRGB565Row = I422ToRGB565Row_NEON; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: for (int y = 0; y < height; ++y) { michael@0: I422ToRGB565Row(src_y, src_u, src_v, dst_rgb565, width); michael@0: dst_rgb565 += dst_stride_rgb565; michael@0: src_y += src_stride_y; michael@0: if (y & 1) { michael@0: src_u += src_stride_u; michael@0: src_v += src_stride_v; michael@0: } michael@0: } michael@0: return 0; michael@0: } michael@0: michael@0: // Convert I420 to specified format michael@0: LIBYUV_API michael@0: int ConvertFromI420(const uint8* y, int y_stride, michael@0: const uint8* u, int u_stride, michael@0: const uint8* v, int v_stride, michael@0: uint8* dst_sample, int dst_sample_stride, michael@0: int width, int height, michael@0: uint32 fourcc) { michael@0: uint32 format = CanonicalFourCC(fourcc); michael@0: if (!y || !u|| !v || !dst_sample || michael@0: width <= 0 || height == 0) { michael@0: return -1; michael@0: } michael@0: int r = 0; michael@0: switch (format) { michael@0: // Single plane formats michael@0: case FOURCC_YUY2: michael@0: r = I420ToYUY2(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 2, michael@0: width, height); michael@0: break; michael@0: case FOURCC_UYVY: michael@0: r = I420ToUYVY(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 2, michael@0: width, height); michael@0: break; michael@0: case FOURCC_RGBP: michael@0: r = I420ToRGB565(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 2, michael@0: width, height); michael@0: break; michael@0: case FOURCC_RGBO: michael@0: r = I420ToARGB1555(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 2, michael@0: width, height); michael@0: break; michael@0: case FOURCC_R444: michael@0: r = I420ToARGB4444(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 2, michael@0: width, height); michael@0: break; michael@0: case FOURCC_24BG: michael@0: r = I420ToRGB24(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 3, michael@0: width, height); michael@0: break; michael@0: case FOURCC_RAW: michael@0: r = I420ToRAW(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 3, michael@0: width, height); michael@0: break; michael@0: case FOURCC_ARGB: michael@0: r = I420ToARGB(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 4, michael@0: width, height); michael@0: break; michael@0: case FOURCC_BGRA: michael@0: r = I420ToBGRA(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 4, michael@0: width, height); michael@0: break; michael@0: case FOURCC_ABGR: michael@0: r = I420ToABGR(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 4, michael@0: width, height); michael@0: break; michael@0: case FOURCC_RGBA: michael@0: r = I420ToRGBA(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width * 4, michael@0: width, height); michael@0: break; michael@0: case FOURCC_BGGR: michael@0: r = I420ToBayerBGGR(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: case FOURCC_GBRG: michael@0: r = I420ToBayerGBRG(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: case FOURCC_GRBG: michael@0: r = I420ToBayerGRBG(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: case FOURCC_RGGB: michael@0: r = I420ToBayerRGGB(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: case FOURCC_I400: michael@0: r = I400Copy(y, y_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: case FOURCC_NV12: { michael@0: uint8* dst_uv = dst_sample + width * height; michael@0: r = I420ToNV12(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: dst_uv, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: } michael@0: case FOURCC_NV21: { michael@0: uint8* dst_vu = dst_sample + width * height; michael@0: r = I420ToNV21(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: dst_vu, michael@0: dst_sample_stride ? dst_sample_stride : width, michael@0: width, height); michael@0: break; michael@0: } michael@0: // TODO(fbarchard): Add M420 and Q420. michael@0: // Triplanar formats michael@0: // TODO(fbarchard): halfstride instead of halfwidth michael@0: case FOURCC_I420: michael@0: case FOURCC_YU12: michael@0: case FOURCC_YV12: { michael@0: int halfwidth = (width + 1) / 2; michael@0: int halfheight = (height + 1) / 2; michael@0: uint8* dst_u; michael@0: uint8* dst_v; michael@0: if (format == FOURCC_YV12) { michael@0: dst_v = dst_sample + width * height; michael@0: dst_u = dst_v + halfwidth * halfheight; michael@0: } else { michael@0: dst_u = dst_sample + width * height; michael@0: dst_v = dst_u + halfwidth * halfheight; michael@0: } michael@0: r = I420Copy(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, width, michael@0: dst_u, halfwidth, michael@0: dst_v, halfwidth, michael@0: width, height); michael@0: break; michael@0: } michael@0: case FOURCC_I422: michael@0: case FOURCC_YV16: { michael@0: int halfwidth = (width + 1) / 2; michael@0: uint8* dst_u; michael@0: uint8* dst_v; michael@0: if (format == FOURCC_YV16) { michael@0: dst_v = dst_sample + width * height; michael@0: dst_u = dst_v + halfwidth * height; michael@0: } else { michael@0: dst_u = dst_sample + width * height; michael@0: dst_v = dst_u + halfwidth * height; michael@0: } michael@0: r = I420ToI422(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, width, michael@0: dst_u, halfwidth, michael@0: dst_v, halfwidth, michael@0: width, height); michael@0: break; michael@0: } michael@0: case FOURCC_I444: michael@0: case FOURCC_YV24: { michael@0: uint8* dst_u; michael@0: uint8* dst_v; michael@0: if (format == FOURCC_YV24) { michael@0: dst_v = dst_sample + width * height; michael@0: dst_u = dst_v + width * height; michael@0: } else { michael@0: dst_u = dst_sample + width * height; michael@0: dst_v = dst_u + width * height; michael@0: } michael@0: r = I420ToI444(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, width, michael@0: dst_u, width, michael@0: dst_v, width, michael@0: width, height); michael@0: break; michael@0: } michael@0: case FOURCC_I411: { michael@0: int quarterwidth = (width + 3) / 4; michael@0: uint8* dst_u = dst_sample + width * height; michael@0: uint8* dst_v = dst_u + quarterwidth * height; michael@0: r = I420ToI411(y, y_stride, michael@0: u, u_stride, michael@0: v, v_stride, michael@0: dst_sample, width, michael@0: dst_u, quarterwidth, michael@0: dst_v, quarterwidth, michael@0: width, height); michael@0: break; michael@0: } michael@0: michael@0: // Formats not supported - MJPG, biplanar, some rgb formats. michael@0: default: michael@0: return -1; // unknown fourcc - return failure code. michael@0: } michael@0: return r; michael@0: } michael@0: michael@0: #ifdef __cplusplus michael@0: } // extern "C" michael@0: } // namespace libyuv michael@0: #endif