1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: sad.cpp,v 1.8 2008/06/19 10:39:59 tjdwave 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): Chris Bowley (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 #include <util/instrumentation/libdirac_instrument/sad.h>
39 using namespace dirac_instr;
40 using namespace dirac;
41 
42 // constructor
DrawSad(Picture & picture,DrawPictureMotionParams & draw_params,const TwoDArray<MvCostData> & cost,const TwoDArray<PredMode> & mode,int scale)43 DrawSad::DrawSad(Picture & picture, DrawPictureMotionParams & draw_params, const TwoDArray<MvCostData> & cost, const TwoDArray<PredMode> & mode,
44                  int scale)
45 :
46     DrawOverlay(picture, draw_params),
47     m_scale(scale),
48     m_cost(cost),
49     m_mode(mode)
50 {}
51 
52 // destructor
~DrawSad()53 DrawSad::~DrawSad()
54 {}
55 
56 // colours a motion vector block appropriately and indicates intra coding using a white box
DrawBlock(int j,int i)57 void DrawSad::DrawBlock(int j, int i)
58 {
59     // get U and V for motion vector block
60     int U = 0, V = 0;
61     int value = int(m_cost[j][i].SAD / (double(m_scale) / 250));
62     GetPowerUV(value, U, V);
63     DrawMvBlockUV(j, i, U, V);
64 
65     // if intra, draw white box round block
66     if (m_mode[j][i]==dirac::INTRA)
67     {
68         int yidx = (j*m_draw_params.MvYBlockY());
69         int xidx = (i*m_draw_params.MvYBlockX());
70         for (int ypx=0; ypx<m_draw_params.MvYBlockY(); ++ypx)
71         {
72             if ((yidx+ypx)>=m_picture.Data(Y_COMP).LengthY() ||
73                 (xidx+m_draw_params.MvYBlockX()-1)>= m_picture.Data(Y_COMP).LengthX())
74                 break;
75             m_picture.Data(Y_COMP)[(j*m_draw_params.MvYBlockY())+ypx][(i*m_draw_params.MvYBlockX())] = 250;
76             m_picture.Data(Y_COMP)[(j*m_draw_params.MvYBlockY())+ypx][(i*m_draw_params.MvYBlockX())+m_draw_params.MvYBlockX()-1] = 250;
77         }// ypx
78 
79         for (int xpx=0; xpx<m_draw_params.MvYBlockX(); ++xpx)
80         {
81             if ((yidx+m_draw_params.MvYBlockY()-1)>=m_picture.Data(Y_COMP).LengthY() ||
82                 (xidx+xpx)>= m_picture.Data(Y_COMP).LengthX())
83                 break;
84             m_picture.Data(Y_COMP)[(j*m_draw_params.MvYBlockY())][(i*m_draw_params.MvYBlockX())+xpx] = 250;
85             m_picture.Data(Y_COMP)[(j*m_draw_params.MvYBlockY())+m_draw_params.MvYBlockY()-1][(i*m_draw_params.MvYBlockX())+xpx] = 250;
86         }// xpx
87     }
88 }
89 
90 // displays power bar legend
DrawLegend()91 void DrawSad::DrawLegend()
92 {
93     DrawPowerBar(0, m_scale);
94 }
95