2231 lines · 68.3 KB · C++
RawDownload
/* *  Copyright 2011 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_argb.h" #include "libyuv/cpu_id.h"#ifdef HAVE_JPEG#include "libyuv/mjpeg_decoder.h"#endif#include "libyuv/planar_functions.h"  // For CopyPlane and ARGBShuffle.#include "libyuv/rotate_argb.h"#include "libyuv/row.h"#include "libyuv/video_common.h" #ifdef __cplusplusnamespace libyuv {extern "C" {#endif // Copy ARGB with optional flippingLIBYUV_APIint ARGBCopy(const uint8_t* src_argb,             int src_stride_argb,             uint8_t* dst_argb,             int dst_stride_argb,             int width,             int height) {  if (!src_argb || !dst_argb || width <= 0 || height == 0) {    return -1;  }  // Negative height means invert the image.  if (height < 0) {    height = -height;    src_argb = src_argb + (height - 1) * src_stride_argb;    src_stride_argb = -src_stride_argb;  }   CopyPlane(src_argb, src_stride_argb, dst_argb, dst_stride_argb, width * 4,            height);  return 0;} // Convert I420 to ARGB with matrixstatic int I420ToARGBMatrix(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_argb,                            int dst_stride_argb,                            const struct YuvConstants* yuvconstants,                            int width,                            int height) {  int y;  void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,                        const uint8_t* v_buf, uint8_t* rgb_buf,                        const struct YuvConstants* yuvconstants, int width) =      I422ToARGBRow_C;  if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {    return -1;  }  // Negative height means invert the image.  if (height < 0) {    height = -height;    dst_argb = dst_argb + (height - 1) * dst_stride_argb;    dst_stride_argb = -dst_stride_argb;  }#if defined(HAS_I422TOARGBROW_SSSE3)  if (TestCpuFlag(kCpuHasSSSE3)) {    I422ToARGBRow = I422ToARGBRow_Any_SSSE3;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_SSSE3;    }  }#endif#if defined(HAS_I422TOARGBROW_AVX2)  if (TestCpuFlag(kCpuHasAVX2)) {    I422ToARGBRow = I422ToARGBRow_Any_AVX2;    if (IS_ALIGNED(width, 16)) {      I422ToARGBRow = I422ToARGBRow_AVX2;    }  }#endif#if defined(HAS_I422TOARGBROW_NEON)  if (TestCpuFlag(kCpuHasNEON)) {    I422ToARGBRow = I422ToARGBRow_Any_NEON;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_NEON;    }  }#endif#if defined(HAS_I422TOARGBROW_MSA)  if (TestCpuFlag(kCpuHasMSA)) {    I422ToARGBRow = I422ToARGBRow_Any_MSA;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_MSA;    }  }#endif   for (y = 0; y < height; ++y) {    I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);    dst_argb += dst_stride_argb;    src_y += src_stride_y;    if (y & 1) {      src_u += src_stride_u;      src_v += src_stride_v;    }  }  return 0;} // Convert I420 to ARGB.LIBYUV_APIint I420ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvI601Constants, width, height);} // Convert I420 to ABGR.LIBYUV_APIint I420ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuI601Constants,  // Use Yvu matrix                          width, height);} // Convert J420 to ARGB.LIBYUV_APIint J420ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvJPEGConstants, width, height);} // Convert J420 to ABGR.LIBYUV_APIint J420ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuJPEGConstants,  // Use Yvu matrix                          width, height);} // Convert H420 to ARGB.LIBYUV_APIint H420ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvH709Constants, width, height);} // Convert H420 to ABGR.LIBYUV_APIint H420ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I420ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuH709Constants,  // Use Yvu matrix                          width, height);} // Convert I422 to ARGB with matrixstatic int I422ToARGBMatrix(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_argb,                            int dst_stride_argb,                            const struct YuvConstants* yuvconstants,                            int width,                            int height) {  int y;  void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,                        const uint8_t* v_buf, uint8_t* rgb_buf,                        const struct YuvConstants* yuvconstants, int width) =      I422ToARGBRow_C;  if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) {    return -1;  }  // Negative height means invert the image.  if (height < 0) {    height = -height;    dst_argb = dst_argb + (height - 1) * dst_stride_argb;    dst_stride_argb = -dst_stride_argb;  }  // Coalesce rows.  if (src_stride_y == width && src_stride_u * 2 == width &&      src_stride_v * 2 == width && dst_stride_argb == width * 4) {    width *= height;    height = 1;    src_stride_y = src_stride_u = src_stride_v = dst_stride_argb = 0;  }#if defined(HAS_I422TOARGBROW_SSSE3)  if (TestCpuFlag(kCpuHasSSSE3)) {    I422ToARGBRow = I422ToARGBRow_Any_SSSE3;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_SSSE3;    }  }#endif#if defined(HAS_I422TOARGBROW_AVX2)  if (TestCpuFlag(kCpuHasAVX2)) {    I422ToARGBRow = I422ToARGBRow_Any_AVX2;    if (IS_ALIGNED(width, 16)) {      I422ToARGBRow = I422ToARGBRow_AVX2;    }  }#endif#if defined(HAS_I422TOARGBROW_NEON)  if (TestCpuFlag(kCpuHasNEON)) {    I422ToARGBRow = I422ToARGBRow_Any_NEON;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_NEON;    }  }#endif#if defined(HAS_I422TOARGBROW_MSA)  if (TestCpuFlag(kCpuHasMSA)) {    I422ToARGBRow = I422ToARGBRow_Any_MSA;    if (IS_ALIGNED(width, 8)) {      I422ToARGBRow = I422ToARGBRow_MSA;    }  }#endif   for (y = 0; y < height; ++y) {    I422ToARGBRow(src_y, src_u, src_v, dst_argb, yuvconstants, width);    dst_argb += dst_stride_argb;    src_y += src_stride_y;    src_u += src_stride_u;    src_v += src_stride_v;  }  return 0;} // Convert I422 to ARGB.LIBYUV_APIint I422ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvI601Constants, width, height);} // Convert I422 to ABGR.LIBYUV_APIint I422ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuI601Constants,  // Use Yvu matrix                          width, height);} // Convert J422 to ARGB.LIBYUV_APIint J422ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvJPEGConstants, width, height);} // Convert J422 to ABGR.LIBYUV_APIint J422ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuJPEGConstants,  // Use Yvu matrix                          width, height);} // Convert H422 to ARGB.LIBYUV_APIint H422ToARGB(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_argb,               int dst_stride_argb,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_argb, dst_stride_argb,                          &kYuvH709Constants, width, height);} // Convert H422 to ABGR.LIBYUV_APIint H422ToABGR(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_abgr,               int dst_stride_abgr,               int width,               int height) {  return I422ToARGBMatrix(src_y, src_stride_y, src_v,                          src_stride_v,  // Swap U and V                          src_u, src_stride_u, dst_abgr, dst_stride_abgr,                          &kYvuH709Constants,  // Use Yvu matrix                          width, height);} // Convert 10 bit YUV to ARGB with matrix// TODO(fbarchard): Consider passing scale multiplier to I210ToARGB to// multiply 10 bit yuv into high bits to allow any number of bits.static int I010ToAR30Matrix(const uint16_t* src_y,                            int src_stride_y,                            const uint16_t* src_u,                            int src_stride_u,                            const uint16_t* src_v,                            int src_stride_v,                            uint8_t* dst_ar30,                            int dst_stride_ar30,                            const struct YuvConstants* yuvconstants,                            int width,                            int height) {  int y;  void (*I210ToAR30Row)(const uint16_t* y_buf, const uint16_t* u_buf,                        const uint16_t* v_buf, uint8_t* rgb_buf,                        const struct YuvConstants* yuvconstants, int width) =      I210ToAR30Row_C;  if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) {    return -1;  }  // Negative height means invert the image.  if (height < 0) {    height = -height;    dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30;    dst_stride_ar30 = -dst_stride_ar30;  }#if defined(HAS_I210TOAR30ROW_SSSE3)  if (TestCpuFlag(kCpuHasSSSE3)) {    I210ToAR30Row = I210ToAR30Row_Any_SSSE3;    if (IS_ALIGNED(width, 8)) {      I210ToAR30Row = I210ToAR30Row_SSSE3;    }  }#endif#if defined(HAS_I210TOAR30ROW_AVX2)  if (TestCpuFlag(kCpuHasAVX2)) {    I210ToAR30Row = I210ToAR30Row_Any_AVX2;    if (IS_ALIGNED(width, 16)) {      I210ToAR30Row = I210ToAR30Row_AVX2;    }  }#endif  for (y = 0; y < height; ++y) {    I210ToAR30Row(src_y, src_u, src_v, dst_ar30, yuvconstants, width);    dst_ar30 += dst_stride_ar30;    src_y += src_stride_y;    if (y & 1) {      src_u += src_stride_u;      src_v += src_stride_v;    }  }  return 0;} // Convert I010 to AR30.LIBYUV_APIint I010ToAR30(const uint16_t* src_y,               int src_stride_y,               const uint16_t* src_u,               int src_stride_u,               const uint16_t* src_v,               int src_stride_v,               uint8_t* dst_ar30,               int dst_stride_ar30,               int width,               int height) {  return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_ar30, dst_stride_ar30,                          &kYuvI601Constants, width, height);} // Convert H010 to AR30.LIBYUV_APIint H010ToAR30(const uint16_t* src_y,               int src_stride_y,               const uint16_t* src_u,               int src_stride_u,               const uint16_t* src_v,               int src_stride_v,               uint8_t* dst_ar30,               int dst_stride_ar30,               int width,               int height) {  return I010ToAR30Matrix(src_y, src_stride_y, src_u, src_stride_u, src_v,                          src_stride_v, dst_ar30, dst_stride_ar30,                          &kYuvH709Constants, width, height);

Lines 1–500 of 2231.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t