1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: motion_colour.cpp,v 1.7 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/motion_colour.h>
39 using namespace dirac_instr;
40 using namespace dirac;
41 
42 // constructor
DrawMotionColour(Picture & picture,DrawPictureMotionParams & draw_params,const MvArray & mv,int mv_scale,int mv_clip)43 DrawMotionColour::DrawMotionColour(Picture & picture, DrawPictureMotionParams & draw_params, const MvArray & mv,
44                                    int mv_scale, int mv_clip)
45 :
46     DrawOverlay(picture, draw_params),
47     m_mv_scale(mv_scale),
48     m_mv_clip(mv_clip),
49     m_mv(mv)
50 {}
51 
52 // destructor
~DrawMotionColour()53 DrawMotionColour::~DrawMotionColour()
54 {}
55 
56 // colours motion vector block appropriately
DrawBlock(int j,int i)57 void DrawMotionColour::DrawBlock(int j, int i)
58 {
59     DrawMvBlockUV(j, i, (((m_mv[j][i].x) * (125/m_mv_clip)) / m_mv_scale),
60                         (((m_mv[j][i].y) * (125/m_mv_clip)) / m_mv_scale));
61 }
62 
63 // draws colour wheel legend
DrawLegend()64 void DrawMotionColour::DrawLegend()
65 {
66     int y_start = m_draw_params.PicY()-31;
67 
68     for (int ypx=y_start+1, y=-15; ypx<=y_start+30; ++ypx, y+=m_draw_params.ChromaFactorY())
69     {
70         // white background
71         for (int xpx=1; xpx<40; ++xpx)
72         {
73             m_picture.Data(Y_COMP)[ypx][xpx]=0;
74         }
75 
76         // crosshair vertical line
77         m_picture.Data(Y_COMP)[ypx][21]=88-128;
78     }
79 
80     // colour in the rectangle
81     for (int ypx=(m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1, y=15;
82          ypx>(m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(30/m_draw_params.ChromaFactorY());
83          --ypx, y-=m_draw_params.ChromaFactorY())
84     {
85         for (int xpx=40/m_draw_params.ChromaFactorX(), x=20; xpx>=0; --xpx, x-=m_draw_params.ChromaFactorX())
86         {
87             m_picture.Data(U_COMP)[ypx][xpx]=(x*25)-128;
88             m_picture.Data(V_COMP)[ypx][xpx]=(y*25)-128;
89         }
90     }
91 
92     // crosshair horizontal linem_
93     for (int xpx=0; xpx<40; ++xpx)
94     {
95         m_picture.Data(Y_COMP)[y_start+16][xpx]=88-128;
96     }
97 
98     // vertical black line
99     for (int ypx=y_start+1; ypx<=y_start+30; ++ypx)
100     {
101         m_picture.Data(Y_COMP)[ypx][41]=-128;
102         m_picture.Data(Y_COMP)[ypx][0]=-128;
103     }
104 
105     // horizontal black line
106     for (int xpx=0; xpx<=41; ++xpx)
107     {
108         m_picture.Data(Y_COMP)[y_start][xpx]=0;
109         m_picture.Data(Y_COMP)[m_picture.Data(Y_COMP).LastY()][xpx]=0;
110     }
111 
112     // display the clip value
113     DrawValue(m_mv_clip, m_draw_params.PicY()-47, 0);
114 }
115