/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 | | // Shared fixed-point building blocks, reused by the C fallback and SIMD tails |
19 | 0 | #define SHARPYUV_YUV_FIX 16 // fixed-point precision for RGB->YUV |
20 | | |
21 | | // Clamps v to [0, max]. |
22 | 0 | static WEBP_INLINE uint16_t SharpYuvClip16(int v, int max) { |
23 | 0 | return (v < 0) ? 0 : (v > max) ? (uint16_t)max : (uint16_t)v; |
24 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvClip16 Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvClip16 |
25 | | |
26 | | // (13933*r + 46871*g + 4732*b + 32768) >> 16, in exact int64 precision: |
27 | | // r/g/b are usually <= 65536 (the sRGB-linear range), but some transfer |
28 | | // functions' EOTF (e.g. Smpte428) can push them to ~71501, and even the |
29 | | // bounded sRGB case comes within 1 of overflowing 32 bits at full white. |
30 | 0 | static WEBP_INLINE int SharpYuvRGBToGray(int64_t r, int64_t g, int64_t b) { |
31 | 0 | const int64_t luma = |
32 | 0 | 13933 * r + 46871 * g + 4732 * b + (1LL << (SHARPYUV_YUV_FIX - 1)); |
33 | 0 | return (int)(luma >> SHARPYUV_YUV_FIX); |
34 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvRGBToGray Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvRGBToGray |
35 | | |
36 | | // round((coeffs[0]*r + coeffs[1]*g + coeffs[2]*b + coeffs[3]) >> |
37 | | // (SHARPYUV_YUV_FIX + sfix)), fit in int64's |
38 | | static WEBP_INLINE int SharpYuvConvertComponent(int r, int g, int b, |
39 | 0 | const int coeffs[4], int sfix) { |
40 | 0 | const int64_t srounder = 1LL << (SHARPYUV_YUV_FIX + sfix - 1); |
41 | 0 | const int64_t luma = (int64_t)coeffs[0] * r + (int64_t)coeffs[1] * g + |
42 | 0 | (int64_t)coeffs[2] * b + coeffs[3] + srounder; |
43 | 0 | return (int)(luma >> (SHARPYUV_YUV_FIX + sfix)); |
44 | 0 | } Unexecuted instantiation: sharpyuv.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_dsp.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_sse2.c:SharpYuvConvertComponent Unexecuted instantiation: sharpyuv_avx2.c:SharpYuvConvertComponent |
45 | | |
46 | | extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref, |
47 | | uint16_t* dst, int len, int bit_depth); |
48 | | extern void (*SharpYuvUpdateRGB)(const int16_t* src, const int16_t* ref, |
49 | | int16_t* dst, int len); |
50 | | extern void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len, |
51 | | const uint16_t* best_y, uint16_t* out, |
52 | | int bit_depth); |
53 | | |
54 | | // Reconstructs one row of the final Y plane from the W (luma proxy) row and |
55 | | // the corresponding (2x subsampled) RGB-offset row. 'width' is the number of |
56 | | // output samples, 'uv_w' the stride between the r/g/b planes of best_uv. |
57 | | // coeffs is a yuv_matrix->rgb_to_y-style {kr, kg, kb, add} row (see |
58 | | // RGBToYUVComponent in sharpyuv.c, which this must stay in sync with). |
59 | | // y_out points to a uint8_t buffer if yuv_bit_depth <= 8, uint16_t otherwise. |
60 | | extern void (*SharpYuvConvertRowY)(const uint16_t* best_y, |
61 | | const int16_t* best_uv, int width, int uv_w, |
62 | | const int coeffs[4], int sfix, |
63 | | int yuv_bit_depth, void* y_out); |
64 | | |
65 | | // Same, for one row of the U/V planes (no upsampling involved). |
66 | | extern void (*SharpYuvConvertRowUV)(const int16_t* best_uv, int uv_w, |
67 | | const int coeffs_u[4], |
68 | | const int coeffs_v[4], int sfix, |
69 | | int yuv_bit_depth, void* u_out, |
70 | | void* v_out); |
71 | | |
72 | | // Fast paths for the (default, most common) kSharpYuvTransferFunctionSrgb |
73 | | // transfer function, used by UpdateW/UpdateChroma in sharpyuv.c. The caller |
74 | | // is responsible for checking transfer_type and falling back to the |
75 | | // (unchanged) generic per-pixel path for any other transfer function. |
76 | | extern void (*SharpYuvUpdateWSrgb)(const uint16_t* src, uint16_t* dst, int w, |
77 | | int bit_depth); |
78 | | extern void (*SharpYuvUpdateChromaSrgb)(const uint16_t* src1, |
79 | | const uint16_t* src2, int16_t* dst, |
80 | | int uv_w, int bit_depth); |
81 | | |
82 | | void SharpYuvInitDsp(void); |
83 | | |
84 | | #endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_ |