# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

mot_comp.h
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: mot_comp.h,v 1.22 2008/08/27 00:17:11 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) 2004.
21 * All Rights Reserved.
22 *
23 * Contributor(s): Richard Felton (Original Author),
24 * Thomas Davies
25 * Anuradha Suraparaju
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
29 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
30 * the GPL or the LGPL are applicable instead of those above. If you wish to
31 * allow use of your version of this file only under the terms of the either
32 * the GPL or LGPL and not to allow others to use your version of this file
33 * under the MPL, indicate your decision by deleting the provisions above
34 * and replace them with the notice and other provisions required by the GPL
35 * or LGPL. If you do not delete the provisions above, a recipient may use
36 * your version of this file under the terms of any one of the MPL, the GPL
37 * or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
39
40 // Motion Compensation routines.
41 // Supports different sizes of blocks as long as the parameters
42 // describing them are 'legal'. Blocks overlap the edge of the image
43 // being written to but blocks in the reference image are forced to
44 // lie completely within the image bounds.
45
46 #ifndef _INCLUDED_MOT_COMP
47 #define _INCLUDED_MOT_COMP
48
49 #include <cstdlib>
50 #include <ctime>
51 #include <iostream>
52 #include <vector>
53 #include <libdirac_common/common.h>
54 #include <libdirac_common/upconvert.h>
55 #include <libdirac_common/motion.h>
56 #include <libdirac_common/picture_buffer.h>
57
58 namespace dirac
59 {
60 class PictureBuffer;
61 class Picture;
62
64
70 class MotionCompensator
71 {
72
73 public:
75
78 MotionCompensator( const PicturePredParams &ppp );
80 virtual ~MotionCompensator();
81
83
93 static void CompensatePicture ( const PicturePredParams &ppp,
94 const AddOrSub direction ,
95 const MvData& mv_data,
96 Picture* in_pic ,
97 Picture* refptr[2]);
98
100
108 void CompensatePicture( const AddOrSub direction ,
109 const MvData& mv_data,
110 Picture* in_pic ,
111 Picture* refsptr[2] );
112
113 private:
114 //private, body-less copy constructor: this class should not be copied
115 MotionCompensator( const MotionCompensator& cpy );
116 //private, body-less assignment=: this class should not be assigned
117 MotionCompensator& operator=( const MotionCompensator& rhs );
118
119 //functions
120
122 void CompensateComponent( Picture* pic ,
123 Picture* refsptr[2] ,
124 const MvData& mv_data , const CompSort cs);
125
128 void DCBlock( TwoDArray<ValueType> &block_data ,
129 const ValueType dc);
130 void ReConfig();
131
132 // Calculates a weighting arrays blocks.
133 void CalculateWeights(int xbsep, int ybsep, TwoDArray<ValueType>* wt_array);
134
136
147 void CreateBlock(int xbsep, int ybsep, bool FullX, bool FullY, TwoDArray<ValueType>& WeightArray);
148
150 void FlipX(const TwoDArray<ValueType>& Original, TwoDArray<ValueType>& Flipped);
151
153 void FlipY(const TwoDArray<ValueType>& Original, TwoDArray<ValueType>& Flipped);
154
155 virtual void CompensateBlock( TwoDArray<ValueType>& pic_data ,
156 const ImageCoords& pos ,
157 const ImageCoords &orig_pic_size,
158 PredMode block_mode,
159 ValueType dc,
160 const PicArray& ref1up_data ,
161 const MVector& mv1 ,
162 const PicArray& ref2up_data ,
163 const MVector& mv2 ,
164 const TwoDArray<ValueType>& Weights );
166 virtual void BlockPixelPred( TwoDArray<ValueType>& block_data ,
167 const ImageCoords& pos,
168 const ImageCoords &orig_pic_size,
169 const PicArray& refup_data ,
170 const MVector& mv) = 0;
171
172 // Adjust the block value based on reference weights
173 /*
174 * Adjust the block value based on reference weights of each
175 * reference picture.
176 * val1_block - Block predicted from a single reference picture
177 * val2_block - Block predicted from second reference picture
178 * mode is REF1AND2
179 * block_mode - Block prediction mode.
180 *
181 * On return, val1_block will contain the weight reference weight
182 * adjusted block values
183 */
184 void AdjustBlockByRefWeights (TwoDArray<ValueType>& val1_block,
185 TwoDArray<ValueType>& val2_block,
186 PredMode block_mode);
187
188 // Adjust the block value based spatial weighting matrix
189 /*
190 * Adjust the block value based on spatial weighting matrix
191 * val_block - Predicted block
192 * pos - position of top lef corner of block in picture
193 * wt_array - spatial weighting matrix
194 *
195 * On return, val_block will contain the spatial weight adjusted block
196 * values
197 */
198 void AdjustBlockBySpatialWeights (TwoDArray<ValueType>& val_block,
199 const ImageCoords &pos,
200 const TwoDArray<ValueType> &wt_array);
201 protected:
202 //variables
203
205 PicturePredParams m_predparams;
206
208 ChromaFormat m_cformat;
209 bool luma_or_chroma; //true if we're doing luma, false if we're coding chroma
210
211 // A marker saying whether we're doing MC addition or subtraction
212 AddOrSub m_add_or_sub;
213
214 // Block information
215 OLBParams m_bparams;
216 // Arrays of block weights
217 TwoDArray<ValueType>* m_block_weights;
218 // Arrays of super block weights
219 TwoDArray<ValueType>* m_macro_block_weights;
220 // Arrays of sub super block weights
221 TwoDArray<ValueType>* m_sub_block_weights;
222 };
223
225 class MotionCompensator_Pixel : public MotionCompensator
226 {
227
228 public:
230
233 MotionCompensator_Pixel (const PicturePredParams &ppp);
234
235 private:
237 virtual void BlockPixelPred( TwoDArray<ValueType>& block_data ,
238 const ImageCoords& pos,
239 const ImageCoords &orig_pic_size,
240 const PicArray& refup_data ,
241 const MVector& mv);
242 };
243
245 class MotionCompensator_HalfPixel : public MotionCompensator
246 {
247 public:
249
252 MotionCompensator_HalfPixel (const PicturePredParams &ppp);
253 private:
255 virtual void BlockPixelPred( TwoDArray<ValueType>& block_data ,
256 const ImageCoords& pos,
257 const ImageCoords &orig_pic_size,
258 const PicArray& refup_data ,
259 const MVector& mv);
260 };
261
263 class MotionCompensator_QuarterPixel : public MotionCompensator
264 {
265 public:
267
270 MotionCompensator_QuarterPixel (const PicturePredParams &ppp);
271 private:
273 virtual void BlockPixelPred( TwoDArray<ValueType>& block_data ,
274 const ImageCoords& pos,
275 const ImageCoords &orig_pic_size,
276 const PicArray& refup_data ,
277 const MVector& mv);
278 };
279
281 class MotionCompensator_EighthPixel : public MotionCompensator
282 {
283 public:
285
288 MotionCompensator_EighthPixel (const PicturePredParams &ppp);
289 private:
291 virtual void BlockPixelPred( TwoDArray<ValueType>& block_data ,
292 const ImageCoords& pos,
293 const ImageCoords &orig_pic_size,
294 const PicArray& refup_data ,
295 const MVector& mv);
296 };
297
298
299 } // namespace dirac
300
301 #endif
dirac::PredMode
PredMode
Prediction modes for blocks.
Definition: common.h:84
dirac::MotionCompensator_EighthPixel::BlockPixelPred
virtual void BlockPixelPred(TwoDArray< ValueType > &block_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, const PicArray &refup_data, const MVector &mv)
Motion-compensate a block.
dirac::MotionCompensator_QuarterPixel::BlockPixelPred
virtual void BlockPixelPred(TwoDArray< ValueType > &block_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, const PicArray &refup_data, const MVector &mv)
Motion-compensate a block.
dirac::TwoDArray< ValueType >
dirac::MotionCompensator_Pixel::BlockPixelPred
virtual void BlockPixelPred(TwoDArray< ValueType > &block_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, const PicArray &refup_data, const MVector &mv)
Motion-compensate a block.
upconvert.h
dirac::MotionCompensator_Pixel
Pixel precision Motion compensator class.
Definition: mot_comp.h:225
dirac::MotionCompensator_HalfPixel::BlockPixelPred
virtual void BlockPixelPred(TwoDArray< ValueType > &block_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, const PicArray &refup_data, const MVector &mv)
Motion-compensate a block.
dirac::MotionCompensator::MotionCompensator
MotionCompensator(const PicturePredParams &ppp)
Constructor.
dirac::MotionCompensator::m_bparams
OLBParams m_bparams
Definition: mot_comp.h:215
dirac::MotionCompensator_EighthPixel::MotionCompensator_EighthPixel
MotionCompensator_EighthPixel(const PicturePredParams &ppp)
Constructor.
dirac::MotionCompensator::m_predparams
PicturePredParams m_predparams
The codec parameters.
Definition: mot_comp.h:205
dirac::MotionCompensator_Pixel::MotionCompensator_Pixel
MotionCompensator_Pixel(const PicturePredParams &ppp)
Constructor.
dirac::MotionCompensator::AdjustBlockByRefWeights
void AdjustBlockByRefWeights(TwoDArray< ValueType > &val1_block, TwoDArray< ValueType > &val2_block, PredMode block_mode)
dirac::MotionCompensator::FlipY
void FlipY(const TwoDArray< ValueType > &Original, TwoDArray< ValueType > &Flipped)
Flips the values in an array in the y direction.
common.h
dirac::PicArray
A class for picture component data.
Definition: common.h:718
dirac::MotionCompensator::~MotionCompensator
virtual ~MotionCompensator()
Destructor.
motion.h
dirac::MotionCompensator_HalfPixel
Half Pixel precision Motion compensator class.
Definition: mot_comp.h:245
dirac::MotionCompensator::CompensateComponent
void CompensateComponent(Picture *pic, Picture *refsptr[2], const MvData &mv_data, const CompSort cs)
Motion-compensate a component.
dirac::MotionVector< int >
ChromaFormat
ChromaFormat
Definition: common_types.h:58
dirac::MotionCompensator::m_cformat
ChromaFormat m_cformat
The chroma format.
Definition: mot_comp.h:208
picture_buffer.h
dirac::OLBParams
Parameters for overlapped block motion compensation.
Definition: common.h:817
dirac::MotionCompensator::AdjustBlockBySpatialWeights
void AdjustBlockBySpatialWeights(TwoDArray< ValueType > &val_block, const ImageCoords &pos, const TwoDArray< ValueType > &wt_array)
dirac::MotionCompensator_QuarterPixel::MotionCompensator_QuarterPixel
MotionCompensator_QuarterPixel(const PicturePredParams &ppp)
Constructor.
dirac::MotionCompensator::m_sub_block_weights
TwoDArray< ValueType > * m_sub_block_weights
Definition: mot_comp.h:221
dirac::MotionCompensator_HalfPixel::MotionCompensator_HalfPixel
MotionCompensator_HalfPixel(const PicturePredParams &ppp)
Constructor.
dirac::PicturePredParams
Structure to hold motion parameters when motion comp is used.
Definition: common.h:967
dirac::MotionCompensator::m_add_or_sub
AddOrSub m_add_or_sub
Definition: mot_comp.h:212
dirac::MotionCompensator::CalculateWeights
void CalculateWeights(int xbsep, int ybsep, TwoDArray< ValueType > *wt_array)
dirac::ValueType
short ValueType
Type of picture data (including motion compensated residuals)
Definition: common.h:70
dirac::MotionCompensator::CreateBlock
void CreateBlock(int xbsep, int ybsep, bool FullX, bool FullY, TwoDArray< ValueType > &WeightArray)
Calculates a weighting block.
dirac::MotionCompensator_EighthPixel
Eighth Pixel precision Motion compensator class.
Definition: mot_comp.h:281
dirac::MotionCompensator::FlipX
void FlipX(const TwoDArray< ValueType > &Original, TwoDArray< ValueType > &Flipped)
Flips the values in an array in the x direction.
dirac
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:51
dirac::AddOrSub
AddOrSub
Addition or subtraction.
Definition: common.h:90
dirac::MotionCompensator::m_macro_block_weights
TwoDArray< ValueType > * m_macro_block_weights
Definition: mot_comp.h:219
dirac::MotionCompensator_QuarterPixel
Quarter Pixel precision Motion compensator class.
Definition: mot_comp.h:263
dirac::MotionCompensator::operator=
MotionCompensator & operator=(const MotionCompensator &rhs)
dirac::MotionCompensator::BlockPixelPred
virtual void BlockPixelPred(TwoDArray< ValueType > &block_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, const PicArray &refup_data, const MVector &mv)=0
Predict pixels in a block. Pure virtual. SubClasses need to define it.
dirac::MvData
Class for all the motion vector data.
Definition: motion.h:219
dirac::CompSort
CompSort
Types of picture component.
Definition: common.h:87
dirac::MotionCompensator::m_block_weights
TwoDArray< ValueType > * m_block_weights
Definition: mot_comp.h:217
dirac::MotionCompensator::ReConfig
void ReConfig()
dirac::MotionCompensator
Abstract Motion compensator class.
Definition: mot_comp.h:70
dirac::MotionCompensator::DCBlock
void DCBlock(TwoDArray< ValueType > &block_data, const ValueType dc)
Recalculate the weight matrix and store other key block related parameters.
dirac::MotionCompensator::CompensateBlock
virtual void CompensateBlock(TwoDArray< ValueType > &pic_data, const ImageCoords &pos, const ImageCoords &orig_pic_size, PredMode block_mode, ValueType dc, const PicArray &ref1up_data, const MVector &mv1, const PicArray &ref2up_data, const MVector &mv2, const TwoDArray< ValueType > &Weights)
dirac::MotionCompensator::CompensatePicture
static void CompensatePicture(const PicturePredParams &ppp, const AddOrSub direction, const MvData &mv_data, Picture *in_pic, Picture *refptr[2])
Convenience function to perform motion compensation on a picture.
dirac::MotionCompensator::luma_or_chroma
bool luma_or_chroma
Definition: mot_comp.h:209
dirac::Picture
A class for encapsulating all the data relating to a picture.
Definition: picture.h:51

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.