1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: enc_picture.h,v 1.6 2008/10/01 01:26:47 asuraparaju Exp $ $Name: Dirac_1_0_2 $
4 *
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
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/
11 *
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.
15 *
16 * The Original Code is BBC Research and Development code.
17 *
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2008.
21 * All Rights Reserved.
22 *
23 * Contributor(s): Thomas Davies (Original Author),
24 *
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 ***** */
37 
38 #ifndef _ENC_PICTURE_H_
39 #define _ENC_PICTURE_H_
40 
41 #include <libdirac_common/picture.h>
42 #include <libdirac_common/motion.h>
43 
44 
45 namespace dirac
46 {
47 static const unsigned int DONE_ME_INIT = 0x1;
48 static const unsigned int DONE_PEL_ME = 0x2;
49 static const unsigned int DONE_SUBPEL_ME = 0x4;
50 static const unsigned int DONE_ME_MODE_DECN = 0x8;
51 static const unsigned int DONE_MV_CODING = 0x10;
52 static const unsigned int DONE_MC = 0x20;
53 static const unsigned int DONE_DWT = 0x40;
54 static const unsigned int DONE_QUANT_SEL = 0x80;
55 static const unsigned int DONE_RES_CODING = 0x100;
56 static const unsigned int DONE_IDWT = 0x200;
57 static const unsigned int DONE_MC_BACK = 0x400;
58 static const unsigned int DONE_SET_PTYPE = 0x800;
59 static const unsigned int DONE_PIC_COMPLEXITY = 0x1000;
60 
61 static const unsigned int ALL_ENC = 0xFFFFFFFF;
62 static const unsigned int NO_ENC = 0;
63 
64 class EncPicture : public Picture
65 {
66 public:
67     EncPicture( const PictureParams& pp );
68 
69     virtual ~EncPicture();
70 
71     //! Initialise the motion estimation data arrays
72     void InitMEData( const PicturePredParams& predparams, const int num_refs);
73 
74     //! Returns the motion data
GetMEData()75     MEData& GetMEData(){ return *m_me_data;}
76 
77     //! Returns the motion data
GetMEData()78     const MEData& GetMEData() const { return *m_me_data;}
79 
80     //! Drops a reference from the motion vector data
81     void DropRef( int rindex );
82 
83 
84     //! Returns a given component of the original data
OrigData(CompSort c)85     const PicArray& OrigData(CompSort c) const { return *m_orig_data[(int) c];}
86 
87     //! Returns a given upconverted component of the original data
88     const PicArray& UpOrigData(CompSort cs) const;
89 
90     //! Initialises a copy of the data arrays into the original data
91     void SetOrigData();
92 
93     //! Returns a version of the picture data suitable for motion estimation
94     const PicArray& DataForME(bool combined_me) const;
95 
96     //! Returns a version of the picture data suitable for subpel motion estimation
97     const PicArray& UpDataForME(bool combined_me) const;
98 
99 
UpdateStatus(const unsigned int mask)100     void UpdateStatus( const unsigned int mask ){ m_status |= mask; }
101 
FlipStatus(const unsigned int mask)102     void FlipStatus( const unsigned int mask){ m_status ^= mask; }
103 
SetStatus(const int status)104     void SetStatus( const int status ){ m_status = status; }
105 
GetStatus()106     unsigned int GetStatus() const{ return m_status; }
107 
108 
GetComplexity()109     double GetComplexity() const {return m_complexity; }
110 
SetComplexity(double c)111     void SetComplexity(double c){ m_complexity = c; }
112 
GetNormComplexity()113     double GetNormComplexity() const { return m_norm_complexity; }
114 
SetNormComplexity(double c)115     void SetNormComplexity( double c ){ m_norm_complexity = c; }
116 
GetPredBias()117     double GetPredBias() const { return m_pred_bias; }
118 
SetPredBias(double b)119     void SetPredBias( double b ){ m_pred_bias = b; }
120 
121 
122 private:
123 
124     virtual void ClearData();
125 
126     //! Filters a (field) picture vertically to reduce aliasing for motion estimation purposes
127     void AntiAliasFilter( PicArray& out_data, const PicArray& in_data ) const;
128 
129     //! Returns an anti-aliased version of the original data
130     const PicArray& FiltData(CompSort c) const;
131 
132     const PicArray& CombinedData() const;
133     const PicArray& UpCombinedData() const;
134     void Combine( PicArray& comb_data, const PicArray& y_data,
135                           const PicArray& u_data, const PicArray& v_data ) const;
136 
137     //! Returns an upconverted anti-aliased version of the original data
138     const PicArray& UpFiltData(CompSort c) const;
139 
140 
141     void SetOrigData(const int c);
142 
143 private:
144 
145     PicArray* m_orig_data[3];
146     mutable PicArray* m_orig_up_data[3];
147     mutable PicArray* m_filt_data[3];
148     mutable PicArray* m_filt_up_data[3];
149 
150     MEData* m_me_data;
151 
152     unsigned int m_status;
153 
154     double m_complexity;
155     double m_norm_complexity;
156 
157     double m_pred_bias;
158 };
159 
160 
161 }
162 
163 #endif
164