1 /* ***** BEGIN LICENSE BLOCK *****
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 Steve Bearcroft's code.
18 * The Initial Developer of the Original Code is Steve Bearcroft.
19 * Portions created by the Initial Developer are Copyright (C) 2004.
20 * All Rights Reserved.
22 * Contributor(s): Steve Bearcroft (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
36 * ***** END LICENSE BLOCK ***** */
37 #include "core_suite.h"
38 #include "motion_comp_test.h"
39 #include "frames_test.h"
41 #include <libdirac_common/picture.h>
42 #include <libdirac_common/picture_buffer.h>
43 #include <libdirac_common/mot_comp.h>
44 using namespace dirac
;
48 //NOTE: ensure that the suite is added to the default registry in
49 //cppunit_testsuite.cpp
50 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (MotionCompTest
, coreSuiteName());
55 MotionCompTest::MotionCompTest()
59 MotionCompTest::~MotionCompTest()
63 void MotionCompTest::setUp()
67 void MotionCompTest::tearDown()
72 MvData
* setupMV1Data(const PicturePredParams
& ppp
, int mv_x
, int mv_y
, PredMode mode
)
74 MvData
* mv_data
= new MvData(ppp
, 2);
75 MvArray
& arr
= mv_data
->Vectors(1);
76 for (int i
=arr
.FirstY(); i
<= arr
.LastY(); i
++)
78 for (int j
=arr
.FirstX(); j
<= arr
.LastX(); j
++)
82 mv_data
->Mode()[i
][j
] = mode
;
88 void setupMV2Data(MvData
* mv_data
, int mv_x
, int mv_y
)
90 MvArray
& arr
= mv_data
->Vectors(2);
91 for (int i
=arr
.FirstY(); i
<= arr
.LastY(); i
++)
93 for (int j
=arr
.FirstX(); j
<= arr
.LastX(); j
++)
101 void MotionCompTest::testZeroMotionComp()
103 for (int i
= 0; i
< 4; ++i
)
105 testZeroMotionComp(static_cast<MVPrecisionType
>(i
));
109 void MotionCompTest::testZeroMotionComp(MVPrecisionType precision
)
111 PictureBuffer pbuffer
;
112 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 1, true);
113 PicturePredParams
&ppp
= cp
.GetPicPredParams();
114 OLBParams
bparams(12, 12, 8, 8);
116 ppp
.SetMVPrecision(precision
);
117 ppp
.SetBlockSizes(bparams
, format420
);
118 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
119 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
120 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
122 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
123 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
125 // MotionCompensator mc( cp );
127 MvData
* mv_data
= setupMV1Data(ppp
, 0, 0, REF1_ONLY
);
129 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
131 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
133 pbuffer
.PushPicture(pp
);
134 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
136 pp
.SetPicSort(PictureSort::InterRefPictureSort());
138 pp
.Refs().push_back(0);
139 pbuffer
.PushPicture(pp
);
140 PicturesTest::zeroPicture(pbuffer
.GetPicture(1));
143 pbuffer
.PushPicture(pp
);
144 PicturesTest::zeroPicture(pbuffer
.GetPicture(2));
146 Picture
* ref_pics
[2] = { &pbuffer
.GetPicture(1), &pbuffer
.GetPicture(2) };
148 // mc.CompensatePicture(ADD, pbuffer, 1, *mv_data);
149 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
151 // MotionCompensator mc2( cp );
153 //too many rounding errors for this to be exactly true;
154 //CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer.GetPicture(0), pbuffer.GetPicture(1)));
155 // mc2.CompensatePicture(SUBTRACT, pbuffer, 1, *mv_data);
156 MotionCompensator::CompensatePicture(ppp
, SUBTRACT
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
158 CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer
.GetPicture(2), pbuffer
.GetPicture(1)));
162 void MotionCompTest::testAddandSubMotionComp()
164 for (int i
= 0; i
< 4; ++i
)
166 testAddandSubMotionComp(static_cast<MVPrecisionType
>(i
));
170 void MotionCompTest::testAddandSubMotionComp(MVPrecisionType precision
)
172 PictureBuffer pbuffer
;
173 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 1, true);
174 PicturePredParams
&ppp
= cp
.GetPicPredParams();
175 OLBParams
bparams(12, 12, 8, 8);
176 ppp
.SetMVPrecision(precision
);
177 ppp
.SetBlockSizes(bparams
, format420
);
178 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
179 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
181 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
182 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
185 MvData
* mv_data
= setupMV1Data(ppp
, 5, 5, REF1_ONLY
);
187 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
189 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
191 pbuffer
.PushPicture(pp
);
192 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
194 pp
.SetPicSort(PictureSort::InterRefPictureSort());
196 pp
.Refs().push_back(0);
197 pbuffer
.PushPicture(pp
);
198 PicturesTest::zeroPicture(pbuffer
.GetPicture(1));
201 pbuffer
.PushPicture(pp
);
202 PicturesTest::zeroPicture(pbuffer
.GetPicture(2));
204 Picture
* ref_pics
[2] = { &pbuffer
.GetPicture(1), &pbuffer
.GetPicture(2) };
206 // MotionCompensator mc( cp );
207 // mc.CompensatePicture(ADD, pbuffer, 1, *mv_data);
208 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
210 // MotionCompensator mc2( cp );
211 // mc2.CompensatePicture(SUBTRACT, pbuffer, 1, *mv_data);
212 MotionCompensator::CompensatePicture(ppp
, SUBTRACT
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
214 CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer
.GetPicture(2), pbuffer
.GetPicture(1)));
218 void MotionCompTest::testL2_picture()
220 for (int i
= 0; i
< 4; ++i
)
222 testL2_picture(static_cast<MVPrecisionType
>(i
));
226 void MotionCompTest::testL2_picture(MVPrecisionType precision
)
228 PictureBuffer pbuffer
;
229 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 1, true);
230 PicturePredParams
&ppp
= cp
.GetPicPredParams();
231 OLBParams
bparams(12, 12, 8, 8);
232 ppp
.SetMVPrecision(precision
);
233 ppp
.SetBlockSizes(bparams
, format420
);
234 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
235 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
237 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
238 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
241 MvData
* mv_data
= setupMV1Data(ppp
, 5, 5, REF1_ONLY
);
243 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
245 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
247 pbuffer
.PushPicture(pp
);
248 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
250 pp
.SetPicSort(PictureSort::InterNonRefPictureSort());
252 pp
.Refs().push_back(0);
253 pbuffer
.PushPicture(pp
);
254 PicturesTest::zeroPicture(pbuffer
.GetPicture(1));
257 pbuffer
.PushPicture(pp
);
258 PicturesTest::zeroPicture(pbuffer
.GetPicture(2));
260 Picture
* ref_pics
[2] = { &pbuffer
.GetPicture(1), &pbuffer
.GetPicture(2) };
262 // MotionCompensator mc( cp );
263 // mc.CompensatePicture(ADD, pbuffer, 1, *mv_data);
264 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
266 // MotionCompensator mc2( cp );
267 // mc2.CompensatePicture(SUBTRACT, pbuffer, 1, *mv_data);
268 MotionCompensator::CompensatePicture(ppp
, SUBTRACT
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
270 CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer
.GetPicture(2), pbuffer
.GetPicture(1)));
275 void MotionCompTest::testI_picture()
277 PictureBuffer pbuffer
;
278 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 2, true);
279 PicturePredParams
&ppp
= cp
.GetPicPredParams();
280 OLBParams
bparams(12, 12, 8, 8);
281 ppp
.SetBlockSizes(bparams
, format420
);
282 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
283 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
285 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
286 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
290 MvData
* mv_data
= setupMV1Data(ppp
, 5, 5, REF1_ONLY
);
292 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
294 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
296 pbuffer
.PushPicture(pp
);
297 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
299 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
301 pp
.Refs().push_back(0);
302 pbuffer
.PushPicture(pp
);
303 PicturesTest::setupPicture(pbuffer
.GetPicture(1),0);
305 Picture
* ref_pics
[2] = { &pbuffer
.GetPicture(1), &pbuffer
.GetPicture(1) };
307 // MotionCompensator mc( cp );
308 // mc.CompensatePicture(ADD, pbuffer, 1, *mv_data);
309 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
311 CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer
.GetPicture(0), pbuffer
.GetPicture(1)));
316 void MotionCompTest::testRef2()
318 for (int i
= 0; i
< 4; ++i
)
320 testRef2(static_cast<MVPrecisionType
>(i
));
324 void MotionCompTest::testRef2(MVPrecisionType precision
)
326 PictureBuffer pbuffer
;
327 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 2, true);
328 PicturePredParams
&ppp
= cp
.GetPicPredParams();
329 OLBParams
bparams(12, 12, 8, 8);
330 ppp
.SetMVPrecision(precision
);
331 ppp
.SetBlockSizes(bparams
, format420
);
332 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
333 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
335 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
336 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
340 MvData
* mv_data
= setupMV1Data(ppp
, 5, 5, REF2_ONLY
);
341 setupMV2Data(mv_data
, 0, 0);
343 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
345 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
347 pbuffer
.PushPicture(pp
);
348 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
350 pp
.SetPicSort(PictureSort::InterRefPictureSort());
352 pp
.Refs().push_back(2);
353 pp
.Refs().push_back(0);
354 pbuffer
.PushPicture(pp
);
355 PicturesTest::zeroPicture(pbuffer
.GetPicture(1));
358 pbuffer
.PushPicture(pp
);
359 PicturesTest::zeroPicture(pbuffer
.GetPicture(2));
361 Picture
* ref_pics
[2] = { &pbuffer
.GetPicture(1), &pbuffer
.GetPicture(2) };
363 // MotionCompensator mc( cp );
364 // mc.CompensatePicture(ADD, pbuffer, 1, *mv_data);
365 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
367 //too many rounding errors for this to be exactly true;
368 //CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer.GetPicture(0), pbuffer.GetPicture(1)));
370 // MotionCompensator mc2( cp );
371 // mc2.CompensatePicture(SUBTRACT, pbuffer, 1, *mv_data);
372 MotionCompensator::CompensatePicture(ppp
, SUBTRACT
, *mv_data
, &pbuffer
.GetPicture(0), ref_pics
);
374 CPPUNIT_ASSERT (PicturesTest::equalPictures (pbuffer
.GetPicture(2), pbuffer
.GetPicture(1)));
378 void MotionCompTest::testRef1and2()
380 for (int i
= 0; i
< 4; ++i
)
382 testRef1and2(static_cast<MVPrecisionType
>(i
));
386 void MotionCompTest::testRef1and2(MVPrecisionType precision
)
388 PictureBuffer pbuffer
;
389 CodecParams
cp(VIDEO_FORMAT_CIF
, INTER_PICTURE
, 2, true);
390 PicturePredParams
&ppp
= cp
.GetPicPredParams();
391 OLBParams
bparams(12, 12, 8, 8);
392 ppp
.SetMVPrecision(precision
);
393 ppp
.SetBlockSizes(bparams
, format420
);
394 ppp
.SetXNumSB( X_SIZE
/ ppp
.LumaBParams(0).Xbsep() );
395 ppp
.SetYNumSB( Y_SIZE
/ ppp
.LumaBParams(0).Ybsep() );
397 ppp
.SetXNumBlocks( 4*ppp
.XNumSB() );
398 ppp
.SetYNumBlocks( 4*ppp
.YNumSB() );
400 MvData
* mv_data
= setupMV1Data(ppp
, 5, 5, REF1_ONLY
);
401 setupMV2Data(mv_data
, 5, 5);
403 MvData
* mv_data1
= setupMV1Data(ppp
, 7, 3, REF2_ONLY
);
404 setupMV2Data(mv_data1
, 7, 3);
406 MvData
* mv_data2
= setupMV1Data(ppp
, 5, 5, REF1AND2
);
407 setupMV2Data(mv_data2
, 7, 3);
409 PictureParams
pp(format420
, X_SIZE
, Y_SIZE
, 8, 8);
411 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
413 pbuffer
.PushPicture(pp
);
414 PicturesTest::setupPicture(pbuffer
.GetPicture(0),0);
416 pp
.SetPicSort(PictureSort::IntraRefPictureSort());
418 pbuffer
.PushPicture(pp
);
419 PicturesTest::setupPicture(pbuffer
.GetPicture(1),50);
421 pp
.SetPicSort(PictureSort::InterRefPictureSort());
423 pp
.Refs().push_back(0);
424 pp
.Refs().push_back(1);
425 pbuffer
.PushPicture(pp
);
426 PicturesTest::zeroPicture(pbuffer
.GetPicture(2));
429 pbuffer
.PushPicture(pp
);
430 PicturesTest::zeroPicture(pbuffer
.GetPicture(3));
432 //MotionCompensator mc( cp );
434 Picture
* ref_pics
[2];
435 ref_pics
[0] = &pbuffer
.GetPicture(0);
436 ref_pics
[1] = &pbuffer
.GetPicture(1);
438 //mc.CompensatePicture(ADD, pbuffer, 2, *mv_data);
439 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data
, &pbuffer
.GetPicture(2), ref_pics
);
441 //MotionCompensator mc2( cp );
443 //mc2.CompensatePicture(ADD, pbuffer, 2, *mv_data1);
444 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data1
, &pbuffer
.GetPicture(2), ref_pics
);
446 // MotionCompensator mc3( cp );
448 // mc3.CompensatePicture(ADD, pbuffer, 3, *mv_data2);
449 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data2
, &pbuffer
.GetPicture(3), ref_pics
);
451 //MotionCompensator mc4( cp );
453 //mc4.CompensatePicture(ADD, pbuffer, 3, *mv_data2);
454 MotionCompensator::CompensatePicture(ppp
, ADD
, *mv_data2
, &pbuffer
.GetPicture(3), ref_pics
);
456 CPPUNIT_ASSERT (PicturesTest::almostEqualPictures (pbuffer
.GetPicture(2), pbuffer
.GetPicture(3), 5 ));