/src/libwebp/sharpyuv/sharpyuv_dsp.h
Line | Count | Source |
1 | | // Copyright 2022 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style license |
4 | | // that can be found in the COPYING file in the root of the source |
5 | | // tree. An additional intellectual property rights grant can be found |
6 | | // in the file PATENTS. All contributing project authors may |
7 | | // be found in the AUTHORS file in the root of the source tree. |
8 | | // ----------------------------------------------------------------------------- |
9 | | // |
10 | | // Speed-critical functions for Sharp YUV. |
11 | | |
12 | | #ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_ |
13 | | #define WEBP_SHARPYUV_SHARPYUV_DSP_H_ |
14 | | |
15 | | #include "./sharpyuv_cpu.h" |
16 | | #include "webp/types.h" |
17 | | |
18 | | #ifdef __cplusplus |
19 | | extern "C" { |
20 | | #endif |
21 | | |
22 | | // Shared fixed-point building blocks, reused by the C fallback and SIMD tails |
23 | 0 | #define SHARPYUV_YUV_FIX 16 // fixed-point precision for RGB->YUV |
24 | | |
25 | | // Clamps v to [0, max]. |
26 | 0 | static WEBP_INLINE uint16_t SharpYuvClip16(int v, int max) { |
27 | 0 | return (v < 0) ? 0 : (v > max) ? (uint16_t)max : (uint16_t)v; |
28 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvClip16 |
29 | | |
30 | | // (13933*r + 46871*g + 4732*b + 32768) >> 16, in exact int64 precision: |
31 | | // r/g/b are usually <= 65536 (the sRGB-linear range), but some transfer |
32 | | // functions' EOTF (e.g. Smpte428) can push them to ~71501, and even the |
33 | | // bounded sRGB case comes within 1 of overflowing 32 bits at full white. |
34 | 0 | static WEBP_INLINE int SharpYuvRGBToGray(int64_t r, int64_t g, int64_t b) { |
35 | 0 | const int64_t luma = |
36 | 0 | 13933 * r + 46871 * g + 4732 * b + (1LL << (SHARPYUV_YUV_FIX - 1)); |
37 | 0 | return (int)(luma >> SHARPYUV_YUV_FIX); |
38 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvRGBToGray |
39 | | |
40 | | // round((coeffs[0]*r + coeffs[1]*g + coeffs[2]*b + coeffs[3]) >> |
41 | | // (SHARPYUV_YUV_FIX + sfix)), fit in int64's |
42 | | static WEBP_INLINE int SharpYuvConvertComponent(int r, int g, int b, |
43 | 0 | const int coeffs[4], int sfix) { |
44 | 0 | const int64_t srounder = 1LL << (SHARPYUV_YUV_FIX + sfix - 1); |
45 | 0 | const int64_t luma = (int64_t)coeffs[0] * r + (int64_t)coeffs[1] * g + |
46 | 0 | (int64_t)coeffs[2] * b + coeffs[3] + srounder; |
47 | 0 | return (int)(luma >> (SHARPYUV_YUV_FIX + sfix)); |
48 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvConvertComponent |
49 | | |
50 | | extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref, |
51 | | uint16_t* dst, int len, int bit_depth); |
52 | | extern void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, |
53 | | int16_t* dst, int len); |
54 | | extern void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len, |
55 | | const uint16_t* best_y, uint16_t* out, |
56 | | int bit_depth); |
57 | | |
58 | | // Reconstructs one row of the final Y plane from the W (luma proxy) row and |
59 | | // the corresponding (2x subsampled) RGB-offset row. 'width' is the number of |
60 | | // output samples, 'uv_w' the stride between the r/g/b planes of best_uv. |
61 | | // coeffs is a yuv_matrix->rgb_to_y-style {kr, kg, kb, add} row (see |
62 | | // RGBToYUVComponent in sharpyuv.c, which this must stay in sync with). |
63 | | // y_out points to a uint8_t buffer if yuv_bit_depth <= 8, uint16_t otherwise. |
64 | | extern void (*SharpYuvConvertRowY)(const uint16_t* best_y, |
65 | | const int16_t* best_uv, int width, int uv_w, |
66 | | const int coeffs[4], int sfix, |
67 | | int yuv_bit_depth, void* y_out); |
68 | | |
69 | | // Same, for one row of the U/V planes (no upsampling involved). |
70 | | extern void (*SharpYuvConvertRowUV)(const int16_t* best_uv, int uv_w, |
71 | | const int coeffs_u[4], |
72 | | const int coeffs_v[4], int sfix, |
73 | | int yuv_bit_depth, void* u_out, |
74 | | void* v_out); |
75 | | |
76 | | // Fast paths for transfer functions using gamma<->linear tables |
77 | | // (BT.709, BT.601, BT.2020-10, BT.2020-12, and sRGB), used by |
78 | | // UpdateW/UpdateChroma in sharpyuv.c. The caller is responsible for checking |
79 | | // transfer_type and falling back to the generic per-pixel path for any other |
80 | | // transfer function. |
81 | | extern void (*SharpYuvUpdateW709)(const uint16_t* src, uint16_t* dst, int w, |
82 | | int bit_depth); |
83 | | extern void (*SharpYuvUpdateChroma709)(const uint16_t* src1, |
84 | | const uint16_t* src2, int16_t* dst, |
85 | | int uv_w, int bit_depth); |
86 | | extern void (*SharpYuvUpdateWSrgb)(const uint16_t* src, uint16_t* dst, int w, |
87 | | int bit_depth); |
88 | | extern void (*SharpYuvUpdateChromaSrgb)(const uint16_t* src1, |
89 | | const uint16_t* src2, int16_t* dst, |
90 | | int uv_w, int bit_depth); |
91 | | |
92 | | void SharpYuvInitDsp(void); |
93 | | |
94 | | #ifdef __cplusplus |
95 | | } // extern "C" |
96 | | #endif |
97 | | |
98 | | #endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_ |