summaryrefslogtreecommitdiffstats
path: root/media/libwebp/sharpyuv/sharpyuv.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /media/libwebp/sharpyuv/sharpyuv.h
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'media/libwebp/sharpyuv/sharpyuv.h')
-rw-r--r--media/libwebp/sharpyuv/sharpyuv.h85
1 files changed, 77 insertions, 8 deletions
diff --git a/media/libwebp/sharpyuv/sharpyuv.h b/media/libwebp/sharpyuv/sharpyuv.h
index 7b9904d6f9..fe95891599 100644
--- a/media/libwebp/sharpyuv/sharpyuv.h
+++ b/media/libwebp/sharpyuv/sharpyuv.h
@@ -22,22 +22,37 @@ extern "C" {
#else
// This explicitly marks library functions and allows for changing the
// signature for e.g., Windows DLL builds.
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define SHARPYUV_EXTERN extern __attribute__((visibility("default")))
-#else
-#if defined(_MSC_VER) && defined(WEBP_DLL)
+#if defined(_WIN32) && defined(WEBP_DLL)
#define SHARPYUV_EXTERN __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
+#define SHARPYUV_EXTERN extern __attribute__((visibility("default")))
#else
#define SHARPYUV_EXTERN extern
-#endif /* _MSC_VER && WEBP_DLL */
-#endif /* __GNUC__ >= 4 */
+#endif /* defined(_WIN32) && defined(WEBP_DLL) */
#endif /* WEBP_EXTERN */
#endif /* SHARPYUV_EXTERN */
+#ifndef SHARPYUV_INLINE
+#ifdef WEBP_INLINE
+#define SHARPYUV_INLINE WEBP_INLINE
+#else
+#ifndef _MSC_VER
+#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+#define SHARPYUV_INLINE inline
+#else
+#define SHARPYUV_INLINE
+#endif
+#else
+#define SHARPYUV_INLINE __forceinline
+#endif /* _MSC_VER */
+#endif /* WEBP_INLINE */
+#endif /* SHARPYUV_INLINE */
+
// SharpYUV API version following the convention from semver.org
#define SHARPYUV_VERSION_MAJOR 0
-#define SHARPYUV_VERSION_MINOR 2
-#define SHARPYUV_VERSION_PATCH 1
+#define SHARPYUV_VERSION_MINOR 4
+#define SHARPYUV_VERSION_PATCH 0
// Version as a uint32_t. The major number is the high 8 bits.
// The minor number is the middle 8 bits. The patch number is the low 16 bits.
#define SHARPYUV_MAKE_VERSION(MAJOR, MINOR, PATCH) \
@@ -61,6 +76,33 @@ typedef struct {
int rgb_to_v[4];
} SharpYuvConversionMatrix;
+typedef struct SharpYuvOptions SharpYuvOptions;
+
+// Enums for transfer functions, as defined in H.273,
+// https://www.itu.int/rec/T-REC-H.273-202107-I/en
+typedef enum SharpYuvTransferFunctionType {
+ // 0 is reserved
+ kSharpYuvTransferFunctionBt709 = 1,
+ // 2 is unspecified
+ // 3 is reserved
+ kSharpYuvTransferFunctionBt470M = 4,
+ kSharpYuvTransferFunctionBt470Bg = 5,
+ kSharpYuvTransferFunctionBt601 = 6,
+ kSharpYuvTransferFunctionSmpte240 = 7,
+ kSharpYuvTransferFunctionLinear = 8,
+ kSharpYuvTransferFunctionLog100 = 9,
+ kSharpYuvTransferFunctionLog100_Sqrt10 = 10,
+ kSharpYuvTransferFunctionIec61966 = 11,
+ kSharpYuvTransferFunctionBt1361 = 12,
+ kSharpYuvTransferFunctionSrgb = 13,
+ kSharpYuvTransferFunctionBt2020_10Bit = 14,
+ kSharpYuvTransferFunctionBt2020_12Bit = 15,
+ kSharpYuvTransferFunctionSmpte2084 = 16, // PQ
+ kSharpYuvTransferFunctionSmpte428 = 17,
+ kSharpYuvTransferFunctionHlg = 18,
+ kSharpYuvTransferFunctionNum
+} SharpYuvTransferFunctionType;
+
// Converts RGB to YUV420 using a downsampling algorithm that minimizes
// artefacts caused by chroma subsampling.
// This is slower than standard downsampling (averaging of 4 UV values).
@@ -85,6 +127,8 @@ typedef struct {
// adjacent pixels on the y, u and v channels. If yuv_bit_depth > 8, they
// should be multiples of 2.
// width, height: width and height of the image in pixels
+// This function calls SharpYuvConvertWithOptions with a default transfer
+// function of kSharpYuvTransferFunctionSrgb.
SHARPYUV_EXTERN int SharpYuvConvert(const void* r_ptr, const void* g_ptr,
const void* b_ptr, int rgb_step,
int rgb_stride, int rgb_bit_depth,
@@ -93,6 +137,31 @@ SHARPYUV_EXTERN int SharpYuvConvert(const void* r_ptr, const void* g_ptr,
int yuv_bit_depth, int width, int height,
const SharpYuvConversionMatrix* yuv_matrix);
+struct SharpYuvOptions {
+ // This matrix cannot be NULL and can be initialized by
+ // SharpYuvComputeConversionMatrix.
+ const SharpYuvConversionMatrix* yuv_matrix;
+ SharpYuvTransferFunctionType transfer_type;
+};
+
+// Internal, version-checked, entry point
+SHARPYUV_EXTERN int SharpYuvOptionsInitInternal(const SharpYuvConversionMatrix*,
+ SharpYuvOptions*, int);
+
+// Should always be called, to initialize a fresh SharpYuvOptions
+// structure before modification. SharpYuvOptionsInit() must have succeeded
+// before using the 'options' object.
+static SHARPYUV_INLINE int SharpYuvOptionsInit(
+ const SharpYuvConversionMatrix* yuv_matrix, SharpYuvOptions* options) {
+ return SharpYuvOptionsInitInternal(yuv_matrix, options, SHARPYUV_VERSION);
+}
+
+SHARPYUV_EXTERN int SharpYuvConvertWithOptions(
+ const void* r_ptr, const void* g_ptr, const void* b_ptr, int rgb_step,
+ int rgb_stride, int rgb_bit_depth, void* y_ptr, int y_stride, void* u_ptr,
+ int u_stride, void* v_ptr, int v_stride, int yuv_bit_depth, int width,
+ int height, const SharpYuvOptions* options);
+
// TODO(b/194336375): Add YUV444 to YUV420 conversion. Maybe also add 422
// support (it's rarely used in practice, especially for images).