1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: pred_mode.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/pred_mode.h>
39 using namespace dirac_instr;
40 using namespace dirac;
41 
42 // constructor
DrawPredMode(Picture & picture,DrawPictureMotionParams & draw_params,const TwoDArray<PredMode> & mode)43 DrawPredMode::DrawPredMode(Picture & picture, DrawPictureMotionParams & draw_params, const TwoDArray<PredMode> & mode)
44 :
45     DrawOverlay(picture, draw_params),
46     m_mode(mode)
47 {}
48 
49 // destructor
~DrawPredMode()50 DrawPredMode::~DrawPredMode()
51 {}
52 
53 // colours a motion vector block according to prediction picture
DrawBlock(int j,int i)54 void DrawPredMode::DrawBlock(int j, int i)
55 {
56     int power = 0, U = 0, V = 0;
57 
58     // get prediction mode
59     if (m_mode[j][i] == dirac::INTRA)
60         power=100; // red
61     else if (m_mode[j][i] == dirac::REF1_ONLY)
62         power=250; // blue
63     else if (m_mode[j][i] == dirac::REF2_ONLY)
64         power=50; // yellow
65     else if (m_mode[j][i] == dirac::REF1AND2)
66         power=0; // green
67 
68     GetPowerUV(power, U, V);
69     DrawMvBlockUV(j, i, U, V);
70 }
71 
72 // displays colours representing prediction references
DrawLegend()73 void DrawPredMode::DrawLegend()
74 {
75     // blank background
76     for (int ypx=m_draw_params.PicY()-65; ypx<m_draw_params.PicY(); ++ypx)
77     {
78         for (int xpx=7; xpx>=0; --xpx)
79             m_picture.Data(Y_COMP)[ypx][xpx]=0;
80     }
81 
82     int U=0, V=0;
83 
84     GetPowerUV(100, U, V); // intra
85     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(64/m_draw_params.ChromaFactorY())+1, 0, U, V);
86     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(56/m_draw_params.ChromaFactorY())+1, 0, U, V);
87 
88     GetPowerUV(250, U, V); // ref 1
89     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(48/m_draw_params.ChromaFactorY())+1, 0, U, V);
90     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(40/m_draw_params.ChromaFactorY())+1, 0, U, V);
91 
92     GetPowerUV(50, U, V); // ref 2
93     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(32/m_draw_params.ChromaFactorY())+1, 0, U, V);
94     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(24/m_draw_params.ChromaFactorY())+1, 0, U, V);
95 
96     GetPowerUV(0, U, V); // ref 1 and 2
97     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(16/m_draw_params.ChromaFactorY())+1, 0, U, V);
98     DrawBlockUV((m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(8/m_draw_params.ChromaFactorY())+1, 0, U, V);
99 
100     // black horizontal lines
101     for (int xpx=15; xpx>=0; --xpx)
102     {
103         m_picture.Data(Y_COMP)[m_draw_params.PicY()-65][xpx]=0;
104         m_picture.Data(Y_COMP)[m_draw_params.PicY()-49][xpx]=0;
105         m_picture.Data(Y_COMP)[m_draw_params.PicY()-33][xpx]=0;
106     }
107 
108     for (int xpx=31; xpx>=0; --xpx)
109     {
110         m_picture.Data(Y_COMP)[m_picture.Data(Y_COMP).LastY()-16][xpx]=0;
111     }
112 
113     // draw labels
114     DrawCharacter(m_symbols.LetterI(), m_draw_params.PicY()-64, 8);
115     DrawCharacter(m_symbols.Number1(), m_draw_params.PicY()-48, 8);
116     DrawCharacter(m_symbols.Number2(), m_draw_params.PicY()-32, 8);
117     DrawCharacter(m_symbols.Number1(), m_draw_params.PicY()-16, 8);
118     DrawCharacter(m_symbols.SymbolPlus(), m_draw_params.PicY()-16, 16);
119     DrawCharacter(m_symbols.Number2(), m_draw_params.PicY()-16, 24);
120 
121     // blank background
122     for (int ypx=(m_draw_params.PicY()/m_draw_params.ChromaFactorY())-1-(16/m_draw_params.ChromaFactorY());
123         ypx<=m_picture.Data(U_COMP).LastY(); ++ypx)
124     {
125         // no chrominance
126         for (int xpx=(32/m_draw_params.MvYBlockX())-1; xpx>=(16/m_draw_params.ChromaFactorX()); --xpx)
127         {
128             m_picture.Data(U_COMP)[ypx][xpx]=0;
129             m_picture.Data(V_COMP)[ypx][xpx]=0;
130         }
131     }
132 }
133