OSDN Git Service

Update README.md
[android-x86/hardware-intel-common-vaapi.git] / src / i965_vpp_avs.h
1 /*
2  * i965_vpp_avs.h - Adaptive Video Scaler (AVS) block
3  *
4  * Copyright (C) 2014 Intel Corporation
5  *   Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #ifndef I965_VPP_AVS_H
29 #define I965_VPP_AVS_H
30
31 #include <stdint.h>
32 #include <stdbool.h>
33
34 /** Maximum number of phases for the sharp filter */
35 #define AVS_MAX_PHASES 32
36
37 /** Maximum number of coefficients for luma samples */
38 #define AVS_MAX_LUMA_COEFFS 8
39
40 /** Maximum number of coefficients for chroma samples */
41 #define AVS_MAX_CHROMA_COEFFS 4
42
43 typedef struct avs_coeffs               AVSCoeffs;
44 typedef struct avs_coeffs_range         AVSCoeffsRange;
45 typedef struct avs_config               AVSConfig;
46 typedef struct avs_state                AVSState;
47
48 /** AVS coefficients for one phase */
49 struct avs_coeffs {
50     /** Coefficients for luma samples on the X-axis (horizontal) */
51     float y_k_h[AVS_MAX_LUMA_COEFFS];
52     /** Coefficients for luma samples on the Y-axis (vertical) */
53     float y_k_v[AVS_MAX_LUMA_COEFFS];
54     /** Coefficients for chroma samples on the X-axis (horizontal) */
55     float uv_k_h[AVS_MAX_CHROMA_COEFFS];
56     /** Coefficients for chroma samples on the Y-axis (vertical) */
57     float uv_k_v[AVS_MAX_CHROMA_COEFFS];
58 };
59
60 /** AVS coefficients range used for validation */
61 struct avs_coeffs_range {
62     /** Lower bound for all coefficients */
63     AVSCoeffs lower_bound;
64     /** Upper bound for all coefficients */
65     AVSCoeffs upper_bound;
66 };
67
68 /** Static configuration (per-generation) */
69 struct avs_config {
70     /** Number of bits used for the fractional part of a coefficient */
71     int coeff_frac_bits;
72     /** The smallest float that could be represented as a coefficient */
73     float coeff_epsilon;
74     /** Coefficients range */
75     AVSCoeffsRange coeff_range;
76     /** Number of phases for the sharp filter */
77     int num_phases;
78     /** Number of coefficients for luma samples */
79     int num_luma_coeffs;
80     /** Number of coefficients for chroma samples */
81     int num_chroma_coeffs;
82 };
83
84 /** AVS block state */
85 struct avs_state {
86     /** Per-generation configuration parameters */
87     const AVSConfig *config;
88     /** Scaling flags */
89     uint32_t flags;
90     /** Scaling factor on the X-axis (horizontal) */
91     float scale_x;
92     /** Scaling factor on the Y-axis (vertical) */
93     float scale_y;
94     /** Coefficients for the polyphase scaler */
95     AVSCoeffs coeffs[AVS_MAX_PHASES + 1];
96 };
97
98 /** Initializes AVS state with the supplied configuration */
99 void
100 avs_init_state(AVSState *avs, const AVSConfig *config);
101
102 /** Updates AVS coefficients for the supplied factors and quality level */
103 bool
104 avs_update_coefficients(AVSState *avs, float sx, float sy, uint32_t flags);
105
106 /** Checks whether AVS is needed, e.g. if high-quality scaling is requested */
107 static inline bool
108 avs_is_needed(uint32_t flags)
109 {
110     return ((flags & VA_FILTER_SCALING_MASK) >= VA_FILTER_SCALING_HQ);
111 }
112
113 #endif /* I965_VPP_AVS_H */