123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- /*
- * Copyright 2012 The LibYuv Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
- #include "libyuv/convert_from.h"
- #include "libyuv/basic_types.h"
- #include "libyuv/convert.h" // For I420Copy
- #include "libyuv/cpu_id.h"
- #include "libyuv/planar_functions.h"
- #include "libyuv/rotate.h"
- #include "libyuv/row.h"
- #include "libyuv/scale.h" // For ScalePlane()
- #include "libyuv/video_common.h"
- #ifdef __cplusplus
- namespace libyuv {
- extern "C" {
- #endif
- #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
- static __inline int Abs(int v) {
- return v >= 0 ? v : -v;
- }
- // I420 To any I4xx YUV format with mirroring.
- static int I420ToI4xx(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_y,
- int dst_stride_y,
- uint8_t* dst_u,
- int dst_stride_u,
- uint8_t* dst_v,
- int dst_stride_v,
- int src_y_width,
- int src_y_height,
- int dst_uv_width,
- int dst_uv_height) {
- const int dst_y_width = Abs(src_y_width);
- const int dst_y_height = Abs(src_y_height);
- const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1);
- const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1);
- if (src_y_width == 0 || src_y_height == 0 || dst_uv_width <= 0 ||
- dst_uv_height <= 0) {
- return -1;
- }
- if (dst_y) {
- ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, dst_y,
- dst_stride_y, dst_y_width, dst_y_height, kFilterBilinear);
- }
- ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u,
- dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear);
- ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v,
- dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear);
- return 0;
- }
- // Convert 8 bit YUV to 10 bit.
- LIBYUV_API
- int I420ToI010(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint16_t* dst_y,
- int dst_stride_y,
- uint16_t* dst_u,
- int dst_stride_u,
- uint16_t* dst_v,
- int dst_stride_v,
- int width,
- int height) {
- int halfwidth = (width + 1) >> 1;
- int halfheight = (height + 1) >> 1;
- if (!src_u || !src_v || !dst_u || !dst_v || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- halfheight = (height + 1) >> 1;
- src_y = src_y + (height - 1) * src_stride_y;
- src_u = src_u + (halfheight - 1) * src_stride_u;
- src_v = src_v + (halfheight - 1) * src_stride_v;
- src_stride_y = -src_stride_y;
- src_stride_u = -src_stride_u;
- src_stride_v = -src_stride_v;
- }
- // Convert Y plane.
- Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width,
- height);
- // Convert UV planes.
- Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth,
- halfheight);
- Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth,
- halfheight);
- return 0;
- }
- // 420 chroma is 1/2 width, 1/2 height
- // 422 chroma is 1/2 width, 1x height
- LIBYUV_API
- int I420ToI422(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_y,
- int dst_stride_y,
- uint8_t* dst_u,
- int dst_stride_u,
- uint8_t* dst_v,
- int dst_stride_v,
- int width,
- int height) {
- const int dst_uv_width = (Abs(width) + 1) >> 1;
- const int dst_uv_height = Abs(height);
- return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
- src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
- dst_v, dst_stride_v, width, height, dst_uv_width,
- dst_uv_height);
- }
- // 420 chroma is 1/2 width, 1/2 height
- // 444 chroma is 1x width, 1x height
- LIBYUV_API
- int I420ToI444(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_y,
- int dst_stride_y,
- uint8_t* dst_u,
- int dst_stride_u,
- uint8_t* dst_v,
- int dst_stride_v,
- int width,
- int height) {
- const int dst_uv_width = Abs(width);
- const int dst_uv_height = Abs(height);
- return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
- src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
- dst_v, dst_stride_v, width, height, dst_uv_width,
- dst_uv_height);
- }
- // Copy to I400. Source can be I420,422,444,400,NV12,NV21
- LIBYUV_API
- int I400Copy(const uint8_t* src_y,
- int src_stride_y,
- uint8_t* dst_y,
- int dst_stride_y,
- int width,
- int height) {
- if (!src_y || !dst_y || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- src_y = src_y + (height - 1) * src_stride_y;
- src_stride_y = -src_stride_y;
- }
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
- return 0;
- }
- LIBYUV_API
- int I422ToYUY2(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_yuy2,
- int dst_stride_yuy2,
- int width,
- int height) {
- int y;
- void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
- const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
- I422ToYUY2Row_C;
- if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
- dst_stride_yuy2 = -dst_stride_yuy2;
- }
- // Coalesce rows.
- if (src_stride_y == width && src_stride_u * 2 == width &&
- src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) {
- width *= height;
- height = 1;
- src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0;
- }
- #if defined(HAS_I422TOYUY2ROW_SSE2)
- if (TestCpuFlag(kCpuHasSSE2)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
- if (IS_ALIGNED(width, 16)) {
- I422ToYUY2Row = I422ToYUY2Row_SSE2;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_AVX2)
- if (TestCpuFlag(kCpuHasAVX2)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
- if (IS_ALIGNED(width, 32)) {
- I422ToYUY2Row = I422ToYUY2Row_AVX2;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_NEON)
- if (TestCpuFlag(kCpuHasNEON)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
- if (IS_ALIGNED(width, 16)) {
- I422ToYUY2Row = I422ToYUY2Row_NEON;
- }
- }
- #endif
- for (y = 0; y < height; ++y) {
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
- src_y += src_stride_y;
- src_u += src_stride_u;
- src_v += src_stride_v;
- dst_yuy2 += dst_stride_yuy2;
- }
- return 0;
- }
- LIBYUV_API
- int I420ToYUY2(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_yuy2,
- int dst_stride_yuy2,
- int width,
- int height) {
- int y;
- void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
- const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
- I422ToYUY2Row_C;
- if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
- dst_stride_yuy2 = -dst_stride_yuy2;
- }
- #if defined(HAS_I422TOYUY2ROW_SSE2)
- if (TestCpuFlag(kCpuHasSSE2)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
- if (IS_ALIGNED(width, 16)) {
- I422ToYUY2Row = I422ToYUY2Row_SSE2;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_AVX2)
- if (TestCpuFlag(kCpuHasAVX2)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
- if (IS_ALIGNED(width, 32)) {
- I422ToYUY2Row = I422ToYUY2Row_AVX2;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_NEON)
- if (TestCpuFlag(kCpuHasNEON)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
- if (IS_ALIGNED(width, 16)) {
- I422ToYUY2Row = I422ToYUY2Row_NEON;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_MMI)
- if (TestCpuFlag(kCpuHasMMI)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_MMI;
- if (IS_ALIGNED(width, 8)) {
- I422ToYUY2Row = I422ToYUY2Row_MMI;
- }
- }
- #endif
- #if defined(HAS_I422TOYUY2ROW_MSA)
- if (TestCpuFlag(kCpuHasMSA)) {
- I422ToYUY2Row = I422ToYUY2Row_Any_MSA;
- if (IS_ALIGNED(width, 32)) {
- I422ToYUY2Row = I422ToYUY2Row_MSA;
- }
- }
- #endif
- for (y = 0; y < height - 1; y += 2) {
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
- I422ToYUY2Row(src_y + src_stride_y, src_u, src_v,
- dst_yuy2 + dst_stride_yuy2, width);
- src_y += src_stride_y * 2;
- src_u += src_stride_u;
- src_v += src_stride_v;
- dst_yuy2 += dst_stride_yuy2 * 2;
- }
- if (height & 1) {
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
- }
- return 0;
- }
- LIBYUV_API
- int I422ToUYVY(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_uyvy,
- int dst_stride_uyvy,
- int width,
- int height) {
- int y;
- void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
- const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
- I422ToUYVYRow_C;
- if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
- dst_stride_uyvy = -dst_stride_uyvy;
- }
- // Coalesce rows.
- if (src_stride_y == width && src_stride_u * 2 == width &&
- src_stride_v * 2 == width && dst_stride_uyvy == width * 2) {
- width *= height;
- height = 1;
- src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0;
- }
- #if defined(HAS_I422TOUYVYROW_SSE2)
- if (TestCpuFlag(kCpuHasSSE2)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
- if (IS_ALIGNED(width, 16)) {
- I422ToUYVYRow = I422ToUYVYRow_SSE2;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_AVX2)
- if (TestCpuFlag(kCpuHasAVX2)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
- if (IS_ALIGNED(width, 32)) {
- I422ToUYVYRow = I422ToUYVYRow_AVX2;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_NEON)
- if (TestCpuFlag(kCpuHasNEON)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
- if (IS_ALIGNED(width, 16)) {
- I422ToUYVYRow = I422ToUYVYRow_NEON;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_MMI)
- if (TestCpuFlag(kCpuHasMMI)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_MMI;
- if (IS_ALIGNED(width, 8)) {
- I422ToUYVYRow = I422ToUYVYRow_MMI;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_MSA)
- if (TestCpuFlag(kCpuHasMSA)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_MSA;
- if (IS_ALIGNED(width, 32)) {
- I422ToUYVYRow = I422ToUYVYRow_MSA;
- }
- }
- #endif
- for (y = 0; y < height; ++y) {
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
- src_y += src_stride_y;
- src_u += src_stride_u;
- src_v += src_stride_v;
- dst_uyvy += dst_stride_uyvy;
- }
- return 0;
- }
- LIBYUV_API
- int I420ToUYVY(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_uyvy,
- int dst_stride_uyvy,
- int width,
- int height) {
- int y;
- void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
- const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
- I422ToUYVYRow_C;
- if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
- dst_stride_uyvy = -dst_stride_uyvy;
- }
- #if defined(HAS_I422TOUYVYROW_SSE2)
- if (TestCpuFlag(kCpuHasSSE2)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
- if (IS_ALIGNED(width, 16)) {
- I422ToUYVYRow = I422ToUYVYRow_SSE2;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_AVX2)
- if (TestCpuFlag(kCpuHasAVX2)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
- if (IS_ALIGNED(width, 32)) {
- I422ToUYVYRow = I422ToUYVYRow_AVX2;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_NEON)
- if (TestCpuFlag(kCpuHasNEON)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
- if (IS_ALIGNED(width, 16)) {
- I422ToUYVYRow = I422ToUYVYRow_NEON;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_MMI)
- if (TestCpuFlag(kCpuHasMMI)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_MMI;
- if (IS_ALIGNED(width, 8)) {
- I422ToUYVYRow = I422ToUYVYRow_MMI;
- }
- }
- #endif
- #if defined(HAS_I422TOUYVYROW_MSA)
- if (TestCpuFlag(kCpuHasMSA)) {
- I422ToUYVYRow = I422ToUYVYRow_Any_MSA;
- if (IS_ALIGNED(width, 32)) {
- I422ToUYVYRow = I422ToUYVYRow_MSA;
- }
- }
- #endif
- for (y = 0; y < height - 1; y += 2) {
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
- I422ToUYVYRow(src_y + src_stride_y, src_u, src_v,
- dst_uyvy + dst_stride_uyvy, width);
- src_y += src_stride_y * 2;
- src_u += src_stride_u;
- src_v += src_stride_v;
- dst_uyvy += dst_stride_uyvy * 2;
- }
- if (height & 1) {
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
- }
- return 0;
- }
- LIBYUV_API
- int I420ToNV12(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_y,
- int dst_stride_y,
- uint8_t* dst_uv,
- int dst_stride_uv,
- int width,
- int height) {
- int halfwidth = (width + 1) / 2;
- int halfheight = (height + 1) / 2;
- if (!src_y || !src_u || !src_v || !dst_y || !dst_uv || width <= 0 ||
- height == 0) {
- return -1;
- }
- // Negative height means invert the image.
- if (height < 0) {
- height = -height;
- halfheight = (height + 1) >> 1;
- src_y = src_y + (height - 1) * src_stride_y;
- src_u = src_u + (halfheight - 1) * src_stride_u;
- src_v = src_v + (halfheight - 1) * src_stride_v;
- src_stride_y = -src_stride_y;
- src_stride_u = -src_stride_u;
- src_stride_v = -src_stride_v;
- }
- if (dst_y) {
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
- }
- MergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, dst_stride_uv,
- halfwidth, halfheight);
- return 0;
- }
- LIBYUV_API
- int I420ToNV21(const uint8_t* src_y,
- int src_stride_y,
- const uint8_t* src_u,
- int src_stride_u,
- const uint8_t* src_v,
- int src_stride_v,
- uint8_t* dst_y,
- int dst_stride_y,
- uint8_t* dst_vu,
- int dst_stride_vu,
- int width,
- int height) {
- return I420ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u,
- src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu,
- width, height);
- }
- // Convert I420 to specified format
- LIBYUV_API
- int ConvertFromI420(const uint8_t* y,
- int y_stride,
- const uint8_t* u,
- int u_stride,
- const uint8_t* v,
- int v_stride,
- uint8_t* dst_sample,
- int dst_sample_stride,
- int width,
- int height,
- uint32_t fourcc) {
- uint32_t format = CanonicalFourCC(fourcc);
- int r = 0;
- if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) {
- return -1;
- }
- switch (format) {
- // Single plane formats
- case FOURCC_YUY2:
- r = I420ToYUY2(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 2, width,
- height);
- break;
- case FOURCC_UYVY:
- r = I420ToUYVY(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 2, width,
- height);
- break;
- case FOURCC_RGBP:
- r = I420ToRGB565(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 2, width,
- height);
- break;
- case FOURCC_RGBO:
- r = I420ToARGB1555(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 2,
- width, height);
- break;
- case FOURCC_R444:
- r = I420ToARGB4444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 2,
- width, height);
- break;
- case FOURCC_24BG:
- r = I420ToRGB24(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 3, width,
- height);
- break;
- case FOURCC_RAW:
- r = I420ToRAW(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 3, width,
- height);
- break;
- case FOURCC_ARGB:
- r = I420ToARGB(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 4, width,
- height);
- break;
- case FOURCC_BGRA:
- r = I420ToBGRA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 4, width,
- height);
- break;
- case FOURCC_ABGR:
- r = I420ToABGR(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 4, width,
- height);
- break;
- case FOURCC_RGBA:
- r = I420ToRGBA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 4, width,
- height);
- break;
- case FOURCC_AR30:
- r = I420ToAR30(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width * 4, width,
- height);
- break;
- case FOURCC_I400:
- r = I400Copy(y, y_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width, width,
- height);
- break;
- case FOURCC_NV12: {
- uint8_t* dst_uv = dst_sample + width * height;
- r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width, dst_uv,
- dst_sample_stride ? dst_sample_stride : width, width,
- height);
- break;
- }
- case FOURCC_NV21: {
- uint8_t* dst_vu = dst_sample + width * height;
- r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride ? dst_sample_stride : width, dst_vu,
- dst_sample_stride ? dst_sample_stride : width, width,
- height);
- break;
- }
- // Triplanar formats
- case FOURCC_I420:
- case FOURCC_YV12: {
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
- int halfstride = (dst_sample_stride + 1) / 2;
- int halfheight = (height + 1) / 2;
- uint8_t* dst_u;
- uint8_t* dst_v;
- if (format == FOURCC_YV12) {
- dst_v = dst_sample + dst_sample_stride * height;
- dst_u = dst_v + halfstride * halfheight;
- } else {
- dst_u = dst_sample + dst_sample_stride * height;
- dst_v = dst_u + halfstride * halfheight;
- }
- r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
- width, height);
- break;
- }
- case FOURCC_I422:
- case FOURCC_YV16: {
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
- int halfstride = (dst_sample_stride + 1) / 2;
- uint8_t* dst_u;
- uint8_t* dst_v;
- if (format == FOURCC_YV16) {
- dst_v = dst_sample + dst_sample_stride * height;
- dst_u = dst_v + halfstride * height;
- } else {
- dst_u = dst_sample + dst_sample_stride * height;
- dst_v = dst_u + halfstride * height;
- }
- r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
- width, height);
- break;
- }
- case FOURCC_I444:
- case FOURCC_YV24: {
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
- uint8_t* dst_u;
- uint8_t* dst_v;
- if (format == FOURCC_YV24) {
- dst_v = dst_sample + dst_sample_stride * height;
- dst_u = dst_v + dst_sample_stride * height;
- } else {
- dst_u = dst_sample + dst_sample_stride * height;
- dst_v = dst_u + dst_sample_stride * height;
- }
- r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
- dst_sample_stride, dst_u, dst_sample_stride, dst_v,
- dst_sample_stride, width, height);
- break;
- }
- // Formats not supported - MJPG, biplanar, some rgb formats.
- default:
- return -1; // unknown fourcc - return failure code.
- }
- return r;
- }
- #ifdef __cplusplus
- } // extern "C"
- } // namespace libyuv
- #endif
|