• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_TXB_RDOPT_H_
13 #define AOM_AV1_ENCODER_TXB_RDOPT_H_
14 
15 #include "av1/common/blockd.h"
16 #include "av1/common/txb_common.h"
17 #include "av1/encoder/encoder.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*!\brief Adjust the magnitude of quantized coefficients to achieve better
24  * rate-distortion (RD) trade-off.
25  *
26  * \ingroup coefficient_coding
27  *
28  * This function goes through each coefficient and greedily choose to lower
29  * the coefficient magnitude by 1 or not based on the RD score.
30  *
31  * The coefficients are processing in reversed scan order.
32  *
33  * Note that, the end of block position (eob) may change if the original last
34  * coefficient is lowered to zero.
35  *
36  * \param[in]    cpi            Top-level encoder structure
37  * \param[in]    x              Pointer to structure holding the data for the
38                                 current encoding macroblock
39  * \param[in]    plane          The index of the current plane
40  * \param[in]    block          The index of the current transform block in the
41  * \param[in]    tx_size        The transform size
42  * \param[in]    tx_type        The transform type
43  * \param[in]    txb_ctx        Context info for entropy coding transform block
44  * skip flag (tx_skip) and the sign of DC coefficient (dc_sign).
45  * \param[out]   rate_cost      The entropy cost of coding the transform block
46  * after adjustment of coefficients.
47  * \param[in]    sharpness      When sharpness > 0, the function will be less
48  * aggressive towards lowering the magnitude of coefficients.
49  * In this way, the transform block will contain more high-frequency
50  * coefficients and therefore will preserve the sharpness of the reconstructed
51  * block.
52  */
53 int av1_optimize_txb(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
54                      int block, TX_SIZE tx_size, TX_TYPE tx_type,
55                      const TXB_CTX *const txb_ctx, int *rate_cost,
56                      int sharpness);
57 
58 /*!\brief Compute the entropy cost of coding coefficients in a transform block.
59  *
60  * \ingroup coefficient_coding
61  *
62  * \param[in]    x                    Pointer to structure holding the data for
63  the current encoding macroblock.
64  * \param[in]    plane                The index of the current plane.
65  * \param[in]    block                The index of the current transform block
66  in the
67  * macroblock. It's defined by number of 4x4 units that have been coded before
68  * the currernt transform block.
69  * \param[in]    tx_size              The transform size.
70  * \param[in]    tx_type              The transform type.
71  * \param[in]    txb_ctx              Context info for entropy coding transform
72  block
73  * skip flag (tx_skip) and the sign of DC coefficient (dc_sign).
74  * \param[in]    reduced_tx_set_used  Whether the transform type is chosen from
75  * a reduced set.
76  */
77 int av1_cost_coeffs_txb(const MACROBLOCK *x, const int plane, const int block,
78                         const TX_SIZE tx_size, const TX_TYPE tx_type,
79                         const TXB_CTX *const txb_ctx, int reduced_tx_set_used);
80 
81 /*!\brief Estimate the entropy cost of coding a transform block using Laplacian
82  * distribution.
83  *
84  * \ingroup coefficient_coding
85  *
86  * This function compute the entropy costs of the end of block position (eob)
87  * and the transform type (tx_type) precisely.
88  *
89  * Then using \ref av1_cost_coeffs_txb_estimate to estimate the entropy costs
90  * of coefficients in the transform block.
91  *
92  * In the end, the function returns the sum of entropy costs of end of block
93  * position (eob), transform type (tx_type) and coefficients.
94  *
95  * Compared to \ref av1_cost_coeffs_txb, this function is much faster but less
96  * accurate.
97  *
98  * \param[in]    x              Pointer to structure holding the data for the
99                                 current encoding macroblock
100  * \param[in]    plane          The index of the current plane
101  * \param[in]    block          The index of the current transform block in the
102  * macroblock. It's defined by number of 4x4 units that have been coded before
103  * the currernt transform block
104  * \param[in]    tx_size        The transform size
105  * \param[in]    tx_type        The transform type
106  * \param[in]    txb_ctx        Context info for entropy coding transform block
107  * skip flag (tx_skip) and the sign of DC coefficient (dc_sign).
108  * \param[in]    reduced_tx_set_used  Whether the transform type is chosen from
109  * a reduced set.
110  * \param[in]    adjust_eob     Whether to adjust the end of block position
111  (eob)
112  * or not.
113  * \return       int            Estimated entropy cost of coding the transform
114  block.
115  */
116 int av1_cost_coeffs_txb_laplacian(const MACROBLOCK *x, const int plane,
117                                   const int block, const TX_SIZE tx_size,
118                                   const TX_TYPE tx_type,
119                                   const TXB_CTX *const txb_ctx,
120                                   const int reduced_tx_set_used,
121                                   const int adjust_eob);
122 
123 /*!\brief Estimate the entropy cost of transform coefficients using Laplacian
124  * distribution.
125  *
126  * \ingroup coefficient_coding
127  *
128  * This function assumes each transform coefficient is of its own Laplacian
129  * distribution and the coefficient is the only observation of the Laplacian
130  * distribution.
131  *
132  * Based on that, each coefficient's coding cost can be estimated by computing
133  * the entropy of the corresponding Laplacian distribution.
134  *
135  * This function then return the sum of the estimated entropy cost for all
136  * coefficients in the transform block.
137  *
138  * Note that the entropy cost of end of block (eob) and transform type (tx_type)
139  * are not included.
140  *
141  * \param[in]    x              Pointer to structure holding the data for the
142                                 current encoding macroblock
143  * \param[in]    plane          The index of the current plane
144  * \param[in]    block          The index of the current transform block in the
145  * macroblock. It's defined by number of 4x4 units that have been coded before
146  * the currernt transform block
147  * \param[in]    tx_size        The transform size
148  * \param[in]    tx_type        The transform type
149  * \return       int            Estimated entropy cost of coefficients in the
150  * transform block.
151  */
152 int av1_cost_coeffs_txb_estimate(const MACROBLOCK *x, const int plane,
153                                  const int block, const TX_SIZE tx_size,
154                                  const TX_TYPE tx_type);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif  // AOM_AV1_ENCODER_TXB_RDOPT_H_
161