Updating Contact email
[BrunelResearch-dirac.git] / libdirac_encoder / quant_chooser.h
blobf1bc0bb8545c7d5fe5870df33e57c4e800a26094
1 /* ***** BEGIN LICENSE BLOCK *****
3 * $Id$ $Name$
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
27 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
28 * the GPL or the LGPL are applicable instead of those above. If you wish to
29 * allow use of your version of this file only under the terms of the either
30 * the GPL or LGPL and not to allow others to use your version of this file
31 * under the MPL, indicate your decision by deleting the provisions above
32 * and replace them with the notice and other provisions required by the GPL
33 * or LGPL. If you do not delete the provisions above, a recipient may use
34 * your version of this file under the terms of any one of the MPL, the GPL
35 * or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 #ifndef _QUANT_CHOOSER_H_
40 #define _QUANT_CHOOSER_H_
42 #include <libdirac_common/arrays.h>
43 #include <libdirac_common/wavelet_utils.h>
44 #include <libdirac_common/common.h>
46 namespace dirac
48 //! Choose a quantiser
49 /*!
50 This class chooses a quantiser or quantisers for a subband
52 class QuantChooser
54 public:
56 //! Constructor
57 QuantChooser( const CoeffArray& pic_data , const float lambda );
59 //! Finds the best quantisers for the subband, returning the predicted number of bits needed
60 int GetBestQuant( Subband& node );
62 //! Sets the factor used for correcting the entropy calculation
63 void SetEntropyCorrection( const float ecfac ){ m_entropy_correctionfactor = ecfac; }
64 private:
65 //! Copy constructor is private and body-less. This class should not be copied.
66 QuantChooser(const QuantChooser& cpy);
68 //! Assignment = is private and body-less. This class should not be assigned.
69 QuantChooser& operator=(const QuantChooser& rhs);
71 //! Calculate errors and entropies for integral-bit quantisers
72 void IntegralErrorCalc( Subband& node , const int xratio , const int yratio );
74 //! Calculate errors and entropies for non-integral-bit quantisers
75 void NonIntegralErrorCalc( Subband& node, const int xratio, const int yratio );
77 //! Having got statistics, calculate the Lagrangian costs
78 void LagrangianCalc();
80 //! Select the best quantisation index on the basis of the Lagrangian calculations
81 void SelectBestQuant();
83 CoeffType BlockAbsMax( const Subband& node );
85 //! Set the skip flag for a codeblock
86 void SetSkip( CodeBlock& cblock , const int qidx);
88 private:
89 //! The perceptual weighting factor of the subband being tested
90 float m_subband_wt;
92 //! The smallest quantisation index being tested
93 int m_bottom_idx;
94 //! The largest quantisation index being tested
95 int m_top_idx;
96 //! The step we use in jumping through the list of quantisers
97 int m_index_step;
99 //! The index of the quantiser with the lowest cost
100 int m_min_idx;
102 //! A local reference to the data under consideration
103 const CoeffArray& m_coeff_data;
105 //! The lambda value to be used in the Lagrangian calculation
106 const float m_lambda;
108 //! A value for correcting the crude calculation of the entropy
109 float m_entropy_correctionfactor;
111 //! An array used to count the number of zeroes
112 OneDArray<int> m_count0;
113 //! The number of ones (equal to the number of coefficients)
114 int m_count1;
115 //! An array used to count the number of positive values
116 OneDArray<int> m_countPOS;
117 //! An array used to count the number of negative values
118 OneDArray<int> m_countNEG;
119 //! An array used to collate the sum of the perceptually-weighted errors
120 OneDArray<double> m_error_total;
121 //! An array used to collate the computed costs
122 OneDArray<CostType> m_costs;
126 } // namespace dirac
130 #endif