#include "avif/internal.h"
#if !defined(AVIF_LIBYUV_ENABLED)
avifResult avifImageRGBToYUVLibYUV(avifImage * image, const avifRGBImage * rgb)
{
(void)image;
(void)rgb;
return AVIF_RESULT_NOT_IMPLEMENTED;
}
avifResult avifImageYUVToRGBLibYUV(const avifImage * image, avifRGBImage * rgb, avifBool reformatAlpha, avifBool * alphaReformattedWithLibYUV)
{
(void)image;
(void)rgb;
(void)reformatAlpha;
*alphaReformattedWithLibYUV = AVIF_FALSE;
return AVIF_RESULT_NOT_IMPLEMENTED;
}
avifResult avifRGBImagePremultiplyAlphaLibYUV(avifRGBImage * rgb)
{
(void)rgb;
return AVIF_RESULT_NOT_IMPLEMENTED;
}
avifResult avifRGBImageUnpremultiplyAlphaLibYUV(avifRGBImage * rgb)
{
(void)rgb;
return AVIF_RESULT_NOT_IMPLEMENTED;
}
avifResult avifRGBImageToF16LibYUV(avifRGBImage * rgb)
{
(void)rgb;
return AVIF_RESULT_NOT_IMPLEMENTED;
}
unsigned int avifLibYUVVersion(void)
{
return 0;
}
#else
#include <assert.h>
#include <limits.h>
#include <string.h>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#pragma clang diagnostic ignored "-Wnewline-eof"
#endif
#include <libyuv.h>
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#if defined(__clang__)
#define IGNORE_CFI_ICALL …
#else
#define IGNORE_CFI_ICALL
#endif
#if LIBYUV_VERSION < 1844
#define I444ToRGB24Matrix …
#define I422ToRGB24MatrixFilter …
#endif
#if LIBYUV_VERSION < 1841
#define I420ToRGB24MatrixFilter …
#endif
#if LIBYUV_VERSION < 1840
#define ABGRToJ400 …
#endif
#if LIBYUV_VERSION < 1838
#define I422ToRGB565Matrix …
#endif
#if LIBYUV_VERSION < 1813
#define I422ToARGBMatrixFilter …
#define I420ToARGBMatrixFilter …
#define I210ToARGBMatrixFilter …
#define I010ToARGBMatrixFilter …
#define I420AlphaToARGBMatrixFilter …
#define I422AlphaToARGBMatrixFilter …
#define I010AlphaToARGBMatrixFilter …
#define I210AlphaToARGBMatrixFilter …
#endif
#if LIBYUV_VERSION < 1782
#define RAWToJ420 …
#endif
#if LIBYUV_VERSION < 1781
#define I012ToARGBMatrix …
#endif
#if LIBYUV_VERSION < 1780
#define I410ToARGBMatrix …
#define I410AlphaToARGBMatrix …
#define I210AlphaToARGBMatrix …
#define I010AlphaToARGBMatrix …
#endif
#if LIBYUV_VERSION < 1771
#define I422AlphaToARGBMatrix …
#define I444AlphaToARGBMatrix …
#endif
#if LIBYUV_VERSION < 1756
#define I400ToARGBMatrix …
#endif
static int avifReorderARGBThenConvertToYUV(int (*ReorderARGB)(const uint8_t *, int, uint8_t *, int, int, int),
int (*ConvertToYUV)(const uint8_t *, int, uint8_t *, int, uint8_t *, int, uint8_t *, int, int, int),
const uint8_t * src_abgr,
int src_stride_abgr,
uint8_t * dst_y,
int dst_stride_y,
uint8_t * dst_u,
int dst_stride_u,
uint8_t * dst_v,
int dst_stride_v,
avifPixelFormat dst_format,
int width,
int height)
{ … }
#define AVIF_DEFINE_CONVERSION(NAME, REORDER_ARGB, CONVERT_TO_YUV, YUV_FORMAT) …
#if LIBYUV_VERSION < 1840
AVIF_DEFINE_CONVERSION(ABGRToJ422, ABGRToARGB, ARGBToJ422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(ABGRToJ420, ABGRToARGB, ARGBToJ420, AVIF_PIXEL_FORMAT_YUV420)
#endif
AVIF_DEFINE_CONVERSION(avifRAWToI444, RAWToARGB, ARGBToI444, AVIF_PIXEL_FORMAT_YUV444)
AVIF_DEFINE_CONVERSION(avifRAWToI422, RAWToARGB, ARGBToI422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifRAWToJ422, RAWToARGB, ARGBToJ422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifABGRToI444, ABGRToARGB, ARGBToI444, AVIF_PIXEL_FORMAT_YUV444)
AVIF_DEFINE_CONVERSION(avifABGRToI422, ABGRToARGB, ARGBToI422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifBGRAToI444, BGRAToARGB, ARGBToI444, AVIF_PIXEL_FORMAT_YUV444)
AVIF_DEFINE_CONVERSION(avifBGRAToI422, BGRAToARGB, ARGBToI422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifBGRAToJ422, BGRAToARGB, ARGBToJ422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifBGRAToJ420, BGRAToARGB, ARGBToJ420, AVIF_PIXEL_FORMAT_YUV420)
AVIF_DEFINE_CONVERSION(avifRGB24ToI444, RGB24ToARGB, ARGBToI444, AVIF_PIXEL_FORMAT_YUV444)
AVIF_DEFINE_CONVERSION(avifRGB24ToI422, RGB24ToARGB, ARGBToI422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifRGB24ToJ422, RGB24ToARGB, ARGBToJ422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifRGBAToI444, RGBAToARGB, ARGBToI444, AVIF_PIXEL_FORMAT_YUV444)
AVIF_DEFINE_CONVERSION(avifRGBAToI422, RGBAToARGB, ARGBToI422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifRGBAToJ422, RGBAToARGB, ARGBToJ422, AVIF_PIXEL_FORMAT_YUV422)
AVIF_DEFINE_CONVERSION(avifRGBAToJ420, RGBAToARGB, ARGBToJ420, AVIF_PIXEL_FORMAT_YUV420)
static avifResult avifImageRGBToYUVLibYUV8bpc(avifImage * image, const avifRGBImage * rgb);
avifResult avifImageRGBToYUVLibYUV(avifImage * image, const avifRGBImage * rgb)
{ … }
avifResult avifImageRGBToYUVLibYUV8bpc(avifImage * image, const avifRGBImage * rgb)
{ … }
static const avifBool lutIsYVU[AVIF_RGB_FORMAT_COUNT] = …;
YUV400ToRGBMatrix;
YUVToRGBMatrixFilter;
YUVAToRGBMatrixFilter;
YUVToRGBMatrix;
YUVAToRGBMatrix;
YUVToRGBMatrixFilterHighBitDepth;
YUVAToRGBMatrixFilterHighBitDepth;
YUVToRGBMatrixHighBitDepth;
YUVAToRGBMatrixHighBitDepth;
LibyuvConversionFunction;
static avifBool nearestNeighborFilterAllowed(int chromaUpsampling)
{ … }
static avifBool getLibYUVConversionFunction(avifPixelFormat yuvFormat,
int yuvDepth,
avifRGBImage * rgb,
avifBool alphaPreferred,
LibyuvConversionFunction * lcf)
{ … }
static void getLibYUVConstants(const avifImage * image, const struct YuvConstants ** matrixYUV, const struct YuvConstants ** matrixYVU)
{ … }
static avifResult avifImageDownshiftTo8bpc(const avifImage * image, avifImage * image8, avifBool downshiftAlpha)
{ … }
IGNORE_CFI_ICALL avifResult avifImageYUVToRGBLibYUV(const avifImage * image, avifRGBImage * rgb, avifBool reformatAlpha, avifBool * alphaReformattedWithLibYUV)
{ … }
avifResult avifRGBImagePremultiplyAlphaLibYUV(avifRGBImage * rgb)
{ … }
avifResult avifRGBImageUnpremultiplyAlphaLibYUV(avifRGBImage * rgb)
{ … }
avifResult avifRGBImageToF16LibYUV(avifRGBImage * rgb)
{ … }
unsigned int avifLibYUVVersion(void)
{ … }
#endif